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

#include <DataSection.hh>

Inheritance diagram for TPEF::DataSection:
Inheritance graph
Collaboration diagram for TPEF::DataSection:
Collaboration graph

Public Member Functions

virtual ~DataSection ()
 
virtual SectionType type () const
 
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

 DataSection (bool init)
 
virtual Sectionclone () const
 
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 ()
 

Private Attributes

std::vector< Bytedata_
 Contains the data of data section.
 

Static Private Attributes

static DataSection proto_
 Prototype instance of section.
 

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

Data section for initialized data.

Derives from uninitialized data section so, this is extension of UDataSection.

Definition at line 52 of file DataSection.hh.

Constructor & Destructor Documentation

◆ ~DataSection()

TPEF::DataSection::~DataSection ( )
virtual

Destructor.

Definition at line 64 of file DataSection.cc.

64 {
65}

◆ DataSection()

TPEF::DataSection::DataSection ( bool  init)
protected

Constructor.

Parameters
inittrue if registeration is wanted

Definition at line 51 of file DataSection.cc.

51 : UDataSection(false) {
52
53 if (init) {
55 }
56
59}
static void registerSection(const Section *section)
Definition Section.cc:114
void unsetFlagNoBits()
void unsetFlagVLen()
UDataSection(bool init)

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

Here is the call graph for this function:

Member Function Documentation

◆ addByte()

void TPEF::DataSection::addByte ( Byte  aByte)
virtual

Adds byte of data into section.

Method copies data that is given in parameter.

Parameters
aByteByte that will be copied into the section.

Definition at line 200 of file DataSection.cc.

200 {
201 data_.push_back(aByte);
202}
std::vector< Byte > data_
Contains the data of data section.

References data_.

Referenced by addMAU(), TTAProgram::ProgramWriter::createBinary(), TPEF::AOutDataSectionReader::readData(), TPEF::AOutStringSectionReader::readData(), TPEF::TPEFDataSectionReader::readData(), TPEF::TPEFStringSectionReader::readData(), setDataLength(), TPEF::StringSection::string2Chunk(), and MachineResourceManager::stringToChunk().

◆ addMAU()

void TPEF::DataSection::addMAU ( MinimumAddressableUnit  aMAU)
virtual

Adds MAU to the end of section.

Parameters
aMAUMAU that will be copied into the section.
Exceptions
OutOfRangeIf the given value could not fit to the bit count defined by the address space's MAU width (when interpreted as unsigned or signed integer).

Definition at line 150 of file DataSection.cc.

150 {
151 int mauBits = aSpace()->MAU();
152
153 if (MathTools::requiredBits(aMAU) > mauBits) {
154 if (MathTools::requiredBitsSigned(aMAU) > mauBits) {
155 throw OutOfRange(
156 __FILE__, __LINE__, __func__,
157 "The given value does not fit to the MAU of address space.");
158 }
159 }
160
161 // how many bits are left to last byte
162 int modulo = mauBits % BYTE_BITWIDTH;
163
164 // write first bits
165 if (modulo != 0) {
166 mauBits -= modulo;
167 addByte(static_cast<Byte>(aMAU >> mauBits));
168 }
169
170 // move shifting to right for the next MAU
171 mauBits -= BYTE_BITWIDTH;
172
173 // write the rest
174 for (; mauBits >= 0;
175 mauBits = mauBits - BYTE_BITWIDTH) {
176
177 addByte(static_cast<Byte>(aMAU >> mauBits));
178 }
179}
#define __func__
const Byte BYTE_BITWIDTH
Definition BaseType.hh:136
unsigned char Byte
Definition BaseType.hh:116
static int requiredBits(unsigned long int number)
static int requiredBitsSigned(SLongWord number)
Byte MAU() const
virtual void addByte(Byte aByte)
ASpaceElement * aSpace() const

References __func__, addByte(), TPEF::Section::aSpace(), BYTE_BITWIDTH, TPEF::ASpaceElement::MAU(), MathTools::requiredBits(), and MathTools::requiredBitsSigned().

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

Here is the call graph for this function:

◆ byte() [1/2]

Byte TPEF::DataSection::byte ( const Chunk chunk) const
virtual

Returns byte from chunk's offset.

Parameters
chunkChunk containing offset of data.
Returns
Byte from chunk offset.

Reimplemented from TPEF::UDataSection.

Definition at line 114 of file DataSection.cc.

114 {
115 return data_[chunk->offset()];
116}
SectionOffset offset() const
virtual Chunk * chunk(SectionOffset offset) const
Definition Section.cc:212

References TPEF::RawSection::chunk(), data_, and TPEF::Chunk::offset().

Referenced by TPEF::TPEFDataSectionWriter::actualWriteData(), TPEF::TPEFStringSectionWriter::actualWriteData(), TPEF::AOutStringSectionReader::readData(), TPEF::TPEFStringSectionReader::readData(), TPEFDumper::section(), and ProgramImageGenerator::writeDataSection().

Here is the call graph for this function:

◆ byte() [2/2]

Byte TPEF::DataSection::byte ( Word  offset) const
virtual

Returns byte from byte offset.

Parameters
offsetOffset of data.
Returns
Byte from offset.

Definition at line 188 of file DataSection.cc.

188 {
189 return data_[offset];
190}

References data_.

◆ clone()

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

Creates an instance of DataSection.

Returns
Newly created section.

Reimplemented from TPEF::UDataSection.

Reimplemented in TPEF::LEDataSection, and TPEF::StringSection.

Definition at line 103 of file DataSection.cc.

103 {
104 return new DataSection(false);
105}
DataSection(bool init)

◆ isDataSection()

virtual bool TPEF::DataSection::isDataSection ( ) const
inlineoverridevirtual

Reimplemented from TPEF::Section.

Definition at line 71 of file DataSection.hh.

71{ return true; }

◆ length()

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

◆ MAU()

MinimumAddressableUnit TPEF::DataSection::MAU ( Word  index) const
virtual

Returns one MAU from section by gived MAU index.

Parameters
indexIndex of MAU to return.
Returns
One MAU of data section.

Definition at line 125 of file DataSection.cc.

125 {
126
127 int byteOffset = MAUsToBytes(index);
128 int mauInBytes = MAUsToBytes(1);
129
130 MinimumAddressableUnit retVal = 0;
131
132 // read all the bytes to retval
133 for(int i = 0; i < mauInBytes; i++) {
134 retVal = (retVal << BYTE_BITWIDTH) |
135 static_cast<MinimumAddressableUnit>(byte(byteOffset+i));
136 }
137
138 return retVal;
139}
Word MinimumAddressableUnit
Type for storing a MAU (must be unsigned type!). This limits the maximum size of the simulated minimu...
Definition BaseType.hh:184
virtual Word MAUsToBytes(Word mauCount) const
Definition Section.cc:320

References BYTE_BITWIDTH, and TPEF::RawSection::MAUsToBytes().

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

Here is the call graph for this function:

◆ setByte()

void TPEF::DataSection::setByte ( Word  offset,
Byte  aByte 
)
protectedvirtual

Sets value of one byte of data section.

NOTE: Byte here is tpef file byte. (8bits).

Parameters
offsetOffset where to write the byte.
aByteValue to write.

Definition at line 86 of file DataSection.cc.

86 {
87 if (offset >= data_.size()) {
89 "Can't set byte " +
90 Conversion::toString(static_cast<int>(aByte)) +
91 " to offset: " + Conversion::toString(offset) +
92 "\t data section size: " + Conversion::toString(data_.size()));
93 }
94 data_[offset] = aByte;
95}
#define abortWithError(message)
static std::string toString(const T &source)

References abortWithError, data_, and Conversion::toString().

Referenced by writeValue(), TPEF::LEDataSection::writeValue(), writeValue(), and TPEF::LEDataSection::writeValue().

Here is the call graph for this function:

◆ setDataLength()

void TPEF::DataSection::setDataLength ( Word  aLength)
virtual

Tries to set data length.

Can be used only for making section bigger. Asserts if method is tried to use for making section smaller.

Initializes data with zeros.

Parameters
lengthLength to which section is expanded.

Reimplemented from TPEF::RawSection.

Definition at line 225 of file DataSection.cc.

225 {
226 assert(length() <= aLength);
227 while (length() < aLength) {
228 addByte(0);
229 }
230}
#define assert(condition)
virtual Word length() const

References addByte(), assert, and length().

Here is the call graph for this function:

◆ type()

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

Returns section's type.

Returns
Type of section.

Reimplemented from TPEF::UDataSection.

Reimplemented in TPEF::LEDataSection, and TPEF::StringSection.

Definition at line 73 of file DataSection.cc.

73 {
74 return ST_DATA;
75}
@ ST_DATA
Initialized data section.
Definition Section.hh:80

References TPEF::Section::ST_DATA.

◆ writeValue() [1/2]

void TPEF::DataSection::writeValue ( Word  index,
Word  numOfMAUs,
signed long  value 
)
virtual

Writes signed value to data section.

For example, when we call writeValue(0, 4, -3) and MAU is 2bit start of data section will be 11 11 11 01.

MAUs are stored in data section like this: 00000011 000000011 00000011 00000001 (one MAU per byte)

If we call writeValue(0, 4, -3) and MAU is 10bit start of data section will be 1111111111 1111111111 1111111111 1111111101.

However the MAUs are stored in data section like this:

00000011 11111111|00000011 11111111|00000011 11111111|00000011 11111101| MAU1 | MAU2 | MAU3 | MAU4 |

Parameters
indexMAU offset to section where to we write value.
numOfMAUsNumber of MAUs that we use for storing value.
valueValue to write.

Reimplemented in TPEF::LEDataSection.

Definition at line 305 of file DataSection.cc.

305 {
306
307 int mauInBytes = MAUsToBytes(1);
308
309 MinimumAddressableUnit mauMask =
310 static_cast<unsigned int>(-1) >>
311 (sizeof(mauMask)*BYTE_BITWIDTH - aSpace()->MAU());
312
313 int shiftCount = 0;
314
315 // start writing from end of area..
316 for (int i = numOfMAUs - 1; i >= 0; i--) {
317 int byteOffset = MAUsToBytes(index + i);
318
319 MinimumAddressableUnit currentMAU =
320 static_cast<MinimumAddressableUnit>(~0);
321
322 if (shiftCount < static_cast<int>(sizeof(value)*BYTE_BITWIDTH)) {
323 // I tried math tools... system tests went broken :(
324 // ssooo... if it's not broken....
325 currentMAU = (value >> shiftCount) & mauMask;
326 shiftCount += aSpace()->MAU();
327 }
328
329 // write current MAU :)
330 for (int j = mauInBytes-1; j >= 0; j--) {
331 Byte currentByte = static_cast<Byte>(currentMAU);
332 setByte(byteOffset + j,currentByte);
333 currentMAU = currentMAU >> BYTE_BITWIDTH;
334 }
335 }
336}
virtual void setByte(Word offset, Byte aByte)

References TPEF::Section::aSpace(), BYTE_BITWIDTH, TPEF::ASpaceElement::MAU(), TPEF::RawSection::MAUsToBytes(), and setByte().

Here is the call graph for this function:

◆ writeValue() [2/2]

void TPEF::DataSection::writeValue ( Word  index,
Word  numOfMAUs,
unsigned long  value 
)
virtual

Writes unsigned value to data section.

Value is aligned to field as normal big endian value least significant bit is stored to last bit of last MAU.

If we call writeValue(0, 4, 3) and MAU is 2bit start of data section will be 00 00 00 11.

However the MAUs are stored in data section like this: 00000000|000000000|00000000|00000011 (one MAU per byte) MAU1 | MAU2 | MAU3 | MAU4

Parameters
indexMAU offset to section where to we write value.
numOfMAUsNumber of MAUs that we use for storing value.
valueValue to write.

Reimplemented in TPEF::LEDataSection.

Definition at line 250 of file DataSection.cc.

250 {
251
252 int mauInBytes = MAUsToBytes(1);
253
254 MinimumAddressableUnit mauMask =
255 static_cast<unsigned int>(-1) >>
256 (sizeof(mauMask)*BYTE_BITWIDTH - aSpace()->MAU());
257
258 int shiftCount = 0;
259
260 // start writing from end of area..
261 for (int i = numOfMAUs - 1; i >= 0; i--) {
262 int byteOffset = MAUsToBytes(index + i);
263
264 MinimumAddressableUnit currentMAU = 0;
265
266 if (shiftCount < static_cast<int>(sizeof(value)*BYTE_BITWIDTH)) {
267 // I tried math tools... system tests went broken :(
268 // ssooo... if it's not broken....
269 currentMAU = (value >> shiftCount) & mauMask;
270 }
271
272 shiftCount += aSpace()->MAU();
273
274 // write current MAU :)
275 for (int j = mauInBytes-1; j >= 0; j--) {
276 Byte currentByte = static_cast<Byte>(currentMAU);
277 setByte(byteOffset + j, currentByte);
278 currentMAU = currentMAU >> BYTE_BITWIDTH;
279 }
280 }
281}

References TPEF::Section::aSpace(), BYTE_BITWIDTH, TPEF::ASpaceElement::MAU(), TPEF::RawSection::MAUsToBytes(), and setByte().

Referenced by TPEF::AOutRelocationSectionReader::finalize(), and DataSectionCreator::writeDataLineToTPEF().

Here is the call graph for this function:

Member Data Documentation

◆ data_

std::vector<Byte> TPEF::DataSection::data_
private

Contains the data of data section.

Definition at line 83 of file DataSection.hh.

Referenced by addByte(), byte(), byte(), length(), and setByte().

◆ proto_

DataSection TPEF::DataSection::proto_
staticprivate

Prototype instance of section.

Definition at line 80 of file DataSection.hh.


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