OpenASIP 2.2
Loading...
Searching...
No Matches
ProGeScriptGenerator.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ProGeScriptGenerator.cc
26 *
27 * Implementation of ProGeScriptGenerator class.
28 *
29 * @author Esa M��tt� 2007 (esa.maatta-no.spam-tut.fi)
30 * @author Otto Esko 2008 (otto.esko-no.spam-tut.fi)
31 * @author Pekka J��skel�inen 2011
32 * @author Vinogradov Viacheslav(added Verilog generating) 2012
33 * @note rating: red
34 */
35
36#include <iostream>
37#include <vector>
38#include <list>
39#include <string>
40#include <fstream>
41#include <algorithm>
42#include <utility>
43
44#include "CompilerWarnings.hh"
45IGNORE_CLANG_WARNING("-Wkeyword-macro")
46#include <boost/regex.hpp>
48
50#include "HDBManager.hh"
51#include "CachedHDBManager.hh"
52#include "HDBRegistry.hh"
53#include "FileSystem.hh"
56#include "FUEntry.hh"
57#include "FUImplementation.hh"
58#include "RFEntry.hh"
59#include "RFImplementation.hh"
60
61using namespace ProGe;
62
66using std::string;
67using std::endl;
68using std::list;
69
70// Default HDL simulation length unless another is given
71const string MAGICAL_RUNTIME_CONSTANT = "52390";
72
73/**
74 * The constructor.
75 *
76 * Script generating needs a IDF file and hdb files mentioned there. Working
77 * directory is assumed to be the destination directory for script files.
78 *
79 * @param dstDir Directory where to generate scripts.
80 * @param progeOutDir Directory where ProGes output vhdl files lie.
81 * @param testBenchDir Directory where a test bench files are located.
82 * @param projectRoot Directory that is project root, needed if relative dirs
83 * wanted to generated scripts. Useful if other dirs given are under this
84 * directory.
85 */
87 const ProGe::HDL language, const IDF::MachineImplementation& idf,
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)
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}
119
120/**
121 * The destructor.
122 */
126
127
128/**
129 * Generates all scripts to destination dir (dstDir_).
130 *
131 * @exception IOException
132 */
133void
156
157/**
158 * Generates a script for compilation using modelsim.
159 *
160 * @exception IOException
161 */
162void
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}
229
230/**
231 * Generates a script for compilation using ghdl.
232 *
233 * @exception IOException
234 */
235void
237 std::string scriptName, std::string tbName,
238 std::vector<std::list<std::string>> filesToCompile,
239 bool clearWorkingDir) {
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}
276
277/**
278 * Generates a script for compilation using iVerilog.
279 *
280 * @exception IOException
281 */
282void
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}
310
311/**
312 * Generates a script for simulating using modelsims vsim.
313 */
314void
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}
349
350/**
351 * Generates a script for simulating using ghdl.
352 *
353 * @exception IOException
354 */
355void
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}
380
381/**
382 * Generates a script for simulating using iVerilog.
383 *
384 * @exception IOException
385 */
386void
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}
408
409/**
410 * Creates a script file given as parameter and sets permissions.
411 *
412 * @param Name of the script file to be created
413 * @exception IOException
414 */
415void
416ProGeScriptGenerator::createExecutableFile(const std::string& fileName) {
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}
425
426/**
427 * Generates the start of the shell script for compilation script.
428 *
429 * @param stream Stream where output is put.
430 */
431void
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}
444
445/**
446 * Generates the start of the shell script for simulation script.
447 *
448 * The script includes option parsing for simulation controls.
449 * Shell variable \"runtime\" holds default simulation time set by this class
450 * or user defined time by option.
451 *
452 * @param stream Stream where output is put.
453 */
454void
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}
468
469
470/**
471 * Outputs shell commands to stream.
472 *
473 * Creates script commands using list of files and command prefix and outputs
474 * them to the given stream.
475 *
476 * @param stream Output stream.
477 * @param files List of filenames to use.
478 * @param cmdPrefix Prefix command.
479 * @param cmdPostfix Prefix command.
480 */
481void
483 std::ostream& stream,
484 const std::list<std::string>& files,
485 const std::string& cmdPrefix,
486 const std::string& cmdPostfix) {
487
488 list<string>::const_iterator iter = files.begin();
489 while (iter != files.end()) {
490 outputScriptCommand(stream, *iter++, cmdPrefix, cmdPostfix);
491 }
492}
493
494/**
495 * Outputs shell command to stream.
496 *
497 * Creates script commands using a file and command prefix and outputs
498 * them to the given stream.
499 *
500 * @param stream Output stream.
501 * @param files List of filenames to use.
502 * @param cmdPrefix Prefix command.
503 * @param cmdPostfix Postfix command.
504 */
505void
507 std::ostream& stream,
508 const std::string& file,
509 const std::string& cmdPrefix,
510 const std::string& cmdPostfix) {
511
512 stream << cmdPrefix << " " << file << " " << cmdPostfix << endl;
513}
514
515
516/**
517 * Regex find from a file.
518 *
519 * Finds text matching the given regex from file by line at a time.
520 * Case is ignored when interpreting the regex.
521 *
522 * @param perlre Perl syntax regular expression.
523 * @param matchRegion Region from the match appended to output list.
524 * @param fileName Name and path of file name to be opened and read.
525 * @param found List where matches are appended.
526 */
527void
529 const std::string& perlre,
530 const unsigned int& matchRegion,
531 const std::string& fileName,
532 std::list<std::string>& found) {
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}
560
561
562/**
563 * Relative file name/path sort using a reference.
564 *
565 * Sorts file in one list according to other list,placing in beginning of
566 * list, only relative order matters (which entry comes first). Algorithm
567 * used does relative sort between two lists, the other is sorted according
568 * to the other.
569 *
570 * @param toSort List to be sorted.
571 * @param acSort List where reference order is taken from.
572 */
573void
575 std::list<std::string>& toSort,
576 std::list<std::string>& acSort) {
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}
605
606
607/**
608 * Relative file name/path sort using a reference.
609 *
610 * Sorts file in one list according to other list, placing in end of list,
611 * only relative order matters (which entry comes first). Algorithm used
612 * does relative sort between two lists, the other is sorted according to
613 * the other.
614 *
615 * @param toSort List to be sorted.
616 * @param acSort List where reference order is taken from.
617 */
618void
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;
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}
650
651/**
652 * Gets compilation order for vhdl files from IDF/HDB files.
653 *
654 * @param order List of file names is relative compilation order.
655 */
656void
657ProGeScriptGenerator::getBlockOrder(std::list<std::string>& order) {
658
659 std::set<string> uniqueFiles;
660
661 // FU implementation HDL files
662 for (int i = 0; i < idf_.fuImplementationCount(); i++) {
663 const FUImplementationLocation& fuLoc = idf_.fuImplementation(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++) {
680 const RFImplementationLocation& rfLoc = idf_.rfImplementation(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}
695
696
697/**
698 * Prefixes strings in a container with a string within a range.
699 *
700 * @param tlist Container of strings.
701 * @param prefix Prefix to be added to strings in container.
702 * @param start Starting location in a container, 0 is the first.
703 * @param end Ending location in a container, size-1 is the last.
704 */
705void
707 std::list<std::string>& tlist,
708 const std::string& prefix,
709 int start,
710 int end) {
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}
723
724
725/**
726 * Gets file names from project directory.
727 */
728void
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}
790
791/**
792 * Reorders filename lists by arranging packages (*_pkg*) to the beginning of
793 * the lists.
794 */
795void
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}
813
814/**
815 * Prepares filename lists, generally sorts them.
816 */
817void
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}
#define __func__
#define POP_CLANG_DIAGS
#define IGNORE_CLANG_WARNING(X)
find Finds info of the inner loops in the program
#define DS
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 &regex, const std::string &directory, STLCONT &found)
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
void findFiles(const std::string &perlre, T files, std::list< std::string > &found)
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 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)
std::list< std::string > vhdlFiles_
void generateSimulationStart(std::ostream &stream)
const std::string ghdlCompileScriptName_
const std::string modsimCompileScriptName_
const std::string simulationRuntime_
const std::string platformDir_
const std::string ghdlSimulateScriptName_
void prefixStrings(std::list< std::string > &tlist, const std::string &prefix, int start=0, int end=-1)
std::list< std::string > platformFiles_
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")
const std::string iverilogCompileScriptName_
const std::string platformTestbenchName_
Definition FUGen.hh:54
HDL
HDLs supported by ProGe.
Definition ProGeTypes.hh:40
@ VHDL
VHDL.
Definition ProGeTypes.hh:41