35 std::vector<std::pair<std::string, std::vector<std::string>>> lut_init_data;
36 for (
const auto& lut_type : gl->get_gate_types([](
const GateType* gt) { return gt->has_property(GateTypeProperty::c_lut); }))
39 if (init_component ==
nullptr)
49 const auto& data_category = gl->get_gate_location_data_category();
50 const auto& data_identifier = gl->get_gate_location_data_identifiers();
52 gate->delete_data(data_category, data_identifier.first);
53 gate->delete_data(data_category, data_identifier.second);
56 gate->delete_data(
"generic",
"READ_MODE");
57 gate->delete_data(
"generic",
"WRITE_MODE");
61 for (
const auto& [init_category, init_identifiers] : lut_init_data)
63 for (
const auto& init_identifier : init_identifiers)
65 gate->delete_data(init_category, init_identifier);
74 std::string new_net_name;
75 new_net_name =
utils::replace(net_name, std::string(
"__"), std::string(
"___05F"));
76 new_net_name =
utils::replace(new_net_name, std::string(
"'"), std::string(
"__027"));
77 new_net_name =
utils::replace(new_net_name, std::string(
"("), std::string(
"__028"));
78 new_net_name =
utils::replace(new_net_name, std::string(
")"), std::string(
"__029"));
79 new_net_name =
utils::replace(new_net_name, std::string(
"["), std::string(
"__05b"));
80 new_net_name =
utils::replace(new_net_name, std::string(
"]"), std::string(
"__05d"));
87 std::vector<std::pair<std::string,std::string> > replace_names;
88 for (
auto it : gate_type_names)
89 if (it.first->get_name() != it.second)
90 replace_names.push_back(std::make_pair(it.first->get_name(), it.second));
91 if (replace_names.empty())
return;
93 ifstr.open(netlist_verilog);
98 std::getline(ifstr, line);
99 for (
auto jt : replace_names)
104 pos = line.find(jt.first, pos);
105 if (pos == std::string::npos)
break;
106 line.replace(pos, jt.first.size(), jt.second);
107 pos += jt.second.size();
110 buffer += line +
"\n";
113 std::ofstream ofstr(netlist_verilog, std::ofstream::trunc);
118 const int VerilatorEngine::s_command_lines = 3;
125 const std::vector<const Gate*> simulation_gates(simInput->
get_gates().begin(), simInput->
get_gates().end());
145 if (provided_models.empty())
147 log_info(
"verilator",
"the property 'provided_models' has not been set (use set_engine_property method to assign).");
157 if (!write_testbench_files(simInput))
159 log_error(
"verilator",
"error, testbench files for verilog could not be written");
164 log_error(
"verilator",
"could not create gate definitions in verilog");
189 std::stringstream callbacks;
193 std::stringstream callback;
195 <<
" auto " << net_name <<
"_net = netMap.find(std::string(\"" << input_net->get_name() <<
"\"));\n"
196 <<
" if (" << net_name <<
"_net == netMap.end()) {\n"
197 <<
" std::cerr << \"no SALEAE input data found for net " << net_name <<
"\" << std::endl;\n"
200 <<
" if (!sp.register_callback(" << net_name <<
"_net->second, set_simulation_value, &dut->" << net_name <<
")) {\n"
201 <<
" std::cerr << \"cannot initialize callback for net " << net_name <<
"\" << std::endl;\n"
208 callbacks << callback.str() << std::endl;
211 testbench_cpp =
utils::replace(testbench_cpp, std::string(
"<set_callbacks>"), callbacks.str());
214 testbench_cpp_file << testbench_cpp;
215 testbench_cpp_file.close();
222 return s_command_lines;
231 std::vector<std::string> retval = {
"verilator",
254 "--trace-underscore",
255 "--coverage-underscore",
257 "saleae_directory.cpp",
262 #if defined(__APPLE__)
274 if (!m_compiler.empty())
276 retval.push_back(
"--compiler");
277 retval.push_back(m_compiler);
284 return {
"make",
"-j" + std::to_string(m_num_of_threads),
"--no-print-directory",
"-C",
"obj_dir/",
"-f",
"V" +
m_design_name +
".mk"};
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr)
const std::string & get_init_category() const
static bool is_class_of(const GateTypeComponent *component)
const std::vector< std::string > & get_init_identifiers() const
const std::vector< Gate * > & get_gates() const
const GateLibrary * get_gate_library() const
std::string get_working_directory() const
virtual std::string get_engine_property(const std::string &key)
SimulationInput * mSimulationInput
bool install_saleae_parser(std::string dirname) const
std::string mResultFilename
SimulationEngine * createEngine() const override
VerilatorEngine(const std::string &nam)
std::string m_design_name
bool setSimulationInput(SimulationInput *simInput) override
std::unique_ptr< Netlist > m_partial_netlist
std::vector< std::string > commandLine(int lineIndex) const override
int numberCommandLines() const override
std::filesystem::path m_simulator_dir
#define log_error(channel,...)
#define log_info(channel,...)
#define log_warning(channel,...)
std::unique_ptr< Netlist > get_partial_netlist(const Netlist *nl, const std::vector< const Gate * > &subgraph_gates)
bool write(Netlist *netlist, const ProgramArguments &args)
T replace(const T &str, const T &search, const T &replace)
bool convert_gate_library_to_verilog(const Netlist *nl, const std::filesystem::path verilator_sim_path, const std::filesystem::path model_path="")
std::unordered_map< GateType *, std::string > get_gate_gate_types_from_netlist(const Netlist *nl)
std::string escape_net_name(std::string net_name)
void remove_unwanted_parameters_from_netlist(Netlist *nl)
const std::string get_testbench_cpp_template()
void cleanup_gate_type_names(const Netlist *nl, const std::filesystem::path &netlist_verilog)
const char * path_to_rapidjson_includedir
const char * path_to_verilator_executable