OpenASIP  2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ProgramImageGenerator Class Reference

#include <ProgramImageGenerator.hh>

Collaboration diagram for ProgramImageGenerator:
Collaboration graph

Public Types

enum  OutputFormat {
  BINARY, ASCII, ARRAY, MIF,
  VHDL, COE, HEX, BIN2N
}
 Different output formats of images. More...
 
typedef std::map< std::string, TPEF::Binary * > TPEFMap
 

Public Member Functions

 ProgramImageGenerator ()
 
virtual ~ProgramImageGenerator ()
 
void loadCompressorPlugin (const std::string &fileName)
 
void loadCompressorParameters (CodeCompressorPlugin::ParameterTable parameters)
 
void loadPrograms (TPEFMap programs)
 
void loadMachine (const TTAMachine::Machine &machine)
 
void loadBEM (const BinaryEncoding &bem)
 
void generateProgramImage (const std::string &programName, std::ostream &stream, OutputFormat format, int mausPerLine=0)
 
void generateDataImage (const std::string &programName, TPEF::Binary &program, const std::string &addressSpace, std::ostream &stream, OutputFormat format, int mausPerLine, bool usePregeneratedImage)
 
void generateDecompressor (std::ostream &stream, TCEString entityStr)
 
int imemMauWidth () const
 
CodeCompressorPlugincompressor ()
 
void setEntityName (const std::string &entity)
 
void writeDataSection (TPEF::Binary &program, BitVector &bitVector, const std::string &addressSpace, TPEF::Section &section)
 

Static Public Member Functions

static std::vector< std::string > availableCompressors ()
 
static void printCompressorDescription (const std::string &fileName, std::ostream &stream)
 

Private Types

typedef std::set< TPEF::Binary * > ProgramSet
 Typedef for program set. More...
 

Private Member Functions

TPEF::InstructionElementrelocTarget (const TPEF::Binary &program, const TPEF::DataSection &dataSection, Word dataSectionOffset) const
 

Static Private Member Functions

static CodeCompressorPlugincreateCompressor (const std::string &fileName, PluginTools &pluginTool)
 

Private Attributes

CodeCompressorPlugincompressor_
 The code compressor. More...
 
std::string entityName_
 Toplevel entity name. More...
 
PluginTools pluginTool_
 The plugin tool. More...
 

Detailed Description

The main class of program image generator module.

This class provides the interface that is available to different user interfaces.

Definition at line 67 of file ProgramImageGenerator.hh.

Member Typedef Documentation

◆ ProgramSet

typedef std::set<TPEF::Binary*> ProgramImageGenerator::ProgramSet
private

Typedef for program set.

Definition at line 121 of file ProgramImageGenerator.hh.

◆ TPEFMap

typedef std::map<std::string, TPEF::Binary*> ProgramImageGenerator::TPEFMap

Definition at line 81 of file ProgramImageGenerator.hh.

Member Enumeration Documentation

◆ OutputFormat

Different output formats of images.

Enumerator
BINARY 

Real binary format.

ASCII 

ASCII 1's and 0's.

ARRAY 

ASCII 1's and 0's in array form.

MIF 

MIF Memory Initialization File.

VHDL 

Array as a Vhdl package.

COE 

COE memory initialization format.

HEX 

HEX memory initialization format.

BIN2N 

Binary format padded to 2**n.

Definition at line 71 of file ProgramImageGenerator.hh.

71  {
72  BINARY, ///< Real binary format.
73  ASCII, ///< ASCII 1's and 0's.
74  ARRAY, ///< ASCII 1's and 0's in array form.
75  MIF, ///< MIF Memory Initialization File
76  VHDL, ///< Array as a Vhdl package
77  COE, ///< COE memory initialization format
78  HEX, ///< HEX memory initialization format
79  BIN2N /// Binary format padded to 2**n
80  };

Constructor & Destructor Documentation

◆ ProgramImageGenerator()

ProgramImageGenerator::ProgramImageGenerator ( )

The constructor.

Parameters
programThe program.
bemThe binary encoding map.
machineThe machine.

Definition at line 91 of file ProgramImageGenerator.cc.

91  :
93 }

◆ ~ProgramImageGenerator()

ProgramImageGenerator::~ProgramImageGenerator ( )
virtual

The destructor.

Definition at line 99 of file ProgramImageGenerator.cc.

99  {
100  delete compressor_;
101 }

References compressor_.

Member Function Documentation

◆ availableCompressors()

std::vector< std::string > ProgramImageGenerator::availableCompressors ( )
static

Returns a vector containing paths to the compressors available.

Returns
The vector.

Definition at line 609 of file ProgramImageGenerator.cc.

609  {
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 }

References Environment::codeCompressorPaths(), FileSystem::directoryContents(), FileSystem::fileExists(), FileSystem::fileExtension(), and FileSystem::fileIsDirectory().

Referenced by main().

Here is the call graph for this function:

◆ compressor()

CodeCompressorPlugin& ProgramImageGenerator::compressor ( )
inline

◆ createCompressor()

CodeCompressorPlugin * ProgramImageGenerator::createCompressor ( const std::string &  fileName,
PluginTools pluginTool 
)
staticprivate

Creates the code compressor from the given dynamic module.

Parameters
fileNameName of the file.
pluginToolThe plugin tool to use.
Returns
The newly created code compressor plugin.
Exceptions
FileNotFoundIf the given file is not found from the search paths of code compressor plugins.
DynamicLibraryExceptionIf the dynamic library cannot be opened.

Definition at line 666 of file ProgramImageGenerator.cc.

667  {
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 }

References PluginTools::addSearchPath(), Environment::codeCompressorPaths(), FileSystem::fileExists(), PluginTools::importSymbol(), and PluginTools::registerModule().

Referenced by loadCompressorPlugin(), and printCompressorDescription().

Here is the call graph for this function:

◆ generateDataImage()

void ProgramImageGenerator::generateDataImage ( const std::string &  programName,
TPEF::Binary program,
const std::string &  addressSpace,
std::ostream &  stream,
OutputFormat  format,
int  mausPerLine,
bool  usePregeneratedImage 
)

Generates the data image of the given address space to the given output stream in the given format.

Parameters
programThe program of which data image is generated.
addressSpaceThe address space.
streamThe output stream.
formatThe output format.
mausPerLineTells how many MAUs of data is generated on one line.
usePregeneratedImageTells whether use the program image that was previously generated for relocation of data elements.
Exceptions
InvalidDataIf tried to use pregenerated program but it has not been generated or if the given program is not in the program set loaded or if machine is not loaded or if is does not have the given address space.
OutOfRangeIf the given MAUs per line is not positive.

Definition at line 404 of file ProgramImageGenerator.cc.

407  {
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 }

References __func__, TTAMachine::Machine::addressSpaceNavigator(), ARRAY, ASCII, assert, BIN2N, BINARY, COE, CodeCompressorPlugin::compress(), compressor_, entityName_, Exception::errorMessage(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), HEX, TTAMachine::Machine::Navigator< ComponentType >::item(), CodeCompressorPlugin::machine(), MIF, program, VHDL, TTAMachine::AddressSpace::width(), writeDataSection(), and BitImageWriter::writeImage().

Referenced by main().

Here is the call graph for this function:

◆ generateDecompressor()

void ProgramImageGenerator::generateDecompressor ( std::ostream &  stream,
TCEString  entityStr 
)

Generates the decompressor to the given output stream.

Note! The program image should have been generated at first. Otherwise this may not function properly.

Parameters
streamThe output stream.
entityStrThe entity string used to make HDL entity/component names unique for multiprocessor designs.

Definition at line 592 of file ProgramImageGenerator.cc.

594  {
595  if (compressor_ == NULL) {
596  return;
597  } else {
598  compressor_->generateDecompressor(stream, entityStr);
599  }
600 }

References compressor_, and CodeCompressorPlugin::generateDecompressor().

Referenced by createCompressor().

Here is the call graph for this function:

◆ generateProgramImage()

void ProgramImageGenerator::generateProgramImage ( const std::string &  programName,
std::ostream &  stream,
OutputFormat  format,
int  mausPerLine = 0 
)

Generates the program image to the given output stream in the given format.

If the output is in ASCII format, mausPerLine parameter defines the number of MAUs printed per line. If 0 is given, each instruction is printed on different line.

Parameters
streamThe output stream.
formatThe output format.
mausPerLineIf the output is ASCII format, defines the number of MAUs printed per line.
Exceptions
InvalidDataIf machine or BEM is not loaded or if they are erroneous or if the given program is not in the program set.
OutOfRangeIf mausPerLine is negative.

Definition at line 185 of file ProgramImageGenerator.cc.

189  {
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 }

References __func__, TTAMachine::FunctionUnit::addressSpace(), ARRAY, ASCII, assert, BIN2N, BINARY, CodeCompressorPlugin::binaryEncoding(), TTAMachine::Machine::busNavigator(), COE, CodeCompressorPlugin::compress(), compressor_, TTAMachine::Machine::controlUnit(), TTAMachine::Machine::Navigator< ComponentType >::count(), CodeCompressorPlugin::currentProgram(), entityName_, HEX, TTAProgram::Instruction::immediate(), TTAProgram::Instruction::immediateCount(), TTAProgram::Program::instructionCount(), TTAProgram::Program::instructionVector(), TTAProgram::Terminal::isAddress(), TTAProgram::Terminal::isImmediate(), TTAProgram::Terminal::isInstructionAddress(), TTAProgram::Instruction::isNOP(), Application::logStream(), CodeCompressorPlugin::machine(), MIF, TTAProgram::Program::moveAt(), TTAProgram::Program::moveCount(), SimValue::sIntWordValue(), TTAProgram::Move::source(), TTAProgram::Program::targetProcessor(), TTAProgram::TerminalImmediate::value(), TTAProgram::Immediate::value(), TTAProgram::Terminal::value(), Application::verboseLevel(), VHDL, TTAMachine::AddressSpace::width(), BinaryEncoding::width(), and BitImageWriter::writeImage().

Referenced by RemoteController::loadIMemImage(), and main().

Here is the call graph for this function:

◆ imemMauWidth()

int ProgramImageGenerator::imemMauWidth ( ) const

Asks the instruction memory mau width from code compressor plugin and returns it

Returns
instruction memory mau width

Definition at line 739 of file ProgramImageGenerator.cc.

739  {
740 
741  return compressor_->imemMauWidth();
742 }

References compressor_, and CodeCompressorPlugin::imemMauWidth().

Referenced by main().

Here is the call graph for this function:

◆ loadBEM()

void ProgramImageGenerator::loadBEM ( const BinaryEncoding bem)

Sets the binary encoding map used when generating the program image.

Parameters
bemThe binary encoding map.

Definition at line 162 of file ProgramImageGenerator.cc.

162  {
163  compressor_->setBEM(bem);
164 }

References compressor_, and CodeCompressorPlugin::setBEM().

Referenced by RemoteController::loadIMemImage(), main(), and ProGe::RV32MicroCodeGenerator::RV32MicroCodeGenerator().

Here is the call graph for this function:

◆ loadCompressorParameters()

void ProgramImageGenerator::loadCompressorParameters ( CodeCompressorPlugin::ParameterTable  parameters)

Loads the given code compressor plugin parameters to the plugin.

Parameters
parametersThe parameters.

Definition at line 127 of file ProgramImageGenerator.cc.

128  {
129 
130  compressor_->setParameters(parameters);
131 }

References compressor_, and CodeCompressorPlugin::setParameters().

Referenced by main().

Here is the call graph for this function:

◆ loadCompressorPlugin()

void ProgramImageGenerator::loadCompressorPlugin ( const std::string &  fileName)

Loads the code compressor plugin from the given object file.

Parameters
fileNameThe file name.
Exceptions
FileNotFoundIf the given file is not found from the search paths of code compressor plugins.
DynamicLibraryExceptionIf the dynamic library cannot be opened.

Definition at line 114 of file ProgramImageGenerator.cc.

114  {
115  CodeCompressorPlugin* newCompressor = createCompressor(
116  fileName, pluginTool_);
117  delete compressor_;
118  compressor_ = newCompressor;
119 }

References compressor_, createCompressor(), and pluginTool_.

Referenced by main().

Here is the call graph for this function:

◆ loadMachine()

void ProgramImageGenerator::loadMachine ( const TTAMachine::Machine machine)

Sets the machine which executes the programs.

Parameters
machineThe machine.

Definition at line 151 of file ProgramImageGenerator.cc.

151  {
153 }

References compressor_, machine, and CodeCompressorPlugin::setMachine().

Referenced by RemoteController::loadIMemImage(), main(), and ProGe::RV32MicroCodeGenerator::RV32MicroCodeGenerator().

Here is the call graph for this function:

◆ loadPrograms()

void ProgramImageGenerator::loadPrograms ( TPEFMap  programs)

Loads the programs to be generated to the compressor plugin.

Parameters
programsThe programs.

Definition at line 140 of file ProgramImageGenerator.cc.

140  {
141  compressor_->setPrograms(programs);
142 }

References compressor_, and CodeCompressorPlugin::setPrograms().

Referenced by RemoteController::loadIMemImage(), and main().

Here is the call graph for this function:

◆ printCompressorDescription()

void ProgramImageGenerator::printCompressorDescription ( const std::string &  fileName,
std::ostream &  stream 
)
static

Loads the code compressor plugin from the given file and prints its description to the given stream.

Parameters
fileNameThe code compressor plugin file.
streamThe output stream.
Exceptions
FileNotFoundIf the given file is not found from the search paths of code compressor plugins.
DynamicLibraryExceptionIf the dynamic library cannot be opened.

Definition at line 645 of file ProgramImageGenerator.cc.

646  {
647  PluginTools pluginTool;
649  fileName, pluginTool);
650  compressor->printDescription(stream);
651  delete compressor;
652 }

References compressor(), createCompressor(), and CodeCompressorPlugin::printDescription().

Referenced by main().

Here is the call graph for this function:

◆ relocTarget()

TPEF::InstructionElement * ProgramImageGenerator::relocTarget ( const TPEF::Binary program,
const TPEF::DataSection dataSection,
Word  dataSectionOffset 
) const
private

Returns an InstructionElement that is relocation target of the data in data section at the given offset. Returns NULL if the data doesn't need to be altered.

Parameters
dataSectionThe data section,
dataSectionOffsetThe offset.
Returns
The InstructionElement or NULL.

Definition at line 694 of file ProgramImageGenerator.cc.

697  {
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 }

References assert, TPEF::RelocElement::destination(), TPEF::Section::element(), TPEF::Section::elementCount(), TPEF::RelocElement::location(), TPEF::Chunk::offset(), program, and TPEF::RelocSection::referencedSection().

Referenced by writeDataSection().

Here is the call graph for this function:

◆ setEntityName()

void ProgramImageGenerator::setEntityName ( const std::string &  entity)

Definition at line 746 of file ProgramImageGenerator.cc.

746  {
747 
748  entityName_ = entity;
749 }

References entityName_.

Referenced by main().

◆ writeDataSection()

void ProgramImageGenerator::writeDataSection ( TPEF::Binary program,
BitVector bitVector,
const std::string &  addressSpace,
TPEF::Section section 
)

Definition at line 510 of file ProgramImageGenerator.cc.

513  {
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 }

References __func__, TPEF::Section::aSpace(), TPEF::DataSection::byte(), TPEF::StringSection::chunk2String(), compressor_, CodeCompressorPlugin::currentProgram(), TPEF::CodeSection::indexOfInstruction(), TTAProgram::Program::instructionAt(), TTAMachine::Machine::isLittleEndian(), TPEF::DataSection::length(), CodeCompressorPlugin::machine(), CodeCompressorPlugin::memoryAddress(), TPEF::ASpaceElement::name(), program, BitVector::pushBack(), relocTarget(), and TPEF::Section::startingAddress().

Referenced by generateDataImage().

Here is the call graph for this function:

Member Data Documentation

◆ compressor_

CodeCompressorPlugin* ProgramImageGenerator::compressor_
private

◆ entityName_

std::string ProgramImageGenerator::entityName_
private

Toplevel entity name.

Definition at line 133 of file ProgramImageGenerator.hh.

Referenced by generateDataImage(), generateProgramImage(), and setEntityName().

◆ pluginTool_

PluginTools ProgramImageGenerator::pluginTool_
private

The plugin tool.

Definition at line 135 of file ProgramImageGenerator.hh.

Referenced by loadCompressorPlugin().


The documentation for this class was generated from the following files:
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
TPEF::Section::aSpace
ASpaceElement * aSpace() const
TTAProgram::Instruction::isNOP
bool isNOP() const
Definition: Instruction.hh:90
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
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::createCompressor
static CodeCompressorPlugin * createCompressor(const std::string &fileName, PluginTools &pluginTool)
Definition: ProgramImageGenerator.cc:666
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
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
Byte
unsigned char Byte
Definition: BaseType.hh:116
TTAMachine::Machine::Navigator::count
int count() const
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::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
CodeCompressorPlugin::machine
const TTAMachine::Machine & machine() const
Definition: CodeCompressorPlugin.cc:310
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
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
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
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)
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
TTAProgram::Terminal::value
virtual SimValue value() const
Definition: Terminal.cc:178
TPEF::ASpaceElement::name
Chunk * name() const
ProgramImageGenerator::VHDL
@ VHDL
Array as a Vhdl package.
Definition: ProgramImageGenerator.hh:76
TTAProgram::Move
Definition: Move.hh:55
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
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
DEFAULT_Compressor
Definition: DefaultCompressor.hh:41
AddressImage
UInt32 AddressImage
Type for storing addresses to memory image.
Definition: BaseType.hh:179
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
VhdlProgramImageWriter
Definition: VhdlProgramImageWriter.hh:43
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
TTAProgram::Instruction::immediateCount
int immediateCount() const
Definition: Instruction.cc:267
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
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
TPEF::RelocElement::location
SectionElement * location() const
CodeCompressorPlugin::binaryEncoding
const BinaryEncoding & binaryEncoding() const
Definition: CodeCompressorPlugin.cc:280
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::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
TPEF::Chunk
Definition: Chunk.hh:45
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
TTAMachine::Machine
Definition: Machine.hh:73
InstructionBitVector
Definition: InstructionBitVector.hh:50
Bin2nImageWriter
Definition: Bin2nImageWriter.hh:46