OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
TCEString entityStr_
 
const HDL language_
 
std::set< std::string > copiedFiles_
 Copied files.
 
HDLTemplateInstantiator instantiator_
 Object that instantiates templates.
 

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}
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
void setEntityString(const TCEString &entityStr)
const IDF::MachineImplementation & implementation_
The IDF object model.
HDLTemplateInstantiator instantiator_
Object that instantiates templates.

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}
#define assert(condition)
RFEntry * rfByEntryID(RowID id) const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
virtual bool hasImplementation() const
Definition RFEntry.cc:74
RFImplementation & implementation() const
Definition RFEntry.cc:102
void copyFiles(const HDB::HWBlockImplementation &implementation, const std::string &hdbFile, const std::string &dstDirectory)

References assert, copyFiles(), HDB::RFEntry::hasImplementation(), HDB::HDBRegistry::hdb(), HDB::RFEntry::implementation(), implementation, HDB::HDBRegistry::instance(), 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++) {
281 vector<string> modulePaths = Environment::vhdlPaths(hdbFile);
282
283 string absoluteFile;
284 try {
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 =
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}
#define __func__
#define DS
static std::vector< std::string > vhdlPaths(const std::string &hdbPath)
std::string errorMessage() const
Definition Exception.cc:123
static bool createDirectory(const std::string &path)
static const std::string DIRECTORY_SEPARATOR
static std::string fileOfPath(const std::string pathName)
static void copy(const std::string &source, const std::string &target)
static std::string findFileInSearchPaths(const std::vector< std::string > &searchPaths, const std::string &file)
static bool fileExists(const std::string fileName)
void setCopied(const std::string &file)
bool isCopied(const std::string &file) const
HDL
HDLs supported by ProGe.
Definition ProGeTypes.hh:40
@ Verilog
Verilog.
Definition ProGeTypes.hh:42
@ VHDL
VHDL.
Definition ProGeTypes.hh:41

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}
static std::string dataDirPath(const std::string &prog)
void instantiateTemplateFile(const std::string &templateFile, const std::string &dstFile)

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++) {
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++) {
115 copyBaseRFFiles(rfImpl, dstDirectory);
116 }
117
118 // copy IU files
119 for (int i = 0; i < implementation_.iuImplementationCount(); i++) {
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}
static const std::string UTILITY_VERILOG_FILE
static const std::string UTILITY_VHDL_FILE
FUImplementation & implementation() const
Definition FUEntry.cc:86
virtual bool hasImplementation() const
Definition FUEntry.cc:74
FUEntry * fuByEntryID(RowID id) const
RFImplementationLocation & iuImplementation(const std::string &iu) const
RFImplementationLocation & rfImplementation(const std::string &rf) const
FUImplementationLocation & fuImplementation(const std::string &fu) const
void copyBaseRFFiles(const IDF::RFImplementationLocation &implementation, const std::string &dstDirectory)

References assert, FileSystem::copy(), copyBaseRFFiles(), copyFiles(), Environment::dataDirPath(), FileSystem::DIRECTORY_SEPARATOR, DS, HDB::HDBManager::fuByEntryID(), IDF::MachineImplementation::fuImplementation(), IDF::MachineImplementation::fuImplementationCount(), HDB::FUEntry::hasImplementation(), HDB::HDBRegistry::hdb(), IDF::UnitImplementationLocation::hdbFile(), IDF::UnitImplementationLocation::id(), HDB::FUEntry::implementation(), implementation_, HDB::HDBRegistry::instance(), 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}
static bool containsKey(const ContainerType &aContainer, const KeyType &aKey)
std::set< std::string > copiedFiles_
Copied files.

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: