OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ProGeScriptGenerator Class Reference

#include <ProGeScriptGenerator.hh>

Collaboration diagram for ProGeScriptGenerator:
Collaboration graph

Public Member Functions

 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")
 
virtual ~ProGeScriptGenerator ()
 
void generateAll ()
 
void generateModsimCompile ()
 
void generateGhdlCompile (std::string scriptName, std::string tbName, std::vector< std::list< std::string > > filesToCompile, bool clearWorkingDir)
 
void generatePlatformGhdlCompile ()
 
void generateIverilogCompile ()
 
void generateModsimSimulate ()
 
void generateGhdlSimulate ()
 
void generatePlatformGhdlSimulate ()
 
void generateIverilogSimulate ()
 

Private Member Functions

void generateCompileStart (std::ostream &stream)
 
void generateSimulationStart (std::ostream &stream)
 
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)
 
void outputScriptCommand (std::ostream &stream, const std::string &file, const std::string &cmdPrefix, const std::string &cmdPostfix)
 
template<typename T >
void findFiles (const std::string &perlre, T files, std::list< std::string > &found)
 
template<typename T >
void findFiles (const std::string &perlre, T &files)
 
void findText (const std::string &perlre, const unsigned int &matchRegion, const std::string &fileName, std::list< std::string > &found)
 
void getBlockOrder (std::list< std::string > &order)
 
void sortFilesFirst (std::list< std::string > &toSort, std::list< std::string > &acSort)
 
void sortFilesLast (std::list< std::string > &toSort, std::list< std::string > &acSort)
 
template<typename CONT >
void uniqueFileNames (CONT &files, const std::string &rootDirectory)
 
void prefixStrings (std::list< std::string > &tlist, const std::string &prefix, int start=0, int end=-1)
 
void fetchFiles ()
 
void packageFilesFirst ()
 
void prepareFiles ()
 

Private Attributes

std::string dstDir_
 
std::string progeOutDir_
 
std::string sharedOutDir_
 
std::string testBenchDir_
 
std::list< std::string > vhdlFiles_
 
std::list< std::string > gcuicFiles_
 
std::list< std::string > testBenchFiles_
 
std::list< std::string > platformFiles_
 
const std::string workDir_
 
const std::string vhdlDir_
 
const std::string verDir_
 
const std::string gcuicDir_
 
const std::string tbDir_
 
const std::string platformDir_
 
const std::string modsimCompileScriptName_
 
const std::string ghdlCompileScriptName_
 
const std::string iverilogCompileScriptName_
 
const std::string modsimSimulateScriptName_
 
const std::string ghdlSimulateScriptName_
 
const std::string iverilogSimulateScriptName_
 
const std::string ghdlPlatformCompileScriptName_
 
const std::string testbenchName_
 
const std::string platformTestbenchName_
 
const std::string toplevelEntity_
 
const IDF::MachineImplementationidf_
 
const ProGe::HDL language_
 
const std::string simulationRuntime_
 

Detailed Description

Class for script generating objects.

Base class for script generating. simulationRuntime defaults to 52390ns, can be changed in generateprocessor with a command line parameter, but not in ProDe yet. TODO.

Definition at line 52 of file ProGeScriptGenerator.hh.

Constructor & Destructor Documentation

◆ ProGeScriptGenerator()

ProGeScriptGenerator::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 = "tta0",
const std::string &  simulationRuntime = "52390" 
)

The constructor.

Script generating needs a IDF file and hdb files mentioned there. Working directory is assumed to be the destination directory for script files.

Parameters
dstDirDirectory where to generate scripts.
progeOutDirDirectory where ProGes output vhdl files lie.
testBenchDirDirectory where a test bench files are located.
projectRootDirectory that is project root, needed if relative dirs wanted to generated scripts. Useful if other dirs given are under this directory.

Definition at line 86 of file ProGeScriptGenerator.cc.

92 : dstDir_(dstDir),
93 progeOutDir_(progeOutDir),
94 sharedOutDir_(sharedOutDir),
95 testBenchDir_(testBenchDir),
96 workDir_("work"),
97 vhdlDir_("vhdl"),
98 verDir_("verilog"),
99 gcuicDir_("gcu_ic"),
100 tbDir_("tb"),
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),
112 idf_(idf),
113 language_(language),
114 simulationRuntime_(simulationRuntime) {
115 fetchFiles();
117 prepareFiles();
118}
const std::string modsimSimulateScriptName_
const IDF::MachineImplementation & idf_
const std::string ghdlPlatformCompileScriptName_
const std::string iverilogSimulateScriptName_
const std::string toplevelEntity_
const std::string ghdlCompileScriptName_
const std::string modsimCompileScriptName_
const std::string simulationRuntime_
const std::string platformDir_
const std::string ghdlSimulateScriptName_
const std::string testbenchName_
const std::string iverilogCompileScriptName_
const std::string platformTestbenchName_

References fetchFiles(), packageFilesFirst(), and prepareFiles().

Here is the call graph for this function:

◆ ~ProGeScriptGenerator()

ProGeScriptGenerator::~ProGeScriptGenerator ( )
virtual

The destructor.

Definition at line 123 of file ProGeScriptGenerator.cc.

123 {
124
125}

Member Function Documentation

◆ createExecutableFile()

void ProGeScriptGenerator::createExecutableFile ( const std::string &  fileName)
private

Creates a script file given as parameter and sets permissions.

Parameters
Nameof the script file to be created
Exceptions
IOException

Definition at line 416 of file ProGeScriptGenerator.cc.

416 {
418 bool isCreated = FileSystem::createFile(fileName);
419 if (!isCreated) {
420 string errorMsg = "Unable to create file " + fileName;
421 throw IOException(__FILE__, __LINE__, __func__, errorMsg);
422 }
424}
#define __func__
static bool createFile(const std::string &file)
static bool removeFileOrDirectory(const std::string &path)
static bool setFileExecutable(const std::string fileName)

References __func__, FileSystem::createFile(), FileSystem::removeFileOrDirectory(), and FileSystem::setFileExecutable().

Referenced by generateGhdlCompile(), generateGhdlSimulate(), generateIverilogCompile(), generateIverilogSimulate(), generateModsimCompile(), and generateModsimSimulate().

Here is the call graph for this function:

◆ fetchFiles()

void ProGeScriptGenerator::fetchFiles ( )
private

Gets file names from project directory.

Definition at line 729 of file ProGeScriptGenerator.cc.

729 {
730
731 // files that match are accepted
732 string vhdlRegex =
733 ((language_==VHDL)?".*\\.(vhd|vhdl|pkg)$":".*\\.(v)$");
734
735 // generate relative paths
736 bool absolutePaths = false;
737
738 // getting files from project dir
741 if (FileSystem::fileIsDirectory(dirName)) {
742 findFiles(vhdlRegex,
743 FileSystem::directoryContents(dirName, absolutePaths),
744 vhdlFiles_);
745 // add the toplevelEntity + _imem_mau_pkg.vhdl to vhdlFiles_.
746 // It is generated by PIG so it is not yet present.
747 if(language_==VHDL){
748 string imemMauPkg = dirName + FileSystem::DIRECTORY_SEPARATOR
749 + toplevelEntity_ + "_imem_mau_pkg.vhdl";
750 vhdlFiles_.push_back(imemMauPkg);
751 }
752 }
754
755 std::string sharedDir =
758
759 if (sharedDir != FileSystem::absolutePathOf(dirName)
760 && FileSystem::fileIsDirectory(sharedDir)) {
761 findFiles(
762 vhdlRegex,
763 FileSystem::directoryContents(sharedDir, absolutePaths),
764 vhdlFiles_);
765 }
766
768 if (FileSystem::fileIsDirectory(dirName)) {
769 findFiles(vhdlRegex,
770 FileSystem::directoryContents(dirName, absolutePaths),
772 }
773
777 } else {
778 findFiles(vhdlRegex,
781 }
782
783 dirName = progeOutDir_ + DS + platformDir_;
784 if (FileSystem::fileIsDirectory(dirName)) {
785 findFiles(
786 vhdlRegex, FileSystem::directoryContents(dirName, absolutePaths),
788 }
789}
#define DS
static std::string absolutePathOf(const std::string &pathName)
static const std::string DIRECTORY_SEPARATOR
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
static bool fileIsDirectory(const std::string fileName)
static bool findFromDirectoryRecursive(const std::string &regex, const std::string &directory, STLCONT &found)
void findFiles(const std::string &perlre, T files, std::list< std::string > &found)
std::list< std::string > gcuicFiles_
std::list< std::string > testBenchFiles_
std::list< std::string > vhdlFiles_
std::list< std::string > platformFiles_
@ VHDL
VHDL.
Definition ProGeTypes.hh:41

References FileSystem::absolutePathOf(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::directoryContents(), DS, dstDir_, FileSystem::fileIsDirectory(), findFiles(), FileSystem::findFromDirectoryRecursive(), gcuicDir_, gcuicFiles_, language_, platformDir_, platformFiles_, progeOutDir_, sharedOutDir_, testBenchDir_, testBenchFiles_, toplevelEntity_, verDir_, ProGe::VHDL, vhdlDir_, and vhdlFiles_.

Referenced by ProGeScriptGenerator().

Here is the call graph for this function:

◆ findFiles() [1/2]

template<typename T >
void ProGeScriptGenerator::findFiles ( const std::string &  perlre,
T &  files 
)
private

◆ findFiles() [2/2]

template<typename T >
void ProGeScriptGenerator::findFiles ( const std::string &  perlre,
files,
std::list< std::string > &  found 
)
private

Referenced by fetchFiles().

◆ findText()

void ProGeScriptGenerator::findText ( const std::string &  perlre,
const unsigned int &  matchRegion,
const std::string &  fileName,
std::list< std::string > &  found 
)
private

Regex find from a file.

Finds text matching the given regex from file by line at a time. Case is ignored when interpreting the regex.

Parameters
perlrePerl syntax regular expression.
matchRegionRegion from the match appended to output list.
fileNameName and path of file name to be opened and read.
foundList where matches are appended.

Definition at line 528 of file ProGeScriptGenerator.cc.

532 {
533
534 const int LINESIZE = 1000;
535
536 const boost::regex re(perlre,
537 boost::regex::perl|boost::regex::icase);
538
539 char line[LINESIZE];
540 string::const_iterator begin;
541 string::const_iterator end;
542 string stemp;
543 std::ifstream ifs( fileName.c_str() , std::ifstream::in );
544 boost::match_results<string::const_iterator> matches;
545 while (ifs.good()) {
546
547 ifs.getline(line, LINESIZE-1);
548 stemp = string(line);
549
550 begin = stemp.begin();
551 end = stemp.end();
552
553 if (boost::regex_search(begin, end, matches, re)) {
554 found.push_back(string(matches[matchRegion].first,
555 matches[matchRegion].second));
556 }
557 }
558 ifs.close();
559}

◆ generateAll()

void ProGeScriptGenerator::generateAll ( )

Generates all scripts to destination dir (dstDir_).

Exceptions
IOException

Definition at line 134 of file ProGeScriptGenerator.cc.

134 {
136
137 if (language_ == VHDL) {
141 if (!platformFiles_.empty()) {
144 {platformFiles_}, false);
145 }
146 } else
148
150
151 if(language_==VHDL)
153 else
155}
void generateGhdlCompile(std::string scriptName, std::string tbName, std::vector< std::list< std::string > > filesToCompile, bool clearWorkingDir)

References gcuicFiles_, generateGhdlCompile(), generateGhdlSimulate(), generateIverilogCompile(), generateIverilogSimulate(), generateModsimCompile(), generateModsimSimulate(), ghdlCompileScriptName_, ghdlPlatformCompileScriptName_, language_, platformFiles_, platformTestbenchName_, testBenchFiles_, testbenchName_, ProGe::VHDL, and vhdlFiles_.

Referenced by ProGe::ProGeUI::generateScripts().

Here is the call graph for this function:

◆ generateCompileStart()

void ProGeScriptGenerator::generateCompileStart ( std::ostream &  stream)
private

Generates the start of the shell script for compilation script.

Parameters
streamStream where output is put.

Definition at line 432 of file ProGeScriptGenerator.cc.

432 {
433 stream << "#!/bin/bash" << endl;
434 stream << "# This script was automatically generated." << endl << endl;
435
436 // Copy common compile start from template
437 static const string separator(FileSystem::DIRECTORY_SEPARATOR);
438 const string scriptTmpl = Environment::dataDirPath("ProGe") +
439 separator + "tb" + separator + "compile.sh.tmpl";
440
441 std::ifstream scriptTmplIn(scriptTmpl.c_str());
442 stream << scriptTmplIn.rdbuf();
443}
static std::string dataDirPath(const std::string &prog)

References Environment::dataDirPath(), and FileSystem::DIRECTORY_SEPARATOR.

Referenced by generateGhdlCompile(), generateIverilogCompile(), and generateModsimCompile().

Here is the call graph for this function:

◆ generateGhdlCompile()

void ProGeScriptGenerator::generateGhdlCompile ( std::string  scriptName,
std::string  tbName,
std::vector< std::list< std::string > >  filesToCompile,
bool  clearWorkingDir 
)

Generates a script for compilation using ghdl.

Exceptions
IOException

Definition at line 236 of file ProGeScriptGenerator.cc.

239 {
240 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR + scriptName;
241
242 createExecutableFile(dstFile);
243
244 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
245 generateCompileStart(stream);
246
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;
252 }
253
254 stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
255 stream << " echo \"-c option is not available for ghdl.\"; exit 2;"
256 << endl;
257 stream << "fi" << endl;
258
259 stream << endl;
260 string program = "ghdl -i ${std_version} --workdir=" + workDir_;
261 string exitOnFailure = " || exit 1";
262
263 for (auto& files : filesToCompile) {
264 outputScriptCommands(stream, files, program, exitOnFailure);
265 stream << endl;
266 }
267 // compile command for ghdl
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;
272
273 stream << "exit 0" << endl;
274 stream.close();
275}
find Finds info of the inner loops in the program
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)
void generateCompileStart(std::ostream &stream)

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, generateCompileStart(), outputScriptCommands(), program, and workDir_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generateGhdlSimulate()

void ProGeScriptGenerator::generateGhdlSimulate ( )

Generates a script for simulating using ghdl.

Exceptions
IOException

Definition at line 356 of file ProGeScriptGenerator.cc.

356 {
357 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
359 createExecutableFile(dstFile);
360
361 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
363
364 stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
365 stream << " echo \"-c option is not available for ghdl.\"; exit 2;"
366 << endl;
367 stream << "fi" << endl;
368 stream << "if [ -e ${tb_entity} ]; then" << endl
369 << " ./${tb_entity}"
370 << " --stop-time=${runtime}ns" << endl
371 << "else" << 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
376 << "fi" << endl;
377
378 stream.close();
379}
void generateSimulationStart(std::ostream &stream)

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, generateSimulationStart(), and ghdlSimulateScriptName_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generateIverilogCompile()

void ProGeScriptGenerator::generateIverilogCompile ( )

Generates a script for compilation using iVerilog.

Exceptions
IOException

Definition at line 283 of file ProGeScriptGenerator.cc.

283 {
284 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
286
287 createExecutableFile(dstFile);
288
289 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
290 generateCompileStart(stream);
291
292 stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
293 stream << " echo \"-c option is not available for iverilog.\"; exit 2;"
294 << endl;
295 stream << "fi" << endl;
296
297 stream << "rm -rf " << testbenchName_ << endl
298 << endl
299 << "iverilog -g2001 -D _IVERILOG_ "
300 << "-D SIMTIME=" << simulationRuntime_ << " "
301 << "-Itb -Iverilog -Igcu_ic ";
302 outputScriptCommands(stream, vhdlFiles_, ""," \\");
303 outputScriptCommands(stream, gcuicFiles_, ""," \\");
304 outputScriptCommands(stream, testBenchFiles_, ""," \\");
305
306 stream << "-s " << testbenchName_ << " \\" << endl;
307 stream << "-o " << testbenchName_ << endl;
308 stream.close();
309}

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, gcuicFiles_, generateCompileStart(), iverilogCompileScriptName_, outputScriptCommands(), simulationRuntime_, testBenchFiles_, testbenchName_, and vhdlFiles_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generateIverilogSimulate()

void ProGeScriptGenerator::generateIverilogSimulate ( )

Generates a script for simulating using iVerilog.

Exceptions
IOException

Definition at line 387 of file ProGeScriptGenerator.cc.

387 {
388 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
390
391 createExecutableFile(dstFile);
392
393 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
395
396 stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
397 stream << " echo \"-c option is not available for iverilog.\"; exit 2;"
398 << endl;
399 stream << "fi" << endl;
400
401 stream << "./" << testbenchName_
402 << " --assert-level=none --stop-time="
403 << "${runtime}" << "ns"
404 << endl;
405
406 stream.close();
407}

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, generateSimulationStart(), iverilogSimulateScriptName_, and testbenchName_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generateModsimCompile()

void ProGeScriptGenerator::generateModsimCompile ( )

Generates a script for compilation using modelsim.

Exceptions
IOException

Definition at line 163 of file ProGeScriptGenerator.cc.

163 {
164 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
166 const string coverageOpt = "+cover=sbcet";
167
168 createExecutableFile(dstFile);
169
170 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
171 generateCompileStart(stream);
172
173 stream << "rm -rf " << workDir_ << endl;
174 stream << "vlib " << workDir_ << endl;
175 stream << "vmap" << endl;
176
177 stream << "if [ \"$only_add_files\" = \"yes\" ]; then" << endl;
178 stream << " echo \"-a option is not available for modelsim.\"; exit 2;"
179 << endl;
180 stream << "fi" << endl;
181
182 stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
183 stream << " coverage_opt=\"" << coverageOpt << "\"" << endl;
184 stream << "fi" << endl;
185
186 stream << endl;
187 string coverageOptAssign = " $coverage_opt";
188 string program =
189 ((language_==VHDL)?
190 "vcom": "vlog +define+SIMTIME=" + simulationRuntime_ +
191 " +incdir+verilog +incdir+gcu_ic +incdir+tb");
192 string exitOnFailure = "|| exit 1";
193 string checkSynthesisFLag = (language_==VHDL)?" -check_synthesis":"";
194
195 for (const std::string& file : vhdlFiles_) {
196 if (file.find("_pkg.") != std::string::npos) {
197 // Do not add coverage option for package files since unused
198 // functions in the packages are not excluded and thus spoils
199 // code coverage.
200 outputScriptCommand(stream, file, program, exitOnFailure);
201 } else {
203 stream, file, program + coverageOptAssign + checkSynthesisFLag,
204 exitOnFailure);
205 }
206 }
207
208 stream << endl;
209 for (const std::string& file : gcuicFiles_) {
210 if (file.find("_pkg.") != std::string::npos) {
211 // Do not add coverage option for package files since unused
212 // functions in the packages are not excluded and thus spoils
213 // code coverage.
214 outputScriptCommand(stream, file,
215 program + checkSynthesisFLag, exitOnFailure);
216 } else {
218 stream, file, program + coverageOptAssign + checkSynthesisFLag,
219 exitOnFailure);
220 }
221 }
222
223 stream << endl;
224 outputScriptCommands(stream, testBenchFiles_, program, exitOnFailure);
225
226 stream << "exit 0" << endl;
227 stream.close();
228}
void outputScriptCommand(std::ostream &stream, const std::string &file, const std::string &cmdPrefix, const std::string &cmdPostfix)

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, gcuicFiles_, generateCompileStart(), language_, modsimCompileScriptName_, outputScriptCommand(), outputScriptCommands(), program, simulationRuntime_, testBenchFiles_, ProGe::VHDL, vhdlFiles_, and workDir_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generateModsimSimulate()

void ProGeScriptGenerator::generateModsimSimulate ( )

Generates a script for simulating using modelsims vsim.

Definition at line 315 of file ProGeScriptGenerator.cc.

315 {
316 string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
318
319 createExecutableFile(dstFile);
320
321 std::ofstream stream(dstFile.c_str(), std::ofstream::out);
323
324 stream << "master_coverage_db=accumulated_coverage.ucdb" << endl;
325 stream << "coverage_db=cov000.ucdb" << endl;
326 stream << "res_opt=\"-t $sim_res\"";
327 stream << endl;
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;
336 stream << endl;
337 stream << "vsim " << testbenchName_ << " $res_opt -c $coverage_opt"
338 << " -do \"$do_script\"" << endl;
339 stream << endl;
340 stream << "# merge produced code coverage data into master database."
341 << endl;
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;
346
347 stream.close();
348}

References createExecutableFile(), FileSystem::DIRECTORY_SEPARATOR, dstDir_, generateSimulationStart(), modsimSimulateScriptName_, and testbenchName_.

Referenced by generateAll().

Here is the call graph for this function:

◆ generatePlatformGhdlCompile()

void ProGeScriptGenerator::generatePlatformGhdlCompile ( )

◆ generatePlatformGhdlSimulate()

void ProGeScriptGenerator::generatePlatformGhdlSimulate ( )

◆ generateSimulationStart()

void ProGeScriptGenerator::generateSimulationStart ( std::ostream &  stream)
private

Generates the start of the shell script for simulation script.

The script includes option parsing for simulation controls. Shell variable "runtime" holds default simulation time set by this class or user defined time by option.

Parameters
streamStream where output is put.

Definition at line 455 of file ProGeScriptGenerator.cc.

455 {
456 stream << "#!/bin/bash" << endl;
457 stream << "# This script was automatically generated." << endl << endl;
458 stream << "DEFAULT_RUN_TIME=" << simulationRuntime_ << endl << endl;
459
460 // Copy rest of the shell script start from template
461 static const string separator(FileSystem::DIRECTORY_SEPARATOR);
462 const string scriptTmpl = Environment::dataDirPath("ProGe") +
463 separator + "tb" + separator + "simulate.sh.tmpl";
464
465 std::ifstream scriptTmplIn(scriptTmpl.c_str());
466 stream << scriptTmplIn.rdbuf();
467}

References Environment::dataDirPath(), FileSystem::DIRECTORY_SEPARATOR, and simulationRuntime_.

Referenced by generateGhdlSimulate(), generateIverilogSimulate(), and generateModsimSimulate().

Here is the call graph for this function:

◆ getBlockOrder()

void ProGeScriptGenerator::getBlockOrder ( std::list< std::string > &  order)
private

Gets compilation order for vhdl files from IDF/HDB files.

Parameters
orderList of file names is relative compilation order.

Definition at line 657 of file ProGeScriptGenerator.cc.

657 {
658
659 std::set<string> uniqueFiles;
660
661 // FU implementation HDL files
662 for (int i = 0; i < idf_.fuImplementationCount(); i++) {
664 string hdbFile = fuLoc.hdbFile();
667 HDB::FUEntry* fu = hdb.fuByEntryID(fuLoc.id());
668 const HDB::FUImplementation& fuImpl = fu->implementation();
669 for (int j = 0; j < fuImpl.implementationFileCount(); j++) {
670 string file = FileSystem::fileOfPath(fuImpl.file(j).pathToFile());
671 if (uniqueFiles.find(file) == uniqueFiles.end()) {
672 order.push_back(file);
673 uniqueFiles.insert(file);
674 }
675 }
676 }
677
678 // RF implementation HDL files
679 for (int i = 0; i < idf_.rfImplementationCount(); i++) {
681 string hdbFile = rfLoc.hdbFile();
684 HDB::RFEntry* rf = hdb.rfByEntryID(rfLoc.id());
685 const HDB::RFImplementation& rfImpl = rf->implementation();
686 for (int j = 0; j < rfImpl.implementationFileCount(); j++) {
687 string file = FileSystem::fileOfPath(rfImpl.file(j).pathToFile());
688 if (uniqueFiles.find(file) == uniqueFiles.end()) {
689 order.push_back(file);
690 uniqueFiles.insert(file);
691 }
692 }
693 }
694}
static std::string fileOfPath(const std::string pathName)
FUImplementation & implementation() const
Definition FUEntry.cc:86
FUEntry * fuByEntryID(RowID id) const
RFEntry * rfByEntryID(RowID id) const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
BlockImplementationFile & file(int index) const
RFImplementation & implementation() const
Definition RFEntry.cc:102
RFImplementationLocation & rfImplementation(const std::string &rf) const
FUImplementationLocation & fuImplementation(const std::string &fu) const
UnitImplementationLocation RFImplementationLocation
UnitImplementationLocation FUImplementationLocation

References HDB::HWBlockImplementation::file(), FileSystem::fileOfPath(), HDB::HDBManager::fuByEntryID(), IDF::MachineImplementation::fuImplementation(), IDF::MachineImplementation::fuImplementationCount(), HDB::HDBRegistry::hdb(), IDF::UnitImplementationLocation::hdbFile(), idf_, HDB::FUEntry::implementation(), HDB::RFEntry::implementation(), HDB::HWBlockImplementation::implementationFileCount(), HDB::HDBRegistry::instance(), HDB::BlockImplementationFile::pathToFile(), HDB::HDBManager::rfByEntryID(), IDF::MachineImplementation::rfImplementation(), and IDF::MachineImplementation::rfImplementationCount().

Referenced by prepareFiles().

Here is the call graph for this function:

◆ outputScriptCommand()

void ProGeScriptGenerator::outputScriptCommand ( std::ostream &  stream,
const std::string &  file,
const std::string &  cmdPrefix,
const std::string &  cmdPostfix 
)
private

Outputs shell command to stream.

Creates script commands using a file and command prefix and outputs them to the given stream.

Parameters
streamOutput stream.
filesList of filenames to use.
cmdPrefixPrefix command.
cmdPostfixPostfix command.

Definition at line 506 of file ProGeScriptGenerator.cc.

510 {
511
512 stream << cmdPrefix << " " << file << " " << cmdPostfix << endl;
513}

Referenced by generateModsimCompile(), and outputScriptCommands().

◆ outputScriptCommands()

void ProGeScriptGenerator::outputScriptCommands ( std::ostream &  stream,
const std::list< std::string > &  files,
const std::string &  cmdPrefix,
const std::string &  cmdPostfix 
)
private

Outputs shell commands to stream.

Creates script commands using list of files and command prefix and outputs them to the given stream.

Parameters
streamOutput stream.
filesList of filenames to use.
cmdPrefixPrefix command.
cmdPostfixPrefix command.

Definition at line 482 of file ProGeScriptGenerator.cc.

486 {
487
488 list<string>::const_iterator iter = files.begin();
489 while (iter != files.end()) {
490 outputScriptCommand(stream, *iter++, cmdPrefix, cmdPostfix);
491 }
492}

References outputScriptCommand().

Referenced by generateGhdlCompile(), generateIverilogCompile(), and generateModsimCompile().

Here is the call graph for this function:

◆ packageFilesFirst()

void ProGeScriptGenerator::packageFilesFirst ( )
private

Reorders filename lists by arranging packages (*_pkg*) to the beginning of the lists.

Definition at line 796 of file ProGeScriptGenerator.cc.

796 {
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) {
801 return true;
802 } else if (!str1IsPkg && str2IsPkg) {
803 return false;
804 } else {
805 return str1 < str2;
806 }
807 };
808
809 vhdlFiles_.sort(packageComp);
810 gcuicFiles_.sort(packageComp);
811 testBenchFiles_.sort(packageComp);
812}

References gcuicFiles_, testBenchFiles_, and vhdlFiles_.

Referenced by ProGeScriptGenerator().

◆ prefixStrings()

void ProGeScriptGenerator::prefixStrings ( std::list< std::string > &  tlist,
const std::string &  prefix,
int  start = 0,
int  end = -1 
)
private

Prefixes strings in a container with a string within a range.

Parameters
tlistContainer of strings.
prefixPrefix to be added to strings in container.
startStarting location in a container, 0 is the first.
endEnding location in a container, size-1 is the last.

Definition at line 706 of file ProGeScriptGenerator.cc.

710 {
711
712 if (end == -1 || end >= static_cast<int>(tlist.size())) {
713 end = tlist.size() - 1;
714 }
715
716 list<string>::iterator itl = tlist.begin();
717 for (int c = 0; c <= end; ++c, ++itl) {
718 if (c >= start) {
719 *itl = prefix + *itl;
720 }
721 }
722}

Referenced by prepareFiles().

◆ prepareFiles()

void ProGeScriptGenerator::prepareFiles ( )
private

Prepares filename lists, generally sorts them.

Definition at line 818 of file ProGeScriptGenerator.cc.

818 {
819
820 const string DS = FileSystem::DIRECTORY_SEPARATOR;
821 if(language_==VHDL){
822 string gcuIcDirName = progeOutDir_ + DS + gcuicDir_ + DS;
823 list<string> gcuicFirstOrder;
824 gcuicFirstOrder.push_back("gcu_opcodes_pkg.vhdl");
825 prefixStrings(gcuicFirstOrder, gcuIcDirName);
826 sortFilesFirst(gcuicFiles_, gcuicFirstOrder);
827
828 list<string> gcuicLastOrder;
829 gcuicLastOrder.push_back("ic.vhdl");
830 prefixStrings(gcuicLastOrder, gcuIcDirName);
831 sortFilesLast(gcuicFiles_, gcuicLastOrder);
832
833 string vhdlDirName = progeOutDir_ + DS + vhdlDir_ + DS;
834 list<string> vhdlFirstOrder;
835 vhdlFirstOrder.push_back("tce_util_pkg.vhdl");
836 vhdlFirstOrder.push_back(toplevelEntity_ + "_imem_mau_pkg.vhdl");
837 vhdlFirstOrder.push_back(toplevelEntity_ + "_globals_pkg.vhdl");
838 vhdlFirstOrder.push_back(toplevelEntity_ + "_params_pkg.vhdl");
839 // add FU and RF files in correct order
840 getBlockOrder(vhdlFirstOrder);
841 prefixStrings(vhdlFirstOrder, vhdlDirName);
842 sortFilesFirst(vhdlFiles_, vhdlFirstOrder);
843
844 list<string> vhdlLastOrder;
845 string toplevelFile = toplevelEntity_ + ".vhdl";
846 vhdlLastOrder.push_back(toplevelFile);
847 prefixStrings(vhdlLastOrder, vhdlDirName);
848 sortFilesLast(vhdlFiles_, vhdlLastOrder);
849
850 string tbDirName = progeOutDir_ + DS + tbDir_ + DS;
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");
856 prefixStrings(testBenchLastOrder, tbDirName);
857 sortFilesLast(testBenchFiles_, testBenchLastOrder);
858 } else {
859 //nothing to do here
860 }
861 // make dirs relative to dstDir_
862 list<string>::iterator itl;
863 itl = vhdlFiles_.begin();
864 while (itl != vhdlFiles_.end()) {
866 }
867 itl = gcuicFiles_.begin();
868 while (itl != gcuicFiles_.end()) {
870 }
871 itl = testBenchFiles_.begin();
872 while (itl != testBenchFiles_.end()) {
874 }
875 itl = platformFiles_.begin();
876 while (itl != platformFiles_.end()) {
878 }
879}
static bool relativeDir(const std::string &baseDir, std::string &toRelDir)
void sortFilesFirst(std::list< std::string > &toSort, std::list< std::string > &acSort)
void sortFilesLast(std::list< std::string > &toSort, std::list< std::string > &acSort)
void getBlockOrder(std::list< std::string > &order)
void prefixStrings(std::list< std::string > &tlist, const std::string &prefix, int start=0, int end=-1)

References FileSystem::DIRECTORY_SEPARATOR, DS, dstDir_, gcuicDir_, gcuicFiles_, getBlockOrder(), language_, platformFiles_, prefixStrings(), progeOutDir_, FileSystem::relativeDir(), sortFilesFirst(), sortFilesLast(), tbDir_, testBenchFiles_, toplevelEntity_, ProGe::VHDL, vhdlDir_, and vhdlFiles_.

Referenced by ProGeScriptGenerator().

Here is the call graph for this function:

◆ sortFilesFirst()

void ProGeScriptGenerator::sortFilesFirst ( std::list< std::string > &  toSort,
std::list< std::string > &  acSort 
)
private

Relative file name/path sort using a reference.

Sorts file in one list according to other list,placing in beginning of list, only relative order matters (which entry comes first). Algorithm used does relative sort between two lists, the other is sorted according to the other.

Parameters
toSortList to be sorted.
acSortList where reference order is taken from.

Definition at line 574 of file ProGeScriptGenerator.cc.

576 {
577
578 typedef std::list<std::string>::iterator listStrIt;
579
580 listStrIt itAc1 = acSort.begin();
581 listStrIt itTo = toSort.begin();
582 listStrIt itTo2;
583
584 while (itAc1 != acSort.end()) {
585 // now check list to be sorted
586 bool swapped = false;
587 itTo2 = itTo;
588 while (itTo2 != toSort.end()) {
589 if (FileSystem::compareFileNames(*itTo2, *itAc1, dstDir_)) {
590 // now change itTo2 and itTo places
591 string temp = *itTo;
592 *itTo = *itTo2;
593 *itTo2 = temp;
594 swapped = true;
595 break;
596 }
597 ++itTo2;
598 }
599 if (swapped) {
600 ++itTo;
601 }
602 ++itAc1;
603 }
604}
static bool compareFileNames(const std::string &first, const std::string &second, const std::string &rootDirectory)

References FileSystem::compareFileNames(), and dstDir_.

Referenced by prepareFiles().

Here is the call graph for this function:

◆ sortFilesLast()

void ProGeScriptGenerator::sortFilesLast ( std::list< std::string > &  toSort,
std::list< std::string > &  acSort 
)
private

Relative file name/path sort using a reference.

Sorts file in one list according to other list, placing in end of list, only relative order matters (which entry comes first). Algorithm used does relative sort between two lists, the other is sorted according to the other.

Parameters
toSortList to be sorted.
acSortList where reference order is taken from.

Definition at line 619 of file ProGeScriptGenerator.cc.

621 {
622 typedef std::list<std::string>::iterator listStrIt;
623 typedef std::list<std::string>::reverse_iterator rlistStrIt;
624
625 listStrIt itAc1 = acSort.begin();
626 rlistStrIt itTo = toSort.rbegin();
627 rlistStrIt itTo2;
628
629 while (itAc1 != acSort.end()) {
630 // now check list to be sorted
631 bool swapped = false;
632 itTo2 = itTo;
633 while (itTo2 != toSort.rend()) {
634 if (FileSystem::compareFileNames(*itTo2, *itAc1,dstDir_)) {
635 // now change itTo2 and itTo places
636 string temp = *itTo;
637 *itTo = *itTo2;
638 *itTo2 = temp;
639 swapped = true;
640 break;
641 }
642 ++itTo2;
643 }
644 if (swapped) {
645 ++itTo;
646 }
647 ++itAc1;
648 }
649}

References FileSystem::compareFileNames(), and dstDir_.

Referenced by prepareFiles().

Here is the call graph for this function:

◆ uniqueFileNames()

template<typename CONT >
void ProGeScriptGenerator::uniqueFileNames ( CONT &  files,
const std::string &  rootDirectory 
)
private

Member Data Documentation

◆ dstDir_

std::string ProGeScriptGenerator::dstDir_
private

◆ gcuicDir_

const std::string ProGeScriptGenerator::gcuicDir_
private

Definition at line 152 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles(), and prepareFiles().

◆ gcuicFiles_

std::list<std::string> ProGeScriptGenerator::gcuicFiles_
private

◆ ghdlCompileScriptName_

const std::string ProGeScriptGenerator::ghdlCompileScriptName_
private

Definition at line 158 of file ProGeScriptGenerator.hh.

Referenced by generateAll().

◆ ghdlPlatformCompileScriptName_

const std::string ProGeScriptGenerator::ghdlPlatformCompileScriptName_
private

Definition at line 163 of file ProGeScriptGenerator.hh.

Referenced by generateAll().

◆ ghdlSimulateScriptName_

const std::string ProGeScriptGenerator::ghdlSimulateScriptName_
private

Definition at line 161 of file ProGeScriptGenerator.hh.

Referenced by generateGhdlSimulate().

◆ idf_

const IDF::MachineImplementation& ProGeScriptGenerator::idf_
private

Definition at line 169 of file ProGeScriptGenerator.hh.

Referenced by getBlockOrder().

◆ iverilogCompileScriptName_

const std::string ProGeScriptGenerator::iverilogCompileScriptName_
private

Definition at line 159 of file ProGeScriptGenerator.hh.

Referenced by generateIverilogCompile().

◆ iverilogSimulateScriptName_

const std::string ProGeScriptGenerator::iverilogSimulateScriptName_
private

Definition at line 162 of file ProGeScriptGenerator.hh.

Referenced by generateIverilogSimulate().

◆ language_

const ProGe::HDL ProGeScriptGenerator::language_
private

◆ modsimCompileScriptName_

const std::string ProGeScriptGenerator::modsimCompileScriptName_
private

Definition at line 157 of file ProGeScriptGenerator.hh.

Referenced by generateModsimCompile().

◆ modsimSimulateScriptName_

const std::string ProGeScriptGenerator::modsimSimulateScriptName_
private

Definition at line 160 of file ProGeScriptGenerator.hh.

Referenced by generateModsimSimulate().

◆ platformDir_

const std::string ProGeScriptGenerator::platformDir_
private

Definition at line 154 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles().

◆ platformFiles_

std::list<std::string> ProGeScriptGenerator::platformFiles_
private

Definition at line 146 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles(), generateAll(), and prepareFiles().

◆ platformTestbenchName_

const std::string ProGeScriptGenerator::platformTestbenchName_
private

Definition at line 167 of file ProGeScriptGenerator.hh.

Referenced by generateAll().

◆ progeOutDir_

std::string ProGeScriptGenerator::progeOutDir_
private

Definition at line 136 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles(), and prepareFiles().

◆ sharedOutDir_

std::string ProGeScriptGenerator::sharedOutDir_
private

Definition at line 138 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles().

◆ simulationRuntime_

const std::string ProGeScriptGenerator::simulationRuntime_
private

◆ tbDir_

const std::string ProGeScriptGenerator::tbDir_
private

Definition at line 153 of file ProGeScriptGenerator.hh.

Referenced by prepareFiles().

◆ testBenchDir_

std::string ProGeScriptGenerator::testBenchDir_
private

Definition at line 140 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles().

◆ testBenchFiles_

std::list<std::string> ProGeScriptGenerator::testBenchFiles_
private

◆ testbenchName_

const std::string ProGeScriptGenerator::testbenchName_
private

◆ toplevelEntity_

const std::string ProGeScriptGenerator::toplevelEntity_
private

Definition at line 168 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles(), and prepareFiles().

◆ verDir_

const std::string ProGeScriptGenerator::verDir_
private

Definition at line 151 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles().

◆ vhdlDir_

const std::string ProGeScriptGenerator::vhdlDir_
private

Definition at line 150 of file ProGeScriptGenerator.hh.

Referenced by fetchFiles(), and prepareFiles().

◆ vhdlFiles_

std::list<std::string> ProGeScriptGenerator::vhdlFiles_
private

◆ workDir_

const std::string ProGeScriptGenerator::workDir_
private

Definition at line 149 of file ProGeScriptGenerator.hh.

Referenced by generateGhdlCompile(), and generateModsimCompile().


The documentation for this class was generated from the following files: