OpenASIP
2.0
|
#include <CodeSectionCreator.hh>
Classes | |
struct | InternalElement |
struct | InternalSection |
Public Member Functions | |
CodeSectionCreator (MachineResourceManager &resourceManager, const TTAMachine::Machine &targetMachine, AssemblyParserDiagnostic *parent) | |
void | newSection (UValue startAddress) |
void | addMove (const ParserMove &move) |
void | finalize (TPEF::Binary &tpef, LabelManager &labels) |
void | cleanup () |
Private Types | |
enum | ElementType { EMPTY, MOVE, IMMEDIATE } |
Private Member Functions | |
void | startNewInstruction () |
UValue | slotNumber () |
UValue | immediateIndex () |
bool | isDestinationAlreadyWritten (const InternalElement &elem) const |
void | addAnnotationes (TPEF::InstructionElement &instrElem, InternalElement &elem, LabelManager &lables) const |
Private Attributes | |
const TTAMachine::Machine & | mach_ |
InternalSection | internalSection_ |
Internal representation of code section. More... | |
MachineResourceManager & | resources_ |
TPEF Resources and strings. More... | |
AssemblyParserDiagnostic * | parent_ |
Place to add warnings during compilation. More... | |
bool | isNextBegin_ |
Next element is starting element of instruction. More... | |
UValue | slotNumber_ |
Slot number of current move. More... | |
UValue | immediateIndex_ |
Immediate index. More... | |
Static Private Attributes | |
static const UValue | CODE_RELOC_SIZE = 32 |
Bitwidth of immediate value containing address to relocate. More... | |
Read moves and creates TPEF code section out of them.
Definition at line 58 of file CodeSectionCreator.hh.
|
private |
Type of move element.
Enumerator | |
---|---|
EMPTY | Empty move. |
MOVE | Data transport. |
IMMEDIATE | Long immediate assignment. |
Definition at line 80 of file CodeSectionCreator.hh.
CodeSectionCreator::CodeSectionCreator | ( | MachineResourceManager & | resourceManager, |
const TTAMachine::Machine & | targetMachine, | ||
AssemblyParserDiagnostic * | parent | ||
) |
|
private |
Adds annotations of element of internal presentation to TPEF element.
instrElem | TPEF InstructionElement where to add annotation data. |
elem | Element of internal presentation that caontains annotationes from assembly code. |
CompileError | If defined value needs more room that is defined in init data. |
Definition at line 636 of file CodeSectionCreator.cc.
References __func__, TPEF::InstructionElement::addAnnotation(), CodeSectionCreator::InternalElement::annotationes, CodeSectionCreator::InternalElement::asmLineNumber, BYTE_BITWIDTH, LiteralOrExpression::isExpression, LiteralOrExpression::isSigned, InitDataField::litOrExpr, LabelManager::resolveExpressionValue(), InitDataField::toString(), LiteralOrExpression::value, and InitDataField::width.
Referenced by finalize().
void CodeSectionCreator::addMove | ( | const ParserMove & | move | ) |
Adds new move to section.
If exception is thrown, creator will remain as it was before function call.
move | Parsed move. |
CompileError | If referenced resource is not found from machine. |
Definition at line 102 of file CodeSectionCreator.cc.
References __func__, AssemblyParserDiagnostic::addWarning(), CodeSectionCreator::InternalElement::annotationes, ParserMove::annotationes, CodeSectionCreator::InternalElement::asmLineNumber, ParserMove::asmLineNumber, assert, ParserMove::destination, CodeSectionCreator::InternalElement::dstIndex, CodeSectionCreator::InternalElement::dstType, CodeSectionCreator::InternalElement::dstUnit, CodeSectionCreator::InternalSection::elements, EMPTY, ParserMove::EMPTY, Exception::errorMessage(), MachineResourceManager::findBusWidth(), ParserMove::guard, CodeSectionCreator::InternalElement::guardIndex, CodeSectionCreator::InternalElement::guardType, CodeSectionCreator::InternalElement::guardUnit, IMMEDIATE, immediateIndex(), ParserSource::immTerm, CodeSectionCreator::InternalElement::immValue, MachineResourceManager::ResourceID::index, internalSection_, CodeSectionCreator::InternalElement::isBegin, ParserMove::isBegin, isDestinationAlreadyWritten(), CodeSectionCreator::InternalElement::isGuarded, ParserGuard::isGuarded, CodeSectionCreator::InternalElement::isInverted, ParserGuard::isInverted, ParserSource::isRegister, ParserMove::LONG_IMMEDIATE, MOVE, parent_, ParserSource::regTerm, ParserGuard::regTerm, MachineResourceManager::resourceID(), resources_, MachineResourceManager::RQST_GUARD, MachineResourceManager::RQST_INVGUARD, MachineResourceManager::RQST_READ, MachineResourceManager::RQST_WRITE, Exception::setCause(), CompileError::setCodeFileLineNumber(), CodeSectionCreator::InternalElement::slot, slotNumber(), ParserMove::source, CodeSectionCreator::InternalElement::srcIndex, CodeSectionCreator::InternalElement::srcType, CodeSectionCreator::InternalElement::srcUnit, startNewInstruction(), Conversion::toString(), RegisterTerm::toString(), ParserMove::TRANSPORT, CodeSectionCreator::InternalElement::type, MachineResourceManager::ResourceID::type, ParserMove::type, MachineResourceManager::ResourceID::unit, LiteralOrExpression::value, and MachineResourceManager::ResourceID::width.
Referenced by AddMoveActor::operator()().
void CodeSectionCreator::cleanup | ( | ) |
Frees all internally allocated data.
Definition at line 518 of file CodeSectionCreator.cc.
References immediateIndex_, isNextBegin_, and slotNumber_.
Referenced by AssemblerParser::cleanup(), and finalize().
void CodeSectionCreator::finalize | ( | TPEF::Binary & | tpef, |
LabelManager & | labels | ||
) |
Writes created sections to given binary.
All data stored inside creator is freed after this call, unless exception is thrown.
In case of exception creator restores its state to be same that state was before running finalize() (finalize() can be runned again).
tpef | Binary where to created sections should be added. |
labels | LabelManager where to add data labels and relocations. |
CompileError | If there is any errors during compiling. |
Definition at line 347 of file CodeSectionCreator.cc.
References __func__, addAnnotationes(), TPEF::CodeSection::addElement(), LabelManager::addRelocation(), TTAMachine::Machine::addressSpaceNavigator(), TPEF::Binary::addSection(), CodeSectionCreator::InternalElement::asmLineNumber, LabelManager::aSpaceElement(), LabelManager::aSpaceName(), assert, cleanup(), LabelManager::clearLastRelocations(), CODE_RELOC_SIZE, MachineResourceManager::codeAddressSpace(), LabelManager::commitLastRelocations(), TPEF::ImmediateElement::destinationUnit(), CodeSectionCreator::InternalElement::dstIndex, CodeSectionCreator::InternalElement::dstType, CodeSectionCreator::InternalElement::dstUnit, CodeSectionCreator::InternalSection::elements, EMPTY, TTAMachine::AddressSpace::end(), LiteralOrExpression::expression, CodeSectionCreator::InternalElement::guardIndex, CodeSectionCreator::InternalElement::guardType, CodeSectionCreator::InternalElement::guardUnit, IMMEDIATE, CodeSectionCreator::InternalElement::immValue, internalSection_, CodeSectionCreator::InternalElement::isBegin, LiteralOrExpression::isExpression, CodeSectionCreator::InternalElement::isGuarded, CodeSectionCreator::InternalElement::isInverted, TTAMachine::Machine::Navigator< ComponentType >::item(), Expression::label, Application::logStream(), mach_, MOVE, MathTools::requiredBits(), LabelManager::resolveExpressionValue(), resources_, MachineResourceManager::resourceSection(), TPEF::Section::setASpace(), TPEF::InstructionElement::setBegin(), TPEF::MoveElement::setBus(), Exception::setCause(), 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::Section::setLink(), TPEF::Section::setName(), TPEF::MoveElement::setSourceIndex(), TPEF::MoveElement::setSourceType(), TPEF::MoveElement::setSourceUnit(), TPEF::ImmediateElement::setWord(), CodeSectionCreator::InternalElement::slot, CodeSectionCreator::InternalElement::srcIndex, CodeSectionCreator::InternalElement::srcType, CodeSectionCreator::InternalElement::srcUnit, MachineResourceManager::stringToChunk(), CodeSectionCreator::InternalElement::type, and LiteralOrExpression::value.
Referenced by AssemblerParser::finalize().
|
private |
Returns next possible index for inline immediate.
Definition at line 550 of file CodeSectionCreator.cc.
References immediateIndex_.
Referenced by addMove().
|
private |
Returns true if RF index or FU port is written twice in a same instruction.
elem | Move to check. |
Definition at line 562 of file CodeSectionCreator.cc.
References CodeSectionCreator::InternalElement::dstIndex, CodeSectionCreator::InternalElement::dstType, CodeSectionCreator::InternalElement::dstUnit, CodeSectionCreator::InternalSection::elements, CodeSectionCreator::InternalElement::guardIndex, CodeSectionCreator::InternalElement::guardType, CodeSectionCreator::InternalElement::guardUnit, internalSection_, CodeSectionCreator::InternalElement::isBegin, CodeSectionCreator::InternalElement::isGuarded, CodeSectionCreator::InternalElement::isInverted, MOVE, and CodeSectionCreator::InternalElement::type.
Referenced by addMove().
void CodeSectionCreator::newSection | ( | UValue | startAddress | ) |
Creator to start new section from given start address.
startAddress | Start address of next section. |
OutOfRange | Start address is not in code address space. |
Definition at line 81 of file CodeSectionCreator.cc.
References internalSection_, and CodeSectionCreator::InternalSection::startAddress.
Referenced by NewCodeSectionActor::operator()().
|
private |
Returns slot number for currently added move.
Definition at line 539 of file CodeSectionCreator.cc.
References slotNumber_.
Referenced by addMove().
|
private |
Inits privat attributes for start of new instruction.
Definition at line 528 of file CodeSectionCreator.cc.
References immediateIndex_, and slotNumber_.
Referenced by addMove().
|
staticprivate |
Bitwidth of immediate value containing address to relocate.
Definition at line 178 of file CodeSectionCreator.hh.
Referenced by finalize().
|
private |
Immediate index.
Definition at line 175 of file CodeSectionCreator.hh.
Referenced by cleanup(), immediateIndex(), and startNewInstruction().
|
private |
Internal representation of code section.
Definition at line 160 of file CodeSectionCreator.hh.
Referenced by addMove(), finalize(), isDestinationAlreadyWritten(), and newSection().
|
private |
Next element is starting element of instruction.
Definition at line 169 of file CodeSectionCreator.hh.
Referenced by cleanup().
|
private |
Definition at line 157 of file CodeSectionCreator.hh.
Referenced by finalize().
|
private |
Place to add warnings during compilation.
Definition at line 166 of file CodeSectionCreator.hh.
Referenced by addMove().
|
private |
TPEF Resources and strings.
Definition at line 163 of file CodeSectionCreator.hh.
Referenced by addMove(), and finalize().
|
private |
Slot number of current move.
Definition at line 172 of file CodeSectionCreator.hh.
Referenced by cleanup(), slotNumber(), and startNewInstruction().