46#include <boost/regex.hpp> 
   88    const std::string& dstDir, 
const std::string& progeOutDir,
 
   89    const std::string& sharedOutDir, 
const std::string& testBenchDir,
 
   90    const std::string& toplevelEntity = 
"tta0",
 
   91    const std::string& simulationRuntime)
 
   93      progeOutDir_(progeOutDir),
 
   94      sharedOutDir_(sharedOutDir),
 
   95      testBenchDir_(testBenchDir),
 
  101      platformDir_(
"platform"),
 
  102      modsimCompileScriptName_(
"modsim_compile.sh"),
 
  103      ghdlCompileScriptName_(
"ghdl_compile.sh"),
 
  104      iverilogCompileScriptName_(
"iverilog_compile.sh"),
 
  105      modsimSimulateScriptName_(
"modsim_simulate.sh"),
 
  106      ghdlSimulateScriptName_(
"ghdl_simulate.sh"),
 
  107      iverilogSimulateScriptName_(
"iverilog_simulate.sh"),
 
  108      ghdlPlatformCompileScriptName_(
"ghdl_platform_compile.sh"),
 
  109      testbenchName_(
"testbench"),
 
  110      platformTestbenchName_(
"tta_almaif_tb"),
 
  111      toplevelEntity_(toplevelEntity),
 
  114      simulationRuntime_(simulationRuntime) {
 
 
  166    const string coverageOpt = 
"+cover=sbcet";
 
  170    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  173    stream << 
"rm -rf " << 
workDir_ << endl;
 
  174    stream << 
"vlib " << 
workDir_ << endl;
 
  175    stream << 
"vmap"  << endl;
 
  177    stream << 
"if [ \"$only_add_files\" = \"yes\" ]; then" << endl;
 
  178    stream << 
"    echo \"-a option is not available for modelsim.\"; exit 2;" 
  180    stream << 
"fi" << endl;
 
  182    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  183    stream << 
"    coverage_opt=\"" << coverageOpt << 
"\"" << endl;
 
  184    stream << 
"fi" << endl;
 
  187    string coverageOptAssign = 
" $coverage_opt";
 
  191        " +incdir+verilog +incdir+gcu_ic +incdir+tb");
 
  192    string exitOnFailure = 
"|| exit 1";
 
  193    string checkSynthesisFLag = (
language_==
VHDL)?
" -check_synthesis":
"";
 
  196        if (file.find(
"_pkg.") != std::string::npos) {
 
  203                stream, file, 
program + coverageOptAssign + checkSynthesisFLag,
 
  210        if (file.find(
"_pkg.") != std::string::npos) {
 
  215                program + checkSynthesisFLag, exitOnFailure);
 
  218                stream, file, 
program + coverageOptAssign + checkSynthesisFLag,
 
  226    stream << 
"exit 0" << endl;
 
 
  237    std::string scriptName, std::string tbName,
 
  238    std::vector<std::list<std::string>> filesToCompile,
 
  239    bool clearWorkingDir) {
 
  244    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  247    if (clearWorkingDir) {
 
  248        stream << 
"rm -rf " << 
workDir_ << endl;
 
  249        stream << 
"mkdir -p work" << endl;
 
  250        stream << 
"rm -rf bus.dump" << endl;
 
  251        stream << 
"rm -rf " << tbName << endl;
 
  254    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  255    stream << 
"    echo \"-c option is not available for ghdl.\"; exit 2;" 
  257    stream << 
"fi" << endl;
 
  261    string exitOnFailure = 
" || exit 1";
 
  263    for (
auto& files : filesToCompile) {
 
  268    stream << 
"if [ \"$only_add_files\" = \"no\" ]; then" << endl;
 
  269    stream << 
"    ghdl -m ${std_version} -Wno-hide --workdir=" << 
workDir_ 
  270           << 
" --ieee=synopsys -fexplicit " << tbName << endl;
 
  271    stream << 
"fi" << endl;
 
  273    stream << 
"exit 0" << endl;
 
 
  289    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  292    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  293    stream << 
"    echo \"-c option is not available for iverilog.\"; exit 2;" 
  295    stream << 
"fi" << endl;
 
  299           << 
"iverilog -g2001 -D _IVERILOG_ " 
  301           << 
"-Itb -Iverilog -Igcu_ic ";
 
 
  321    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  324    stream << 
"master_coverage_db=accumulated_coverage.ucdb" << endl;
 
  325    stream << 
"coverage_db=cov000.ucdb" << endl;
 
  326    stream << 
"res_opt=\"-t $sim_res\"";
 
  328    stream << 
"coverage_opt=\"\"" << endl;
 
  329    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  330    stream << 
"    coverage_opt=\"-coverage\"" << endl;
 
  331    stream << 
"    do_script=\"" << 
"coverage save -onexit ${coverage_db}; " 
  332           << 
"run ${runtime} ns; exit" << 
"\"" << endl;
 
  333    stream << 
"else" << endl;
 
  334    stream << 
"    do_script=\"" << 
"run ${runtime} ns; exit" << 
"\"" << endl;
 
  335    stream << 
"fi" << endl;
 
  337    stream << 
"vsim " << 
testbenchName_ << 
" $res_opt -c $coverage_opt" 
  338           << 
" -do \"$do_script\"" << endl;
 
  340    stream << 
"# merge produced code coverage data into master database." 
  342    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  343    stream << 
"    vcover merge $master_coverage_db " 
  344           << 
"$master_coverage_db $coverage_db > /dev/null 2>&1" << endl;
 
  345    stream << 
"fi" << endl;
 
 
  361    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  364    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  365    stream << 
"    echo \"-c option is not available for ghdl.\"; exit 2;" 
  367    stream << 
"fi" << endl;
 
  368    stream << 
"if [ -e ${tb_entity} ]; then" << endl
 
  370           << 
" --stop-time=${runtime}ns" << endl
 
  372           << 
"    # Newer GHDL versions does not produce binary." << endl
 
  373           << 
"    ghdl -r ${std_version} --workdir=work --ieee=synopsys " 
  374           << 
"${tb_entity} --stop-time=${runtime}ns " 
  375           << 
"--ieee-asserts=disable-at-0 ${generic_list}" << endl
 
 
  393    std::ofstream stream(dstFile.c_str(), std::ofstream::out);
 
  396    stream << 
"if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
 
  397    stream << 
"    echo \"-c option is not available for iverilog.\"; exit 2;" 
  399    stream << 
"fi" << endl;
 
  402           << 
" --assert-level=none --stop-time=" 
  403           << 
"${runtime}" << 
"ns" 
 
  420        string errorMsg = 
"Unable to create file " + fileName;
 
 
  433    stream << 
"#!/bin/bash" << endl;
 
  434    stream << 
"# This script was automatically generated." << endl << endl;
 
  439        separator + 
"tb" + separator + 
"compile.sh.tmpl";
 
  441    std::ifstream scriptTmplIn(scriptTmpl.c_str());
 
  442    stream << scriptTmplIn.rdbuf();
 
 
  456    stream << 
"#!/bin/bash" << endl;
 
  457    stream << 
"# This script was automatically generated." << endl << endl;
 
  463        separator + 
"tb" + separator + 
"simulate.sh.tmpl";
 
  465    std::ifstream scriptTmplIn(scriptTmpl.c_str());
 
  466    stream << scriptTmplIn.rdbuf();
 
 
  483    std::ostream& stream,
 
  484    const std::list<std::string>& files,
 
  485    const std::string& cmdPrefix,
 
  486    const std::string& cmdPostfix) {
 
  488    list<string>::const_iterator iter = files.begin();
 
  489    while (iter != files.end()) {
 
 
  507    std::ostream& stream,
 
  508    const std::string& file,
 
  509    const std::string& cmdPrefix,
 
  510    const std::string& cmdPostfix) {
 
  512    stream << cmdPrefix << 
" " << file << 
" " << cmdPostfix << endl;
 
 
  529    const std::string& perlre,
 
  530    const unsigned int& matchRegion,
 
  531    const std::string& fileName,
 
  532    std::list<std::string>& found) {
 
  534    const int LINESIZE = 1000;
 
  536    const boost::regex re(perlre, 
 
  537            boost::regex::perl|boost::regex::icase);
 
  540    string::const_iterator begin;
 
  541    string::const_iterator end;
 
  543    std::ifstream ifs( fileName.c_str() , std::ifstream::in );
 
  544    boost::match_results<string::const_iterator> matches;
 
  547        ifs.getline(line, LINESIZE-1);
 
  548        stemp = string(line);
 
  550        begin = stemp.begin();
 
  553        if (boost::regex_search(begin, end, matches, re)) {
 
  554            found.push_back(
string(matches[matchRegion].first, 
 
  555                matches[matchRegion].second));
 
 
  575    std::list<std::string>& toSort,
 
  576    std::list<std::string>& acSort) {
 
  578    typedef std::list<std::string>::iterator listStrIt;
 
  580    listStrIt itAc1 = acSort.begin();
 
  581    listStrIt itTo  = toSort.begin();
 
  584    while (itAc1 != acSort.end()) {
 
  586        bool swapped = 
false;
 
  588        while (itTo2 != toSort.end()) {
 
 
  620    std::list<std::string>& toSort,
 
  621    std::list<std::string>& acSort) {
 
  622    typedef std::list<std::string>::iterator listStrIt;
 
  623    typedef std::list<std::string>::reverse_iterator  rlistStrIt;
 
  625    listStrIt itAc1 = acSort.begin();
 
  626    rlistStrIt itTo    = toSort.rbegin();
 
  629    while (itAc1 != acSort.end()) {
 
  631        bool swapped = 
false;
 
  633        while (itTo2 != toSort.rend()) {
 
 
  659    std::set<string> uniqueFiles;    
 
  664        string hdbFile = fuLoc.
hdbFile();
 
  671            if (uniqueFiles.find(file) == uniqueFiles.end()) {
 
  672                order.push_back(file);
 
  673                uniqueFiles.insert(file);
 
  681        string hdbFile = rfLoc.
hdbFile();
 
  688            if (uniqueFiles.find(file) == uniqueFiles.end()) {
 
  689                order.push_back(file);
 
  690                uniqueFiles.insert(file);
 
 
  707    std::list<std::string>& tlist, 
 
  708    const std::string& prefix,
 
  712    if (end == -1 || end >= 
static_cast<int>(tlist.size())) {
 
  713        end = tlist.size() - 1;
 
  716    list<string>::iterator itl = tlist.begin();
 
  717    for (
int c = 0; c <= end; ++c, ++itl) {
 
  719            *itl = prefix + *itl; 
 
 
  736    bool absolutePaths = 
false;
 
  755    std::string sharedDir = 
 
 
  797    auto packageComp = [](
const string& str1, 
const string& str2) -> 
bool {
 
  798        bool str1IsPkg = (str1.find(
"_pkg") != string::npos);
 
  799        bool str2IsPkg = (str2.find(
"_pkg") != string::npos);
 
  800        if (str1IsPkg && !str2IsPkg) {
 
  802        } 
else if (!str1IsPkg && str2IsPkg) {
 
 
  823        list<string> gcuicFirstOrder;
 
  824        gcuicFirstOrder.push_back(
"gcu_opcodes_pkg.vhdl");
 
  828        list<string> gcuicLastOrder;
 
  829        gcuicLastOrder.push_back(
"ic.vhdl");
 
  834        list<string> vhdlFirstOrder;
 
  835        vhdlFirstOrder.push_back(
"tce_util_pkg.vhdl");
 
  844        list<string> vhdlLastOrder;
 
  846        vhdlLastOrder.push_back(toplevelFile);
 
  851        list<string> testBenchLastOrder;
 
  852        testBenchLastOrder.push_back(
"testbench_cfg.vhdl");
 
  853        testBenchLastOrder.push_back(
"testbench.vhdl");
 
  854        testBenchLastOrder.push_back(
"proc_arch.vhdl");
 
  855        testBenchLastOrder.push_back(
"proc_ent.vhdl");
 
  862    list<string>::iterator itl;
 
 
#define IGNORE_CLANG_WARNING(X)
 
find Finds info of the inner loops in the program
 
const string MAGICAL_RUNTIME_CONSTANT
 
static std::string dataDirPath(const std::string &prog)
 
static bool createFile(const std::string &file)
 
static std::string absolutePathOf(const std::string &pathName)
 
static bool removeFileOrDirectory(const std::string &path)
 
static const std::string DIRECTORY_SEPARATOR
 
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
 
static std::string fileOfPath(const std::string pathName)
 
static bool compareFileNames(const std::string &first, const std::string &second, const std::string &rootDirectory)
 
static bool fileIsDirectory(const std::string fileName)
 
static bool setFileExecutable(const std::string fileName)
 
static bool relativeDir(const std::string &baseDir, std::string &toRelDir)
 
static bool findFromDirectoryRecursive(const std::string ®ex, const std::string &directory, STLCONT &found)
 
std::string pathToFile() const
 
FUImplementation & implementation() const
 
FUEntry * fuByEntryID(RowID id) const
 
RFEntry * rfByEntryID(RowID id) const
 
static HDBRegistry & instance()
 
CachedHDBManager & hdb(const std::string fileName)
 
int implementationFileCount() const
 
BlockImplementationFile & file(int index) const
 
RFImplementation & implementation() const
 
RFImplementationLocation & rfImplementation(const std::string &rf) const
 
FUImplementationLocation & fuImplementation(const std::string &fu) const
 
int fuImplementationCount() const
 
int rfImplementationCount() const
 
virtual std::string hdbFile() const
 
void generateModsimSimulate()
 
void generateGhdlSimulate()
 
void findFiles(const std::string &perlre, T files, std::list< std::string > &found)
 
std::string testBenchDir_
 
std::list< std::string > gcuicFiles_
 
void sortFilesFirst(std::list< std::string > &toSort, std::list< std::string > &acSort)
 
void sortFilesLast(std::list< std::string > &toSort, std::list< std::string > &acSort)
 
std::list< std::string > testBenchFiles_
 
const std::string modsimSimulateScriptName_
 
void createExecutableFile(const std::string &fileName)
 
void outputScriptCommands(std::ostream &stream, const std::list< std::string > &files, const std::string &cmdPrefix, const std::string &cmdPostfix)
 
const std::string vhdlDir_
 
const IDF::MachineImplementation & idf_
 
const std::string ghdlPlatformCompileScriptName_
 
void getBlockOrder(std::list< std::string > &order)
 
void generateCompileStart(std::ostream &stream)
 
const std::string iverilogSimulateScriptName_
 
void findText(const std::string &perlre, const unsigned int &matchRegion, const std::string &fileName, std::list< std::string > &found)
 
const std::string toplevelEntity_
 
void generateGhdlCompile(std::string scriptName, std::string tbName, std::vector< std::list< std::string > > filesToCompile, bool clearWorkingDir)
 
void outputScriptCommand(std::ostream &stream, const std::string &file, const std::string &cmdPrefix, const std::string &cmdPostfix)
 
const std::string verDir_
 
std::list< std::string > vhdlFiles_
 
void generateSimulationStart(std::ostream &stream)
 
const std::string ghdlCompileScriptName_
 
const std::string workDir_
 
const ProGe::HDL language_
 
const std::string modsimCompileScriptName_
 
const std::string simulationRuntime_
 
const std::string platformDir_
 
const std::string ghdlSimulateScriptName_
 
void generateIverilogCompile()
 
void generateModsimCompile()
 
void prefixStrings(std::list< std::string > &tlist, const std::string &prefix, int start=0, int end=-1)
 
void generateIverilogSimulate()
 
std::list< std::string > platformFiles_
 
virtual ~ProGeScriptGenerator()
 
const std::string testbenchName_
 
ProGeScriptGenerator(const ProGe::HDL language, const IDF::MachineImplementation &idf, const std::string &dstDir, const std::string &progeOutDir, const std::string &sharedOutDir, const std::string &testBenchDir, const std::string &toplevelEntity, const std::string &simulationRuntime="52390")
 
std::string sharedOutDir_
 
const std::string iverilogCompileScriptName_
 
const std::string platformTestbenchName_
 
const std::string gcuicDir_
 
HDL
HDLs supported by ProGe.