OpenASIP  2.0
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Static Private Attributes | List of all members
TPEF::TPEFSectionReader Class Reference

#include <TPEFSectionReader.hh>

Inheritance diagram for TPEF::TPEFSectionReader:
Inheritance graph
Collaboration diagram for TPEF::TPEFSectionReader:
Collaboration graph

Classes

struct  Header
 

Public Member Functions

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

Protected Member Functions

 TPEFSectionReader ()
 
virtual void readData (BinaryStream &stream, Section *section) const
 
virtual BinaryReaderparent () const
 
virtual void readInfo (BinaryStream &stream, Section *sect) const
 
- Protected Member Functions inherited from TPEF::SectionReader
 SectionReader ()
 
virtual Section::SectionType type () const =0
 Returns type (TPEF) section which actual section reader reads. More...
 
virtual void finalize (Section *section) const
 

Static Protected Member Functions

static const Headerheader ()
 
- Static Protected Member Functions inherited from TPEF::SectionReader
static const SectionReaderfindSectionReader (const Section::SectionType type, const BinaryReader *bReader)
 
static void registerSectionReader (const SectionReader *sReader)
 

Private Member Functions

 TPEFSectionReader (const TPEFSectionReader &)
 

Static Private Attributes

static Header header_
 Stores values that are needed in actual SectionReader classes. 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)
 

Detailed Description

Abstract base class for all TPEFSectionReaders.

Class implements default definitions of virtual methods declared in SectionReader class and reading headers of TPEF sections.

Definition at line 48 of file TPEFSectionReader.hh.

Constructor & Destructor Documentation

◆ ~TPEFSectionReader()

TPEF::TPEFSectionReader::~TPEFSectionReader ( )
virtual

Destructor

Definition at line 56 of file TPEFSectionReader.cc.

56  {
57 }

◆ TPEFSectionReader() [1/2]

TPEF::TPEFSectionReader::TPEFSectionReader ( )
protected

Constructor

Definition at line 50 of file TPEFSectionReader.cc.

50  : SectionReader() {
51 }

◆ TPEFSectionReader() [2/2]

TPEF::TPEFSectionReader::TPEFSectionReader ( const TPEFSectionReader )
private

Member Function Documentation

◆ header()

const TPEFSectionReader::Header & TPEF::TPEFSectionReader::header ( )
staticprotected

◆ parent()

BinaryReader * TPEF::TPEFSectionReader::parent ( ) const
protectedvirtual

◆ readData()

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

Reads section data from TPEF binary file.

Base implementation for all TPEF section readers. Reads and keeps section header data for later use by concrete section readers. Header data is accessed by readData methods of subclasses.

Parameters
streamStream to be read from.
sectionSection where the information is to be 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.

Reimplemented in TPEF::TPEFRelocSectionReader, TPEF::TPEFCodeSectionReader, TPEF::TPEFLineNumSectionReader, TPEF::TPEFResourceSectionReader, TPEF::TPEFSymbolSectionReader, TPEF::TPEFASpaceSectionReader, TPEF::TPEFDataSectionReader, TPEF::TPEFDebugSectionReader, TPEF::TPEFStringSectionReader, and TPEF::TPEFUDataSectionReader.

Definition at line 86 of file TPEFSectionReader.cc.

86  {
87  TPEFReader* tpefReader = dynamic_cast<TPEFReader*>(parent());
88 
89  FileOffset startOffset = stream.readPosition();
90  stream.setReadPosition(startOffset + TPEFHeaders::SH_FLAGS);
91  Byte sectionFlags = stream.readByte();
92 
93  // if section vLen flag is not equal to the read value
94  if(section->vLen() != ((sectionFlags & Section::SF_VLEN) != 0)) {
95  throw UnexpectedValue(
96  __FILE__, __LINE__, __func__,
97  "read SF_VLEN flag doesn't match for section");
98  }
99 
100  section->setFlags(sectionFlags);
101 
102  stream.setReadPosition(startOffset + TPEFHeaders::SH_ADDR);
103  section->setStartingAddress(stream.readWord());
104 
105  stream.setReadPosition(startOffset + TPEFHeaders::SH_LINK);
106  header_.linkId = stream.readHalfWord();
107 
108  SectionKey linkKey(header_.linkId);
109  section->setLink(CREATE_SAFEPOINTER(linkKey));
110 
111  // set address space reference
112  stream.setReadPosition(startOffset + TPEFHeaders::SH_ASPACE);
113  Byte aSpaceIndex = stream.readByte();
114  SectionIndexKey aSpaceKey(tpefReader->aSpaceId(), aSpaceIndex);
115  section->setASpace(CREATE_SAFEPOINTER(aSpaceKey));
116 
117  // set name
118  stream.setReadPosition(startOffset + TPEFHeaders::SH_NAME);
119  Word sectionOffsetOfName = stream.readWord();
120 
121  if (tpefReader->strTableId() != 0) {
122  SectionOffsetKey nameKey(tpefReader->strTableId(),
123  sectionOffsetOfName);
124 
125  section->setName(CREATE_SAFEPOINTER(nameKey));
126  } else {
127  section->setName(&SafePointer::null);
128  }
129 
130  // add section key for new section
131  stream.setReadPosition(startOffset + TPEFHeaders::SH_ID);
132  header_.sectionId = stream.readHalfWord();
133 
134  SectionKey sectionKey(header_.sectionId);
135  SafePointer::addObjectReference(sectionKey, section);
136 
137  stream.setReadPosition(startOffset + TPEFHeaders::SH_INFO);
138  readInfo(stream, section);
139 
140  stream.setReadPosition(startOffset + TPEFHeaders::SH_ENTSIZE);
141  header_.elementSize = stream.readWord();
142 
143  // read offset of section body
144  stream.setReadPosition(startOffset + TPEFHeaders::SH_OFFSET);
145  header_.bodyOffset = stream.readWord();
146 
147  stream.setReadPosition(startOffset + TPEFHeaders::SH_SIZE);
148  header_.bodyLength = stream.readWord();
149 
150  // actual class does reading of section body
151  stream.setReadPosition(header_.bodyOffset);
152 }

References __func__, TPEF::ReferenceManager::SafePointer::addObjectReference(), TPEF::TPEFReader::aSpaceId(), TPEF::TPEFSectionReader::Header::bodyLength, TPEF::TPEFSectionReader::Header::bodyOffset, TPEF::TPEFSectionReader::Header::elementSize, header_, TPEF::TPEFSectionReader::Header::linkId, TPEF::ReferenceManager::SafePointer::null, parent(), TPEF::BinaryStream::readByte(), TPEF::BinaryStream::readHalfWord(), readInfo(), TPEF::BinaryStream::readPosition(), TPEF::BinaryStream::readWord(), TPEF::TPEFSectionReader::Header::sectionId, TPEF::Section::setASpace(), TPEF::Section::setFlags(), TPEF::Section::setLink(), TPEF::Section::setName(), TPEF::BinaryStream::setReadPosition(), TPEF::Section::setStartingAddress(), TPEF::Section::SF_VLEN, TPEF::TPEFHeaders::SH_ADDR, TPEF::TPEFHeaders::SH_ASPACE, TPEF::TPEFHeaders::SH_ENTSIZE, TPEF::TPEFHeaders::SH_FLAGS, TPEF::TPEFHeaders::SH_ID, TPEF::TPEFHeaders::SH_INFO, TPEF::TPEFHeaders::SH_LINK, TPEF::TPEFHeaders::SH_NAME, TPEF::TPEFHeaders::SH_OFFSET, TPEF::TPEFHeaders::SH_SIZE, TPEF::TPEFReader::strTableId(), and TPEF::Section::vLen().

Referenced by TPEF::TPEFASpaceSectionReader::readData(), TPEF::TPEFDebugSectionReader::readData(), TPEF::TPEFStringSectionReader::readData(), TPEF::TPEFUDataSectionReader::readData(), TPEF::TPEFDataSectionReader::readData(), TPEF::TPEFCodeSectionReader::readData(), TPEF::TPEFSymbolSectionReader::readData(), TPEF::TPEFLineNumSectionReader::readData(), TPEF::TPEFResourceSectionReader::readData(), and TPEF::TPEFRelocSectionReader::readData().

Here is the call graph for this function:

◆ readInfo()

void TPEF::TPEFSectionReader::readInfo ( BinaryStream stream,
Section sect 
) const
protectedvirtual

Reads info field of section header.

Read position of stream will be moved 4 bytes forward.

Parameters
streamStream where from info word is read.

Reimplemented in TPEF::TPEFRelocSectionReader, TPEF::TPEFCodeSectionReader, and TPEF::TPEFLineNumSectionReader.

Definition at line 162 of file TPEFSectionReader.cc.

163  {
164  // move four bytes forward by default
165  stream.readWord();
166 }

References TPEF::BinaryStream::readWord().

Referenced by readData().

Here is the call graph for this function:

Member Data Documentation

◆ header_

TPEFSectionReader::Header TPEF::TPEFSectionReader::header_
staticprivate

Stores values that are needed in actual SectionReader classes.

Definition at line 79 of file TPEFSectionReader.hh.

Referenced by header(), and readData().


The documentation for this class was generated from the following files:
TPEF::TPEFReader::instance
static BinaryReader * instance()
Definition: TPEFReader.cc:262
TPEF::TPEFHeaders::SH_LINK
@ SH_LINK
Section identifier link.
Definition: TPEFHeaders.hh:88
TPEF::SectionReader::SectionReader
SectionReader()
Definition: SectionReader.cc:57
TPEF::TPEFSectionReader::Header::bodyOffset
Word bodyOffset
Definition: TPEFSectionReader.hh:69
TPEF::TPEFHeaders::SH_OFFSET
@ SH_OFFSET
Offset to section data.
Definition: TPEFHeaders.hh:83
TPEF::ReferenceManager::SafePointer::null
static const SafePointer null
The default SafePointer that is used in null references.
Definition: SafePointer.hh:229
TPEF::TPEFHeaders::SH_ASPACE
@ SH_ASPACE
Section address space identifier.
Definition: TPEFHeaders.hh:86
TPEF::TPEFHeaders::SH_INFO
@ SH_INFO
Section specific information, usually zero.
Definition: TPEFHeaders.hh:89
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::TPEFSectionReader::Header::elementSize
Word elementSize
Definition: TPEFSectionReader.hh:68
TPEF::TPEFHeaders::SH_ENTSIZE
@ SH_ENTSIZE
Size of section elements (if fixed size).
Definition: TPEFHeaders.hh:90
UnexpectedValue
Definition: Exception.hh:455
TPEF::TPEFHeaders::SH_ID
@ SH_ID
Section identification code.
Definition: TPEFHeaders.hh:85
TPEF::TPEFSectionReader::readInfo
virtual void readInfo(BinaryStream &stream, Section *sect) const
Definition: TPEFSectionReader.cc:162
__func__
#define __func__
Definition: Application.hh:67
TPEF::FileOffset
Word FileOffset
Type for storing absolute file offsets.
Definition: TPEFBaseType.hh:52
TPEF::TPEFSectionReader::Header::linkId
SectionId linkId
Definition: TPEFSectionReader.hh:66
TPEF::TPEFSectionReader::parent
virtual BinaryReader * parent() const
Definition: TPEFSectionReader.cc:65
TPEF::TPEFHeaders::SH_SIZE
@ SH_SIZE
Size of section data.
Definition: TPEFHeaders.hh:84
TPEF::Section::SF_VLEN
@ SF_VLEN
Contains elements with variable length.
Definition: Section.hh:90
TPEF::TPEFHeaders::SH_ADDR
@ SH_ADDR
Starting memory address of program section.
Definition: TPEFHeaders.hh:82
TPEF::TPEFHeaders::SH_FLAGS
@ SH_FLAGS
Flags of section.
Definition: TPEFHeaders.hh:81
TPEF::TPEFHeaders::SH_NAME
@ SH_NAME
Section offset to name.
Definition: TPEFHeaders.hh:79
TPEF::TPEFSectionReader::header_
static Header header_
Stores values that are needed in actual SectionReader classes.
Definition: TPEFSectionReader.hh:79
TPEF::TPEFSectionReader::Header::bodyLength
Word bodyLength
Definition: TPEFSectionReader.hh:70
TPEF::TPEFSectionReader::Header::sectionId
SectionId sectionId
Definition: TPEFSectionReader.hh:65