@@ -53,7 +53,6 @@ def get_dependent_files(filename):
5353 return headers
5454
5555def main ():
56-
5756 avail_fpgas = {
5857 'ZedBoard' : 'xc7z020clg484-1' ,
5958 'ZCU104' : 'xczu7ev-ffvc1156-2-e' ,
@@ -99,45 +98,55 @@ def main():
9998
10099 if args .csim and args .tb_file == '' or args .cosim and args .tb_file == '' :
101100 parser .error ('The --csim and --cosim arguments requires --tb_file.' )
102-
103- print ( args )
104-
101+ # ==========================================================================
102+ # Setup
103+ # ==========================================================================
105104 curr_dir = os .getcwd ().replace ('\\ ' , '/' ) + '/'
106105 hls_prj_dir = curr_dir + '/hls_prj/'
107106 hls_report_dir = hls_prj_dir + '/reports'
108107 hls_tool = 'vhls' if args .use_vivado_hls else 'vitis'
109108 prj_name = f'{ hls_tool } _{ args .board } _{ args .top } '
110-
109+ reset_string = ' -reset ' if args .no_reset_prj else ''
110+ # ==========================================================================
111+ # Adjust CFLAGS and add defines
112+ # ==========================================================================
111113 cflags = args .cflags + ' -I' + curr_dir + args .include
112114 if hls_tool == 'vhls' :
113115 cflags = '-fno-builtin ' + cflags .replace ('c++14' , 'c++0x' )
114116 print (f'[WARNING] Replacing C++14 with C++11 in Vivado HLS. CFLAGS: { cflags } ' )
115-
117+ # ==========================================================================
118+ # Generate script file
119+ # ==========================================================================
116120 with open (args .script_name , 'w' ) as f :
117121 f .write (get_tcl_utils ())
118122 f .write (f'exec mkdir -p -- { hls_prj_dir } \n ' )
119123 f .write (f'exec mkdir -p -- { hls_report_dir } \n ' )
120124 f .write (f'cd { hls_prj_dir } \n ' )
121- f .write ('open_project {} "{}"\n ' . format ( '-reset' if not args . no_reset_prj else '' , prj_name ) )
125+ f .write (f 'open_project { reset_string } "{ prj_name } "\n ' )
122126 f .write (f'set_top "{ args .top } "\n ' )
123127 if not args .no_reset_prj :
124128 pass
125129 if args .csim or args .cosim :
126130 pass
127131 if hls_tool == 'vitis' :
128- f .write (f'open_solution -flow_target vivado -reset " { args .top } "\n ' )
132+ f .write (f'open_solution -flow_target vivado { reset_string } "solution_ { args .top } "\n ' )
129133 else :
130- f .write (f'open_solution "{ args .top } "\n ' )
134+ f .write (f'open_solution "solution_{ args .top } "\n ' )
135+ # ======================================================================
136+ # Config Synthesis for current solution
137+ # ======================================================================
131138 if not args .no_reset_prj :
132139 f .write (f'set_part { avail_fpgas [args .board ]} ;# { args .board } \n ' )
133140 f .write (f'create_clock -period { args .period } -name default\n ' )
134- if hls_tool == 'vitis' :
135- f .write (f'config_compile -name_max_length=12 -pipeline_style=frp -enable_auto_rewind=1\n ' )
136- else :
137- f .write (f'config_compile -name_max_length=12\n ' )
138- f .write (f'config_schedule -effort={ args .scheduler_effort } -relax_ii_for_timing=0\n ' )
139- f .write (f'config_core DSP48 -latency 3\n ' )
140-
141+ if hls_tool == 'vitis' :
142+ f .write (f'config_compile -name_max_length=12 -pipeline_style=frp -enable_auto_rewind=1\n ' )
143+ else :
144+ f .write (f'config_compile -name_max_length=12\n ' )
145+ f .write (f'config_schedule -effort={ args .scheduler_effort } -relax_ii_for_timing=0\n ' )
146+ f .write (f'config_core DSP48 -latency 3\n ' )
147+ # ======================================================================
148+ # Add only significant files to synthesis
149+ # ======================================================================
141150 # TODO: Recursively include only the files from which the top function depends on.
142151 headers = []
143152 if args .top_file :
@@ -158,7 +167,9 @@ def main():
158167 tmp = tmp .replace ('>' , '' )
159168 headers .append (tmp )
160169 print (headers )
161-
170+ # ======================================================================
171+ # Add files
172+ # ======================================================================
162173 f .write (f'# Source files\n ' )
163174 for fpath , subdirs , files in os .walk (args .src ):
164175 for fname in files :
@@ -183,13 +194,23 @@ def main():
183194 if fname .startswith (args .tb_file ):
184195 print (f'[INFO] Adding simulation file: { unix_filename } ' )
185196 f .write (f'add_files -tb { unix_filename } -cflags "{ cflags } "\n ' )
186-
197+ # ======================================================================
198+ # Start CSim
199+ # ======================================================================
187200 if args .csim :
188- f .write (f'csim_design -clean -O -ldflags { args .ldflags } -argv { args .argv } \n ' )
201+ csim_cmd = 'csim_design -clean -O'
202+ if args .ldflags :
203+ csim_cmd += f' -ldflags { args .ldflags } '
204+ if args .argv :
205+ csim_cmd += f' -argv { args .argv } '
206+ f .write (f'{ csim_cmd } \n ' )
207+ # ======================================================================
208+ # Run Synthesis and report
209+ # ======================================================================
210+ report_outfile = hls_report_dir + f'/{ hls_tool } _{ args .board } _{ args .top } .rpt'
189211 if not args .no_synthesis :
190212 f .write (f'csynth_design\n ' )
191213 csynth_report = hls_prj_dir + prj_name + f'/solution_{ args .top } /syn/report/{ args .top } _csynth.rpt'
192- report_outfile = hls_report_dir + f'/{ hls_tool } _{ args .board } _{ args .top } .rpt'
193214 report_info = f'''puts "================================================================"
194215puts "\[INFO\] Reporting information"
195216puts "================================================================"
@@ -200,7 +221,9 @@ def main():
200221close $fin
201222close $fout'''
202223 f .write (f'{ report_info } \n ' )
203-
224+ # ======================================================================
225+ # Run Cosim and report
226+ # ======================================================================
204227 if args .cosim :
205228 cosim_cmd = f'cosim_design -trace_level port -ldflags "{ args .ldflags } " -argv "{ args .argv } "'
206229 if hls_tool == 'vitis' and args .debug_dataflow :
@@ -209,28 +232,32 @@ def main():
209232
210233 f .write (f'{ cosim_cmd } \n ' )
211234
212- cosim_report = hls_prj_dir + prj_name + f'/solution_{ args .top } /syn /report/{ args .top } _cosim.rpt'
235+ cosim_report = hls_prj_dir + prj_name + f'/solution_{ args .top } /sim /report/{ args .top } _cosim.rpt'
213236 report_info = f'''puts "================================================================"
214237puts "\[INFO\] Reporting information"
215238puts "================================================================"
216- set fin [open { csynth_report } r]
239+ set fin [open { cosim_report } r]
217240set fout [open { report_outfile } a]
218241grep "Simulation tool" 10 $fin 0 $fout
219242close $fin
220243close $fout'''
221244 f .write (f'{ report_info } \n ' )
245+ # ======================================================================
246+ # Export IP
247+ # ======================================================================
222248 if args .export :
223249 f .write ('export_design -format ip_catalog\n ' )
224250 if args .place_and_route :
225251 f .write ('export_design -flow impl -rtl verilog -format ip_catalog\n ' )
226-
252+ # ======================================================================
253+ # Close and run
254+ # ======================================================================
227255 closing = f'''puts "================================================================"
228256puts "\[INFO\] Closing project: { prj_name } "
229257puts "================================================================"
230258exit
231259cd { curr_dir } '''
232260 f .write (f'{ closing } \n ' )
233-
234261 if args .run_hls :
235262 if hls_tool == 'vhls' :
236263 os .system (f'vivado_hls -f { args .script_name } ' )
0 commit comments