torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EdifFlattener.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Source for the EDIF flattener.
18 
19 #include "torc/Generic.hpp"
20 #include <fstream>
21 #include <boost/filesystem.hpp>
22 
23 using namespace torc::generic;
24 
25 int main(int argc, char** argv) {
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;
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 }
int main(int argc, char **argv)
Bison stack class.
static MessageTable * instance()
Main torc::generic namespace header.
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
std::string getMessage(MessageId inId) const
void parse(const std::string &inFileName, const RootSharedPtr &outRoot, const LinkerSharedPtr &outLinker, const ObjectFactorySharedPtr &inFactory, const ParserOptions &inOptions)
Definition: EdifParser.cpp:40