00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/physical/XdlImporter.hpp $ 00003 // $Id: XdlImporter.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Header for the XdlImporter class. 00018 00019 #ifndef TORC_PHYSICAL_XDLIMPORTER_HPP 00020 #define TORC_PHYSICAL_XDLIMPORTER_HPP 00021 00022 // The foundation of this code comes from Timo Bingmann's Flex Bison C++ Template/Example, 00023 // available at http://idlebox.net/2007/flex-bison-cpp-example. 00024 00025 #include "torc/physical/Design.hpp" 00026 #include <boost/smart_ptr.hpp> 00027 #include <boost/filesystem.hpp> 00028 #include <string> 00029 #include <vector> 00030 00031 // forward declarations of friends outside our namespace. 00032 namespace torc { 00033 class XdlParser; 00034 class XdlScanner; 00035 class location; 00036 } // torc 00037 00038 namespace torc { 00039 namespace physical { 00040 00041 namespace physical { class XdlImporterUnitTest; } 00042 00043 /// \brief Importer from XDL format into a physical design. 00044 /// \details The XdlImporter creates the XdlParser and XdlScanner classes and connects them. 00045 /// The input stream is then fed into the scanner object, which delivers a sequence of 00046 /// tokens to the parser. The importer is also available as a parameter to the grammar 00047 /// rules. 00048 class XdlImporter { 00049 00050 // friends 00051 /// \brief The unit test class has access to our internals. 00052 friend class torc::physical::physical::XdlImporterUnitTest; 00053 00054 // types 00055 /// \brief Imported type name. 00056 typedef std::string string; 00057 /// \brief Imported type name. 00058 typedef std::istream istream; 00059 00060 public: 00061 // constructors 00062 /// \brief Construct the parser importer context. 00063 XdlImporter(void); 00064 /// \brief Virtual destructor. 00065 virtual ~XdlImporter(void) {} 00066 00067 // members 00068 /// \brief Enable debug output in the flex scanner. 00069 bool mTraceScanning; 00070 /// \brief Enable debug output in the bison parser. 00071 bool mTraceParsing; 00072 /// \brief Name of file or input stream for error messages. 00073 string mStreamName; 00074 /// \brief Pointer to the current lexer instance. 00075 /// \details This serves to connect the parser to the scanner, and is used by the yylex 00076 /// macro. 00077 class torc::XdlScanner* lexer; 00078 00079 // macros 00080 /// \cond OMIT_FROM_DOXYGEN 00081 // Doxygen gets confused by the explicit "__attribute__ ((deprecated))" so we used this 00082 #define DEPRECATED __attribute__ ((deprecated)) 00083 /// \endcond 00084 00085 // operators 00086 /// \brief Import XDL from an input stream. 00087 /// \param in Input stream. 00088 /// \param name Stream name to use for error messages. 00089 /// \returns true if successfully parsed. 00090 /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(stream, 00091 /// name); 00092 DEPRECATED bool import(istream& in, const string& name = "stream input") 00093 { return (*this)(in, name); } 00094 /// \brief Import XDL from an input stream. 00095 /// \param in Input stream. 00096 /// \param name Stream name to use for error messages. 00097 /// \returns true if successfully parsed. 00098 bool operator()(istream& in, const string& name = "stream input"); 00099 00100 /// \brief Import XDL from a string. 00101 /// \param input Input stream. 00102 /// \param name Stream name to use for error messages. 00103 /// \returns true if successfully parsed. 00104 /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(input, 00105 /// name); 00106 DEPRECATED bool import(const string& input, const string& name = "string stream") 00107 { return (*this)(input, name); } 00108 /// \brief Import XDL from a string. 00109 /// \param input Input stream. 00110 /// \param name Stream name to use for error messages. 00111 /// \returns true if successfully parsed. 00112 bool operator()(const string& input, const string& name = "string stream"); 00113 00114 /// \brief Import XDL from a file. 00115 /// \param filename Input file name. 00116 /// \returns true if successfully parsed. 00117 /// \deprecated Please use operator()(...) instead of import(...). i.e. importer(filename); 00118 DEPRECATED bool import(const boost::filesystem::path& filename) 00119 { return (*this)(filename); } 00120 /// \brief Import XDL from a file. 00121 /// \param filename Input file name. 00122 /// \returns true if successfully parsed. 00123 bool operator()(const boost::filesystem::path& filename); 00124 00125 // functions 00126 // To demonstrate pure handling of parse errors, instead of 00127 // simply dumping them on the standard error output, we will pass 00128 // them to the importer using the following two member functions. 00129 /// \brief Error handling with associated line number. 00130 /// \details This can be modified to output the error in another manner, for example to a 00131 /// dialog box. 00132 void error(const location& l, const string& m); 00133 /// \brief General error handling. 00134 /// \details This can be modified to output the error in another manner, for example to a 00135 /// dialog box. 00136 void error(const string& m); 00137 /// \brief Signals a parsing failure by deasserting the success flag. 00138 void failure(void) { mSuccess = false; } 00139 00140 // accessors 00141 /// \brief Returns a shared pointer for the design. 00142 /// \details This design is created and populated during XDL import process. 00143 DesignSharedPtr getDesignPtr(void) { return mDesignPtr; } 00144 00145 protected: 00146 // friends 00147 /// \brief The XdlParse has access to our members. 00148 friend class torc::XdlParser; 00149 00150 // enums 00151 /// \brief The pip type, either regular or routethrough. 00152 enum EPipType { ePipTypeRegular = 0, ePipTypeRoutethrough }; 00153 00154 // members 00155 // error flags 00156 bool mSuccess; ///< Flag signaling parsing success. 00157 00158 // design variables 00159 string mDesignName; ///< Name of the design. 00160 string mDesignPart; ///< Device, package, and speed grade specified for the design. 00161 string mDesignDevice; ///< Device specified for the design. 00162 string mDesignPackage; ///< Package specified for the design. 00163 string mDesignSpeedGrade; ///< Speed grade specified for the design. 00164 string mDesignXdlVersion; ///< XDL version read in by the design. 00165 DesignSharedPtr mDesignPtr; ///< Shared pointer to the design. 00166 CircuitWeakPtr mCircuitPtr; ///< Weak pointer to the circuit. 00167 00168 // module variables 00169 boost::uint32_t mModuleCount; ///< Number of modules read for the design. 00170 string mModuleName; ///< Name of the module. 00171 string mModuleAnchor; ///< Module anchor instance name. 00172 string mModuleInstance; ///< Name of instantiating instance for module reference. 00173 ModuleSharedPtr mModulePtr; ///< Shared pointer to the current module. 00174 00175 // instance reference variables 00176 string mReferenceInstantiation; ///< Name under which the module was instantiated. 00177 string mReferenceModule; ///< Name of the referenced module. 00178 string mReferenceInstance; ///< Name of the referenced instance. 00179 ModuleSharedPtr mReferenceModulePtr; ///< Shared pointer to the referenced module. 00180 InstanceSharedPtr mReferenceInstancePtr; ///< Shared pointer to the referenced instance. 00181 InstanceReferenceSharedPtr mInstanceReferencePtr; ///< Shared pointer to instance reference. 00182 00183 // port variables 00184 string mPortName; ///< Name of the port. 00185 string mPortInstance; ///< Current port instance name. 00186 string mPortPin; ///< Current port pin name. 00187 PortTempVector mPortTempVector; ///< Vector of ports not yet mapped to instances. 00188 00189 // instance variables 00190 boost::uint32_t mInstanceCount; ///< Number of instances read for the design. 00191 string mInstanceName; ///< Current instance name. 00192 TileTypeName mInstanceType; ///< Current instance type. 00193 SiteName mInstanceSite; ///< Current instance site name. 00194 TileName mInstanceTile; ///< Current instance tile name. 00195 torc::physical::EInstanceBonding mInstanceBonding; ///< Current instance bonding. 00196 InstanceSharedPtr mInstancePtr; ///< Shared pointer to the current instance. 00197 00198 // net variables 00199 boost::uint32_t mNetCount; ///< Number of nets read for the design. 00200 torc::physical::ENetType mNetType; ///< Current net type. 00201 string mNetName; ///< Current net name. 00202 NetSharedPtr mNetPtr; ///< Shared pointer to the current net. 00203 00204 // pin variables 00205 InstanceName mPinInstance; ///< Current pin instance name. 00206 PinName mPinName; ///< Current pin name. 00207 torc::physical::EPinDirection mPinDirection; ///< Current pin direction. 00208 00209 // pip variables 00210 TileName mPipTile; ///< Current pip tile name. 00211 WireName mPipSource; ///< Current pip source wire name. 00212 WireName mPipSink; ///< Current pip sink wire name. 00213 torc::physical::EPipDirection mPipDirection; ///< Current pip directionality. 00214 00215 // routethrough variables 00216 string mRoutethroughConfigSetting; ///< Current routethrough config setting. 00217 string mRoutethroughConfigName; ///< Current routethrough config name. 00218 string mRoutethroughConfigValue; ///< Current routethrough config value. 00219 string mRoutethroughInstance; ///< Current routethrough Instance name. 00220 WireName mRoutethroughSource; ///< Current routethrough source wire name. 00221 WireName mRoutethroughSink; ///< Current routethrough sink wire name. 00222 00223 // config variables 00224 boost::uint32_t mConfigCount; ///< Number of configurations read for the design. 00225 ConfigMap mConfigMap; ///< Current config map. 00226 string mConfigSetting; ///< Current config setting. 00227 string mConfigName; ///< Current config name. 00228 string mConfigValue; ///< Current config value. 00229 00230 // functions 00231 /// \brief Initialize the database if applicable. 00232 /// \details Only the torc::architecture::XdlImporter subclass actually initializes the 00233 /// database. 00234 virtual void initializeDatabase(void) {} 00235 /// \brief Bind the given instance pin to its database Tilewire if applicable. 00236 virtual void bind(torc::physical::InstancePinSharedPtr&) {} 00237 /// \brief Bind the given pip to the database arc and wire usage if applicable. 00238 virtual void bind(torc::physical::Pip&, EPipType) {} 00239 }; 00240 00241 } // namespace physical 00242 } // namespace torc 00243 00244 #endif // TORC_PHYSICAL_XDLIMPORTER_HPP