OpenASIP  2.0
ProGeCmdLineOptions.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 ProGeCmdLineOptions.cc
26  *
27  * Implementation of ProGeCmdLineOptions 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  * @note rating: red
32  */
33 
34 #include <iostream>
35 #include <sstream>
36 #include "ProGeCmdLineOptions.hh"
37 #include "tce_config.h"
38 
39 using std::string;
40 using std::cout;
41 using std::endl;
42 
43 const string BEM_PARAM_NAME = "bem";
44 const string IDF_PARAM_NAME = "idf";
45 const string ICDECODER_PARAM_NAME = "gen";
46 const string HDL_PARAM_NAME = "hdl";
47 const string OUTPUTDIR_PARAM_NAME = "output";
48 const string SHARED_OUTPUTDIR_PARAM_NAME = "shared-files-dir";
49 const string PLUGIN_PARAMETERS_PARAM_NAME = "pluginparameters";
50 const string INTEGRATOR_NAME = "integrator";
51 const string IMEM_TYPE = "imem";
52 const string DMEM_TYPE = "dmem";
53 const string CLK_FREQUENCY = "clock-frequency";
54 const string TPEF_NAME = "program";
55 const string ENTITY_NAME = "entity-name";
56 const string USE_ABSOLUTE_PATHS = "absolute-paths";
57 const string LIST_INTEGRATORS = "list-integrators";
58 const string DEVICE_FAMILY = "device-family";
59 const string DEVICE_NAME = "device-name";
60 const string GENERATE_TESTBENCH = "generate-testbench";
61 const string SIMULATION_RUNTIME = "sim-runtime";
62 const string FORCE_OUTPUT = "force-output";
63 const string FU_ICGATE_LIST = "fu-ic-gate";
64 const string SYNC_RESET = "sync-reset";
65 const string HDB_LIST = "hdb-list";
66 const string ICD_ARG_LIST = "icd-arg-list";
67 const string PREFER_GEN = "prefer-generation";
68 const string RF_ICGATE_LIST = "rf-ic-gate";
69 const string DONT_RESET_ALL = "dont-reset-all";
70 const string FU_BACKREGISTER_LIST = "fu-back-register";
71 const string FU_FRONTREGISTER_LIST = "fu-front-register";
72 const string FU_MIDDLEREGISTER_LIST = "fu-middle-register";
73 
74 /**
75  * The constructor.
76  */
78  CmdLineOptions("") {
79 
81  BEM_PARAM_NAME, "The BEM file", "b");
83 
85  IDF_PARAM_NAME, "The IDF file", "i");
87 
89  HDL_PARAM_NAME, "The HDL to generate. 'vhdl' = VHDL", "l");
90  addOption(hdlParam);
91 
94  OUTPUTDIR_PARAM_NAME, "The output directory", "o");
96 
100  "The directory for HDL files that are potentially shared between "
101  "multiple generated processors.", "s");
103 
104  StringCmdLineOptionParser* pluginParameters =
106  PLUGIN_PARAMETERS_PARAM_NAME, "List plugin parameters for an "
107  "IC/Decoder generator plugin file.", "u");
108  addOption(pluginParameters);
109 
112  INTEGRATOR_NAME, "Select the target for platform integration.",
113  "g");
115 
117  IMEM_TYPE,
118  "Instruction memory type. Available types depends on "
119  "the platform integrator. Types are 'vhdl_array', 'onchip', "
120  "'sram', 'dram' and 'none'.",
121  "f");
123 
126  DMEM_TYPE, "Data memory type. Available types depends on the "
127  "platform integrator. Types are 'vhdl_array', 'onchip', 'sram',"
128  " 'dram' and 'none'", "d");
130 
133  CLK_FREQUENCY, "Defines the target clock frequency.", "c");
134  addOption(fmax);
135 
136  StringCmdLineOptionParser* programName =
138  TPEF_NAME, "Name of tpef program.", "p");
139  addOption(programName);
140 
142  ENTITY_NAME,
143  "String to use to make the generated VHDL entities unique. This "
144  "is also used in the name of the top level entity platform "
145  "integrator creates. Default is 'tta0' for the core, thus "
146  "'tta0_toplevel' for the platform integrator top level "
147  "component.",
148  "e");
150 
153  USE_ABSOLUTE_PATHS, "Use absolute paths in generated platform "
154  "integrator files.", "a");
156 
159  GENERATE_TESTBENCH, "Generate testbench.", "t");
161 
162  BoolCmdLineOptionParser* listIntegrators =
164  LIST_INTEGRATORS, "List available integrators and information "
165  "about them.", "n");
166  addOption(listIntegrators);
167 
170  DEVICE_FAMILY,
171  "Set FPGA device family for integration. Stand-alone integrators "
172  "may ignore this parameter. Example: \"Stratix II\" or "
173  "Stratix\\ II", "m");
175 
177  DEVICE_NAME,
178  "Set FPGA device family for integration. Stand-alone integrators "
179  "may ignore this parameter. Example: \"xc7z020clg400-1\"");
181 
184  "The runtime of the simulation in nanoseconds. Default: 52390 ns",
185  "r");
186  addOption(simTime);
187 
189  FORCE_OUTPUT, "Forces output writing into existing directory.", "F");
190  addOption(forceOutput);
191 
193  SYNC_RESET, "Generate Synchronous reset (default async).");
195 
197  HDB_LIST, "Comma separated list of HDBs for automated generation.",
198  "h");
200 
202  ICD_ARG_LIST,
203  "Comma separated list of IC decoder plugin arguments "
204  "for automated generation.");
206 
208  PREFER_GEN,
209  "Prefer HDL generation over existing HDB implementations.");
210  addOption(preferGen);
211 
214  "Doesn't reset unnecessary registers (default false).");
215  addOption(resetAll);
216 
218  RF_ICGATE_LIST, "Comma separated list of RFs to IC-Gate.");
220 
222  FU_ICGATE_LIST, "Comma separated list of FUs to IC-Gate.");
224 
227  "Comma separated list of FUs to back-register.");
228  addOption(fuBackRegList);
229 
232  "Comma separated list of FUs to front-register.");
233  addOption(fuFrontRegList);
234 
235  StringCmdLineOptionParser* fuMiddleRegList =
238  "Comma separated list of FUs to middle-register.");
239  addOption(fuMiddleRegList);
240 }
241 
242 
243 /**
244  * The destructor.
245  */
247 }
248 
249 
250 /**
251  * Returns the ADF or PCF file given as last argument.
252  *
253  * @return The name of the file.
254  */
255 std::string
257  return argument(numberOfArguments());
258 }
259 
260 
261 /**
262  * Returns the given BEM file.
263  *
264  * @return The name of the file.
265  */
266 std::string
268  return findOption(BEM_PARAM_NAME)->String();
269 }
270 
271 
272 /**
273  * Returns the given IDF file.
274  *
275  * @return The name of the file.
276  */
277 std::string
279  return findOption(IDF_PARAM_NAME)->String();
280 }
281 
282 
283 /**
284  * Returns the given HDL parameter.
285  *
286  * @return The HDL parameter.
287  */
288 std::string
290  return findOption(HDL_PARAM_NAME)->String();
291 }
292 
293 
294 /**
295  * Returns the given output directory.
296  *
297  * @return The given output directory.
298  */
299 std::string
302 }
303 
304 /**
305  * Returns the given output directory.
306  *
307  * @return The given output directory.
308  */
309 std::string
312 }
313 
314 
315 /**
316  * Returns the IC/decoder generator plugin parameter list query.
317  *
318  * @return The plugin parameter query.
319  */
320 std::string
323 }
324 
325 
326 std::string
328  return findOption(INTEGRATOR_NAME)->String();
329 }
330 
331 
332 std::string
334  return findOption(IMEM_TYPE)->String();
335 }
336 
337 
338 std::string
340  return findOption(DMEM_TYPE)->String();
341 }
342 
343 
344 int
346 
347  int freq = 0;
348  if (findOption(CLK_FREQUENCY)->isDefined()) {
349  freq = findOption(CLK_FREQUENCY)->integer();
350  }
351  return freq;
352 }
353 
354 
355 std::string
357  return findOption(TPEF_NAME)->String();
358 }
359 
360 
361 std::string
363  return findOption(ENTITY_NAME)->String();
364 }
365 
366 bool
369 }
370 
371 bool
374 }
375 
376 bool
379 }
380 
381 std::string
383  string deviceFamily = "";
384  if (findOption(DEVICE_FAMILY)->isDefined()) {
385  deviceFamily = findOption(DEVICE_FAMILY)->String();
386  }
387  return deviceFamily;
388 }
389 
390 std::string
392  string devicePart = "";
393  if (findOption(DEVICE_NAME)->isDefined()) {
394  devicePart = findOption(DEVICE_NAME)->String();
395  }
396  return devicePart;
397 }
398 
399 /**
400  * Gets the HDL simulation time from Cmd line options. If none given, the
401  * legacy MAGICAL RUNTIME CONSTANT value 52390ns will be used.
402  */
403 std::string
405  int simTime = 52390;
406  if (findOption(SIMULATION_RUNTIME)->isDefined()) {
407  simTime = findOption(SIMULATION_RUNTIME)->integer();
408  }
409  std::ostringstream s;
410  s << simTime;
411 
412  return s.str();
413 }
414 
415 /**
416  * Returns true if ProGe is allowed to write the processor files to an
417  * existing directory.
418  */
419 bool
421  return findOption(FORCE_OUTPUT)->isFlagOn();
422 }
423 
424 /**
425  * Returns true if synchronous reset.
426  */
427 bool
429  return findOption(SYNC_RESET)->isFlagOn();
430 }
431 
432 /**
433  * Returns true if asynchronous reset.
434  */
435 bool
437  return !findOption(SYNC_RESET)->isFlagOn();
438 }
439 
440 /**
441  * Helper for arguments with comma-separated arguments
442  */
443 std::vector<std::string>
445  const std::string argumentName) const {
446  std::vector<std::string> list;
447  std::string str;
448  if (findOption(argumentName)->isDefined()) {
449  str = findOption(argumentName)->String();
450  }
451  std::stringstream ss(str);
452  while (ss.good()) {
453  std::string sub;
454  std::getline(ss, sub, ',');
455  if (sub.size() > 1) {
456  list.emplace_back(sub);
457  }
458  }
459  return list;
460 }
461 
462 /**
463  * Return list of HDBs.
464  */
465 std::vector<std::string>
468 }
469 
470 /**
471  * Return list of RFs to IC-Gate.
472  */
473 std::vector<std::string>
476 }
477 
478 /**
479  * Return list of option/argument pairs for ICDecoder plugin
480  */
481 std::vector<std::pair<std::string, std::string>>
483  auto raw_pairs = commaSeparatedList(ICD_ARG_LIST);
484  std::vector<std::pair<std::string, std::string>> parsed_pairs;
485 
486  for (std::string key_val_pair : raw_pairs) {
487  if (key_val_pair.size() > 1) {
488  std::stringstream kvp(key_val_pair);
489  std::string key;
490  std::string value;
491  std::getline(kvp, key, ':');
492  std::getline(kvp, value, ':');
493  parsed_pairs.emplace_back(key, value);
494  }
495  }
496  return parsed_pairs;
497 }
498 
499 /**
500  * Return list of FUs to IC-Gate.
501  */
502 std::vector<std::string>
505 }
506 
507 std::vector<std::string>
510 }
511 
512 std::vector<std::string>
515 }
516 
517 std::vector<std::string>
520 }
521 
522 /**
523  * Returns true if preferring HDL Generation.
524  */
525 bool
527  return findOption(PREFER_GEN)->isFlagOn();
528 }
529 
530 /**
531  * Returns true if all registers should be reseted.
532  */
533 bool
535  return !findOption(DONT_RESET_ALL)->isFlagOn();
536 }
537 
538 /**
539  * Prints the version of the application.
540  */
541 void
543  std::cout << "generateprocessor - OpenASIP Processor Generator "
544  << Application::TCEVersionString() << std::endl;
545 }
546 
547 
548 /**
549  * Prints help of the application.
550  */
551 void
553  printVersion();
554  cout << "Usage: generateprocessor [options] <processor>" << endl
555  << "where <processor> means either an ADF or PCF file." << endl;
557 }
ProGeCmdLineOptions::~ProGeCmdLineOptions
virtual ~ProGeCmdLineOptions()
Definition: ProGeCmdLineOptions.cc:246
ENTITY_NAME
const string ENTITY_NAME
Definition: ProGeCmdLineOptions.cc:55
ProGeCmdLineOptions::printHelp
virtual void printHelp() const
Definition: ProGeCmdLineOptions.cc:552
HDB_LIST
const string HDB_LIST
Definition: ProGeCmdLineOptions.cc:65
ProGeCmdLineOptions::processorToGenerate
std::string processorToGenerate() const
Definition: ProGeCmdLineOptions.cc:256
ProGeCmdLineOptions.hh
FORCE_OUTPUT
const string FORCE_OUTPUT
Definition: ProGeCmdLineOptions.cc:62
ProGeCmdLineOptions::tpefName
std::string tpefName() const
Definition: ProGeCmdLineOptions.cc:356
ICD_ARG_LIST
const string ICD_ARG_LIST
Definition: ProGeCmdLineOptions.cc:66
ProGeCmdLineOptions::bemFile
std::string bemFile() const
Definition: ProGeCmdLineOptions.cc:267
IMEM_TYPE
const string IMEM_TYPE
Definition: ProGeCmdLineOptions.cc:51
INTEGRATOR_NAME
const string INTEGRATOR_NAME
Definition: ProGeCmdLineOptions.cc:50
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
ProGeCmdLineOptions::useAbsolutePaths
bool useAbsolutePaths() const
Definition: ProGeCmdLineOptions.cc:367
FU_BACKREGISTER_LIST
const string FU_BACKREGISTER_LIST
Definition: ProGeCmdLineOptions.cc:70
FU_MIDDLEREGISTER_LIST
const string FU_MIDDLEREGISTER_LIST
Definition: ProGeCmdLineOptions.cc:72
HDL_PARAM_NAME
const string HDL_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:46
ProGeCmdLineOptions::icdArgList
std::vector< std::pair< std::string, std::string > > icdArgList() const
Definition: ProGeCmdLineOptions.cc:482
ProGeCmdLineOptions::generateTestbench
bool generateTestbench() const
Definition: ProGeCmdLineOptions.cc:372
DEVICE_NAME
const string DEVICE_NAME
Definition: ProGeCmdLineOptions.cc:59
ProGeCmdLineOptions::printVersion
virtual void printVersion() const
Definition: ProGeCmdLineOptions.cc:542
PLUGIN_PARAMETERS_PARAM_NAME
const string PLUGIN_PARAMETERS_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:49
CmdLineOptionParser::isFlagOn
virtual bool isFlagOn() const
Definition: CmdLineOptionParser.cc:126
ProGeCmdLineOptions::asyncReset
bool asyncReset() const
Definition: ProGeCmdLineOptions.cc:436
PREFER_GEN
const string PREFER_GEN
Definition: ProGeCmdLineOptions.cc:67
ProGeCmdLineOptions::pluginParametersQuery
std::string pluginParametersQuery() const
Definition: ProGeCmdLineOptions.cc:321
BEM_PARAM_NAME
const string BEM_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:43
SHARED_OUTPUTDIR_PARAM_NAME
const string SHARED_OUTPUTDIR_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:48
ProGeCmdLineOptions::idfFile
std::string idfFile() const
Definition: ProGeCmdLineOptions.cc:278
ProGeCmdLineOptions::commaSeparatedList
std::vector< std::string > commaSeparatedList(const std::string argumentName) const
Definition: ProGeCmdLineOptions.cc:444
SIMULATION_RUNTIME
const string SIMULATION_RUNTIME
Definition: ProGeCmdLineOptions.cc:61
ProGeCmdLineOptions::fuFrontRegistered
std::vector< std::string > fuFrontRegistered() const
Definition: ProGeCmdLineOptions.cc:513
FU_FRONTREGISTER_LIST
const string FU_FRONTREGISTER_LIST
Definition: ProGeCmdLineOptions.cc:71
CmdLineParser::addOption
void addOption(CmdLineOptionParser *opt)
ProGeCmdLineOptions::fuIcGateList
std::vector< std::string > fuIcGateList() const
Definition: ProGeCmdLineOptions.cc:503
DMEM_TYPE
const string DMEM_TYPE
Definition: ProGeCmdLineOptions.cc:52
ProGeCmdLineOptions::listAvailableIntegrators
bool listAvailableIntegrators() const
Definition: ProGeCmdLineOptions.cc:377
ProGeCmdLineOptions::hdbList
std::vector< std::string > hdbList() const
Definition: ProGeCmdLineOptions.cc:466
DONT_RESET_ALL
const string DONT_RESET_ALL
Definition: ProGeCmdLineOptions.cc:69
ProGeCmdLineOptions::fuBackRegistered
std::vector< std::string > fuBackRegistered() const
Definition: ProGeCmdLineOptions.cc:508
USE_ABSOLUTE_PATHS
const string USE_ABSOLUTE_PATHS
Definition: ProGeCmdLineOptions.cc:56
CmdLineOptions
Definition: CmdLineOptions.hh:54
BoolCmdLineOptionParser
Definition: CmdLineOptionParser.hh:278
ProGeCmdLineOptions::syncReset
bool syncReset() const
Definition: ProGeCmdLineOptions.cc:428
CmdLineOptions::printHelp
virtual void printHelp() const
Definition: CmdLineOptions.cc:262
ProGeCmdLineOptions::clockFrequency
int clockFrequency() const
Definition: ProGeCmdLineOptions.cc:345
ProGeCmdLineOptions::imemType
std::string imemType() const
Definition: ProGeCmdLineOptions.cc:333
ProGeCmdLineOptions::simulationRuntime
std::string simulationRuntime() const
Definition: ProGeCmdLineOptions.cc:404
IDF_PARAM_NAME
const string IDF_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:44
ICDECODER_PARAM_NAME
const string ICDECODER_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:45
CmdLineOptionParser::String
virtual std::string String(int index=0) const
Definition: CmdLineOptionParser.cc:102
GENERATE_TESTBENCH
const string GENERATE_TESTBENCH
Definition: ProGeCmdLineOptions.cc:60
RF_ICGATE_LIST
const string RF_ICGATE_LIST
Definition: ProGeCmdLineOptions.cc:68
ProGeCmdLineOptions::preferHDLGeneration
bool preferHDLGeneration() const
Definition: ProGeCmdLineOptions.cc:526
OUTPUTDIR_PARAM_NAME
const string OUTPUTDIR_PARAM_NAME
Definition: ProGeCmdLineOptions.cc:47
ProGeCmdLineOptions::sharedOutputDirectory
std::string sharedOutputDirectory() const
Definition: ProGeCmdLineOptions.cc:310
ProGeCmdLineOptions::forceOutputDirectory
bool forceOutputDirectory() const
Definition: ProGeCmdLineOptions.cc:420
LIST_INTEGRATORS
const string LIST_INTEGRATORS
Definition: ProGeCmdLineOptions.cc:57
SYNC_RESET
const string SYNC_RESET
Definition: ProGeCmdLineOptions.cc:64
ProGeCmdLineOptions::fuMiddleRegistered
std::vector< std::string > fuMiddleRegistered() const
Definition: ProGeCmdLineOptions.cc:518
TPEF_NAME
const string TPEF_NAME
Definition: ProGeCmdLineOptions.cc:54
ProGeCmdLineOptions::ProGeCmdLineOptions
ProGeCmdLineOptions()
Definition: ProGeCmdLineOptions.cc:77
ProGeCmdLineOptions::dmemType
std::string dmemType() const
Definition: ProGeCmdLineOptions.cc:339
sub
#define sub
Definition: ConstantTransformer.cc:63
DEVICE_FAMILY
const string DEVICE_FAMILY
Definition: ProGeCmdLineOptions.cc:58
ProGeCmdLineOptions::deviceFamilyName
std::string deviceFamilyName() const
Definition: ProGeCmdLineOptions.cc:382
ProGeCmdLineOptions::hdl
std::string hdl() const
Definition: ProGeCmdLineOptions.cc:289
ProGeCmdLineOptions::outputDirectory
std::string outputDirectory() const
Definition: ProGeCmdLineOptions.cc:300
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
CmdLineParser::argument
virtual std::string argument(int index) const
ProGeCmdLineOptions::resetAllRegisters
bool resetAllRegisters() const
Definition: ProGeCmdLineOptions.cc:534
Application::TCEVersionString
static std::string TCEVersionString()
Definition: Application.cc:510
ProGeCmdLineOptions::integratorName
std::string integratorName() const
Definition: ProGeCmdLineOptions.cc:327
ProGeCmdLineOptions::deviceName
std::string deviceName() const
Definition: ProGeCmdLineOptions.cc:391
ProGeCmdLineOptions::entityName
std::string entityName() const
Definition: ProGeCmdLineOptions.cc:362
StringCmdLineOptionParser
Definition: CmdLineOptionParser.hh:180
CLK_FREQUENCY
const string CLK_FREQUENCY
Definition: ProGeCmdLineOptions.cc:53
FU_ICGATE_LIST
const string FU_ICGATE_LIST
Definition: ProGeCmdLineOptions.cc:63
ProGeCmdLineOptions::rfIcGateList
std::vector< std::string > rfIcGateList() const
Definition: ProGeCmdLineOptions.cc:474
IntegerCmdLineOptionParser
Definition: CmdLineOptionParser.hh:117