OpenASIP  2.0
HWBlockImplementation.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 HWBlockImplementation.cc
26  *
27  * Implementation of HWBlockImplementation 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 "HWBlockImplementation.hh"
37 #include "SequenceTools.hh"
38 #include "ContainerTools.hh"
39 
40 using std::string;
41 
42 namespace HDB {
43 
44 /**
45  * The constructor.
46  *
47  * @param moduleName Name of the module.
48  * @param clkPort Name of the clock port.
49  * @param rstPort Name of the reset port.
50  * @param glockPort Name of the global lock port.
51  */
53  const std::string& moduleName,
54  const std::string& clkPort,
55  const std::string& rstPort,
56  const std::string& glockPort) :
57  moduleName_(moduleName), clkPort_(clkPort), rstPort_(rstPort),
58  glockPort_(glockPort) {
59 }
60 
61 /**
62  * Copy constructor.
63  *
64  * @param original HWBlock to copy.
65  */
67  const HWBlockImplementation& original) {
68 
69  moduleName_ = original.moduleName();
70  clkPort_ = original.clkPort();
71  rstPort_ = original.rstPort();
72  glockPort_ = original.glockPort();
73  hasID_ = original.hasID();
74 
75  if (original.hasID()) {
76  id_ = original.id();
77  } else {
78  id_ = -1;
79  }
80 
81  // Deep copy implementation file list.
82  for (int i = 0; i < original.implementationFileCount(); i++) {
83  BlockImplementationFile* newFile =
84  new BlockImplementationFile(original.file(i));
85 
86  addImplementationFile(newFile);
87  }
88 }
89 
90 
91 /**
92  * The destructor.
93  */
96 }
97 
98 
99 /**
100  * Tells whether the implementation has an ID.
101  *
102  * @return True if the entry has an ID, otherwise false.
103  */
104 bool
106  return hasID_;
107 }
108 
109 
110 /**
111  * Sets the ID for the implementation.
112  *
113  * @param id The ID to set.
114  */
115 void
117  hasID_ = true;
118  id_ = id;
119 }
120 
121 
122 /**
123  * Returns the ID of the implementation.
124  *
125  * @return ID of the implementation.
126  */
127 RowID
129  if (!hasID()) {
130  throw NotAvailable(__FILE__, __LINE__, __func__);
131  } else {
132  return id_;
133  }
134 }
135 
136 /**
137  * Sets the module name.
138  *
139  * @param name Name of the module.
140  */
141 void
142 HWBlockImplementation::setModuleName(const std::string& name) {
143  moduleName_ = name;
144 }
145 
146 
147 /**
148  * Returns the name of the module.
149  *
150  * @return The name of the module.
151  */
152 std::string
154  return moduleName_;
155 }
156 
157 
158 /**
159  * Sets the name of the clock port.
160  *
161  * @param name Name of the port.
162  */
163 void
164 HWBlockImplementation::setClkPort(const std::string& name) {
165  clkPort_ = name;
166 }
167 
168 
169 /**
170  * Returns the name of the clock signal port.
171  *
172  * @return The name of the port.
173  */
174 std::string
176  return clkPort_;
177 }
178 
179 
180 /**
181  * Sets the name of the reset port.
182  *
183  * @param name Name of the port.
184  */
185 void
186 HWBlockImplementation::setRstPort(const std::string& name) {
187  rstPort_ = name;
188 }
189 
190 
191 /**
192  * Returns the name of the reset port.
193  *
194  * @return The name of the port.
195  */
196 std::string
198  return rstPort_;
199 }
200 
201 
202 /**
203  * Sets the name of the global lock port.
204  *
205  * @param name Name of the port.
206  */
207 void
208 HWBlockImplementation::setGlockPort(const std::string& name) {
209  glockPort_ = name;
210 }
211 
212 
213 /**
214  * Returns the name of the global lock port.
215  *
216  * @return The name of the port.
217  */
218 std::string
220  return glockPort_;
221 }
222 
223 
224 /**
225  * Adds a new implementation file for the block implementation.
226  *
227  * @param file The file to add.
228  */
229 void
231  files_.push_back(file);
232 }
233 
234 
235 /**
236  * Removes the given block implementation file from the implementation.
237  *
238  * @param file The file to remove.
239  */
240 void
242  const BlockImplementationFile& file) {
244 }
245 
246 
247 /**
248  * Returns the number of files which constitutes the implementation of the
249  * block.
250  *
251  * @return The number of files.
252  */
253 int
255  return files_.size();
256 }
257 
258 
259 /**
260  * Returns a block implementation file by the given index.
261  *
262  * @param index The index.
263  * @exception OutOfRange If the index is negative or not smaller than the
264  * number of files.
265  */
267 HWBlockImplementation::file(int index) const {
268  if (index < 0 || index >= implementationFileCount()) {
269  const string procName = "HWBlockImplementation::file";
270  throw OutOfRange(__FILE__, __LINE__, procName);
271  }
272 
273  return *files_[index];
274 }
275 }
HDB::HWBlockImplementation::rstPort_
std::string rstPort_
Name of the reset port.
Definition: HWBlockImplementation.hh:89
HDB::HWBlockImplementation::clkPort
std::string clkPort() const
Definition: HWBlockImplementation.cc:175
HDB::HWBlockImplementation::moduleName_
std::string moduleName_
Name of the module.
Definition: HWBlockImplementation.hh:85
HDB::HWBlockImplementation::file
BlockImplementationFile & file(int index) const
Definition: HWBlockImplementation.cc:267
HDB
Definition: CostDatabase.hh:49
HDB::HWBlockImplementation::HWBlockImplementation
HWBlockImplementation(const std::string &moduleName, const std::string &clkPort, const std::string &rstPort, const std::string &glockPort)
Definition: HWBlockImplementation.cc:52
HDB::HWBlockImplementation::~HWBlockImplementation
virtual ~HWBlockImplementation()
Definition: HWBlockImplementation.cc:94
OutOfRange
Definition: Exception.hh:320
SequenceTools.hh
HDB::HWBlockImplementation::implementationFileCount
int implementationFileCount() const
Definition: HWBlockImplementation.cc:254
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
HDB::HWBlockImplementation::setClkPort
void setClkPort(const std::string &name)
Definition: HWBlockImplementation.cc:164
HDB::HWBlockImplementation::files_
FileTable files_
Contains the block implementation files.
Definition: HWBlockImplementation.hh:93
HDB::HWBlockImplementation::setGlockPort
void setGlockPort(const std::string &name)
Definition: HWBlockImplementation.cc:208
HDB::BlockImplementationFile
Definition: BlockImplementationFile.hh:44
NotAvailable
Definition: Exception.hh:728
HDB::HWBlockImplementation::hasID_
bool hasID_
Tells whether the implementation has an ID.
Definition: HWBlockImplementation.hh:95
HDB::HWBlockImplementation::rstPort
std::string rstPort() const
Definition: HWBlockImplementation.cc:197
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
HDB::HWBlockImplementation::addImplementationFile
void addImplementationFile(BlockImplementationFile *file)
Definition: HWBlockImplementation.cc:230
ContainerTools::removeValueIfExists
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)
HDB::HWBlockImplementation::id_
RowID id_
ID of the implementation.
Definition: HWBlockImplementation.hh:98
__func__
#define __func__
Definition: Application.hh:67
HDB::HWBlockImplementation::clkPort_
std::string clkPort_
Name of the clock port.
Definition: HWBlockImplementation.hh:87
HDB::HWBlockImplementation::setModuleName
void setModuleName(const std::string &name)
Definition: HWBlockImplementation.cc:142
HDB::HWBlockImplementation
Definition: HWBlockImplementation.hh:49
HDB::HWBlockImplementation::glockPort_
std::string glockPort_
Name of the global lock port.
Definition: HWBlockImplementation.hh:91
HDB::HWBlockImplementation::setID
void setID(RowID id)
Definition: HWBlockImplementation.cc:116
HDB::HWBlockImplementation::id
RowID id() const
Definition: HWBlockImplementation.cc:128
BlockImplementationFile.hh
HDB::HWBlockImplementation::moduleName
std::string moduleName() const
Definition: HWBlockImplementation.cc:153
HDB::HWBlockImplementation::setRstPort
void setRstPort(const std::string &name)
Definition: HWBlockImplementation.cc:186
HDB::HWBlockImplementation::glockPort
std::string glockPort() const
Definition: HWBlockImplementation.cc:219
HDB::HWBlockImplementation::removeImplementationFile
void removeImplementationFile(const BlockImplementationFile &file)
Definition: HWBlockImplementation.cc:241
HDB::HWBlockImplementation::hasID
bool hasID() const
Definition: HWBlockImplementation.cc:105
HWBlockImplementation.hh
ContainerTools.hh