OpenASIP  2.0
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. More...
 
AOutTextSectionReaderoperator= (const AOutTextSectionReader &)
 Assignment not allowed. More...
 

Static Private Attributes

static AOutTextSectionReader proto_
 Prototype to be registered to SectionReader. More...
 

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.

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
218  if (reg < AOutReader::FIRST_FP_REGISTER) {
219  regOffset = AOutReader::FIRST_INT_REGISTER;
220 
221  // fp reg
222  } else if (reg < AOutReader::FIRST_BOOL_REGISTER) {
223  regOffset = AOutReader::FIRST_FP_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 }

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 }

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 }

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 }

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);
323  SafePointer::addObjectReference(offKey, elem);
324 }

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 }

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  {
252  if (dest < AOutReader::FIRST_FP_REGISTER) {
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 }

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  {
288  if (src < AOutReader::FIRST_FP_REGISTER) {
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:
TPEF::AOutTextSectionReader::initializeMove
void initializeMove(BinaryStream &stream, MoveElement *move) const
Definition: AOutTextSectionReader.cc:190
TPEF::AOutTextSectionReader::updateMoveDestination
void updateMoveDestination(MoveElement *move, const HalfWord dest) const
Definition: AOutTextSectionReader.cc:250
TPEF::AOutTextSectionReader::initializeImmediateMove
void initializeImmediateMove(BinaryStream &stream, MoveElement *move, ImmediateElement *immediate) const
Definition: AOutTextSectionReader.cc:162
TPEF::ResourceElement::BOOL_RF
@ BOOL_RF
Universal boolean register file.
Definition: ResourceElement.hh:68
TPEF::MoveElement::MF_UNIT
@ MF_UNIT
Function unit.
Definition: MoveElement.hh:56
TPEF::MoveElement::MF_IMM
@ MF_IMM
Immediate.
Definition: MoveElement.hh:55
TPEF::AOutTextSectionReader::convertAOutIndexToTPEF
Word convertAOutIndexToTPEF(const Word reg) const
Definition: AOutTextSectionReader.cc:209
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::ReferenceManager::SafePointer::addObjectReference
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
Definition: SafePointer.cc:306
TPEF::MoveElement::MF_RF
@ MF_RF
Register file.
Definition: MoveElement.hh:54
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::AOutReader::FIRST_BOOL_REGISTER
static const Word FIRST_BOOL_REGISTER
Index of the first Boolean register.
Definition: AOutReader.hh:135
TPEF::ResourceElement::INLINE_IMM
@ INLINE_IMM
Inline immediate unit id.
Definition: ResourceElement.hh:72
TPEF::AOutSectionReader::parent
virtual BinaryReader * parent() const
Definition: AOutSectionReader.cc:57
TPEF::FileOffset
Word FileOffset
Type for storing absolute file offsets.
Definition: TPEFBaseType.hh:52
TPEF::SectionReader::registerSectionReader
static void registerSectionReader(const SectionReader *sReader)
Definition: SectionReader.cc:145
TPEF::AOutSectionReader::AOutSectionReader
AOutSectionReader()
Definition: AOutSectionReader.cc:41
TPEF::AOutReader::ST_TEXT
@ ST_TEXT
Text section.
Definition: AOutReader.hh:116
TPEF::AOutTextSectionReader::setReference
void setReference(InstructionElement *elem, SectionOffset sectionOffset, SectionId sectionID) const
Definition: AOutTextSectionReader.cc:319
TPEF::SectionOffset
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Definition: TPEFBaseType.hh:49
TPEF::AOutTextSectionReader::updateMoveSource
void updateMoveSource(MoveElement *move, const Word src) const
Definition: AOutTextSectionReader.cc:286
TPEF::AOutReader::FIRST_FU_REGISTER
static const Word FIRST_FU_REGISTER
Index of the first function unit register.
Definition: AOutReader.hh:137
TPEF::ResourceElement::UNIVERSAL_BUS
@ UNIVERSAL_BUS
Universal bus.
Definition: ResourceElement.hh:64
TPEF::ResourceElement::FP_RF
@ FP_RF
Universal floating point register file.
Definition: ResourceElement.hh:69
TPEF::Section::ST_CODE
@ ST_CODE
Text section.
Definition: Section.hh:79
TPEF::ResourceElement::INT_RF
@ INT_RF
Universal integer register file.
Definition: ResourceElement.hh:67
TPEF::AOutReader::FIRST_FP_REGISTER
static const Word FIRST_FP_REGISTER
Index of the first floating-point register.
Definition: AOutReader.hh:133
TPEF::AOutReader::FIRST_INT_REGISTER
static const Word FIRST_INT_REGISTER
Index of the first integer register in a.out.
Definition: AOutReader.hh:131
TPEF::ResourceElement::UNIVERSAL_FU
@ UNIVERSAL_FU
Universal function unit.
Definition: ResourceElement.hh:65