torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::VerilogImporter Class Reference

Importer from structural verilog format into a generic design. More...

#include <VerilogImporter.hpp>

+ Collaboration diagram for torc::generic::VerilogImporter:

Public Member Functions

 VerilogImporter (void)
 Construct the parser importer context. More...
 
bool operator() (const boost::filesystem::path &inFilename, const std::string &inArguments=std::string())
 Import Verilog from a file. More...
 
void failure (void)
 Signals a parsing failure by deasserting the success flag. More...
 
RootSharedPtr getRootPtr (void)
 Returns a shared pointer for the root. More...
 

Protected Types

typedef std::string string
 Imported type name. More...
 

Protected Attributes

string mStreamName
 Name of file or input stream for error messages. More...
 
bool mSuccess
 Flag signaling parsing success. More...
 
RootSharedPtr mRootPtr
 Root of generic netlist. More...
 

Friends

class torc::generic::generic::VerilogImporterUnitTest
 The unit test class has access to our internals. More...
 

Detailed Description

Importer from structural verilog format into a generic design.

Definition at line 38 of file VerilogImporter.hpp.

Member Typedef Documentation

typedef std::string torc::generic::VerilogImporter::string
protected

Imported type name.

Definition at line 45 of file VerilogImporter.hpp.

Constructor & Destructor Documentation

torc::generic::VerilogImporter::VerilogImporter ( void  )

Construct the parser importer context.

Definition at line 92 of file VerilogImporter.cpp.

92  {
93  // assume success unless we encounter an error
94  mSuccess = true;
95  }
bool mSuccess
Flag signaling parsing success.

Member Function Documentation

void torc::generic::VerilogImporter::failure ( void  )
inline

Signals a parsing failure by deasserting the success flag.

Definition at line 67 of file VerilogImporter.hpp.

67 { mSuccess = false; }
bool mSuccess
Flag signaling parsing success.
RootSharedPtr torc::generic::VerilogImporter::getRootPtr ( void  )
inline

Returns a shared pointer for the root.

This root is created and populated during verilog import process.

Definition at line 71 of file VerilogImporter.hpp.

71 { return mRootPtr; }
RootSharedPtr mRootPtr
Root of generic netlist.

+ Here is the caller graph for this function:

bool torc::generic::VerilogImporter::operator() ( const boost::filesystem::path &  inFilename,
const std::string &  inArguments = std::string() 
)

Import Verilog from a file.

Parameters
inFilenameInput file name.
inArgumentsAdditional Verilator command line arguments.
Returns
true if successfully parsed.
Todo:
Release the arguments in argv after use with free()

Definition at line 97 of file VerilogImporter.cpp.

98  {
99 
100  int argc = 0;
101  char* env[] = {
102  0
103  };
104  std::string arguments =
105  "./VerilogImporter "
106  + inFilename.string()
107  + " --cc "
108  + "-Itorc/externals/verilator/include "
109  // + "--dump-tree "
110  ;
111  // combine the local arguments and the user supplied arguments
112  std::string input = arguments + " " + inArguments;
113  // tokenize just so we can count arguments (so much uglier than it should be ...)
114  boost::char_separator<char> sep(" ");
115  boost::tokenizer< boost::char_separator<char> > tokens(input, sep);
116  typedef boost::token_iterator_generator< boost::char_separator<char> >::type Iterator;
117  Iterator p = boost::make_token_iterator<string>(input.begin(), input.end(), sep);
118  Iterator e = boost::make_token_iterator<string>(input.end(), input.end(), sep);
119  while(p != e) { *p++; argc++; }
120  // declare an array of sufficient size
121  char* argv[argc];
122  // put all of the arguments into the array
123  argc = 0;
124  BOOST_FOREACH(const string& t, tokens) { argv[argc++] = strdup(t.c_str()); }
125  /// \todo Release the arguments in argv after use with free()
126 
127  // General initialization
128  ios::sync_with_stdio();
129 
130  // enable the following if we ever allow command line -D definitions
131  V3PreShell::boot(env);
132 
133  // parse command line options
134  v3Global.opt.bin(argv[0]);
135  string argString = V3Options::argString(argc-1, argv+1);
136  v3Global.opt.parseOpts(new FileLine("COMMAND_LINE",0), argc-1, argv+1);
137  if(!v3Global.opt.outFormatOk() && !v3Global.opt.preprocOnly() && !v3Global.opt.lintOnly()
138  && !v3Global.opt.cdc()) {
139  v3fatal("verilator: Need --cc, --sc, --sp, --cdc, --lint-only or --E option");
140  }
141  // release memory allocated for the command line arguments
142  while(argc) { free(argv[--argc]); }
143 
144  // extract environment variables
145  V3Options::getenvSYSTEMC();
146  V3Options::getenvSYSTEMC_ARCH();
147  V3Options::getenvSYSTEMC_INCLUDE();
148  V3Options::getenvSYSTEMC_LIBDIR();
149  V3Options::getenvSYSTEMPERL();
150  V3Options::getenvSYSTEMPERL_INCLUDE();
151 
152  V3Error::abortIfErrors();
153 
154  V3File::addSrcDepend(v3Global.opt.bin());
155 
156  // Internal tests (after option parsing as need debug() setting)
157  V3Graph::test();
158 
159  // Read first filename
160  v3Global.readFiles();
161 
162  // restore C++ and C io to their default unsyncronized state
163  ios::sync_with_stdio(false);
164 
165  // create a Generic object factory and root
167  mRootPtr = objectFactoryPtr->newRootPtr("WORK");
168 
169  // visit the abstract syntax tree and extract the generic netlist representation
170  torc::generic::VerilogImporterVisitor verilogImporterVisitor(objectFactoryPtr, mRootPtr);
171  v3Global.rootp()->accept(verilogImporterVisitor);
172 
173  // export the EDIF design
174  string outFileName = "output.edf";
175  fstream edifExport(outFileName.c_str(), ios_base::out);
176  torc::generic::EdifExporter exporter(edifExport);
177  exporter(mRootPtr);
178 
179  return mSuccess;
180  }
bool mSuccess
Flag signaling parsing success.
boost::shared_ptr< ObjectFactory > ObjectFactorySharedPtr
std::string string
RootSharedPtr mRootPtr
Root of generic netlist.
AST visitor to convert structural Verilog into a generic design.
V3Global v3Global
Global variables for Verilator.

Friends And Related Function Documentation

friend class torc::generic::generic::VerilogImporterUnitTest
friend

The unit test class has access to our internals.

Definition at line 42 of file VerilogImporter.hpp.

Field Documentation

RootSharedPtr torc::generic::VerilogImporter::mRootPtr
protected

Root of generic netlist.

Definition at line 53 of file VerilogImporter.hpp.

string torc::generic::VerilogImporter::mStreamName
protected

Name of file or input stream for error messages.

Definition at line 48 of file VerilogImporter.hpp.

bool torc::generic::VerilogImporter::mSuccess
protected

Flag signaling parsing success.

Definition at line 51 of file VerilogImporter.hpp.


The documentation for this class was generated from the following files: