OpenASIP  2.0
RFImplementation.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 RFImplementation.cc
26  *
27  * Implementation of RFImplementation class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "RFImplementation.hh"
36 #include "RFEntry.hh"
37 #include "RFExternalPort.hh"
38 #include "RFPortImplementation.hh"
40 #include "SequenceTools.hh"
41 #include "ContainerTools.hh"
42 
43 using std::string;
44 
45 namespace HDB {
46 
47 /**
48  * The constructor.
49  *
50  * @param moduleName Name of the module.
51  * @param clkPort Name of the clock port.
52  * @param rstPort Name of the reset port.
53  * @param glockPort Name of the global lock port.
54  * @param sizeParam Name of the parameter that defines the size of the
55  * register file.
56  * @param widthParam Name of the parameter that defines the width of the
57  * register file.
58  * @param guardPort Name of the guard port.
59  * @param sacParam Flag for separate address cycle. Default value is false.
60  */
62  const std::string& moduleName,
63  const std::string& clkPort,
64  const std::string& rstPort,
65  const std::string& glockPort,
66  const std::string& sizeParam,
67  const std::string& widthParam,
68  const std::string& guardPort,
69  bool sacParam) :
70  HWBlockImplementation(moduleName, clkPort, rstPort, glockPort),
71  sizeParam_(sizeParam), widthParam_(widthParam), guardPort_(guardPort),
72  sepAddrCycleParam_(sacParam) {
73 }
74 
75 
76 /**
77  * Copy constructor.
78  *
79  * @param original RFImplementation to copy.
80  */
82  HWBlockImplementation(original) {
83 
84  sizeParam_ = original.sizeParam_;
85  widthParam_ = original.widthParam_;
86  guardPort_ = original.guardPort_;
88 
89  // Deep copy ports.
90  for (int i = 0; i < original.portCount(); i++) {
91  RFPortImplementation* p = new RFPortImplementation(original.port(i));
92  addPort(p);
93  }
94 
95  // Copy parameters.
96  parameters_ = original.parameters_;
97 
98  // Deep copy external ports.
99  for (int i = 0; i < original.externalPortCount(); i++) {
100  RFExternalPort* p = new RFExternalPort(original.externalPort(i));
101  addExternalPort(p);
102  }
103 
104 }
105 
106 
107 /**
108  * The destructor.
109  */
113 }
114 
115 /**
116  * Sets the name of the size parameter.
117  *
118  * @param sizeParam Name of the size parameter.
119  */
120 void
121 RFImplementation::setSizeParameter(const std::string& sizeParam) {
122  sizeParam_ = sizeParam;
123 }
124 
125 
126 /**
127  * Returns the name of the size parameter.
128  *
129  * @return The name of the size parameter.
130  */
131 std::string
133  return sizeParam_;
134 }
135 
136 
137 /**
138  * Sets the name of the width parameter.
139  *
140  * @param widthParam Name of the width parameter.
141  */
142 void
143 RFImplementation::setWidthParameter(const std::string& widthParam) {
144  widthParam_ = widthParam;
145 }
146 
147 
148 /**
149  * Returns the name of the width parameter.
150  *
151  * @return The name of the width parameter.
152  */
153 std::string
155  return widthParam_;
156 }
157 
158 
159 /**
160  * Sets the name of the guard port.
161  *
162  * @param guardPort Name of the guard port.
163  */
164 void
165 RFImplementation::setGuardPort(const std::string& guardPort) {
167 }
168 
169 
170 /**
171  * Returns the name of the guard port.
172  *
173  * @return The name of the guard port.
174  */
175 std::string
177  return guardPort_;
178 }
179 
180 /**
181  * Sets flag for separate address cycle.
182  *
183  * @param enable Flag value.
184  */
186  sepAddrCycleParam_ = enable;
187 }
188 
189 /**
190  * Returns flag for separate address cycle.
191  *
192  * @return The flag value. True if enabled.
193  */
195  return sepAddrCycleParam_;
196 }
197 
198 /**
199  * Adds a new port to the RF implementation.
200  *
201  * @param port The port to be added.
202  */
203 void
205  ports_.push_back(port);
206 }
207 
208 /**
209  * Adds a new external port to the RF implementation.
210  *
211  * @param extPort The external port to be added.
212  */
213 void
215  externalPorts_.push_back(extPort);
216 }
217 
218 
219 /**
220  * Deletes the given port from the RF implementation.
221  *
222  * @param port The port to delete.
223  * @exception InstanceNotFound If the given port is not in this RF
224  * implementation.
225  */
226 void
229  if (!deleted) {
230  throw InstanceNotFound(__FILE__, __LINE__, __func__);
231  }
232 }
233 
234 /**
235  * Deletes the given external port.
236  *
237  * @param port The port to delete.
238  * @exception InstanceNotFound If the given port is not in this RF
239  * implementation.
240  */
241 void
244  if (!removed) {
245  throw InstanceNotFound(__FILE__, __LINE__, __func__);
246  }
247 }
248 
249 /**
250  * Returns the number of ports.
251  *
252  * @return The number of ports.
253  */
254 int
256  return ports_.size();
257 }
258 
259 
260 /**
261  * Returns the number of external ports.
262  *
263  * @return The number of external ports.
264  */
265 int
267  return externalPorts_.size();
268 
269 }
270 
271 
272 /**
273  * Returns the port at the given position.
274  *
275  * @param index The position index.
276  * @return The port.
277  * @exception OutOfRange If the index is negative or not smaller than the
278  * number of ports.
279  */
281 RFImplementation::port(int index) const {
282  if (index < 0 || index >= portCount()) {
283  const string procName = "RFImplementation::port";
284  throw OutOfRange(__FILE__, __LINE__, procName);
285  }
286 
287  return *ports_[index];
288 }
289 
290 /**
291  * Returns the external port at the given position.
292  *
293  * @param index The position index.
294  * @return The port.
295  * @exception OutOfRange If the given index is negative or not smaller the
296  * number of external ports.
297  */
300  if (index < 0 || index >= externalPortCount()) {
301  const string procName = "RFImplementation::externalPort";
302  throw OutOfRange(__FILE__, __LINE__, procName);
303  }
304 
305  return *externalPorts_[index];
306 }
307 
308 /**
309  * Adds the given parameter for the implementation.
310  *
311  * @param name Name of the parameter.
312  * @param type Type of the parameter.
313  * @param value Value of the parameter.
314  * @exception IllegalParameters If the RF implementation contains a
315  * parameter with the same name already.
316  */
317 void
319  const std::string& name, const std::string& type,
320  const std::string& value) {
321  if (hasParameter(name)) {
322  throw IllegalParameters(__FILE__, __LINE__, __func__);
323  } else {
324  Parameter param = {name, type, value};
325  parameters_.push_back(param);
326  }
327 }
328 
329 /**
330  * Removes the parameter of the given name.
331  *
332  * @param name Name of the parameter.
333  */
334 void
335 RFImplementation::removeParameter(const std::string& name) {
336  for (ParameterTable::iterator iter = parameters_.begin();
337  iter != parameters_.end(); iter++) {
338  if (iter->name == name) {
339  parameters_.erase(iter);
340  return;
341  }
342  }
343 }
344 
345 
346 /**
347  * Returns the number of parameters.
348  *
349  * @return The number of parameters.
350  */
351 int
353  return parameters_.size();
354 }
355 
356 
357 /**
358  * Returns a parameter by the given index.
359  *
360  * @param index The index.
361  * @return The parameter.
362  * @exception OutOfRange If the index is negative or not smaller than the
363  * number of parameters.
364  */
366 RFImplementation::parameter(int index) const {
367  if (index < 0 || index >= parameterCount()) {
368  throw OutOfRange(__FILE__, __LINE__, __func__);
369  }
370 
371  return parameters_[index];
372 }
373 
374 /**
375  * Tells whether the implementation has the given parameter.
376  *
377  * @param name Name of the parameter.
378  * @return True if the implementation has the parameter, otherwise false.
379  */
380 bool
381 RFImplementation::hasParameter(const std::string& name) const {
382  for (ParameterTable::const_iterator iter = parameters_.begin();
383  iter != parameters_.end(); iter++) {
384  if (iter->name == name) {
385  return true;
386  }
387  }
388  return false;
389 }
390 
391 }
392 
393 
394 
HDB::RFImplementation::setWidthParameter
void setWidthParameter(const std::string &widthParam)
Definition: RFImplementation.cc:143
HDB::RFImplementation::removeParameter
void removeParameter(const std::string &name)
Definition: RFImplementation.cc:335
HDB::RFImplementation::deleteExternalPort
void deleteExternalPort(RFExternalPort *port)
Definition: RFImplementation.cc:242
HDB
Definition: CostDatabase.hh:49
HDB::RFImplementation::setSeparateAddressCycleParameter
void setSeparateAddressCycleParameter(bool enable)
Definition: RFImplementation.cc:185
OutOfRange
Definition: Exception.hh:320
SequenceTools.hh
HDB::RFImplementation::parameterCount
int parameterCount() const
Definition: RFImplementation.cc:352
HDB::RFImplementation::widthParameter
std::string widthParameter() const
Definition: RFImplementation.cc:154
HDB::RFImplementation::sizeParam_
std::string sizeParam_
Name of the size parameter.
Definition: RFImplementation.hh:106
HDB::RFImplementation::parameters_
ParameterTable parameters_
Contains the parameters.
Definition: RFImplementation.hh:119
HDB::RFImplementation::externalPorts_
ExternalPortTable externalPorts_
Contains the external ports.
Definition: RFImplementation.hh:117
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
HDB::RFImplementation::hasParameter
bool hasParameter(const std::string &name) const
Definition: RFImplementation.cc:381
HDB::RFExternalPort
Definition: RFExternalPort.hh:41
HDB::RFImplementation::externalPort
RFExternalPort & externalPort(int index) const
Definition: RFImplementation.cc:299
HDB::RFImplementation
Definition: RFImplementation.hh:50
IllegalParameters
Definition: Exception.hh:113
HDB::RFImplementation::sizeParameter
std::string sizeParameter() const
Definition: RFImplementation.cc:132
HDB::RFImplementation::setGuardPort
void setGuardPort(const std::string &guardPort)
Definition: RFImplementation.cc:165
RFImplementation.hh
HDB::RFImplementation::widthParam_
std::string widthParam_
Name of the width parameter.
Definition: RFImplementation.hh:108
HDB::RFImplementation::~RFImplementation
virtual ~RFImplementation()
Definition: RFImplementation.cc:110
__func__
#define __func__
Definition: Application.hh:67
RFPortImplementation.hh
HDB::RFImplementation::addExternalPort
void addExternalPort(RFExternalPort *extPort)
Definition: RFImplementation.cc:214
HDB::RFImplementation::setSizeParameter
void setSizeParameter(const std::string &sizeParam)
Definition: RFImplementation.cc:121
HDB::HWBlockImplementation
Definition: HWBlockImplementation.hh:49
HDB::RFImplementation::port
RFPortImplementation & port(int index) const
Definition: RFImplementation.cc:281
HDB::RFPortImplementation
Definition: RFPortImplementation.hh:43
HDB::RFImplementation::ports_
PortTable ports_
Contains the ports.
Definition: RFImplementation.hh:115
HDB::RFImplementation::guardPort_
std::string guardPort_
Name of the guard port.
Definition: RFImplementation.hh:110
BlockImplementationFile.hh
HDB::RFImplementation::guardPort
std::string guardPort() const
Definition: RFImplementation.cc:176
HDB::RFImplementation::portCount
int portCount() const
Definition: RFImplementation.cc:255
HDB::RFImplementation::sepAddrCycleParam_
bool sepAddrCycleParam_
State of separate address cycle parameter.
Definition: RFImplementation.hh:112
HDB::RFImplementation::deletePort
void deletePort(RFPortImplementation *port)
Definition: RFImplementation.cc:227
HDB::RFImplementation::parameter
Parameter parameter(int index) const
Definition: RFImplementation.cc:366
RFEntry.hh
HDB::Parameter
Definition: HDBTypes.hh:46
HDB::RFImplementation::RFImplementation
RFImplementation(const std::string &moduleName, const std::string &clkPort, const std::string &rstPort, const std::string &glockPort, const std::string &sizeParam, const std::string &widthParam, const std::string &guardPort, bool sacParam=false)
Definition: RFImplementation.cc:61
HDB::RFImplementation::externalPortCount
int externalPortCount() const
Definition: RFImplementation.cc:266
HDB::RFImplementation::addParameter
void addParameter(const std::string &name, const std::string &type, const std::string &value)
Definition: RFImplementation.cc:318
HDB::RFImplementation::separateAddressCycleParameter
bool separateAddressCycleParameter() const
Definition: RFImplementation.cc:194
RFExternalPort.hh
InstanceNotFound
Definition: Exception.hh:304
ContainerTools::deleteValueIfExists
static bool deleteValueIfExists(ContainerType &aContainer, const ElementType &aKey)
HDB::RFImplementation::addPort
void addPort(RFPortImplementation *port)
Definition: RFImplementation.cc:204
ContainerTools.hh