OpenASIP  2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TPEF::Section Class Referenceabstract

#include <Section.hh>

Inheritance diagram for TPEF::Section:
Inheritance graph
Collaboration diagram for TPEF::Section:
Collaboration graph

Public Types

enum  SectionType {
  ST_NULL = 0x00, ST_STRTAB = 0x01, ST_SYMTAB = 0x02, ST_DEBUG = 0x03,
  ST_RELOC = 0x04, ST_LINENO = 0x05, ST_NOTE = 0x06, ST_ADDRSP = 0x07,
  ST_MR = 0x0A, ST_CODE = 0x81, ST_DATA = 0x82, ST_UDATA = 0x83,
  ST_LEDATA = 0x84, ST_DUMMY = 0xff
}
 
enum  SectionFlag { SF_VLEN = 0x40, SF_NOBITS = 0x80 }
 

Public Member Functions

virtual SectionType type () const =0
 Returns SectioType of actual section instance. More...
 
virtual ~Section ()
 
virtual bool isChunkable () const
 
virtual Chunkchunk (SectionOffset offset) const
 
bool isProgramSection () const
 
bool isAuxSection () const
 
virtual void addElement (SectionElement *element)
 
virtual void setElement (Word index, SectionElement *element)
 
SectionElementelement (Word index) const
 
Word elementCount () const
 
void setFlagNoBits ()
 
void unsetFlagNoBits ()
 
bool noBits () const
 
bool vLen () const
 
Byte flags () const
 
void setFlags (Byte flagByte)
 
void setStartingAddress (AddressImage address)
 
AddressImage startingAddress () const
 
void setLink (const ReferenceManager::SafePointer *aLink)
 
void setLink (Section *aLink)
 
Sectionlink () const
 
void setASpace (const ReferenceManager::SafePointer *addrSpace)
 
void setASpace (ASpaceElement *addrSpace)
 
ASpaceElementaSpace () const
 
void setName (const ReferenceManager::SafePointer *sectionName)
 
void setName (Chunk *sectionName)
 
Chunkname () const
 
virtual bool isDataSection () const
 
virtual bool isCodeSection () const
 
- Public Member Functions inherited from TPEF::SafePointable
virtual ~SafePointable ()
 

Static Public Member Functions

static SectioncreateSection (SectionType type)
 
static bool isProgramSection (SectionType type)
 

Protected Member Functions

virtual Sectionclone () const =0
 Creates clone of instance. More...
 
 Section ()
 
void setFlagVLen ()
 
void unsetFlagVLen ()
 
- Protected Member Functions inherited from TPEF::SafePointable
 SafePointable ()
 

Static Protected Member Functions

static void registerSection (const Section *section)
 

Private Types

typedef std::map< SectionType, const Section * > SectionPrototypeMap
 Type of map that contains section prototypes. More...
 

Private Member Functions

 Section (const Section &)
 
bool flag (SectionFlag aFlag) const
 
void setFlag (SectionFlag aFlag)
 
void unsetFlag (SectionFlag aFlag)
 

Private Attributes

std::vector< SectionElement * > elements_
 Contain elements. More...
 
const ReferenceManager::SafePointerlink_
 TPEF link field. More...
 
const ReferenceManager::SafePointeraSpace_
 TPEF address space field. More...
 
const ReferenceManager::SafePointername_
 TPEF name field. More...
 
Byte flags_
 TPEF flag byte. More...
 
Word startingAddress_
 TPEF startin memory address field. More...
 

Static Private Attributes

static SectionPrototypeMapprototypes_ = NULL
 Container for registere section prototypes. More...
 
static const Byte PROGRAM_SECTION_MASK = 0x80
 Mask for checking if section is auxiliary or program section. More...
 

Detailed Description

Abstract base class for concrete sections.

Stores section header data and handles registration requests and book keeping for concrete sections. See prototype design pattern.

Definition at line 64 of file Section.hh.

Member Typedef Documentation

◆ SectionPrototypeMap

typedef std::map<SectionType, const Section*> TPEF::Section::SectionPrototypeMap
private

Type of map that contains section prototypes.

Definition at line 165 of file Section.hh.

Member Enumeration Documentation

◆ SectionFlag

TPEF section flags.

Enumerator
SF_VLEN 

Contains elements with variable length.

SF_NOBITS 

Not initialized or not stored in this file.

Definition at line 89 of file Section.hh.

89  {
90  SF_VLEN = 0x40, ///< Contains elements with variable length.
91  SF_NOBITS = 0x80 ///< Not initialized or not stored in this file.
92  };

◆ SectionType

TPEF section type ids.

Enumerator
ST_NULL 

NULL Section.

ST_STRTAB 

String table.

ST_SYMTAB 

Symbol table.

ST_DEBUG 

Debug section.

ST_RELOC 

Relocation section.

ST_LINENO 

Line number section.

ST_NOTE 

Note section.

ST_ADDRSP 

Address space section.

ST_MR 

Machine resources section.

ST_CODE 

Text section.

ST_DATA 

Initialized data section.

ST_UDATA 

Uninitialized data section.

ST_LEDATA 

Initialized little endian data section.

ST_DUMMY 

Dummy section type for testing purposes.

Definition at line 69 of file Section.hh.

69  {
70  ST_NULL = 0x00, ///< NULL Section
71  ST_STRTAB = 0x01, ///< String table.
72  ST_SYMTAB = 0x02, ///< Symbol table.
73  ST_DEBUG = 0x03, ///< Debug section.
74  ST_RELOC = 0x04, ///< Relocation section.
75  ST_LINENO = 0x05, ///< Line number section.
76  ST_NOTE = 0x06, ///< Note section.
77  ST_ADDRSP = 0x07, ///< Address space section.
78  ST_MR = 0x0A, ///< Machine resources section.
79  ST_CODE = 0x81, ///< Text section.
80  ST_DATA = 0x82, ///< Initialized data section.
81  ST_UDATA = 0x83, ///< Uninitialized data section.
82  ST_LEDATA = 0x84, ///< Initialized little endian data section.
83  ST_DUMMY = 0xff ///< Dummy section type for testing purposes.
84  };

Constructor & Destructor Documentation

◆ ~Section()

TPEF::Section::~Section ( )
virtual

Destructor.

Definition at line 76 of file Section.cc.

76  {
77  while (elements_.size() != 0) {
78  delete elements_[elements_.size() - 1];
79  elements_.pop_back();
80  }
81 }

References elements_.

◆ Section() [1/2]

TPEF::Section::Section ( )
protected

Constructor.

Definition at line 64 of file Section.cc.

64  :
65  SafePointable(),
69  flags_(0),
70  startingAddress_(0) {
71 }

◆ Section() [2/2]

TPEF::Section::Section ( const Section )
private

Member Function Documentation

◆ addElement()

void TPEF::Section::addElement ( SectionElement element)
virtual

Adds an element to section.

Parameters
elementElement that is added to section.

Reimplemented in TPEF::CodeSection.

Definition at line 133 of file Section.cc.

133  {
134  assert(element != NULL);
135  elements_.push_back(element);
136 }

References assert, element(), and elements_.

Referenced by TPEF::CodeSection::addElement(), MachineResourceManager::addResourceElement(), TTAProgram::TPEFResourceUpdater::bus(), MachineResourceManager::codeAddressSpace(), TTAProgram::ProgramWriter::createASpaceElement(), TTAProgram::ProgramWriter::createBinary(), TTAProgram::ProgramWriter::createRelocSections(), TPEF::AOutSymbolSectionReader::finalize(), LabelManager::finalize(), MachineResourceManager::findDataAddressSpace(), TTAProgram::TPEFResourceUpdater::functionUnit(), TTAProgram::TPEFResourceUpdater::functionUnitPort(), TTAProgram::TPEFResourceUpdater::immediateUnit(), TPEF::AOutSymbolSectionReader::initializeSymbol(), MachineResourceManager::initResourceSection(), TTAProgram::TPEFResourceUpdater::operand(), TPEF::TPEFDebugSectionReader::readData(), TPEF::TPEFASpaceSectionReader::readData(), TPEF::TPEFSymbolSectionReader::readData(), TPEF::TPEFLineNumSectionReader::readData(), TPEF::TPEFResourceSectionReader::readData(), TPEF::TPEFRelocSectionReader::readData(), TPEF::AOutTextSectionReader::readData(), TPEF::AOutRelocationSectionReader::readData(), TPEF::AOutSymbolSectionReader::readData(), TPEF::AOutReader::readData(), TTAProgram::TPEFResourceUpdater::registerFile(), MachineResourceManager::undefinedAddressSpace(), and LabelManager::writeProcedureSymbols().

Here is the call graph for this function:

◆ aSpace()

ASpaceElement* TPEF::Section::aSpace ( ) const

◆ chunk()

Chunk * TPEF::Section::chunk ( SectionOffset  offset) const
virtual

Returns a chunk that has offset to a data of section.

Parameters
offsetOffset to a data that is wanted to be referenced.
Returns
Chunk for raw data section.
Exceptions
NotChunkableIf Section is not derived from RawSection.

Reimplemented in TPEF::RawSection.

Definition at line 169 of file Section.cc.

169  {
170  throw NotChunkable(__FILE__, __LINE__, "Section::chunk");
171 }

Referenced by TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::ReferenceManager::SafePointer::resolve(), and TPEF::TPEFSectionWriter::writeBodyStartOffset().

◆ clone()

virtual Section* TPEF::Section::clone ( ) const
protectedpure virtual

◆ createSection()

Section * TPEF::Section::createSection ( SectionType  type)
static

Creates instance of concrete section type.

Parameters
typeType of section instance that is to be created.
Returns
Pointer to newly created section.
Exceptions
InstanceNotFoundIf there is no registered instance for type.

Definition at line 91 of file Section.cc.

91  {
92  if (prototypes_ == NULL ||
94 
95  throw InstanceNotFound(
96  __FILE__, __LINE__, __func__,
97  TCEString("No prototype for section type: ") +
98  Conversion::toString(static_cast<int>(type)));
99  }
100 
101  Section* section = (*prototypes_)[type]->clone();
102  return section;
103 }

References __func__, clone(), MapTools::containsKey(), prototypes_, Conversion::toString(), and type().

Referenced by TPEF::TPEFReader::readData(), and TPEF::AOutReader::readData().

Here is the call graph for this function:

◆ element()

SectionElement* TPEF::Section::element ( Word  index) const

◆ elementCount()

Word TPEF::Section::elementCount ( ) const

◆ flag()

bool TPEF::Section::flag ( SectionFlag  aFlag) const
private

◆ flags()

Byte TPEF::Section::flags ( ) const

◆ isAuxSection()

bool TPEF::Section::isAuxSection ( ) const

◆ isChunkable()

bool TPEF::Section::isChunkable ( ) const
virtual

Returns true if section is chunkable.

Returns
True if section is chunkable.

Reimplemented in TPEF::RawSection.

Definition at line 157 of file Section.cc.

157  {
158  return false;
159 }

Referenced by TPEFDumper::sectionHeader(), TPEF::TPEFTools::sectionOfElement(), and TPEF::TPEFSectionWriter::writeBodyStartOffset().

◆ isCodeSection()

virtual bool TPEF::Section::isCodeSection ( ) const
inlinevirtual

◆ isDataSection()

virtual bool TPEF::Section::isDataSection ( ) const
inlinevirtual

Reimplemented in TPEF::DataSection.

Definition at line 142 of file Section.hh.

142 { return false; }

Referenced by TTAProgram::ProgramWriter::createDataSections().

◆ isProgramSection() [1/2]

bool TPEF::Section::isProgramSection ( ) const

◆ isProgramSection() [2/2]

static bool TPEF::Section::isProgramSection ( SectionType  type)
static

◆ link()

Section* TPEF::Section::link ( ) const

◆ name()

Chunk* TPEF::Section::name ( ) const

◆ noBits()

bool TPEF::Section::noBits ( ) const

◆ registerSection()

void TPEF::Section::registerSection ( const Section section)
staticprotected

Registers section instance that implements some section type.

Every registered prototype implements one of used sections. These registered sections are used to clone section instances by SectionType.

Parameters
sectionSection instance that will be registered.

Definition at line 114 of file Section.cc.

114  {
115 
116  // We can't create prototypes_ map statically, because we don't know
117  //if it is initialized before this method is called.
118  if (prototypes_ == NULL) {
120  }
121 
122  assert(!MapTools::containsKey(*prototypes_, section->type()));
123 
124  (*prototypes_)[section->type()] = section;
125 }

References assert, MapTools::containsKey(), prototypes_, and type().

Referenced by TPEF::ASpaceSection::ASpaceSection(), TPEF::CodeSection::CodeSection(), TPEF::DataSection::DataSection(), TPEF::DebugSection::DebugSection(), TPEF::LEDataSection::LEDataSection(), TPEF::LineNumSection::LineNumSection(), TPEF::NullSection::NullSection(), TPEF::RelocSection::RelocSection(), TPEF::ResourceSection::ResourceSection(), TPEF::StringSection::StringSection(), TPEF::SymbolSection::SymbolSection(), and TPEF::UDataSection::UDataSection().

Here is the call graph for this function:

◆ setASpace() [1/2]

void TPEF::Section::setASpace ( ASpaceElement addrSpace)

◆ setASpace() [2/2]

void TPEF::Section::setASpace ( const ReferenceManager::SafePointer addrSpace)

◆ setElement()

void TPEF::Section::setElement ( Word  index,
SectionElement element 
)
virtual

Sets replaces an element in given index with another.

Parameters
indexIndex of element that is replaced.
elementElement that is set to given index.

Reimplemented in TPEF::CodeSection.

Definition at line 145 of file Section.cc.

145  {
146  assert(element != NULL);
147  assert(index < elementCount());
148  elements_[index] = element;
149 }

References assert, element(), elementCount(), and elements_.

Referenced by TPEF::AOutSymbolSectionReader::finalize(), and TPEF::CodeSection::setElement().

Here is the call graph for this function:

◆ setFlag()

void TPEF::Section::setFlag ( SectionFlag  aFlag)
private

◆ setFlagNoBits()

void TPEF::Section::setFlagNoBits ( )

◆ setFlags()

void TPEF::Section::setFlags ( Byte  flagByte)

◆ setFlagVLen()

void TPEF::Section::setFlagVLen ( )
protected

◆ setLink() [1/2]

void TPEF::Section::setLink ( const ReferenceManager::SafePointer aLink)

◆ setLink() [2/2]

void TPEF::Section::setLink ( Section aLink)

◆ setName() [1/2]

void TPEF::Section::setName ( Chunk sectionName)

◆ setName() [2/2]

void TPEF::Section::setName ( const ReferenceManager::SafePointer sectionName)

◆ setStartingAddress()

void TPEF::Section::setStartingAddress ( AddressImage  address)

◆ startingAddress()

AddressImage TPEF::Section::startingAddress ( ) const

◆ type()

virtual SectionType TPEF::Section::type ( ) const
pure virtual

◆ unsetFlag()

void TPEF::Section::unsetFlag ( SectionFlag  aFlag)
private

◆ unsetFlagNoBits()

void TPEF::Section::unsetFlagNoBits ( )

◆ unsetFlagVLen()

void TPEF::Section::unsetFlagVLen ( )
protected

◆ vLen()

bool TPEF::Section::vLen ( ) const

Member Data Documentation

◆ aSpace_

const ReferenceManager::SafePointer* TPEF::Section::aSpace_
private

TPEF address space field.

Definition at line 175 of file Section.hh.

◆ elements_

std::vector<SectionElement*> TPEF::Section::elements_
private

Contain elements.

Definition at line 170 of file Section.hh.

Referenced by addElement(), setElement(), and ~Section().

◆ flags_

Byte TPEF::Section::flags_
private

TPEF flag byte.

Definition at line 179 of file Section.hh.

◆ link_

const ReferenceManager::SafePointer* TPEF::Section::link_
private

TPEF link field.

Definition at line 173 of file Section.hh.

◆ name_

const ReferenceManager::SafePointer* TPEF::Section::name_
private

TPEF name field.

Definition at line 177 of file Section.hh.

◆ PROGRAM_SECTION_MASK

const Byte TPEF::Section::PROGRAM_SECTION_MASK = 0x80
staticprivate

Mask for checking if section is auxiliary or program section.

Definition at line 183 of file Section.hh.

◆ prototypes_

Section::SectionPrototypeMap * TPEF::Section::prototypes_ = NULL
staticprivate

Container for registere section prototypes.

Definition at line 168 of file Section.hh.

Referenced by createSection(), and registerSection().

◆ startingAddress_

Word TPEF::Section::startingAddress_
private

TPEF startin memory address field.

Definition at line 181 of file Section.hh.


The documentation for this class was generated from the following files:
TPEF::Section::flags_
Byte flags_
TPEF flag byte.
Definition: Section.hh:179
TPEF::Section::prototypes_
static SectionPrototypeMap * prototypes_
Container for registere section prototypes.
Definition: Section.hh:168
TPEF::Section::aSpace_
const ReferenceManager::SafePointer * aSpace_
TPEF address space field.
Definition: Section.hh:175
TPEF::Section::ST_SYMTAB
@ ST_SYMTAB
Symbol table.
Definition: Section.hh:72
TPEF::Section::ST_DUMMY
@ ST_DUMMY
Dummy section type for testing purposes.
Definition: Section.hh:83
TPEF::Section::link_
const ReferenceManager::SafePointer * link_
TPEF link field.
Definition: Section.hh:173
TPEF::Section::ST_DEBUG
@ ST_DEBUG
Debug section.
Definition: Section.hh:73
TPEF::Section::SectionPrototypeMap
std::map< SectionType, const Section * > SectionPrototypeMap
Type of map that contains section prototypes.
Definition: Section.hh:165
TPEF::Section::type
virtual SectionType type() const =0
Returns SectioType of actual section instance.
TPEF::Section::name_
const ReferenceManager::SafePointer * name_
TPEF name field.
Definition: Section.hh:177
TPEF::ReferenceManager::SafePointer::null
static const SafePointer null
The default SafePointer that is used in null references.
Definition: SafePointer.hh:229
TPEF::Section::startingAddress_
Word startingAddress_
TPEF startin memory address field.
Definition: Section.hh:181
Conversion::toString
static std::string toString(const T &source)
TPEF::Section::element
SectionElement * element(Word index) const
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::Section::Section
Section()
Definition: Section.cc:64
TPEF::Section::ST_DATA
@ ST_DATA
Initialized data section.
Definition: Section.hh:80
TPEF::Section::ST_LEDATA
@ ST_LEDATA
Initialized little endian data section.
Definition: Section.hh:82
__func__
#define __func__
Definition: Application.hh:67
TPEF::Section::elements_
std::vector< SectionElement * > elements_
Contain elements.
Definition: Section.hh:170
TPEF::SafePointable::SafePointable
SafePointable()
Definition: SafePointable.cc:55
TPEF::Section::ST_UDATA
@ ST_UDATA
Uninitialized data section.
Definition: Section.hh:81
TPEF::Section::ST_LINENO
@ ST_LINENO
Line number section.
Definition: Section.hh:75
TPEF::Section::SF_VLEN
@ SF_VLEN
Contains elements with variable length.
Definition: Section.hh:90
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
TPEF::Section::ST_STRTAB
@ ST_STRTAB
String table.
Definition: Section.hh:71
TCEString
Definition: TCEString.hh:53
TPEF::Section::ST_RELOC
@ ST_RELOC
Relocation section.
Definition: Section.hh:74
TPEF::Section::ST_NOTE
@ ST_NOTE
Note section.
Definition: Section.hh:76
TPEF::Section::ST_NULL
@ ST_NULL
NULL Section.
Definition: Section.hh:70
NotChunkable
Definition: Exception.hh:353
TPEF::Section::ST_CODE
@ ST_CODE
Text section.
Definition: Section.hh:79
TPEF::Section::ST_MR
@ ST_MR
Machine resources section.
Definition: Section.hh:78
TPEF::Section::SF_NOBITS
@ SF_NOBITS
Not initialized or not stored in this file.
Definition: Section.hh:91
TPEF::Section::ST_ADDRSP
@ ST_ADDRSP
Address space section.
Definition: Section.hh:77
InstanceNotFound
Definition: Exception.hh:304
TPEF::Section::elementCount
Word elementCount() const