46 #include <boost/regex.hpp>
61 using namespace ProGe;
89 const std::string& dstDir,
90 const std::string& progeOutDir,
91 const std::string& sharedOutDir,
92 const std::string& testBenchDir,
93 const std::string& toplevelEntity =
"tta0",
94 const std::string& simulationRuntime) :
96 progeOutDir_(progeOutDir),
97 sharedOutDir_(sharedOutDir),
98 testBenchDir_(testBenchDir),
104 modsimCompileScriptName_(
"modsim_compile.sh"),
105 ghdlCompileScriptName_(
"ghdl_compile.sh"),
106 iverilogCompileScriptName_(
"iverilog_compile.sh"),
107 modsimSimulateScriptName_(
"modsim_simulate.sh"),
108 ghdlSimulateScriptName_(
"ghdl_simulate.sh"),
109 iverilogSimulateScriptName_(
"iverilog_simulate.sh"),
110 testbenchName_(
"testbench"),
111 toplevelEntity_(toplevelEntity),
114 simulationRuntime_(simulationRuntime){
161 const string coverageOpt =
"+cover=sbcet";
165 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
168 stream <<
"rm -rf " <<
workDir_ << endl;
169 stream <<
"vlib " <<
workDir_ << endl;
170 stream <<
"vmap" << endl;
172 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
173 stream <<
" coverage_opt=\"" << coverageOpt <<
"\"" << endl;
174 stream <<
"fi" << endl;
177 string coverageOptAssign =
" $coverage_opt";
181 " +incdir+verilog +incdir+gcu_ic +incdir+tb");
182 string exitOnFailure =
"|| exit 1";
183 string checkSynthesisFLag = (
language_==
VHDL)?
" -check_synthesis":
"";
186 if (file.find(
"_pkg.") != std::string::npos) {
193 stream, file,
program + coverageOptAssign + checkSynthesisFLag,
200 if (file.find(
"_pkg.") != std::string::npos) {
205 program + checkSynthesisFLag, exitOnFailure);
208 stream, file,
program + coverageOptAssign + checkSynthesisFLag,
216 stream <<
"exit 0" << endl;
232 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
235 stream <<
"rm -rf " <<
workDir_ << endl;
236 stream <<
"mkdir -p work" << endl;
237 stream <<
"rm -rf bus.dump" << endl;
240 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
241 stream <<
" echo \"-c option is not available for ghdl.\"; exit 2;"
243 stream <<
"fi" << endl;
247 string exitOnFailure =
" || exit 1";
258 stream <<
"ghdl -m --workdir=" <<
workDir_
261 stream <<
"exit 0" << endl;
277 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
280 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
281 stream <<
" echo \"-c option is not available for iverilog.\"; exit 2;"
283 stream <<
"fi" << endl;
287 <<
"iverilog -g2001 -D _IVERILOG_ "
289 <<
"-Itb -Iverilog -Igcu_ic ";
309 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
312 stream <<
"master_coverage_db=accumulated_coverage.ucdb" << endl;
313 stream <<
"coverage_db=cov000.ucdb" << endl;
314 stream <<
"res_opt=\"-t $sim_res\"";
316 stream <<
"coverage_opt=\"\"" << endl;
317 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
318 stream <<
" coverage_opt=\"-coverage\"" << endl;
319 stream <<
" do_script=\"" <<
"coverage save -onexit ${coverage_db}; "
320 <<
"run ${runtime} ns; exit" <<
"\"" << endl;
321 stream <<
"else" << endl;
322 stream <<
" do_script=\"" <<
"run ${runtime} ns; exit" <<
"\"" << endl;
323 stream <<
"fi" << endl;
325 stream <<
"vsim " <<
testbenchName_ <<
" $res_opt -c $coverage_opt"
326 <<
" -do \"$do_script\"" << endl;
328 stream <<
"# merge produced code coverage data into master database."
330 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
331 stream <<
" vcover merge $master_coverage_db "
332 <<
"$master_coverage_db $coverage_db > /dev/null 2>&1" << endl;
333 stream <<
"fi" << endl;
349 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
352 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
353 stream <<
" echo \"-c option is not available for ghdl.\"; exit 2;"
355 stream <<
"fi" << endl;
358 <<
" --stop-time=${runtime}ns" << endl
360 <<
" # Newer GHDL versions does not produce binary." << endl
362 <<
" --stop-time=${runtime}ns --ieee-asserts=disable-at-0" << endl
380 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
383 stream <<
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
384 stream <<
" echo \"-c option is not available for iverilog.\"; exit 2;"
386 stream <<
"fi" << endl;
389 <<
" --assert-level=none --stop-time="
390 <<
"${runtime}" <<
"ns"
407 string errorMsg =
"Unable to create file " + fileName;
420 stream <<
"#!/bin/bash" << endl;
421 stream <<
"# This script was automatically generated." << endl << endl;
426 separator +
"tb" + separator +
"compile.sh.tmpl";
428 std::ifstream scriptTmplIn(scriptTmpl.c_str());
429 stream << scriptTmplIn.rdbuf();
443 stream <<
"#!/bin/bash" << endl;
444 stream <<
"# This script was automatically generated." << endl << endl;
450 separator +
"tb" + separator +
"simulate.sh.tmpl";
452 std::ifstream scriptTmplIn(scriptTmpl.c_str());
453 stream << scriptTmplIn.rdbuf();
470 std::ostream& stream,
471 const std::list<std::string>& files,
472 const std::string& cmdPrefix,
473 const std::string& cmdPostfix) {
475 list<string>::const_iterator iter = files.begin();
476 while (iter != files.end()) {
494 std::ostream& stream,
495 const std::string& file,
496 const std::string& cmdPrefix,
497 const std::string& cmdPostfix) {
499 stream << cmdPrefix <<
" " << file <<
" " << cmdPostfix << endl;
516 const std::string& perlre,
517 const unsigned int& matchRegion,
518 const std::string& fileName,
519 std::list<std::string>& found) {
521 const int LINESIZE = 1000;
523 const boost::regex re(perlre,
524 boost::regex::perl|boost::regex::icase);
527 string::const_iterator begin;
528 string::const_iterator end;
530 std::ifstream ifs( fileName.c_str() , std::ifstream::in );
531 boost::match_results<string::const_iterator> matches;
534 ifs.getline(line, LINESIZE-1);
535 stemp = string(line);
537 begin = stemp.begin();
540 if (boost::regex_search(begin, end, matches, re)) {
541 found.push_back(
string(matches[matchRegion].first,
542 matches[matchRegion].second));
562 std::list<std::string>& toSort,
563 std::list<std::string>& acSort) {
565 typedef std::list<std::string>::iterator listStrIt;
567 listStrIt itAc1 = acSort.begin();
568 listStrIt itTo = toSort.begin();
571 while (itAc1 != acSort.end()) {
573 bool swapped =
false;
575 while (itTo2 != toSort.end()) {
607 std::list<std::string>& toSort,
608 std::list<std::string>& acSort) {
609 typedef std::list<std::string>::iterator listStrIt;
610 typedef std::list<std::string>::reverse_iterator rlistStrIt;
612 listStrIt itAc1 = acSort.begin();
613 rlistStrIt itTo = toSort.rbegin();
616 while (itAc1 != acSort.end()) {
618 bool swapped =
false;
620 while (itTo2 != toSort.rend()) {
646 std::set<string> uniqueFiles;
651 string hdbFile = fuLoc.
hdbFile();
658 if (uniqueFiles.find(file) == uniqueFiles.end()) {
659 order.push_back(file);
660 uniqueFiles.insert(file);
668 string hdbFile = rfLoc.
hdbFile();
675 if (uniqueFiles.find(file) == uniqueFiles.end()) {
676 order.push_back(file);
677 uniqueFiles.insert(file);
694 std::list<std::string>& tlist,
695 const std::string& prefix,
699 if (end == -1 || end >=
static_cast<int>(tlist.size())) {
700 end = tlist.size() - 1;
703 list<string>::iterator itl = tlist.begin();
704 for (
int c = 0; c <= end; ++c, ++itl) {
706 *itl = prefix + *itl;
723 bool absolutePaths =
false;
740 std::string sharedDir =
775 auto packageComp = [](
const string& str1,
const string& str2) ->
bool {
776 bool str1IsPkg = (str1.find(
"_pkg") != string::npos);
777 bool str2IsPkg = (str2.find(
"_pkg") != string::npos);
778 if (str1IsPkg && !str2IsPkg) {
780 }
else if (!str1IsPkg && str2IsPkg) {
801 list<string> gcuicFirstOrder;
802 gcuicFirstOrder.push_back(
"gcu_opcodes_pkg.vhdl");
806 list<string> gcuicLastOrder;
807 gcuicLastOrder.push_back(
"ic.vhdl");
812 list<string> vhdlFirstOrder;
813 vhdlFirstOrder.push_back(
"tce_util_pkg.vhdl");
822 list<string> vhdlLastOrder;
824 vhdlLastOrder.push_back(toplevelFile);
829 list<string> testBenchLastOrder;
830 testBenchLastOrder.push_back(
"testbench_cfg.vhdl");
831 testBenchLastOrder.push_back(
"testbench.vhdl");
832 testBenchLastOrder.push_back(
"proc_arch.vhdl");
833 testBenchLastOrder.push_back(
"proc_ent.vhdl");
840 list<string>::iterator itl;