OpenASIP  2.0
Public Member Functions | Private Member Functions | List of all members
GenerateProcessor Class Reference

#include <GenerateProcessor.hh>

Inheritance diagram for GenerateProcessor:
Inheritance graph
Collaboration diagram for GenerateProcessor:
Collaboration graph

Public Member Functions

 GenerateProcessor ()
 
virtual ~GenerateProcessor ()
 
bool generateProcessor (int argc, char *argv[])
 
- Public Member Functions inherited from ProGe::ProGeUI
virtual ~ProGeUI ()
 
 ProGeUI ()
 
void generateProcessor (const ProGeOptions &options, int imemWidthInMAUs, std::ostream &errorStream, std::ostream &warningStream, std::ostream &verboseStream)
 
void generateTestBench (const ProGe::HDL language, const std::string &dstDir, const std::string &progeOutDir)
 
void generateScripts (const ProGe::HDL language, const std::string &dstDir, const std::string &progeOutDir, const std::string &sharedOutDir, const std::string &testBenchDir, const std::string &simulationRuntime)
 
void loadMachine (const TTAMachine::Machine &adf)
 
void loadBinaryEncoding (const BinaryEncoding &bem)
 
void loadMachineImplementation (const IDF::MachineImplementation &idf)
 

Private Member Functions

void getOutputDir (const ProGeCmdLineOptions &options, std::string &outputDir)
 
bool listICDecPluginParameters (const std::string &pluginFile) const
 
void listIntegrators () const
 
bool validIntegratorParameters (const ProGeCmdLineOptions &options) const
 
MemType string2MemType (const std::string &memoryString) const
 

Additional Inherited Members

- Protected Member Functions inherited from ProGe::ProGeUI
void loadMachine (const std::string &adfFile)
 
void loadBinaryEncoding (const std::string &bemFile)
 
void loadMachineImplementation (const std::string &idfFile)
 
void loadProcessorConfiguration (const std::string &configurationFile)
 
void loadICDecoderGeneratorPlugin (const std::string &pluginFile, const std::string &pluginName)
 
void integrateProcessor (std::ostream &warningStream, std::ostream &errorStream, std::string progeOutDir, std::string sharedOutputDir, const std::string &platformIntegrator, const std::string &coreEntityName, const std::string &programName, const std::string &deviceFamily, const std::string &deviceName, MemType imem, MemType dmem, HDL language, int fmax, bool syncReset)
 
- Protected Attributes inherited from ProGe::ProGeUI
TTAMachine::Machinemachine_
 The loaded machine. More...
 

Detailed Description

Implements the command line user interface 'generateprocessor'.

Definition at line 46 of file GenerateProcessor.hh.

Constructor & Destructor Documentation

◆ GenerateProcessor()

GenerateProcessor::GenerateProcessor ( )

The constructor.

Definition at line 82 of file GenerateProcessor.cc.

82  {
83 }

◆ ~GenerateProcessor()

GenerateProcessor::~GenerateProcessor ( )
virtual

The destructor.

Definition at line 89 of file GenerateProcessor.cc.

89  {
90 }

Member Function Documentation

◆ generateProcessor()

bool GenerateProcessor::generateProcessor ( int  argc,
char *  argv[] 
)

Parses the command line arguments and generates the processor.

Returns
True if the generation of the processor was succesful, otherwise false.

Definition at line 100 of file GenerateProcessor.cc.

100  {
101 
103  string entity = "";
104 
105  try {
106 
107  options.parse(argv, argc);
108  ProGeOptions progeOptions(options);
109 
110  std::string pluginParamQuery = options.pluginParametersQuery();
111  if (pluginParamQuery != "") {
112  return listICDecPluginParameters(pluginParamQuery);
113  }
114 
118  }
119 
122  }
123 
124  if (options.listAvailableIntegrators()) {
125  listIntegrators();
126  return true;
127  }
128 
129  if (options.numberOfArguments() == 0) {
130  options.printHelp();
131  return false;
132  }
133 
135  options.printHelp();
136  return false;
137  }
138 
139  if (!options.forceOutputDirectory() &&
140  FileSystem::fileExists(progeOptions.outputDirectory)) {
141  cerr << "Error: Output directory " << progeOptions.outputDirectory
142  << " already exists." << endl;
143  return false;
144  }
145 
146  string processorDefinition = options.processorToGenerate();
147  if (FileSystem::fileExtension(processorDefinition) == ".adf") {
148  loadMachine(processorDefinition);
149  } else if (FileSystem::fileExtension(processorDefinition) ==
150  ".pcf") {
151  loadProcessorConfiguration(processorDefinition);
152  } else {
153  cerr << "Unknown file: " << processorDefinition
154  << ". The given file must be either an ADF or PCF file."
155  << endl;
156  throw IllegalCommandLine(__FILE__, __LINE__, __func__);
157  }
158 
159  string bem = options.bemFile();
160  string idf = options.idfFile();
161  string hdl = options.hdl();
162 
163  int imemWidthInMAUs = DEFAULT_IMEMWIDTH_IN_MAUS;
164  if (machine_->isRISCVMachine()) {
165  imemWidthInMAUs = 4;
166  }
167 
168  if (bem != "") {
169  loadBinaryEncoding(bem);
170  }
171  if (idf != "") {
173  }
174 
175  ProGeUI::generateProcessor(
176  progeOptions, imemWidthInMAUs, std::cerr, std::cerr, std::cerr);
177  } catch (ParserStopRequest) {
178  return false;
179  } catch (const IllegalCommandLine& exception) {
180  cerr << exception.errorMessage() << endl;
181  return false;
182  } catch (const Exception& e) {
183  cerr << e.errorMessage() << endl;
184  cerr << "Exception thrown at: " << e.fileName() << ":"
185  << e.lineNum() << endl;
186  cerr << " message: " << e.errorMessage() << endl;
187  return false;
188  }
189 
190  ProGeOptions progeOptions(options);
191 
192  if (options.generateTestbench()) {
193  string testBenchDir = progeOptions.outputDirectory +
195  try {
196  ProGeUI::generateTestBench(
197  progeOptions.language, testBenchDir,
198  progeOptions.outputDirectory);
199  } catch (const Exception& e) {
200  std::cerr << "Warning: Processor Generator failed to "
201  << "generate testbench." << std::endl;
202  std::cerr << e.errorMessage() << std::endl;
203  }
204 
205  try {
206  ProGeUI::generateScripts(
207  progeOptions.language, progeOptions.outputDirectory,
208  progeOptions.outputDirectory,
209  progeOptions.sharedOutputDirectory, testBenchDir,
210  progeOptions.simulationRuntime);
211  } catch (const Exception& e) {
212  std::cerr << "Warning: Processor Generator failed to "
213  << "generate simulation/compilation scripts."
214  << std::endl;
215  std::cerr << e.errorMessage() << std::endl;
216  }
217  }
218 
219  string integrator = options.integratorName();
220  if (!integrator.empty()) {
221  if (progeOptions.language == Verilog) {
222  std::cerr << "Verilog is not yet supported by Platform Integrator"
223  << std::endl;
224  return false;
225  }
226 
227  string progeOutDir = progeOptions.outputDirectory;
228  string sharedOutDir = progeOptions.sharedOutputDirectory;
229  if (!options.useAbsolutePaths()) {
230  string cwd = FileSystem::currentWorkingDir();
231  FileSystem::relativeDir(cwd, progeOutDir);
232  FileSystem::relativeDir(cwd, sharedOutDir);
233  }
234 
235  string platformDir = progeOutDir + FileSystem::DIRECTORY_SEPARATOR +
236  "platform";
237  string program =
238  StringTools::chopString(options.tpefName(), ".tpef").at(0);
239  MemType imem = string2MemType(options.imemType());
240  MemType dmem = string2MemType(options.dmemType());
241  int fmax = options.clockFrequency();
242  string devFamily = options.deviceFamilyName();
243  string devName = options.deviceName();
244  bool syncReset = options.syncReset();
245 
246  try {
247  ProGeUI::integrateProcessor(
248  std::cout, std::cerr, progeOutDir, sharedOutDir, integrator,
249  progeOptions.entityName, program, devFamily, devName, imem,
250  dmem, progeOptions.language, fmax, syncReset);
251  } catch (const Exception& e) {
252  std::cerr << "Processor integration failed: "
253  << e.procedureName() << ": "
254  << e.errorMessage() << endl;
255  return false;
256  }
257  }
258 
259  return true;
260 }

References __func__, StringTools::chopString(), FileSystem::currentWorkingDir(), DEFAULT_IMEMWIDTH_IN_MAUS, FileSystem::DIRECTORY_SEPARATOR, ProGeOptions::entityName, Exception::errorMessage(), FileSystem::fileExists(), FileSystem::fileExtension(), Exception::fileName(), ProGe::ProGeUI::generateProcessor(), ProGe::ProGeUI::generateScripts(), ProGe::ProGeUI::generateTestBench(), ProGe::ProGeUI::integrateProcessor(), CmdLineOptions::isVerboseSpamSwitchDefined(), CmdLineOptions::isVerboseSwitchDefined(), ProGeOptions::language, Exception::lineNum(), loadMachine(), CmdLineParser::numberOfArguments(), options, ProGeOptions::outputDirectory, CmdLineOptions::parse(), MachInfoCmdLineOptions::printHelp(), Exception::procedureName(), program, FileSystem::relativeDir(), Application::setVerboseLevel(), ProGeOptions::sharedOutputDirectory, ProGeOptions::simulationRuntime, Application::VERBOSE_LEVEL_INCREASED, Application::VERBOSE_LEVEL_SPAM, and ProGe::Verilog.

Referenced by main().

Here is the call graph for this function:

◆ getOutputDir()

void GenerateProcessor::getOutputDir ( const ProGeCmdLineOptions options,
std::string &  outputDir 
)
private

Generates the output directory name.

Parameters
optionsProge command line options.
outputDirString where output directory name is to be stored.

Definition at line 269 of file GenerateProcessor.cc.

271  {
272 
273  outputDir = options.outputDirectory();
274 
275  if (outputDir == "") {
276  outputDir = FileSystem::currentWorkingDir() +
277  FileSystem::DIRECTORY_SEPARATOR + "proge-output";
278  } else {
279  outputDir = FileSystem::expandTilde(outputDir);
280  outputDir = FileSystem::absolutePathOf(outputDir);
281  }
282 }

References FileSystem::absolutePathOf(), FileSystem::currentWorkingDir(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::expandTilde(), and options.

Here is the call graph for this function:

◆ listICDecPluginParameters()

bool GenerateProcessor::listICDecPluginParameters ( const std::string &  pluginFile) const
private

Prints listing of IC/Decoder generator plugin parameters to stdout.

Parameters
pluginFileFull path to the plugin file.

Definition at line 290 of file GenerateProcessor.cc.

291  {
292 
293  // An ugly way to determine the plugin name which should be the
294  // file name minus the "Plugin.so" ending.
295  string pluginName = FileSystem::fileOfPath(pluginFile);
296  pluginName = FileSystem::fileNameBody(pluginFile);
297  if (pluginName.length() < 6 ||
298  pluginName.substr(pluginName.length() - 6) != "Plugin") {
299 
300  cerr << "Unable to determine plugin name. Plugin file must be named "
301  << "'<plugin name>Plugin.so'." << endl;;
302  return false;
303  }
304 
305  pluginName = pluginName.substr(0, pluginName.length() - 6);
306 
307  // initialize plugin tool
308  PluginTools pluginTool;
309  std::vector<string> pluginPaths = Environment::icDecoderPluginPaths();
310  for (std::vector<string>::const_iterator iter = pluginPaths.begin();
311  iter != pluginPaths.end(); iter++) {
312  try {
313  pluginTool.addSearchPath(*iter);
314  } catch (const FileNotFound&) {
315  }
316  }
317 
318  try {
319  pluginTool.registerModule(pluginFile);
320  } catch (const FileNotFound&) {
321  cerr << "Plugin file '" << pluginFile << "' not found." << endl;
322  return false;
323  } catch (Exception& e) {
324  cerr << "Error loading plugin file '" << pluginFile << "': "
325  << e.errorMessage() << endl;
326 
327  return false;
328  }
329 
330 
331  ICDecoderGeneratorPlugin* (*creator)(
333 
334  ICDecoderGeneratorPlugin* plugin;
335 
337  BinaryEncoding bem;
338 
339  try {
340  pluginTool.importSymbol(
341  "create_generator_plugin_" + pluginName, creator, pluginFile);
342 
343  plugin = creator(machine, bem);
344  } catch (Exception& e) {
345  cerr << "Error loading plugin '" << pluginName << "' from '"
346  << pluginFile << "':" << endl;
347  cerr << e.errorMessage() << endl;
348  return false;
349  }
350 
351  assert(plugin != NULL);
352 
353  cout << pluginName << ":" << endl;
354  cout << plugin->pluginDescription() << endl << endl;
355  cout << "Recognized parameters:" << endl
356  << "----------------------" << endl;
357 
358  for (int i = 0; i < plugin->recognizedParameterCount(); i++) {
359  std::string paramName = plugin->recognizedParameter(i);
360  cout << paramName << endl;
361  cout << " " << plugin->parameterDescription(paramName) << endl;
362  cout << endl;
363  }
364  cout << "----------------------" << endl;
365 
366  delete plugin;
367  return true;
368 }

References PluginTools::addSearchPath(), assert, Exception::errorMessage(), FileSystem::fileNameBody(), FileSystem::fileOfPath(), Environment::icDecoderPluginPaths(), PluginTools::importSymbol(), machine, and PluginTools::registerModule().

Here is the call graph for this function:

◆ listIntegrators()

void GenerateProcessor::listIntegrators ( ) const
private

Definition at line 372 of file GenerateProcessor.cc.

372  {
373 
374  std::vector<PlatformIntegrator*> integrators;
375  // append new integrators here
376  integrators.push_back(new Stratix2DSPBoardIntegrator());
377  integrators.push_back(new Stratix3DevKitIntegrator());
378  integrators.push_back(new KoskiIntegrator());
379  integrators.push_back(new AvalonIntegrator());
380  integrators.push_back(new AlmaIFIntegrator());
381 
382  for (unsigned int i = 0; i < integrators.size(); i++) {
383  integrators.at(i)->printInfo(std::cout);
384  delete integrators.at(i);
385  }
386  std::cout << "Please refer to the user manual for more information on "
387  << "Platform Integrators." << std::endl;
388 }

◆ string2MemType()

MemType GenerateProcessor::string2MemType ( const std::string &  memoryString) const
private

Definition at line 440 of file GenerateProcessor.cc.

440  {
441 
442  MemType memory = UNKNOWN;
443  if (memoryString == "none") {
444  memory = NONE;
445  } else if (memoryString == "vhdl_array") {
446  memory = VHDL_ARRAY;
447  } else if (memoryString == "onchip") {
448  memory = ONCHIP;
449  } else if (memoryString == "sram") {
450  memory = SRAM;
451  } else if (memoryString == "dram") {
452  memory = DRAM;
453  }
454  return memory;
455 }

References DRAM, NONE, ONCHIP, SRAM, UNKNOWN, and VHDL_ARRAY.

◆ validIntegratorParameters()

bool GenerateProcessor::validIntegratorParameters ( const ProGeCmdLineOptions options) const
private

Definition at line 392 of file GenerateProcessor.cc.

393  {
394 
395  if (options.integratorName().empty()) {
396  return true;
397  }
398  string entity = options.entityName();
399  if (entity.empty()) {
400  std::cerr << "Entity name must be given" << endl;
401  return false;
402  }
403  string program = options.tpefName();
404  if (program.empty()) {
405  std::cerr
406  << "Tpef is required for platform integration" << endl;
407  return false;
408  }
409  if (!StringTools::endsWith(program, ".tpef")) {
410  std::cerr << "Program does not have '.tpef' ending" << endl;
411  return false;
412  }
413 
414  string imem = options.imemType();
415  if (imem.empty()) {
416  std::cerr << "Instruction memory type is required for platform "
417  << "integration" << endl;
418  return false;
419  }
420  string dmem = options.dmemType();
421  if (dmem.empty()) {
422  std::cerr << "Data memory type is required for platform integration"
423  << endl;
424  return false;
425  }
426  if (string2MemType(imem) == UNKNOWN) {
427  std::cerr
428  << "Invalid instruction memory type " << imem << endl;
429  return false;
430  }
431  if (string2MemType(dmem) == UNKNOWN) {
432  std::cerr << "Invalid data memory type " << dmem << endl;
433  return false;
434  }
435  return true;
436 }

References StringTools::endsWith(), options, program, and UNKNOWN.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
StringTools::endsWith
static bool endsWith(const std::string &source, const std::string &searchString)
Definition: StringTools.cc:126
MachInfoCmdLineOptions::printHelp
virtual void printHelp() const
Definition: MachInfoCmdLineOptions.cc:89
BinaryEncoding
Definition: BinaryEncoding.hh:61
Exception::procedureName
std::string procedureName() const
AvalonIntegrator
Definition: AvalonIntegrator.hh:39
Exception::lineNum
int lineNum() const
FileNotFound
Definition: Exception.hh:224
GenerateProcessor::validIntegratorParameters
bool validIntegratorParameters(const ProGeCmdLineOptions &options) const
Definition: GenerateProcessor.cc:392
ParserStopRequest
Definition: Exception.hh:491
ProGe::Verilog
@ Verilog
Verilog.
Definition: ProGeTypes.hh:42
TTAMachine::Machine::isRISCVMachine
bool isRISCVMachine() const
Definition: Machine.cc:1063
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
PluginTools
Definition: PluginTools.hh:53
SRAM
@ SRAM
Definition: MemoryGenerator.hh:62
GenerateProcessor::listICDecPluginParameters
bool listICDecPluginParameters(const std::string &pluginFile) const
Definition: GenerateProcessor.cc:290
ProGe::ICDecoderGeneratorPlugin
Definition: ICDecoderGeneratorPlugin.hh:68
ProGeOptions
Definition: ProGeOptions.hh:41
ProGe::ProGeUI::loadProcessorConfiguration
void loadProcessorConfiguration(const std::string &configurationFile)
Definition: ProGeUI.cc:190
Application::setVerboseLevel
static void setVerboseLevel(const int level=VERBOSE_LEVEL_DEFAULT)
Definition: Application.hh:186
KoskiIntegrator
Definition: KoskiIntegrator.hh:40
Environment::icDecoderPluginPaths
static std::vector< std::string > icDecoderPluginPaths(bool libraryPathsOnly=false)
Definition: Environment.cc:635
Stratix3DevKitIntegrator
Definition: Stratix3DevKitIntegrator.hh:44
IllegalCommandLine
Definition: Exception.hh:438
FileSystem::absolutePathOf
static std::string absolutePathOf(const std::string &pathName)
Definition: FileSystem.cc:303
FileSystem::relativeDir
static bool relativeDir(const std::string &baseDir, std::string &toRelDir)
Definition: FileSystem.cc:762
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
DRAM
@ DRAM
Definition: MemoryGenerator.hh:63
DEFAULT_IMEMWIDTH_IN_MAUS
const int DEFAULT_IMEMWIDTH_IN_MAUS
Definition: GenerateProcessor.cc:63
Exception::fileName
std::string fileName() const
assert
#define assert(condition)
Definition: Application.hh:86
ProGeCmdLineOptions
Definition: ProGeCmdLineOptions.hh:43
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
FileSystem::fileExtension
static std::string fileExtension(const std::string &fileName)
Definition: FileSystem.cc:279
Stratix2DSPBoardIntegrator
Definition: Stratix2DSPBoardIntegrator.hh:52
__func__
#define __func__
Definition: Application.hh:67
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
GenerateProcessor::listIntegrators
void listIntegrators() const
Definition: GenerateProcessor.cc:372
AlmaIFIntegrator
Definition: AlmaIFIntegrator.hh:40
CmdLineOptions::isVerboseSwitchDefined
virtual bool isVerboseSwitchDefined() const
Definition: CmdLineOptions.cc:300
Exception
Definition: Exception.hh:54
ProGe::ProGeUI::machine_
TTAMachine::Machine * machine_
The loaded machine.
Definition: ProGeUI.hh:114
FileSystem::expandTilde
static std::string expandTilde(const std::string &stringWithTilde)
Definition: FileSystem.cc:217
Application::VERBOSE_LEVEL_INCREASED
static const int VERBOSE_LEVEL_INCREASED
Increased verbose level - print information about modules etc.
Definition: Application.hh:224
GenerateProcessor::string2MemType
MemType string2MemType(const std::string &memoryString) const
Definition: GenerateProcessor.cc:440
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
NONE
@ NONE
Definition: MemoryGenerator.hh:59
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
MemType
MemType
Definition: MemoryGenerator.hh:57
ProGe::ProGeUI::loadBinaryEncoding
void loadBinaryEncoding(const BinaryEncoding &bem)
Definition: ProGeUI.cc:170
ONCHIP
@ ONCHIP
Definition: MemoryGenerator.hh:61
ProGe::ProGeUI::loadMachineImplementation
void loadMachineImplementation(const IDF::MachineImplementation &idf)
Definition: ProGeUI.cc:175
PluginTools::addSearchPath
void addSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:95
FileSystem::fileExists
static bool fileExists(const std::string fileName)
StringTools::chopString
static std::vector< TCEString > chopString(const std::string &source, const std::string &delimiters)
Definition: StringTools.cc:181
ProGe::ProGeUI::loadMachine
void loadMachine(const TTAMachine::Machine &adf)
Definition: ProGeUI.cc:165
UNKNOWN
@ UNKNOWN
Definition: MemoryGenerator.hh:58
Application::VERBOSE_LEVEL_SPAM
static const int VERBOSE_LEVEL_SPAM
More Increased verbose level - spam about ddg heights of loops.
Definition: Application.hh:226
VHDL_ARRAY
@ VHDL_ARRAY
Definition: MemoryGenerator.hh:60
FileSystem::currentWorkingDir
static std::string currentWorkingDir()
Definition: FileSystem.cc:142
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
FileSystem::fileNameBody
static std::string fileNameBody(const std::string &fileName)
Definition: FileSystem.cc:291
TTAMachine::Machine
Definition: Machine.hh:73
CmdLineOptions::isVerboseSpamSwitchDefined
virtual bool isVerboseSpamSwitchDefined() const
Definition: CmdLineOptions.cc:310