torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EdifFlattener.cpp File Reference

Source for the EDIF flattener. More...

#include "torc/Generic.hpp"
#include <fstream>
#include <boost/filesystem.hpp>
+ Include dependency graph for EdifFlattener.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Source for the EDIF flattener.

Definition in file EdifFlattener.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file EdifFlattener.cpp.

25  {
26 
27  // iterate through each EDIF file specified
28  for(int i = 1; i < argc; i++) {
29 
30  // build the file names
31  boost::filesystem::path sourcePath = argv[i];
32  boost::filesystem::path targetPath = sourcePath;
33  targetPath = targetPath.replace_extension().string()
34  + ".flat" + boost::filesystem::extension(sourcePath);
35 
36  try {
37  // read the source file
38  std::cout << "Reading source: " << sourcePath.string() << " ... ";
39  std::cout.flush();
40  boost::shared_ptr<ObjectFactory> factoryPtr(new ObjectFactory());
41  boost::shared_ptr<Root> rootPtr;
42  factoryPtr->create(rootPtr);
43  boost::shared_ptr<Linker> linkerPtr(new Linker(rootPtr));
44  ParserOptions options;
45  EdifParser parser;
46  try {
47  parser.parse(sourcePath.string(), rootPtr, linkerPtr, factoryPtr, options);
48  std::cout << "done." << std::endl;
49  } catch(Error& e) {
50  std::cerr << std::endl;
51  std::cerr << MessageTable::instance()->getMessage(e.getErrorMessageId())
52  << std::endl;
53  const std::vector<Error::StackFrameInfo> &stack = e.getStackTrace();
54  for(std::vector<Error::StackFrameInfo>::const_iterator it = stack.begin();
55  it != stack.end(); it++) {
56  std::cerr << " " << (*it).getFunction() << "() [" << (*it).getFile() << ":"
57  << (*it).getLine() << "]" << std::endl;
58  }
59  }
60 
61  // flatten all designs that are present
62  typedef std::vector<DesignSharedPtr> DesignSharedPtrVector;
63  DesignSharedPtrVector designs;
64  rootPtr->getDesigns(designs);
65  DesignSharedPtrVector::iterator dp = designs.begin();
66  DesignSharedPtrVector::iterator de = designs.end();
67  while(dp < de) {
68  // look up the design name and specifics
69  DesignSharedPtr designPtr = *dp++;
70  std::string designName = designPtr->getName();
71  std::cout << " Flattening design " << designName << " ... ";
72  std::cout.flush();
73  flatten(designPtr, factoryPtr, true);
74  std::cout << "done." << std::endl;
75  }
76 
77  // prune unused cells and libraries
78  prune(rootPtr);
79 
80  // write the target file
81  std::cout << " Writing target: " << targetPath.string() << " ... ";
82  std::cout.flush();
83  std::fstream targetStream(targetPath.string().c_str(), std::ios_base::out);
84  Decompiler decompiler(rootPtr, targetStream);
85  decompiler();
86  std::cout << "done." << std::endl;
87  }
88  // report failure
89  catch(...) {
90  std::cerr << "ERROR: Failed to flatten " << sourcePath.string() << std::endl;
91  }
92  }
93 
94  return 0;
95 }
Bison stack class.
The Top level parser for parsing EDIF files.
Definition: EdifParser.hpp:41
std::vector< DesignSharedPtr > DesignSharedPtrVector
Vector of Design shared pointers.
std::string string
boost::shared_ptr< Design > DesignSharedPtr
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
const std::vector< StackFrameInfo > & getStackTrace() const
Definition: Error.hpp:175
Represents a repository of unresolved usage references.
Definition: Linker.hpp:51
boost::filesystem::path path
void prune(RootSharedPtr &inRootPtr)
Prune all unused cells and libraries from the given root.
Definition: Pruning.cpp:58
const MessageId getErrorMessageId() const
Definition: Error.hpp:195
void flatten(const InstanceSharedPtr &inInstance, const ObjectFactorySharedPtr &inFactory, bool inRecursive, const std::string &inSeparator, const InstanceRenamingFunction &inInstanceRenameFunc, const NetRenamingFunction &inNetRenameFunc, const InstanceNamingFunction &inInstanceNameFunc, const NetNamingFunction &inNetNameFunc)
Definition: Flattening.cpp:739
void parse(const std::string &inFileName, const RootSharedPtr &outRoot, const LinkerSharedPtr &outLinker, const ObjectFactorySharedPtr &inFactory, const ParserOptions &inOptions)
Definition: EdifParser.cpp:40

+ Here is the call graph for this function: