OpenASIP  2.0
ProgramImageGenerator.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ProgramImageGenerator.cc
26  *
27  * Implementation of ProgramImageGenerator class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Otto Esko 2008-2009 (otto.esko-no.spam-tut.fi)
31  * @author Pekka Jääskeläinen 2009 (pekka.jaaskelainen-no.spam-tut.fi)
32  * @author Otto Esko 2010(otto.esko-no.spam-tut.fi)
33  * @author Pekka Jääskeläinen 2011
34  * @note rating: red
35  */
36 
37 #include <vector>
38 #include <string>
39 #include <cmath>
40 
41 #include "ProgramImageGenerator.hh"
44 #include "RawImageWriter.hh"
45 #include "MifImageWriter.hh"
46 #include "VhdlImageWriter.hh"
48 #include "CoeImageWriter.hh"
49 #include "HexImageWriter.hh"
50 #include "Bin2nImageWriter.hh"
52 #include "InstructionBitVector.hh"
53 #include "CodeCompressorPlugin.hh"
54 #include "DefaultCompressor.hh"
55 #include "PIGTextGenerator.hh"
56 
57 #include "ControlUnit.hh"
58 #include "BinaryEncoding.hh"
59 #include "StringSection.hh"
60 #include "CodeSection.hh"
61 #include "RelocSection.hh"
62 #include "RelocElement.hh"
63 #include "Binary.hh"
64 #include "InstructionElement.hh"
65 #include "Program.hh"
66 #include "Move.hh"
67 #include "Terminal.hh"
68 #include "TerminalImmediate.hh"
69 #include "Immediate.hh"
70 #include "Machine.hh"
71 
72 #include "PluginTools.hh"
73 #include "Environment.hh"
74 #include "FileSystem.hh"
75 
76 using namespace TTAMachine;
77 using namespace TPEF;
78 using namespace TTAProgram;
79 
80 using std::vector;
81 using std::string;
82 using boost::format;
83 
84 /**
85  * The constructor.
86  *
87  * @param program The program.
88  * @param bem The binary encoding map.
89  * @param machine The machine.
90  */
92  compressor_(new DEFAULT_Compressor()), entityName_("") {
93 }
94 
95 
96 /**
97  * The destructor.
98  */
100  delete compressor_;
101 }
102 
103 
104 /**
105  * Loads the code compressor plugin from the given object file.
106  *
107  * @param fileName The file name.
108  * @exception FileNotFound If the given file is not found from the search
109  * paths of code compressor plugins.
110  * @exception DynamicLibraryException If the dynamic library cannot be
111  * opened.
112  */
113 void
114 ProgramImageGenerator::loadCompressorPlugin(const std::string& fileName) {
115  CodeCompressorPlugin* newCompressor = createCompressor(
116  fileName, pluginTool_);
117  delete compressor_;
118  compressor_ = newCompressor;
119 }
120 
121 /**
122  * Loads the given code compressor plugin parameters to the plugin.
123  *
124  * @param parameters The parameters.
125  */
126 void
129 
130  compressor_->setParameters(parameters);
131 }
132 
133 
134 /**
135  * Loads the programs to be generated to the compressor plugin.
136  *
137  * @param programs The programs.
138  */
139 void
141  compressor_->setPrograms(programs);
142 }
143 
144 
145 /**
146  * Sets the machine which executes the programs.
147  *
148  * @param machine The machine.
149  */
150 void
153 }
154 
155 
156 /**
157  * Sets the binary encoding map used when generating the program image.
158  *
159  * @param bem The binary encoding map.
160  */
161 void
163  compressor_->setBEM(bem);
164 }
165 
166 
167 /**
168  * Generates the program image to the given output stream in the given
169  * format.
170  *
171  * If the output is in ASCII format, mausPerLine parameter defines the number
172  * of MAUs printed per line. If 0 is given, each instruction is printed on
173  * different line.
174  *
175  * @param stream The output stream.
176  * @param format The output format.
177  * @param mausPerLine If the output is ASCII format, defines the number of
178  MAUs printed per line.
179  * @exception InvalidData If machine or BEM is not loaded or if they are
180  * erroneous or if the given program is not in the
181  * program set.
182  * @exception OutOfRange If mausPerLine is negative.
183  */
184 void
186  const std::string& programName,
187  std::ostream& stream,
188  OutputFormat format,
189  int mausPerLine) {
190 
191  if (mausPerLine < 0) {
192  string errorMsg = "Negative number of MAUs printed per line.";
193  throw OutOfRange(__FILE__, __LINE__, __func__, errorMsg);
194  }
195  InstructionBitVector* programBits = compressor_->compress(programName);
196  int mau = compressor_->machine().controlUnit()->addressSpace()->width();
197  BitImageWriter* writer = NULL;
198 
199  if (Application::verboseLevel() > 0) {
200  size_t instructionCount =
202  size_t uncompressedWidth = compressor_->binaryEncoding().width();
204  << (boost::format(
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))).
210  str();
211 
213  << (boost::format(
214  "compressed total size %d bits (%d bytes)\n")
215  % programBits->size()
216  % size_t(std::ceil(programBits->size() / 8.0))).str();
217 
218  // count some stats from the program that affect instruction
219  // memory usage
221  TTAMachine::Machine mach = prog.targetProcessor();
222 
224  prog.instructionVector();
225 
226  std::size_t moveSlots = mach.busNavigator().count();
227  std::size_t maxMoves = moveSlots * prog.instructionCount();
228  std::size_t moves = prog.moveCount();
229  std::size_t NOPCount = maxMoves - moves;
230 
232  << (boost::format(
233  "number of NOP moves: %d (%.1f%% of total move slots)\n")
234  % NOPCount % (float(NOPCount) * 100 / maxMoves)).str();
235 
236 
237  // immediate stats
238  int totalImmediates = 0;
239  int totalLongImmediates = 0;
240  std::set<int> allImmediates;
241  std::set<int> programAddresses;
242  std::set<int> dataAddresses;
243 
244  for (int m = 0; m < prog.moveCount(); ++m) {
245  const TTAProgram::Move& move = prog.moveAt(m);
246  if (move.source().isImmediate()) {
247  const auto value = move.source().value().sIntWordValue();
248  ++totalImmediates;
249  allImmediates.insert(value);
250  if (move.source().isAddress()) {
251  dataAddresses.insert(value);
252  } else if (move.source().isInstructionAddress()) {
253  programAddresses.insert(value);
254  }
255  }
256  }
257  // find the long immediates also
258  for (TTAProgram::Program::InstructionVector::const_iterator i =
259  instructions.begin(); i != instructions.end(); ++i) {
260  const TTAProgram::Instruction& instruction = **i;
261  for (int imm = 0; imm < instruction.immediateCount(); ++imm) {
262  const Immediate& immediate = instruction.immediate(imm);
263  const auto value = immediate.value().value().sIntWordValue();
264  ++totalImmediates;
265  ++totalLongImmediates;
266  allImmediates.insert(value);
267  if (immediate.value().isAddress()) {
268  dataAddresses.insert(value);
269  } else if (immediate.value().isInstructionAddress()) {
270  programAddresses.insert(value);
271  }
272  }
273 
274  }
275 
276  // variables for NOP counting
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;
285 
286  // Find information about NOP instructions from program's instr.vectors
287  for (TTAProgram::Program::InstructionVector::const_iterator i =
288  instructions.begin(); i != instructions.end(); ++i) {
289  const TTAProgram::Instruction& instruction = **i;
290  if (instruction.isNOP()) {
291 
292  // Increase count for each single full instruction NOP
293  ++totalFullNOPs;
294 
295  // Find full instruction NOP groups iteratively, ie. if there
296  // are 4 NOPs in a row, decrease count for 3 NOPs, etc.
297  if (fourConsecutiveNOPs) {
298  // We don't change count beyond 4 or more consecutive
299  // NOP instructions.
300  } else if (threeConsecutiveNOPs) {
301  fourConsecutiveNOPs = true;
302  ++totalFourConsNOPs;
303  --totalThreeConsNOPs; // Actually 4 NOPs in a row, not 3
304  } else if (twoConsecutiveNOPs) {
305  threeConsecutiveNOPs = true;
306  ++totalThreeConsNOPs;
307  --totalTwoConsNOPs; // Actually 3 NOPs in a row, not 2
308  } else if (oneConsecutiveNOP) {
309  twoConsecutiveNOPs = true;
310  ++totalTwoConsNOPs;
311  }
312  oneConsecutiveNOP = true;
313  } else {
314  oneConsecutiveNOP = false;
315  twoConsecutiveNOPs = false;
316  threeConsecutiveNOPs = false;
317  fourConsecutiveNOPs = false;
318  }
319  }
320 
321  // Print information about immediates, addresses and NOPs
323  << (boost::format(
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")
332  % totalImmediates
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())
338  % totalFullNOPs
339  % (totalFullNOPs * 100.0 / instructionCount)
340  % totalTwoConsNOPs
341  % totalThreeConsNOPs
342  % totalFourConsNOPs)
343  .str();
344  }
345 
346 
347  if (format == BINARY) {
348  writer = new RawImageWriter(*programBits);
349  } else if (format == ASCII) {
350  // change this to "mausPerLine > 0" when mau == instructionwidth
351  // does not apply anymore
352  if (mausPerLine > 1) {
353  writer = new AsciiImageWriter(*programBits, mau * mausPerLine);
354  } else {
355  writer = new AsciiProgramImageWriter(*programBits);
356  }
357  } else if (format == ARRAY) {
358  if (mausPerLine > 1) {
359  writer = new ArrayImageWriter(*programBits, mau * mausPerLine);
360  } else {
361  writer = new ArrayProgramImageWriter(*programBits);
362  }
363  } else if (format == MIF) {
364  writer = new MifImageWriter(*programBits, mau);
365  } else if (format == VHDL) {
366  writer = new VhdlProgramImageWriter(*programBits, entityName_);
367  } else if (format == COE) {
368  writer = new CoeImageWriter(*programBits, mau);
369  } else if (format == HEX) {
370  writer = new HexImageWriter(*programBits, mau);
371  } else if (format == BIN2N) {
372  writer = new Bin2nProgramImageWriter(*programBits);
373  } else {
374  assert(false);
375  }
376 
377 
378  writer->writeImage(stream);
379 
380  delete writer;
381  delete programBits;
382 }
383 
384 
385 /**
386  * Generates the data image of the given address space to the given
387  * output stream in the given format.
388  *
389  * @param program The program of which data image is generated.
390  * @param addressSpace The address space.
391  * @param stream The output stream.
392  * @param format The output format.
393  * @param mausPerLine Tells how many MAUs of data is generated on one line.
394  * @param usePregeneratedImage Tells whether use the program image that was
395  * previously generated for relocation of data
396  * elements.
397  * @exception InvalidData If tried to use pregenerated program but it has not
398  * been generated or if the given program is not in
399  * the program set loaded or if machine is not loaded
400  * or if is does not have the given address space.
401  * @exception OutOfRange If the given MAUs per line is not positive.
402  */
403 void
405  const std::string& programName, TPEF::Binary& program,
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.";
410  throw OutOfRange(__FILE__, __LINE__, __func__, errorMsg);
411  }
412 
413  const Machine* mach = NULL;
414  try {
415  mach = &compressor_->machine();
416  } catch (const Exception& e) {
417  throw InvalidData(__FILE__, __LINE__, __func__, e.errorMessage());
418  }
419 
420  Machine::AddressSpaceNavigator navigator =
421  mach->addressSpaceNavigator();
422  if (!navigator.hasItem(addressSpace)) {
423  const string procName = "ProgramImageGenerator::generateDataImage";
424  throw InstanceNotFound(__FILE__, __LINE__, procName);
425  }
426  AddressSpace* as = navigator.item(addressSpace);
427  int memWidth = mausPerLine * as->width();
428 
429  if (!usePregeneratedImage) {
430  InstructionBitVector* programBits = compressor_->compress(programName);
431  delete programBits;
432  }
433 
434  BitVector dataBits;
435 
436  // TODO: LEDATA? if le adf?
437  for (unsigned int i = 0; i < program.sectionCount(Section::ST_DATA);
438  i++) {
439  writeDataSection(program, dataBits, addressSpace,
440  *program.section(Section::ST_DATA, i));
441  }
442  for (unsigned int i = 0; i < program.sectionCount(Section::ST_LEDATA);
443  i++) {
444 
445  unsigned int lineOffset = dataBits.size(); // start afer previous
446  // this writes data into the databits struct, not from it!
447  writeDataSection(program, dataBits, addressSpace,
448  *program.section(Section::ST_LEDATA, i));
449 
450  // The stupid binary images are in big-endian bitness
451  // format(bit 0 == highest bit).
452  // Have to convert LE data into nasty mixed endian for
453  // initialization with those tools.
454  while (lineOffset < dataBits.size()) {
455  // Pad to full line width.
456  // if need padding (size not divisible by mem width)
457  // and we are at last iter of the loop, add pad.
458  if ((dataBits.size() % memWidth &&
459  lineOffset > (dataBits.size() - memWidth))) {
460  unsigned int preferredSize =
461  ((dataBits.size() / (memWidth))+1) *
462  (memWidth);
463  while (dataBits.size() < preferredSize) {
464  dataBits.push_back(0);
465  }
466  }
467 
468  for (int k = 0; k < mausPerLine/2; k++) {
469  int bitOffset0 = k * as->width();
470  int bitOffset1 = (mausPerLine-k-1) * as->width();
471  // swap bytes of one MAU.
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;
477  }
478  }
479  lineOffset += memWidth;
480  }
481  }
482 
483  BitImageWriter* writer = NULL;
484  if (format == BINARY) {
485  writer = new RawImageWriter(dataBits);
486  } else if (format == ASCII) {
487  writer = new AsciiImageWriter(dataBits, as->width() * mausPerLine);
488  } else if (format == ARRAY) {
489  writer = new ArrayImageWriter(dataBits, as->width() * mausPerLine);
490  } else if (format == MIF) {
491  writer = new MifImageWriter(dataBits, as->width() * mausPerLine);
492  } else if (format == VHDL) {
493  writer = new VhdlImageWriter(
494  dataBits, as->width() * mausPerLine, entityName_);
495  } else if (format == COE) {
496  writer = new CoeImageWriter(dataBits, as->width() * mausPerLine);
497  } else if (format == HEX) {
498  writer = new HexImageWriter(dataBits, as->width() * mausPerLine);
499  } else if (format == BIN2N) {
500  writer = new Bin2nImageWriter(dataBits, as->width() * mausPerLine);
501  } else {
502  assert(false);
503  }
504 
505  writer->writeImage(stream);
506  delete writer;
507 }
508 
509 void
511  TPEF::Binary& program, BitVector& dataBits,
512  const std::string& addressSpace,
513  Section& section) {
514 
515  // get the data section
516  StringSection* stringSection = program.strings();
517 
518  CodeSection* codeSection = dynamic_cast<CodeSection*>(
519  program.section(Section::ST_CODE, 0));
520 
521  if (stringSection->chunk2String(section.aSpace()->name()) ==
522  addressSpace) {
523 
524  // correct data section found
525  DataSection& dataSection = dynamic_cast<DataSection&>(section);
526 
527  // fill the beginning of the data image with zeros
528  AddressImage startingAddress = dataSection.startingAddress();
529  // If we already have put something, fill the correct number,
530  // not from 0.
531  unsigned int zeroFillStart = dataBits.size() / 8; // 8 bits per byte
532  for (AddressImage i = zeroFillStart; i < startingAddress; i++) {
533  dataBits.pushBack(0, 8);
534  }
535  if (zeroFillStart > startingAddress) {
536  throw InvalidData(
537  __FILE__,__LINE__,__func__, "Illegal order of data sections.");
538  }
539 
540  // fill the data
541  Word sectionLength = dataSection.length();
542  for (Word offset = 0; offset < sectionLength;) {
544  this->relocTarget(program, dataSection, offset);
545  if (relocTarget != NULL) {
546  Word indexOfInstruction =
547  codeSection->indexOfInstruction(*relocTarget);
548  Instruction& instruction =
550  indexOfInstruction);
551  try {
552  unsigned int memAddress = compressor_->memoryAddress(
553  instruction);
555  // Byteswap the pointer
556  unsigned int num = memAddress;
557  memAddress = ((num>>24)&0xff) |
558  ((num<<8)&0xff0000) |
559  ((num>>8)&0xff00) |
560  ((num<<24)&0xff000000);
561  }
562  dataBits.pushBack(memAddress, 32);
563  offset += 4;
564  } catch (const Exception& e) {
565  string errorMsg =
566  "Program image must be generated before "
567  "generating data image.";
568  throw InvalidData(
569  __FILE__, __LINE__, __func__, errorMsg);
570  }
571  } else {
572  Byte byte = dataSection.byte(offset);
573  dataBits.pushBack(byte, 8);
574  offset++;
575  }
576  }
577  }
578 }
579 
580 
581 /**
582  * Generates the decompressor to the given output stream.
583  *
584  * Note! The program image should have been generated at first. Otherwise
585  * this may not function properly.
586  *
587  * @param stream The output stream.
588  * @param entityStr The entity string used to make HDL entity/component
589  * names unique for multiprocessor designs.
590  */
591 void
593  std::ostream& stream,
594  TCEString entityStr) {
595  if (compressor_ == NULL) {
596  return;
597  } else {
598  compressor_->generateDecompressor(stream, entityStr);
599  }
600 }
601 
602 
603 /**
604  * Returns a vector containing paths to the compressors available.
605  *
606  * @return The vector.
607  */
608 std::vector<std::string>
610 
611  std::vector<string> paths = Environment::codeCompressorPaths();
612  std::vector<string> files;
613  for (std::vector<string>::const_iterator iter = paths.begin();
614  iter != paths.end(); iter++) {
615  if (FileSystem::fileExists(*iter)) {
616  std::vector<string> filesInPath = FileSystem::directoryContents(
617  *iter);
618  for (std::vector<string>::const_iterator iter =
619  filesInPath.begin();
620  iter != filesInPath.end(); iter++) {
621  if (!FileSystem::fileIsDirectory(*iter) &&
622  FileSystem::fileExtension(*iter) == ".so") {
623  files.push_back(*iter);
624  }
625  }
626  }
627  }
628 
629  return files;
630 }
631 
632 
633 /**
634  * Loads the code compressor plugin from the given file and prints its
635  * description to the given stream.
636  *
637  * @param fileName The code compressor plugin file.
638  * @param stream The output stream.
639  * @exception FileNotFound If the given file is not found from the search
640  * paths of code compressor plugins.
641  * @exception DynamicLibraryException If the dynamic library cannot be
642  * opened.
643  */
644 void
646  const std::string& fileName, std::ostream& stream) {
647  PluginTools pluginTool;
649  fileName, pluginTool);
650  compressor->printDescription(stream);
651  delete compressor;
652 }
653 
654 /**
655  * Creates the code compressor from the given dynamic module.
656  *
657  * @param fileName Name of the file.
658  * @param pluginTool The plugin tool to use.
659  * @return The newly created code compressor plugin.
660  * @exception FileNotFound If the given file is not found from the search
661  * paths of code compressor plugins.
662  * @exception DynamicLibraryException If the dynamic library cannot be
663  * opened.
664  */
667  const std::string& fileName, PluginTools& pluginTool) {
668  vector<string> searchPaths = Environment::codeCompressorPaths();
669  for (vector<string>::const_iterator iter = searchPaths.begin();
670  iter != searchPaths.end(); iter++) {
671  if (FileSystem::fileExists(*iter)) {
672  pluginTool.addSearchPath(*iter);
673  }
674  }
675 
676  pluginTool.registerModule(fileName);
677  CodeCompressorPlugin* (*pluginCreator)();
678  pluginTool.importSymbol(
679  "create_code_compressor", pluginCreator, fileName);
680 
681  return pluginCreator();
682 }
683 
684 /**
685  * Returns an InstructionElement that is relocation target of the data in
686  * data section at the given offset. Returns NULL if the data doesn't need
687  * to be altered.
688  *
689  * @param dataSection The data section,
690  * @param dataSectionOffset The offset.
691  * @return The InstructionElement or NULL.
692  */
695  const TPEF::Binary& program,
696  const TPEF::DataSection& dataSection,
697  Word dataSectionOffset) const {
698 
699  // find the correct reloc section
700  for (unsigned int i = 0; i < program.sectionCount(Section::ST_RELOC);
701  i++) {
702  RelocSection* section = dynamic_cast<RelocSection*>(
703  program.section(Section::ST_RELOC, i));
704  assert(section != NULL);
705  if (section->referencedSection() == &dataSection) {
706  // correct reloc section found
707  Word elemCount = section->elementCount();
708  for (Word elemIndex = 0; elemIndex < elemCount; elemIndex++) {
709  RelocElement* relocElem = dynamic_cast<RelocElement*>(
710  section->element(elemIndex));
711  assert(relocElem != NULL);
712  Chunk* location = dynamic_cast<Chunk*>(
713  relocElem->location());
714  assert(location != NULL);
715  if (location->offset() == dataSectionOffset) {
716  InstructionElement* destination =
717  dynamic_cast<InstructionElement*>(
718  relocElem->destination());
719  if (destination != NULL) {
720  return destination;
721  } else {
722  return NULL;
723  }
724  }
725  }
726  }
727  }
728 
729  return NULL;
730 }
731 
732 /**
733  * Asks the instruction memory mau width from code compressor plugin and
734  * returns it
735  *
736  * @return instruction memory mau width
737  */
738 int
740 
741  return compressor_->imemMauWidth();
742 }
743 
744 
745 void
746 ProgramImageGenerator::setEntityName(const std::string& entity) {
747 
748  entityName_ = entity;
749 }
ProgramImageGenerator::generateProgramImage
void generateProgramImage(const std::string &programName, std::ostream &stream, OutputFormat format, int mausPerLine=0)
Definition: ProgramImageGenerator.cc:185
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Immediate::value
TerminalImmediate & value() const
Definition: Immediate.cc:103
CodeCompressorPlugin::generateDecompressor
virtual void generateDecompressor(std::ostream &stream, TCEString entityStr)=0
TTAProgram::Program
Definition: Program.hh:63
CodeCompressorPlugin::printDescription
virtual void printDescription(std::ostream &stream)=0
TPEF::DataSection::byte
virtual Byte byte(const Chunk *chunk) const
Definition: DataSection.cc:114
BinaryEncoding
Definition: BinaryEncoding.hh:61
ProgramImageGenerator::availableCompressors
static std::vector< std::string > availableCompressors()
Definition: ProgramImageGenerator.cc:609
TPEF::Section::aSpace
ASpaceElement * aSpace() const
TTAProgram::Instruction::isNOP
bool isNOP() const
Definition: Instruction.hh:90
FileSystem.hh
InstructionBitVector.hh
ProgramImageGenerator::loadBEM
void loadBEM(const BinaryEncoding &bem)
Definition: ProgramImageGenerator.cc:162
RawImageWriter.hh
ProgramImageGenerator::loadCompressorParameters
void loadCompressorParameters(CodeCompressorPlugin::ParameterTable parameters)
Definition: ProgramImageGenerator.cc:127
DefaultCompressor.hh
TTAProgram::Terminal::isInstructionAddress
virtual bool isInstructionAddress() const
Definition: Terminal.cc:87
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
TTAProgram::Terminal::isAddress
virtual bool isAddress() const
Definition: Terminal.cc:75
PluginTools
Definition: PluginTools.hh:53
TPEF::InstructionElement
Definition: InstructionElement.hh:77
BitVector
Definition: BitVector.hh:44
TPEF::Binary
Definition: Binary.hh:49
RawImageWriter
Definition: RawImageWriter.hh:43
ProgramImageGenerator::ASCII
@ ASCII
ASCII 1's and 0's.
Definition: ProgramImageGenerator.hh:73
TTAProgram::Instruction
Definition: Instruction.hh:57
OutOfRange
Definition: Exception.hh:320
ProgramImageGenerator::~ProgramImageGenerator
virtual ~ProgramImageGenerator()
Definition: ProgramImageGenerator.cc:99
VhdlImageWriter.hh
ProgramImageGenerator::createCompressor
static CodeCompressorPlugin * createCompressor(const std::string &fileName, PluginTools &pluginTool)
Definition: ProgramImageGenerator.cc:666
CoeImageWriter.hh
BitImageWriter
Definition: BitImageWriter.hh:41
TTAProgram::Program::moveAt
const Move & moveAt(int number) const
Definition: Program.cc:480
CodeCompressorPlugin::compress
virtual InstructionBitVector * compress(const std::string &program)=0
CodeCompressorPlugin::setBEM
void setBEM(const BinaryEncoding &bem)
Definition: CodeCompressorPlugin.cc:192
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
TPEF::DataSection
Definition: DataSection.hh:52
TTAMachine::FunctionUnit::addressSpace
virtual AddressSpace * addressSpace() const
Definition: FunctionUnit.cc:580
TPEF::StringSection::chunk2String
std::string chunk2String(const Chunk *chunk) const
Definition: StringSection.cc:72
TPEF::RelocSection::referencedSection
Section * referencedSection() const
AsciiProgramImageWriter
Definition: AsciiProgramImageWriter.hh:43
InstructionElement.hh
Terminal.hh
ProgramImageGenerator::loadPrograms
void loadPrograms(TPEFMap programs)
Definition: ProgramImageGenerator.cc:140
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
StringSection.hh
Byte
unsigned char Byte
Definition: BaseType.hh:116
TTAMachine::Machine::Navigator::count
int count() const
ProgramImageGenerator::loadCompressorPlugin
void loadCompressorPlugin(const std::string &fileName)
Definition: ProgramImageGenerator.cc:114
ProgramImageGenerator::printCompressorDescription
static void printCompressorDescription(const std::string &fileName, std::ostream &stream)
Definition: ProgramImageGenerator.cc:645
ProgramImageGenerator::relocTarget
TPEF::InstructionElement * relocTarget(const TPEF::Binary &program, const TPEF::DataSection &dataSection, Word dataSectionOffset) const
Definition: ProgramImageGenerator.cc:694
CodeCompressorPlugin::setPrograms
void setPrograms(std::map< std::string, TPEF::Binary * > &programs)
Definition: CodeCompressorPlugin.cc:144
MifImageWriter
Definition: MifImageWriter.hh:17
TPEF::RelocSection
Definition: RelocSection.hh:47
ProgramImageGenerator::MIF
@ MIF
MIF Memory Initialization File.
Definition: ProgramImageGenerator.hh:75
TTAProgram::Program::InstructionVector
std::vector< Instruction * > InstructionVector
Vector for instructions.
Definition: Program.hh:66
TPEF::Section
Definition: Section.hh:64
TPEF::StringSection
Definition: StringSection.hh:48
ProgramImageGenerator::HEX
@ HEX
HEX memory initialization format.
Definition: ProgramImageGenerator.hh:78
TTAMachine::Machine::isLittleEndian
bool isLittleEndian() const
Definition: Machine.hh:258
Bin2nProgramImageWriter
Definition: Bin2nProgramImageWriter.hh:45
ArrayProgramImageWriter.hh
BitVector::pushBack
void pushBack(long long unsigned int integer, int size)
Definition: BitVector.cc:94
CodeCompressorPlugin::machine
const TTAMachine::Machine & machine() const
Definition: CodeCompressorPlugin.cc:310
ProgramImageGenerator::imemMauWidth
int imemMauWidth() const
Definition: ProgramImageGenerator.cc:739
TPEF::Section::element
SectionElement * element(Word index) const
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::TerminalImmediate::value
virtual SimValue value() const
Definition: TerminalImmediate.cc:75
CodeCompressorPlugin::ParameterTable
std::vector< Parameter > ParameterTable
Table for passing plugin parameters.
Definition: CodeCompressorPlugin.hh:94
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
Environment::codeCompressorPaths
static std::vector< std::string > codeCompressorPaths(bool libraryPathsOnly=false)
Definition: Environment.cc:571
ProgramImageGenerator::loadMachine
void loadMachine(const TTAMachine::Machine &machine)
Definition: ProgramImageGenerator.cc:151
ProgramImageGenerator::generateDataImage
void generateDataImage(const std::string &programName, TPEF::Binary &program, const std::string &addressSpace, std::ostream &stream, OutputFormat format, int mausPerLine, bool usePregeneratedImage)
Definition: ProgramImageGenerator.cc:404
FileSystem::fileIsDirectory
static bool fileIsDirectory(const std::string fileName)
HexImageWriter
Definition: HexImageWriter.hh:46
ProgramImageGenerator::entityName_
std::string entityName_
Toplevel entity name.
Definition: ProgramImageGenerator.hh:133
TTAProgram::Immediate
Definition: Immediate.hh:54
ProgramImageGenerator.hh
RelocSection.hh
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
InvalidData
Definition: Exception.hh:149
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
ProgramImageGenerator::setEntityName
void setEntityName(const std::string &entity)
Definition: ProgramImageGenerator.cc:746
PIGTextGenerator.hh
BinaryEncoding.hh
FileSystem::fileExtension
static std::string fileExtension(const std::string &fileName)
Definition: FileSystem.cc:279
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
BinaryEncoding::width
virtual int width(const TCEString &templateName) const
Definition: BinaryEncoding.cc:768
TPEF::RelocElement::destination
SectionElement * destination() const
__func__
#define __func__
Definition: Application.hh:67
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
CodeCompressorPlugin::setParameters
void setParameters(ParameterTable parameters)
Definition: CodeCompressorPlugin.cc:133
ArrayProgramImageWriter
Definition: ArrayProgramImageWriter.hh:44
VhdlImageWriter
Definition: VhdlImageWriter.hh:43
RelocElement.hh
TTAProgram::Terminal::value
virtual SimValue value() const
Definition: Terminal.cc:178
Environment.hh
TPEF::ASpaceElement::name
Chunk * name() const
ProgramImageGenerator::VHDL
@ VHDL
Array as a Vhdl package.
Definition: ProgramImageGenerator.hh:76
TTAProgram::Move
Definition: Move.hh:55
Machine.hh
Exception
Definition: Exception.hh:54
CodeCompressorPlugin::currentProgram
TTAProgram::Program & currentProgram() const
Definition: CodeCompressorPlugin.cc:295
TTAMachine::Machine::addressSpaceNavigator
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition: Machine.cc:392
CodeCompressorPlugin::imemMauWidth
int imemMauWidth() const
Definition: CodeCompressorPlugin.cc:600
TPEF::CodeSection
Definition: CodeSection.hh:44
PluginTools.hh
ProgramImageGenerator::writeDataSection
void writeDataSection(TPEF::Binary &program, BitVector &bitVector, const std::string &addressSpace, TPEF::Section &section)
Definition: ProgramImageGenerator.cc:510
TPEF::RelocElement
Definition: RelocElement.hh:51
TTAProgram::Instruction::immediate
Immediate & immediate(int i) const
Definition: Instruction.cc:285
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
MifImageWriter.hh
DEFAULT_Compressor
Definition: DefaultCompressor.hh:41
AddressImage
UInt32 AddressImage
Type for storing addresses to memory image.
Definition: BaseType.hh:179
VhdlProgramImageWriter.hh
CodeCompressorPlugin::memoryAddress
unsigned int memoryAddress(const TTAProgram::Instruction &instruction) const
Definition: CodeCompressorPlugin.cc:262
ArrayImageWriter
Definition: ArrayImageWriter.hh:43
ProgramImageGenerator::BINARY
@ BINARY
Real binary format.
Definition: ProgramImageGenerator.hh:72
SimValue::sIntWordValue
SIntWord sIntWordValue() const
Definition: SimValue.cc:944
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
TTAProgram::Program::instructionCount
int instructionCount() const
Definition: Program.cc:1209
TPEF::Chunk::offset
SectionOffset offset() const
ProgramImageGenerator::compressor_
CodeCompressorPlugin * compressor_
The code compressor.
Definition: ProgramImageGenerator.hh:131
Program.hh
VhdlProgramImageWriter
Definition: VhdlProgramImageWriter.hh:43
TerminalImmediate.hh
Immediate.hh
PluginTools::addSearchPath
void addSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:95
FileSystem::fileExists
static bool fileExists(const std::string fileName)
TTAProgram::Program::moveCount
int moveCount() const
Definition: Program.cc:494
AsciiImageWriter
Definition: AsciiImageWriter.hh:45
CodeCompressorPlugin
Definition: CodeCompressorPlugin.hh:84
TCEString
Definition: TCEString.hh:53
ProgramImageGenerator::generateDecompressor
void generateDecompressor(std::ostream &stream, TCEString entityStr)
Definition: ProgramImageGenerator.cc:592
TTAProgram::Instruction::immediateCount
int immediateCount() const
Definition: Instruction.cc:267
ControlUnit.hh
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
CodeCompressorPlugin::setMachine
void setMachine(const TTAMachine::Machine &machine)
Definition: CodeCompressorPlugin.cc:161
TTAProgram::Program::targetProcessor
TTAMachine::Machine & targetProcessor() const
Definition: Program.cc:202
ProgramImageGenerator::BIN2N
@ BIN2N
Binary format padded to 2**n.
Definition: ProgramImageGenerator.hh:79
BitImageWriter::writeImage
virtual void writeImage(std::ostream &stream) const =0
TPEF::DataSection::length
virtual Word length() const
Definition: DataSection.cc:210
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
ProgramImageGenerator::pluginTool_
PluginTools pluginTool_
The plugin tool.
Definition: ProgramImageGenerator.hh:135
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
ProgramImageGenerator::ProgramImageGenerator
ProgramImageGenerator()
Definition: ProgramImageGenerator.cc:91
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
CodeCompressorPlugin.hh
Bin2nProgramImageWriter.hh
HexImageWriter.hh
TPEF::RelocElement::location
SectionElement * location() const
CodeCompressorPlugin::binaryEncoding
const BinaryEncoding & binaryEncoding() const
Definition: CodeCompressorPlugin.cc:280
Move.hh
TTAMachine
Definition: Assembler.hh:48
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63
CoeImageWriter
Definition: CoeImageWriter.hh:41
ProgramImageGenerator::compressor
CodeCompressorPlugin & compressor()
Definition: ProgramImageGenerator.hh:106
ProgramImageGenerator::OutputFormat
OutputFormat
Different output formats of images.
Definition: ProgramImageGenerator.hh:71
Bin2nImageWriter.hh
ProgramImageGenerator::COE
@ COE
COE memory initialization format.
Definition: ProgramImageGenerator.hh:77
TTAProgram::Program::instructionVector
InstructionVector instructionVector() const
Definition: Program.cc:1196
ProgramImageGenerator::ARRAY
@ ARRAY
ASCII 1's and 0's in array form.
Definition: ProgramImageGenerator.hh:74
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TPEF::CodeSection::indexOfInstruction
Word indexOfInstruction(const InstructionElement &elem) const
Definition: CodeSection.cc:232
TPEF::Section::startingAddress
AddressImage startingAddress() const
ProgramImageGenerator::TPEFMap
std::map< std::string, TPEF::Binary * > TPEFMap
Definition: ProgramImageGenerator.hh:81
TPEF::Chunk
Definition: Chunk.hh:45
CodeSection.hh
InstanceNotFound
Definition: Exception.hh:304
TPEF::Section::elementCount
Word elementCount() const
FileSystem::directoryContents
static std::vector< std::string > directoryContents(const std::string &directory, const bool absolutePaths=true)
Definition: FileSystem.cc:600
TPEF
Definition: Assembler.hh:43
TTAMachine::Machine
Definition: Machine.hh:73
Binary.hh
AsciiProgramImageWriter.hh
InstructionBitVector
Definition: InstructionBitVector.hh:50
Bin2nImageWriter
Definition: Bin2nImageWriter.hh:46