59 #define SIM_SUBDIR (Param->getOption<std::string>(OPT_output_directory) + std::string("/verilator")) 63 const std::string& _top_fname,
const std::string& _inc_dirs)
68 if(std::filesystem::exists(verilator_beh_dir))
70 std::filesystem::remove_all(verilator_beh_dir);
72 std::filesystem::create_directory(verilator_beh_dir +
"/");
83 const std::list<std::string>& file_list)
85 for(
const auto&
file : file_list)
87 if(
file.find(
".vhd") != std::string::npos)
92 const auto generate_vcd_output = (
Param->isOption(OPT_generate_vcd) &&
Param->getOption<
bool>(OPT_generate_vcd)) ||
93 (
Param->isOption(OPT_discrepancy) &&
Param->getOption<
bool>(OPT_discrepancy)) ||
94 (
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw));
95 const auto output_directory =
Param->getOption<std::string>(OPT_output_directory);
96 log_file =
"${BEH_DIR}/" + top_filename +
"_verilator.log";
97 script <<
"export VM_PARALLEL_BUILDS=1" << std::endl
99 <<
"BEH_CC=\"${CC}\"" << std::endl
100 <<
"obj_dir=\"${BEH_DIR}/verilator_obj\"" << std::endl
102 std::string beh_cflags =
"-DVERILATOR -isystem $(dirname $(which verilator))/../share/verilator/include/vltstd";
104 const auto vflags = [&]() {
106 if(cflags.find(
"-m32") != std::string::npos)
108 flags +=
" +define+__M32";
110 else if(cflags.find(
"-mx32") != std::string::npos)
112 flags +=
" +define+__MX32";
114 else if(cflags.find(
"-m64") != std::string::npos)
116 flags +=
" +define+__M64";
118 const auto inc_dir_list = string_to_container<std::vector<std::string>>(
inc_dirs,
",");
119 for(
const auto& inc : inc_dir_list)
121 flags +=
" +incdir+" + inc;
127 script <<
"verilator_bin" 130 script <<
"verilator" 132 <<
" --cc --exe --Mdir ${obj_dir} -Wno-fatal -Wno-lint -sv " << vflags
133 <<
" ${BEH_DIR}/libmdpi.so -O3 --output-split-cfuncs 3000 --output-split-ctrace 3000";
134 if(!generate_vcd_output)
136 script <<
" --x-assign fast --x-initial fast --noassert";
139 auto nThreadsVerilator = 1;
140 if(
Param->isOption(OPT_verilator_parallel) &&
Param->getOption<
int>(OPT_verilator_parallel) > 1)
142 const auto thread_support =
143 system(
"bash -c \"if [ $(verilator --version | grep Verilator | sed -E 's/Verilator ([0-9]+).*/\1/') -ge 4 " 144 "]; then exit 0; else exit 1; fi\" > /dev/null 2>&1") == 0;
145 THROW_WARNING(
"Installed version of Verilator does not support multi-threading.");
148 nThreadsVerilator =
Param->getOption<
int>(OPT_verilator_parallel);
152 if(nThreadsVerilator > 1)
154 script <<
" --threads " << nThreadsVerilator;
156 if(generate_vcd_output)
158 script <<
" --trace --trace-underscore";
159 auto is_verilator_l2_name =
160 system(
"bash -c \"if [[ \\\"x$(verilator --l2-name v 2>&1 | head -n1 | grep -i 'Invalid Option')\\\" = " 161 "\\\"x\\\" ]]; then exit 0; else exit 1; fi\" > /dev/null 2>&1") == 0;
162 if(is_verilator_l2_name)
164 script <<
" --l2-name bambu_testbench";
167 for(
const auto&
file : file_list)
171 script <<
" ${BEH_DIR}/libmdpi.so";
175 script <<
" " <<
file;
178 script <<
" --top-module bambu_testbench" << std::endl
179 <<
"if [ $? -ne 0 ]; then exit 1; fi" << std::endl
182 <<
"ln -sf " + output_directory +
" ${obj_dir}\n";
184 const auto nThreadsMake =
185 Param->isOption(OPT_verilator_parallel) ?
Param->getOption<
int>(OPT_verilator_parallel) : 1;
186 script <<
"make -C ${obj_dir}" 187 <<
" -j " << nThreadsMake <<
" OPT=\"-fstrict-aliasing\"" 188 <<
" -f Vbambu_testbench.mk Vbambu_testbench";
190 script <<
" VM_PARALLEL_BUILDS=1 CFG_CXXFLAGS_NO_UNUSED=\"\"";
193 script << std::endl << std::endl;
195 return "${obj_dir}/Vbambu_testbench 2>&1 | tee " +
log_file;
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
void CheckExecution() override
Checks if the current specification can be executed or not.
exceptions managed by PandA
#define THROW_WARNING(str_expr)
helper function used to throw a warning in a standard way: though it uses PRINT_DBG_MEX, the debug level used is such that the message is always printed
~VerilatorWrapper() override
Destructor.
Wrapper to Verilator simulator.
constants used in Input/Output
utility function used to read files.
VerilatorWrapper(const ParameterConstRef &Param, const std::string &suffix, const std::string &top_fname, const std::string &inc_dirs)
Constructor.
bool ends_with(const std::string &str, const std::string &pattern)
This file collects some utility functions and macros.
std::string suffix
suffix added to the SIM dir
std::string GenerateScript(std::ostream &script, const std::string &top_filename, const std::list< std::string > &file_list) override
Generates the proper simulation script.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
this class is used to manage the command-line or XML options.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
void Clean() const override
Remove files created during simulation.