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

#include <Section.hh>

Inheritance diagram for TPEF::RawSection:
Inheritance graph
Collaboration diagram for TPEF::RawSection:
Collaboration graph

Public Member Functions

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 void setDataLength (Word length)
 
virtual Word length () 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 SectionType type () const =0
 Returns SectioType of actual section instance. More...
 
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 isDataSection () const
 
virtual bool isCodeSection () const
 
- Public Member Functions inherited from TPEF::SafePointable
virtual ~SafePointable ()
 

Protected Member Functions

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

Private Types

typedef std::map< SectionOffset, Chunk * > ChunkMap
 Type of map that contains chunks. More...
 

Private Member Functions

 RawSection (const RawSection &)
 

Private Attributes

Word length_
 The length of raw data section. More...
 
ChunkMap dataChunks_
 Container for already created chunks. More...
 
std::vector< Chunk * > referredChunksCache_
 Table containing all the chunks that are requested from 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

Abstract base class for sections that stores raw data.

These sections are chunkable, that is they can create elements (chunks) on demand. These chunks point (using offsets) to section's raw data.

Definition at line 196 of file Section.hh.

Member Typedef Documentation

◆ ChunkMap

typedef std::map<SectionOffset, Chunk*> TPEF::RawSection::ChunkMap
private

Type of map that contains chunks.

Definition at line 234 of file Section.hh.

Constructor & Destructor Documentation

◆ ~RawSection()

TPEF::RawSection::~RawSection ( )
virtual

Destructor.

Definition at line 186 of file Section.cc.

186  {
188 }

References dataChunks_, and MapTools::deleteAllValues().

Here is the call graph for this function:

◆ RawSection() [1/2]

TPEF::RawSection::RawSection ( )
protected

Constructor.

Definition at line 180 of file Section.cc.

180  : Section(), length_(0) {
181 }

◆ RawSection() [2/2]

TPEF::RawSection::RawSection ( const RawSection )
private

Member Function Documentation

◆ assureInSection()

void TPEF::RawSection::assureInSection ( SectionOffset  offset) const
virtual

Checks that section is not indexed out of bounds.

If section is indexed out of bounds, exception is thrown.

Parameters
offsetThe offset being checked that it is in the area of section.
Exceptions
OutOfRangeif not in area of section.

Definition at line 354 of file Section.cc.

355  {
356  if (offset >= length())
357  throw OutOfRange(__FILE__, __LINE__, __func__);
358 }

References __func__, and length().

Referenced by chunk().

Here is the call graph for this function:

◆ belongsToSection()

bool TPEF::RawSection::belongsToSection ( const Chunk chunk) const

Returns true if the chunk in parameter belongs to this section.

Parameters
chunkChunk that is checked.
Returns
True if the chunk in parameter belongs to this section.

Definition at line 238 of file Section.cc.

238  {
239 
241  return dataChunks_[chunk->offset()] == chunk;
242  }
243 
244  return false;
245 }

References chunk(), MapTools::containsKey(), dataChunks_, and TPEF::Chunk::offset().

Referenced by TTAProgram::TPEFProgramFactory::createDataMemories(), and TPEFDumper::section().

Here is the call graph for this function:

◆ bytesToMAUs()

Word TPEF::RawSection::bytesToMAUs ( Word  bytes) const
virtual

Returns how many MAUs is amount of bytes described in parameter.

Parameters
bytesNumber of bytes to convert.
Returns
Number of MAUs.

Definition at line 296 of file Section.cc.

296  {
297  assert(aSpace() != NULL);
298 
299  if (aSpace()->MAU() == 0) {
300  abortWithError("MAU of address space can't be zero.");
301  }
302 
303  Word mauSize = static_cast<Word>(
304  ceil(static_cast<double>(aSpace()->MAU()) /
305  static_cast<double>(BYTE_BITWIDTH)));
306 
307  // must be even
308  assert ((bytes % mauSize) == 0);
309 
310  return bytes / mauSize;
311 }

References abortWithError, TPEF::Section::aSpace(), assert, and BYTE_BITWIDTH.

Referenced by chunkToMAUIndex(), TTAProgram::TPEFProgramFactory::createLabels(), and lengthInMAUs().

Here is the call graph for this function:

◆ chunk()

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

Returns a chunk object to data in the section at a given offset.

Checks that there is something in the section before returning chunk. In the other words, Chunks can not be given from outside of section's data.

Parameters
offsetThe offset of wanted data chunk.
Returns
Chunk pointing data.
Exceptions
NotChunkableIf called on a section that is not RawSection.

Reimplemented from TPEF::Section.

Definition at line 212 of file Section.cc.

212  {
213  Chunk* newChunk = NULL;
214 
215  try {
216  assureInSection(offset);
217  } catch (const OutOfRange& e) {
218  throw NotChunkable(__FILE__, __LINE__, __func__, e.errorMessage());
219  }
220  if (!MapTools::containsKey(dataChunks_, offset)) {
221  newChunk = new Chunk(offset);
222  dataChunks_[offset] = newChunk;
223  referredChunksCache_.clear();
224  } else {
225  newChunk = dataChunks_[offset];
226  }
227 
228  return newChunk;
229 }

References __func__, assureInSection(), MapTools::containsKey(), dataChunks_, Exception::errorMessage(), and referredChunksCache_.

Referenced by TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::TPEFDataSectionWriter::actualWriteData(), belongsToSection(), TPEF::DataSection::byte(), TPEF::StringSection::chunk2String(), chunkToMAUIndex(), TTAProgram::ProgramWriter::createBinary(), TTAProgram::ProgramWriter::createDataSections(), TPEF::TPEFUDataSectionWriter::createKeys(), TTAProgram::ProgramWriter::createRelocSections(), LabelManager::createSymbolWithReference(), LabelManager::finalize(), TPEF::AOutSymbolSectionReader::initializeSymbol(), TPEF::TPEFStringSectionReader::readData(), TPEF::AOutStringSectionReader::readData(), TPEF::TPEFTools::sectionOfElement(), TPEF::StringSection::string2Chunk(), and DataSectionCreator::writeDataLineToTPEF().

Here is the call graph for this function:

◆ chunkToMAUIndex()

Word TPEF::RawSection::chunkToMAUIndex ( const Chunk chunk) const
virtual

Returns MAU index to given chunk.

Parameters
chunkChunk whose MAU index should be found.
Returns
MAU index to data referred by the chunk.

Definition at line 341 of file Section.cc.

341  {
342  return bytesToMAUs(chunk->offset());
343 }

References bytesToMAUs(), chunk(), and TPEF::Chunk::offset().

Referenced by TTAProgram::TPEFProgramFactory::createDataMemories(), TPEF::TPEFRelocSectionReader::finalize(), TPEF::AOutRelocationSectionReader::finalize(), and TPEFDumper::section().

Here is the call graph for this function:

◆ empty()

bool TPEF::RawSection::empty ( ) const

◆ isChunkable()

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

Returns true if section is chunkable.

Returns
True if section is chunkable.

Reimplemented from TPEF::Section.

Definition at line 196 of file Section.cc.

196  {
197  return true;
198 }

◆ length()

Word TPEF::RawSection::length ( ) const
virtual

Returns length of data inside section.

Returns
Length of data inside section.

Reimplemented in TPEF::DataSection.

Definition at line 275 of file Section.cc.

275  {
276  return length_;
277 }

References length_.

Referenced by assureInSection(), lengthInMAUs(), TPEF::TPEFTools::sectionOfElement(), setDataLength(), setLengthInMAUs(), and TPEF::TPEFUDataSectionWriter::writeSize().

◆ lengthInMAUs()

Word TPEF::RawSection::lengthInMAUs ( ) const
virtual

Returns length of data section in MAUs.

Returns
Length of data inside sect.

Definition at line 285 of file Section.cc.

285  {
286  return bytesToMAUs(length());
287 }

References bytesToMAUs(), and length().

Referenced by TTAProgram::ProgramWriter::createBinary(), TTAProgram::TPEFProgramFactory::createDataMemories(), TTAProgram::ProgramWriter::createDataSections(), LabelManager::findRelocationDstSection(), TTAProgram::ProgramWriter::findSection(), LabelManager::findSectionByAddress(), and TPEFDumper::section().

Here is the call graph for this function:

◆ MAUsToBytes()

Word TPEF::RawSection::MAUsToBytes ( Word  maus) const
virtual

Returns how many bytes some amount of MAUs are.

Parameters
mausNumber of MAUs to convert.
Returns
Number of bytes that are needed for storing some amount of MAUs.

Definition at line 320 of file Section.cc.

320  {
321  assert(aSpace() != NULL);
322 
323  if (aSpace()->MAU() == 0) {
324  abortWithError("MAU of address space can't be zero for this method.");
325  }
326 
327  Word mauSize = static_cast<Word>(
328  ceil(static_cast<double>(aSpace()->MAU()) /
329  static_cast<double>(BYTE_BITWIDTH)));
330 
331  return maus * mauSize;
332 }

References abortWithError, TPEF::Section::aSpace(), assert, and BYTE_BITWIDTH.

Referenced by TTAProgram::ProgramWriter::createBinary(), TTAProgram::ProgramWriter::createRelocSections(), LabelManager::createSymbolWithReference(), LabelManager::finalize(), TPEF::DataSection::MAU(), setLengthInMAUs(), DataSectionCreator::writeDataLineToTPEF(), TPEF::LEDataSection::writeValue(), and TPEF::DataSection::writeValue().

Here is the call graph for this function:

◆ referredChunk()

Chunk * TPEF::RawSection::referredChunk ( Word  index) const

Returns chunks that is requested from section before.

Parameters
Indexof chunk to return.
Returns
Chunk to return.

Definition at line 378 of file Section.cc.

378  {
379  if (referredChunksCache_.empty()) {
380  ChunkMap::iterator iter = dataChunks_.begin();
381 
382  while (iter != dataChunks_.end()) {
383  referredChunksCache_.push_back((*iter).second);
384  iter++;
385  }
386  }
387 
388  return referredChunksCache_[index];
389 }

References dataChunks_, and referredChunksCache_.

Referenced by TPEF::TPEFUDataSectionWriter::createKeys().

◆ referredChunkCount()

Word TPEF::RawSection::referredChunkCount ( ) const

Returns number of chunks that are requested from section.

Returns
Number of requested chunks.

Definition at line 366 of file Section.cc.

366  {
367  return dataChunks_.size();
368 }

References dataChunks_.

Referenced by TPEF::TPEFUDataSectionWriter::createKeys().

◆ setDataLength()

void TPEF::RawSection::setDataLength ( Word  length)
virtual

Sets the length of section's data.

Parameters
lengthbytes of data in section.

Reimplemented in TPEF::DataSection.

Definition at line 253 of file Section.cc.

253  {
254  // should this method be overrided to throw exception if
255  // called with DataSection or StringSection classes
256  length_ = length;
257 }

References length(), and length_.

Referenced by TPEF::TPEFUDataSectionReader::readData(), TPEF::AOutReader::readData(), and setLengthInMAUs().

Here is the call graph for this function:

◆ setLengthInMAUs()

void TPEF::RawSection::setLengthInMAUs ( Word  length)
virtual

Sets the length of section's data.

Parameters
lengthSection length in MAUs.

Definition at line 265 of file Section.cc.

265  {
267 }

References length(), MAUsToBytes(), and setDataLength().

Referenced by TTAProgram::ProgramWriter::createDataSections(), and DataSectionCreator::finalize().

Here is the call graph for this function:

Member Data Documentation

◆ dataChunks_

ChunkMap TPEF::RawSection::dataChunks_
mutableprivate

Container for already created chunks.

Definition at line 237 of file Section.hh.

Referenced by belongsToSection(), chunk(), referredChunk(), referredChunkCount(), and ~RawSection().

◆ length_

Word TPEF::RawSection::length_
private

The length of raw data section.

Definition at line 231 of file Section.hh.

Referenced by length(), and setDataLength().

◆ referredChunksCache_

std::vector<Chunk*> TPEF::RawSection::referredChunksCache_
mutableprivate

Table containing all the chunks that are requested from section.

Definition at line 240 of file Section.hh.

Referenced by chunk(), and referredChunk().


The documentation for this class was generated from the following files:
TPEF::Section::aSpace
ASpaceElement * aSpace() const
TPEF::RawSection::setDataLength
virtual void setDataLength(Word length)
Definition: Section.cc:253
OutOfRange
Definition: Exception.hh:320
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
TPEF::RawSection::MAUsToBytes
virtual Word MAUsToBytes(Word mauCount) const
Definition: Section.cc:320
TPEF::RawSection::referredChunksCache_
std::vector< Chunk * > referredChunksCache_
Table containing all the chunks that are requested from section.
Definition: Section.hh:240
TPEF::RawSection::dataChunks_
ChunkMap dataChunks_
Container for already created chunks.
Definition: Section.hh:237
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::RawSection::assureInSection
virtual void assureInSection(SectionOffset offset) const
Definition: Section.cc:354
TPEF::Section::Section
Section()
Definition: Section.cc:64
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
TPEF::RawSection::length_
Word length_
The length of raw data section.
Definition: Section.hh:231
__func__
#define __func__
Definition: Application.hh:67
TPEF::RawSection::bytesToMAUs
virtual Word bytesToMAUs(Word byteCount) const
Definition: Section.cc:296
MAU
MinimumAddressableUnit MAU
Definition: CustomDBGController.cc:44
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
TPEF::Chunk::offset
SectionOffset offset() const
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
TPEF::RawSection::length
virtual Word length() const
Definition: Section.cc:275
NotChunkable
Definition: Exception.hh:353
TPEF::RawSection::chunk
virtual Chunk * chunk(SectionOffset offset) const
Definition: Section.cc:212