torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TraceNode.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 TraceNode class.
18 
19 #ifndef TORC_ROUTER_TRACENODE_HPP
20 #define TORC_ROUTER_TRACENODE_HPP
21 
24 #include <boost/cstdint.hpp>
25 #include <functional>
26 #include <vector>
27 #include <list>
28 #include <set>
29 #include <iostream>
30 
31 namespace torc {
32 namespace router {
33 
34  // Pack TraceNode objects tightly.
35  /// \todo Have to justify the packing decision, and its impact on memory footprint versus
36  /// performance.
37  #ifdef __GNUC__
38  #pragma pack(push, 2)
39  #endif
40 
41  /// \brief An object that holds more complete path information for routing and tracing.
42  /// \details A TraceNode contains children pointers to allow tracing of arcs through a
43  /// device to recover complete nets from the device usage information.
44  class TraceNode {
45  // friends
46  /// \brief The TraceNode allows access to protected functions from Trace objects.
47  friend class Trace;
48  // types
49  /// \brief Imported type name.
51  /// \brief Imported type name.
53  /// \brief Imported type name.
55  public:
56  /// \brief Vector of TraceNode pointers.
57  typedef std::vector<TraceNode*> TraceNodePtrVector;
58  /// \brief List of TraceNode pointers.
59  typedef std::list<TraceNode*> TraceNodePtrList;
60  /// \brief Pair consisting of a Tilewire and TraceNode pointer.
61  typedef std::pair<Tilewire, TraceNode*> TilewireTraceNodePtrPair;
62  /// \brief Iterator for vector of TraceNode pointers.
63  typedef TraceNodePtrVector::iterator TraceNodePtrVectorIterator;
64  /// \brief Pair consiting of an Arc and a TraceNode pointer.
65  typedef std::pair<Arc, TraceNode*> ArcTraceNodePtrPair;
66  /// \brief Vector of pairs of source Tilewires and TraceNode pointers.
67  typedef std::vector<TilewireTraceNodePtrPair> TilewireTraceNodePtrPairVector;
68  /// \brief Vector of paires of Arcs and TraceNode pointers.
69  typedef std::vector<ArcTraceNodePtrPair> ArcTraceNodePtrPairVector;
70  protected:
71  // members
72  // /// \brief Tilewire of this node.
74  /// \brief TilewireVector representing this node.
75  //TilewireVector mSegment;
76  /// \brief Vector of child pointers.
78  /// \brief Vector of parent pointers.
79  //TilewireTraceNodePtrPairVector mParents;
81  /// \brief Depth from furthest parent with no parent.
82  boost::int32_t mDepth;
83  public:
84  /// \brief Static allocation and deallocation count
85  static boost::int32_t sLiveNodes;
86  public:
87  // constructors
88  /// \brief Null Constructor.
89  //TraceNode() : mTilewire(Tilewire::sInvalid) , mDepth(-1) {
90  TraceNode() : mDepth(-1) {
91  sLiveNodes++;
92  }
93  /// \brief Public Constructor.
94  TraceNode(Tilewire inTilewire) : mTilewire(inTilewire), mDepth(-1) {
95  sLiveNodes++;
96  }
97  /// \brief Destructor.
98  /// \details Recursively deletes all connected nodes.
100  //std::cout << "DESTRUCT! " << mTilewire.getWireIndex() << "@"
101  // << mTilewire.getTileIndex() << std::endl;
102  /*for (unsigned int i = 0; i < mChildren.size(); i++) {
103  for (unsigned int j = 0; j < mChildren[i]->getNumParents(); j++) {
104  if (mChildren[i]->getParent(j) == this) {
105  mChildren[i]->removeParent(j);
106  break;
107  }
108  }
109  delete mChildren[i];
110  mChildren[i] = 0;
111  }
112  mChildren.clear();
113  for (unsigned int i = 0; i < mParents.size(); i++) {
114  if (mParents[i]->getNumChildren() > 0) {
115  for (unsigned int j = 0; j < mParents[i]->getNumChildren(); j++) {
116  if (mParents[i]->getChild(j) == this) {
117  mParents[i]->removeChild(j);
118  break;
119  }
120  }
121  }
122  delete mParents[i];
123  mParents[i] = 0;
124  }
125  mParents.clear();*/
126  sLiveNodes--;
127  }
128  // accessors
129  /// \brief Get the Tilewire associated with this node.
130  inline Tilewire getTilewire() { return mTilewire; }
131  //TilewireVector& getSegment() { return mSegment; }
132  /// \brief Get the depth of this node from the furthest node with no parent.
133  inline boost::int32_t getDepth() const { return mDepth; }
134  /// \brief Set the depth of this node.
135  inline void setDepth(boost::int32_t inDepth) { mDepth = inDepth; }
136  /// \brief Add children to the node.
137  void addChildren(const TraceNodePtrVector& newChildren) {
138  boost::uint32_t size = newChildren.size();
139  if (size == 0) return;
140  mChildren.reserve(mChildren.size() + size);
141  // insert children into the node
142  mChildren.insert(mChildren.end(), newChildren.begin(), newChildren.end());
143  }
144  /// brief Add child to the node.
145  void addChild(TraceNode* newChild) {
146  if (newChild == 0) return;
147  mChildren.push_back(newChild);
148  }
149  /// \brief Add parent to the node.
150  void addParent(TraceNode* newParent) {
151  mParents.push_back(newParent);
152  }
153  /// \brief Get the number of children.
154  boost::uint32_t getNumChildren() {
155  return mChildren.size();
156  }
157  /// \brief Get the number of parents.
158  boost::uint32_t getNumParents() {
159  return mParents.size();
160  }
161  /// \brief Get a child by index, returns 0 for invalid index.
162  TraceNode* getChild(boost::uint32_t index) {
163  if (index >= mChildren.size()) return 0;
164  return mChildren[index];
165  }
166  /// \brief Get a parent by index, returns 0 for invalid index.
167  TraceNode* getParent(boost::uint32_t index) {
168  if (index >= mParents.size()) return 0;
169  return mParents[index];
170  }
171  /// \brief Remove a child by index, returns 0 for invalid index.
172  TraceNode* removeChild(boost::uint32_t index) {
173  if (index >= mChildren.size()) return 0;
174  TraceNode* node = mChildren[index];
175  mChildren.erase(mChildren.begin() + index);
176  return node;
177  }
178  /// \brief Remove a parent by index, returns 0 for invalid index.
179  TraceNode* removeParent(boost::uint32_t index) {
180  if (index >= mParents.size()) return 0;
181  TraceNode* node = mParents[index];
182  mParents.erase(mParents.begin() + index);
183  return node;
184  }
185  };
186 
187  #ifdef __GNUC__
188  #pragma pack(pop)
189  #endif
190 
191  /// \brief Vector of TraceNode pointer.
192  typedef std::vector<TraceNode*> TraceNodePtrVector;
193 
194 } // namespace router
195 } // namespace torc
196 
197 #endif // TORC_ROUTER_TRACENODE_HPP
std::pair< Tilewire, TraceNode * > TilewireTraceNodePtrPair
Pair consisting of a Tilewire and TraceNode pointer.
Definition: TraceNode.hpp:61
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
std::vector< Tilewire > TilewireVector
Vector of Tilewire objects.
Definition: Tilewire.hpp:101
Tilewire getTilewire()
Get the Tilewire associated with this node.
Definition: TraceNode.hpp:130
void addParent(TraceNode *newParent)
Add parent to the node.
Definition: TraceNode.hpp:150
TraceNode * getChild(boost::uint32_t index)
Get a child by index, returns 0 for invalid index.
Definition: TraceNode.hpp:162
TraceNodePtrVector mChildren
TilewireVector representing this node.
Definition: TraceNode.hpp:77
architecture::TilewireVector TilewireVector
Imported type name.
Definition: TraceNode.hpp:54
boost::int32_t mDepth
Depth from furthest parent with no parent.
Definition: TraceNode.hpp:82
Header for the Arc class.
TraceNode * getParent(boost::uint32_t index)
Get a parent by index, returns 0 for invalid index.
Definition: TraceNode.hpp:167
std::vector< TraceNode * > TraceNodePtrVector
Vector of TraceNode pointer.
Definition: TraceNode.hpp:192
architecture::Arc Arc
Imported type name.
Definition: TraceNode.hpp:52
~TraceNode()
Destructor.
Definition: TraceNode.hpp:99
boost::int32_t getDepth() const
Get the depth of this node from the furthest node with no parent.
Definition: TraceNode.hpp:133
std::pair< Arc, TraceNode * > ArcTraceNodePtrPair
Pair consiting of an Arc and a TraceNode pointer.
Definition: TraceNode.hpp:65
architecture::Tilewire Tilewire
Imported type name.
Definition: TraceNode.hpp:50
void setDepth(boost::int32_t inDepth)
Set the depth of this node.
Definition: TraceNode.hpp:135
Provides path extraction from usage information in a DDB instance..
Definition: Trace.hpp:36
TraceNode * removeParent(boost::uint32_t index)
Remove a parent by index, returns 0 for invalid index.
Definition: TraceNode.hpp:179
std::vector< TilewireTraceNodePtrPair > TilewireTraceNodePtrPairVector
Vector of pairs of source Tilewires and TraceNode pointers.
Definition: TraceNode.hpp:67
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
TraceNode(Tilewire inTilewire)
Public Constructor.
Definition: TraceNode.hpp:94
static boost::int32_t sLiveNodes
Static allocation and deallocation count.
Definition: TraceNode.hpp:85
std::vector< TraceNode * > TraceNodePtrVector
Vector of TraceNode pointers.
Definition: TraceNode.hpp:57
boost::uint32_t getNumParents()
Get the number of parents.
Definition: TraceNode.hpp:158
std::vector< ArcTraceNodePtrPair > ArcTraceNodePtrPairVector
Vector of paires of Arcs and TraceNode pointers.
Definition: TraceNode.hpp:69
void addChildren(const TraceNodePtrVector &newChildren)
Add children to the node.
Definition: TraceNode.hpp:137
TraceNodePtrVector::iterator TraceNodePtrVectorIterator
Iterator for vector of TraceNode pointers.
Definition: TraceNode.hpp:63
TraceNode()
Null Constructor.
Definition: TraceNode.hpp:90
boost::uint32_t getNumChildren()
Get the number of children.
Definition: TraceNode.hpp:154
TraceNodePtrVector mParents
Vector of parent pointers.
Definition: TraceNode.hpp:80
std::list< TraceNode * > TraceNodePtrList
List of TraceNode pointers.
Definition: TraceNode.hpp:59
An object that holds more complete path information for routing and tracing.
Definition: TraceNode.hpp:44
TraceNode * removeChild(boost::uint32_t index)
Remove a child by index, returns 0 for invalid index.
Definition: TraceNode.hpp:172
Header for the EncapsulatedInteger template.
void addChild(TraceNode *newChild)
brief Add child to the node.
Definition: TraceNode.hpp:145