torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical/Instance.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 Instance class.
18 
19 #ifndef TORC_PHYSICAL_INSTANCE_HPP
20 #define TORC_PHYSICAL_INSTANCE_HPP
21 
22 #include "torc/physical/Named.hpp"
29 #include <boost/smart_ptr.hpp>
30 #include <vector>
31 #include <map>
32 
33 namespace torc {
34 namespace physical {
35 
36  // forward declarations
37 
38  /// \brief Shared pointer encapsulation of an InstancePin.
39  typedef boost::shared_ptr<class InstancePin> InstancePinSharedPtr;
40 
41  /// \brief Weak pointer encapsulation of an InstancePin.
42  typedef boost::weak_ptr<class InstancePin> InstancePinWeakPtr;
43 
44  /// \brief Vector of InstancePin shared pointers.
45  typedef std::vector<InstancePinSharedPtr> InstancePinSharedPtrVector;
46 
47  /// \brief Physical design instance.
48  /// \details This class describes a physical instance in the design.
49  /// \todo Need a good way of finding the direction of each instance pin.
50  class Instance : public Renamable<class Circuit>, public Progeny<class Circuit>,
51  public ConfigMap, public common::Annotated, protected Progenitor<Instance> {
52  // friends
53  /// \brief The Factory class has direct access to our internals.
54  friend class Factory;
55  /// \brief The InstancePin class has direct access to our internals.
56  /// \details This is provided to allow notification when instance pins are added or removed
57  /// for this object.
58  friend class InstancePinBase;
59  protected:
60  // types
61  /// \brief Imported type name.
63  /// \brief Map from instance pin name to instance pin
64  typedef std::multimap<PinName, InstancePinSharedPtr> InstancePinMap;
65  // members
66  /// \brief The instance logic type.
67  /// \details The type should be a valid logic type for the target architecture, or the name
68  /// of a module defined in this design.
69  string mType;
70  /// \brief The instance placement tile, or an empty string if unplaced.
71  string mTile;
72  /// \brief The instance placement site, or an empty string if unplaced.
73  string mSite;
74  /// \brief The instance bonding.
75  /// \details The bonding must be EInstanceBonding::eInstanceBondingUnknown unless this
76  /// instance is an unplaced IO. For an unplaced IO, the bonding setting determines
77  /// whether the instance will be placed on a bonded pad or an unbonded pad.
79  /// \brief The module instance reference, if any.
80  /// \details If this instance is the instantiation of a module instance, the
81  /// InstanceReference points back to the original instance in the instantiation module.
82  /// Instance refrences are rarely used, and almost never needed, and are only supported
83  /// to faithfully replicate XDL designs.
85  /// \brief The map of pin names to InstancePin weak pointers.
87  // functions
88  /// \brief Add the referenced InstancePin to our pin map.
89  void addPin(const InstancePinWeakPtr& inInstancePinPtr);
90  /// \brief Remove the referenced InstancePin from our pin map.
91  void removePin(const InstancePinWeakPtr& inInstancePinPtr);
92  // constructors
93  /// \brief Protected constructor.
94  /// \param inName The instance name.
95  /// \param inType The instance type.
96  /// \param inTile The instance tile, or an empty string if unplaced.
97  /// \param inSite The instance site, or an empty string if unplaced.
98  /// \param inBonding The specified bonding for unplaced IO, or eInstanceBondingUnknown for
99  /// placed IO instances and non-IO instances.
100  /// \param inInstanceReferencePtr The module instance reference, if applicable. The
101  /// default value is almost always correct. Note that instance references are never
102  /// required for XDL, and are only supported to completely replicated the original
103  /// design.
104  Instance(const string& inName, const string& inType, const string& inTile,
105  const string& inSite, EInstanceBonding inBonding,
106  InstanceReferenceSharedPtr& inInstanceReferencePtr) : Renamable<class Circuit>(inName),
107  mType(inType), mTile(inTile), mSite(inSite), mBonding(inBonding),
108  mInstanceReferencePtr(inInstanceReferencePtr) {}
109  public:
110  // types
111  /// \brief Constant iterator to InstancePin shared pointers.
112  typedef InstancePinMap::const_iterator InstancePinSharedPtrConstIterator;
113  /// \brief Non-constant iterator to InstancePin shared pointers.
114  typedef InstancePinMap::iterator InstancePinSharedPtrIterator;
115  // operators
116  /// \brief Equality operator.
117  /// \details This function deems instances equal if their names are identical.
118  /// \param rhs The instance to compare against.
119  /// \returns true if both instance names are identical, or false otherwise.
120  bool operator ==(const Instance& rhs) const { return mName == rhs.mName; }
121  /// \brief Unplace the instance.
122  /// \details The instance is unplaced by clearing its site and tile.
123  // functions
124  /// \brief Unplace this instance by clearing its site and tile fields.
125  void unplace(void) {
126  mSite.clear();
127  mTile.clear();
128  }
129  /// \brief Returns an InstancePin iterator for the requested pin.
130  const InstancePinSharedPtrConstIterator findPin(const PinName& inPinName) const {
132  return p;
133  }
134  /// \brief Returns a range that encompasses all instance pins for the given pin.
135  /// \returns A constance iterator pair that encompasses all instance pins for the given
136  /// pins. Refer to std::pair to determine how to extract the iterators.
137  std::pair<InstancePinSharedPtrConstIterator, InstancePinSharedPtrConstIterator>
138  findPinRange(const PinName& inPinName) const {
139  return mInstancePins.equal_range(inPinName);
140  }
141  /// \brief Returns the number of instance pins associated with the given pin.
142  size_t getPinCount(const string& inPinName) const
143  { return mInstancePins.count(inPinName); }
144  // accessors
145  /// \brief Returns the logic type for this instance.
146  const string& getType(void) const { return mType; }
147  /// \brief Returns the placement tile for this instance.
148  const string& getTile(void) const { return mTile; }
149  /// \brief Returns the placement site for this instance.
150  const string& getSite(void) const { return mSite; }
151  /// \brief Returns the IO bonding for this instance.
152  EInstanceBonding getBonding(void) const { return mBonding; }
153  /// \brief Returns the instance reference for this instance, if any.
155  { return mInstanceReferencePtr; }
156  /// \brief Sets the logic type for this instance.
157  void setType(const string& inType) { mType = inType; }
158  /// \brief Sets the placement tile for this instance.
159  void setTile(const string& inTile) { mTile = inTile; }
160  /// \brief Sets the placement site for this instance.
161  void setSite(const string& inSite) { mSite = inSite; }
162  /// \brief Sets the IO bonding for this instance.
163  /// \details The bonding must be EInstanceBonding::eInstanceBondingUnknown unless this
164  /// instance is an unplaced IO. For an unplaced IO, the bonding setting determines
165  /// whether the instance will be placed on a bonded pad or an unbonded pad.
166  void setBonding(EInstanceBonding inBonding) { mBonding = inBonding; }
167  /// \brief Sets the instance reference for this instance.
168  /// \details If this instance is the instantiation of a module instance, the
169  /// InstanceReference points back to the original instance in the instantiation module.
170  /// Instance refrences are rarely used, and almost never needed, and are only supported
171  /// to faithfully replicate XDL designs.
172  void setInstanceReferencePtr(InstanceReferenceSharedPtr inInstanceReferenceSharedPtr)
173  { mInstanceReferencePtr = inInstanceReferenceSharedPtr; }
174  // iterators
175  /// \brief Returns the begin constant iterator for instance pins.
177  /// \brief Returns the end constant iterator for instance pins.
179  /// \brief Returns the begin non-constant iterator for instance pins.
181  /// \brief Returns the end non-constant iterator for instance pins.
183  /// \brief Returns the number of instance pins in the instance.
184  size_t getPinCount(void) const { return mInstancePins.size(); }
185  };
186 
187  /// \brief Shared pointer encapsulation of an Instance.
188  typedef boost::shared_ptr<Instance> InstanceSharedPtr;
189 
190  /// \brief Weak pointer encapsulation of an Instance.
191  typedef boost::weak_ptr<Instance> InstanceWeakPtr;
192 
193  /// \brief Vector of Instance shared pointers.
194  typedef std::vector<InstanceSharedPtr> InstanceSharedPtrVector;
195 
196 } // namespace physical
197 } // namespace torc
198 
199 #endif // TORC_PHYSICAL_INSTANCE_HPP
size_t getPinCount(const string &inPinName) const
Returns the number of instance pins associated with the given pin.
Header for the Renamable class.
size_t getPinCount(void) const
Returns the number of instance pins in the instance.
Header for the ConfigMap class.
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
EInstanceBonding
Enumeration of pad bonding types.
void removePin(const InstancePinWeakPtr &inInstancePinPtr)
Remove the referenced InstancePin from our pin map.
InstanceReferenceSharedPtr getInstanceReferencePtr(void) const
Returns the instance reference for this instance, if any.
const InstancePinSharedPtrConstIterator findPin(const PinName &inPinName) const
Returns an InstancePin iterator for the requested pin.
Physical design instance-pin pair, suitable for specifying a net endpoint.
const string & getType(void) const
Returns the logic type for this instance.
Header for the InstanceReference class.
Encapsulation of a site pin name.
void setType(const string &inType)
Sets the logic type for this instance.
string mSite
The instance placement site, or an empty string if unplaced.
string mName
The name of the object.
Definition: Named.hpp:43
void addPin(const InstancePinWeakPtr &inInstancePinPtr)
Add the referenced InstancePin to our pin map.
InstancePinMap::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointers.
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
const string & getSite(void) const
Returns the placement site for this instance.
InstancePinSharedPtrIterator pinsEnd(void)
Returns the end non-constant iterator for instance pins.
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
void unplace(void)
Unplace the instance.
std::string string
std::string string
Imported type name.
Header for the Progenitor class.
Header for the Annotated class.
void setBonding(EInstanceBonding inBonding)
Sets the IO bonding for this instance.
bool operator==(const Instance &rhs) const
Equality operator.
Physical design instance.
Instance(const string &inName, const string &inType, const string &inTile, const string &inSite, EInstanceBonding inBonding, InstanceReferenceSharedPtr &inInstanceReferencePtr)
Protected constructor.
Header for the Named class.
InstancePinMap::const_iterator InstancePinSharedPtrConstIterator
Constant iterator to InstancePin shared pointers.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
InstancePinMap mInstancePins
The map of pin names to InstancePin weak pointers.
EInstanceBonding mBonding
The instance bonding.
InstancePinSharedPtrIterator pinsBegin(void)
Returns the begin non-constant iterator for instance pins.
Factory class for physical netlist elements.
InstancePinSharedPtrConstIterator pinsBegin(void) const
Returns the begin constant iterator for instance pins.
Concept for any object that may have children.
Definition: Progenitor.hpp:36
Concept for any object that may have a parent.
Definition: Progeny.hpp:29
Header for the Progeny class.
void setInstanceReferencePtr(InstanceReferenceSharedPtr inInstanceReferenceSharedPtr)
Sets the instance reference for this instance.
const string & getTile(void) const
Returns the placement tile for this instance.
Concept for any object that can be renamed.
void setTile(const string &inTile)
Sets the placement tile for this instance.
Configuration setting map.
Definition: ConfigMap.hpp:39
InstanceReferenceSharedPtr mInstanceReferencePtr
The module instance reference, if any.
string mTile
The instance placement tile, or an empty string if unplaced.
std::pair< InstancePinSharedPtrConstIterator, InstancePinSharedPtrConstIterator > findPinRange(const PinName &inPinName) const
Returns a range that encompasses all instance pins for the given pin.
boost::weak_ptr< class InstancePin > InstancePinWeakPtr
Weak pointer encapsulation of an InstancePin.
string mType
The instance logic type.
void setSite(const string &inSite)
Sets the placement site for this instance.
EInstanceBonding getBonding(void) const
Returns the IO bonding for this instance.
Circuit composed of instances and nets.
Definition: Circuit.hpp:46
boost::weak_ptr< Instance > InstanceWeakPtr
Weak pointer encapsulation of an Instance.
InstancePinSharedPtrConstIterator pinsEnd(void) const
Returns the end constant iterator for instance pins.
std::multimap< PinName, InstancePinSharedPtr > InstancePinMap
Map from instance pin name to instance pin.
boost::shared_ptr< InstanceReference > InstanceReferenceSharedPtr
Shared pointer encapsulation of an InstanceReference.
Concept for any object that can be annotated.
Definition: Annotated.hpp:29