@@ -236,10 +236,47 @@ def _get_mapped_libraries(self):
236236 del libraries ["others" ]
237237 return libraries
238238
239- def _create_optimize_script (self , design_to_optimize , optimized_design , config ):
239+ def _optimize_design (self , config ):
240+ """
241+ Return if design shall be optimized.
242+ """
243+
244+ return config .sim_options .get ("modelsim.three_step_flow" , False )
245+
246+ @staticmethod
247+ def _design_to_optimize (config ):
248+ """
249+ Return the design to optimize.
250+ """
251+ if config .architecture_name is None :
252+ architecture_suffix = ""
253+ else :
254+ architecture_suffix = f"({ config .architecture_name !s} )"
255+
256+ return (
257+ config .library_name + "." + config .entity_name + architecture_suffix
258+ if config .vhdl_configuration_name is None
259+ else config .library_name + "." + config .vhdl_configuration_name
260+ )
261+
262+ @staticmethod
263+ def _to_optimized_design (design_to_optimize ):
264+ """
265+ Return name for optimized design.
266+
267+ vopt has limitations on how the optimized design can be named. Simply removing
268+ non-alphanumeric characters is a simple solution to that.
269+ """
270+
271+ return "opt_" + "" .join (ch for ch in design_to_optimize if ch .isalnum ())
272+
273+ def _create_optimize_function (self , config ):
240274 """
241275 Create vopt script.
242276 """
277+ design_to_optimize = self ._design_to_optimize (config )
278+ optimized_design = self ._to_optimized_design (design_to_optimize )
279+
243280 vopt_flags = [
244281 f"{ design_to_optimize } " ,
245282 f"-work {{{ config .library_name } }}" ,
@@ -261,17 +298,18 @@ def _create_optimize_script(self, design_to_optimize, optimized_design, config):
261298 tcl = """
262299proc vunit_optimize {{vopt_extra_args ""}} {"""
263300 tcl += """
264- set vopt_failed [catch {{
265- eval vopt ${{vopt_extra_args}} {{{vopt_flags}}}
266- }}]
267-
268- if {{${{vopt_failed}}}} {{
269- echo Command 'vopt ${{vopt_extra_args}} {vopt_flags}' failed
270- echo Bad flag from vopt_extra_args?
271- return true
272- }}
301+ echo Optimizing using command 'vopt ${{vopt_extra_args}} {vopt_flags}'
302+ set vopt_failed [catch {{
303+ eval vopt ${{vopt_extra_args}} {{{vopt_flags}}}
304+ }}]
273305
274- return False
306+ if {{${{vopt_failed}}}} {{
307+ echo Command 'vopt ${{vopt_extra_args}} {vopt_flags}' failed
308+ echo Bad flag from vopt_extra_args?
309+ return true
310+ }}
311+
312+ return False
275313}}
276314""" .format (
277315 vopt_flags = " " .join (vopt_flags )
@@ -355,19 +393,7 @@ def _release_library_lock(self, library, config):
355393 self ._library_locks [config .library_name ].release ()
356394
357395 def _optimize (self , config , script_path ):
358- if config .architecture_name is None :
359- architecture_suffix = ""
360- else :
361- architecture_suffix = f"({ config .architecture_name !s} )"
362-
363- design_to_optimize = (
364- config .library_name + "." + config .entity_name + architecture_suffix
365- if config .vhdl_configuration_name is None
366- else config .library_name + "." + config .vhdl_configuration_name
367- )
368-
369- if not config .sim_options .get ("modelsim.three_step_flow" , False ):
370- return design_to_optimize
396+ design_to_optimize = self ._design_to_optimize (config )
371397
372398 libraries = {lib .name : lib for lib in self ._libraries }
373399 library = libraries [config .library_name ]
@@ -392,14 +418,10 @@ def _optimize(self, config, script_path):
392418
393419 LOGGER .debug ("Optimizing %s" , design_to_optimize )
394420
395- # vopt has limitations on how the optimized design can be named. Simply removing
396- # non-alphanumeric characters is a simple solution to that
397- optimized_design = "opt_" + "" .join (ch for ch in design_to_optimize if ch .isalnum ())
421+ optimized_design = self ._to_optimized_design (design_to_optimize )
398422
399423 optimize_file_name = script_path / "optimize.do"
400- write_file (
401- str (optimize_file_name ), self ._create_optimize_script (design_to_optimize , optimized_design , config )
402- )
424+ write_file (str (optimize_file_name ), self ._create_optimize_function (config ))
403425
404426 if self ._persistent_shell is not None :
405427 status = self ._run_persistent_optimize (optimize_file_name )
@@ -441,13 +463,18 @@ def _optimize(self, config, script_path):
441463 else :
442464 LOGGER .debug ("Reusing optimized %s." , design_to_optimize )
443465
444- return optimized_design
466+ return True
445467
446- def _create_load_function (self , test_suite_name , config , output_path , simulation_target ):
468+ def _create_load_function (self , test_suite_name , config , output_path , optimize_design ):
447469 """
448470 Create the vunit_load TCL function that runs the vsim command and loads the design
449471 """
450472
473+ if optimize_design :
474+ simulation_target = self ._to_optimized_design (self ._design_to_optimize (config ))
475+ else :
476+ simulation_target = self ._design_to_optimize (config )
477+
451478 set_generic_str = " " .join (
452479 (
453480 f"-g/{ config .entity_name !s} /{ name !s} ={ encode_generic_value (value )!s} "
@@ -485,16 +512,15 @@ def _create_load_function(self, test_suite_name, config, output_path, simulation
485512 # There is a known bug in modelsim that prevents the -modelsimini flag from accepting
486513 # a space in the path even with escaping, see issue #36
487514 if " " not in self ._sim_cfg_file_name :
488- modelsimini_option = f"-modelsimini { fix_path (self ._sim_cfg_file_name )!s} "
489- vsim_flags .insert (0 , modelsimini_option )
515+ vsim_flags .insert (0 , f"-modelsimini { fix_path (self ._sim_cfg_file_name )!s} " )
490516
491517 for library in self ._libraries :
492518 vsim_flags += ["-L" , library .name ]
493519
494520 vhdl_assert_stop_level_mapping = {"warning" : 1 , "error" : 2 , "failure" : 3 }
495521
496522 tcl = """
497- proc vunit_load {{vsim_extra_args ""} {vopt_extra_args ""} } {"""
523+ proc vunit_load {{vsim_extra_args ""}} {"""
498524
499525 tcl += """
500526 set vsim_failed [catch {{
0 commit comments