torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical/XdlImporter.hpp
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 Header for the XdlImporter class.
18 
19 #ifndef TORC_PHYSICAL_XDLIMPORTER_HPP
20 #define TORC_PHYSICAL_XDLIMPORTER_HPP
21 
22 // The foundation of this code comes from Timo Bingmann's Flex Bison C++ Template/Example,
23 // available at http://idlebox.net/2007/flex-bison-cpp-example.
24 
25 #include "torc/physical/Design.hpp"
26 #include <boost/smart_ptr.hpp>
27 #include <boost/filesystem.hpp>
28 #include <string>
29 #include <vector>
30 
31 // forward declarations of friends outside our namespace.
32 namespace torc {
33  class XdlParser;
34  class XdlScanner;
35  class location;
36 } // torc
37 
38 namespace torc {
39 namespace physical {
40 
41 namespace physical { class XdlImporterUnitTest; }
42 
43  /// \brief Importer from XDL format into a physical design.
44  /// \details The XdlImporter creates the XdlParser and XdlScanner classes and connects them.
45  /// The input stream is then fed into the scanner object, which delivers a sequence of
46  /// tokens to the parser. The importer is also available as a parameter to the grammar
47  /// rules.
48  class XdlImporter {
49 
50  // friends
51  /// \brief The unit test class has access to our internals.
53 
54  // types
55  /// \brief Imported type name.
57  /// \brief Imported type name.
58  typedef std::istream istream;
59 
60  public:
61  // constructors
62  /// \brief Construct the parser importer context.
63  XdlImporter(void);
64  /// \brief Virtual destructor.
65  virtual ~XdlImporter(void) {}
66 
67  // members
68  /// \brief Enable debug output in the flex scanner.
70  /// \brief Enable debug output in the bison parser.
72  /// \brief Name of file or input stream for error messages.
73  string mStreamName;
74  /// \brief Pointer to the current lexer instance.
75  /// \details This serves to connect the parser to the scanner, and is used by the yylex
76  /// macro.
78 
79  // macros
80  /// \cond OMIT_FROM_DOXYGEN
81  // Doxygen gets confused by the explicit "__attribute__ ((deprecated))" so we used this
82  #define DEPRECATED __attribute__ ((deprecated))
83  /// \endcond
84 
85  // operators
86  /// \brief Import XDL from an input stream.
87  /// \param in Input stream.
88  /// \param name Stream name to use for error messages.
89  /// \returns true if successfully parsed.
90  /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(stream,
91  /// name);
92  DEPRECATED bool import(istream& in, const string& name = "stream input")
93  { return (*this)(in, name); }
94  /// \brief Import XDL from an input stream.
95  /// \param in Input stream.
96  /// \param name Stream name to use for error messages.
97  /// \returns true if successfully parsed.
98  bool operator()(istream& in, const string& name = "stream input");
99 
100  /// \brief Import XDL from a string.
101  /// \param input Input stream.
102  /// \param name Stream name to use for error messages.
103  /// \returns true if successfully parsed.
104  /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(input,
105  /// name);
106  DEPRECATED bool import(const string& input, const string& name = "string stream")
107  { return (*this)(input, name); }
108  /// \brief Import XDL from a string.
109  /// \param input Input stream.
110  /// \param name Stream name to use for error messages.
111  /// \returns true if successfully parsed.
112  bool operator()(const string& input, const string& name = "string stream");
113 
114  /// \brief Import XDL from a file.
115  /// \param filename Input file name.
116  /// \returns true if successfully parsed.
117  /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(filename);
118  DEPRECATED bool import(const boost::filesystem::path& filename)
119  { return (*this)(filename); }
120  /// \brief Import XDL from a file.
121  /// \param filename Input file name.
122  /// \returns true if successfully parsed.
123  bool operator()(const boost::filesystem::path& filename);
124 
125  // functions
126  // To demonstrate pure handling of parse errors, instead of
127  // simply dumping them on the standard error output, we will pass
128  // them to the importer using the following two member functions.
129  /// \brief Error handling with associated line number.
130  /// \details This can be modified to output the error in another manner, for example to a
131  /// dialog box.
132  void error(const location& l, const string& m);
133  /// \brief General error handling.
134  /// \details This can be modified to output the error in another manner, for example to a
135  /// dialog box.
136  void error(const string& m);
137  /// \brief Signals a parsing failure by deasserting the success flag.
138  void failure(void) { mSuccess = false; }
139 
140  // accessors
141  /// \brief Returns a shared pointer for the design.
142  /// \details This design is created and populated during XDL import process.
144 
145  protected:
146  // friends
147  /// \brief The XdlParse has access to our members.
148  friend class torc::XdlParser;
149 
150  // enums
151  /// \brief The pip type, either regular or routethrough.
153 
154  // members
155  // error flags
156  bool mSuccess; ///< Flag signaling parsing success.
157 
158  // design variables
159  string mDesignName; ///< Name of the design.
160  string mDesignPart; ///< Device, package, and speed grade specified for the design.
161  string mDesignDevice; ///< Device specified for the design.
162  string mDesignPackage; ///< Package specified for the design.
163  string mDesignSpeedGrade; ///< Speed grade specified for the design.
164  string mDesignXdlVersion; ///< XDL version read in by the design.
165  DesignSharedPtr mDesignPtr; ///< Shared pointer to the design.
166  CircuitWeakPtr mCircuitPtr; ///< Weak pointer to the circuit.
167 
168  // module variables
169  boost::uint32_t mModuleCount; ///< Number of modules read for the design.
170  string mModuleName; ///< Name of the module.
171  string mModuleAnchor; ///< Module anchor instance name.
172  string mModuleInstance; ///< Name of instantiating instance for module reference.
173  ModuleSharedPtr mModulePtr; ///< Shared pointer to the current module.
174 
175  // instance reference variables
176  string mReferenceInstantiation; ///< Name under which the module was instantiated.
177  string mReferenceModule; ///< Name of the referenced module.
178  string mReferenceInstance; ///< Name of the referenced instance.
179  ModuleSharedPtr mReferenceModulePtr; ///< Shared pointer to the referenced module.
180  InstanceSharedPtr mReferenceInstancePtr; ///< Shared pointer to the referenced instance.
181  InstanceReferenceSharedPtr mInstanceReferencePtr; ///< Shared pointer to instance reference.
182 
183  // port variables
184  string mPortName; ///< Name of the port.
185  string mPortInstance; ///< Current port instance name.
186  string mPortPin; ///< Current port pin name.
187  PortTempVector mPortTempVector; ///< Vector of ports not yet mapped to instances.
188 
189  // instance variables
190  boost::uint32_t mInstanceCount; ///< Number of instances read for the design.
191  string mInstanceName; ///< Current instance name.
192  TileTypeName mInstanceType; ///< Current instance type.
193  SiteName mInstanceSite; ///< Current instance site name.
194  TileName mInstanceTile; ///< Current instance tile name.
195  torc::physical::EInstanceBonding mInstanceBonding; ///< Current instance bonding.
196  InstanceSharedPtr mInstancePtr; ///< Shared pointer to the current instance.
197 
198  // net variables
199  boost::uint32_t mNetCount; ///< Number of nets read for the design.
200  torc::physical::ENetType mNetType; ///< Current net type.
201  string mNetName; ///< Current net name.
202  NetSharedPtr mNetPtr; ///< Shared pointer to the current net.
203 
204  // pin variables
205  InstanceName mPinInstance; ///< Current pin instance name.
206  PinName mPinName; ///< Current pin name.
207  torc::physical::EPinDirection mPinDirection; ///< Current pin direction.
208 
209  // pip variables
210  TileName mPipTile; ///< Current pip tile name.
211  WireName mPipSource; ///< Current pip source wire name.
212  WireName mPipSink; ///< Current pip sink wire name.
213  torc::physical::EPipDirection mPipDirection; ///< Current pip directionality.
214 
215  // routethrough variables
216  string mRoutethroughConfigSetting; ///< Current routethrough config setting.
217  string mRoutethroughConfigName; ///< Current routethrough config name.
218  string mRoutethroughConfigValue; ///< Current routethrough config value.
219  string mRoutethroughInstance; ///< Current routethrough Instance name.
220  WireName mRoutethroughSource; ///< Current routethrough source wire name.
221  WireName mRoutethroughSink; ///< Current routethrough sink wire name.
222 
223  // config variables
224  boost::uint32_t mConfigCount; ///< Number of configurations read for the design.
225  ConfigMap mConfigMap; ///< Current config map.
226  string mConfigSetting; ///< Current config setting.
227  string mConfigName; ///< Current config name.
228  string mConfigValue; ///< Current config value.
229 
230  // functions
231  /// \brief Initialize the database if applicable.
232  /// \details Only the torc::architecture::XdlImporter subclass actually initializes the
233  /// database.
234  virtual void initializeDatabase(void) {}
235  /// \brief Bind the given instance pin to its database Tilewire if applicable.
237  /// \brief Bind the given pip to the database arc and wire usage if applicable.
238  virtual void bind(torc::physical::Pip&, EPipType) {}
239  };
240 
241 } // namespace physical
242 } // namespace torc
243 
244 #endif // TORC_PHYSICAL_XDLIMPORTER_HPP
A Bison parser.
Definition: XdlParser.hpp:149
torc::physical::ENetType mNetType
Current net type.
ENetType
Enumeration of net power types.
void failure(void)
Signals a parsing failure by deasserting the success flag.
boost::weak_ptr< Circuit > CircuitWeakPtr
Weak pointer encapsulation of a Circuit.
Definition: Circuit.hpp:222
string mDesignPackage
Package specified for the design.
friend class torc::physical::physical::XdlImporterUnitTest
The unit test class has access to our internals.
SiteName mInstanceSite
Current instance site name.
string mReferenceModule
Name of the referenced module.
InstanceSharedPtr mReferenceInstancePtr
Shared pointer to the referenced instance.
Encapsulation of a wire name.
EInstanceBonding
Enumeration of pad bonding types.
string mDesignXdlVersion
XDL version read in by the design.
boost::uint32_t mInstanceCount
Number of instances read for the design.
ModuleSharedPtr mReferenceModulePtr
Shared pointer to the referenced module.
string mDesignDevice
Device specified for the design.
string mPortName
Name of the port.
torc::physical::EInstanceBonding mInstanceBonding
Current instance bonding.
string mRoutethroughConfigSetting
Current routethrough config setting.
DesignSharedPtr getDesignPtr(void)
Returns a shared pointer for the design.
Encapsulation of a site name.
Encapsulation of a site pin name.
string mDesignSpeedGrade
Speed grade specified for the design.
string mInstanceName
Current instance name.
virtual void bind(torc::physical::Pip &, EPipType)
Bind the given pip to the database arc and wire usage if applicable.
string mPortPin
Current port pin name.
std::string string
Imported type name.
bool mTraceScanning
Enable debug output in the flex scanner.
bool mSuccess
Flag signaling parsing success.
PinName mPinName
Current pin name.
Encapsulation of a tile name.
TileName mPipTile
Current pip tile name.
ModuleSharedPtr mModulePtr
Shared pointer to the current module.
ConfigMap mConfigMap
Current config map.
TileName mInstanceTile
Current instance tile name.
XdlImporter(void)
Construct the parser importer context.
WireName mRoutethroughSource
Current routethrough source wire name.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
boost::uint32_t mConfigCount
Number of configurations read for the design.
std::string string
string mReferenceInstance
Name of the referenced instance.
void error(const location &l, const string &m)
Error handling with associated line number.
InstanceReferenceSharedPtr mInstanceReferencePtr
Shared pointer to instance reference.
boost::shared_ptr< Module > ModuleSharedPtr
Shared pointer encapsulation of a Module.
Definition: Module.hpp:114
EPipType
The pip type, either regular or routethrough.
class torc::XdlScanner * lexer
Pointer to the current lexer instance.
string mConfigName
Current config name.
boost::uint32_t mModuleCount
Number of modules read for the design.
Header for the Design class.
bool mTraceParsing
Enable debug output in the bison parser.
Encapsulation of an instance name.
std::istream istream
Imported type name.
CircuitWeakPtr mCircuitPtr
Weak pointer to the circuit.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
string mDesignPart
Device, package, and speed grade specified for the design.
TileTypeName mInstanceType
Current instance type.
string mRoutethroughInstance
Current routethrough Instance name.
string mStreamName
Name of file or input stream for error messages.
boost::filesystem::path path
virtual ~XdlImporter(void)
Virtual destructor.
DesignSharedPtr mDesignPtr
Shared pointer to the design.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
virtual void bind(torc::physical::InstancePinSharedPtr &)
Bind the given instance pin to its database Tilewire if applicable.
std::vector< PortTemp > PortTempVector
Vector.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
PortTempVector mPortTempVector
Vector of ports not yet mapped to instances.
NetSharedPtr mNetPtr
Shared pointer to the current net.
string mModuleInstance
Name of instantiating instance for module reference.
Physical design programmable interconnect point.
Definition: Pip.hpp:34
string mNetName
Current net name.
WireName mPipSink
Current pip sink wire name.
string mReferenceInstantiation
Name under which the module was instantiated.
Configuration setting map.
Definition: ConfigMap.hpp:39
InstanceName mPinInstance
Current pin instance name.
bool operator()(istream &in, const string &name="stream input")
Import XDL from an input stream.
WireName mPipSource
Current pip source wire name.
virtual void initializeDatabase(void)
Initialize the database if applicable.
Importer from XDL format into a physical design.
boost::uint32_t mNetCount
Number of nets read for the design.
torc::physical::EPipDirection mPipDirection
Current pip directionality.
string mModuleAnchor
Module anchor instance name.
string mModuleName
Name of the module.
EPipDirection
Enumeration of pip directionality.
string mDesignName
Name of the design.
Encapsulation of a tile type name.
string mRoutethroughConfigName
Current routethrough config name.
string mConfigValue
Current config value.
boost::shared_ptr< InstanceReference > InstanceReferenceSharedPtr
Shared pointer encapsulation of an InstanceReference.
EPinDirection
Enumeration of instance pin directionality.
torc::physical::EPinDirection mPinDirection
Current pin direction.
InstanceSharedPtr mInstancePtr
Shared pointer to the current instance.
string mConfigSetting
Current config setting.
string mRoutethroughConfigValue
Current routethrough config value.
string mPortInstance
Current port instance name.
WireName mRoutethroughSink
Current routethrough sink wire name.