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

#include <TPEFASpaceSectionReader.hh>

Inheritance diagram for TPEF::TPEFASpaceSectionReader:
Inheritance graph
Collaboration diagram for TPEF::TPEFASpaceSectionReader:
Collaboration graph

Protected Member Functions

 TPEFASpaceSectionReader ()
 
virtual ~TPEFASpaceSectionReader ()
 
virtual void readData (BinaryStream &stream, Section *section) const
 
virtual Section::SectionType type () const
 
- Protected Member Functions inherited from TPEF::TPEFSectionReader
 TPEFSectionReader ()
 
virtual BinaryReaderparent () const
 
virtual void readInfo (BinaryStream &stream, Section *sect) const
 
- Protected Member Functions inherited from TPEF::SectionReader
 SectionReader ()
 
virtual void finalize (Section *section) const
 

Private Member Functions

 TPEFASpaceSectionReader (const TPEFASpaceSectionReader &)
 Copying not allowed. More...
 
TPEFASpaceSectionReaderoperator= (TPEFASpaceSectionReader &)
 Assignment not allowed. More...
 

Static Private Attributes

static TPEFASpaceSectionReader proto_
 Prototype instance of TPEFASpaceSectionReader to be registered to SectionReader. More...
 

Additional Inherited Members

- Public Types inherited from TPEF::SectionReader
typedef BinaryReader::Length Length
 
- Public Member Functions inherited from TPEF::TPEFSectionReader
virtual ~TPEFSectionReader ()
 
- Public Member Functions inherited from TPEF::SectionReader
virtual ~SectionReader ()
 
- 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::TPEFSectionReader
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)
 

Detailed Description

Reads address space section from TPEF binary file.

Definition at line 46 of file TPEFASpaceSectionReader.hh.

Constructor & Destructor Documentation

◆ TPEFASpaceSectionReader() [1/2]

TPEF::TPEFASpaceSectionReader::TPEFASpaceSectionReader ( )
protected

Constructor.

Registers itself to SectionReader.

Definition at line 57 of file TPEFASpaceSectionReader.cc.

References TPEF::SectionReader::registerSectionReader().

Here is the call graph for this function:

◆ ~TPEFASpaceSectionReader()

TPEF::TPEFASpaceSectionReader::~TPEFASpaceSectionReader ( )
protectedvirtual

Destructor.

Definition at line 64 of file TPEFASpaceSectionReader.cc.

64  {
65 }

◆ TPEFASpaceSectionReader() [2/2]

TPEF::TPEFASpaceSectionReader::TPEFASpaceSectionReader ( const TPEFASpaceSectionReader )
private

Copying not allowed.

Member Function Documentation

◆ operator=()

TPEFASpaceSectionReader& TPEF::TPEFASpaceSectionReader::operator= ( TPEFASpaceSectionReader )
private

Assignment not allowed.

◆ readData()

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

Reads section data from TPEF binary file.

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 value were out of range.
WrongSubclassSome class couldn't do what it was asked for.
UnexpectedValueIf there was unexpected value when reading.

Reimplemented from TPEF::TPEFSectionReader.

Definition at line 90 of file TPEFASpaceSectionReader.cc.

91  {
92  // base classes implementation must be called with these.
93  TPEFSectionReader::readData(stream, section);
94 
95  // just being paranoid...
96  ASpaceSection* aSpaceSection =
97  dynamic_cast<ASpaceSection*>(section);
98  assert(aSpaceSection != NULL);
99 
100  std::set<Byte> alreadyUsedIds;
101 
102  bool undefFound = false;
103 
104  // check that link section is defined properly
105  assert(header().linkId != 0);
106 
107  if (!section->noBits()) {
108  // start of first element
109  SectionOffset elementStart = header().bodyOffset;
110 
111  while (elementStart + header().elementSize <=
112  header().bodyOffset + header().bodyLength) {
113 
114  ASpaceElement *elem = new ASpaceElement();
115 
116  // first byte of address space element is a unique identifier
117  Byte id = stream.readByte();
118 
119  // check that the identifier is really unique
120  if (alreadyUsedIds.find(id) != alreadyUsedIds.end()) {
121  bool twoASpaceElementsWithSameId = false;
122  assert(twoASpaceElementsWithSameId);
123  } else {
124  alreadyUsedIds.insert(id);
125  }
126 
127  SectionIndexKey sectionIndexKey(
128  dynamic_cast<TPEFReader*>(parent())->aSpaceId(), id);
129  SafePointer::addObjectReference(sectionIndexKey, elem);
130 
131  elem->setMAU(stream.readByte());
132  elem->setAlign(stream.readByte());
133  elem->setWordSize(stream.readByte());
134 
135  SectionOffsetKey nameSectionOffset(
136  header().linkId, stream.readWord());
137 
138  elem->setName(CREATE_SAFEPOINTER(nameSectionOffset));
139 
140  // check undef aspace
141  if (id == 0) {
142  assert(elem->MAU() == 0);
143  assert(elem->align() == 0);
144  assert(elem->wordSize() == 0);
145  assert(nameSectionOffset.offset() == 0);
146  aSpaceSection->setUndefinedASpace(elem);
147  undefFound = true;
148  }
149 
150  section->addElement(elem);
151 
152  elementStart += header().elementSize;
153  stream.setReadPosition(elementStart);
154  }
155  }
156 
157  // if there was no undef aspace create it (if nobits flag is set)
158  if (!undefFound) {
159  ASpaceElement *elem = new ASpaceElement();
160  elem->setMAU(0);
161  elem->setAlign(0);
162  elem->setWordSize(0);
163  section->addElement(elem);
164  aSpaceSection->setUndefinedASpace(elem);
165  }
166 }

References TPEF::Section::addElement(), TPEF::ReferenceManager::SafePointer::addObjectReference(), TPEF::ASpaceElement::align(), assert, TPEF::TPEFSectionReader::Header::bodyOffset, TPEF::TPEFSectionReader::Header::elementSize, TPEF::TPEFSectionReader::header(), TPEF::ASpaceElement::MAU(), TPEF::Section::noBits(), TPEF::ReferenceManager::SectionOffsetKey::offset(), TPEF::TPEFSectionReader::parent(), TPEF::BinaryStream::readByte(), TPEF::TPEFSectionReader::readData(), TPEF::BinaryStream::readWord(), TPEF::ASpaceElement::setAlign(), TPEF::ASpaceElement::setMAU(), TPEF::ASpaceElement::setName(), TPEF::BinaryStream::setReadPosition(), TPEF::ASpaceSection::setUndefinedASpace(), TPEF::ASpaceElement::setWordSize(), and TPEF::ASpaceElement::wordSize().

Here is the call graph for this function:

◆ type()

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

Returns the type of section it is meant to read.

Returns
The type of section it can read.

Implements TPEF::SectionReader.

Definition at line 73 of file TPEFASpaceSectionReader.cc.

73  {
74  return Section::ST_ADDRSP;
75 }

References TPEF::Section::ST_ADDRSP.

Member Data Documentation

◆ proto_

TPEFASpaceSectionReader TPEF::TPEFASpaceSectionReader::proto_
staticprivate

Prototype instance of TPEFASpaceSectionReader to be registered to SectionReader.

Definition at line 63 of file TPEFASpaceSectionReader.hh.


The documentation for this class was generated from the following files:
TPEF::TPEFSectionReader::TPEFSectionReader
TPEFSectionReader()
Definition: TPEFSectionReader.cc:50
TPEF::TPEFSectionReader::Header::bodyOffset
Word bodyOffset
Definition: TPEFSectionReader.hh:69
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
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::SectionReader::registerSectionReader
static void registerSectionReader(const SectionReader *sReader)
Definition: SectionReader.cc:145
TPEF::TPEFSectionReader::parent
virtual BinaryReader * parent() const
Definition: TPEFSectionReader.cc:65
TPEF::SectionOffset
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Definition: TPEFBaseType.hh:49
TPEF::TPEFSectionReader::readData
virtual void readData(BinaryStream &stream, Section *section) const
Definition: TPEFSectionReader.cc:86
TPEF::Section::ST_ADDRSP
@ ST_ADDRSP
Address space section.
Definition: Section.hh:77
TPEF::TPEFSectionReader::header
static const Header & header()
Definition: TPEFSectionReader.cc:174