OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ProGe::BlockSourceCopier Class Reference

#include <BlockSourceCopier.hh>

Collaboration diagram for ProGe::BlockSourceCopier:
Collaboration graph

Public Member Functions

 BlockSourceCopier (const IDF::MachineImplementation &implementation, TCEString entityStr, const ProGe::HDL language)
 
virtual ~BlockSourceCopier ()
 
void copyShared (const std::string &dstDirectory)
 
void copyProcessorSpecific (const std::string &dstDirectory)
 
void instantiateHDLTemplate (const std::string &srcFile, const std::string &dstDirectory, std::string newName="0")
 
HDLTemplateInstantiatorgetTemplateInstatiator ()
 

Private Member Functions

void copyBaseRFFiles (const IDF::RFImplementationLocation &implementation, const std::string &dstDirectory)
 
void copyFiles (const HDB::HWBlockImplementation &implementation, const std::string &hdbFile, const std::string &dstDirectory)
 
void copyFromTemplate (const std::string &templateFile, const std::string &dstDirectory)
 
void setCopied (const std::string &file)
 
bool isCopied (const std::string &file) const
 

Private Attributes

const IDF::MachineImplementationimplementation_
 The IDF object model. More...
 
TCEString entityStr_
 
const HDL language_
 
std::set< std::string > copiedFiles_
 Copied files. More...
 
HDLTemplateInstantiator instantiator_
 Object that instantiates templates. More...
 

Detailed Description

Copies the block definition files used in the processor implementation to the output directory of ProGe.

Definition at line 63 of file BlockSourceCopier.hh.

Constructor & Destructor Documentation

◆ BlockSourceCopier()

ProGe::BlockSourceCopier::BlockSourceCopier ( const IDF::MachineImplementation implementation,
TCEString  entityStr,
const ProGe::HDL  language 
)

The constructor.

Definition at line 67 of file BlockSourceCopier.cc.

70  :
71  implementation_(implementation), entityStr_(entityStr), language_(language){
73 }

References entityStr_, instantiator_, and HDLTemplateInstantiator::setEntityString().

Here is the call graph for this function:

◆ ~BlockSourceCopier()

ProGe::BlockSourceCopier::~BlockSourceCopier ( )
virtual

The destructor.

Definition at line 79 of file BlockSourceCopier.cc.

79  {
80 }

Member Function Documentation

◆ copyBaseRFFiles()

void ProGe::BlockSourceCopier::copyBaseRFFiles ( const IDF::RFImplementationLocation implementation,
const std::string &  dstDirectory 
)
private

Copies the block definition files of the given RF implementation to the proper subdirectories of the given directory.

Parameters
implementationThe location of the RF implementation.
dstDirectoryThe destination "root" directory.
Exceptions
IOExceptionIf some file cannot be copied or HDB cannot be opened.

Definition at line 251 of file BlockSourceCopier.cc.

253  {
254  string hdbFile = implementation.hdbFile();
255  int id = implementation.id();
256  HDBManager& manager = HDBRegistry::instance().hdb(hdbFile);
257  RFEntry* entry = manager.rfByEntryID(id);
258  assert(entry->hasImplementation());
259  RFImplementation& impl = entry->implementation();
260  copyFiles(impl, hdbFile, dstDirectory);
261  delete entry;
262 }

References assert, copyFiles(), HDB::RFEntry::hasImplementation(), HDB::RFEntry::implementation(), implementation, and HDB::HDBManager::rfByEntryID().

Referenced by copyShared().

Here is the call graph for this function:

◆ copyFiles()

void ProGe::BlockSourceCopier::copyFiles ( const HDB::HWBlockImplementation implementation,
const std::string &  hdbFile,
const std::string &  dstDirectory 
)
private

Copies the block definition files of the given HW block implementation to the proper subdirectories of the given directory.

Parameters
implementationThe block implementation.
hdbFileThe HDB file that contains the block.
dstDirectoryThe destination "root" directory.
Exceptions
UnreachableStreamIf some file cannot be copied to the destination directory.
FileNotFoundIf the file referred to in HDB is not found.

Definition at line 276 of file BlockSourceCopier.cc.

278  {
279  for (int i = 0; i < implementation.implementationFileCount(); i++) {
280  BlockImplementationFile& file = implementation.file(i);
281  vector<string> modulePaths = Environment::vhdlPaths(hdbFile);
282 
283  string absoluteFile;
284  try {
285  absoluteFile = FileSystem::findFileInSearchPaths(
286  modulePaths, file.pathToFile());
287  } catch (const Exception& e) {
288  string errorMsg =
289  "Problem with " + implementation.moduleName() + " in HDB " +
290  hdbFile + ".\n" +
291  "Unable to find file mentioned in HDB: " + file.pathToFile() +
292  ":\n";
293  errorMsg += e.errorMessage();
294  throw FileNotFound(__FILE__, __LINE__, __func__, errorMsg);
295  }
296 
297  if (!isCopied(absoluteFile)) {
298  string fileName = FileSystem::fileOfPath(absoluteFile);
299  string targetDir, targetFile;
301 
302  if(language_== VHDL && (ProGe::HDL)file.format()==VHDL) {
303  targetDir = dstDirectory + DS + "vhdl";
304  } else
305  if(language_== Verilog && (ProGe::HDL) file.format()==Verilog) {
306  targetDir = dstDirectory + DS + "verilog";
307  } else {
308  setCopied(absoluteFile);
309  continue;//next file for check
310  }
311 
312  targetFile = targetDir + DS + fileName;
313 
314  if (!FileSystem::fileExists(targetDir)) {
315  bool directoryCreated =
316  FileSystem::createDirectory(targetDir);
317  if (!directoryCreated) {
318  string errorMsg = "Unable to create directory " +
319  targetDir + ".";
320  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
321  }
322  }
323 
324  try {
325  FileSystem::copy(absoluteFile, targetFile);
326  } catch (const Exception& e) {
327  string errorMsg = "Unable to copy file " + targetFile + ":";
328  errorMsg += e.errorMessage();
329 
330  throw UnreachableStream(
331  __FILE__, __LINE__, __func__, errorMsg);
332  }
333  setCopied(absoluteFile);
334  }
335  }
336 }

References __func__, FileSystem::copy(), FileSystem::createDirectory(), FileSystem::DIRECTORY_SEPARATOR, DS, Exception::errorMessage(), FileSystem::fileExists(), FileSystem::fileOfPath(), FileSystem::findFileInSearchPaths(), HDB::BlockImplementationFile::format(), implementation, isCopied(), language_, HDB::BlockImplementationFile::pathToFile(), setCopied(), ProGe::Verilog, ProGe::VHDL, and Environment::vhdlPaths().

Referenced by copyBaseRFFiles(), and copyShared().

Here is the call graph for this function:

◆ copyFromTemplate()

void ProGe::BlockSourceCopier::copyFromTemplate ( const std::string &  templateFile,
const std::string &  dstDirectory 
)
private

◆ copyProcessorSpecific()

void ProGe::BlockSourceCopier::copyProcessorSpecific ( const std::string &  dstDirectory)

Copies the block definition files of the blocks given in IDF to proper subdirectories of the given directory.

This method copies the processor-specific files that are not reused between multiple TTAs.

Parameters
dstDirectoryThe destination "root" directory.
Exceptions
IOExceptionIf some file cannot be copied or HDB cannot be opened.

Definition at line 145 of file BlockSourceCopier.cc.

145  {
146  // copy decompressor file
147  const string DS = FileSystem::DIRECTORY_SEPARATOR;
148  string decompressorTargetDir = dstDirectory + DS + "gcu_ic";
149  if (!FileSystem::fileExists(decompressorTargetDir)) {
150  if (!FileSystem::createDirectory(decompressorTargetDir)) {
151  string errorMsg = "Unable to create directory " +
152  decompressorTargetDir;
153  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
154  }
155  }
156 
157  string sourceFile;
158  string dstFile;
160  sourceFile = implementation_.decompressorFile();
161  string file = FileSystem::fileOfPath(sourceFile);
162  dstFile = decompressorTargetDir + DS + file;
163  FileSystem::copy(sourceFile, dstFile);
164  } else {
165  sourceFile = Environment::dataDirPath("ProGe") + DS +
166  ((language_ == Verilog) ? "idecompressor.v.tmpl"
167  : "idecompressor.vhdl.tmpl");
168  string file =
169  ((language_ == Verilog) ? "idecompressor.v"
170  : "idecompressor.vhdl");
171  dstFile = decompressorTargetDir + DS + file;
172 
173  if (!FileSystem::fileExists(dstFile)) {
174  instantiator_.instantiateTemplateFile(sourceFile, dstFile);
175  }
176  }
177 
178  string ifetchSrcFile;
179  ifetchSrcFile =
180  Environment::dataDirPath("ProGe") + DS +
181  ((language_ == Verilog) ? "ifetch.v.tmpl" : "ifetch.vhdl.tmpl");
182  string ifetchTargetDir = decompressorTargetDir;
183  assert(FileSystem::fileExists(ifetchTargetDir));
184  string ifetchDstFile =
185  ifetchTargetDir + DS + ((language_==Verilog)?"ifetch.v":"ifetch.vhdl");
186 
187  if (!FileSystem::fileExists(ifetchDstFile)) {
188  instantiator_.instantiateTemplateFile(ifetchSrcFile, ifetchDstFile);
189  }
190 }

References __func__, assert, FileSystem::copy(), FileSystem::createDirectory(), Environment::dataDirPath(), IDF::MachineImplementation::decompressorFile(), FileSystem::DIRECTORY_SEPARATOR, DS, FileSystem::fileExists(), FileSystem::fileOfPath(), IDF::MachineImplementation::hasDecompressorFile(), implementation_, HDLTemplateInstantiator::instantiateTemplateFile(), instantiator_, language_, and ProGe::Verilog.

Referenced by ProGe::ProcessorGenerator::generateProcessor().

Here is the call graph for this function:

◆ copyShared()

void ProGe::BlockSourceCopier::copyShared ( const std::string &  dstDirectory)

Copies the block definition files of the blocks given in IDF to proper subdirectories of the given directory.

This method copies the files that can and are potentially shared by multiple TTAs in the same system design. That is, the FU, RF and IU implementations.

Parameters
dstDirectoryThe destination "root" directory.
Exceptions
IOExceptionIf some file cannot be copied or HDB cannot be opened.

Definition at line 96 of file BlockSourceCopier.cc.

96  {
97  // copy FU files
98  for (int i = 0; i < implementation_.fuImplementationCount(); i++) {
99  FUImplementationLocation& fuImpl =
101  string hdbFile = fuImpl.hdbFile();
102  int id = fuImpl.id();
103  HDBManager& manager = HDBRegistry::instance().hdb(hdbFile);
104  FUEntry* entry = manager.fuByEntryID(id);
105  assert(entry->hasImplementation());
106  FUImplementation& impl = entry->implementation();
107  copyFiles(impl, hdbFile, dstDirectory);
108  delete entry;
109  }
110 
111  // copy RF files
112  for (int i = 0; i < implementation_.rfImplementationCount(); i++) {
113  RFImplementationLocation& rfImpl =
115  copyBaseRFFiles(rfImpl, dstDirectory);
116  }
117 
118  // copy IU files
119  for (int i = 0; i < implementation_.iuImplementationCount(); i++) {
120  RFImplementationLocation& rfImpl =
122  copyBaseRFFiles(rfImpl, dstDirectory);
123  }
124 
125  const string DS = FileSystem::DIRECTORY_SEPARATOR;
126  string sourceDir = Environment::dataDirPath("ProGe");
127  // copy the utility VHDL or Verilog files
130  dstDirectory + DS + ((language_==VHDL)?"vhdl":"verilog") + DS + ((language_==VHDL)?UTILITY_VHDL_FILE:UTILITY_VERILOG_FILE));
131 }

References assert, FileSystem::copy(), copyBaseRFFiles(), copyFiles(), Environment::dataDirPath(), FileSystem::DIRECTORY_SEPARATOR, DS, HDB::HDBManager::fuByEntryID(), IDF::MachineImplementation::fuImplementation(), IDF::MachineImplementation::fuImplementationCount(), HDB::FUEntry::hasImplementation(), IDF::UnitImplementationLocation::hdbFile(), IDF::UnitImplementationLocation::id(), HDB::FUEntry::implementation(), implementation_, IDF::MachineImplementation::iuImplementation(), IDF::MachineImplementation::iuImplementationCount(), language_, IDF::MachineImplementation::rfImplementation(), IDF::MachineImplementation::rfImplementationCount(), UTILITY_VERILOG_FILE, UTILITY_VHDL_FILE, and ProGe::VHDL.

Referenced by ProGe::ProcessorGenerator::generateProcessor().

Here is the call graph for this function:

◆ getTemplateInstatiator()

HDLTemplateInstantiator & ProGe::BlockSourceCopier::getTemplateInstatiator ( )

Returns reference to template instantiator instance used by this.

Definition at line 237 of file BlockSourceCopier.cc.

237  {
238  return instantiator_;
239 }

References instantiator_.

Referenced by DefaultICDecoderGenerator::generate(), and ProGe::ProcessorGenerator::generateProcessor().

◆ instantiateHDLTemplate()

void ProGe::BlockSourceCopier::instantiateHDLTemplate ( const std::string &  srcFile,
const std::string &  dstDirectory,
std::string  newName = "0" 
)

Copies given template file to given directory and instantiates it, ie. removes the .tmpl from the filename and converts it to .vhdl while replacing occurances of "ENTITY_STR" with entityStr_.

Parameters
srcFileThe location and name of the .tmpl file to copy
dstDirectoryThe directory to copy to and instantiate in.
newNameNew name for the file. If "0", only ".tmpl" is removed.

Definition at line 202 of file BlockSourceCopier.cc.

204  {
205  const string DS = FileSystem::DIRECTORY_SEPARATOR;
206 
207  if (!FileSystem::fileExists(srcFile)) {
208  string errorMsg = "Source file " + srcFile + " not found.";
209  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
210  }
211 
212  if (!FileSystem::fileExists(dstDirectory)) {
213  if (!FileSystem::createDirectory(dstDirectory)) {
214  string errorMsg = "Unable to create directory " +
215  dstDirectory;
216  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
217  }
218  }
219 
220  string source = FileSystem::fileOfPath(srcFile);
221  string dstFile;
222 
223  if (newName == "0") {
224  dstFile = source.erase(source.find(".tmpl", 0), string::npos);
225  } else {
226  dstFile = newName;
227  }
228 
230  srcFile, dstDirectory + DS + dstFile);
231 }

References __func__, FileSystem::createDirectory(), FileSystem::DIRECTORY_SEPARATOR, DS, FileSystem::fileExists(), FileSystem::fileOfPath(), HDLTemplateInstantiator::instantiateTemplateFile(), and instantiator_.

Referenced by DefaultICDecoderGenerator::generate().

Here is the call graph for this function:

◆ isCopied()

bool ProGe::BlockSourceCopier::isCopied ( const std::string &  file) const
private

Tells whether the given file is copied already.

Parameters
fileThe file.
Returns
True if the file is copied, otherwise false.

Definition at line 357 of file BlockSourceCopier.cc.

357  {
359 }

References AssocTools::containsKey(), and copiedFiles_.

Referenced by copyFiles().

Here is the call graph for this function:

◆ setCopied()

void ProGe::BlockSourceCopier::setCopied ( const std::string &  file)
private

Marks the file as copied.

Parameters
fileThe file.

Definition at line 344 of file BlockSourceCopier.cc.

344  {
345  copiedFiles_.insert(file);
346 }

References copiedFiles_.

Referenced by copyFiles().

Member Data Documentation

◆ copiedFiles_

std::set<std::string> ProGe::BlockSourceCopier::copiedFiles_
private

Copied files.

Definition at line 99 of file BlockSourceCopier.hh.

Referenced by isCopied(), and setCopied().

◆ entityStr_

TCEString ProGe::BlockSourceCopier::entityStr_
private

Definition at line 96 of file BlockSourceCopier.hh.

Referenced by BlockSourceCopier().

◆ implementation_

const IDF::MachineImplementation& ProGe::BlockSourceCopier::implementation_
private

The IDF object model.

Definition at line 95 of file BlockSourceCopier.hh.

Referenced by copyProcessorSpecific(), and copyShared().

◆ instantiator_

HDLTemplateInstantiator ProGe::BlockSourceCopier::instantiator_
private

Object that instantiates templates.

Definition at line 101 of file BlockSourceCopier.hh.

Referenced by BlockSourceCopier(), copyProcessorSpecific(), getTemplateInstatiator(), and instantiateHDLTemplate().

◆ language_

const HDL ProGe::BlockSourceCopier::language_
private

Definition at line 97 of file BlockSourceCopier.hh.

Referenced by copyFiles(), copyProcessorSpecific(), and copyShared().


The documentation for this class was generated from the following files:
IDF::UnitImplementationLocation
Definition: UnitImplementationLocation.hh:48
HDB::FUEntry
Definition: FUEntry.hh:49
ProGe::BlockSourceCopier::copiedFiles_
std::set< std::string > copiedFiles_
Copied files.
Definition: BlockSourceCopier.hh:99
FileNotFound
Definition: Exception.hh:224
HDB::RFEntry::hasImplementation
virtual bool hasImplementation() const
Definition: RFEntry.cc:74
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition: FileSystem.cc:400
ProGe::Verilog
@ Verilog
Verilog.
Definition: ProGeTypes.hh:42
UnreachableStream
Definition: Exception.hh:171
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
ProGe::BlockSourceCopier::copyFiles
void copyFiles(const HDB::HWBlockImplementation &implementation, const std::string &hdbFile, const std::string &dstDirectory)
Definition: BlockSourceCopier.cc:276
AssocTools::containsKey
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
HDB::RFEntry
Definition: RFEntry.hh:47
IDF::MachineImplementation::iuImplementation
RFImplementationLocation & iuImplementation(const std::string &iu) const
Definition: MachineImplementation.cc:399
ProGe::BlockSourceCopier::instantiator_
HDLTemplateInstantiator instantiator_
Object that instantiates templates.
Definition: BlockSourceCopier.hh:101
ProGe::BlockSourceCopier::copyBaseRFFiles
void copyBaseRFFiles(const IDF::RFImplementationLocation &implementation, const std::string &dstDirectory)
Definition: BlockSourceCopier.cc:251
HDB::BlockImplementationFile
Definition: BlockImplementationFile.hh:44
IDF::MachineImplementation::hasDecompressorFile
bool hasDecompressorFile() const
Definition: MachineImplementation.cc:219
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
UTILITY_VHDL_FILE
static const std::string UTILITY_VHDL_FILE
Definition: BlockSourceCopier.cc:59
ProGe::BlockSourceCopier::entityStr_
TCEString entityStr_
Definition: BlockSourceCopier.hh:96
IDF::MachineImplementation::rfImplementation
RFImplementationLocation & rfImplementation(const std::string &rf) const
Definition: MachineImplementation.cc:377
assert
#define assert(condition)
Definition: Application.hh:86
HDB::RFImplementation
Definition: RFImplementation.hh:50
ProGe::VHDL
@ VHDL
VHDL.
Definition: ProGeTypes.hh:41
__func__
#define __func__
Definition: Application.hh:67
FileSystem::copy
static void copy(const std::string &source, const std::string &target)
Definition: FileSystem.cc:524
HDB::HDBManager
Definition: HDBManager.hh:82
IDF::MachineImplementation::decompressorFile
std::string decompressorFile() const
Definition: MachineImplementation.cc:205
IDF::MachineImplementation::rfImplementationCount
int rfImplementationCount() const
Definition: MachineImplementation.cc:310
ProGe::BlockSourceCopier::setCopied
void setCopied(const std::string &file)
Definition: BlockSourceCopier.cc:344
HDB::RFEntry::implementation
RFImplementation & implementation() const
Definition: RFEntry.cc:102
Exception
Definition: Exception.hh:54
ProGe::BlockSourceCopier::language_
const HDL language_
Definition: BlockSourceCopier.hh:97
HDB::BlockImplementationFile::pathToFile
std::string pathToFile() const
Definition: BlockImplementationFile.cc:61
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
IDF::MachineImplementation::iuImplementationCount
int iuImplementationCount() const
Definition: MachineImplementation.cc:321
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
UTILITY_VERILOG_FILE
static const std::string UTILITY_VERILOG_FILE
Definition: BlockSourceCopier.cc:60
HDB::FUImplementation
Definition: FUImplementation.hh:53
ProGe::BlockSourceCopier::isCopied
bool isCopied(const std::string &file) const
Definition: BlockSourceCopier.cc:357
Environment::vhdlPaths
static std::vector< std::string > vhdlPaths(const std::string &hdbPath)
Definition: Environment.cc:760
IDF::MachineImplementation::fuImplementationCount
int fuImplementationCount() const
Definition: MachineImplementation.cc:299
IDF::UnitImplementationLocation::id
virtual int id() const
Definition: UnitImplementationLocation.cc:127
FileSystem::fileExists
static bool fileExists(const std::string fileName)
HDLTemplateInstantiator::setEntityString
void setEntityString(const TCEString &entityStr)
Definition: HDLTemplateInstantiator.hh:51
HDB::BlockImplementationFile::format
Format format() const
Definition: BlockImplementationFile.cc:70
ProGe::HDL
HDL
HDLs supported by ProGe.
Definition: ProGeTypes.hh:40
IDF::UnitImplementationLocation::hdbFile
virtual std::string hdbFile() const
Definition: UnitImplementationLocation.cc:99
IOException
Definition: Exception.hh:130
HDLTemplateInstantiator::instantiateTemplateFile
void instantiateTemplateFile(const std::string &templateFile, const std::string &dstFile)
Definition: HDLTemplateInstantiator.cc:113
HDB::FUEntry::hasImplementation
virtual bool hasImplementation() const
Definition: FUEntry.cc:74
IDF::MachineImplementation::fuImplementation
FUImplementationLocation & fuImplementation(const std::string &fu) const
Definition: MachineImplementation.cc:355
HDB::FUEntry::implementation
FUImplementation & implementation() const
Definition: FUEntry.cc:86
DS
#define DS
Definition: LLVMBackend.cc:124
FileSystem::findFileInSearchPaths
static std::string findFileInSearchPaths(const std::vector< std::string > &searchPaths, const std::string &file)
Definition: FileSystem.cc:562
HDB::HDBManager::fuByEntryID
FUEntry * fuByEntryID(RowID id) const
Definition: HDBManager.cc:2828
ProGe::BlockSourceCopier::implementation_
const IDF::MachineImplementation & implementation_
The IDF object model.
Definition: BlockSourceCopier.hh:95
Environment::dataDirPath
static std::string dataDirPath(const std::string &prog)
Definition: Environment.cc:176
HDB::HDBManager::rfByEntryID
RFEntry * rfByEntryID(RowID id) const
Definition: HDBManager.cc:2885