OpenASIP 2.2
Loading...
Searching...
No Matches
Protected Member Functions | Private Member Functions | List of all members
TPEF::TPEFSectionWriter Class Referenceabstract

#include <TPEFSectionWriter.hh>

Inheritance diagram for TPEF::TPEFSectionWriter:
Inheritance graph
Collaboration diagram for TPEF::TPEFSectionWriter:
Collaboration graph

Protected Member Functions

 TPEFSectionWriter ()
 
virtual ~TPEFSectionWriter ()
 
virtual const BinaryWriterparent () const
 
virtual void actualWriteHeader (BinaryStream &stream, const Section *sect) const
 
virtual void actualWriteData (BinaryStream &stream, const Section *sect) const
 
virtual Section::SectionType type () const =0
 Returns SectionTypet hat actual reader or writer instance can handle.
 
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
 
virtual Word elementSize (const Section *section) const
 
- Protected Member Functions inherited from TPEF::SectionWriter
 SectionWriter ()
 
virtual ~SectionWriter ()
 
virtual void finalize (BinaryStream &stream, Section *section) const
 

Private Member Functions

 TPEFSectionWriter (const TPEFSectionWriter &)
 
void writeBodyStartOffset (BinaryStream &stream, const Section *sect) const
 

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

Base class for all TPEF filetype writer classes.

Definition at line 49 of file TPEFSectionWriter.hh.

Constructor & Destructor Documentation

◆ TPEFSectionWriter() [1/2]

TPEF::TPEFSectionWriter::TPEFSectionWriter ( )
protected

Constructor.

Definition at line 63 of file TPEFSectionWriter.cc.

◆ ~TPEFSectionWriter()

TPEF::TPEFSectionWriter::~TPEFSectionWriter ( )
protectedvirtual

Destructor.

Definition at line 69 of file TPEFSectionWriter.cc.

69 {
70}

◆ TPEFSectionWriter() [2/2]

TPEF::TPEFSectionWriter::TPEFSectionWriter ( const TPEFSectionWriter )
private

Member Function Documentation

◆ actualWriteData()

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

Empty default implementation of method.

This is used if Section does not contain any data part.

Parameters
streamWhere to write.
sectData to write.

Implements TPEF::SectionWriter.

Reimplemented in TPEF::TPEFCodeSectionWriter, TPEF::TPEFDataSectionWriter, TPEF::TPEFStringSectionWriter, TPEF::TPEFASpaceSectionWriter, TPEF::TPEFDebugSectionWriter, TPEF::TPEFLineNumSectionWriter, TPEF::TPEFRelocSectionWriter, TPEF::TPEFResourceSectionWriter, and TPEF::TPEFSymbolSectionWriter.

Definition at line 193 of file TPEFSectionWriter.cc.

194 {
195}

◆ actualWriteHeader()

void TPEF::TPEFSectionWriter::actualWriteHeader ( BinaryStream stream,
const Section sect 
) const
protectedvirtual

Writes section's header into stream.

Parameters
streamStream where to write.
sectSection to be written.

Implements TPEF::SectionWriter.

Definition at line 89 of file TPEFSectionWriter.cc.

91 {
92
93 // inform reference manager about the section
94 SectionOffset sectionOffset = stream.writePosition();
95
96 // getSectionId must be overridden for special section identifiers
97 // like NullSection's
99
100 // create reference keys for section class
101 SafePointer::addObjectReference(SectionKey(id), sect);
102 SafePointer::addObjectReference(FileOffsetKey(sectionOffset), sect);
103
104 // start writing header fields
105 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_NAME);
106 Chunk* name = sect->name();
107
108 if (name != NULL) {
109 SectionOffsetReplacer nameReplacer(name);
110 nameReplacer.resolve();
111 } else {
112 stream.writeWord(0);
113 }
114
115 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_TYPE);
116 stream.writeByte(sect->type());
117
118 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_FLAGS);
119 stream.writeByte(sect->flags());
120
121 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_ADDR);
122
123 if (sect->isProgramSection()) {
124 stream.writeWord(sect->startingAddress());
125 } else {
126 stream.writeWord(0);
127 }
128
129 // offset of the section data
130 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_OFFSET);
131 writeBodyStartOffset(stream, sect);
132
133 // size of the section
134 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_SIZE);
135 writeSize(stream, sect);
136
137 // section identification code
138 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_ID);
139 stream.writeHalfWord(id);
140
141
142 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_ASPACE);
143 if (sect->aSpace() != NULL) {
144 // section address space identifier
145 SectionIndexReplacer indexReplacer(sect->aSpace(), sizeof(Byte));
146 indexReplacer.resolve();
147 } else {
148 bool addressSpaceCantBeNull = false;
149 assert(addressSpaceCantBeNull);
150 }
151
152 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_PADDING);
153 stream.writeByte(0);
154
155 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_LINK);
156 Section* linkSect = sect->link();
157
158 if (linkSect != NULL) {
159 SectionIdReplacer linkReplacer(linkSect);
160 linkReplacer.resolve();
161 } else {
162 stream.writeHalfWord(0);
163 }
164
165 // by deafult info field is not used.
166 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_INFO);
167 writeInfo(stream, sect);
168
169 // section elements size is asked from actual section writer
170 stream.setWritePosition(sectionOffset + TPEFHeaders::SH_ENTSIZE);
171
172 // check that if element size is zero then vLen flag is set or
173 // section is null section
174 assert((elementSize(sect) == 0) ==
175 (sect->vLen() || (sect->type() == Section::ST_NULL)));
176 stream.writeWord(elementSize(sect));
177
178 // create keys for section elements if nobits flag is set.
179 if (sect->noBits()) {
180 createKeys(sect);
181 }
182}
#define assert(condition)
unsigned char Byte
Definition BaseType.hh:116
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
@ ST_NULL
NULL Section.
Definition Section.hh:70
virtual Word elementSize(const Section *section) const
virtual void writeInfo(BinaryStream &stream, const Section *sect) const
virtual void createKeys(const Section *sect) const
virtual void writeSize(BinaryStream &stream, const Section *sect) const
void writeBodyStartOffset(BinaryStream &stream, const Section *sect) const
virtual SectionId getSectionId() const
@ SH_LINK
Section identifier link.
@ SH_FLAGS
Flags of section.
@ SH_ASPACE
Section address space identifier.
@ SH_OFFSET
Offset to section data.
@ SH_ID
Section identification code.
@ SH_INFO
Section specific information, usually zero.
@ SH_ADDR
Starting memory address of program section.
@ SH_SIZE
Size of section data.
@ SH_NAME
Section offset to name.
@ SH_TYPE
Type of section.
@ SH_ENTSIZE
Size of section elements (if fixed size).
@ SH_PADDING
Padding, must be zero.
HalfWord SectionId
Type for storing binary file section ids.
Word SectionOffset
Type for storing offsets relative to a given base offset value.

References TPEF::ReferenceManager::SafePointer::addObjectReference(), TPEF::Section::aSpace(), assert, createKeys(), elementSize(), TPEF::Section::flags(), getSectionId(), TPEF::Section::isProgramSection(), TPEF::Section::link(), TPEF::Section::name(), TPEF::Section::noBits(), TPEF::ValueReplacer::resolve(), TPEF::BinaryStream::setWritePosition(), 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_PADDING, TPEF::TPEFHeaders::SH_SIZE, TPEF::TPEFHeaders::SH_TYPE, TPEF::Section::ST_NULL, TPEF::Section::startingAddress(), TPEF::Section::type(), TPEF::Section::vLen(), writeBodyStartOffset(), TPEF::BinaryStream::writeByte(), TPEF::BinaryStream::writeHalfWord(), writeInfo(), TPEF::BinaryStream::writePosition(), writeSize(), and TPEF::BinaryStream::writeWord().

Here is the call graph for this function:

◆ createKeys()

void TPEF::TPEFSectionWriter::createKeys ( const Section sect) const
protectedvirtual

Fall through method for creating reference keys.

This method is used for those sections, whose elements can be referred, but there is no section body stored in TPEF binary (if section has no bits flag set, then this method is invoked instead writeData).

Empty implementation for sections that don't need keys created if section do not have body.

Parameters
sectSection which for keys will be created.

Reimplemented in TPEF::TPEFDebugSectionWriter, TPEF::TPEFSymbolSectionWriter, and TPEF::TPEFUDataSectionWriter.

Definition at line 286 of file TPEFSectionWriter.cc.

286 {
287}

Referenced by actualWriteHeader().

◆ elementSize()

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

◆ getSectionId()

SectionId TPEF::TPEFSectionWriter::getSectionId ( ) const
protectedvirtual

Get section identification code for the section.

Returns
Valid section identification code.

Reimplemented in TPEF::TPEFNullSectionWriter.

Definition at line 268 of file TPEFSectionWriter.cc.

268 {
270}
static SectionId getUniqueSectionId()

References TPEF::SectionWriter::getUniqueSectionId().

Referenced by actualWriteHeader().

Here is the call graph for this function:

◆ parent()

const BinaryWriter & TPEF::TPEFSectionWriter::parent ( ) const
protectedvirtual

Returns binary writer which for section writers are created.

Returns
Binary writer which for section writers are created.

Implements TPEF::SectionWriter.

Definition at line 78 of file TPEFSectionWriter.cc.

78 {
79 return TPEFWriter::instance();
80}
static const BinaryWriter & instance()
Definition TPEFWriter.cc:70

References TPEF::TPEFWriter::instance().

Here is the call graph for this function:

◆ type()

virtual Section::SectionType TPEF::TPEFSectionWriter::type ( ) const
protectedpure virtual

◆ writeBodyStartOffset()

void TPEF::TPEFSectionWriter::writeBodyStartOffset ( BinaryStream stream,
const Section sect 
) const
private

Writes Section's data area offset into stream.

Parameters
streamStream where to write.
sectSection which data's offset to write.

Definition at line 245 of file TPEFSectionWriter.cc.

246 {
247
248 if (sect->noBits()) {
249 stream.writeWord(0);
250
251 } else {
252 if (sect->isChunkable()) {
253 FileOffsetReplacer replacer(sect->chunk(0));
254 replacer.resolve();
255 } else {
256 FileOffsetReplacer replacer(sect->element(0));
257 replacer.resolve();
258 }
259 }
260}

References TPEF::Section::chunk(), TPEF::Section::element(), TPEF::Section::isChunkable(), TPEF::Section::noBits(), TPEF::ValueReplacer::resolve(), and TPEF::BinaryStream::writeWord().

Referenced by actualWriteHeader().

Here is the call graph for this function:

◆ writeInfo()

void TPEF::TPEFSectionWriter::writeInfo ( BinaryStream stream,
const Section sect 
) const
protectedvirtual

Writes section info field into stream.

Default implementation writes, there zero word.

Parameters
streamStream where to write.
sectSection which info field to write.

Reimplemented in TPEF::TPEFCodeSectionWriter, TPEF::TPEFLineNumSectionWriter, and TPEF::TPEFRelocSectionWriter.

Definition at line 233 of file TPEFSectionWriter.cc.

234 {
235 stream.writeWord(0);
236}

References TPEF::BinaryStream::writeWord().

Referenced by actualWriteHeader().

Here is the call graph for this function:

◆ writeSize()

void TPEF::TPEFSectionWriter::writeSize ( BinaryStream stream,
const Section sect 
) const
protectedvirtual

Writes section size field in to stream.

Default implementation, which uses replacer class to write size.

Parameters
streamStream, where to write.
sectSection which size to write.

Reimplemented in TPEF::TPEFNullSectionWriter, and TPEF::TPEFUDataSectionWriter.

Definition at line 218 of file TPEFSectionWriter.cc.

219 {
220 SectionSizeReplacer replacer(sect);
221 replacer.resolve();
222}

References TPEF::ValueReplacer::resolve().

Referenced by actualWriteHeader().

Here is the call graph for this function:

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