OpenASIP 2.2
Loading...
Searching...
No Matches
OperationContainer.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2011 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 OperationContainer.cc
26 *
27 * Definition of OperationContainer class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2011
31 * @note rating: red
32 */
33
34#include <vector>
35
36#include "OperationContainer.hh"
37#include "OperationIndex.hh"
39#include "Operation.hh"
40#include "OperationIndex.hh"
43#include "Application.hh"
44#include "PluginTools.hh"
45#include "StringTools.hh"
46#include "Environment.hh"
47#include "OperationModule.hh"
48#include "OperationBehavior.hh"
49#include "IdealSRAM.hh"
50#include "SimValue.hh"
51#include "TCEString.hh"
52#include "ObjectState.hh"
53
54using std::string;
55using std::vector;
56
57const string OperationContainer::CREATE_FUNCTION = "createOpBehavior_";
58const string OperationContainer::DELETE_FUNCTION = "deleteOpBehavior_";
60const Word OperationContainer::MEMORY_END = 65535;
61const Word OperationContainer::MAUSIZE = 8;
62
68
69// TODO: endianess
71 new IdealSRAM(MEMORY_START, MEMORY_END, MAUSIZE, false);
72
74 memory_, programCounter_, returnAddress_, 0);
75
76/**
77 * Constructor.
78 */
81
82/**
83 * Destructor.
84 */
87
88/**
89 * Returns the instance of OperationIndex.
90 *
91 * @return The instance of OperationIndex.
92 */
95 if (index_ == NULL) {
96 index_ = new OperationIndex();
97 vector<string> paths = Environment::osalPaths();
98 for (size_t i = 0; i < paths.size(); i++) {
99 index_->addPath(paths[i]);
100 }
101 }
102 return *index_;
103}
104
105/**
106 * Returns the instance of OperationSerializer.
107 *
108 * @return The instance of OperationSerializer.
109 */
112 if (serializer_ == NULL) {
114 }
115 return *serializer_;
116}
117
118/**
119 * Returns the instance of OperationContext.
120 *
121 * @return Instance of OperationContext.
122 */
127
128/**
129 * Returns the memory model instance.
130 *
131 * @return Memory model instance.
132 */
133Memory&
137
138/**
139 * Returns a certain module in a certain path.
140 *
141 * If module is not found, a NullOperationModule is returned.
142 *
143 * @param path The name of the path.
144 * @param mod The name of the module.
145 * @return The module or NullOperationModule.
146 */
148OperationContainer::module(const std::string& path, const std::string& mod) {
150 try {
151 for (int i = 0; i < index.moduleCount(path); i++) {
152 if (index.module(i, path).name() == mod) {
153 return index.module(i, path);
154 }
155 }
156 } catch (const Exception& e) {
158 }
160}
161
162/**
163 * Returns a certain operation in a certain module and a path.
164 *
165 * If operation is not found, NULL is returned.
166 *
167 * @param path The name of the path.
168 * @param mod The name of the module.
169 * @param oper The name of the operation.
170 * @return The operation.
171 */
174 const std::string& path,
175 const std::string& mod,
176 const std::string& oper) {
177
178 OperationModule& opModule = module(path, mod);
179 assert(&opModule != &NullOperationModule::instance());
180
182 serializer.setSourceFile(opModule.propertiesModule());
183 try {
184 ObjectState* root = serializer.readState();
185 for (int i = 0; i < root->childCount(); i++) {
186 if (root->child(i)->stringAttribute("name") == oper) {
187
188 OperationIndex* index = new OperationIndex;
189 index->addPath(path);
190
191 Operation* op =
193 op->loadState(root->child(i));
194
195 OperationBehaviorLoader* behaviorLoader =
196 new OperationBehaviorLoader(*index);
197 OperationBehaviorProxy* behaviorProxy =
198 new OperationBehaviorProxy(*op, *behaviorLoader, true);
199
200 op->setBehavior(*behaviorProxy);
201
202 delete root;
203 return op;
204 }
205 }
206 } catch (const Exception& e) {
207 return NULL;
208 }
209 return NULL;
210}
211
212/**
213 * Returns true if operation exists.
214 *
215 * @param name The name of the operation.
216 * @return True if operation exists, false otherwise.
217 */
218bool
219OperationContainer::operationExists(const std::string& name) {
220
222
223 for (int i = 0; i < index.moduleCount(); i++) {
224 OperationModule& mod = index.module(i);
225 for (int j = 0; j < index.operationCount(mod); j++) {
226 if (index.operationName(j, mod) == name) {
227 return true;
228 }
229 }
230 }
231 return false;
232}
233
234/**
235 * Returns true if operation is effective.
236 *
237 * Effective means that is is found first in list of search paths.
238 *
239 * @param module The module in which operation is defined.
240 * @param name The name of the operation.
241 * @return True if operation is effective.
242 */
243bool
245 OperationModule& module,
246 const std::string& name) {
247
248 try {
250 for (int i = 0; i < index.pathCount(); i++) {
251 string path = index.path(i);
252 for (int j = 0; j < index.moduleCount(path); j++) {
253 OperationModule& mod = index.module(j, path);
254 for (int k = 0; k < index.operationCount(mod); k++) {
255 string opName = index.operationName(k, mod);
256 if (opName == name) {
257 if (&module == &mod) {
258 return true;
259 } else {
260 return false;
261 }
262 }
263 }
264 }
265 }
266 } catch (const Exception& e) {
267 return false;
268 }
269 // never should come here
270 assert(false);
271 return false;
272}
273
274/**
275 * This function is called to clean up the static objects.
276 *
277 * This function should be called only when application is closed.
278 */
279void
281
282 if (index_ != NULL) {
283 delete index_;
284 index_ = NULL;
285 }
286
287 if (serializer_ != NULL) {
288 delete serializer_;
289 serializer_ = NULL;
290 }
291
292 if (memory_ != NULL) {
293 delete memory_;
294 memory_ = NULL;
295 }
296}
297
298/**
299 * Returns the start point of the memory.
300 *
301 * @return Memory start point.
302 */
303Word
307
308/**
309 * Returns the end point of the memory.
310 *
311 * @return Memory end point.
312 */
313Word
#define assert(condition)
UInt32 InstructionAddress
Definition BaseType.hh:175
static std::vector< std::string > osalPaths()
static NullOperationBehavior & instance()
static NullOperationModule & instance()
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
int childCount() const
static const Word MEMORY_START
Starting point of the memory.
static IdealSRAM * memory_
Memory used througout the execution of the program.
static bool operationExists(const std::string &name)
static PluginTools tools_
PluginTools used by OperationContainer;.
static Memory & memory()
static OperationSerializer & operationSerializer()
static bool isEffective(OperationModule &module, const std::string &name)
static OperationContext & operationContext()
static OperationModule & module(const std::string &path, const std::string &mod)
static OperationContext context_
Operation context used through the execution of the program.
static Operation * operation(const std::string &path, const std::string &module, const std::string &oper)
static OperationIndex & operationIndex()
static OperationIndex * index_
Contains information of operations.
static const std::string DELETE_FUNCTION
Operation behavior deletion function name.
static InstructionAddress programCounter_
Program counter.
static const std::string CREATE_FUNCTION
Creation function name for operation behavior.
static OperationSerializer * serializer_
Static instance of operation serializer.
static const Word MEMORY_END
End point of the memory.
static SimValue returnAddress_
Return address.
static const Word MAUSIZE
MAU size of the memory.
std::string operationName(int i, const OperationModule &om)
OperationModule & module(int i)
std::string path(int i) const
void addPath(const std::string &path)
int operationCount(const OperationModule &om)
int pathCount() const
int moduleCount() const
virtual std::string name() const
virtual std::string propertiesModule() const
void setSourceFile(const std::string &filename)
virtual ObjectState * readState()
virtual void setBehavior(OperationBehavior &behavior)
Definition Operation.cc:378
virtual void loadState(const ObjectState *state)
Definition Operation.cc:480