186 const std::string& programName,
187 std::ostream& stream,
191 if (mausPerLine < 0) {
192 string errorMsg =
"Negative number of MAUs printed per line.";
200 size_t instructionCount =
205 "%s: %d instructions\n"
206 "uncompressed total size %d bits (%d bytes),\n")
207 % programName % instructionCount
208 % (uncompressedWidth * instructionCount)
209 %
int(std::ceil(uncompressedWidth * instructionCount / 8.0))).
214 "compressed total size %d bits (%d bytes)\n")
215 % programBits->size()
216 % size_t(std::ceil(programBits->size() / 8.0))).str();
229 std::size_t NOPCount = maxMoves - moves;
233 "number of NOP moves: %d (%.1f%% of total move slots)\n")
234 % NOPCount % (float(NOPCount) * 100 / maxMoves)).str();
238 int totalImmediates = 0;
239 int totalLongImmediates = 0;
240 std::set<int> allImmediates;
241 std::set<int> programAddresses;
242 std::set<int> dataAddresses;
244 for (
int m = 0; m < prog.
moveCount(); ++m) {
249 allImmediates.insert(value);
251 dataAddresses.insert(value);
253 programAddresses.insert(value);
258 for (TTAProgram::Program::InstructionVector::const_iterator i =
259 instructions.begin(); i != instructions.end(); ++i) {
265 ++totalLongImmediates;
266 allImmediates.insert(value);
268 dataAddresses.insert(value);
270 programAddresses.insert(value);
277 int totalFullNOPs = 0;
278 int totalTwoConsNOPs = 0;
279 int totalThreeConsNOPs = 0;
280 int totalFourConsNOPs = 0;
281 bool oneConsecutiveNOP =
false;
282 bool twoConsecutiveNOPs =
false;
283 bool threeConsecutiveNOPs =
false;
284 bool fourConsecutiveNOPs =
false;
287 for (TTAProgram::Program::InstructionVector::const_iterator i =
288 instructions.begin(); i != instructions.end(); ++i) {
290 if (instruction.
isNOP()) {
297 if (fourConsecutiveNOPs) {
300 }
else if (threeConsecutiveNOPs) {
301 fourConsecutiveNOPs =
true;
303 --totalThreeConsNOPs;
304 }
else if (twoConsecutiveNOPs) {
305 threeConsecutiveNOPs =
true;
306 ++totalThreeConsNOPs;
308 }
else if (oneConsecutiveNOP) {
309 twoConsecutiveNOPs =
true;
312 oneConsecutiveNOP =
true;
314 oneConsecutiveNOP =
false;
315 twoConsecutiveNOPs =
false;
316 threeConsecutiveNOPs =
false;
317 fourConsecutiveNOPs =
false;
324 "total immediates: %d (long %.1f%%), "
325 "different immediate values: %d,\n"
326 "instr. addresses %d (%.1f%%), "
327 "data addresses %d (%.1f%%),\n"
328 "total full instruction NOPs: %d (%.1f%% of instructions),\n"
329 "two consecutive full instruction NOPs: %d,\n"
330 "three consecutive full instruction NOPs: %d,\n"
331 "four consecutive full instruction NOPs: %d\n")
333 % (totalLongImmediates * 100.0 / totalImmediates)
334 % allImmediates.size() % programAddresses.size()
335 % (programAddresses.size() * 100.0 / allImmediates.size())
336 % dataAddresses.size()
337 % (dataAddresses.size() * 100.0 / allImmediates.size())
339 % (totalFullNOPs * 100.0 / instructionCount)
349 }
else if (format ==
ASCII) {
352 if (mausPerLine > 1) {
357 }
else if (format ==
ARRAY) {
358 if (mausPerLine > 1) {
363 }
else if (format ==
MIF) {
365 }
else if (format ==
VHDL) {
367 }
else if (format ==
COE) {
369 }
else if (format ==
HEX) {
371 }
else if (format ==
BIN2N) {
406 const std::string& addressSpace, std::ostream& stream,
OutputFormat format,
407 int mausPerLine,
bool usePregeneratedImage) {
408 if (mausPerLine < 1) {
409 string errorMsg =
"Data memory width in MAUs must be positive.";
422 if (!navigator.
hasItem(addressSpace)) {
423 const string procName =
"ProgramImageGenerator::generateDataImage";
427 int memWidth = mausPerLine * as->
width();
429 if (!usePregeneratedImage) {
445 unsigned int lineOffset = dataBits.size();
454 while (lineOffset < dataBits.size()) {
458 if ((dataBits.size() % memWidth &&
459 lineOffset > (dataBits.size() - memWidth))) {
460 unsigned int preferredSize =
461 ((dataBits.size() / (memWidth))+1) *
463 while (dataBits.size() < preferredSize) {
464 dataBits.push_back(0);
468 for (
int k = 0; k < mausPerLine/2; k++) {
469 int bitOffset0 = k * as->
width();
470 int bitOffset1 = (mausPerLine-k-1) * as->
width();
472 for (
int j = 0; j < as->
width(); j++) {
473 bool bit0 = dataBits[lineOffset+bitOffset0 + j];
474 dataBits[lineOffset+bitOffset0+j] =
475 dataBits[lineOffset+bitOffset1+j];
476 dataBits[lineOffset+bitOffset1+j] = bit0;
479 lineOffset += memWidth;
486 }
else if (format ==
ASCII) {
488 }
else if (format ==
ARRAY) {
490 }
else if (format ==
MIF) {
492 }
else if (format ==
VHDL) {
495 }
else if (format ==
COE) {
497 }
else if (format ==
HEX) {
499 }
else if (format ==
BIN2N) {
512 const std::string& addressSpace,
531 unsigned int zeroFillStart = 0;
537 zeroFillStart = dataBits.size() / 8;
540 for (
AddressImage i = zeroFillStart; i < startingAddress; i++) {
543 if (zeroFillStart > startingAddress) {
545 __FILE__,__LINE__,
__func__,
"Illegal order of data sections.");
549 Word sectionLength = dataSection.
length();
550 for (Word offset = 0; offset < sectionLength;) {
554 Word indexOfInstruction =
564 unsigned int num = memAddress;
565 memAddress = ((num>>24)&0xff) |
566 ((num<<8)&0xff0000) |
568 ((num<<24)&0xff000000);
574 "Program image must be generated before "
575 "generating data image.";
577 __FILE__, __LINE__,
__func__, errorMsg);
580 Byte byte = dataSection.
byte(offset);
601 std::ostream& stream,
616std::vector<std::string>
620 std::vector<string> files;
621 for (std::vector<string>::const_iterator iter = paths.begin();
622 iter != paths.end(); iter++) {
626 for (std::vector<string>::const_iterator iter =
628 iter != filesInPath.end(); iter++) {
631 files.push_back(*iter);
654 const std::string& fileName, std::ostream& stream) {
657 fileName, pluginTool);
675 const std::string& fileName,
PluginTools& pluginTool) {
677 for (vector<string>::const_iterator iter = searchPaths.begin();
678 iter != searchPaths.end(); iter++) {
687 "create_code_compressor", pluginCreator, fileName);
689 return pluginCreator();
705 Word dataSectionOffset)
const {
716 for (Word elemIndex = 0; elemIndex < elemCount; elemIndex++) {
719 assert(relocElem != NULL);
723 if (location->
offset() == dataSectionOffset) {
727 if (destination != NULL) {
765 "Data-start option is used "
766 "to set the global data start address for the address spaces. "
767 "The default is the first address of the address space. "
768 "data-start option must either be just the start "
769 "of the default address space (a single unsigned integer), "
770 "or a list consisting of pairs: "
771 "<Address-Space Name>,<Address-Space Start>");
785 for (
int i = 1; i <= size; i += 2) {
787 if (as_name == aSpace) {
807 for (
int i = 1; i <= size; i += 2) {
809 if (as_name == aSpace) {
#define abortWithError(message)
#define assert(condition)
UInt32 AddressImage
Type for storing addresses to memory image.
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
static MachInfoCmdLineOptions options
static int verboseLevel()
static std::ostream & logStream()
virtual int width(const TCEString &templateName) const
virtual void writeImage(std::ostream &stream) const =0
void pushBack(long long unsigned int integer, int size)
virtual int listSize() const
virtual std::string String(int index=0) const
void setBEM(const BinaryEncoding &bem)
void setParameters(ParameterTable parameters)
void setPrograms(std::map< std::string, TPEF::Binary * > &programs)
const TTAMachine::Machine & machine() const
TTAProgram::Program & currentProgram() const
virtual InstructionBitVector * compress(const std::string &program)=0
unsigned int memoryAddress(const TTAProgram::Instruction &instruction) const
const BinaryEncoding & binaryEncoding() const
void setMachine(const TTAMachine::Machine &machine)
virtual void printDescription(std::ostream &stream)=0
virtual void generateDecompressor(std::ostream &stream, TCEString entityStr)=0
std::vector< Parameter > ParameterTable
Table for passing plugin parameters.
static ULongWord toUnsignedLong(const T &source)
static std::vector< std::string > codeCompressorPaths(bool libraryPathsOnly=false)
std::string errorMessage() const
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
static std::string fileExtension(const std::string &fileName)
static bool fileIsDirectory(const std::string fileName)
static bool fileExists(const std::string fileName)
TPEF::InstructionElement * relocTarget(const TPEF::Binary &program, const TPEF::DataSection &dataSection, Word dataSectionOffset) const
static CodeCompressorPlugin * createCompressor(const std::string &fileName, PluginTools &pluginTool)
bool isDataStartSet(std::string aSpace) const
std::string entityName_
Toplevel entity name.
void loadPrograms(TPEFMap programs)
void setDataStartOptions(CmdLineOptionParser *options)
virtual ~ProgramImageGenerator()
static std::vector< std::string > availableCompressors()
CodeCompressorPlugin * compressor_
The code compressor.
void writeDataSection(TPEF::Binary &program, BitVector &bitVector, const std::string &addressSpace, TPEF::Section §ion)
CmdLineOptionParser * dataStartOptions_
uint64_t dataStartAddress(std::string aSpace) const
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)
static const std::string DATA_START_DESC
OutputFormat
Different output formats of images.
@ 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)
PluginTools pluginTool_
The plugin tool.
CodeCompressorPlugin & compressor()
void loadBEM(const BinaryEncoding &bem)
SIntWord sIntWordValue() const
SectionOffset offset() const
Word indexOfInstruction(const InstructionElement &elem) const
virtual Word length() const
virtual Byte byte(const Chunk *chunk) const
SectionElement * destination() const
SectionElement * location() const
Section * referencedSection() const
AddressImage startingAddress() const
@ ST_DATA
Initialized data section.
@ ST_LEDATA
Initialized little endian data section.
@ ST_RELOC
Relocation section.
SectionElement * element(Word index) const
Word elementCount() const
ASpaceElement * aSpace() const
std::string chunk2String(const Chunk *chunk) const
virtual int width() const
virtual AddressSpace * addressSpace() const
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
bool isLittleEndian() const
virtual BusNavigator busNavigator() const
virtual AddressSpaceNavigator addressSpaceNavigator() const
virtual ControlUnit * controlUnit() const
int immediateCount() const
Immediate & immediate(int i) const
Terminal & source() const
std::vector< Instruction * > InstructionVector
Vector for instructions.
const Move & moveAt(int number) const
TTAMachine::Machine & targetProcessor() const
Instruction & instructionAt(InstructionAddress address) const
int instructionCount() const
InstructionVector instructionVector() const
virtual SimValue value() const
virtual bool isAddress() const
virtual bool isInstructionAddress() const
virtual bool isImmediate() const