OpenASIP 2.2
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static 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 setDataStartOptions (CmdLineOptionParser *options)
 
bool isDataStartSet (std::string aSpace) const
 
uint64_t dataStartAddress (std::string aSpace) const
 
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.
 

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.
 
std::string entityName_
 Toplevel entity name.
 
CmdLineOptionParserdataStartOptions_
 
PluginTools pluginTool_
 The plugin tool.
 

Static Private Attributes

static const std::string DATA_START_DESC
 

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 68 of file ProgramImageGenerator.hh.

Member Typedef Documentation

◆ ProgramSet

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

Typedef for program set.

Definition at line 125 of file ProgramImageGenerator.hh.

◆ TPEFMap

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

Definition at line 82 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 72 of file ProgramImageGenerator.hh.

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

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}
std::string entityName_
Toplevel entity name.
CodeCompressorPlugin * compressor_
The code compressor.

◆ ~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 617 of file ProgramImageGenerator.cc.

617 {
618
619 std::vector<string> paths = Environment::codeCompressorPaths();
620 std::vector<string> files;
621 for (std::vector<string>::const_iterator iter = paths.begin();
622 iter != paths.end(); iter++) {
623 if (FileSystem::fileExists(*iter)) {
624 std::vector<string> filesInPath = FileSystem::directoryContents(
625 *iter);
626 for (std::vector<string>::const_iterator iter =
627 filesInPath.begin();
628 iter != filesInPath.end(); iter++) {
629 if (!FileSystem::fileIsDirectory(*iter) &&
630 FileSystem::fileExtension(*iter) == ".so") {
631 files.push_back(*iter);
632 }
633 }
634 }
635 }
636
637 return files;
638}
static std::vector< std::string > codeCompressorPaths(bool libraryPathsOnly=false)
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)

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 674 of file ProgramImageGenerator.cc.

675 {
676 vector<string> searchPaths = Environment::codeCompressorPaths();
677 for (vector<string>::const_iterator iter = searchPaths.begin();
678 iter != searchPaths.end(); iter++) {
679 if (FileSystem::fileExists(*iter)) {
680 pluginTool.addSearchPath(*iter);
681 }
682 }
683
684 pluginTool.registerModule(fileName);
685 CodeCompressorPlugin* (*pluginCreator)();
686 pluginTool.importSymbol(
687 "create_code_compressor", pluginCreator, fileName);
688
689 return pluginCreator();
690}
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
void addSearchPath(const std::string &searchPath)
void registerModule(const std::string &module)

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:

◆ dataStartAddress()

uint64_t ProgramImageGenerator::dataStartAddress ( std::string  aSpace) const

Definition at line 796 of file ProgramImageGenerator.cc.

796 {
798 assert(opts);
799 if (opts->isDefined()) {
800 int size = opts->listSize();
801 if (size == 1) {
802 return Conversion::toUnsignedLong(opts->String(1));
803 }
804 if (size % 2 != 0) {
805 abortWithError("ERROR: " + DATA_START_DESC);
806 }
807 for (int i = 1; i <= size; i += 2) {
808 TCEString as_name = opts->String(i);
809 if (as_name == aSpace) {
810 return Conversion::toUnsignedLong(opts->String(i + 1));
811 }
812 }
813 }
814 abortWithError("ERROR: " + DATA_START_DESC);
815}
#define abortWithError(message)
#define assert(condition)
virtual int listSize() const
virtual std::string String(int index=0) const
static ULongWord toUnsignedLong(const T &source)
CmdLineOptionParser * dataStartOptions_
static const std::string DATA_START_DESC

References abortWithError, assert, DATA_START_DESC, dataStartOptions_, CmdLineOptionParser::isDefined(), CmdLineOptionParser::listSize(), CmdLineOptionParser::String(), and Conversion::toUnsignedLong().

Referenced by writeDataSection().

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
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}
#define __func__
find Finds info of the inner loops in the program
virtual void writeImage(std::ostream &stream) const =0
const TTAMachine::Machine & machine() const
virtual InstructionBitVector * compress(const std::string &program)=0
std::string errorMessage() const
Definition Exception.cc:123
void writeDataSection(TPEF::Binary &program, BitVector &bitVector, const std::string &addressSpace, TPEF::Section &section)
@ ST_DATA
Initialized data section.
Definition Section.hh:80
@ ST_LEDATA
Initialized little endian data section.
Definition Section.hh:82
virtual int width() const
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition Machine.cc:392

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, TPEF::Section::ST_DATA, TPEF::Section::ST_LEDATA, 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 600 of file ProgramImageGenerator.cc.

602 {
603 if (compressor_ == NULL) {
604 return;
605 } else {
606 compressor_->generateDecompressor(stream, entityStr);
607 }
608}
virtual void generateDecompressor(std::ostream &stream, TCEString entityStr)=0

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
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}
static int verboseLevel()
static std::ostream & logStream()
virtual int width(const TCEString &templateName) const
TTAProgram::Program & currentProgram() const
const BinaryEncoding & binaryEncoding() const
SIntWord sIntWordValue() const
Definition SimValue.cc:944
virtual AddressSpace * addressSpace() const
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345
TerminalImmediate & value() const
Definition Immediate.cc:103
Immediate & immediate(int i) const
Terminal & source() const
Definition Move.cc:302
std::vector< Instruction * > InstructionVector
Vector for instructions.
Definition Program.hh:66
const Move & moveAt(int number) const
Definition Program.cc:480
TTAMachine::Machine & targetProcessor() const
Definition Program.cc:202
int moveCount() const
Definition Program.cc:494
int instructionCount() const
Definition Program.cc:1209
InstructionVector instructionVector() const
Definition Program.cc:1196
virtual SimValue value() const
virtual SimValue value() const
Definition Terminal.cc:178
virtual bool isAddress() const
Definition Terminal.cc:75
virtual bool isInstructionAddress() const
Definition Terminal.cc:87
virtual bool isImmediate() const
Definition Terminal.cc:63

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::Immediate::value(), TTAProgram::Terminal::value(), TTAProgram::TerminalImmediate::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 747 of file ProgramImageGenerator.cc.

747 {
748
749 return compressor_->imemMauWidth();
750}

References compressor_, and CodeCompressorPlugin::imemMauWidth().

Referenced by main().

Here is the call graph for this function:

◆ isDataStartSet()

bool ProgramImageGenerator::isDataStartSet ( std::string  aSpace) const

Definition at line 774 of file ProgramImageGenerator.cc.

774 {
776 assert(opts);
777 if (opts->isDefined()) {
778 int size = opts->listSize();
779 if (size == 1) {
780 return true;
781 }
782 if (size % 2 != 0) {
783 abortWithError("ERROR: " + DATA_START_DESC);
784 }
785 for (int i = 1; i <= size; i += 2) {
786 TCEString as_name = opts->String(i);
787 if (as_name == aSpace) {
788 return true;
789 }
790 }
791 }
792 return false;
793}

References abortWithError, assert, DATA_START_DESC, dataStartOptions_, CmdLineOptionParser::isDefined(), CmdLineOptionParser::listSize(), and CmdLineOptionParser::String().

Referenced by writeDataSection().

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}
void setBEM(const BinaryEncoding &bem)

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}
void setParameters(ParameterTable parameters)

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}
static CodeCompressorPlugin * createCompressor(const std::string &fileName, PluginTools &pluginTool)
PluginTools pluginTool_
The plugin tool.

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}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
void setMachine(const TTAMachine::Machine &machine)

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}
void setPrograms(std::map< std::string, TPEF::Binary * > &programs)

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 653 of file ProgramImageGenerator.cc.

654 {
655 PluginTools pluginTool;
657 fileName, pluginTool);
659 delete compressor;
660}
virtual void printDescription(std::ostream &stream)=0
CodeCompressorPlugin & compressor()

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 702 of file ProgramImageGenerator.cc.

705 {
706
707 // find the correct reloc section
708 for (unsigned int i = 0; i < program.sectionCount(Section::ST_RELOC);
709 i++) {
710 RelocSection* section = dynamic_cast<RelocSection*>(
711 program.section(Section::ST_RELOC, i));
712 assert(section != NULL);
713 if (section->referencedSection() == &dataSection) {
714 // correct reloc section found
715 Word elemCount = section->elementCount();
716 for (Word elemIndex = 0; elemIndex < elemCount; elemIndex++) {
717 RelocElement* relocElem = dynamic_cast<RelocElement*>(
718 section->element(elemIndex));
719 assert(relocElem != NULL);
720 Chunk* location = dynamic_cast<Chunk*>(
721 relocElem->location());
722 assert(location != NULL);
723 if (location->offset() == dataSectionOffset) {
724 InstructionElement* destination =
725 dynamic_cast<InstructionElement*>(
726 relocElem->destination());
727 if (destination != NULL) {
728 return destination;
729 } else {
730 return NULL;
731 }
732 }
733 }
734 }
735 }
736
737 return NULL;
738}
SectionOffset offset() const
SectionElement * destination() const
SectionElement * location() const
Section * referencedSection() const
@ ST_RELOC
Relocation section.
Definition Section.hh:74
SectionElement * element(Word index) const
Word elementCount() const

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

Referenced by writeDataSection().

Here is the call graph for this function:

◆ setDataStartOptions()

void ProgramImageGenerator::setDataStartOptions ( CmdLineOptionParser options)

Definition at line 760 of file ProgramImageGenerator.cc.

760 {
762}
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46

References dataStartOptions_, and options.

Referenced by main().

◆ setEntityName()

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

Definition at line 754 of file ProgramImageGenerator.cc.

754 {
755
756 entityName_ = entity;
757}

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 = 0;
532 if ((dataBits.size() == 0) && isDataStartSet(addressSpace)) {
533 // User can set custom starting address, which means that the
534 // beginning is not zero-filled up to that point
535 zeroFillStart = dataStartAddress(addressSpace);
536 } else {
537 zeroFillStart = dataBits.size() / 8; // 8 bits per byte
538 }
539
540 for (AddressImage i = zeroFillStart; i < startingAddress; i++) {
541 dataBits.pushBack(0, 8);
542 }
543 if (zeroFillStart > startingAddress) {
544 throw InvalidData(
545 __FILE__,__LINE__,__func__, "Illegal order of data sections.");
546 }
547
548 // fill the data
549 Word sectionLength = dataSection.length();
550 for (Word offset = 0; offset < sectionLength;) {
552 this->relocTarget(program, dataSection, offset);
553 if (relocTarget != NULL) {
554 Word indexOfInstruction =
555 codeSection->indexOfInstruction(*relocTarget);
556 Instruction& instruction =
558 indexOfInstruction);
559 try {
560 unsigned int memAddress = compressor_->memoryAddress(
561 instruction);
563 // Byteswap the pointer
564 unsigned int num = memAddress;
565 memAddress = ((num>>24)&0xff) |
566 ((num<<8)&0xff0000) |
567 ((num>>8)&0xff00) |
568 ((num<<24)&0xff000000);
569 }
570 dataBits.pushBack(memAddress, 32);
571 offset += 4;
572 } catch (const Exception& e) {
573 string errorMsg =
574 "Program image must be generated before "
575 "generating data image.";
576 throw InvalidData(
577 __FILE__, __LINE__, __func__, errorMsg);
578 }
579 } else {
580 Byte byte = dataSection.byte(offset);
581 dataBits.pushBack(byte, 8);
582 offset++;
583 }
584 }
585 }
586}
UInt32 AddressImage
Type for storing addresses to memory image.
Definition BaseType.hh:179
unsigned char Byte
Definition BaseType.hh:116
unsigned int memoryAddress(const TTAProgram::Instruction &instruction) const
TPEF::InstructionElement * relocTarget(const TPEF::Binary &program, const TPEF::DataSection &dataSection, Word dataSectionOffset) const
bool isDataStartSet(std::string aSpace) const
uint64_t dataStartAddress(std::string aSpace) const
Chunk * name() const
Word indexOfInstruction(const InstructionElement &elem) const
virtual Word length() const
virtual Byte byte(const Chunk *chunk) const
AddressImage startingAddress() const
@ ST_CODE
Text section.
Definition Section.hh:79
ASpaceElement * aSpace() const
std::string chunk2String(const Chunk *chunk) const
bool isLittleEndian() const
Definition Machine.hh:258
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374

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

Referenced by generateDataImage().

Here is the call graph for this function:

Member Data Documentation

◆ compressor_

CodeCompressorPlugin* ProgramImageGenerator::compressor_
private

◆ DATA_START_DESC

const std::string ProgramImageGenerator::DATA_START_DESC
staticprivate

Definition at line 139 of file ProgramImageGenerator.hh.

Referenced by dataStartAddress(), and isDataStartSet().

◆ dataStartOptions_

CmdLineOptionParser* ProgramImageGenerator::dataStartOptions_
private

Definition at line 140 of file ProgramImageGenerator.hh.

Referenced by dataStartAddress(), isDataStartSet(), and setDataStartOptions().

◆ entityName_

std::string ProgramImageGenerator::entityName_
private

Toplevel entity name.

Definition at line 137 of file ProgramImageGenerator.hh.

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

◆ pluginTool_

PluginTools ProgramImageGenerator::pluginTool_
private

The plugin tool.

Definition at line 142 of file ProgramImageGenerator.hh.

Referenced by loadCompressorPlugin().


The documentation for this class was generated from the following files: