OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
TTAProgram::DataDefinition Class Reference

#include <DataDefinition.hh>

Inheritance diagram for TTAProgram::DataDefinition:
Inheritance graph
Collaboration diagram for TTAProgram::DataDefinition:
Collaboration graph

Public Member Functions

 DataDefinition (Address start, int size, bool littleEndian, MinimumAddressableUnit *initData=NULL, bool allZeros=false)
 
 DataDefinition (Address start, const std::vector< MinimumAddressableUnit > &initData, bool littleEndian)
 
virtual ~DataDefinition ()
 
virtual Address startAddress () const
 
virtual void setStartAddress (Address start)
 
virtual bool isInitialized () const
 
virtual MinimumAddressableUnit MAU (int index) const
 
virtual int size () const
 
virtual bool isAddress () const
 
virtual bool isInstructionAddress () const
 
virtual Address destinationAddress () const
 
virtual void setDestinationAddress (Address dest)
 
virtual DataDefinitioncopy () const
 
bool isLittleEndian () const
 

Private Attributes

Address start_
 Start address of definition. More...
 
int size_
 Size of uninitialized data definition. More...
 
std::vector< MinimumAddressableUnit > * data_
 Init data of definition. More...
 
bool allZeros_
 Is all the data zeros? (In this case data_ is null) More...
 
bool littleEndian_
 

Detailed Description

Describes characteristics of an initialized or uninitialized memory area.

Definition at line 52 of file DataDefinition.hh.

Constructor & Destructor Documentation

◆ DataDefinition() [1/2]

TTAProgram::DataDefinition::DataDefinition ( Address  start,
int  size,
bool  littleEndian,
MinimumAddressableUnit initData = NULL,
bool  allZeros = false 
)

Creates data area definition.

Parameters
startStarting address of definition.
sizeNumber of MAUs that area represents.
initDataTable of initialization data if initialized definition.
Exceptions
OutOfRangeIn case the initialization data contains data that do not fit in a MAU.

Definition at line 52 of file DataDefinition.cc.

55  : start_(start),
56  size_(size),
57  allZeros_(allZeros),
58  littleEndian_(littleEndian) {
59  if (initData != NULL) {
60  data_ = new std::vector<MinimumAddressableUnit>(size);
61  for (int i = 0 ; i < size; i++) {
62  const int mauBits = start.space().width();
63  const MinimumAddressableUnit mau = initData[i];
64  if (MathTools::requiredBits(mau) > mauBits) {
65  if (MathTools::requiredBitsSigned(mau) > mauBits) {
66  throw OutOfRange(
67  __FILE__, __LINE__, __func__,
68  "The given value does not fit to the MAU of address "
69  "space.");
70  }
71  }
72 
73 
74  (*data_)[i] = mau;
75  }
76  } else {
77  data_ = NULL;
78  }
79 }

References __func__, data_, MathTools::requiredBits(), MathTools::requiredBitsSigned(), size(), TTAProgram::Address::space(), and TTAMachine::AddressSpace::width().

Referenced by copy().

Here is the call graph for this function:

◆ DataDefinition() [2/2]

TTAProgram::DataDefinition::DataDefinition ( Address  start,
const std::vector< MinimumAddressableUnit > &  initData,
bool  littleEndian 
)

Creates initialized data area definition.

Parameters
startStarting address of definition.
initDataInitialization data.
Exceptions
OutOfRangeIn case the initialization data contains data that do not fit in a MAU.

Definition at line 89 of file DataDefinition.cc.

92  : start_(start), allZeros_(false), littleEndian_(littleEndian) {
93  // check that the MAUs are not too large for the address space
94  for (std::size_t i = 0 ; i < initData.size(); i++) {
95  const int mauBits = start.space().width();
96  const MinimumAddressableUnit mau = initData[i];
97 
98  if (MathTools::requiredBits(mau) > mauBits) {
99 
100  if (MathTools::requiredBitsSigned(mau) > mauBits) {
101  throw OutOfRange(
102  __FILE__, __LINE__, __func__,
103  "The given value does not fit to the MAU of address "
104  "space.");
105  }
106  }
107  }
108 
109  data_ = new std::vector<MinimumAddressableUnit>(initData);
110  size_ = data_->size();
111 }

References __func__, data_, MathTools::requiredBits(), MathTools::requiredBitsSigned(), size_, TTAProgram::Address::space(), and TTAMachine::AddressSpace::width().

Here is the call graph for this function:

◆ ~DataDefinition()

TTAProgram::DataDefinition::~DataDefinition ( )
virtual

Frees all the init data if there is any.

Definition at line 116 of file DataDefinition.cc.

116  {
117  if (data_ != NULL) {
118  delete data_;
119  data_ = NULL;
120  }
121 }

References data_.

Member Function Documentation

◆ copy()

DataDefinition * TTAProgram::DataDefinition::copy ( ) const
virtual

POM style copy constructor, which supports dynamic binding.

Returns
Copy of the object.

Reimplemented in TTAProgram::DataInstructionAddressDef, and TTAProgram::DataAddressDef.

Definition at line 262 of file DataDefinition.cc.

262  {
263  DataDefinition* newDef = NULL;
264 
265  if (allZeros_) {
266  newDef = new DataDefinition(start_, size_, littleEndian_, NULL, true);
267  } else if (isInitialized()) {
268  newDef = new DataDefinition(start_, *data_, littleEndian_);
269  } else {
270  newDef = new DataDefinition(start_, size_, littleEndian_);
271  }
272 
273  return newDef;
274 }

References allZeros_, data_, DataDefinition(), isInitialized(), littleEndian_, size_, and start_.

Referenced by TTAProgram::DataMemory::copy(), and TTAProgram::Program::copyDataMemoriesFrom().

Here is the call graph for this function:

◆ destinationAddress()

Address TTAProgram::DataDefinition::destinationAddress ( ) const
virtual

Returns address where to initialization data refers.

Returns
Address where to initialization data refers.

Reimplemented in TTAProgram::DataInstructionAddressDef, and TTAProgram::DataAddressDef.

Definition at line 241 of file DataDefinition.cc.

241  {
242  throw WrongSubclass(
243  __FILE__, __LINE__, __func__,
244  "Data definition does not contain an address reference.");
245 }

References __func__.

Referenced by ControlFlowGraph::computeLeadersFromRelocations(), TTAProgram::Program::copyDataMemoriesFrom(), TTAProgram::ProgramWriter::createDataSections(), llvm::LLVMTCEBuilder::deleteDeadProcedures(), MAU(), and TTAProgram::Program::replaceUniversalAddressSpaces().

◆ isAddress()

bool TTAProgram::DataDefinition::isAddress ( ) const
virtual

Returns true if init data of definition contains an address.

Returns
True if init data of definition contains an address.

Reimplemented in TTAProgram::DataInstructionAddressDef, and TTAProgram::DataAddressDef.

Definition at line 221 of file DataDefinition.cc.

221  {
222  return false;
223 }

Referenced by TTAProgram::ProgramWriter::createDataSections(), MAU(), and TTAProgram::Program::replaceUniversalAddressSpaces().

◆ isInitialized()

bool TTAProgram::DataDefinition::isInitialized ( ) const
virtual

Returns true if data definition contains initialization data.

Returns
True if data definition contains initialization data.

Reimplemented in TTAProgram::DataInstructionAddressDef, and TTAProgram::DataAddressDef.

Definition at line 144 of file DataDefinition.cc.

144  {
145  return allZeros_ || (data_ != NULL);
146 }

References allZeros_, and data_.

Referenced by copy(), TTAProgram::ProgramWriter::createDataSections(), POMDisassembler::dataDefDescription(), SimulatorFrontend::initializeDataMemories(), main(), and MAU().

◆ isInstructionAddress()

bool TTAProgram::DataDefinition::isInstructionAddress ( ) const
virtual

Returns true if init data of definition contains an instruction address.

Returns
True if init data of definition contains an instruction address.

Reimplemented in TTAProgram::DataInstructionAddressDef.

Definition at line 231 of file DataDefinition.cc.

231  {
232  return false;
233 }

Referenced by ControlFlowGraph::computeLeadersFromRelocations(), TTAProgram::Program::copyDataMemoriesFrom(), and TTAProgram::Program::replaceUniversalAddressSpaces().

◆ isLittleEndian()

bool TTAProgram::DataDefinition::isLittleEndian ( ) const
inline

Definition at line 78 of file DataDefinition.hh.

78 { return littleEndian_; }

References littleEndian_.

Referenced by TTAProgram::DataAddressDef::copy().

◆ MAU()

MinimumAddressableUnit TTAProgram::DataDefinition::MAU ( int  index) const
virtual

Returns one MAU of initialization values from requested index.

Parameters
indexIndex of the MAU whic is returned.
Returns
One MAU of initialization values from requested index.

Definition at line 155 of file DataDefinition.cc.

155  {
156  assert(index < size());
157 
158  if (isAddress()) {
159  if (littleEndian_) {
160  index = size() - index -1;
161  }
162 
164 
165  // how many bits should be masked out
166  int maskBits = index * startAddress().space().width();
167 
168  // how many bits is the whole area definition
169  int totalAreaDefBits = size() * startAddress().space().width();
170 
171  // how many bits of the data definition should not be masked out
172  int remainingBits = totalAreaDefBits - maskBits;
173 
174  // how many bits is value that is stored as a address
175  int addressBits = sizeof(retVal) * BYTE_BITWIDTH;
176 
177  // how many bits will be masked from start of address
178  int addressMaskBits = addressBits - remainingBits;
179 
180  // mask out bits if needed
181  if (addressMaskBits >= 0) {
182  retVal = retVal << addressMaskBits;
183  } else {
184  retVal = retVal >> (-addressMaskBits);
185  }
186 
187  // align MAU bits to right
188  retVal = retVal >> (addressBits - startAddress().space().width());
189 
190  // return MAU
191  return retVal;
192 
193  } else if(allZeros_) {
194  return 0;
195  } else if (isInitialized()) {
196  return (*data_)[index];
197 
198  } else {
199  throw NotAvailable(
200  __FILE__, __LINE__, __func__,
201  "Definition does not contain initialisation data.");
202  }
203 }

References __func__, allZeros_, assert, BYTE_BITWIDTH, data_, destinationAddress(), isAddress(), isInitialized(), littleEndian_, TTAProgram::Address::location(), size(), TTAProgram::Address::space(), startAddress(), and TTAMachine::AddressSpace::width().

Referenced by TTAProgram::ProgramWriter::createDataSections(), POMDisassembler::dataDefDescription(), SimulatorFrontend::initializeDataMemories(), and main().

Here is the call graph for this function:

◆ setDestinationAddress()

void TTAProgram::DataDefinition::setDestinationAddress ( Address  dest)
virtual

Set new destination address for the data definition.

Reimplemented in TTAProgram::DataAddressDef.

Definition at line 251 of file DataDefinition.cc.

251  {
252  throw WrongSubclass(
253  __FILE__, __LINE__, __func__,
254  "Data definition does not refer to a data address.");
255 }

References __func__.

Referenced by TTAProgram::Program::replaceUniversalAddressSpaces().

◆ setStartAddress()

void TTAProgram::DataDefinition::setStartAddress ( Address  start)
virtual

Definition at line 134 of file DataDefinition.cc.

134  {
135  start_ = start;
136 }

References start_.

Referenced by TTAProgram::DataMemory::setAddressSpace().

◆ size()

int TTAProgram::DataDefinition::size ( ) const
virtual

◆ startAddress()

Address TTAProgram::DataDefinition::startAddress ( ) const
virtual

Member Data Documentation

◆ allZeros_

bool TTAProgram::DataDefinition::allZeros_
private

Is all the data zeros? (In this case data_ is null)

Definition at line 91 of file DataDefinition.hh.

Referenced by copy(), isInitialized(), and MAU().

◆ data_

std::vector<MinimumAddressableUnit>* TTAProgram::DataDefinition::data_
private

Init data of definition.

Definition at line 88 of file DataDefinition.hh.

Referenced by copy(), DataDefinition(), isInitialized(), MAU(), and ~DataDefinition().

◆ littleEndian_

bool TTAProgram::DataDefinition::littleEndian_
private

Definition at line 93 of file DataDefinition.hh.

Referenced by copy(), isLittleEndian(), and MAU().

◆ size_

int TTAProgram::DataDefinition::size_
private

Size of uninitialized data definition.

Definition at line 85 of file DataDefinition.hh.

Referenced by copy(), DataDefinition(), and size().

◆ start_

Address TTAProgram::DataDefinition::start_
private

Start address of definition.

Definition at line 82 of file DataDefinition.hh.

Referenced by copy(), setStartAddress(), and startAddress().


The documentation for this class was generated from the following files:
TTAProgram::DataDefinition::DataDefinition
DataDefinition(Address start, int size, bool littleEndian, MinimumAddressableUnit *initData=NULL, bool allZeros=false)
Definition: DataDefinition.cc:52
TTAProgram::DataDefinition::size_
int size_
Size of uninitialized data definition.
Definition: DataDefinition.hh:85
TTAProgram::DataDefinition::startAddress
virtual Address startAddress() const
Definition: DataDefinition.cc:129
TTAProgram::DataDefinition::size
virtual int size() const
Definition: DataDefinition.cc:211
OutOfRange
Definition: Exception.hh:320
TTAProgram::DataDefinition::isAddress
virtual bool isAddress() const
Definition: DataDefinition.cc:221
TTAProgram::Address::space
const TTAMachine::AddressSpace & space() const
TTAProgram::DataDefinition::start_
Address start_
Start address of definition.
Definition: DataDefinition.hh:82
NotAvailable
Definition: Exception.hh:728
assert
#define assert(condition)
Definition: Application.hh:86
WrongSubclass
Definition: Exception.hh:336
TTAProgram::DataDefinition::destinationAddress
virtual Address destinationAddress() const
Definition: DataDefinition.cc:241
MinimumAddressableUnit
Word MinimumAddressableUnit
Type for storing a MAU (must be unsigned type!). This limits the maximum size of the simulated minimu...
Definition: BaseType.hh:184
TTAProgram::DataDefinition::isInitialized
virtual bool isInitialized() const
Definition: DataDefinition.cc:144
__func__
#define __func__
Definition: Application.hh:67
TTAProgram::DataDefinition::allZeros_
bool allZeros_
Is all the data zeros? (In this case data_ is null)
Definition: DataDefinition.hh:91
MathTools::requiredBits
static int requiredBits(unsigned long int number)
TTAProgram::Address::location
InstructionAddress location() const
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
TTAProgram::DataDefinition::littleEndian_
bool littleEndian_
Definition: DataDefinition.hh:93
MathTools::requiredBitsSigned
static int requiredBitsSigned(SLongWord number)
TTAProgram::DataDefinition::data_
std::vector< MinimumAddressableUnit > * data_
Init data of definition.
Definition: DataDefinition.hh:88