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

#include <StringSection.hh>

Inheritance diagram for TPEF::StringSection:
Inheritance graph
Collaboration diagram for TPEF::StringSection:
Collaboration graph

Public Member Functions

virtual ~StringSection ()
 
virtual SectionType type () const
 
std::string chunk2String (const Chunk *chunk) const
 
Chunkstring2Chunk (const std::string &str)
 
- Public Member Functions inherited from TPEF::DataSection
virtual ~DataSection ()
 
virtual Byte byte (const Chunk *chunk) const
 
virtual Byte byte (Word offset) const
 
virtual void addByte (Byte aByte)
 
virtual MinimumAddressableUnit MAU (Word index) const
 
virtual void addMAU (MinimumAddressableUnit aMAU)
 
virtual void writeValue (Word index, Word numOfMAUs, unsigned long value)
 
virtual void writeValue (Word index, Word numOfMAUs, signed long value)
 
virtual Word length () const
 
virtual void setDataLength (Word length)
 
virtual bool isDataSection () const override
 
- Public Member Functions inherited from TPEF::UDataSection
virtual ~UDataSection ()
 
- Public Member Functions inherited from TPEF::RawSection
virtual bool isChunkable () const
 
virtual Chunkchunk (SectionOffset offset) const
 
virtual void assureInSection (SectionOffset offset) const
 
virtual ~RawSection ()
 
bool empty () const
 
virtual void setLengthInMAUs (Word length)
 
virtual Word lengthInMAUs () const
 
virtual Word bytesToMAUs (Word byteCount) const
 
virtual Word MAUsToBytes (Word mauCount) const
 
virtual Word chunkToMAUIndex (const Chunk *chunk) const
 
Word referredChunkCount () const
 
ChunkreferredChunk (Word index) const
 
bool belongsToSection (const Chunk *chunk) const
 
- Public Member Functions inherited from TPEF::Section
virtual ~Section ()
 
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 isCodeSection () const
 
- Public Member Functions inherited from TPEF::SafePointable
virtual ~SafePointable ()
 

Protected Member Functions

 StringSection (bool init)
 
virtual Sectionclone () const
 
- Protected Member Functions inherited from TPEF::DataSection
 DataSection (bool init)
 
virtual void setByte (Word offset, Byte aByte)
 
- Protected Member Functions inherited from TPEF::UDataSection
 UDataSection (bool init)
 
- Protected Member Functions inherited from TPEF::RawSection
 RawSection ()
 
- Protected Member Functions inherited from TPEF::Section
 Section ()
 
void setFlagVLen ()
 
void unsetFlagVLen ()
 
- Protected Member Functions inherited from TPEF::SafePointable
 SafePointable ()
 

Static Private Attributes

static StringSection proto_
 Prototype of the section. More...
 

Additional Inherited Members

- Public Types inherited from TPEF::Section
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 }
 
- Static Public Member Functions inherited from TPEF::Section
static SectioncreateSection (SectionType type)
 
static bool isProgramSection (SectionType type)
 
- Static Protected Member Functions inherited from TPEF::Section
static void registerSection (const Section *section)
 

Detailed Description

Represents a string table section.

Definition at line 48 of file StringSection.hh.

Constructor & Destructor Documentation

◆ ~StringSection()

TPEF::StringSection::~StringSection ( )
virtual

Destructor.

Definition at line 62 of file StringSection.cc.

62  {
63 }

◆ StringSection()

TPEF::StringSection::StringSection ( bool  init)
protected

Constructor.

Parameters
initTrue if registeration is wanted.

Definition at line 50 of file StringSection.cc.

50  : DataSection(false) {
51  if (init) {
53  }
54 
55  unsetFlagVLen();
57 }

References TPEF::Section::registerSection(), TPEF::Section::unsetFlagNoBits(), and TPEF::Section::unsetFlagVLen().

Referenced by clone().

Here is the call graph for this function:

Member Function Documentation

◆ chunk2String()

string TPEF::StringSection::chunk2String ( const Chunk chunk) const

Returns the string of the given chunk.

Parameters
chunkChunk where string starts.
Exceptions
UnexpectedValueIf no terminating zero is found.

Definition at line 72 of file StringSection.cc.

72  {
73  unsigned int offset = chunk->offset();
74  assert(offset <= length());
75 
76  string result = "";
77  while (byte(offset) != 0) {
78  // if we are reading the last byte in section and it is not zero,
79  // we have an exception
80  if (offset == length() - 1) {
81  throw UnexpectedValue(
82  __FILE__, __LINE__, __func__,
83  "No terminating zero found!");
84  }
85  result.append(1, byte(offset));
86  offset++;
87  }
88 
89  return result;
90 }

References __func__, assert, TPEF::RawSection::chunk(), TPEF::DataSection::length(), and TPEF::Chunk::offset().

Referenced by MachineResourceManager::addResourceElement(), TPEF::TPEFTools::addressSpaceName(), TTAProgram::TPEFResourceUpdater::bus(), TPEFDisassembler::createDisassemblyElement(), TTAProgram::TPEFProgramFactory::createLabels(), TPEF::AOutSymbolSectionReader::finalize(), TTAProgram::TPEFResourceUpdater::functionUnit(), TTAProgram::TPEFResourceUpdater::functionUnitPort(), TTAProgram::TPEFResourceUpdater::immediateUnit(), TTAProgram::TPEFResourceUpdater::initCache(), TPEF::AOutSymbolSectionReader::initializeSymbol(), TTAProgram::TPEFResourceUpdater::operand(), TTAProgram::TPEFResourceUpdater::registerFile(), TPEF::TPEFTools::resourceName(), TPEFDumper::section(), TPEFDumper::sectionHeader(), TTAProgram::TPEFProgramFactory::stringOfChunk(), TPEFDumper::symbolString(), and ProgramImageGenerator::writeDataSection().

Here is the call graph for this function:

◆ clone()

Section * TPEF::StringSection::clone ( ) const
protectedvirtual

Creates an instance of the class.

Returns
Newly created section.

Reimplemented from TPEF::DataSection.

Definition at line 158 of file StringSection.cc.

158  {
159  return new StringSection(false);
160 }

References StringSection().

Here is the call graph for this function:

◆ string2Chunk()

Chunk * TPEF::StringSection::string2Chunk ( const std::string &  str)

Checks if string is already found from section and returns chunk pointing to it.

If string is not already found from section, it is added to end, before returning chunk.

Parameters
strString to find from section.
Returns
Chunk pointing to requested string.

Definition at line 103 of file StringSection.cc.

103  {
104 
105  // needed first byte
106  if (length() == 0) {
107  addByte(0);
108  }
109 
110  for (int i = 0;
111  i < static_cast<int>(length()) -
112  static_cast<int>(str.length()); i++) {
113 
114  Word charsToMatch = str.length() + 1;
115 
116  while (charsToMatch) {
117  charsToMatch--;
118 
119  if (byte(i + charsToMatch) != str.c_str()[charsToMatch]) {
120  charsToMatch = 1;
121  break;
122  }
123  }
124 
125  // we found matching string
126  if (charsToMatch == 0) {
127  return chunk(i);
128  }
129  }
130 
131  // didn't find matching string, add new one
132  SectionOffset returnOffset = length();
133 
134  for (Word i = 0; i < str.size(); i++) {
135  addByte(str[i]);
136  }
137  addByte(0);
138 
139  return chunk(returnOffset);
140 }

References TPEF::DataSection::addByte(), TPEF::RawSection::chunk(), and TPEF::DataSection::length().

Referenced by TTAProgram::TPEFResourceUpdater::bus(), TTAProgram::ProgramWriter::createASpaceElement(), TTAProgram::ProgramWriter::createBinary(), TTAProgram::ProgramWriter::createDataSections(), TTAProgram::ProgramWriter::createRelocSections(), LabelManager::finalize(), TTAProgram::TPEFResourceUpdater::functionUnit(), TTAProgram::TPEFResourceUpdater::functionUnitPort(), TTAProgram::TPEFResourceUpdater::immediateUnit(), TTAProgram::TPEFResourceUpdater::operand(), TPEF::AOutSymbolSectionReader::readData(), TPEF::AOutReader::readData(), TTAProgram::TPEFResourceUpdater::registerFile(), MachineResourceManager::stringToChunk(), and LabelManager::writeProcedureSymbols().

Here is the call graph for this function:

◆ type()

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

Returns the type of section.

Returns
Type of section.

Reimplemented from TPEF::DataSection.

Definition at line 148 of file StringSection.cc.

148  {
149  return ST_STRTAB;
150 }

References TPEF::Section::ST_STRTAB.

Member Data Documentation

◆ proto_

StringSection TPEF::StringSection::proto_
staticprivate

Prototype of the section.

Definition at line 64 of file StringSection.hh.


The documentation for this class was generated from the following files:
TPEF::Section::unsetFlagVLen
void unsetFlagVLen()
TPEF::DataSection::addByte
virtual void addByte(Byte aByte)
Definition: DataSection.cc:200
assert
#define assert(condition)
Definition: Application.hh:86
UnexpectedValue
Definition: Exception.hh:455
__func__
#define __func__
Definition: Application.hh:67
TPEF::StringSection::StringSection
StringSection(bool init)
Definition: StringSection.cc:50
TPEF::Section::unsetFlagNoBits
void unsetFlagNoBits()
TPEF::Section::registerSection
static void registerSection(const Section *section)
Definition: Section.cc:114
TPEF::SectionOffset
Word SectionOffset
Type for storing offsets relative to a given base offset value.
Definition: TPEFBaseType.hh:49
TPEF::Chunk::offset
SectionOffset offset() const
TPEF::Section::ST_STRTAB
@ ST_STRTAB
String table.
Definition: Section.hh:71
TPEF::DataSection::DataSection
DataSection(bool init)
Definition: DataSection.cc:51
TPEF::DataSection::length
virtual Word length() const
Definition: DataSection.cc:210
TPEF::RawSection::chunk
virtual Chunk * chunk(SectionOffset offset) const
Definition: Section.cc:212