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/router/TraceNode.hpp $ 00003 // $Id: TraceNode.hpp 1 2011-02-25 22:11: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 TraceNode class. 00018 00019 #ifndef TORC_ROUTER_TRACENODE_HPP 00020 #define TORC_ROUTER_TRACENODE_HPP 00021 00022 #include "torc/architecture/Arc.hpp" 00023 #include "torc/common/EncapsulatedInteger.hpp" 00024 #include <boost/cstdint.hpp> 00025 #include <functional> 00026 #include <vector> 00027 #include <list> 00028 #include <set> 00029 #include <iostream> 00030 00031 namespace torc { 00032 namespace router { 00033 00034 // Pack TraceNode objects tightly. 00035 /// \todo Have to justify the packing decision, and its impact on memory footprint versus 00036 /// performance. 00037 #ifdef __GNUC__ 00038 #pragma pack(push, 2) 00039 #endif 00040 00041 /// \brief An object that holds more complete path information for routing and tracing. 00042 /// \details A TraceNode contains children pointers to allow tracing of arcs through a 00043 /// device to recover complete nets from the device usage information. 00044 class TraceNode { 00045 // friends 00046 /// \brief The TraceNode allows access to protected functions from Trace objects. 00047 friend class Trace; 00048 // types 00049 /// \brief Imported type name. 00050 typedef architecture::Tilewire Tilewire; 00051 /// \brief Imported type name. 00052 typedef architecture::Arc Arc; 00053 /// \brief Imported type name. 00054 typedef architecture::TilewireVector TilewireVector; 00055 public: 00056 /// \brief Vector of TraceNode pointers. 00057 typedef std::vector<TraceNode*> TraceNodePtrVector; 00058 /// \brief List of TraceNode pointers. 00059 typedef std::list<TraceNode*> TraceNodePtrList; 00060 /// \brief Pair consisting of a Tilewire and TraceNode pointer. 00061 typedef std::pair<Tilewire, TraceNode*> TilewireTraceNodePtrPair; 00062 /// \brief Iterator for vector of TraceNode pointers. 00063 typedef TraceNodePtrVector::iterator TraceNodePtrVectorIterator; 00064 /// \brief Pair consiting of an Arc and a TraceNode pointer. 00065 typedef std::pair<Arc, TraceNode*> ArcTraceNodePtrPair; 00066 /// \brief Vector of pairs of source Tilewires and TraceNode pointers. 00067 typedef std::vector<TilewireTraceNodePtrPair> TilewireTraceNodePtrPairVector; 00068 /// \brief Vector of paires of Arcs and TraceNode pointers. 00069 typedef std::vector<ArcTraceNodePtrPair> ArcTraceNodePtrPairVector; 00070 protected: 00071 // members 00072 // /// \brief Tilewire of this node. 00073 Tilewire mTilewire; 00074 /// \brief TilewireVector representing this node. 00075 //TilewireVector mSegment; 00076 /// \brief Vector of child pointers. 00077 TraceNodePtrVector mChildren; 00078 /// \brief Vector of parent pointers. 00079 //TilewireTraceNodePtrPairVector mParents; 00080 TraceNodePtrVector mParents; 00081 /// \brief Depth from furthest parent with no parent. 00082 boost::int32_t mDepth; 00083 public: 00084 /// \brief Static allocation and deallocation count 00085 static boost::int32_t sLiveNodes; 00086 public: 00087 // constructors 00088 /// \brief Null Constructor. 00089 //TraceNode() : mTilewire(Tilewire::sInvalid) , mDepth(-1) { 00090 TraceNode() : mDepth(-1) { 00091 sLiveNodes++; 00092 } 00093 /// \brief Public Constructor. 00094 TraceNode(Tilewire inTilewire) : mTilewire(inTilewire), mDepth(-1) { 00095 sLiveNodes++; 00096 } 00097 /// \brief Destructor. 00098 /// \details Recursively deletes all connected nodes. 00099 ~TraceNode() { 00100 //std::cout << "DESTRUCT! " << mTilewire.getWireIndex() << "@" 00101 // << mTilewire.getTileIndex() << std::endl; 00102 /*for (unsigned int i = 0; i < mChildren.size(); i++) { 00103 for (unsigned int j = 0; j < mChildren[i]->getNumParents(); j++) { 00104 if (mChildren[i]->getParent(j) == this) { 00105 mChildren[i]->removeParent(j); 00106 break; 00107 } 00108 } 00109 delete mChildren[i]; 00110 mChildren[i] = 0; 00111 } 00112 mChildren.clear(); 00113 for (unsigned int i = 0; i < mParents.size(); i++) { 00114 if (mParents[i]->getNumChildren() > 0) { 00115 for (unsigned int j = 0; j < mParents[i]->getNumChildren(); j++) { 00116 if (mParents[i]->getChild(j) == this) { 00117 mParents[i]->removeChild(j); 00118 break; 00119 } 00120 } 00121 } 00122 delete mParents[i]; 00123 mParents[i] = 0; 00124 } 00125 mParents.clear();*/ 00126 sLiveNodes--; 00127 } 00128 // accessors 00129 /// \brief Get the Tilewire associated with this node. 00130 inline Tilewire getTilewire() { return mTilewire; } 00131 //TilewireVector& getSegment() { return mSegment; } 00132 /// \brief Get the depth of this node from the furthest node with no parent. 00133 inline boost::int32_t getDepth() const { return mDepth; } 00134 /// \brief Set the depth of this node. 00135 inline void setDepth(boost::int32_t inDepth) { mDepth = inDepth; } 00136 /// \brief Add children to the node. 00137 void addChildren(const TraceNodePtrVector& newChildren) { 00138 boost::uint32_t size = newChildren.size(); 00139 if (size == 0) return; 00140 mChildren.reserve(mChildren.size() + size); 00141 // insert children into the node 00142 mChildren.insert(mChildren.end(), newChildren.begin(), newChildren.end()); 00143 } 00144 /// brief Add child to the node. 00145 void addChild(TraceNode* newChild) { 00146 if (newChild == 0) return; 00147 mChildren.push_back(newChild); 00148 } 00149 /// \brief Add parent to the node. 00150 void addParent(TraceNode* newParent) { 00151 mParents.push_back(newParent); 00152 } 00153 /// \brief Get the number of children. 00154 boost::uint32_t getNumChildren() { 00155 return mChildren.size(); 00156 } 00157 /// \brief Get the number of parents. 00158 boost::uint32_t getNumParents() { 00159 return mParents.size(); 00160 } 00161 /// \brief Get a child by index, returns 0 for invalid index. 00162 TraceNode* getChild(boost::uint32_t index) { 00163 if (index >= mChildren.size()) return 0; 00164 return mChildren[index]; 00165 } 00166 /// \brief Get a parent by index, returns 0 for invalid index. 00167 TraceNode* getParent(boost::uint32_t index) { 00168 if (index >= mParents.size()) return 0; 00169 return mParents[index]; 00170 } 00171 /// \brief Remove a child by index, returns 0 for invalid index. 00172 TraceNode* removeChild(boost::uint32_t index) { 00173 if (index >= mChildren.size()) return 0; 00174 TraceNode* node = mChildren[index]; 00175 mChildren.erase(mChildren.begin() + index); 00176 return node; 00177 } 00178 /// \brief Remove a parent by index, returns 0 for invalid index. 00179 TraceNode* removeParent(boost::uint32_t index) { 00180 if (index >= mParents.size()) return 0; 00181 TraceNode* node = mParents[index]; 00182 mParents.erase(mParents.begin() + index); 00183 return node; 00184 } 00185 }; 00186 00187 #ifdef __GNUC__ 00188 #pragma pack(pop) 00189 #endif 00190 00191 /// \brief Vector of TraceNode pointer. 00192 typedef std::vector<TraceNode*> TraceNodePtrVector; 00193 00194 } // namespace router 00195 } // namespace torc 00196 00197 #endif // TORC_ROUTER_TRACENODE_HPP