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

#include <TPEFASpaceSectionWriter.hh>

Inheritance diagram for TPEF::TPEFASpaceSectionWriter:
Inheritance graph
Collaboration diagram for TPEF::TPEFASpaceSectionWriter:
Collaboration graph

Protected Member Functions

 TPEFASpaceSectionWriter ()
 
virtual ~TPEFASpaceSectionWriter ()
 
virtual Section::SectionType type () const
 
virtual void actualWriteData (BinaryStream &stream, const Section *section) const
 
virtual Word elementSize (const Section *section) const
 
- Protected Member Functions inherited from TPEF::TPEFSectionWriter
 TPEFSectionWriter ()
 
virtual ~TPEFSectionWriter ()
 
virtual const BinaryWriterparent () const
 
virtual void actualWriteHeader (BinaryStream &stream, const Section *sect) const
 
virtual void createKeys (const Section *sect) const
 
virtual void writeSize (BinaryStream &stream, const Section *sect) const
 
virtual void writeInfo (BinaryStream &stream, const Section *sect) const
 
virtual SectionId getSectionId () const
 
- Protected Member Functions inherited from TPEF::SectionWriter
 SectionWriter ()
 
virtual ~SectionWriter ()
 
virtual void finalize (BinaryStream &stream, Section *section) const
 

Private Member Functions

 TPEFASpaceSectionWriter (const TPEFASpaceSectionWriter &)
 Copying not allowed. More...
 
TPEFASpaceSectionWriter operator= (const TPEFASpaceSectionWriter &)
 Assignment not allowed. More...
 
void writeElement (BinaryStream &stream, const ASpaceElement *elem, SectionId id, Word index) const
 

Static Private Attributes

static const TPEFASpaceSectionWriter instance_
 An unique instance of class. More...
 
static const Word elementSize_ = 8
 The fixed size address space element. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from TPEF::SectionWriter
static void writeHeader (BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
 
static void writeData (BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
 
static void finalizeBinary (BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
 
- Static Protected Member Functions inherited from TPEF::SectionWriter
static void registerSectionWriter (const SectionWriter *sWriter)
 
static SectionId getUniqueSectionId ()
 

Detailed Description

Writes TPEF address space section to stream.

Definition at line 47 of file TPEFASpaceSectionWriter.hh.

Constructor & Destructor Documentation

◆ TPEFASpaceSectionWriter() [1/2]

TPEF::TPEFASpaceSectionWriter::TPEFASpaceSectionWriter ( )
protected

Constructor.

Registers itself to SectionWriter.

Definition at line 63 of file TPEFASpaceSectionWriter.cc.

63  : TPEFSectionWriter() {
65 }

References TPEF::SectionWriter::registerSectionWriter().

Here is the call graph for this function:

◆ ~TPEFASpaceSectionWriter()

TPEF::TPEFASpaceSectionWriter::~TPEFASpaceSectionWriter ( )
protectedvirtual

Destructor.

Definition at line 70 of file TPEFASpaceSectionWriter.cc.

70  {
71 }

◆ TPEFASpaceSectionWriter() [2/2]

TPEF::TPEFASpaceSectionWriter::TPEFASpaceSectionWriter ( const TPEFASpaceSectionWriter )
private

Copying not allowed.

Member Function Documentation

◆ actualWriteData()

void TPEF::TPEFASpaceSectionWriter::actualWriteData ( BinaryStream stream,
const Section sect 
) const
protectedvirtual

Writes the data of the section in to stream.

Parameters
streamThe stream to be written to.
sectThe section to be written.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 90 of file TPEFASpaceSectionWriter.cc.

92  {
93 
94  FileOffset startOffset = stream.writePosition();
95 
96  // file offset to data of section
98  FileOffsetKey(startOffset), sect->element(0));
99 
100  // resolve identification code of currently written section
101  SectionKey sectionKey = SafePointer::sectionKeyFor(sect);
102 
103  SectionId sectionId = sectionKey.sectionId();
104 
105  // index zero is reserved for undefined element.
106  Byte index = 1;
107  bool undefASpaceWritten = false;
108 
109  for (unsigned int i = 0; i < sect->elementCount(); i++) {
110 
111  ASpaceElement* elem = dynamic_cast<ASpaceElement*>(sect->element(i));
112  assert(elem != NULL);
113 
114  // references to undefined address space will be written out as
115  // identification code zero
116  if (dynamic_cast<const ASpaceSection*>(sect)->isUndefined(elem)) {
117  assert(elem->MAU() == 0);
118  assert(elem->wordSize() == 0);
119  assert(elem->align() == 0);
120  undefASpaceWritten = true;
121  writeElement(stream, elem, sectionId, 0);
122  } else {
123  writeElement(stream, elem, sectionId, index);
124  }
125 
126  index++;
127  }
128 
129  assert(undefASpaceWritten);
130 
131  SectionSizeReplacer::setSize(sect, stream.writePosition() - startOffset);
132 }

References TPEF::ReferenceManager::SafePointer::addObjectReference(), TPEF::ASpaceElement::align(), assert, TPEF::Section::element(), TPEF::Section::elementCount(), TPEF::ASpaceElement::MAU(), TPEF::ReferenceManager::SectionKey::sectionId(), TPEF::ReferenceManager::SafePointer::sectionKeyFor(), TPEF::SectionSizeReplacer::setSize(), TPEF::ASpaceElement::wordSize(), writeElement(), and TPEF::BinaryStream::writePosition().

Here is the call graph for this function:

◆ elementSize()

Word TPEF::TPEFASpaceSectionWriter::elementSize ( const Section section) const
protectedvirtual

Returns the fixed size length of section elements.

Returns
The fixed size length of section elements.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 168 of file TPEFASpaceSectionWriter.cc.

168  {
169  return elementSize_;
170 }

References elementSize_.

◆ operator=()

TPEFASpaceSectionWriter TPEF::TPEFASpaceSectionWriter::operator= ( const TPEFASpaceSectionWriter )
private

Assignment not allowed.

◆ type()

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

Returns the section type this writer can write.

Returns
The section type writer can write.

Implements TPEF::TPEFSectionWriter.

Definition at line 79 of file TPEFASpaceSectionWriter.cc.

79  {
80  return Section::ST_ADDRSP;
81 }

References TPEF::Section::ST_ADDRSP.

◆ writeElement()

void TPEF::TPEFASpaceSectionWriter::writeElement ( BinaryStream stream,
const ASpaceElement elem,
SectionId  id,
Word  index 
) const
private

Writes address space element to stream.

Parameters
streamStream where to write.
elemElement to write.
idSection identification code of address space section.
indexIdentification code of address space element.

Definition at line 143 of file TPEFASpaceSectionWriter.cc.

147  {
148 
149  // add index of element for index replacer
151  SectionIndexKey(id, index), elem);
152 
153  stream.writeByte(index);
154  stream.writeByte(elem->MAU());
155  stream.writeByte(elem->align());
156  stream.writeByte(elem->wordSize());
157 
158  SectionOffsetReplacer replacer(elem->name());
159  replacer.resolve();
160 }

References TPEF::ReferenceManager::SafePointer::addObjectReference(), TPEF::ASpaceElement::align(), TPEF::ASpaceElement::MAU(), TPEF::ASpaceElement::name(), TPEF::ValueReplacer::resolve(), TPEF::ASpaceElement::wordSize(), and TPEF::BinaryStream::writeByte().

Referenced by actualWriteData().

Here is the call graph for this function:

Member Data Documentation

◆ elementSize_

const Word TPEF::TPEFASpaceSectionWriter::elementSize_ = 8
staticprivate

The fixed size address space element.

Definition at line 75 of file TPEFASpaceSectionWriter.hh.

Referenced by elementSize().

◆ instance_

const TPEFASpaceSectionWriter TPEF::TPEFASpaceSectionWriter::instance_
staticprivate

An unique instance of class.

Definition at line 73 of file TPEFASpaceSectionWriter.hh.


The documentation for this class was generated from the following files:
TPEF::SectionId
HalfWord SectionId
Type for storing binary file section ids.
Definition: TPEFBaseType.hh:43
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::ReferenceManager::SafePointer::addObjectReference
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
Definition: SafePointer.cc:306
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::TPEFASpaceSectionWriter::writeElement
void writeElement(BinaryStream &stream, const ASpaceElement *elem, SectionId id, Word index) const
Definition: TPEFASpaceSectionWriter.cc:143
TPEF::SectionWriter::registerSectionWriter
static void registerSectionWriter(const SectionWriter *sWriter)
Definition: SectionWriter.cc:148
TPEF::TPEFASpaceSectionWriter::elementSize_
static const Word elementSize_
The fixed size address space element.
Definition: TPEFASpaceSectionWriter.hh:75
TPEF::ReferenceManager::SafePointer::sectionKeyFor
static SectionKey sectionKeyFor(const SafePointable *obj)
Definition: SafePointer.cc:408
TPEF::FileOffset
Word FileOffset
Type for storing absolute file offsets.
Definition: TPEFBaseType.hh:52
TPEF::SectionSizeReplacer::setSize
static void setSize(const SafePointable *obj, Word size)
Definition: SectionSizeReplacer.cc:100
TPEF::Section::ST_ADDRSP
@ ST_ADDRSP
Address space section.
Definition: Section.hh:77
TPEF::TPEFSectionWriter::TPEFSectionWriter
TPEFSectionWriter()
Definition: TPEFSectionWriter.cc:63