@@ -57,7 +57,7 @@ def setup(self, edam):
5757 has_system_verilog = True
5858
5959 # This file is a normal source file
60- src_files .append (f [ "name" ] )
60+ src_files .append (f )
6161 unused_files .remove (f )
6262
6363 if file_type in self .TCL_SCRIPT_TYPES :
@@ -71,9 +71,6 @@ def setup(self, edam):
7171 self .edam = edam .copy ()
7272 self .edam ["files" ] = unused_files
7373
74- all_files = src_files + include_files + tcl_files + dpi_libraries
75- self .src_files = src_files
76-
7774 # Append option flags
7875 en_64bit_cmd = [] if self .tool_options .get ("32bit" ) else ["-64bit" ]
7976 sv_cmd = ["-sv" ] if has_system_verilog else []
@@ -88,7 +85,7 @@ def setup(self, edam):
8885 # Append TCL scripts
8986 tcl_cmd = []
9087 for tcl in tcl_files :
91- tcl_cmd . append ( ["-input" , tcl ])
88+ tcl_cmd += ["-input" , tcl ]
9289
9390 # Append DPI libraries
9491 dpi_lib_cmd = []
@@ -104,43 +101,94 @@ def setup(self, edam):
104101 )
105102 )
106103
104+ # Append Verilog parameters
105+ vlogparam_cmd = []
106+ for k , v in self .vlogparam .items ():
107+ val = self ._param_value_str (v , str_quote_style = '"' )
108+ vlogparam_cmd .append (f"-defparam { self .toplevel } .{ k } ={ val } " )
109+
107110 # Append include directories
108111 incdir_cmd = ["+incdir+" + d for d in incdirs ]
109112
110113 # Append top level module
111114 top_cmd = ["-top" , self .toplevel ]
112115
116+ prev_fileopts = ("" , "" , {})
117+ filegroups = []
118+ # Iterate over all relevant source files. If a file has
119+ # different file_type, logical_name or defines compared
120+ # to the previous file, we put it in a new file group
121+ for f in src_files :
122+ lib = f .get ("logical_name" , "" )
123+ defines = f .get ("define" , {})
124+ file_type = f .get ("file_type" )
125+ fileopts = (file_type , lib , defines )
126+ if fileopts != prev_fileopts :
127+ filegroups .append ((fileopts , []))
128+ filegroups [- 1 ][1 ].append (f ["name" ])
129+ prev_fileopts = fileopts
130+
131+ files_cmd = []
132+ for fg in filegroups :
133+ # Ignore empty file groups
134+ if fg [1 ]:
135+ (_ , lib , defines ) = fg [0 ]
136+ if lib :
137+ files_cmd += ["-makelib" , lib ]
138+ for k , v in defines .items ():
139+ files_cmd += ["-define" , f"{ k } ={ v } " ]
140+ files_cmd += fg [1 ]
141+ if lib :
142+ files_cmd += ["-endlib" ]
143+
144+ # This file seems to only be created after a successful build
145+ target = "xcelium.d/run.d/hdl.var"
146+
113147 # Prepare the simulation command
148+ # -enable_cmdline_define_redefinition is required to support file-specific defines
114149 self .commands .add (
115- ["xrun" ]
116- + en_64bit_cmd
150+ [
151+ "xrun" ,
152+ "-elaborate" ,
153+ "-f" ,
154+ "xrun.f" ,
155+ "-enable_cmdline_define_redefinition" ,
156+ ]
157+ + files_cmd ,
158+ [target ],
159+ [f ["name" ] for f in src_files ]
160+ + include_files
161+ + tcl_files
162+ + dpi_libraries
163+ + ["xrun.f" ],
164+ )
165+
166+ self .xrun_f = (
167+ en_64bit_cmd
117168 + sv_cmd
118- + timescale_cmd
119169 + tcl_cmd
120170 + dpi_lib_cmd
121171 + macro_def_cmd
172+ + vlogparam_cmd
122173 + incdir_cmd
123174 + top_cmd
124- + ["-f" , "xrun.f" ]
125- + self .tool_options .get ("xrun_options" , []),
126- ["run" ],
127- include_files + tcl_files + dpi_libraries + ["xrun.f" ],
175+ + self .tool_options .get ("xrun_options" , [])
128176 )
129-
130- self .commands .set_default_target ("run" )
177+ self .commands .set_default_target (target )
131178
132179 def write_config_files (self ):
133- # Update f files to include all sources
134- self .update_config_file ("xrun.f" , "\n " .join (self .src_files ) + "\n " )
180+ print (self .xrun_f )
181+ # Keep all command-line options in xrun.f to detect build config changes
182+ self .update_config_file ("xrun.f" , "\n " .join (self .xrun_f ) + "\n " )
135183
136184 def run (self ):
137- args = ["run " ]
185+ args = ["-R " ]
138186
139187 # Set plusargs
140188 if self .plusarg :
141189 plusargs = []
142190 for key , value in self .plusarg .items ():
143191 plusargs += ["+{}={}" .format (key , self ._param_value_str (value ))]
144- args . append ( "EXTRA_OPTIONS=" + " " . join ( plusargs ))
192+ args += plusargs
145193
146- return ("make " , args , self .work_root )
194+ return ("xrun " , args , self .work_root )
0 commit comments