55 #include <boost/algorithm/string.hpp> 63 #define MODELSIM_BIN \ 64 (Param->isOption(OPT_mentor_modelsim_bin) ? Param->getOption<std::string>(OPT_mentor_modelsim_bin) + "/" : \ 67 #define MODELSIM_VDEL (MODELSIM_BIN + "vdel") 68 #define MODELSIM_VLIB (MODELSIM_BIN + "vlib") 69 #define MODELSIM_VMAP (MODELSIM_BIN + "vmap") 70 #define MODELSIM_VCOM (MODELSIM_BIN + "vcom") 71 #define MODELSIM_VLOG (MODELSIM_BIN + "vlog") 72 #define MODELSIM_VSIM (MODELSIM_BIN + "vsim") 74 #define SIM_SUBDIR (Param->getOption<std::string>(OPT_output_directory) + std::string("/modelsim")) 78 const std::string& _top_fname,
const std::string& _inc_dirs)
82 const auto lic_path = std::getenv(
"LM_LICENSE_FILE");
83 if(!lic_path || std::string(lic_path) ==
"")
85 THROW_WARNING(
"Mentor license file has not been specified. User must set LM_LICENSE_FILE variable to point to " 86 "the license file location.");
99 const std::list<std::string>& file_list)
104 std::string beh_cflags =
"-DMODEL_TECH " + (modelsim_bin.size() ? (
"-isystem " + modelsim_bin +
"../include") :
"");
106 const auto vflags = [&]() {
108 if(cflags.find(
"-m32") != std::string::npos)
110 flags +=
" +define+__M32";
112 else if(cflags.find(
"-mx32") != std::string::npos)
114 flags +=
" +define+__MX32";
116 else if(cflags.find(
"-m64") != std::string::npos)
118 flags +=
" +define+__M64";
120 if(
Param->isOption(OPT_generate_vcd) &&
Param->getOption<
bool>(OPT_generate_vcd))
122 flags +=
" +define+GENERATE_VCD";
124 if(
Param->isOption(OPT_discrepancy) &&
Param->getOption<
bool>(OPT_discrepancy))
126 flags +=
" +define+GENERATE_VCD_DISCREPANCY";
128 const auto inc_dir_list = string_to_container<std::vector<std::string>>(
inc_dirs,
",");
129 for(
const auto& inc : inc_dir_list)
131 flags +=
" +incdir+" + inc;
136 std::string MODELSIM_OPTIMIZER_FLAGS_DEF =
"";
137 if(
Param->getOption<
bool>(OPT_mentor_optimizer))
139 MODELSIM_OPTIMIZER_FLAGS_DEF =
"-O5";
141 script <<
"work_dir=\"${BEH_DIR}/modelsim_work\"" << std::endl;
142 script <<
"if [ ! -d ${BEH_DIR} ]; then" << std::endl;
143 script <<
" mkdir -p ${BEH_DIR}" << std::endl;
144 script <<
"fi" << std::endl << std::endl;
146 log_file =
"${BEH_DIR}/" + top_filename +
"_modelsim.log";
148 script <<
"if [ -d ${work_dir} ]; then" << std::endl;
149 script <<
" " <<
MODELSIM_VDEL <<
" -all -lib ${work_dir}" << std::endl;
150 script <<
"fi" << std::endl << std::endl;
155 script <<
" > /dev/null 2>&1 ";
157 script << std::endl << std::endl;
159 script <<
MODELSIM_VMAP <<
" work ${work_dir}" << std::endl << std::endl;
161 script <<
"sed -i 's/; AssertionFailAction = 1/AssertionFailAction = 2/g' modelsim.ini" << std::endl << std::endl;
164 for(
const auto&
file : file_list)
167 std::filesystem::path file_path(
file);
168 const auto extension = file_path.extension().string();
169 if(extension ==
".vhd" || extension ==
".vhdl" || extension ==
".VHD" || extension ==
".VHDL")
171 script <<
MODELSIM_VCOM <<
" " << vflags <<
" " << MODELSIM_OPTIMIZER_FLAGS_DEF;
172 if(
Param->isOption(OPT_assert_debug) &&
Param->getOption<
bool>(OPT_assert_debug))
174 script <<
" -lint -check_synthesis -fsmsingle -fsmverbose w";
176 script <<
" -work work -2008 " <<
file << std::endl;
178 else if(extension ==
".v" || extension ==
".V" || extension ==
".sv" || extension ==
".SV")
180 script <<
MODELSIM_VLOG <<
" " << vflags <<
" " << MODELSIM_OPTIMIZER_FLAGS_DEF <<
" -sv";
181 if(
Param->isOption(OPT_assert_debug) &&
Param->getOption<
bool>(OPT_assert_debug))
183 script <<
" -lint -fsmsingle -hazards -pedanticerrors -fsmverbose w";
185 script <<
" -work work " <<
file << std::endl;
187 else if(extension ==
".c" || extension ==
".cpp")
189 script <<
MODELSIM_VLOG <<
" " << MODELSIM_OPTIMIZER_FLAGS_DEF <<
" -sv -ccflags \"" << beh_cflags
190 <<
"\" -work work " <<
file << std::endl;
196 script <<
"if [ $? -ne 0 ]; then exit 1; fi" << std::endl << std::endl;
199 std::string sim_cmd =
MODELSIM_VSIM +
" " + vflags +
" -noautoldlibpath";
200 if(
Param->isOption(OPT_assert_debug) &&
Param->getOption<
bool>(OPT_assert_debug))
202 sim_cmd +=
" -pedanticerrors -assertdebug";
203 MODELSIM_OPTIMIZER_FLAGS_DEF =
"+acc -hazards " + MODELSIM_OPTIMIZER_FLAGS_DEF;
206 if(!MODELSIM_OPTIMIZER_FLAGS_DEF.empty())
208 sim_cmd +=
" -voptargs=\"" + MODELSIM_OPTIMIZER_FLAGS_DEF +
"\"";
210 sim_cmd +=
" -do \"set StdArithNoWarnings 1; set StdNumNoWarnings 1; set NumericStdNoWarnings 1; onerror {quit -f " 211 "-code 1;}; run -all; exit -f;\" work.clocked_bambu_testbench 2>&1 | tee " +
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
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
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
redefinition of set to manage ordered/unordered structures
utility function used to read files.
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.
This file collects some utility functions and macros.
modelsimWrapper(const ParameterConstRef &Param, const std::string &suffix, const std::string &top_fname, const std::string &inc_dirs)
Constructor.
#define OUTPUT_LEVEL_VERY_PEDANTIC
verbose debugging print is performed.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
this class is used to manage the command-line or XML options.
~modelsimWrapper() override
Destructor.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
void Clean() const override
Remove files created during simulation.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...