1 /* Authors: Lutong Wang and Bangqi Xu */
2 /*
3  * Copyright (c) 2019, The Regents of the University of California
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of the University nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _GR_NODE_H_
30 #define _GR_NODE_H_
31 
32 #include <iostream>
33 #include <memory>
34 
35 #include "frBaseTypes.h"
36 // #include "db/obj/frNode.h"
37 #include "db/grObj/grBlockObject.h"
38 
39 namespace fr {
40 class frNet;
41 class grNet;
42 class frNode;
43 
44 class grNode : public grBlockObject
45 {
46  public:
47   // constructor
grNode()48   grNode()
49       : grBlockObject(),
50         net(nullptr),
51         loc(),
52         layerNum(0),
53         connFig(nullptr),
54         pin(nullptr),
55         type(frNodeTypeEnum::frcSteiner),
56         /*fNode(nullptr),*/ parent(nullptr),
57         children()
58   {
59   }
grNode(grNode & in)60   grNode(grNode& in)
61       : grBlockObject(),
62         net(in.net),
63         loc(in.loc),
64         layerNum(in.layerNum),
65         connFig(in.connFig),
66         pin(in.pin),
67         type(in.type),
68         parent(in.parent),
69         children(in.children)
70   {
71   }
grNode(frNode & in)72   grNode(frNode& in)
73       : grBlockObject(),
74         net(nullptr),
75         loc(in.loc),
76         layerNum(in.layerNum),
77         connFig(nullptr),
78         pin(in.pin),
79         type(in.type),
80         parent(nullptr),
81         children()
82   {
83   }
84 
85   // setters
addToNet(grNet * in)86   void addToNet(grNet* in) { net = in; }
setLoc(const frPoint & in)87   void setLoc(const frPoint& in) { loc = in; }
setLayerNum(frLayerNum in)88   void setLayerNum(frLayerNum in) { layerNum = in; }
setConnFig(grBlockObject * in)89   void setConnFig(grBlockObject* in) { connFig = in; }
setPin(frBlockObject * in)90   void setPin(frBlockObject* in) { pin = in; }
setType(frNodeTypeEnum in)91   void setType(frNodeTypeEnum in) { type = in; }
setParent(grNode * in)92   void setParent(grNode* in) { parent = in; }
addChild(grNode * in)93   void addChild(grNode* in)
94   {
95     bool exist = false;
96     for (auto child : children) {
97       if (child == in) {
98         exist = true;
99       }
100     }
101     if (!exist) {
102       children.push_back(in);
103     } else {
104       std::cout << "Warning: grNode child already exists\n";
105     }
106   }
clearChildren()107   void clearChildren() { children.clear(); }
removeChild(grNode * in)108   void removeChild(grNode* in)
109   {
110     for (auto it = children.begin(); it != children.end(); it++) {
111       if (*it == in) {
112         children.erase(it);
113         break;
114       }
115     }
116   }
setIter(frListIter<std::unique_ptr<grNode>> & in)117   void setIter(frListIter<std::unique_ptr<grNode>>& in) { iter = in; }
reset()118   void reset()
119   {
120     parent = nullptr;
121     children.clear();
122   }
123 
124   // getters
hasNet()125   bool hasNet() { return (net != nullptr); }
getNet()126   grNet* getNet() { return net; }
getLoc(frPoint & in)127   void getLoc(frPoint& in) { in = loc; }
getLoc()128   frPoint getLoc() { return loc; }
getLayerNum()129   frLayerNum getLayerNum() { return layerNum; }
getConnFig()130   grBlockObject* getConnFig() { return connFig; }
getPin()131   frBlockObject* getPin() { return pin; }
getType()132   frNodeTypeEnum getType() { return type; }
hasParent()133   bool hasParent() { return (parent != nullptr); }
getParent()134   grNode* getParent() { return parent; }
hasChildren()135   bool hasChildren() { return (!children.empty()); }
getChildren()136   std::list<grNode*>& getChildren() { return children; }
getChildren()137   const std::list<grNode*>& getChildren() const { return children; }
getIter()138   frListIter<std::unique_ptr<grNode>> getIter() { return iter; }
139 
typeId()140   frBlockObjectEnum typeId() const override { return grcNode; }
141 
142  protected:
143   grNet* net;
144   frPoint loc;
145   frLayerNum layerNum;
146   grBlockObject* connFig;  // wire / via / patch to parent
147   frBlockObject* pin;      // term / instTerm / null if boundary pin or steiner
148   frNodeTypeEnum type;
149 
150   // frNode *fNode; // corresponding frNode
151   grNode* parent;
152   std::list<grNode*> children;
153 
154   frListIter<std::unique_ptr<grNode>> iter;
155 
156   friend class frNode;
157 };
158 }  // namespace fr
159 
160 #endif