torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical/XdlImporter.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 XdlImporter class.
18 
21 #include <fstream>
22 #include <sstream>
23 
24 namespace torc {
25 namespace physical {
26 
27  using namespace std;
28  using namespace torc;
29 
30  XdlImporter::XdlImporter(void) : mTraceScanning(false), mTraceParsing(false),
31  mDesignName(), mDesignPart(), mDesignDevice(), mDesignPackage(), mDesignSpeedGrade(),
32  mDesignXdlVersion(), mDesignPtr(), mCircuitPtr(), mModuleCount(0), mModuleName(""),
33  mModuleAnchor(""), mModuleInstance(""), mModulePtr(), mReferenceInstantiation(""),
34  mReferenceModule(""), mReferenceInstance(""), mReferenceModulePtr(),
35  mReferenceInstancePtr(), mInstanceReferencePtr(), mPortName(""), mPortInstance(""),
36  mPortPin(""), mInstanceCount(0), mInstanceName(), mInstanceType(""), mInstanceSite(""),
37  mInstanceTile(""), mInstanceBonding(eInstanceBondingUnknown), mNetCount(0),
38  mNetType(eNetTypeNormal), mNetName(), mPinInstance(""), mPinName(""),
39  mPinDirection(ePinDirectionUnknown), mPipTile(""), mPipSource(""), mPipSink(""),
40  mPipDirection(static_cast<EPipDirection>(0)), mRoutethroughConfigSetting(),
41  mRoutethroughConfigName(), mRoutethroughConfigValue(), mRoutethroughInstance(),
42  mRoutethroughSource(""), mRoutethroughSink(""), mConfigCount(0), mConfigSetting(),
43  mConfigName(), mConfigValue() {
44  // assume success unless we encounter an error
45  mSuccess = true;
46  }
47 
48  bool XdlImporter::operator()(istream& in, const string& name) {
49  mStreamName = name;
50 
51  // reset all counts before importing
52  mModuleCount = 0;
53  mInstanceCount = 0;
54  mNetCount = 0;
55  mConfigCount = 0;
56 
57  XdlScanner scanner(&in);
58  scanner.set_debug(mTraceScanning);
59  this->lexer = &scanner;
60 
61  XdlParser parser(*this);
63  bool result = parser.parse() == 0;
64  return mSuccess && result;
65  }
66 
68  string pathname = path.string();
69  ifstream in(pathname.c_str());
70  if(!in.good()) return false;
71  return (*this)(in, pathname);
72  }
73 
74  bool XdlImporter::operator()(const string &input, const string& name) {
75  istringstream iss(input);
76  return (*this)(iss, name);
77  }
78 
79  void XdlImporter::error(const location& l, const string& m) {
80  failure();
81  cerr << l << ": " << m << std::endl;
82  }
83 
84  void XdlImporter::error(const string& m) {
85  failure();
86  cerr << m << std::endl;
87  }
88 
89 } // namespace physical
90 } // namespace torc
91 
92 //namespace {
93 // /// \brief Suppress GCC warnings about unused boost global variables.
94 // void suppress_boost_gcc_warnings(void);
95 // void suppress_boost_gcc_warnings(void) {
96 // (void) boost::system::system_category;
97 // (void) boost::system::generic_category;
98 // (void) boost::system::posix_category;
99 // (void) boost::system::errno_ecat;
100 // (void) boost::system::native_ecat;
101 // }
102 //}
A Bison parser.
Definition: XdlParser.hpp:149
void failure(void)
Signals a parsing failure by deasserting the success flag.
boost::uint32_t mInstanceCount
Number of instances read for the design.
bool mTraceScanning
Enable debug output in the flex scanner.
bool mSuccess
Flag signaling parsing success.
XdlImporter(void)
Construct the parser importer context.
boost::uint32_t mConfigCount
Number of configurations read for the design.
void error(const location &l, const string &m)
Error handling with associated line number.
Header for the XdlImporter class.
class torc::XdlScanner * lexer
Pointer to the current lexer instance.
boost::uint32_t mModuleCount
Number of modules read for the design.
bool mTraceParsing
Enable debug output in the bison parser.
void set_debug(bool b)
Enables or disables debugging output.
std::istream istream
Imported type name.
string mStreamName
Name of file or input stream for error messages.
boost::filesystem::path path
virtual int parse()
Definition: XdlParser.cpp:242
bool operator()(istream &in, const string &name="stream input")
Import XDL from an input stream.
Header for the XdlScanner class.
boost::uint32_t mNetCount
Number of nets read for the design.
EPipDirection
Enumeration of pip directionality.
void set_debug_level(debug_level_type l)
Set the current debugging level.
Definition: XdlParser.cpp:235