OpenASIP
2.0
|
#include <ProgramWriter.hh>
Classes | |
struct | RelocInfo |
struct | ResourceID |
Public Member Functions | |
ProgramWriter (const Program &prog) | |
TPEF::Binary * | createBinary () const |
Static Public Member Functions | |
static TPEF::Binary * | createBinary (const Program &prog) |
Private Member Functions | |
void | createCodeSection (TPEF::CodeSection *code, TPEFResourceUpdater &updater) const |
void | createDataSections (TPEF::Binary *bin, bool littleEndian) const |
void | createRelocSections (TPEF::Binary *bin) const |
TPEF::Section & | findSection (TPEF::Binary &bin, Address address) const |
ResourceID | terminalResource (const Terminal &term, TPEFResourceUpdater &updater) const |
TPEF::Binary::FileType | resolveFileType (TPEF::ResourceSection &resources) const |
TPEF::ASpaceElement & | createASpaceElement (const TTAMachine::AddressSpace &addressSpace, TPEF::Binary &bin) const |
Private Attributes | |
const Program & | prog_ |
Program that is written to TPEF. More... | |
std::map< const TTAMachine::AddressSpace *, TPEF::ASpaceElement * > | aSpaceMap_ |
Created TPEF binary. More... | |
std::vector< RelocInfo > | relocInfos_ |
Static Private Attributes | |
static const HalfWord | IMMEDIATE_ADDRESS_WIDTH = WORD_BITWIDTH |
Default widt that is used as address width of relocations of immediate elements. This should be fixed by checking width from bus or template. More... | |
static const int | MAX_SIMM_WIDTH = 64 |
Maximum width for short immediates. More... | |
Writes new TPEF out of POM and original TPEF.
Writer creates creates whole new code section, code relocation section, resource section and symbol section for code symbols. Data sections, uninitialized data sections and data to data relocations are also copied from original TPEF.
Client of POM has to write data to code relocations and all sections that client wants to preserve from original TPEF.
Definition at line 141 of file ProgramWriter.hh.
TTAProgram::ProgramWriter::ProgramWriter | ( | const Program & | prog | ) |
Constructor.
Definition at line 688 of file ProgramWriter.cc.
|
private |
Creates new address space element to binary or returns already created one.
This function should be used always with same TPEF bin.
addressSpace | ADF address space whose TPEF version is needed. |
bin | Binary to which created address space is added. |
Definition at line 1544 of file ProgramWriter.cc.
References TPEF::Section::addElement(), TTAMachine::FunctionUnit::addressSpace(), aSpaceMap_, MapTools::containsKey(), TTAMachine::Machine::controlUnit(), TTAMachine::Component::name(), prog_, TPEF::Binary::section(), TPEF::ASpaceElement::setMAU(), TPEF::ASpaceElement::setName(), TPEF::StringSection::string2Chunk(), TTAProgram::Program::targetProcessor(), and TTAMachine::AddressSpace::width().
Referenced by createBinary(), createDataSections(), createRelocSections(), and findSection().
Binary * TTAProgram::ProgramWriter::createBinary | ( | ) | const |
Creates TPEF binary.
Definition at line 700 of file ProgramWriter.cc.
References __func__, abortWithError, TPEF::DataSection::addByte(), TPEF::Section::addElement(), TTAProgram::CodeLabel::address(), TTAProgram::Label::address(), TTAMachine::FunctionUnit::addressSpace(), TPEF::Binary::addSection(), TPEF::Section::aSpace(), aSpaceMap_, TPEF::RawSection::chunk(), TTAMachine::Machine::controlUnit(), createASpaceElement(), createCodeSection(), createDataSections(), createRelocSections(), TPEF::Section::element(), TPEF::Section::elementCount(), TTAMachine::AddressSpace::end(), TTAProgram::GlobalScope::globalCodeLabel(), TTAProgram::GlobalScope::globalCodeLabelCount(), TTAProgram::GlobalScope::globalDataLabel(), TTAProgram::GlobalScope::globalDataLabelCount(), TTAProgram::Program::globalScopeConst(), TPEF::CodeSection::instruction(), TTAProgram::Program::instructionCount(), TTAMachine::Machine::isLittleEndian(), TPEF::RawSection::lengthInMAUs(), TTAProgram::Address::location(), TPEF::RawSection::MAUsToBytes(), TTAProgram::Label::name(), TTAProgram::Procedure::name(), TTAMachine::Component::name(), TTAProgram::Program::procedure(), TTAProgram::Program::procedureCount(), prog_, relocInfos_, resolveFileType(), TPEF::Binary::section(), TPEF::Binary::sectionCount(), TPEF::SymbolElement::setAbsolute(), TPEF::Binary::setArch(), TPEF::Section::setASpace(), TPEF::SymbolElement::setBinding(), TPEF::Section::setLink(), TPEF::ASpaceElement::setName(), TPEF::SymbolElement::setName(), TPEF::Section::setName(), TPEF::DataSymElement::setReference(), TPEF::CodeSymElement::setReference(), TPEF::SymbolElement::setSection(), TPEF::Binary::setStrings(), TPEF::Binary::setType(), TPEF::ASpaceSection::setUndefinedASpace(), TTAProgram::Address::space(), TTAMachine::AddressSpace::start(), TTAProgram::CodeSnippet::startAddress(), TTAProgram::Program::startAddress(), TPEF::Section::startingAddress(), TPEF::StringSection::string2Chunk(), TTAProgram::Program::targetProcessor(), Conversion::toString(), and TPEF::UDataSection::type().
Referenced by createBinary(), RemoteController::loadIMemImage(), ProgrammabilityValidator::profile(), and TTAProgram::Program::writeToTPEF().
|
static |
Creates TPEF binary of given Program.
Definition at line 941 of file ProgramWriter.cc.
References createBinary().
|
private |
Creates code section.
code | Code section where to instructions are added. |
updater | Resource updater for finding TPEF resources for machine parts. |
Definition at line 954 of file ProgramWriter.cc.
References __func__, abortWithError, TPEF::InstructionElement::addAnnotation(), TPEF::CodeSection::addElement(), TTAProgram::Terminal::address(), TTAProgram::Instruction::address(), TTAProgram::AnnotatedInstructionElement::annotation(), TTAProgram::AnnotatedInstructionElement::annotationCount(), assert, TTAProgram::Move::bus(), TTAProgram::TPEFResourceUpdater::bus(), TTAMachine::Machine::busNavigator(), TTAProgram::Immediate::destination(), TTAProgram::Move::destination(), TPEF::ImmediateElement::destinationIndex(), TPEF::ImmediateElement::destinationUnit(), POMDisassembler::disassemble(), TTAProgram::TPEFResourceUpdater::functionUnit(), TTAProgram::TPEFResourceUpdater::functionUnitPort(), TTAProgram::MoveGuard::guard(), TTAProgram::Move::guard(), TTAProgram::AnnotatedInstructionElement::hasAnnotations(), TTAMachine::FunctionUnit::hasOperationPort(), TPEF::ResourceElement::id(), TTAProgram::ProgramAnnotation::id(), TTAProgram::Instruction::immediate(), IMMEDIATE_ADDRESS_WIDTH, TTAProgram::Instruction::immediateCount(), TTAProgram::Terminal::immediateUnit(), TTAMachine::Bus::immediateWidth(), TTAProgram::ProgramWriter::ResourceID::index, TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAMachine::HWOperation::io(), TTAProgram::Terminal::isAddress(), TTAMachine::HWOperation::isBound(), TPEF::MoveElement::isEmpty(), TTAProgram::Terminal::isImmediate(), TTAProgram::Terminal::isInstructionAddress(), TTAMachine::Guard::isInverted(), TTAProgram::Move::isUnconditional(), TTAProgram::Address::location(), MAX_SIMM_WIDTH, TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAMachine::Port::name(), TTAProgram::Procedure::name(), TTAMachine::Component::name(), TTAProgram::TPEFResourceUpdater::operand(), TTAMachine::FunctionUnit::operation(), TTAMachine::FunctionUnit::operationCount(), TTAProgram::Move::parent(), TTAMachine::BaseFUPort::parentUnit(), TTAProgram::ProgramAnnotation::payload(), TTAMachine::PortGuard::port(), TTAProgram::Program::procedure(), TTAProgram::Program::procedureCount(), prog_, TTAProgram::TPEFResourceUpdater::registerFile(), TTAMachine::RegisterGuard::registerFile(), TTAMachine::RegisterGuard::registerIndex(), relocInfos_, MathTools::requiredBits(), MathTools::requiredBitsSigned(), TPEF::InstructionElement::setBegin(), TPEF::MoveElement::setBus(), TPEF::ImmediateElement::setDestinationIndex(), TPEF::MoveElement::setDestinationIndex(), TPEF::MoveElement::setDestinationType(), TPEF::ImmediateElement::setDestinationUnit(), TPEF::MoveElement::setDestinationUnit(), TPEF::MoveElement::setEmpty(), TPEF::MoveElement::setGuarded(), TPEF::MoveElement::setGuardIndex(), TPEF::MoveElement::setGuardInverted(), TPEF::MoveElement::setGuardType(), TPEF::MoveElement::setGuardUnit(), TPEF::ImmediateElement::setSignedLong(), TPEF::MoveElement::setSourceIndex(), TPEF::MoveElement::setSourceType(), TPEF::MoveElement::setSourceUnit(), TPEF::Section::setStartingAddress(), TPEF::ImmediateElement::setULongWord(), TTAMachine::ImmediateUnit::signExtends(), TTAMachine::Bus::signExtends(), MathTools::signExtendTo(), SimValue::sLongWordValue(), TTAProgram::Move::source(), TTAProgram::Program::startAddress(), TTAProgram::Program::targetProcessor(), terminalResource(), Conversion::toString(), TTAProgram::ProgramWriter::ResourceID::type, SimValue::uLongWordValue(), TTAProgram::ProgramWriter::ResourceID::unit, SimValue::unsignedValue(), TTAProgram::TerminalImmediate::value(), TTAProgram::Immediate::value(), TTAProgram::Terminal::value(), and MathTools::zeroExtendTo().
Referenced by createBinary().
|
private |
Creates data section to TPEF.
bin | Binary to write the sections to. |
Definition at line 1403 of file ProgramWriter.cc.
References TPEF::DataSection::addMAU(), TTAProgram::DataMemory::addressSpace(), TPEF::Binary::addSection(), TPEF::Section::aSpace(), assert, TPEF::RawSection::chunk(), createASpaceElement(), TTAProgram::DataMemory::dataDefinition(), TTAProgram::DataMemory::dataDefinitionCount(), TTAProgram::Program::dataMemory(), TTAProgram::Program::dataMemoryCount(), TTAProgram::DataDefinition::destinationAddress(), TTAProgram::DataDefinition::isAddress(), TPEF::Section::isDataSection(), TTAProgram::DataDefinition::isInitialized(), TPEF::DataSection::length(), TPEF::RawSection::lengthInMAUs(), TPEF::Section::link(), TTAProgram::Address::location(), Application::logStream(), TPEF::ASpaceElement::MAU(), TTAProgram::DataDefinition::MAU(), TTAMachine::Component::name(), prog_, relocInfos_, TPEF::Binary::section(), TPEF::Section::setASpace(), TPEF::RawSection::setLengthInMAUs(), TPEF::Section::setLink(), TPEF::Section::setName(), TPEF::Section::setStartingAddress(), TTAProgram::DataDefinition::size(), TTAProgram::Address::space(), TTAProgram::DataDefinition::startAddress(), TPEF::Section::startingAddress(), and TPEF::StringSection::string2Chunk().
Referenced by createBinary().
|
private |
Create relocation tables to binary and add relocation elements.
bin | Binary where to add relocation sections. |
NotAvailable | Can't find needed resource. |
Definition at line 1578 of file ProgramWriter.cc.
References TPEF::Section::addElement(), TPEF::Binary::addSection(), TTAProgram::ProgramWriter::RelocInfo::bits, TPEF::RawSection::chunk(), createASpaceElement(), TTAProgram::ProgramWriter::RelocInfo::destination, TPEF::Section::element(), findSection(), TPEF::CodeSection::instruction(), TPEF::Section::isCodeSection(), TTAProgram::Address::location(), TPEF::RawSection::MAUsToBytes(), TPEF::RelocSection::referencedSection(), relocInfos_, TPEF::Binary::section(), TPEF::RelocElement::setASpace(), TPEF::Section::setASpace(), TPEF::RelocElement::setDestination(), TPEF::Section::setLink(), TPEF::RelocElement::setLocation(), TPEF::Section::setName(), TPEF::RelocSection::setReferencedSection(), TPEF::RelocElement::setSize(), TPEF::RelocElement::setSymbol(), TPEF::RelocElement::setType(), TTAProgram::Address::space(), TTAProgram::ProgramWriter::RelocInfo::srcElem, TTAProgram::ProgramWriter::RelocInfo::srcSect, TPEF::Section::startingAddress(), TPEF::StringSection::string2Chunk(), and TPEF::ASpaceSection::undefinedASpace().
Referenced by createBinary().
|
private |
Finds section which contain requested address.
bin | TPEF where from sections are searched. |
address | The address that are looked for. |
Definition at line 1660 of file ProgramWriter.cc.
References __func__, TPEF::Section::aSpace(), createASpaceElement(), TPEF::CodeSection::instructionCount(), TPEF::Section::isCodeSection(), TPEF::Section::isProgramSection(), TPEF::RawSection::lengthInMAUs(), TTAProgram::Address::location(), TTAMachine::Component::name(), TPEF::Binary::section(), TPEF::Binary::sectionCount(), TTAProgram::Address::space(), TPEF::Section::startingAddress(), and Conversion::toString().
Referenced by createRelocSections().
|
private |
Find out the kind of TPEF file type.
This method scans the resource section and checks the type of processor resource elements it contains. Based on their types, it figures out what should be the file type.
resources | Resource section. |
Definition at line 1711 of file ProgramWriter.cc.
References TPEF::Section::element(), TPEF::Section::elementCount(), TPEF::ResourceElement::id(), and TPEF::ResourceElement::type().
Referenced by createBinary().
|
private |
Finds out resource element and index by terminal.
term | Terminal whose TPEF resource information is needed. |
updater | Resource updater for finding TPEF resources. |
Definition at line 1310 of file ProgramWriter.cc.
References __func__, abortWithError, assert, Exception::errorMessage(), TTAProgram::TPEFResourceUpdater::functionUnit(), TTAProgram::TPEFResourceUpdater::functionUnitPort(), TTAMachine::FunctionUnit::hasOperation(), TTAProgram::TerminalFUPort::hintOperation(), TPEF::ResourceElement::id(), TTAProgram::Terminal::immediateUnit(), TTAProgram::TPEFResourceUpdater::immediateUnit(), TTAProgram::Terminal::index(), TTAProgram::ProgramWriter::ResourceID::index, NullOperation::instance(), TTAMachine::HWOperation::io(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediate(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::TerminalFUPort::isOpcodeSetting(), TTAMachine::Component::name(), Operation::name(), TTAProgram::TPEFResourceUpdater::operand(), TTAProgram::TerminalFUPort::operation(), TTAMachine::FunctionUnit::operation(), TTAMachine::Port::parentUnit(), TTAProgram::Terminal::port(), TTAProgram::Terminal::registerFile(), TTAProgram::TPEFResourceUpdater::registerFile(), Exception::setCause(), TTAProgram::ProgramWriter::ResourceID::type, and TTAProgram::ProgramWriter::ResourceID::unit.
Referenced by createCodeSection().
|
mutableprivate |
Created TPEF binary.
Map that contains created address spaces
Definition at line 209 of file ProgramWriter.hh.
Referenced by createASpaceElement(), and createBinary().
|
staticprivate |
Default widt that is used as address width of relocations of immediate elements. This should be fixed by checking width from bus or template.
Definition at line 215 of file ProgramWriter.hh.
Referenced by createCodeSection().
|
staticprivate |
Maximum width for short immediates.
Definition at line 218 of file ProgramWriter.hh.
Referenced by createCodeSection().
|
private |
Program that is written to TPEF.
Definition at line 203 of file ProgramWriter.hh.
Referenced by createASpaceElement(), createBinary(), createCodeSection(), and createDataSections().
|
mutableprivate |
Definition at line 211 of file ProgramWriter.hh.
Referenced by createBinary(), createCodeSection(), createDataSections(), and createRelocSections().