OpenASIP 2.2
Loading...
Searching...
No Matches
Protected Member Functions | Private Member Functions | Static Private Attributes | List of all members
TPEF::TPEFSymbolSectionWriter Class Reference

#include <TPEFSymbolSectionWriter.hh>

Inheritance diagram for TPEF::TPEFSymbolSectionWriter:
Inheritance graph
Collaboration diagram for TPEF::TPEFSymbolSectionWriter:
Collaboration graph

Protected Member Functions

 TPEFSymbolSectionWriter ()
 
virtual ~TPEFSymbolSectionWriter ()
 
virtual Section::SectionType type () const
 
virtual void createKeys (const Section *sect) 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 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

 TPEFSymbolSectionWriter (const TPEFSymbolSectionWriter &)
 Copying not allowed.
 
TPEFSymbolSectionWriter operator= (const TPEFSymbolSectionWriter &)
 Assignment not allowed.
 
void writeValueAndSize (BinaryStream &stream, const SymbolElement *elem) const
 

Static Private Attributes

static const TPEFSymbolSectionWriter instance_
 An unique instance of class.
 
static const Word elementSize_ = 16
 The fixed size address space element.
 

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 symbol table to stream.

Definition at line 47 of file TPEFSymbolSectionWriter.hh.

Constructor & Destructor Documentation

◆ TPEFSymbolSectionWriter() [1/2]

TPEF::TPEFSymbolSectionWriter::TPEFSymbolSectionWriter ( )
protected

Constructor.

Registers itself to SectionWriter.

Definition at line 67 of file TPEFSymbolSectionWriter.cc.

69}
static void registerSectionWriter(const SectionWriter *sWriter)

References TPEF::SectionWriter::registerSectionWriter().

Here is the call graph for this function:

◆ ~TPEFSymbolSectionWriter()

TPEF::TPEFSymbolSectionWriter::~TPEFSymbolSectionWriter ( )
protectedvirtual

Destructor.

Definition at line 74 of file TPEFSymbolSectionWriter.cc.

74 {
75}

◆ TPEFSymbolSectionWriter() [2/2]

TPEF::TPEFSymbolSectionWriter::TPEFSymbolSectionWriter ( const TPEFSymbolSectionWriter )
private

Copying not allowed.

Member Function Documentation

◆ actualWriteData()

void TPEF::TPEFSymbolSectionWriter::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 94 of file TPEFSymbolSectionWriter.cc.

96 {
97
98 FileOffset startOffset = stream.writePosition();
99
100 // file offset to data of section
102 FileOffsetKey(startOffset), sect->element(0));
103
104 // resolve identification code of currently written section
105 SectionKey sectionKey = SafePointer::sectionKeyFor(sect);
106 SectionId sectionId = sectionKey.sectionId();
107
108 // first element should match with undefined symbol
109 SymbolElement *undef = dynamic_cast<SymbolElement*>(sect->element(0));
110 assert(undef != NULL);
111 assert(undef->type() == SymbolElement::STT_NOTYPE);
112 assert(undef->absolute() == true);
113 assert(undef->binding() == SymbolElement::STB_LOCAL);
114 assert(undef->name()->offset() == 0);
115
116 // symbols might have to be organized in a way local symbols are
117 // before weak symbols and global syms will come after everything else
118 for (Word i = 0; i < sect->elementCount(); i++) {
119
120 SymbolElement* elem = dynamic_cast<SymbolElement*>(sect->element(i));
121 assert(elem != NULL);
122
123 // each element must be registered with its index
125 SectionIndexKey(sectionId, i), elem);
126
127 // write name
128 assert(elem->name() != NULL);
129 SectionOffsetReplacer sOffReplacer(elem->name());
130 sOffReplacer.resolve();
131
132 writeValueAndSize(stream, elem);
133
134 // write info
135 stream.writeByte(
136 (elem->binding() << (BYTE_BITWIDTH / 2)) |
137 static_cast<Byte>(elem->type()));
138
139 // other field, right now only STO_ABS is used
140 Byte otherField = 0;
141 if (elem->absolute()) {
142 otherField = otherField | TPEFHeaders::STO_ABS;
143 }
144 stream.writeByte(otherField);
145
146 // section to which the symbol belongs
147 // NOTE: Maybe nullSection should be used for these,
148 // so NULL would be error.
149
150 if (elem->section() != NULL) {
151 SectionIdReplacer sectIdReplacer(elem->section());
152 sectIdReplacer.resolve();
153 } else {
154 stream.writeHalfWord(0);
155 }
156 }
157 SectionSizeReplacer::setSize(sect, stream.writePosition() - startOffset);
158}
#define assert(condition)
const Byte BYTE_BITWIDTH
Definition BaseType.hh:136
unsigned char Byte
Definition BaseType.hh:116
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
static SectionKey sectionKeyFor(const SafePointable *obj)
static void setSize(const SafePointable *obj, Word size)
@ STT_NOTYPE
Type is not defined.
@ STB_LOCAL
Not visible outside the object file that contains it's definition.
void writeValueAndSize(BinaryStream &stream, const SymbolElement *elem) const
@ STO_ABS
Section is absolute, not relocating.
HalfWord SectionId
Type for storing binary file section ids.
Word FileOffset
Type for storing absolute file offsets.

References TPEF::SymbolElement::absolute(), TPEF::ReferenceManager::SafePointer::addObjectReference(), assert, TPEF::SymbolElement::binding(), BYTE_BITWIDTH, TPEF::Section::element(), TPEF::Section::elementCount(), TPEF::SymbolElement::name(), TPEF::Chunk::offset(), TPEF::ValueReplacer::resolve(), TPEF::SymbolElement::section(), TPEF::ReferenceManager::SectionKey::sectionId(), TPEF::ReferenceManager::SafePointer::sectionKeyFor(), TPEF::SectionSizeReplacer::setSize(), TPEF::SymbolElement::STB_LOCAL, TPEF::TPEFHeaders::STO_ABS, TPEF::SymbolElement::STT_NOTYPE, TPEF::SymbolElement::type(), TPEF::BinaryStream::writeByte(), TPEF::BinaryStream::writeHalfWord(), TPEF::BinaryStream::writePosition(), and writeValueAndSize().

Here is the call graph for this function:

◆ createKeys()

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

Creates needed keys for section if noBits flag is set.

Parameters
sectSection which for keys will be created.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 264 of file TPEFSymbolSectionWriter.cc.

264 {
266}

References TPEF::SectionSizeReplacer::setSize().

Here is the call graph for this function:

◆ elementSize()

Word TPEF::TPEFSymbolSectionWriter::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 254 of file TPEFSymbolSectionWriter.cc.

254 {
255 return elementSize_;
256}
static const Word elementSize_
The fixed size address space element.

References elementSize_.

◆ operator=()

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

Assignment not allowed.

◆ type()

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

Returns the section type this writer can write.

Returns
The section type writer can write.

Implements TPEF::TPEFSectionWriter.

Definition at line 83 of file TPEFSymbolSectionWriter.cc.

83 {
84 return Section::ST_SYMTAB;
85}
@ ST_SYMTAB
Symbol table.
Definition Section.hh:72

References TPEF::Section::ST_SYMTAB.

◆ writeValueAndSize()

void TPEF::TPEFSymbolSectionWriter::writeValueAndSize ( BinaryStream stream,
const SymbolElement elem 
) const
private

Writes value and size fields of symbol.

Parameters
streamStream where to write.
elemElement to write.

Definition at line 167 of file TPEFSymbolSectionWriter.cc.

169 {
170
171 switch (elem->type()) {
173 // write value
174 // write size
175 stream.writeWord(0);
176 stream.writeWord(0);
177 break;
178 }
179
182 const CodeSymElement* codeSym =
183 dynamic_cast<const CodeSymElement*>(elem);
184 assert(codeSym != NULL);
185
186 // write value
187 if (codeSym->reference() != NULL) {
188 SectionOffsetReplacer replacer(codeSym->reference());
189 replacer.resolve();
190 } else {
191 stream.writeWord(0);
192 }
193
194 // write size
195 stream.writeWord(codeSym->size());
196 break;
197 }
198
200 const DataSymElement* dataSym =
201 dynamic_cast<const DataSymElement*>(elem);
202 assert(dataSym != NULL);
203
204 // write value
205 if (dataSym->reference() != NULL) {
206 SectionOffsetReplacer replacer(dataSym->reference());
207 replacer.resolve();
208 } else {
209 stream.writeWord(0);
210 }
211
212 // write size
213 stream.writeWord(dataSym->size());
214 break;
215 }
216
218 const SectionSymElement* sectSym =
219 dynamic_cast<const SectionSymElement*>(elem);
220 assert(sectSym != NULL);
221
222 // write value
223 stream.writeWord(sectSym->value());
224 // write size
225 stream.writeWord(sectSym->size());
226 break;
227 }
228
230 const FileSymElement* fileSym =
231 dynamic_cast<const FileSymElement*>(elem);
232 assert(fileSym != NULL);
233
234 // write value
235 stream.writeWord(fileSym->value());
236 // write size
237 stream.writeWord(0);
238 break;
239 }
240
241 default: {
242 bool unknownSymbolType = false;
243 assert(unknownSymbolType);
244 }
245 }
246}
@ STT_PROCEDURE
Symbol gives indicates procedure start position in section.
@ STT_FILE
Name of symbol gives the name of source file associated with this object file.
@ STT_CODE
Associated with executable code.
@ STT_SECTION
Associated with section.
@ STT_DATA
Associated with data object.

References assert, TPEF::CodeSymElement::reference(), TPEF::DataSymElement::reference(), TPEF::ValueReplacer::resolve(), TPEF::CodeSymElement::size(), TPEF::DataSymElement::size(), TPEF::SectionSymElement::size(), TPEF::SymbolElement::STT_CODE, TPEF::SymbolElement::STT_DATA, TPEF::SymbolElement::STT_FILE, TPEF::SymbolElement::STT_NOTYPE, TPEF::SymbolElement::STT_PROCEDURE, TPEF::SymbolElement::STT_SECTION, TPEF::SymbolElement::type(), TPEF::FileSymElement::value(), TPEF::SectionSymElement::value(), and TPEF::BinaryStream::writeWord().

Referenced by actualWriteData().

Here is the call graph for this function:

Member Data Documentation

◆ elementSize_

const Word TPEF::TPEFSymbolSectionWriter::elementSize_ = 16
staticprivate

The fixed size address space element.

Definition at line 75 of file TPEFSymbolSectionWriter.hh.

Referenced by elementSize().

◆ instance_

const TPEFSymbolSectionWriter TPEF::TPEFSymbolSectionWriter::instance_
staticprivate

An unique instance of class.

Definition at line 73 of file TPEFSymbolSectionWriter.hh.


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