Skip to content

Commit 198f972

Browse files
committed
Added ghdl_flags compile and sim options
1 parent cd1fd51 commit 198f972

6 files changed

Lines changed: 109 additions & 13 deletions

File tree

user_guide.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ test = ent.test("test")
302302
test.disable_ieee_warnings()
303303
```
304304
## Setting custom simulation options
305-
Custom simulation options can be set using the`sim_options(name, value)` method. Options can either be set globally, for a library, for an entity or for a specific test.
305+
Custom simulation options can be set using the`set_sim_option(name, value)` method. Options can either be set globally, for a library, for an entity or for a specific test.
306306
```python
307307
vu.set_sim_option("vsim_extra_args.gui", "-voptargs=+acc")
308308
```
@@ -312,6 +312,22 @@ vu.set_sim_option("vsim_extra_args.gui", "-voptargs=+acc")
312312
- Extra arguments passed to `vsim` when loading the design.
313313
* `vsim_extra_args.gui`
314314
- Extra arguments passed to `vsim` when loading the design in GUI mode where it takes precedence over `vsim_extra_args`.
315+
* `ghdl_flags`
316+
- Extra arguments passed to `ghdl --elab-run` command *before* executable specific flags. Must be a list of strings.
317+
- Example `vu.set_sim_option("ghdl_flags", ["--no-vital-checks"])`.
318+
319+
## Setting custom compilation options
320+
Custom compilation options can be set using the `set_compile_option(name, value)` method. Options can be either set globally, for a library or for a specific file returned by the `add_source_files` method.
321+
```python
322+
vu.set_compile_option("ghdl_flags", ["--no-vital-checks"])
323+
```
324+
325+
**NOTE:** Only affects source files added *before* the option is set.
326+
327+
### Known compilation options
328+
* `ghdl_flags`
329+
- Extra arguments passed to `ghdl -a` command. Must be a list of strings.
330+
- Example `vu.set_compile_option("ghdl_flags", ["--no-vital-checks"])`.
315331

316332
## Ctrl-C when using Git/MSYS Bash on Windows
317333
VUnit will catch Ctrl-C and perform a clean shutdown closing all started simulation processes and printing the test report so far. On Git/MSYS Bash on Windows however there is a mechanism that hard kills a process a very short time after pressing Ctrl-C often prohibiting VUnit from completing its shutdown. This can leave simulation process open which have to be manually killed. See this [stack overflow post](http://stackoverflow.com/questions/23678045/control-c-kills-ipython-in-git-bash-on-windows-7) for tips on how to remove this mechanism.

vunit/ghdl_interface.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ def compile_project(self, project, vhdl_standard):
108108
print('Compiling ' + source_file.name + ' into ' + source_file.library.name + ' ...')
109109

110110
if source_file.file_type == 'vhdl':
111-
success = self.compile_vhdl_file(source_file.name, source_file.library.name,
112-
source_file.library.directory, vhdl_standard)
111+
success = self.compile_vhdl_file(source_file.name,
112+
source_file.library.name,
113+
source_file.library.directory,
114+
vhdl_standard,
115+
source_file.compile_options)
113116
elif source_file.file_type == 'verilog':
114117
raise RuntimeError("Unkown file type: " + source_file.file_type)
115118

@@ -130,7 +133,12 @@ def _std_str(self):
130133
else:
131134
assert False
132135

133-
def compile_vhdl_file(self, source_file_name, library_name, library_path, vhdl_standard):
136+
def compile_vhdl_file(self, # pylint: disable=too-many-arguments
137+
source_file_name,
138+
library_name,
139+
library_path,
140+
vhdl_standard,
141+
compile_options):
134142
"""
135143
Compile a vhdl file
136144
"""
@@ -140,6 +148,7 @@ def compile_vhdl_file(self, source_file_name, library_name, library_path, vhdl_s
140148
'--std=%s' % self._std_str()]
141149
for library_name, library_path in self._libraries.items():
142150
cmd += ["-P%s" % library_path]
151+
cmd += compile_options.get("ghdl_flags", [])
143152
cmd += [source_file_name]
144153
proc = Process(cmd)
145154
proc.consume_output()
@@ -172,6 +181,7 @@ def simulate(self, # pylint: disable=too-many-arguments, too-many-locals
172181

173182
if self._has_output_flag():
174183
cmd += ['-o', join(ghdl_output_path, "%s-%s" % (entity_name, architecture_name))]
184+
cmd += config.options.get("ghdl_flags", [])
175185

176186
cmd += [entity_name, architecture_name]
177187

vunit/project.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ def __init__(self, name, library, file_type):
538538
self.file_type = file_type
539539
self.design_units = []
540540
self._content_hash = None
541+
self._compile_options = {}
541542

542543
def __eq__(self, other):
543544
if isinstance(other, type(self)):
@@ -557,9 +558,34 @@ def __hash__(self):
557558
def __repr__(self):
558559
return "SourceFile(%s, %s)" % (self.name, self.library.name)
559560

561+
_allowed_compile_options = ["ghdl_flags"]
562+
563+
def set_compile_option(self, name, value):
564+
"""
565+
Set compile option
566+
"""
567+
if name not in self._allowed_compile_options:
568+
raise ValueError("Unknown compile option %r" % name)
569+
self._compile_options[name] = value
570+
571+
@property
572+
def compile_options(self):
573+
return self._compile_options
574+
575+
def _compile_options_hash(self):
576+
"""
577+
Compute hash of compile options
578+
579+
Needs to be updated if there are nested dictionaries
580+
"""
581+
return hash_string(repr(sorted(self._compile_options.items())))
582+
560583
@property
561584
def content_hash(self):
562-
return self._content_hash
585+
"""
586+
Compute hash of contents and compile options
587+
"""
588+
return hash_string(self._content_hash + self._compile_options_hash())
563589

564590

565591
class VerilogSourceFile(SourceFile):

vunit/test/unit/test_project.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,17 @@ def test_should_recompile_files_affected_by_change(self):
547547
file1, file2, file3 = self.create_dummy_three_file_project(update_file1=True)
548548
self.assert_should_recompile([file1, file2, file3])
549549

550+
def test_should_recompile_files_after_changing_compile_options(self):
551+
file1, file2, file3 = self.create_dummy_three_file_project()
552+
553+
self.update(file1)
554+
self.update(file2)
555+
self.update(file3)
556+
self.assert_should_recompile([])
557+
558+
file2.set_compile_option("ghdl_flags", ["--no-vital-checks"])
559+
self.assert_should_recompile([file2, file3])
560+
550561
def test_should_recompile_files_affected_by_change_with_later_timestamp(self):
551562
file1, file2, file3 = self.create_dummy_three_file_project()
552563

vunit/test_configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def set_generic(self, name, value, scope=create_scope()):
5757
self._generics[scope][name] = value
5858

5959
_known_options = ["vsim_extra_args",
60-
"vsim_extra_args.gui"]
60+
"vsim_extra_args.gui",
61+
"ghdl_flags"]
6162

6263
def set_sim_option(self, name, value, scope=create_scope()):
6364
"""

vunit/ui.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def set_sim_option(self, name, value):
228228
"""
229229
self._configuration.set_sim_option(name, value, scope=create_scope())
230230

231+
def set_compile_option(self, name, value):
232+
"""
233+
Globally set compile option
234+
"""
235+
for source_file in self._project.get_source_files_in_order():
236+
source_file.set_compile_option(name, value)
237+
231238
def set_pli(self, value):
232239
"""
233240
Globally set pli
@@ -244,8 +251,9 @@ def add_source_files(self, pattern, library_name, preprocessors=None, include_di
244251
"""
245252
Add source files matching wildcard pattern to library
246253
"""
247-
for file_name in glob(pattern):
254+
return FileSetFacade(source_files=[
248255
self.add_source_file(file_name, library_name, preprocessors, include_dirs)
256+
for file_name in glob(pattern)])
249257

250258
def add_source_file(self, file_name, library_name, preprocessors=None, include_dirs=None):
251259
"""
@@ -258,10 +266,10 @@ def add_source_file(self, file_name, library_name, preprocessors=None, include_d
258266
add_verilog_include_dir(include_dirs)
259267

260268
file_name = self._preprocess(library_name, abspath(file_name), preprocessors)
261-
self._project.add_source_file(file_name,
262-
library_name,
263-
file_type=file_type,
264-
include_dirs=include_dirs)
269+
return self._project.add_source_file(file_name,
270+
library_name,
271+
file_type=file_type,
272+
include_dirs=include_dirs)
265273

266274
def _preprocess(self, library_name, file_name, preprocessors):
267275
"""
@@ -533,6 +541,14 @@ def set_sim_option(self, name, value):
533541
"""
534542
self._configuration.set_sim_option(name, value, scope=self._scope)
535543

544+
def set_compile_option(self, name, value):
545+
"""
546+
Set compile option within library
547+
"""
548+
for source_file in self._project.get_source_files_in_order():
549+
if source_file.library.name == self._library_name:
550+
source_file.set_compile_option(name, value)
551+
536552
def set_pli(self, value):
537553
""" Set pli within library """
538554
self._configuration.set_pli(value, scope=self._scope)
@@ -544,7 +560,7 @@ def disable_ieee_warnings(self):
544560
self._configuration.disable_ieee_warnings(scope=self._scope)
545561

546562
def add_source_files(self, pattern, preprocessors=None):
547-
self._parent.add_source_files(pattern, self._library_name, preprocessors)
563+
return self._parent.add_source_files(pattern, self._library_name, preprocessors)
548564

549565
def package(self, package_name):
550566
"""
@@ -672,7 +688,7 @@ def generate_codecs(self, codec_package_name=None, used_packages=None, output_fi
672688
output_file_name,
673689
self._parent.use_debug_codecs)
674690

675-
self._parent.add_source_files(output_file_name, self._library_name)
691+
return self._parent.add_source_files(output_file_name, self._library_name)
676692

677693

678694
class TestFacade(object):
@@ -727,6 +743,22 @@ def disable_ieee_warnings(self):
727743
self._config.disable_ieee_warnings(scope=self._scope)
728744

729745

746+
class FileSetFacade(object):
747+
"""
748+
A set of one or more files
749+
"""
750+
751+
def __init__(self, source_files):
752+
self._source_files = source_files
753+
754+
def set_compile_option(self, name, value):
755+
"""
756+
Set compile option
757+
"""
758+
for source_file in self._source_files:
759+
source_file.set_compile_option(name, value)
760+
761+
730762
def select_vhdl_standard():
731763
"""
732764
Select VHDL standard according to environment variable VUNIT_VHDL_STANDARD

0 commit comments

Comments
 (0)