OpenASIP  2.0
PIGCmdLineOptions.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 PIGCmdLineOptions.cc
26  *
27  * Implementation of PIGCmdLineOptions class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Otto Esko 2008 (otto.esko-no.spam-tut.fi)
31  * @author Pekka Jääskeläinen 2011
32  * @note rating: red
33  */
34 
35 #include <iostream>
36 
37 #include "PIGCmdLineOptions.hh"
38 #include "PIGCLITextGenerator.hh"
39 
40 using std::string;
41 
42 const std::string PIGCmdLineOptions::BEM_PARAM_NAME = "bem";
43 const std::string PIGCmdLineOptions::TPEF_PARAM_NAME = "program";
44 const std::string PIGCmdLineOptions::PI_FORMAT_PARAM_NAME = "piformat";
45 const std::string PIGCmdLineOptions::DI_FORMAT_PARAM_NAME = "diformat";
46 const std::string PIGCmdLineOptions::COMPRESSOR_PARAM_NAME = "compressor";
47 const std::string PIGCmdLineOptions::DATA_IMG_PARAM_NAME = "dataimages";
48 const std::string PIGCmdLineOptions::GEN_DECOMP_PARAM_NAME = "decompressor";
50  "dmemwidthinmaus";
52  "compressor param";
54  "showcompressors";
55 const std::string PIGCmdLineOptions::HDL_OUTPUT_DIR = "hdl-dir";
56 const string ENTITY_NAME = "entity-name";
57 
58 /**
59  * The constructor.
60  */
62 
65  TPEF_PARAM_NAME, "The TPEF program file(s)", "p");
67 
69  BEM_PARAM_NAME, "The BEM file", "b");
71 
74  "The output format of program image(s) ('ascii', 'array', 'mif', "
75  "'coe', 'vhdl', 'hex', 'binary' or 'bin2n'). Default is 'ascii'.",
76  "f");
77  addOption(piOutputMode);
78 
80  DI_FORMAT_PARAM_NAME, "The output format of data image(s) "
81  "('ascii', 'array', 'mif', 'coe', 'vhdl', 'hex', 'bin2n' or 'binary'). Default "
82  "is 'ascii'.", "o");
83  addOption(diOutputMode);
84 
86  COMPRESSOR_PARAM_NAME, "Name of the code compressor plugin file.",
87  "c");
88  addOption(pluginFile);
89 
90  BoolCmdLineOptionParser* createDataImages = new BoolCmdLineOptionParser(
92  "Create data images.",
93  "d");
94  addOption(createDataImages);
95 
96  BoolCmdLineOptionParser* createDecompressor =
98  GEN_DECOMP_PARAM_NAME, "Generate decompressor block.", "g");
99  addOption(createDecompressor);
100 
101  IntegerCmdLineOptionParser* dmemMAUsPerLine =
104  "Width of data memory in MAUs. Default is 1.", "w");
105  addOption(dmemMAUsPerLine);
106 
107  StringListCmdLineOptionParser* compressorParams =
110  "Parameter to the code compressor in form 'name=value'.", "u");
111  addOption(compressorParams);
112 
114  SHOW_COMPRESSORS_PARAM_NAME, "Show compressor plugin descriptions.",
115  "s");
117 
118  string hdlDirDesc("Directory root where ProGe generated HDL files. "
119  "Generatebits will write imem_mau_pkg and "
120  "decompressor, if it is needed, under the given "
121  "directory. Otherwise they are written to cwd.");
122 
124  HDL_OUTPUT_DIR, hdlDirDesc, "x");
125  addOption(hdlDir);
126 
129  ENTITY_NAME,
130  "String to use to make the generated VHDL entities unique. This "
131  "should be the same which was given to ProGe when the processor "
132  "was generated (default is 'tta0').", "e");
134 }
135 
136 
137 /**
138  * The destructor.
139  */
141 }
142 
143 
144 /**
145  * Returns the name of the BEM file given as command line parameter.
146  *
147  * @return The name of the BEM file.
148  */
149 std::string
151  return findOption(BEM_PARAM_NAME)->String();
152 }
153 
154 
155 /**
156  * Returns the number of TPEF files given.
157  *
158  * @return The number of TPEF files.
159  */
160 int
163 }
164 
165 
166 /**
167  * Returns the name of the TPEF file given as command line parameter.
168  *
169  * @return The name of the TPEF file.
170  */
171 std::string
172 PIGCmdLineOptions::tpefFile(int index) const {
174  if (index < 0 || index >= tpefFileCount()) {
175  throw OutOfRange(__FILE__, __LINE__, __func__);
176  }
177 
178  return option->String(index + 1);
179 }
180 
181 /**
182  * Returns the program image output format given as command line parameter.
183  *
184  * @return The output format.
185  */
186 std::string
189 }
190 
191 
192 /**
193  * Returns the data image output format given as command line parameter.
194  *
195  * @return The output format.
196  */
197 std::string
200 }
201 
202 
203 /**
204  * Returns the code compressor plugin file name.
205  *
206  * @return The plugin file.
207  */
208 std::string
211 }
212 
213 
214 /**
215  * Returns the given width of data memory in MAUs.
216  *
217  * @return The width.
218  */
219 int
223  if (option->isDefined()) {
224  return option->integer();
225  } else {
226  return 1;
227  }
228 }
229 
230 
231 /**
232  * Tells whether to create data images or not.
233  */
234 bool
237 }
238 
239 
240 /**
241  * Tells whether to generate decompressor block or not.
242  */
243 bool
246 }
247 
248 
249 /**
250  * Returns the number of parameters given to compressor.
251  *
252  * @return The number of parameters.
253  */
254 int
257 }
258 
259 
260 /**
261  * By the given index, returns a parameter given to code compressor.
262  *
263  * @param index The index.
264  * @exception OutOfRange If the given index is negative or not smaller than
265  * the number of parameters given to compressor.
266  */
267 std::string
269  if (index < 0 || index >= compressorParameterCount()) {
270  throw OutOfRange(__FILE__, __LINE__, __func__);
271  }
272 
273  return findOption(COMPRESSOR_PARAMS_PARAM_NAME)->String(index + 1);
274 }
275 
276 /**
277  * Tells whether to show code compressor descriptions or not.
278  */
279 bool
282 }
283 
284 /**
285  * Returns the proge output directory. Empty if not given
286  *
287  * @return proge output directory
288  */
289 std::string
291  return findOption(HDL_OUTPUT_DIR)->String();
292 }
293 
294 std::string
296  return findOption(ENTITY_NAME)->String();
297 }
298 
299 
300 /**
301  * Prints the version of the user interface.
302  */
303 void
305  PIGCLITextGenerator textGenerator;
306  std::cerr <<
307  textGenerator.text(PIGCLITextGenerator::TXT_CLI_TITLE).str()
308  << " "
309  << textGenerator.text(PIGCLITextGenerator::TXT_CLI_VERSION).
310  str() << std::endl;
311 }
312 
313 
314 /**
315  * Prints the help menu of the program.
316  */
317 void
319  printVersion();
320  printUsage();
322 }
323 
324 
325 /**
326  * Prints the usage of the CLI.
327  */
328 void
330  PIGCLITextGenerator textGen;
331  std::cerr << textGen.text(PIGCLITextGenerator::TXT_CLI_USAGE).str()
332  << std::endl;
333 }
PIGCmdLineOptions::dataImageOutputFormat
std::string dataImageOutputFormat() const
Definition: PIGCmdLineOptions.cc:198
PIGCmdLineOptions::bemFile
std::string bemFile() const
Definition: PIGCmdLineOptions.cc:150
PIGCmdLineOptions::COMPRESSOR_PARAM_NAME
static const std::string COMPRESSOR_PARAM_NAME
Long name of the plugin file parameter.
Definition: PIGCmdLineOptions.hh:75
PIGCmdLineOptions::programImageOutputFormat
std::string programImageOutputFormat() const
Definition: PIGCmdLineOptions.cc:187
PIGCmdLineOptions::showCompressors
bool showCompressors() const
Definition: PIGCmdLineOptions.cc:280
PIGCmdLineOptions::generateDataImages
bool generateDataImages() const
Definition: PIGCmdLineOptions.cc:235
CmdLineOptionParser::isDefined
bool isDefined()
Definition: CmdLineOptionParser.cc:169
PIGCmdLineOptions::GEN_DECOMP_PARAM_NAME
static const std::string GEN_DECOMP_PARAM_NAME
Long name of the parameter that tells whether to generate decompressor or not.
Definition: PIGCmdLineOptions.hh:81
OutOfRange
Definition: Exception.hh:320
PIGCmdLineOptions::dataMemoryWidthInMAUs
int dataMemoryWidthInMAUs() const
Definition: PIGCmdLineOptions.cc:220
PIGCmdLineOptions::printHelp
virtual void printHelp() const
Definition: PIGCmdLineOptions.cc:318
PIGCmdLineOptions::HDL_OUTPUT_DIR
static const std::string HDL_OUTPUT_DIR
Long name of the parameter which tells the proge-output dir.
Definition: PIGCmdLineOptions.hh:91
PIGCLITextGenerator::TXT_CLI_TITLE
@ TXT_CLI_TITLE
Definition: PIGCLITextGenerator.hh:48
PIGCLITextGenerator.hh
PIGCmdLineOptions::compressorParameterCount
int compressorParameterCount() const
Definition: PIGCmdLineOptions.cc:255
PIGCmdLineOptions::TPEF_PARAM_NAME
static const std::string TPEF_PARAM_NAME
Long name of the TPEF file parameter.
Definition: PIGCmdLineOptions.hh:69
PIGCmdLineOptions::compressorParameter
std::string compressorParameter(int index) const
Definition: PIGCmdLineOptions.cc:268
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
CmdLineOptionParser::isFlagOn
virtual bool isFlagOn() const
Definition: CmdLineOptionParser.cc:126
PIGCLITextGenerator
Definition: PIGCLITextGenerator.hh:41
PIGCmdLineOptions::SHOW_COMPRESSORS_PARAM_NAME
static const std::string SHOW_COMPRESSORS_PARAM_NAME
Long name of the parameter that tells whether to show compressors.
Definition: PIGCmdLineOptions.hh:89
CmdLineParser::addOption
void addOption(CmdLineOptionParser *opt)
PIGCmdLineOptions::DI_FORMAT_PARAM_NAME
static const std::string DI_FORMAT_PARAM_NAME
Long name of the data image output format parameter.
Definition: PIGCmdLineOptions.hh:73
PIGCmdLineOptions::entityName
std::string entityName() const
Definition: PIGCmdLineOptions.cc:295
CmdLineOptionParser::listSize
virtual int listSize() const
Definition: CmdLineOptionParser.cc:150
CmdLineOptionParser
Definition: CmdLineOptionParser.hh:56
PIGCmdLineOptions::BEM_PARAM_NAME
static const std::string BEM_PARAM_NAME
Long name of the BEM file parameter.
Definition: PIGCmdLineOptions.hh:67
CmdLineOptions
Definition: CmdLineOptions.hh:54
__func__
#define __func__
Definition: Application.hh:67
BoolCmdLineOptionParser
Definition: CmdLineOptionParser.hh:278
PIGCmdLineOptions::generateDecompressor
bool generateDecompressor() const
Definition: PIGCmdLineOptions.cc:244
PIGCmdLineOptions::PIGCmdLineOptions
PIGCmdLineOptions()
Definition: PIGCmdLineOptions.cc:61
ENTITY_NAME
const string ENTITY_NAME
Definition: PIGCmdLineOptions.cc:56
PIGCmdLineOptions::DMEM_WIDTH_IN_MAUS_PARAM_NAME
static const std::string DMEM_WIDTH_IN_MAUS_PARAM_NAME
Long name of the parameter that tells the width of data mem in MAUs.
Definition: PIGCmdLineOptions.hh:83
PIGCmdLineOptions::COMPRESSOR_PARAMS_PARAM_NAME
static const std::string COMPRESSOR_PARAMS_PARAM_NAME
Long name of parameter passed to code compressor plugin.
Definition: PIGCmdLineOptions.hh:87
PIGCmdLineOptions::printVersion
virtual void printVersion() const
Definition: PIGCmdLineOptions.cc:304
PIGCmdLineOptions::progeOutputDirectory
std::string progeOutputDirectory() const
Definition: PIGCmdLineOptions.cc:290
PIGCmdLineOptions.hh
CmdLineOptions::printHelp
virtual void printHelp() const
Definition: CmdLineOptions.cc:262
PIGCmdLineOptions::tpefFileCount
int tpefFileCount() const
Definition: PIGCmdLineOptions.cc:161
CmdLineOptionParser::String
virtual std::string String(int index=0) const
Definition: CmdLineOptionParser.cc:102
PIGCLITextGenerator::TXT_CLI_USAGE
@ TXT_CLI_USAGE
Definition: PIGCLITextGenerator.hh:50
PIGCmdLineOptions::printUsage
void printUsage() const
Definition: PIGCmdLineOptions.cc:329
StringListCmdLineOptionParser
Definition: CmdLineOptionParser.hh:344
PIGCmdLineOptions::PI_FORMAT_PARAM_NAME
static const std::string PI_FORMAT_PARAM_NAME
Long name of the program image output format parameter.
Definition: PIGCmdLineOptions.hh:71
PIGCmdLineOptions::DATA_IMG_PARAM_NAME
static const std::string DATA_IMG_PARAM_NAME
Long name of the parameter that defines whether to create data images.
Definition: PIGCmdLineOptions.hh:78
PIGCmdLineOptions::~PIGCmdLineOptions
virtual ~PIGCmdLineOptions()
Definition: PIGCmdLineOptions.cc:140
PIGCmdLineOptions::compressorPlugin
std::string compressorPlugin() const
Definition: PIGCmdLineOptions.cc:209
CmdLineOptionParser::integer
virtual int integer(int index=0) const
Definition: CmdLineOptionParser.cc:84
CmdLineParser::findOption
CmdLineOptionParser * findOption(std::string name) const
Definition: CmdLineParser.cc:160
PIGCmdLineOptions::tpefFile
std::string tpefFile(int index) const
Definition: PIGCmdLineOptions.cc:172
PIGCLITextGenerator::TXT_CLI_VERSION
@ TXT_CLI_VERSION
Definition: PIGCLITextGenerator.hh:49
StringCmdLineOptionParser
Definition: CmdLineOptionParser.hh:180
IntegerCmdLineOptionParser
Definition: CmdLineOptionParser.hh:117