Go to the documentation of this file.
41 #include <boost/format.hpp>
157 if (format ==
"mif") {
160 }
else if (format ==
"vhdl") {
161 imageFile +=
"_imem_pkg.vhdl";
162 }
else if (format ==
"coe") {
180 const std::string& tpefFile,
181 const std::string& format,
182 const std::string& asName) {
185 if (format ==
"mif") {
187 }
else if (format ==
"vhdl") {
188 imageFile +=
"_pkg.vhdl";
189 }
else if (format ==
"coe") {
208 const std::string& param, std::string& paramName, std::string& paramValue) {
209 string::size_type separatorPos = param.find(
"=", 0);
210 if (separatorPos == string::npos) {
212 "Compressor parameters must be in form "
213 "'parametername=parametervalue'.";
217 paramName = param.substr(0, separatorPos);
218 paramValue = param.substr(separatorPos+1, param.length());
223 int imemMauWidth,
string fileName,
string entityNameStr) {
225 string indentation =
" ";
229 string errorMsg =
"Unable to create file " + fileName;
232 string errorMsg =
"Unable to write to file " + fileName;
235 std::ofstream stream(fileName.c_str());
236 string entityName = entityNameStr +
"_imem_mau";
238 stream <<
"package " << entityName <<
" is" << endl
239 << indentation <<
"-- created by generatebits" << endl
240 << indentation <<
"constant IMEMMAUWIDTH : positive := "
241 << imemMauWidth <<
";" << endl
242 <<
"end " << entityName <<
";" << endl;
244 stream <<
"//package " << entityName <<
" is" << endl
245 << indentation <<
"// created by generatebits" << endl
246 << indentation <<
"parameter IMEMMAUWIDTH = "
247 << imemMauWidth << endl
248 <<
"//end " << entityName <<
";" << endl;
260 string errorMsg =
"Unable to create file " +
264 std::ofstream decompressorStream(
265 fileName.c_str(), std::ofstream::out);
267 decompressorStream.close();
272 const string& source,
273 const string& progeDir,
274 const string& newImage) {
276 if (!progeDir.empty()) {
278 string tbImage = tbDir +
DIR_SEP + newImage;
294 int main(
int argc,
char* argv[]) {
321 string bemFile =
options->bemFile();
322 string piFormat =
options->programImageOutputFormat();
323 string diFormat =
options->dataImageOutputFormat();
324 int dmemMAUsPerLine =
options->dataMemoryWidthInMAUs();
325 string compressor =
options->compressorPlugin();
326 const bool useCompression = compressor !=
"";
327 bool generateDataImages =
options->generateDataImages();
328 bool generateDecompressor =
options->generateDecompressor();
329 bool showCompressors =
options->showCompressors();
331 string progeOutputDir =
options->progeOutputDirectory();
337 if (showCompressors) {
338 std::vector<string> compressorFiles =
340 for (std::vector<string>::const_iterator iter =
341 compressorFiles.begin();
342 iter != compressorFiles.end(); iter++) {
344 std::cout <<
"******************************************"
345 <<
"**********************" << endl;
346 std::cout <<
"Compressor file: " << *iter << endl;
353 std::cout << std::endl;
359 for (
int i = 0; i <
options->compressorParameterCount(); i++) {
360 string param =
options->compressorParameter(i);
370 compressorParams.push_back(newParam);
374 (piFormat !=
"" && piFormat !=
"binary" && piFormat !=
"ascii" &&
375 piFormat !=
"array" && piFormat !=
"mif" && piFormat !=
"vhdl" &&
376 piFormat !=
"coe" && piFormat !=
"hex" && piFormat !=
"bin2n") ||
377 (diFormat !=
"" && diFormat !=
"binary" &&
378 diFormat !=
"ascii" && diFormat !=
"array" && diFormat !=
"mif" &&
379 diFormat !=
"vhdl" && diFormat !=
"coe" && diFormat !=
"hex" && diFormat !=
"bin2n")) {
384 std::vector<Binary*> tpefTable;
389 for (
int i = 0; i <
options->tpefFileCount(); i++) {
390 string tpefFile =
options->tpefFile(i);
392 tpefTable.push_back(tpef);
414 if (useCompression) {
426 "uncompressed instruction width: %d bits (%d bytes)\n" )
427 % bem->
width() % std::ceil(bem->
width() / 8.0)).str();
430 for (
size_t i = 0; i < tpefTable.size(); i++) {
435 ofstream piStream(imageFile.c_str());
436 if (piFormat ==
"binary") {
439 }
else if (piFormat ==
"array") {
443 }
else if (piFormat ==
"mif") {
447 }
else if (piFormat ==
"vhdl") {
451 }
else if (piFormat ==
"coe") {
455 }
else if (piFormat ==
"hex") {
459 }
else if (piFormat ==
"bin2n") {
464 assert(piFormat ==
"ascii" || piFormat ==
"");
471 if (piFormat ==
"ascii" || piFormat ==
"") {
475 if (generateDataImages) {
478 for (
int i = 0; i < asNav.
count(); i++) {
483 tpefFile, diFormat, as->
name());
484 ofstream stream(fileName.c_str());
485 if (diFormat ==
"binary") {
489 }
else if (diFormat ==
"array") {
493 dmemMAUsPerLine,
true);
494 }
else if (diFormat ==
"mif") {
498 dmemMAUsPerLine,
true);
499 }
else if (diFormat ==
"vhdl") {
503 dmemMAUsPerLine,
true);
504 }
else if (diFormat ==
"coe") {
508 dmemMAUsPerLine,
true);
509 }
else if (diFormat ==
"hex") {
513 dmemMAUsPerLine,
true);
514 }
else if (diFormat ==
"bin2n") {
518 dmemMAUsPerLine,
true);
520 assert(diFormat ==
"ascii" || diFormat ==
"");
524 dmemMAUsPerLine,
true);
528 if (diFormat ==
"ascii" || piFormat ==
"") {
529 std::string dmemInitFile(
"dmem_");
530 dmemInitFile += as->
name() +
"_init.img";
532 fileName, progeOutputDir, dmemInitFile);
539 if (generateDecompressor) {
541 if (!progeOutputDir.empty()) {
554 int compressedInstructionWidth = imageGenerator.
imemMauWidth();
555 if (!progeOutputDir.empty()) {
563 createMauPkg(0,compressedInstructionWidth, temp, entityStr);
572 createMauPkg(1,compressedInstructionWidth, temp, entityStr);
575 createMauPkg(0,compressedInstructionWidth, entityStr +
"_" +
581 for (std::vector<Binary*>::iterator iter = tpefTable.begin();
582 iter != tpefTable.end(); iter++) {
void generateProgramImage(const std::string &programName, std::ostream &stream, OutputFormat format, int mausPerLine=0)
const string IMEM_MAU_PKG
virtual void printHelp() const
static std::vector< std::string > availableCompressors()
void loadBEM(const BinaryEncoding &bem)
virtual TCEString name() const
void loadCompressorParameters(CodeCompressorPlugin::ParameterTable parameters)
const string DECOMPRESSOR_FILE
void setSourceFile(const std::string &fileName)
virtual int numberOfArguments() const
@ ASCII
ASCII 1's and 0's.
std::string programDataImageFile(const std::string &tpefFile, const std::string &format, const std::string &asName)
int main(int argc, char *argv[])
void createCompressor(string fileName, ProgramImageGenerator &imageGenerator, string entityStr)
static void setCmdLineOptions(CmdLineOptions *options_)
const string TB_IMEM_FILE
static int verboseLevel()
virtual AddressSpace * addressSpace() const
void createMauPkg(int language, int imemMauWidth, string fileName, string entityNameStr)
void loadPrograms(TPEFMap programs)
static std::ostream & logStream()
virtual boost::format text(int textId)
void loadCompressorPlugin(const std::string &fileName)
static void printCompressorDescription(const std::string &fileName, std::ostream &stream)
static Binary * loadTPEF(const std::string &tpefFile)
@ MIF
MIF Memory Initialization File.
static std::string fileOfPath(const std::string pathName)
@ HEX
HEX memory initialization format.
static bool fileIsCreatable(const std::string fileName)
#define assert(condition)
std::vector< Parameter > ParameterTable
Table for passing plugin parameters.
void loadMachine(const TTAMachine::Machine &machine)
void generateDataImage(const std::string &programName, TPEF::Binary &program, const std::string &addressSpace, std::ostream &stream, OutputFormat format, int mausPerLine, bool usePregeneratedImage)
static bool fileIsDirectory(const std::string fileName)
void copyImageToTb(const string &source, const string &progeDir, const string &newImage)
virtual ControlUnit * controlUnit() const
static bool fileIsWritable(const std::string fileName)
void setEntityName(const std::string &entity)
virtual int width(const TCEString &templateName) const
static void copy(const std::string &source, const std::string &target)
std::string errorMessageStack(bool messagesOnly=false) const
@ VHDL
Array as a Vhdl package.
const string TB_DMEM_FILE
virtual AddressSpaceNavigator addressSpaceNavigator() const
static bool createFile(const std::string &file)
std::string errorMessage() const
void parse(char *argv[], int argc)
static BinaryEncoding * loadBEM(const std::string &bemFile)
static const std::string DIRECTORY_SEPARATOR
static MachInfoCmdLineOptions options
@ BINARY
Real binary format.
const int DEFAULT_IMEMWIDTH_IN_MAUS
static bool fileExists(const std::string fileName)
virtual Machine * machine() const
void generateDecompressor(std::ostream &stream, TCEString entityStr)
void parseParameter(const std::string ¶m, std::string ¶mName, std::string ¶mValue)
static Machine * loadMachine(const std::string &adfFile)
@ BIN2N
Binary format padded to 2**n.
TTAMachine::Machine * readMachine()
ComponentType * item(int index) const
find Finds info of the inner loops in the program
static bool isInstructionMemory(const TTAMachine::AddressSpace &as)
const string VER_IMEM_MAU_PKG
static std::string fileNameBody(const std::string &fileName)
virtual std::string argument(int index) const
@ COE
COE memory initialization format.
@ ARRAY
ASCII 1's and 0's in array form.
std::map< std::string, TPEF::Binary * > TPEFMap
BinaryEncoding * generate()
static Binary * readBinary(BinaryStream &stream)
std::string programImemImageFile(const std::string &tpefFile, const std::string &format)
BinaryEncoding * readBinaryEncoding()