54
54
#include " fileIO.hpp"
55
55
#include " generic_device.hpp"
56
56
#include " hls_manager.hpp"
57
+ #include " library_manager.hpp"
57
58
#include " string_manipulation.hpp"
58
59
#include " structural_manager.hpp"
59
60
#include " structural_objects.hpp"
@@ -218,10 +219,9 @@ std::string HDL_manager::write_components(const std::string& filename, HDLWriter
218
219
}
219
220
220
221
void HDL_manager::write_components (const std::string& filename, const std::list<structural_objectRef>& components,
221
- std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb)
222
+ std::list<std::string>& hdl_files, std::list<std::string>& aux_files,
223
+ bool unique_out)
222
224
{
223
- bool multiFileP =
224
- !tb && parameters->IsParameter (" enable-multifiles" ) && parameters->GetParameter <bool >(" enable-multifiles" );
225
225
// / default language
226
226
auto language = parameters->getOption <HDLWriter_Language>(OPT_writer_language);
227
227
@@ -246,122 +246,81 @@ void HDL_manager::write_components(const std::string& filename, const std::list<
246
246
}
247
247
248
248
// / determine the proper language for each component
249
- std::map<HDLWriter_Language, std::list<structural_objectRef>> component_language ;
249
+ std::map<HDLWriter_Language, std::list<structural_objectRef>> hdl_comp, aux_comp ;
250
250
for (const auto & component : components)
251
251
{
252
- auto * mod = GetPointer<module >(component);
252
+ const auto mod = GetPointer<module >(component);
253
253
THROW_ASSERT (mod, " Expected a component object" );
254
+ const auto n_elements = mod->get_internal_objects_size ();
255
+ const auto np = mod->get_NP_functionality ();
254
256
255
- unsigned int n_elements = mod->get_internal_objects_size ();
256
-
257
- const NP_functionalityRef np = mod->get_NP_functionality ();
258
-
259
- if (n_elements || (np && (np->exist_NP_functionality (type) ||
260
- (language == HDLWriter_Language::VERILOG &&
261
- np->exist_NP_functionality (NP_functionality::VERILOG_FILE_PROVIDED)) ||
262
- (language == HDLWriter_Language::VHDL &&
263
- np->exist_NP_functionality (NP_functionality::VHDL_PROVIDED)))))
264
- {
265
- component_language[language].push_back (component);
266
- }
267
- else
257
+ HDLWriter_Language comp_language = language;
258
+ if (!n_elements && np)
268
259
{
269
- if (np and
270
- (np->exist_NP_functionality (NP_functionality::FSM) or np->exist_NP_functionality (NP_functionality::FSM_CS)))
260
+ const auto has_verilog = np->exist_NP_functionality (NP_functionality::VERILOG_PROVIDED) ||
261
+ np->exist_NP_functionality (NP_functionality::VERILOG_FILE_PROVIDED);
262
+ const auto has_vhdl = np->exist_NP_functionality (NP_functionality::VHDL_PROVIDED) ||
263
+ np->exist_NP_functionality (NP_functionality::FLOPOCO_PROVIDED) ||
264
+ np->exist_NP_functionality (NP_functionality::VHDL_FILE_PROVIDED);
265
+ if (np->exist_NP_functionality (type) || (language == HDLWriter_Language::VERILOG && has_verilog) ||
266
+ (language == HDLWriter_Language::VHDL && has_vhdl) || np->exist_NP_functionality (NP_functionality::FSM) ||
267
+ np->exist_NP_functionality (NP_functionality::FSM_CS))
271
268
{
272
- component_language[ language]. push_back (component) ;
269
+ comp_language = language;
273
270
}
274
- else if (np && (np->exist_NP_functionality (NP_functionality::VERILOG_PROVIDED) ||
275
- np->exist_NP_functionality (NP_functionality::VERILOG_FILE_PROVIDED)))
271
+ else if (has_verilog)
276
272
{
277
- if (!parameters->getOption <bool >(OPT_mixed_design))
278
- {
279
- THROW_ERROR (" VHDL implementation of " + component->get_path () + " is not available" );
280
- }
281
- component_language[HDLWriter_Language::VERILOG].push_back (component);
273
+ comp_language = HDLWriter_Language::VERILOG;
282
274
}
283
- else if (np && (np->exist_NP_functionality (NP_functionality::VHDL_PROVIDED) ||
284
- np->exist_NP_functionality (NP_functionality::FLOPOCO_PROVIDED) ||
285
- np->exist_NP_functionality (NP_functionality::VHDL_FILE_PROVIDED)))
275
+ else if (has_vhdl)
286
276
{
287
- if (!parameters->getOption <bool >(OPT_mixed_design))
288
- {
289
- THROW_ERROR (" Verilog implementation of " + component->get_path () + " is not available" );
290
- }
291
- else
292
- {
293
- THROW_WARNING (component->get_path () + " is available only in VHDL" );
294
- }
295
- component_language[HDLWriter_Language::VHDL].push_back (component);
277
+ comp_language = HDLWriter_Language::VHDL;
296
278
}
297
- else if (np && np ->exist_NP_functionality (NP_functionality::SYSTEM_VERILOG_PROVIDED))
279
+ else if (np->exist_NP_functionality (NP_functionality::SYSTEM_VERILOG_PROVIDED))
298
280
{
299
- component_language[ HDLWriter_Language::SYSTEM_VERILOG]. push_back (component) ;
281
+ comp_language = HDLWriter_Language::SYSTEM_VERILOG;
300
282
}
301
283
else
302
284
{
303
285
THROW_ERROR (" Language not supported! Module " + mod->get_path ());
304
286
}
305
287
}
306
- }
307
-
308
- // / generate the auxiliary files
309
- for (auto l = component_language.begin (); l != component_language.end (); ++l)
310
- {
311
- if (language == l->first )
288
+ const auto library = TM->get_library (component->get_typeRef ()->id_type );
289
+ if (unique_out || library.empty () || !starts_with (library, " STD" ))
312
290
{
313
- continue ;
314
- }
315
- if (multiFileP)
316
- {
317
- language_writerRef writer = language_writer::create_writer (l->first , TM, parameters);
318
- for (const auto & c : component_language[l->first ])
319
- {
320
- std::list<structural_objectRef> singletonList;
321
- singletonList.push_back (c);
322
- std::string mod_name = convert_to_identifier (writer.get (), GET_TYPE_NAME (c));
323
- std::string generated_filename = write_components (mod_name, l->first , singletonList, aux_files);
324
- aux_files.push_back (generated_filename);
325
- }
291
+ hdl_comp[comp_language].push_back (component);
326
292
}
327
293
else
328
294
{
329
- std::string generated_filename = write_components (filename, l->first , component_language[l->first ], aux_files);
330
- aux_files.push_back (generated_filename);
295
+ aux_comp[comp_language].push_back (component);
331
296
}
332
297
}
333
298
334
- if (multiFileP )
299
+ for ( auto & [lang, comps] : aux_comp )
335
300
{
336
- language_writerRef writer = language_writer::create_writer (language , TM, parameters);
337
-
338
- auto counter = component_language[language]. size ( );
339
- for (const auto & c : component_language[language] )
301
+ auto writer = language_writer::create_writer (lang , TM, parameters);
302
+ auto lib_dir = " bambu_lib/ " + writer-> get_name () + " / " ;
303
+ std::filesystem::create_directories (lib_dir );
304
+ for (auto & comp : comps )
340
305
{
341
- --counter;
342
- std::list<structural_objectRef> singletonList;
343
- singletonList.push_back (c);
344
- std::string mod_name = convert_to_identifier (writer.get (), GET_TYPE_NAME (c));
345
- if (counter == 0 )
346
- {
347
- mod_name = filename;
348
- }
349
- std::string generated_filename = write_components (mod_name, language, singletonList, aux_files);
350
- if (counter == 0 )
351
- {
352
- hdl_files.push_back (generated_filename);
353
- }
354
- else
355
- {
356
- aux_files.push_back (generated_filename);
357
- }
306
+ auto mod_name = lib_dir + convert_to_identifier (writer.get (), GET_TYPE_NAME (comp));
307
+ auto generated_filename = write_components (mod_name, lang, {comp}, aux_files);
308
+ aux_files.push_back (generated_filename);
358
309
}
359
310
}
360
- else
311
+
312
+ for (auto & [lang, comps] : hdl_comp)
361
313
{
362
- std::string complete_filename = write_components (filename, language, component_language[language], aux_files);
363
- // / add the generated file to the global list
364
- hdl_files.push_back (complete_filename);
314
+ auto writer = language_writer::create_writer (lang, TM, parameters);
315
+ auto generated_filename = write_components (filename, lang, comps, aux_files);
316
+ if (lang == language)
317
+ {
318
+ hdl_files.push_back (generated_filename);
319
+ }
320
+ else
321
+ {
322
+ aux_files.push_back (generated_filename);
323
+ }
365
324
}
366
325
367
326
#if HAVE_FLOPOCO
@@ -375,7 +334,7 @@ void HDL_manager::write_components(const std::string& filename, const std::list<
375
334
}
376
335
377
336
void HDL_manager::hdl_gen (const std::string& filename, const std::list<structural_objectRef>& cirs,
378
- std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb )
337
+ std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool unique_out )
379
338
{
380
339
PRINT_DBG_MEX (DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
381
340
" compute the list of components for which a structural description exists" );
@@ -398,7 +357,7 @@ void HDL_manager::hdl_gen(const std::string& filename, const std::list<structura
398
357
}
399
358
400
359
// / generate the HDL descriptions for all the components
401
- write_components (filename, list_of_com, hdl_files, aux_files, tb );
360
+ write_components (filename, list_of_com, hdl_files, aux_files, unique_out );
402
361
}
403
362
404
363
/* *
0 commit comments