15 #include "cerata/vhdl/vhdl.h"
21 #include "cerata/logging.h"
22 #include "cerata/utils.h"
24 #include "cerata/vhdl/defaults.h"
31 size_t num_graphs = 0;
34 if (o.comp ==
nullptr) {
35 CERATA_LOG(ERROR,
"OutputSpec contained no component.");
39 CERATA_LOG(DEBUG,
"VHDL: Transforming Component " + o.comp->name() +
" to VHDL-compatible version.");
42 CERATA_LOG(DEBUG,
"VHDL: Generating sources for component " + o.comp->name());
43 auto vhdl_source = vhdl_design.Generate().ToString();
44 auto vhdl_path =
root_dir_ +
"/" +
subdir() +
"/" + o.comp->name() +
".gen.vhd";
47 bool backup = (o.meta.count(meta::BACKUP_EXISTING) > 0) && (o.meta.at(meta::BACKUP_EXISTING) ==
"true");
49 CERATA_LOG(DEBUG,
"VHDL: Saving design to: " + vhdl_path);
51 auto vhdl_file = std::ofstream(vhdl_path);
52 vhdl_file << vhdl_source;
55 CERATA_LOG(DEBUG,
"VHDL: File exists, backing up and saving to " + vhdl_path +
"t");
57 auto original = std::ifstream(vhdl_path, std::ios::binary);
58 auto copy = std::ofstream(vhdl_path +
".bak", std::ios::binary);
59 copy << original.rdbuf();
61 auto vhdl_file = std::ofstream(vhdl_path);
62 vhdl_file << vhdl_source;
67 CERATA_LOG(DEBUG,
"VHDL: Generated output for " + std::to_string(num_graphs) +
" graphs.");