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/Instance.hpp $ 00003 // $Id: Instance.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 Instance class. 00018 00019 #ifndef TORC_PHYSICAL_INSTANCE_HPP 00020 #define TORC_PHYSICAL_INSTANCE_HPP 00021 00022 #include "torc/physical/Named.hpp" 00023 #include "torc/physical/Renamable.hpp" 00024 #include "torc/physical/Progeny.hpp" 00025 #include "torc/physical/Progenitor.hpp" 00026 #include "torc/physical/ConfigMap.hpp" 00027 #include "torc/physical/InstanceReference.hpp" 00028 #include "torc/common/Annotated.hpp" 00029 #include <boost/smart_ptr.hpp> 00030 #include <vector> 00031 #include <map> 00032 00033 namespace torc { 00034 namespace physical { 00035 00036 // forward declarations 00037 00038 /// \brief Shared pointer encapsulation of an InstancePin. 00039 typedef boost::shared_ptr<class InstancePin> InstancePinSharedPtr; 00040 00041 /// \brief Weak pointer encapsulation of an InstancePin. 00042 typedef boost::weak_ptr<class InstancePin> InstancePinWeakPtr; 00043 00044 /// \brief Vector of InstancePin shared pointers. 00045 typedef std::vector<InstancePinSharedPtr> InstancePinSharedPtrVector; 00046 00047 /// \brief Physical design instance. 00048 /// \details This class describes a physical instance in the design. 00049 /// \todo Need a good way of finding the direction of each instance pin. 00050 class Instance : public Renamable<class Circuit>, public Progeny<class Circuit>, 00051 public ConfigMap, public common::Annotated, protected Progenitor<Instance> { 00052 // friends 00053 /// \brief The Factory class has direct access to our internals. 00054 friend class Factory; 00055 /// \brief The InstancePin class has direct access to our internals. 00056 /// \details This is provided to allow notification when instance pins are added or removed 00057 /// for this object. 00058 friend class InstancePinBase; 00059 protected: 00060 // types 00061 /// \brief Imported type name. 00062 typedef std::string string; 00063 /// \brief Map from instance pin name to instance pin 00064 typedef std::multimap<PinName, InstancePinSharedPtr> InstancePinMap; 00065 // members 00066 /// \brief The instance logic type. 00067 /// \details The type should be a valid logic type for the target architecture, or the name 00068 /// of a module defined in this design. 00069 string mType; 00070 /// \brief The instance placement tile, or an empty string if unplaced. 00071 string mTile; 00072 /// \brief The instance placement site, or an empty string if unplaced. 00073 string mSite; 00074 /// \brief The instance bonding. 00075 /// \details The bonding must be EInstanceBonding::eInstanceBondingUnknown unless this 00076 /// instance is an unplaced IO. For an unplaced IO, the bonding setting determines 00077 /// whether the instance will be placed on a bonded pad or an unbonded pad. 00078 EInstanceBonding mBonding; 00079 /// \brief The module instance reference, if any. 00080 /// \details If this instance is the instantiation of a module instance, the 00081 /// InstanceReference points back to the original instance in the instantiation module. 00082 /// Instance refrences are rarely used, and almost never needed, and are only supported 00083 /// to faithfully replicate XDL designs. 00084 InstanceReferenceSharedPtr mInstanceReferencePtr; 00085 /// \brief The map of pin names to InstancePin weak pointers. 00086 InstancePinMap mInstancePins; 00087 // functions 00088 /// \brief Add the referenced InstancePin to our pin map. 00089 void addPin(const InstancePinWeakPtr& inInstancePinPtr); 00090 /// \brief Remove the referenced InstancePin from our pin map. 00091 void removePin(const InstancePinWeakPtr& inInstancePinPtr); 00092 // constructors 00093 /// \brief Protected constructor. 00094 /// \param inName The instance name. 00095 /// \param inType The instance type. 00096 /// \param inTile The instance tile, or an empty string if unplaced. 00097 /// \param inSite The instance site, or an empty string if unplaced. 00098 /// \param inBonding The specified bonding for unplaced IO, or eInstanceBondingUnknown for 00099 /// placed IO instances and non-IO instances. 00100 /// \param inInstanceReferencePtr The module instance reference, if applicable. The 00101 /// default value is almost always correct. Note that instance references are never 00102 /// required for XDL, and are only supported to completely replicated the original 00103 /// design. 00104 Instance(const string& inName, const string& inType, const string& inTile, 00105 const string& inSite, EInstanceBonding inBonding, 00106 InstanceReferenceSharedPtr& inInstanceReferencePtr) : Renamable<class Circuit>(inName), 00107 mType(inType), mTile(inTile), mSite(inSite), mBonding(inBonding), 00108 mInstanceReferencePtr(inInstanceReferencePtr) {} 00109 public: 00110 // types 00111 /// \brief Constant iterator to InstancePin shared pointers. 00112 typedef InstancePinMap::const_iterator InstancePinSharedPtrConstIterator; 00113 /// \brief Non-constant iterator to InstancePin shared pointers. 00114 typedef InstancePinMap::iterator InstancePinSharedPtrIterator; 00115 // operators 00116 /// \brief Equality operator. 00117 /// \details This function deems instances equal if their names are identical. 00118 /// \param rhs The instance to compare against. 00119 /// \returns true if both instance names are identical, or false otherwise. 00120 bool operator ==(const Instance& rhs) const { return mName == rhs.mName; } 00121 /// \brief Unplace the instance. 00122 /// \details The instance is unplaced by clearing its site and tile. 00123 // functions 00124 /// \brief Unplace this instance by clearing its site and tile fields. 00125 void unplace(void) { 00126 mSite.clear(); 00127 mTile.clear(); 00128 } 00129 /// \brief Returns an InstancePin iterator for the requested pin. 00130 const InstancePinSharedPtrConstIterator findPin(const PinName& inPinName) const { 00131 InstancePinSharedPtrConstIterator p = mInstancePins.find(inPinName); 00132 return p; 00133 } 00134 /// \brief Returns a range that encompasses all instance pins for the given pin. 00135 /// \returns A constance iterator pair that encompasses all instance pins for the given 00136 /// pins. Refer to std::pair to determine how to extract the iterators. 00137 std::pair<InstancePinSharedPtrConstIterator, InstancePinSharedPtrConstIterator> 00138 findPinRange(const PinName& inPinName) const { 00139 return mInstancePins.equal_range(inPinName); 00140 } 00141 /// \brief Returns the number of instance pins associated with the given pin. 00142 size_t getPinCount(const string& inPinName) const 00143 { return mInstancePins.count(inPinName); } 00144 // accessors 00145 /// \brief Returns the logic type for this instance. 00146 const string& getType(void) const { return mType; } 00147 /// \brief Returns the placement tile for this instance. 00148 const string& getTile(void) const { return mTile; } 00149 /// \brief Returns the placement site for this instance. 00150 const string& getSite(void) const { return mSite; } 00151 /// \brief Returns the IO bonding for this instance. 00152 EInstanceBonding getBonding(void) const { return mBonding; } 00153 /// \brief Returns the instance reference for this instance, if any. 00154 InstanceReferenceSharedPtr getInstanceReferencePtr(void) const 00155 { return mInstanceReferencePtr; } 00156 /// \brief Sets the logic type for this instance. 00157 void setType(const string& inType) { mType = inType; } 00158 /// \brief Sets the placement tile for this instance. 00159 void setTile(const string& inTile) { mTile = inTile; } 00160 /// \brief Sets the placement site for this instance. 00161 void setSite(const string& inSite) { mSite = inSite; } 00162 /// \brief Sets the IO bonding for this instance. 00163 /// \details The bonding must be EInstanceBonding::eInstanceBondingUnknown unless this 00164 /// instance is an unplaced IO. For an unplaced IO, the bonding setting determines 00165 /// whether the instance will be placed on a bonded pad or an unbonded pad. 00166 void setBonding(EInstanceBonding inBonding) { mBonding = inBonding; } 00167 /// \brief Sets the instance reference for this instance. 00168 /// \details If this instance is the instantiation of a module instance, the 00169 /// InstanceReference points back to the original instance in the instantiation module. 00170 /// Instance refrences are rarely used, and almost never needed, and are only supported 00171 /// to faithfully replicate XDL designs. 00172 void setInstanceReferencePtr(InstanceReferenceSharedPtr inInstanceReferenceSharedPtr) 00173 { mInstanceReferencePtr = inInstanceReferenceSharedPtr; } 00174 // iterators 00175 /// \brief Returns the begin constant iterator for instance pins. 00176 InstancePinSharedPtrConstIterator pinsBegin(void) const { return mInstancePins.begin(); } 00177 /// \brief Returns the end constant iterator for instance pins. 00178 InstancePinSharedPtrConstIterator pinsEnd(void) const { return mInstancePins.end(); } 00179 /// \brief Returns the begin non-constant iterator for instance pins. 00180 InstancePinSharedPtrIterator pinsBegin(void) { return mInstancePins.begin(); } 00181 /// \brief Returns the end non-constant iterator for instance pins. 00182 InstancePinSharedPtrIterator pinsEnd(void) { return mInstancePins.end(); } 00183 /// \brief Returns the number of instance pins in the instance. 00184 size_t getPinCount(void) const { return mInstancePins.size(); } 00185 }; 00186 00187 /// \brief Shared pointer encapsulation of an Instance. 00188 typedef boost::shared_ptr<Instance> InstanceSharedPtr; 00189 00190 /// \brief Weak pointer encapsulation of an Instance. 00191 typedef boost::weak_ptr<Instance> InstanceWeakPtr; 00192 00193 /// \brief Vector of Instance shared pointers. 00194 typedef std::vector<InstanceSharedPtr> InstanceSharedPtrVector; 00195 00196 } // namespace physical 00197 } // namespace torc 00198 00199 #endif // TORC_PHYSICAL_INSTANCE_HPP