torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GenericExample.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 Example program to read in an EDIF file, do something with it, and write it back out.
18 
19 #include "torc/Generic.hpp"
20 #include "torc/Common.hpp"
21 #include <fstream>
22 #include <boost/regex.hpp>
23 
24 using namespace std;
25 using namespace torc::generic;
26 
27 int main(int argc, char* argv[]) {
28 
29  // build the file paths
30  (void) argc;
31  torc::common::DirectoryTree directoryTree(argv[0]);
33  boost::filesystem::path referencePath =
34  executablePath / "torc" / "examples" / "GenericExample.reference.edf";
35  boost::filesystem::path generatedPath =
36  executablePath / "regression" / "GenericExample.generated.edf";
37 
38  // import the EDIF design
39  string inFileName = referencePath.string();
40  fstream fileStream(inFileName.c_str());
41  ObjectFactorySharedPtr factoryPtr(new ObjectFactory());
42  EdifImporter importer(factoryPtr);
43  importer(fileStream, inFileName);
44 
45  // look up an instance of interest
46  RootSharedPtr rootPtr = importer.getRootPtr();
47  InstanceSharedPtr instancePtr = rootPtr->findLibrary("work")->findCell("and")
48  ->findView("verilog")->findInstance("oZ0");
49 
50  // change the INIT property (LUT mask) to XOR
51  PropertySharedPtr initPropertyPtr = instancePtr->getProperty("INIT");
52  string originalMask = initPropertyPtr->getValue().get<Value::String>();
53  std::cout << "The original LUT mask was \"" << originalMask << "\"." << std::endl;
54  Value xorMask(Value::eValueTypeString, string("6"));
55  initPropertyPtr->setValue(xorMask);
56 
57  // export the EDIF design
58  string outFileName = generatedPath.string();
59  fstream edifExport(outFileName.c_str(), ios_base::out);
60  EdifExporter exporter(edifExport);
61  exporter(rootPtr);
62 
63  return 0;
64 }
boost::shared_ptr< Instance > InstanceSharedPtr
Main torc::generic namespace header.
int main(int argc, char *argv[])
boost::shared_ptr< ObjectFactory > ObjectFactorySharedPtr
std::string String
Definition: Value.hpp:61
Encapsulation of filesystem paths that are used by the library.
boost::filesystem::path path
RootSharedPtr getRootPtr(void)
Definition: Generic.hpp:162
boost::shared_ptr< Property > PropertySharedPtr
Main torc::common namespace header.
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.
boost::shared_ptr< Root > RootSharedPtr