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

#include <DataMemory.hh>

Collaboration diagram for TTAProgram::DataMemory:
Collaboration graph

Public Member Functions

 DataMemory (const TTAMachine::AddressSpace &aSpace)
 
virtual ~DataMemory ()
 
void addDataDefinition (DataDefinition *dataDef)
 
DataDefinitiondataDefinition (Address address) const
 
DataDefinitiondataDefinition (int index) const
 
int dataDefinitionCount () const
 
int dataDefinitionsEnd () const
 
void deleteDataDefinition (int index)
 
const TTAMachine::AddressSpaceaddressSpace () const
 
void setAddressSpace (const TTAMachine::AddressSpace &space)
 
DataMemorycopy () const
 

Private Types

typedef std::map< AddressImage, DataDefinition * > DataDefMap
 Map for data definitions. More...
 

Private Attributes

const TTAMachine::AddressSpaceramSpace_
 Address space of the memory. More...
 
DataDefMap dataDefs_
 Data definitions for the address space. More...
 
std::vector< DataDefinition * > indexCache_
 Cache for indexing dataDefinitions. More...
 

Detailed Description

Represents an address space containing data.

Data definitions are ordered in the DataMemory class so that largest index contains the last data definition.

Definition at line 56 of file DataMemory.hh.

Member Typedef Documentation

◆ DataDefMap

Map for data definitions.

Definition at line 76 of file DataMemory.hh.

Constructor & Destructor Documentation

◆ DataMemory()

TTAProgram::DataMemory::DataMemory ( const TTAMachine::AddressSpace aSpace)

Sets address space of the memory.

Parameters
aSpaceAddress space of the memory.

Definition at line 46 of file DataMemory.cc.

46  :
47  ramSpace_(&aSpace) {
48 }

Referenced by copy().

◆ ~DataMemory()

TTAProgram::DataMemory::~DataMemory ( )
virtual

Deletes all the added definitions.

Definition at line 53 of file DataMemory.cc.

53  {
55 }

References dataDefs_, and MapTools::deleteAllValues().

Here is the call graph for this function:

Member Function Documentation

◆ addDataDefinition()

void TTAProgram::DataMemory::addDataDefinition ( DataDefinition dataDef)

Adds data to memory.

Data definitions are sorted by starting address of defined area.

Parameters
dataDefDefinition to add.

Definition at line 66 of file DataMemory.cc.

66  {
67  dataDefs_[dataDef->startAddress().location()] = dataDef;
68  // clear index cache since indices may change
69  indexCache_.clear();
70 }

References dataDefs_, indexCache_, TTAProgram::Address::location(), and TTAProgram::DataDefinition::startAddress().

Referenced by copy(), TTAProgram::Program::copyDataMemoriesFrom(), llvm::LLVMTCEBuilder::createDataDefinition(), TTAProgram::TPEFProgramFactory::createDataMemories(), llvm::LLVMTCEBuilder::createFPDataDefinition(), llvm::LLVMTCEBuilder::createGlobalValueDataDefinition(), llvm::LLVMTCEBuilder::createIntDataDefinition(), llvm::LLVMTCEBuilder::emitDataDef(), llvm::LLVMTCEBuilder::emitSPInitialization(), llvm::LLVMTCEBuilder::initDataSections(), and llvm::LLVMTCEBuilder::padToAlignment().

Here is the call graph for this function:

◆ addressSpace()

const TTAMachine::AddressSpace & TTAProgram::DataMemory::addressSpace ( ) const

Returns the address space of the data memory.

Returns
The address space of the data memory.

Definition at line 182 of file DataMemory.cc.

182  {
183  return *ramSpace_;
184 }

References ramSpace_.

Referenced by TTAProgram::Program::copyDataMemoriesFrom(), TTAProgram::ProgramWriter::createDataSections(), TTAProgram::Program::dataMemory(), POMDisassembler::disassembleProgram(), SimulatorFrontend::initializeDataMemories(), and main().

◆ copy()

DataMemory * TTAProgram::DataMemory::copy ( ) const

POM style copy constructor, which supports dynamic binding.

Returns
Copy of the object.

Definition at line 206 of file DataMemory.cc.

206  {
207  DataMemory* memCopy = new DataMemory(*ramSpace_);
208 
209  for (int i = 0; i < dataDefinitionCount(); i++) {
210  memCopy->addDataDefinition(dataDefinition(i).copy());
211  }
212 
213  return memCopy;
214 }

References addDataDefinition(), TTAProgram::DataDefinition::copy(), dataDefinition(), dataDefinitionCount(), DataMemory(), and ramSpace_.

Here is the call graph for this function:

◆ dataDefinition() [1/2]

DataDefinition & TTAProgram::DataMemory::dataDefinition ( Address  address) const

Finds the data definition, which contains the requested address.

Parameters
addressAddress whose data definition is requested.
Returns
Data definition, which contains requested address.

Definition at line 79 of file DataMemory.cc.

79  {
80  std::map<AddressImage, DataDefinition*>::const_iterator iter =
81  dataDefs_.upper_bound(address.location());
82 
83  if (iter != dataDefs_.begin()) {
84  iter--;
85  DataDefinition* dataDef = (*iter).second;
86  // this data definition should contain the requested address
87  if (address.location() < dataDef->startAddress().location() +
88  dataDef->size()) {
89  return *dataDef;
90  }
91  }
92 
93  throw NotAvailable(
94  __FILE__, __LINE__, __func__,
95  "Address space: " + ramSpace_->name() +
96  " does not contain data definition for requested address:" +
97  Conversion::toString(address.location()));
98 }

References __func__, dataDefs_, TTAProgram::Address::location(), TTAMachine::Component::name(), ramSpace_, TTAProgram::DataDefinition::size(), TTAProgram::DataDefinition::startAddress(), and Conversion::toString().

Referenced by StaticProgramAnalyzer::addProgram(), ControlFlowGraph::computeLeadersFromRelocations(), copy(), TTAProgram::Program::copyDataMemoriesFrom(), TTAProgram::TPEFProgramFactory::createDataMemories(), TTAProgram::ProgramWriter::createDataSections(), llvm::LLVMTCEBuilder::deleteDeadProcedures(), POMDisassembler::disassembleProgram(), SimulatorFrontend::initializeDataMemories(), main(), TTAProgram::Program::replaceUniversalAddressSpaces(), and setAddressSpace().

Here is the call graph for this function:

◆ dataDefinition() [2/2]

DataDefinition & TTAProgram::DataMemory::dataDefinition ( int  index) const

Finds the data definition by index.

Indices may change if new definitions are added to memory.

Parameters
indexIndex of the requested data definition.
Returns
Data definition, which contains requested address.

Definition at line 110 of file DataMemory.cc.

110  {
111  if (indexCache_.empty()) {
112  // create cache
113  for (std::map<AddressImage, DataDefinition*>::const_iterator iter =
114  dataDefs_.begin(); iter != dataDefs_.end(); iter++) {
115 
116  indexCache_.push_back((*iter).second);
117  }
118  }
119 
120  return *indexCache_[index];
121 }

References dataDefs_, and indexCache_.

◆ dataDefinitionCount()

int TTAProgram::DataMemory::dataDefinitionCount ( ) const

◆ dataDefinitionsEnd()

int TTAProgram::DataMemory::dataDefinitionsEnd ( ) const

Returns the place where the data definitions end. Calculates it based only on the last data definition (since dataDefs_ is sorted).

Returns
int end of data definitions

Definition at line 141 of file DataMemory.cc.

141  {
142  std::map<AddressImage, DataDefinition*>::const_reverse_iterator iter =
143  dataDefs_.rbegin();
144 
145  if (iter != dataDefs_.rend()) {
146  DataDefinition* dataDef = (*iter).second;
147  // this data definition should be the last one
148  return dataDef->startAddress().location() + dataDef->size();
149  }
150  // no data definitions added
151  return 0;
152 }

References dataDefs_, TTAProgram::Address::location(), TTAProgram::DataDefinition::size(), and TTAProgram::DataDefinition::startAddress().

Here is the call graph for this function:

◆ deleteDataDefinition()

void TTAProgram::DataMemory::deleteDataDefinition ( int  index)

Deletes the data definition at the given index.

Parameters
indexWhich data definition to delete.

Definition at line 160 of file DataMemory.cc.

160  {
161 
162  if (index < 0 || index >= dataDefinitionCount()) {
163  throw OutOfRange(__FILE__, __LINE__, __func__);
164  }
165 
166  DataDefMap::iterator iter = dataDefs_.begin();
167 
168  for (int i = 0; i < index; i++) {
169  iter++;
170  }
171 
172  dataDefs_.erase(iter);
173  indexCache_.clear();
174 }

References __func__, dataDefinitionCount(), dataDefs_, and indexCache_.

Here is the call graph for this function:

◆ setAddressSpace()

void TTAProgram::DataMemory::setAddressSpace ( const TTAMachine::AddressSpace space)

Set new address space for the data memory.

Parameters
spaceNew address space.

Definition at line 192 of file DataMemory.cc.

192  {
193  ramSpace_ = &space;
194  for (int i = 0; i < dataDefinitionCount(); i++) {
195  DataDefinition& def = dataDefinition(i);
196  def.setStartAddress(Address(def.startAddress().location(), space));
197  }
198 }

References dataDefinition(), dataDefinitionCount(), TTAProgram::Address::location(), ramSpace_, TTAProgram::DataDefinition::setStartAddress(), and TTAProgram::DataDefinition::startAddress().

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

Here is the call graph for this function:

Member Data Documentation

◆ dataDefs_

DataDefMap TTAProgram::DataMemory::dataDefs_
private

Data definitions for the address space.

Definition at line 82 of file DataMemory.hh.

Referenced by addDataDefinition(), dataDefinition(), dataDefinitionCount(), dataDefinitionsEnd(), deleteDataDefinition(), and ~DataMemory().

◆ indexCache_

std::vector<DataDefinition*> TTAProgram::DataMemory::indexCache_
mutableprivate

Cache for indexing dataDefinitions.

Definition at line 85 of file DataMemory.hh.

Referenced by addDataDefinition(), dataDefinition(), and deleteDataDefinition().

◆ ramSpace_

const TTAMachine::AddressSpace* TTAProgram::DataMemory::ramSpace_
private

Address space of the memory.

Definition at line 79 of file DataMemory.hh.

Referenced by addressSpace(), copy(), dataDefinition(), and setAddressSpace().


The documentation for this class was generated from the following files:
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
OutOfRange
Definition: Exception.hh:320
MapTools::deleteAllValues
static void deleteAllValues(MapType &aMap)
TTAProgram::DataMemory::dataDefinitionCount
int dataDefinitionCount() const
Definition: DataMemory.cc:129
TTAProgram::DataMemory::indexCache_
std::vector< DataDefinition * > indexCache_
Cache for indexing dataDefinitions.
Definition: DataMemory.hh:85
Conversion::toString
static std::string toString(const T &source)
NotAvailable
Definition: Exception.hh:728
TTAProgram::DataMemory::dataDefs_
DataDefMap dataDefs_
Data definitions for the address space.
Definition: DataMemory.hh:82
TTAProgram::DataMemory::DataMemory
DataMemory(const TTAMachine::AddressSpace &aSpace)
Definition: DataMemory.cc:46
__func__
#define __func__
Definition: Application.hh:67
TTAProgram::DataMemory::dataDefinition
DataDefinition & dataDefinition(Address address) const
Definition: DataMemory.cc:79
TTAProgram::DataDefinition::copy
virtual DataDefinition * copy() const
Definition: DataDefinition.cc:262
TTAProgram::DataMemory::ramSpace_
const TTAMachine::AddressSpace * ramSpace_
Address space of the memory.
Definition: DataMemory.hh:79