OpenASIP  2.0
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"
45 IGNORE_CLANG_WARNING("-Wkeyword-macro")
46 #include <boost/regex.hpp>
48 
49 #include "ProGeScriptGenerator.hh"
50 #include "HDBManager.hh"
51 #include "CachedHDBManager.hh"
52 #include "HDBRegistry.hh"
53 #include "FileSystem.hh"
54 #include "MachineImplementation.hh"
56 #include "FUEntry.hh"
57 #include "FUImplementation.hh"
58 #include "RFEntry.hh"
59 #include "RFImplementation.hh"
60 
61 using namespace ProGe;
62 
66 using std::string;
67 using std::endl;
68 using std::list;
69 
70 // Default HDL simulation length unless another is given
71 const 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,
88  const IDF::MachineImplementation& idf,
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) :
95  dstDir_(dstDir),
96  progeOutDir_(progeOutDir),
97  sharedOutDir_(sharedOutDir),
98  testBenchDir_(testBenchDir),
99  workDir_("work"),
100  vhdlDir_("vhdl"),
101  verDir_("verilog"),
102  gcuicDir_("gcu_ic"),
103  tbDir_("tb"),
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),
112  idf_(idf),
113  language_(language),
114  simulationRuntime_(simulationRuntime){
115 
116  fetchFiles();
118  prepareFiles();
119 }
120 
121 
122 /**
123  * The destructor.
124  */
126 
127 }
128 
129 
130 /**
131  * Generates all scripts to destination dir (dstDir_).
132  *
133  * @exception IOException
134  */
135 void
138 
139  if(language_==VHDL)
141  else
143 
145 
146  if(language_==VHDL)
148  else
150 }
151 
152 /**
153  * Generates a script for compilation using modelsim.
154  *
155  * @exception IOException
156  */
157 void
159  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
161  const string coverageOpt = "+cover=sbcet";
162 
163  createExecutableFile(dstFile);
164 
165  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
166  generateCompileStart(stream);
167 
168  stream << "rm -rf " << workDir_ << endl;
169  stream << "vlib " << workDir_ << endl;
170  stream << "vmap" << endl;
171 
172  stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
173  stream << " coverage_opt=\"" << coverageOpt << "\"" << endl;
174  stream << "fi" << endl;
175 
176  stream << endl;
177  string coverageOptAssign = " $coverage_opt";
178  string program =
179  ((language_==VHDL)?
180  "vcom": "vlog +define+SIMTIME=" + simulationRuntime_ +
181  " +incdir+verilog +incdir+gcu_ic +incdir+tb");
182  string exitOnFailure = "|| exit 1";
183  string checkSynthesisFLag = (language_==VHDL)?" -check_synthesis":"";
184 
185  for (const std::string& file : vhdlFiles_) {
186  if (file.find("_pkg.") != std::string::npos) {
187  // Do not add coverage option for package files since unused
188  // functions in the packages are not excluded and thus spoils
189  // code coverage.
190  outputScriptCommand(stream, file, program, exitOnFailure);
191  } else {
193  stream, file, program + coverageOptAssign + checkSynthesisFLag,
194  exitOnFailure);
195  }
196  }
197 
198  stream << endl;
199  for (const std::string& file : gcuicFiles_) {
200  if (file.find("_pkg.") != std::string::npos) {
201  // Do not add coverage option for package files since unused
202  // functions in the packages are not excluded and thus spoils
203  // code coverage.
204  outputScriptCommand(stream, file,
205  program + checkSynthesisFLag, exitOnFailure);
206  } else {
208  stream, file, program + coverageOptAssign + checkSynthesisFLag,
209  exitOnFailure);
210  }
211  }
212 
213  stream << endl;
214  outputScriptCommands(stream, testBenchFiles_, program, exitOnFailure);
215 
216  stream << "exit 0" << endl;
217  stream.close();
218 }
219 
220 /**
221  * Generates a script for compilation using ghdl.
222  *
223  * @exception IOException
224  */
225 void
227  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
229 
230  createExecutableFile(dstFile);
231 
232  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
233  generateCompileStart(stream);
234 
235  stream << "rm -rf " << workDir_ << endl;
236  stream << "mkdir -p work" << endl;
237  stream << "rm -rf bus.dump" << endl;
238  stream << "rm -rf " << testbenchName_ << endl;
239 
240  stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
241  stream << " echo \"-c option is not available for ghdl.\"; exit 2;"
242  << endl;
243  stream << "fi" << endl;
244 
245  stream << endl;
246  string program = "ghdl -i --workdir=" + workDir_;
247  string exitOnFailure = " || exit 1";
248  outputScriptCommands(stream, vhdlFiles_, program, exitOnFailure);
249 
250  stream << endl;
251  outputScriptCommands(stream, gcuicFiles_, program, exitOnFailure);
252 
253  stream << endl;
254  outputScriptCommands(stream, testBenchFiles_, program, exitOnFailure);
255 
256  stream << endl;
257  // compile command for ghdl
258  stream << "ghdl -m --workdir=" << workDir_
259  << " --ieee=synopsys -fexplicit " << testbenchName_ << endl;
260 
261  stream << "exit 0" << endl;
262  stream.close();
263 }
264 
265 /**
266  * Generates a script for compilation using iVerilog.
267  *
268  * @exception IOException
269  */
270 void
272  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
274 
275  createExecutableFile(dstFile);
276 
277  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
278  generateCompileStart(stream);
279 
280  stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
281  stream << " echo \"-c option is not available for iverilog.\"; exit 2;"
282  << endl;
283  stream << "fi" << endl;
284 
285  stream << "rm -rf " << testbenchName_ << endl
286  << endl
287  << "iverilog -g2001 -D _IVERILOG_ "
288  << "-D SIMTIME=" << simulationRuntime_ << " "
289  << "-Itb -Iverilog -Igcu_ic ";
290  outputScriptCommands(stream, vhdlFiles_, ""," \\");
291  outputScriptCommands(stream, gcuicFiles_, ""," \\");
292  outputScriptCommands(stream, testBenchFiles_, ""," \\");
293 
294  stream << "-s " << testbenchName_ << " \\" << endl;
295  stream << "-o " << testbenchName_ << endl;
296  stream.close();
297 }
298 
299 /**
300  * Generates a script for simulating using modelsims vsim.
301  */
302 void
304  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
306 
307  createExecutableFile(dstFile);
308 
309  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
310  generateSimulationStart(stream);
311 
312  stream << "master_coverage_db=accumulated_coverage.ucdb" << endl;
313  stream << "coverage_db=cov000.ucdb" << endl;
314  stream << "res_opt=\"-t $sim_res\"";
315  stream << endl;
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;
324  stream << endl;
325  stream << "vsim " << testbenchName_ << " $res_opt -c $coverage_opt"
326  << " -do \"$do_script\"" << endl;
327  stream << endl;
328  stream << "# merge produced code coverage data into master database."
329  << endl;
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;
334 
335  stream.close();
336 }
337 
338 /**
339  * Generates a script for simulating using ghdl.
340  *
341  * @exception IOException
342  */
343 void
345  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
347  createExecutableFile(dstFile);
348 
349  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
350  generateSimulationStart(stream);
351 
352  stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
353  stream << " echo \"-c option is not available for ghdl.\"; exit 2;"
354  << endl;
355  stream << "fi" << endl;
356  stream << "if [ -e " << testbenchName_ << " ]; then" << endl
357  << " ./" << testbenchName_
358  << " --stop-time=${runtime}ns" << endl
359  << "else" << endl
360  << " # Newer GHDL versions does not produce binary." << endl
361  << " ghdl -r --workdir=work --ieee=synopsys " << testbenchName_
362  << " --stop-time=${runtime}ns --ieee-asserts=disable-at-0" << endl
363  << "fi" << endl;
364 
365  stream.close();
366 }
367 
368 /**
369  * Generates a script for simulating using iVerilog.
370  *
371  * @exception IOException
372  */
373 void
375  string dstFile = dstDir_ + FileSystem::DIRECTORY_SEPARATOR +
377 
378  createExecutableFile(dstFile);
379 
380  std::ofstream stream(dstFile.c_str(), std::ofstream::out);
381  generateSimulationStart(stream);
382 
383  stream << "if [ \"$enable_coverage\" = \"yes\" ]; then" << endl;
384  stream << " echo \"-c option is not available for iverilog.\"; exit 2;"
385  << endl;
386  stream << "fi" << endl;
387 
388  stream << "./" << testbenchName_
389  << " --assert-level=none --stop-time="
390  << "${runtime}" << "ns"
391  << endl;
392 
393  stream.close();
394 }
395 
396 /**
397  * Creates a script file given as parameter and sets permissions.
398  *
399  * @param Name of the script file to be created
400  * @exception IOException
401  */
402 void
403 ProGeScriptGenerator::createExecutableFile(const std::string& fileName) {
405  bool isCreated = FileSystem::createFile(fileName);
406  if (!isCreated) {
407  string errorMsg = "Unable to create file " + fileName;
408  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
409  }
411 }
412 
413 /**
414  * Generates the start of the shell script for compilation script.
415  *
416  * @param stream Stream where output is put.
417  */
418 void
420  stream << "#!/bin/bash" << endl;
421  stream << "# This script was automatically generated." << endl << endl;
422 
423  // Copy common compile start from template
424  static const string separator(FileSystem::DIRECTORY_SEPARATOR);
425  const string scriptTmpl = Environment::dataDirPath("ProGe") +
426  separator + "tb" + separator + "compile.sh.tmpl";
427 
428  std::ifstream scriptTmplIn(scriptTmpl.c_str());
429  stream << scriptTmplIn.rdbuf();
430 }
431 
432 /**
433  * Generates the start of the shell script for simulation script.
434  *
435  * The script includes option parsing for simulation controls.
436  * Shell variable \"runtime\" holds default simulation time set by this class
437  * or user defined time by option.
438  *
439  * @param stream Stream where output is put.
440  */
441 void
443  stream << "#!/bin/bash" << endl;
444  stream << "# This script was automatically generated." << endl << endl;
445  stream << "DEFAULT_RUN_TIME=" << simulationRuntime_ << endl << endl;
446 
447  // Copy rest of the shell script start from template
448  static const string separator(FileSystem::DIRECTORY_SEPARATOR);
449  const string scriptTmpl = Environment::dataDirPath("ProGe") +
450  separator + "tb" + separator + "simulate.sh.tmpl";
451 
452  std::ifstream scriptTmplIn(scriptTmpl.c_str());
453  stream << scriptTmplIn.rdbuf();
454 }
455 
456 
457 /**
458  * Outputs shell commands to stream.
459  *
460  * Creates script commands using list of files and command prefix and outputs
461  * them to the given stream.
462  *
463  * @param stream Output stream.
464  * @param files List of filenames to use.
465  * @param cmdPrefix Prefix command.
466  * @param cmdPostfix Prefix command.
467  */
468 void
470  std::ostream& stream,
471  const std::list<std::string>& files,
472  const std::string& cmdPrefix,
473  const std::string& cmdPostfix) {
474 
475  list<string>::const_iterator iter = files.begin();
476  while (iter != files.end()) {
477  outputScriptCommand(stream, *iter++, cmdPrefix, cmdPostfix);
478  }
479 }
480 
481 /**
482  * Outputs shell command to stream.
483  *
484  * Creates script commands using a file and command prefix and outputs
485  * them to the given stream.
486  *
487  * @param stream Output stream.
488  * @param files List of filenames to use.
489  * @param cmdPrefix Prefix command.
490  * @param cmdPostfix Postfix command.
491  */
492 void
494  std::ostream& stream,
495  const std::string& file,
496  const std::string& cmdPrefix,
497  const std::string& cmdPostfix) {
498 
499  stream << cmdPrefix << " " << file << " " << cmdPostfix << endl;
500 }
501 
502 
503 /**
504  * Regex find from a file.
505  *
506  * Finds text matching the given regex from file by line at a time.
507  * Case is ignored when interpreting the regex.
508  *
509  * @param perlre Perl syntax regular expression.
510  * @param matchRegion Region from the match appended to output list.
511  * @param fileName Name and path of file name to be opened and read.
512  * @param found List where matches are appended.
513  */
514 void
516  const std::string& perlre,
517  const unsigned int& matchRegion,
518  const std::string& fileName,
519  std::list<std::string>& found) {
520 
521  const int LINESIZE = 1000;
522 
523  const boost::regex re(perlre,
524  boost::regex::perl|boost::regex::icase);
525 
526  char line[LINESIZE];
527  string::const_iterator begin;
528  string::const_iterator end;
529  string stemp;
530  std::ifstream ifs( fileName.c_str() , std::ifstream::in );
531  boost::match_results<string::const_iterator> matches;
532  while (ifs.good()) {
533 
534  ifs.getline(line, LINESIZE-1);
535  stemp = string(line);
536 
537  begin = stemp.begin();
538  end = stemp.end();
539 
540  if (boost::regex_search(begin, end, matches, re)) {
541  found.push_back(string(matches[matchRegion].first,
542  matches[matchRegion].second));
543  }
544  }
545  ifs.close();
546 }
547 
548 
549 /**
550  * Relative file name/path sort using a reference.
551  *
552  * Sorts file in one list according to other list,placing in beginning of
553  * list, only relative order matters (which entry comes first). Algorithm
554  * used does relative sort between two lists, the other is sorted according
555  * to the other.
556  *
557  * @param toSort List to be sorted.
558  * @param acSort List where reference order is taken from.
559  */
560 void
562  std::list<std::string>& toSort,
563  std::list<std::string>& acSort) {
564 
565  typedef std::list<std::string>::iterator listStrIt;
566 
567  listStrIt itAc1 = acSort.begin();
568  listStrIt itTo = toSort.begin();
569  listStrIt itTo2;
570 
571  while (itAc1 != acSort.end()) {
572  // now check list to be sorted
573  bool swapped = false;
574  itTo2 = itTo;
575  while (itTo2 != toSort.end()) {
576  if (FileSystem::compareFileNames(*itTo2, *itAc1, dstDir_)) {
577  // now change itTo2 and itTo places
578  string temp = *itTo;
579  *itTo = *itTo2;
580  *itTo2 = temp;
581  swapped = true;
582  break;
583  }
584  ++itTo2;
585  }
586  if (swapped) {
587  ++itTo;
588  }
589  ++itAc1;
590  }
591 }
592 
593 
594 /**
595  * Relative file name/path sort using a reference.
596  *
597  * Sorts file in one list according to other list, placing in end of list,
598  * only relative order matters (which entry comes first). Algorithm used
599  * does relative sort between two lists, the other is sorted according to
600  * the other.
601  *
602  * @param toSort List to be sorted.
603  * @param acSort List where reference order is taken from.
604  */
605 void
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;
611 
612  listStrIt itAc1 = acSort.begin();
613  rlistStrIt itTo = toSort.rbegin();
614  rlistStrIt itTo2;
615 
616  while (itAc1 != acSort.end()) {
617  // now check list to be sorted
618  bool swapped = false;
619  itTo2 = itTo;
620  while (itTo2 != toSort.rend()) {
621  if (FileSystem::compareFileNames(*itTo2, *itAc1,dstDir_)) {
622  // now change itTo2 and itTo places
623  string temp = *itTo;
624  *itTo = *itTo2;
625  *itTo2 = temp;
626  swapped = true;
627  break;
628  }
629  ++itTo2;
630  }
631  if (swapped) {
632  ++itTo;
633  }
634  ++itAc1;
635  }
636 }
637 
638 /**
639  * Gets compilation order for vhdl files from IDF/HDB files.
640  *
641  * @param order List of file names is relative compilation order.
642  */
643 void
644 ProGeScriptGenerator::getBlockOrder(std::list<std::string>& order) {
645 
646  std::set<string> uniqueFiles;
647 
648  // FU implementation HDL files
649  for (int i = 0; i < idf_.fuImplementationCount(); i++) {
651  string hdbFile = fuLoc.hdbFile();
652  HDB::CachedHDBManager& hdb =
653  HDB::HDBRegistry::instance().hdb(hdbFile);
654  HDB::FUEntry* fu = hdb.fuByEntryID(fuLoc.id());
655  const HDB::FUImplementation& fuImpl = fu->implementation();
656  for (int j = 0; j < fuImpl.implementationFileCount(); j++) {
657  string file = FileSystem::fileOfPath(fuImpl.file(j).pathToFile());
658  if (uniqueFiles.find(file) == uniqueFiles.end()) {
659  order.push_back(file);
660  uniqueFiles.insert(file);
661  }
662  }
663  }
664 
665  // RF implementation HDL files
666  for (int i = 0; i < idf_.rfImplementationCount(); i++) {
668  string hdbFile = rfLoc.hdbFile();
669  HDB::CachedHDBManager& hdb =
670  HDB::HDBRegistry::instance().hdb(hdbFile);
671  HDB::RFEntry* rf = hdb.rfByEntryID(rfLoc.id());
672  const HDB::RFImplementation& rfImpl = rf->implementation();
673  for (int j = 0; j < rfImpl.implementationFileCount(); j++) {
674  string file = FileSystem::fileOfPath(rfImpl.file(j).pathToFile());
675  if (uniqueFiles.find(file) == uniqueFiles.end()) {
676  order.push_back(file);
677  uniqueFiles.insert(file);
678  }
679  }
680  }
681 }
682 
683 
684 /**
685  * Prefixes strings in a container with a string within a range.
686  *
687  * @param tlist Container of strings.
688  * @param prefix Prefix to be added to strings in container.
689  * @param start Starting location in a container, 0 is the first.
690  * @param end Ending location in a container, size-1 is the last.
691  */
692 void
694  std::list<std::string>& tlist,
695  const std::string& prefix,
696  int start,
697  int end) {
698 
699  if (end == -1 || end >= static_cast<int>(tlist.size())) {
700  end = tlist.size() - 1;
701  }
702 
703  list<string>::iterator itl = tlist.begin();
704  for (int c = 0; c <= end; ++c, ++itl) {
705  if (c >= start) {
706  *itl = prefix + *itl;
707  }
708  }
709 }
710 
711 
712 /**
713  * Gets file names from project directory.
714  */
715 void
717 
718  // files that match are accepted
719  string vhdlRegex =
720  ((language_==VHDL)?".*\\.(vhd|vhdl|pkg)$":".*\\.(v)$");
721 
722  // generate relative paths
723  bool absolutePaths = false;
724 
725  // getting files from project dir
728  if (FileSystem::fileIsDirectory(dirName)) {
729  findFiles(vhdlRegex,
730  FileSystem::directoryContents(dirName, absolutePaths),
731  vhdlFiles_);
732  // add the toplevelEntity + _imem_mau_pkg.vhdl to vhdlFiles_.
733  // It is generated by PIG so it is not yet present.
734  if(language_==VHDL){
735  string imemMauPkg = dirName + FileSystem::DIRECTORY_SEPARATOR
736  + toplevelEntity_ + "_imem_mau_pkg.vhdl";
737  vhdlFiles_.push_back(imemMauPkg);
738  }
739  }
740  std::string sharedDir =
743 
744  if (sharedDir != FileSystem::absolutePathOf(dirName)
745  && FileSystem::fileIsDirectory(sharedDir)) {
746  findFiles(
747  vhdlRegex,
748  FileSystem::directoryContents(sharedDir, absolutePaths),
749  vhdlFiles_);
750  }
751 
753  if (FileSystem::fileIsDirectory(dirName)) {
754  findFiles(vhdlRegex,
755  FileSystem::directoryContents(dirName, absolutePaths),
756  gcuicFiles_);
757  }
758 
762  } else {
763  findFiles(vhdlRegex,
764  FileSystem::directoryContents(dstDir_, absolutePaths),
766  }
767 }
768 
769 /**
770  * Reorders filename lists by arranging packages (*_pkg*) to the beginning of
771  * the lists.
772  */
773 void
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) {
779  return true;
780  } else if (!str1IsPkg && str2IsPkg) {
781  return false;
782  } else {
783  return str1 < str2;
784  }
785  };
786 
787  vhdlFiles_.sort(packageComp);
788  gcuicFiles_.sort(packageComp);
789  testBenchFiles_.sort(packageComp);
790 }
791 
792 /**
793  * Prepares filename lists, generally sorts them.
794  */
795 void
797 
798  const string DS = FileSystem::DIRECTORY_SEPARATOR;
799  if(language_==VHDL){
800  string gcuIcDirName = progeOutDir_ + DS + gcuicDir_ + DS;
801  list<string> gcuicFirstOrder;
802  gcuicFirstOrder.push_back("gcu_opcodes_pkg.vhdl");
803  prefixStrings(gcuicFirstOrder, gcuIcDirName);
804  sortFilesFirst(gcuicFiles_, gcuicFirstOrder);
805 
806  list<string> gcuicLastOrder;
807  gcuicLastOrder.push_back("ic.vhdl");
808  prefixStrings(gcuicLastOrder, gcuIcDirName);
809  sortFilesLast(gcuicFiles_, gcuicLastOrder);
810 
811  string vhdlDirName = progeOutDir_ + DS + vhdlDir_ + DS;
812  list<string> vhdlFirstOrder;
813  vhdlFirstOrder.push_back("tce_util_pkg.vhdl");
814  vhdlFirstOrder.push_back(toplevelEntity_ + "_imem_mau_pkg.vhdl");
815  vhdlFirstOrder.push_back(toplevelEntity_ + "_globals_pkg.vhdl");
816  vhdlFirstOrder.push_back(toplevelEntity_ + "_params_pkg.vhdl");
817  // add FU and RF files in correct order
818  getBlockOrder(vhdlFirstOrder);
819  prefixStrings(vhdlFirstOrder, vhdlDirName);
820  sortFilesFirst(vhdlFiles_, vhdlFirstOrder);
821 
822  list<string> vhdlLastOrder;
823  string toplevelFile = toplevelEntity_ + ".vhdl";
824  vhdlLastOrder.push_back(toplevelFile);
825  prefixStrings(vhdlLastOrder, vhdlDirName);
826  sortFilesLast(vhdlFiles_, vhdlLastOrder);
827 
828  string tbDirName = progeOutDir_ + DS + tbDir_ + DS;
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");
834  prefixStrings(testBenchLastOrder, tbDirName);
835  sortFilesLast(testBenchFiles_, testBenchLastOrder);
836  } else {
837  //nothing to do here
838  }
839  // make dirs relative to dstDir_
840  list<string>::iterator itl;
841  itl = vhdlFiles_.begin();
842  while (itl != vhdlFiles_.end()) {
844  }
845  itl = gcuicFiles_.begin();
846  while (itl != gcuicFiles_.end()) {
848  }
849  itl = testBenchFiles_.begin();
850  while (itl != testBenchFiles_.end()) {
852  }
853 }
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, const std::string &simulationRuntime="52390")
Definition: ProGeScriptGenerator.cc:86
HDB::FUEntry
Definition: FUEntry.hh:49
ProGeScriptGenerator::toplevelEntity_
const std::string toplevelEntity_
Definition: ProGeScriptGenerator.hh:158
HDB::HWBlockImplementation::file
BlockImplementationFile & file(int index) const
Definition: HWBlockImplementation.cc:267
POP_CLANG_DIAGS
#define POP_CLANG_DIAGS
Definition: CompilerWarnings.hh:96
IDF::RFImplementationLocation
UnitImplementationLocation RFImplementationLocation
Definition: ComponentImplementationSelector.hh:57
ProGeScriptGenerator::idf_
const IDF::MachineImplementation & idf_
Definition: ProGeScriptGenerator.hh:159
FileSystem.hh
ProGeScriptGenerator::generateModsimCompile
void generateModsimCompile()
Definition: ProGeScriptGenerator.cc:158
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
ProGeScriptGenerator::fetchFiles
void fetchFiles()
Definition: ProGeScriptGenerator.cc:716
ProGeScriptGenerator::gcuicFiles_
std::list< std::string > gcuicFiles_
Definition: ProGeScriptGenerator.hh:138
FileSystem::setFileExecutable
static bool setFileExecutable(const std::string fileName)
Definition: FileSystem.cc:322
ProGeScriptGenerator::outputScriptCommands
void outputScriptCommands(std::ostream &stream, const std::list< std::string > &files, const std::string &cmdPrefix, const std::string &cmdPostfix)
Definition: ProGeScriptGenerator.cc:469
ProGeScriptGenerator::generateIverilogSimulate
void generateIverilogSimulate()
Definition: ProGeScriptGenerator.cc:374
ProGeScriptGenerator::generateGhdlCompile
void generateGhdlCompile()
Definition: ProGeScriptGenerator.cc:226
ProGeScriptGenerator::findText
void findText(const std::string &perlre, const unsigned int &matchRegion, const std::string &fileName, std::list< std::string > &found)
Definition: ProGeScriptGenerator.cc:515
MAGICAL_RUNTIME_CONSTANT
const string MAGICAL_RUNTIME_CONSTANT
Definition: ProGeScriptGenerator.cc:71
ProGeScriptGenerator::testbenchName_
const std::string testbenchName_
Definition: ProGeScriptGenerator.hh:157
HDB::RFEntry
Definition: RFEntry.hh:47
HDB::HWBlockImplementation::implementationFileCount
int implementationFileCount() const
Definition: HWBlockImplementation.cc:254
IGNORE_CLANG_WARNING
#define IGNORE_CLANG_WARNING(X)
Definition: CompilerWarnings.hh:85
ProGeScriptGenerator::findFiles
void findFiles(const std::string &perlre, T files, std::list< std::string > &found)
ProGeScriptGenerator::generateIverilogCompile
void generateIverilogCompile()
Definition: ProGeScriptGenerator.cc:271
ProGeScriptGenerator::generateSimulationStart
void generateSimulationStart(std::ostream &stream)
Definition: ProGeScriptGenerator.cc:442
HDB::HDBRegistry::hdb
CachedHDBManager & hdb(const std::string fileName)
Definition: HDBRegistry.cc:80
ProGeScriptGenerator::gcuicDir_
const std::string gcuicDir_
Definition: ProGeScriptGenerator.hh:145
ProGeScriptGenerator::getBlockOrder
void getBlockOrder(std::list< std::string > &order)
Definition: ProGeScriptGenerator.cc:644
ProGeScriptGenerator::vhdlDir_
const std::string vhdlDir_
Definition: ProGeScriptGenerator.hh:143
FileSystem::absolutePathOf
static std::string absolutePathOf(const std::string &pathName)
Definition: FileSystem.cc:303
ProGeScriptGenerator::generateCompileStart
void generateCompileStart(std::ostream &stream)
Definition: ProGeScriptGenerator.cc:419
FileSystem::relativeDir
static bool relativeDir(const std::string &baseDir, std::string &toRelDir)
Definition: FileSystem.cc:762
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
ProGeScriptGenerator::sortFilesLast
void sortFilesLast(std::list< std::string > &toSort, std::list< std::string > &acSort)
Definition: ProGeScriptGenerator.cc:606
ProGeScriptGenerator::ghdlSimulateScriptName_
const std::string ghdlSimulateScriptName_
Definition: ProGeScriptGenerator.hh:153
HDB::CachedHDBManager
Definition: CachedHDBManager.hh:63
IDF::MachineImplementation::rfImplementation
RFImplementationLocation & rfImplementation(const std::string &rf) const
Definition: MachineImplementation.cc:377
ProGeScriptGenerator::modsimCompileScriptName_
const std::string modsimCompileScriptName_
Definition: ProGeScriptGenerator.hh:149
FileSystem::fileIsDirectory
static bool fileIsDirectory(const std::string fileName)
ProGeScriptGenerator::sharedOutDir_
std::string sharedOutDir_
Definition: ProGeScriptGenerator.hh:132
ProGeScriptGenerator::ghdlCompileScriptName_
const std::string ghdlCompileScriptName_
Definition: ProGeScriptGenerator.hh:150
ProGeScriptGenerator::language_
const ProGe::HDL language_
Definition: ProGeScriptGenerator.hh:160
HDB::RFImplementation
Definition: RFImplementation.hh:50
ProGe::VHDL
@ VHDL
VHDL.
Definition: ProGeTypes.hh:41
RFImplementation.hh
ProGeScriptGenerator::iverilogCompileScriptName_
const std::string iverilogCompileScriptName_
Definition: ProGeScriptGenerator.hh:151
ProGeScriptGenerator::dstDir_
std::string dstDir_
Definition: ProGeScriptGenerator.hh:128
ProGeScriptGenerator::packageFilesFirst
void packageFilesFirst()
Definition: ProGeScriptGenerator.cc:774
FUEntry.hh
FileSystem::findFromDirectoryRecursive
static bool findFromDirectoryRecursive(const std::string &regex, const std::string &directory, STLCONT &found)
ProGeScriptGenerator::iverilogSimulateScriptName_
const std::string iverilogSimulateScriptName_
Definition: ProGeScriptGenerator.hh:154
__func__
#define __func__
Definition: Application.hh:67
IDF::FUImplementationLocation
UnitImplementationLocation FUImplementationLocation
Definition: ComponentImplementationSelector.hh:55
ProGeScriptGenerator::progeOutDir_
std::string progeOutDir_
Definition: ProGeScriptGenerator.hh:130
ProGeScriptGenerator::~ProGeScriptGenerator
virtual ~ProGeScriptGenerator()
Definition: ProGeScriptGenerator.cc:125
IDF::MachineImplementation::rfImplementationCount
int rfImplementationCount() const
Definition: MachineImplementation.cc:310
ProGeScriptGenerator::verDir_
const std::string verDir_
Definition: ProGeScriptGenerator.hh:144
HDB::RFEntry::implementation
RFImplementation & implementation() const
Definition: RFEntry.cc:102
HDB::BlockImplementationFile::pathToFile
std::string pathToFile() const
Definition: BlockImplementationFile.cc:61
FileSystem::createFile
static bool createFile(const std::string &file)
Definition: FileSystem.cc:468
FUImplementation.hh
ProGeScriptGenerator::tbDir_
const std::string tbDir_
Definition: ProGeScriptGenerator.hh:146
ProGeScriptGenerator::generateAll
void generateAll()
Definition: ProGeScriptGenerator.cc:136
ProGeScriptGenerator::prepareFiles
void prepareFiles()
Definition: ProGeScriptGenerator.cc:796
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
ProGeScriptGenerator::createExecutableFile
void createExecutableFile(const std::string &fileName)
Definition: ProGeScriptGenerator.cc:403
ProGeScriptGenerator::simulationRuntime_
const std::string simulationRuntime_
Definition: ProGeScriptGenerator.hh:163
HDB::FUImplementation
Definition: FUImplementation.hh:53
ProGeScriptGenerator::generateModsimSimulate
void generateModsimSimulate()
Definition: ProGeScriptGenerator.cc:303
CachedHDBManager.hh
ProGeScriptGenerator::prefixStrings
void prefixStrings(std::list< std::string > &tlist, const std::string &prefix, int start=0, int end=-1)
Definition: ProGeScriptGenerator.cc:693
IDF::MachineImplementation::fuImplementationCount
int fuImplementationCount() const
Definition: MachineImplementation.cc:299
ProGe
Definition: FUGen.hh:54
ProGeScriptGenerator::outputScriptCommand
void outputScriptCommand(std::ostream &stream, const std::string &file, const std::string &cmdPrefix, const std::string &cmdPostfix)
Definition: ProGeScriptGenerator.cc:493
ProGeScriptGenerator::sortFilesFirst
void sortFilesFirst(std::list< std::string > &toSort, std::list< std::string > &acSort)
Definition: ProGeScriptGenerator.cc:561
ProGeScriptGenerator.hh
ProGe::HDL
HDL
HDLs supported by ProGe.
Definition: ProGeTypes.hh:40
RFEntry.hh
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
IDF::UnitImplementationLocation::hdbFile
virtual std::string hdbFile() const
Definition: UnitImplementationLocation.cc:99
IOException
Definition: Exception.hh:130
ProGeScriptGenerator::testBenchFiles_
std::list< std::string > testBenchFiles_
Definition: ProGeScriptGenerator.hh:139
ProGeScriptGenerator::workDir_
const std::string workDir_
Definition: ProGeScriptGenerator.hh:142
IDF::MachineImplementation::fuImplementation
FUImplementationLocation & fuImplementation(const std::string &fu) const
Definition: MachineImplementation.cc:355
HDB::FUEntry::implementation
FUImplementation & implementation() const
Definition: FUEntry.cc:86
HDBManager.hh
DS
#define DS
Definition: LLVMBackend.cc:124
ProGeScriptGenerator::testBenchDir_
std::string testBenchDir_
Definition: ProGeScriptGenerator.hh:134
HDBRegistry.hh
FileSystem::compareFileNames
static bool compareFileNames(const std::string &first, const std::string &second, const std::string &rootDirectory)
Definition: FileSystem.cc:724
HDB::HDBManager::fuByEntryID
FUEntry * fuByEntryID(RowID id) const
Definition: HDBManager.cc:2828
ProGeScriptGenerator::vhdlFiles_
std::list< std::string > vhdlFiles_
Definition: ProGeScriptGenerator.hh:137
IDF::MachineImplementation
Definition: MachineImplementation.hh:54
UnitImplementationLocation.hh
CompilerWarnings.hh
MachineImplementation.hh
ProGeScriptGenerator::generateGhdlSimulate
void generateGhdlSimulate()
Definition: ProGeScriptGenerator.cc:344
Environment::dataDirPath
static std::string dataDirPath(const std::string &prog)
Definition: Environment.cc:176
FileSystem::directoryContents
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
Definition: FileSystem.cc:600
HDB::HDBManager::rfByEntryID
RFEntry * rfByEntryID(RowID id) const
Definition: HDBManager.cc:2885
HDB::HDBRegistry::instance
static HDBRegistry & instance()
Definition: HDBRegistry.cc:62
ProGeScriptGenerator::modsimSimulateScriptName_
const std::string modsimSimulateScriptName_
Definition: ProGeScriptGenerator.hh:152