OpenASIP 2.2
Loading...
Searching...
No Matches
DataMemory.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file DataMemory.cc
26 *
27 * Implementation of DataMemory class.
28 *
29 * @author Mikael Lepistö 2006 (mikael.lepisto-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include "DataMemory.hh"
34#include "AddressSpace.hh"
35#include "DataDefinition.hh"
36#include "MapTools.hh"
37#include "Conversion.hh"
38
39namespace TTAProgram {
40
41/**
42 * Sets address space of the memory.
43 *
44 * @param aSpace Address space of the memory.
45 */
47 ramSpace_(&aSpace) {
48}
49
50/**
51 * Deletes all the added definitions.
52 */
56
57
58/**
59 * Adds data to memory.
60 *
61 * Data definitions are sorted by starting address of defined area.
62 *
63 * @param dataDef Definition to add.
64 */
65void
67 dataDefs_[dataDef->startAddress().location()] = dataDef;
68 // clear index cache since indices may change
69 indexCache_.clear();
70}
71
72/**
73 * Finds the data definition, which contains the requested address.
74 *
75 * @param address Address whose data definition is requested.
76 * @return Data definition, which contains requested address.
77 */
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:" +
98}
99
100
101/**
102 * Finds the data definition by index.
103 *
104 * Indices may change if new definitions are added to memory.
105 *
106 * @param index Index of the requested data definition.
107 * @return Data definition, which contains requested address.
108 */
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}
122
123/**
124 * Returns the number of data definitions stored in memory.
125 *
126 * @return Number of data definitions.
127 */
128int
130 return dataDefs_.size();
131}
132
133
134/**
135 * Returns the place where the data definitions end. Calculates it based
136 * only on the last data definition (since dataDefs_ is sorted).
137 *
138 * @return int end of data definitions
139 */
140int
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}
153
154/**
155 * Deletes the data definition at the given index.
156 *
157 * @param index Which data definition to delete.
158 */
159void
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}
175
176/**
177 * Returns the address space of the data memory.
178 *
179 * @return The address space of the data memory.
180 */
183 return *ramSpace_;
184}
185
186/**
187 * Set new address space for the data memory.
188 *
189 * @param space New address space.
190 */
191void
193 ramSpace_ = &space;
194 for (int i = 0; i < dataDefinitionCount(); i++) {
196 def.setStartAddress(Address(def.startAddress().location(), space));
197 }
198}
199
200/**
201 * POM style copy constructor, which supports dynamic binding.
202 *
203 * @return Copy of the object.
204 */
207 DataMemory* memCopy = new DataMemory(*ramSpace_);
208
209 for (int i = 0; i < dataDefinitionCount(); i++) {
211 }
212
213 return memCopy;
214}
215
216}
#define __func__
static std::string toString(const T &source)
static void deleteAllValues(MapType &aMap)
virtual TCEString name() const
InstructionAddress location() const
virtual Address startAddress() const
virtual void setStartAddress(Address start)
virtual DataDefinition * copy() const
const TTAMachine::AddressSpace * ramSpace_
Address space of the memory.
Definition DataMemory.hh:79
void setAddressSpace(const TTAMachine::AddressSpace &space)
void addDataDefinition(DataDefinition *dataDef)
Definition DataMemory.cc:66
std::vector< DataDefinition * > indexCache_
Cache for indexing dataDefinitions.
Definition DataMemory.hh:85
DataDefinition & dataDefinition(Address address) const
Definition DataMemory.cc:79
DataMemory(const TTAMachine::AddressSpace &aSpace)
Definition DataMemory.cc:46
void deleteDataDefinition(int index)
int dataDefinitionCount() const
DataMemory * copy() const
int dataDefinitionsEnd() const
DataDefMap dataDefs_
Data definitions for the address space.
Definition DataMemory.hh:82
const TTAMachine::AddressSpace & addressSpace() const