OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Attributes | List of all members
TPEF::AOutTextSectionReader Class Reference

#include <AOutTextSectionReader.hh>

Inheritance diagram for TPEF::AOutTextSectionReader:
Inheritance graph
Collaboration diagram for TPEF::AOutTextSectionReader:
Collaboration graph

Public Member Functions

virtual ~AOutTextSectionReader ()
 
- Public Member Functions inherited from TPEF::AOutSectionReader
virtual ~AOutSectionReader ()
 
- Public Member Functions inherited from TPEF::SectionReader
virtual ~SectionReader ()
 

Static Public Attributes

static const int OFFSET_TO_IMMEDIATE_VALUE = 4
 

Protected Member Functions

 AOutTextSectionReader ()
 
virtual Section::SectionType type () const
 
virtual void readData (BinaryStream &stream, Section *section) const
 
- Protected Member Functions inherited from TPEF::AOutSectionReader
 AOutSectionReader ()
 
virtual BinaryReaderparent () const
 
- Protected Member Functions inherited from TPEF::SectionReader
 SectionReader ()
 
virtual void finalize (Section *section) const
 

Private Member Functions

void initializeImmediateMove (BinaryStream &stream, MoveElement *move, ImmediateElement *immediate) const
 
void initializeMove (BinaryStream &stream, MoveElement *move) const
 
void updateMoveDestination (MoveElement *move, const HalfWord dest) const
 
void updateMoveSource (MoveElement *move, const Word src) const
 
Word convertAOutIndexToTPEF (const Word reg) const
 
void setReference (InstructionElement *elem, SectionOffset sectionOffset, SectionId sectionID) const
 
 AOutTextSectionReader (const AOutTextSectionReader &)
 Copying not allowed.
 
AOutTextSectionReaderoperator= (const AOutTextSectionReader &)
 Assignment not allowed.
 

Static Private Attributes

static AOutTextSectionReader proto_
 Prototype to be registered to SectionReader.
 

Additional Inherited Members

- Public Types inherited from TPEF::SectionReader
typedef BinaryReader::Length Length
 
- Static Public Member Functions inherited from TPEF::SectionReader
static void readSection (BinaryStream &stream, Section *section, BinaryReader *reader)
 
static void finalizeBinary (Binary *binaryToFinalize, BinaryReader *reader)
 
- Static Protected Member Functions inherited from TPEF::SectionReader
static const SectionReaderfindSectionReader (const Section::SectionType type, const BinaryReader *bReader)
 
static void registerSectionReader (const SectionReader *sReader)
 

Detailed Description

Reads text sections of a.out format.

Definition at line 49 of file AOutTextSectionReader.hh.

Constructor & Destructor Documentation

◆ ~AOutTextSectionReader()

TPEF::AOutTextSectionReader::~AOutTextSectionReader ( )
virtual

Destructor.

Definition at line 71 of file AOutTextSectionReader.cc.

71 {
72}

◆ AOutTextSectionReader() [1/2]

TPEF::AOutTextSectionReader::AOutTextSectionReader ( )
protected

Constructor.

Registers itself to SectionReader.

Definition at line 64 of file AOutTextSectionReader.cc.

66}
static void registerSectionReader(const SectionReader *sReader)

References TPEF::SectionReader::registerSectionReader().

Here is the call graph for this function:

◆ AOutTextSectionReader() [2/2]

TPEF::AOutTextSectionReader::AOutTextSectionReader ( const AOutTextSectionReader )
private

Copying not allowed.

Member Function Documentation

◆ convertAOutIndexToTPEF()

Word TPEF::AOutTextSectionReader::convertAOutIndexToTPEF ( const Word  reg) const
private

Convert an a.out register index into a TPEF register index.

Service helper method. The callers are responsible for ensuring that the given register index is within the allowed range.

Parameters
regA.out index of the register.
Returns
The TPEF index of the same register.

Definition at line 209 of file AOutTextSectionReader.cc.

209 {
210
211 // NOTE: This implementation depends on AOutSymbolSectionReader
212 // implementation (Where resource section is read).
213
214 // offset to first index of given register class
215 int regOffset = 0;
216
217 // int reg
220
221 // fp reg
222 } else if (reg < AOutReader::FIRST_BOOL_REGISTER) {
224
225 // bool register
226 } else if (reg < AOutReader::FIRST_FU_REGISTER) {
228
229 // fu or special register
230 } else {
231 regOffset = 0;
232 }
233
234 return reg - regOffset;
235}
static const Word FIRST_INT_REGISTER
Index of the first integer register in a.out.
static const Word FIRST_BOOL_REGISTER
Index of the first Boolean register.
static const Word FIRST_FU_REGISTER
Index of the first function unit register.
static const Word FIRST_FP_REGISTER
Index of the first floating-point register.

References TPEF::AOutReader::FIRST_BOOL_REGISTER, TPEF::AOutReader::FIRST_FP_REGISTER, TPEF::AOutReader::FIRST_FU_REGISTER, and TPEF::AOutReader::FIRST_INT_REGISTER.

Referenced by updateMoveDestination(), and updateMoveSource().

◆ initializeImmediateMove()

void TPEF::AOutTextSectionReader::initializeImmediateMove ( BinaryStream stream,
MoveElement move,
ImmediateElement immediate 
) const
private

The attributes of move that has immediate in its source field are initialized.

Immediate value of a move is modeled as a separate object.

Parameters
streamStream to be read from.
moveMove to be initialized
immediateImmediate to be initialized.
Exceptions
OutOfRangeIf destination register index is too large.
UnreachableStreamIf there occurs problems with stream.

Definition at line 162 of file AOutTextSectionReader.cc.

164 {
165 move->setSourceType(MoveElement::MF_IMM);
166
167 // mark every immediate to be inline encoded
168 immediate->setDestinationUnit(ResourceElement::INLINE_IMM);
169 immediate->setDestinationIndex(0);
170
171 // mark move source to match immediate
172 move->setSourceUnit(ResourceElement::INLINE_IMM);
173 move->setSourceIndex(0);
174
175 HalfWord dest = stream.readHalfWord();
176 updateMoveDestination(move, dest);
177
178 immediate->setWord(stream.readWord());
179}
void updateMoveDestination(MoveElement *move, const HalfWord dest) const
@ MF_IMM
Immediate.
@ INLINE_IMM
Inline immediate unit id.

References TPEF::ResourceElement::INLINE_IMM, TPEF::MoveElement::MF_IMM, TPEF::BinaryStream::readHalfWord(), TPEF::BinaryStream::readWord(), TPEF::ImmediateElement::setDestinationIndex(), TPEF::ImmediateElement::setDestinationUnit(), TPEF::MoveElement::setSourceIndex(), TPEF::MoveElement::setSourceType(), TPEF::MoveElement::setSourceUnit(), TPEF::ImmediateElement::setWord(), and updateMoveDestination().

Referenced by readData().

Here is the call graph for this function:

◆ initializeMove()

void TPEF::AOutTextSectionReader::initializeMove ( BinaryStream stream,
MoveElement move 
) const
private

Initializes an 'ordinary' Move.

Parameters
streamStream to be read from.
moveMove to be initialized.
Exceptions
OutOfRangeIf destination or source register index is too big.
UnreachableStreamIf there occurs problems with stream.

Definition at line 190 of file AOutTextSectionReader.cc.

191 {
192 HalfWord dest = stream.readHalfWord();
193 updateMoveDestination(move, dest);
194
195 Word src = stream.readWord();
196 updateMoveSource(move, src);
197}
void updateMoveSource(MoveElement *move, const Word src) const

References TPEF::BinaryStream::readHalfWord(), TPEF::BinaryStream::readWord(), updateMoveDestination(), and updateMoveSource().

Referenced by readData().

Here is the call graph for this function:

◆ operator=()

AOutTextSectionReader & TPEF::AOutTextSectionReader::operator= ( const AOutTextSectionReader )
private

Assignment not allowed.

◆ readData()

void TPEF::AOutTextSectionReader::readData ( BinaryStream stream,
Section section 
) const
protectedvirtual

Reads all Moves from stream and stores them in to Section.

One move consists of 4 fields: guard (Byte), immediate (Byte), destination index (HalfWord), and source index (Word). If immediate is 1 then the source field of the move contains an immediate value.

Parameters
streamStream to be read from.
sectionPointer to section in which information is stored.
Exceptions
UnreachableStreamIf reading of section fails.
KeyAlreadyExistsKey was in use when trying to register object.
EndOfFileIf end of file were reached while it shouldn't.
OutOfRangeSome of read values were out of range.
WrongSubclassSome class couldn't do what it was asked for.
UnexpectedValueIf there was unexpected value when reading.

Implements TPEF::SectionReader.

Definition at line 101 of file AOutTextSectionReader.cc.

101 {
102 AOutReader* aOutReader = dynamic_cast<AOutReader*>(parent());
103
104 FileOffset offset = stream.readPosition();
105 Word length = aOutReader->header().sectionSizeText();
106
107 while (stream.readPosition() < offset + length) {
108
109 SectionOffset sectionOffset = stream.readPosition() - offset;
110
111 // we must first discover whether instruction is immediate or not
112 Byte guard = stream.readByte();
113 Byte imm = stream.readByte();
114
115 MoveElement* move = new MoveElement();
116 ImmediateElement* immediate = NULL;
117
118 // guard register is the only boolean register of a.out binaries
119 assert((guard == 0) || (guard == '!') || (guard == '?'));
120 move->setGuardUnit(ResourceElement::BOOL_RF);
121 move->setGuardIndex(0);
122 move->setGuardType(MoveElement::MF_RF);
123 move->setGuarded(guard != 0);
124 move->setGuardInverted(guard == '!');
125
126 // always use universal bus
127 move->setBus(ResourceElement::UNIVERSAL_BUS);
128
129 if (imm == 1) {
130 immediate = new ImmediateElement();
131 initializeImmediateMove(stream, move, immediate);
132 immediate->setBegin(true);
133 section->addElement(immediate);
134 section->addElement(move);
135
136 // set reference pointing immediate, since move is never
137 // referenced
138 setReference(immediate, sectionOffset, AOutReader::ST_TEXT);
139
140 } else {
141 initializeMove(stream, move);
142 move->setBegin(true);
143 section->addElement(move);
144 setReference(move, sectionOffset, AOutReader::ST_TEXT);
145 }
146 }
147}
#define assert(condition)
unsigned char Byte
Definition BaseType.hh:116
@ ST_TEXT
Text section.
virtual BinaryReader * parent() const
void initializeMove(BinaryStream &stream, MoveElement *move) const
void setReference(InstructionElement *elem, SectionOffset sectionOffset, SectionId sectionID) const
void initializeImmediateMove(BinaryStream &stream, MoveElement *move, ImmediateElement *immediate) const
@ MF_RF
Register file.
@ UNIVERSAL_BUS
Universal bus.
@ BOOL_RF
Universal boolean register file.
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Word FileOffset
Type for storing absolute file offsets.

References TPEF::Section::addElement(), assert, TPEF::ResourceElement::BOOL_RF, TPEF::AOutReader::header(), initializeImmediateMove(), initializeMove(), TPEF::MoveElement::MF_RF, TPEF::AOutSectionReader::parent(), TPEF::BinaryStream::readByte(), TPEF::BinaryStream::readPosition(), TPEF::AOutReader::Header::sectionSizeText(), TPEF::InstructionElement::setBegin(), TPEF::MoveElement::setBus(), TPEF::MoveElement::setGuarded(), TPEF::MoveElement::setGuardIndex(), TPEF::MoveElement::setGuardInverted(), TPEF::MoveElement::setGuardType(), TPEF::MoveElement::setGuardUnit(), setReference(), TPEF::AOutReader::ST_TEXT, and TPEF::ResourceElement::UNIVERSAL_BUS.

Here is the call graph for this function:

◆ setReference()

void TPEF::AOutTextSectionReader::setReference ( InstructionElement elem,
SectionOffset  sectionOffset,
SectionId  sectionID 
) const
private

Sets references to ReferenceManager to enable referencing if it's needed later.

Parameters
elemElement to be registered to ReferenceManager.
sectionOffsetThe offset of the element in the section.
sectionIDIdentification code of the referenced section.
Exceptions
KeyAlreadyExistsIf registration fails because of existing key.

Definition at line 319 of file AOutTextSectionReader.cc.

321 {
322 SectionOffsetKey offKey = SectionOffsetKey(sectionID, sectionOffset);
324}
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)

References TPEF::ReferenceManager::SafePointer::addObjectReference().

Referenced by readData().

Here is the call graph for this function:

◆ type()

Section::SectionType TPEF::AOutTextSectionReader::type ( ) const
protectedvirtual

Returns section type which reader can read.

Returns
The type of the section that reader can read.

Implements TPEF::SectionReader.

Definition at line 80 of file AOutTextSectionReader.cc.

80 {
81 return Section::ST_CODE;
82}
@ ST_CODE
Text section.
Definition Section.hh:79

References TPEF::Section::ST_CODE.

◆ updateMoveDestination()

void TPEF::AOutTextSectionReader::updateMoveDestination ( MoveElement move,
const HalfWord  dest 
) const
private

Convert an a.out register index to a TPEF register index and update the destination of the given move to reflect the given register index.

Possible values of move destination field are indices of: integer registers, floating point registers, Boolean registers, or function unit registers. The type of the move destination is also set.

Parameters
moveThe Move to be updated.
destIndex of the destination register.
Exceptions
OutOfRangeIf destination index is too large.

Definition at line 250 of file AOutTextSectionReader.cc.

251 {
253 move->setDestinationUnit(ResourceElement::INT_RF);
254 move->setDestinationType(MoveElement::MF_RF);
255
256 } else if (dest < AOutReader::FIRST_BOOL_REGISTER) {
257 move->setDestinationUnit(ResourceElement::FP_RF);
258 move->setDestinationType(MoveElement::MF_RF);
259
260 } else if (dest < AOutReader::FIRST_FU_REGISTER) {
261 move->setDestinationUnit(ResourceElement::BOOL_RF);
262 move->setDestinationType(MoveElement::MF_RF);
263
264 } else {
265 // for special registers move type fields is same that for fu
266 move->setDestinationUnit(ResourceElement::UNIVERSAL_FU);
267 move->setDestinationType(MoveElement::MF_UNIT);
268 }
269
270 move->setDestinationIndex(convertAOutIndexToTPEF(dest));
271}
Word convertAOutIndexToTPEF(const Word reg) const
@ MF_UNIT
Function unit.
@ UNIVERSAL_FU
Universal function unit.
@ INT_RF
Universal integer register file.
@ FP_RF
Universal floating point register file.

References TPEF::ResourceElement::BOOL_RF, convertAOutIndexToTPEF(), TPEF::AOutReader::FIRST_BOOL_REGISTER, TPEF::AOutReader::FIRST_FP_REGISTER, TPEF::AOutReader::FIRST_FU_REGISTER, TPEF::ResourceElement::FP_RF, TPEF::ResourceElement::INT_RF, TPEF::MoveElement::MF_RF, TPEF::MoveElement::MF_UNIT, TPEF::MoveElement::setDestinationIndex(), TPEF::MoveElement::setDestinationType(), TPEF::MoveElement::setDestinationUnit(), and TPEF::ResourceElement::UNIVERSAL_FU.

Referenced by initializeImmediateMove(), and initializeMove().

Here is the call graph for this function:

◆ updateMoveSource()

void TPEF::AOutTextSectionReader::updateMoveSource ( MoveElement move,
const Word  src 
) const
private

Convert an a.out register index to a TPEF register index and update the source of the given move to reflect the given register index.

Possible values of move source field are indices of: integer registers, floating point registers, Boolean registers, or function unit registers. The type of the move source is also set.

Parameters
moveThe Move to be updated.
srcIndex of the source register.
Exceptions
OutOfRangeIf source index is too large.

Definition at line 286 of file AOutTextSectionReader.cc.

287 {
289 move->setSourceUnit(ResourceElement::INT_RF);
290 move->setSourceType(MoveElement::MF_RF);
291
292 } else if (src < AOutReader::FIRST_BOOL_REGISTER) {
293 move->setSourceUnit(ResourceElement::FP_RF);
294 move->setSourceType(MoveElement::MF_RF);
295
296 } else if (src < AOutReader::FIRST_FU_REGISTER) {
297 move->setSourceUnit(ResourceElement::BOOL_RF);
298 move->setSourceType(MoveElement::MF_RF);
299
300 } else {
301 // for special registers move type fields is same that for fu
302 move->setSourceUnit(ResourceElement::UNIVERSAL_FU);
303 move->setSourceType(MoveElement::MF_UNIT);
304 }
305
306 move->setSourceIndex(convertAOutIndexToTPEF(src));
307}

References TPEF::ResourceElement::BOOL_RF, convertAOutIndexToTPEF(), TPEF::AOutReader::FIRST_BOOL_REGISTER, TPEF::AOutReader::FIRST_FP_REGISTER, TPEF::AOutReader::FIRST_FU_REGISTER, TPEF::ResourceElement::FP_RF, TPEF::ResourceElement::INT_RF, TPEF::MoveElement::MF_RF, TPEF::MoveElement::MF_UNIT, TPEF::MoveElement::setSourceIndex(), TPEF::MoveElement::setSourceType(), TPEF::MoveElement::setSourceUnit(), and TPEF::ResourceElement::UNIVERSAL_FU.

Referenced by initializeMove().

Here is the call graph for this function:

Member Data Documentation

◆ OFFSET_TO_IMMEDIATE_VALUE

const int TPEF::AOutTextSectionReader::OFFSET_TO_IMMEDIATE_VALUE = 4
static

◆ proto_

AOutTextSectionReader TPEF::AOutTextSectionReader::proto_
staticprivate

Prototype to be registered to SectionReader.

Definition at line 84 of file AOutTextSectionReader.hh.


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