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;
 
 
  294int 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) {
 
  427                        "uncompressed instruction width: %d bits (%d bytes)\n" )
 
  428                    % bem->
width() % std::ceil(bem->
width() / 8.0)).str();
 
  431        for (
size_t i = 0; i < tpefTable.size(); i++) {
 
  436            ofstream piStream(imageFile.c_str());
 
  437            if (piFormat == 
"binary") {
 
  440            } 
else if (piFormat == 
"array") {
 
  444            } 
else if (piFormat == 
"mif") {
 
  448            } 
else if (piFormat == 
"vhdl") {
 
  452            } 
else if (piFormat == 
"coe") {
 
  456            } 
else if (piFormat == 
"hex") {
 
  460        } 
else if (piFormat == 
"bin2n") {
 
  465                assert(piFormat == 
"ascii" || piFormat == 
"");
 
  472            if (piFormat == 
"ascii" || piFormat == 
"") {
 
  476            if (generateDataImages) {
 
  479                for (
int i = 0; i < asNav.
count(); i++) {
 
  484                                tpefFile, diFormat, as->
name());
 
  485                        ofstream stream(fileName.c_str());
 
  486                        if (diFormat == 
"binary") {
 
  490                        } 
else if (diFormat == 
"array") {
 
  494                                dmemMAUsPerLine, 
true);
 
  495                        } 
else if (diFormat == 
"mif") {
 
  499                                dmemMAUsPerLine, 
true);
 
  500                        } 
else if (diFormat == 
"vhdl") {
 
  504                                dmemMAUsPerLine, 
true);
 
  505                        } 
else if (diFormat == 
"coe") {
 
  509                                dmemMAUsPerLine, 
true);
 
  510                        } 
else if (diFormat == 
"hex") {
 
  514                                dmemMAUsPerLine, 
true);
 
  515                        } 
else if (diFormat == 
"bin2n") {
 
  519                                dmemMAUsPerLine, 
true);
 
  521                            assert(diFormat == 
"ascii" || diFormat == 
"");
 
  525                                dmemMAUsPerLine, 
true);
 
  529                        if (diFormat == 
"ascii" || piFormat == 
"") {
 
  530                            std::string dmemInitFile(
"dmem_");
 
  531                            dmemInitFile += as->
name() + 
"_init.img";
 
  533                                fileName, progeOutputDir, dmemInitFile);
 
  540        if (generateDecompressor) {
 
  542            if (!progeOutputDir.empty()) {
 
  555        int compressedInstructionWidth = imageGenerator.
imemMauWidth();
 
  556        if (!progeOutputDir.empty()) {
 
  564                createMauPkg(0,compressedInstructionWidth, temp, entityStr);
 
  573                createMauPkg(1,compressedInstructionWidth, temp, entityStr);
 
  576            createMauPkg(0,compressedInstructionWidth, entityStr + 
"_" +
 
  582        for (std::vector<Binary*>::iterator iter = tpefTable.begin();
 
  583             iter != tpefTable.end(); iter++) {
 
 
#define assert(condition)
 
const string VER_IMEM_MAU_PKG
 
int main(int argc, char *argv[])
 
void createCompressor(string fileName, ProgramImageGenerator &imageGenerator, string entityStr)
 
static bool isInstructionMemory(const TTAMachine::AddressSpace &as)
 
void parseParameter(const std::string ¶m, std::string ¶mName, std::string ¶mValue)
 
const string DECOMPRESSOR_FILE
 
const string IMEM_MAU_PKG
 
static Binary * loadTPEF(const std::string &tpefFile)
 
static Machine * loadMachine(const std::string &adfFile)
 
void copyImageToTb(const string &source, const string &progeDir, const string &newImage)
 
const string TB_DMEM_FILE
 
std::string programDataImageFile(const std::string &tpefFile, const std::string &format, const std::string &asName)
 
const int DEFAULT_IMEMWIDTH_IN_MAUS
 
void createMauPkg(int language, int imemMauWidth, string fileName, string entityNameStr)
 
std::string programImemImageFile(const std::string &tpefFile, const std::string &format)
 
const string TB_IMEM_FILE
 
static BinaryEncoding * loadBEM(const std::string &bemFile)
 
find Finds info of the inner loops in the program
 
static MachInfoCmdLineOptions options
 
TTAMachine::Machine * readMachine()
 
static void setCmdLineOptions(CmdLineOptions *options_)
 
static int verboseLevel()
 
static std::ostream & logStream()
 
BinaryEncoding * generate()
 
BinaryEncoding * readBinaryEncoding()
 
virtual int width(const TCEString &templateName) const
 
void parse(char *argv[], int argc)
 
virtual std::string argument(int index) const
 
virtual int numberOfArguments() const
 
std::vector< Parameter > ParameterTable
Table for passing plugin parameters.
 
std::string errorMessageStack(bool messagesOnly=false) const
 
std::string errorMessage() const
 
static bool createFile(const std::string &file)
 
static const std::string DIRECTORY_SEPARATOR
 
static std::string fileNameBody(const std::string &fileName)
 
static std::string fileOfPath(const std::string pathName)
 
static void copy(const std::string &source, const std::string &target)
 
static bool fileIsDirectory(const std::string fileName)
 
static bool fileIsWritable(const std::string fileName)
 
static bool fileIsCreatable(const std::string fileName)
 
static bool fileExists(const std::string fileName)
 
virtual void printHelp() const
 
void loadPrograms(TPEFMap programs)
 
void setDataStartOptions(CmdLineOptionParser *options)
 
static std::vector< std::string > availableCompressors()
 
std::map< std::string, TPEF::Binary * > TPEFMap
 
void generateDataImage(const std::string &programName, TPEF::Binary &program, const std::string &addressSpace, std::ostream &stream, OutputFormat format, int mausPerLine, bool usePregeneratedImage)
 
void setEntityName(const std::string &entity)
 
void loadCompressorPlugin(const std::string &fileName)
 
void loadCompressorParameters(CodeCompressorPlugin::ParameterTable parameters)
 
@ BINARY
Real binary format.
 
@ VHDL
Array as a Vhdl package.
 
@ BIN2N
Binary format padded to 2**n.
 
@ MIF
MIF Memory Initialization File.
 
@ ARRAY
ASCII 1's and 0's in array form.
 
@ ASCII
ASCII 1's and 0's.
 
@ COE
COE memory initialization format.
 
@ HEX
HEX memory initialization format.
 
static void printCompressorDescription(const std::string &fileName, std::ostream &stream)
 
void generateProgramImage(const std::string &programName, std::ostream &stream, OutputFormat format, int mausPerLine=0)
 
void generateDecompressor(std::ostream &stream, TCEString entityStr)
 
void loadMachine(const TTAMachine::Machine &machine)
 
void loadBEM(const BinaryEncoding &bem)
 
static Binary * readBinary(BinaryStream &stream)
 
virtual Machine * machine() const
 
virtual TCEString name() const
 
virtual AddressSpace * addressSpace() const
 
ComponentType * item(int index) const
 
virtual AddressSpaceNavigator addressSpaceNavigator() const
 
virtual ControlUnit * controlUnit() const
 
virtual boost::format text(int textId)
 
void setSourceFile(const std::string &fileName)