OpenASIP  2.0
ICDecoderGeneratorPlugin.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 ICDecoderGeneratorPlugin.cc
26  *
27  * Implementation of ICDecoderGeneratorPlugin class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Vinogradov Viacheslav(added Verilog generating) 2012
31  * @note rating: red
32  */
33 
34 #include <string>
35 
37 #include "MapTools.hh"
38 
39 using std::string;
40 
41 namespace ProGe {
42 
43 /**
44  * Constructor.
45  *
46  * @param machine The machine to generate the IC&decoder for.
47  */
50  const BinaryEncoding& bem,
51  const std::string& description) :
52  machine_(machine), bem_(bem), description_(description) {
53 
54 }
55 
56 
57 /**
58  * Destructor.
59  */
61 }
62 
63 
64 /**
65  * Returns the description of the plugin.
66  *
67  * @return The description.
68  */
69 std::string
71  return description_;
72 }
73 
74 
75 /**
76  * Returns the number of recognized parameters.
77  *
78  * @return The number of recognized parameters.
79  */
80 int
82  return parameterDescriptions_.size();
83 }
84 
85 
86 /**
87  * Returns the name of a recognized parameter by the given index.
88  *
89  * @param index The index.
90  * @return The name of the parameter.
91  * @exception OutOfRange If the given index is negative or not smaller than
92  * the number of recognized parameters.
93  */
94 std::string
96  if (index < 0 || index >= recognizedParameterCount()) {
97  throw OutOfRange(__FILE__, __LINE__, __func__);
98  }
99 
100  int i = 0;
101  for (StringMap::const_iterator iter = parameterDescriptions_.begin();
102  iter != parameterDescriptions_.end(); iter++) {
103  if (i == index) {
104  return iter->first;
105  }
106  i++;
107  }
108 
109  assert(false);
110  return "";
111 }
112 
113 /**
114  * Returns the description of the given parameter.
115  *
116  * @param paramName Name of the parameter.
117  * @return The description of the parameter.
118  * @exception IllegalParameter If the given parameter is unrecognized.
119  */
120 std::string
122  const std::string& paramName) const {
123  try {
124  return MapTools::valueForKey<string>(
125  parameterDescriptions_, paramName);
126  } catch (const KeyNotFound& e) {
127  throw IllegalParameters(
128  __FILE__, __LINE__, __func__, e.errorMessage());
129  }
130 }
131 
132 /**
133  * Sets the given parameter for the plugin.
134  *
135  * @param name Name of the parameter.
136  * @param value Value of the parameter.
137  * @exception IllegalParameter If the given parameter is unrecognized.
138  */
139 void
141  const std::string& name, const std::string& value) {
143  string errorMsg = "Unrecognized IC/decoder plugin parameter: " +
144  name;
145  throw IllegalParameters(__FILE__, __LINE__, __func__, errorMsg);
146  }
147 
148  parameterValues_.erase(name);
149  parameterValues_.insert(std::pair<string, string>(name, value));
150 }
151 
152 /**
153  * Adds the given parameter to the set of recognized parameters.
154  *
155  * @param name Name of the parameter.
156  * @param description Description of the parameter.
157  */
158 void
160  const std::string& name,
161  const std::string& description) {
162 
163  parameterDescriptions_.erase(name);
164  parameterDescriptions_.insert(
165  std::pair<string, string>(name, description));
166 }
167 
168 
169 /**
170  * Tells whether the plugin has the given parameter set.
171  *
172  * @param name Name of the parameter.
173  * @return True if the given parameter is set, otherwise false.
174  */
175 bool
176 ICDecoderGeneratorPlugin::hasParameterSet(const std::string& name) const {
178 }
179 
180 
181 /**
182  * Returns the value of the given parameter.
183  *
184  * @param name Name of the parameter.
185  * @return Value of the parameter.
186  * @exception KeyNotFound If the given parameter is not set.
187  */
188 std::string
189 ICDecoderGeneratorPlugin::parameterValue(const std::string& name) const {
190  if (!hasParameterSet(name)) {
191  throw KeyNotFound(__FILE__, __LINE__, __func__);
192  }
193 
194  return MapTools::valueForKey<string>(parameterValues_, name);
195 }
196 
197 /**
198  * Returns the machine.
199  *
200  * @return The machine.
201  */
202 const TTAMachine::Machine&
204  return machine_;
205 }
206 
207 
208 /**
209  * Returns the binary encoding map.
210  *
211  * @return The binary encoding map.
212  */
213 const BinaryEncoding&
215  return bem_;
216 }
217 }
ProGe::ICDecoderGeneratorPlugin::hasParameterSet
bool hasParameterSet(const std::string &name) const
Definition: ICDecoderGeneratorPlugin.cc:176
BinaryEncoding
Definition: BinaryEncoding.hh:61
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
OutOfRange
Definition: Exception.hh:320
MapTools.hh
ProGe::ICDecoderGeneratorPlugin::bem
const BinaryEncoding & bem() const
Definition: ICDecoderGeneratorPlugin.cc:214
ProGe::ICDecoderGeneratorPlugin::machine_
const TTAMachine::Machine & machine_
The machine to generate.
Definition: ICDecoderGeneratorPlugin.hh:154
ProGe::ICDecoderGeneratorPlugin::addParameter
void addParameter(const std::string &name, const std::string &description)
Definition: ICDecoderGeneratorPlugin.cc:159
ProGe::ICDecoderGeneratorPlugin::bem_
const BinaryEncoding & bem_
The binary encoding map.
Definition: ICDecoderGeneratorPlugin.hh:156
ICDecoderGeneratorPlugin.hh
ProGe::ICDecoderGeneratorPlugin::pluginDescription
std::string pluginDescription() const
Definition: ICDecoderGeneratorPlugin.cc:70
assert
#define assert(condition)
Definition: Application.hh:86
ProGe::ICDecoderGeneratorPlugin::description_
std::string description_
Description of the plugin.
Definition: ICDecoderGeneratorPlugin.hh:162
ProGe::ICDecoderGeneratorPlugin::recognizedParameter
std::string recognizedParameter(int index) const
Definition: ICDecoderGeneratorPlugin.cc:95
IllegalParameters
Definition: Exception.hh:113
__func__
#define __func__
Definition: Application.hh:67
ProGe::ICDecoderGeneratorPlugin::setParameter
void setParameter(const std::string &name, const std::string &value)
Definition: ICDecoderGeneratorPlugin.cc:140
ProGe::ICDecoderGeneratorPlugin::ICDecoderGeneratorPlugin
ICDecoderGeneratorPlugin(const TTAMachine::Machine &machine, const BinaryEncoding &bem, const std::string &description)
Definition: ICDecoderGeneratorPlugin.cc:48
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ProGe::ICDecoderGeneratorPlugin::~ICDecoderGeneratorPlugin
virtual ~ICDecoderGeneratorPlugin()
Definition: ICDecoderGeneratorPlugin.cc:60
ProGe::ICDecoderGeneratorPlugin::parameterValue
std::string parameterValue(const std::string &name) const
Definition: ICDecoderGeneratorPlugin.cc:189
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
ProGe::ICDecoderGeneratorPlugin::parameterDescription
std::string parameterDescription(const std::string &paramName) const
Definition: ICDecoderGeneratorPlugin.cc:121
ProGe::ICDecoderGeneratorPlugin::parameterDescriptions_
StringMap parameterDescriptions_
Parameter descriptions.
Definition: ICDecoderGeneratorPlugin.hh:160
ProGe
Definition: FUGen.hh:54
ProGe::ICDecoderGeneratorPlugin::parameterValues_
StringMap parameterValues_
Parameters set.
Definition: ICDecoderGeneratorPlugin.hh:158
KeyNotFound
Definition: Exception.hh:285
ProGe::ICDecoderGeneratorPlugin::recognizedParameterCount
int recognizedParameterCount() const
Definition: ICDecoderGeneratorPlugin.cc:81
ProGe::ICDecoderGeneratorPlugin::machine
const TTAMachine::Machine & machine() const
Definition: ICDecoderGeneratorPlugin.cc:203
TTAMachine::Machine
Definition: Machine.hh:73