# Hurricane Documentation

# Hurricane VLSI Database

Net.h
1 // ****************************************************************************************************
2 // File: ./hurricane/Net.h
3 // Authors: R. Escassut
4 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
5 //
6 // This file is part of Hurricane.
7 //
8 // Hurricane is free software: you can redistribute it and/or modify it under the terms of the GNU
9 // Lesser General Public License as published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
11 //
12 // Hurricane is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the Lesser GNU General Public License along with Hurricane. If
17 // not, see <http://www.gnu.org/licenses/>.
18 // ****************************************************************************************************
19
20 #ifndef HURRICANE_NET
21 #define HURRICANE_NET
22
23 #include <functional>
24 #include "hurricane/Entity.h"
25 #include "hurricane/Nets.h"
26 #include "hurricane/Component.h"
27 #include "hurricane/Rubbers.h"
28 #include "hurricane/Rubber.h"
29 #include "hurricane/RoutingPads.h"
30 #include "hurricane/Plugs.h"
31 #include "hurricane/Pins.h"
32 #include "hurricane/Contacts.h"
33 #include "hurricane/Segments.h"
34 #include "hurricane/Verticals.h"
35 #include "hurricane/Horizontals.h"
36 #include "hurricane/Pads.h"
37 #include "hurricane/IntrusiveSet.h"
38 #include "hurricane/Path.h"
39 #include "hurricane/NetAlias.h"
40
41 namespace Hurricane {
42
43
44 // ****************************************************************************************************
45 // Net declaration
46 // ****************************************************************************************************
47
48 class Net : public Entity {
49 // **********************
50
51 // Types
52 // *****
53
54 public: typedef Entity Inherit;
55
56 public: typedef unsigned Arity;
57
58 public: class Type {
59 // ***************
60
61 public: enum Code {UNDEFINED=0, LOGICAL=1, CLOCK=2, POWER=3, GROUND=4, BLOCKAGE=5, FUSED=6};
62
63 private: Code _code;
64
65 public: Type(const Code& code = UNDEFINED);
66 public: Type(const Type& type);
67 public: Type(string);
68
69 public: Type& operator=(const Type& type);
70
71 public: operator const Code&() const {return _code;};
72
73 public: const Code& getCode() const {return _code;};
74
75 public: string _getTypeName() const { return _TName("Net::type"); };
76 public: string _getString() const;
77 public: Record* _getRecord() const;
78
79 };
80
81 public: class Direction {
82 // ********************
83
84 public: enum Code { DirIn = 0x0001
85 , DirOut = 0x0002
86 , DirUndefined = 0x0000
87 , ConnTristate = 0x0100
88 , ConnWiredOr = 0x0200
89 , UNDEFINED = DirUndefined
90 , IN = DirIn
91 , OUT = DirOut
92 , INOUT = DirIn | DirOut
93 , TRISTATE = DirOut | ConnTristate
94 , TRANSCV = DirIn | DirOut | ConnTristate
95 , WOR_OUT = DirOut | ConnWiredOr
96 , WOR_INOUT = DirIn | DirOut | ConnWiredOr
97 , DirMask = DirIn | DirOut | DirUndefined
98 };
99
100 private: Code _code;
101
102 public: Direction(const Code& code = UNDEFINED);
103 public: Direction(const Direction& direction);
104 public: Direction(string);
105
106 public: Direction& operator =(const Direction& direction);
107 public: Direction& operator|=(const Direction& direction);
108
109 public: operator const Code&() const {return _code;};
110
111 public: const Code& getCode() const {return _code;};
112
113 public: string _getTypeName() const { return _TName("Net::Direction"); };
114 public: string _getString() const;
115 public: Record* _getRecord() const;
116
117 };
118
119 class ComponentSet : public IntrusiveSet<Component> {
120 // ************************************************
121
122 public: typedef IntrusiveSet<Component> Inherit;
123
124 public: ComponentSet();
125
126 public: virtual unsigned _getHashValue(Component* component) const;
127 public: virtual Component* _getNextElement(Component* component) const;
128 public: virtual void _setNextElement(Component* component, Component* nextComponent) const;
129
130 };
131
132 class RubberSet : public IntrusiveSet<Rubber> {
133 // ******************************************
134
135 public: typedef IntrusiveSet<Rubber> Inherit;
136
137 public: RubberSet();
138
139 public: virtual unsigned _getHashValue(Rubber* rubber) const;
140 public: virtual Rubber* _getNextElement(Rubber* rubber) const;
141 public: virtual void _setNextElement(Rubber* rubber, Rubber* nextRubber) const;
142
143 };
144
145 // Attributes
146 // **********
147
148 private: Cell* _cell;
149 private: Name _name;
150 private: Arity _arity;
151 private: bool _isGlobal;
152 private: bool _isExternal;
153 private: bool _isAutomatic;
154 private: Type _type;
155 private: Direction _direction;
156 private: Point _position;
157 private: ComponentSet _componentSet;
158 private: RubberSet _rubberSet;
159 private: Net* _nextOfCellNetMap;
160 private: NetMainName _mainName;
161
162 // Constructors
163 // ************
164
165 protected: Net(Cell* cell, const Name& name);
166
167 public: static Net* create(Cell* cell, const Name& name);
168
169 // Accessors
170 // *********
171
172 public: virtual Cell* getCell() const {return _cell;};
173 public: virtual Box getBoundingBox() const;
174 public: const Name& getName() const {return _name;};
175 public: const NetMainName* getMainName() const { return &_mainName; }
176 public: const Arity& getArity() const {return _arity;};
177 public: const Type& getType() const {return _type;};
178 public: const Direction& getDirection() const {return _direction;};
179 public: const Point& getPosition() const {return _position;};
180 public: const DbU::Unit& getX() const {return _position.getX();};
181 public: const DbU::Unit& getY() const {return _position.getY();};
182 public: Components getComponents() const {return _componentSet.getElements();};
183 public: Rubbers getRubbers() const {return _rubberSet.getElements();};
184 public: RoutingPads getRoutingPads() const;
185 public: Plugs getPlugs() const;
186 public: Pins getPins() const;
187 public: Contacts getContacts() const;
188 public: Segments getSegments() const;
189 public: Verticals getVerticals() const;
190 public: Horizontals getHorizontals() const;
191 public: Pads getPads() const;
192 public: Plugs getSlavePlugs() const;
193 public: Plugs getConnectedSlavePlugs() const;
194 public: Plugs getUnconnectedSlavePlugs() const;
195 public: Aliases getAliases() const { return new AliasList(this); };
196
197 // Filters
198 // *******
199
200 public: static NetFilter getIsCellNetFilter();
201 public: static NetFilter getIsDeepNetFilter();
202 public: static NetFilter getIsGlobalFilter();
203 public: static NetFilter getIsExternalFilter();
204 public: static NetFilter getIsInternalFilter();
205 public: static NetFilter getIsClockFilter();
206 public: static NetFilter getIsSupplyFilter();
207 public: static NetFilter getIsPowerFilter();
208 public: static NetFilter getIsGroundFilter();
209
210 // Predicates
211 // **********
212
213 public: virtual bool isDeepNet () const {return false;};
214 public: bool isGlobal () const {return _isGlobal;};
215 public: bool isExternal () const {return _isExternal;};
216 public: bool isAutomatic() const {return _isAutomatic;};
217 public: bool isBlockage () const {return (_type == Type::BLOCKAGE);};
218 public: bool isFused () const {return (_type == Type::FUSED);};
219 public: bool isLogical () const {return (_type == Type::LOGICAL);};
220 public: bool isClock () const {return (_type == Type::CLOCK);};
221 public: bool isPower () const {return (_type == Type::POWER);};
222 public: bool isGround () const {return (_type == Type::GROUND);};
223 public: bool isSupply () const {return (isPower() || isGround());};
224 public: bool hasAlias (const Name& name) const;
225
226 // Updators
227 // ********
228
229 public: void setName(Name name);
230 public: void setArity(const Arity& arity);
231 public: void setGlobal(bool isGlobal);
232 public: void setExternal(bool isExternal);
233 public: void setAutomatic(bool isAutomatic);
234 public: void setType(const Type& type);
235 public: void setDirection(const Direction& direction);
236 public: void setPosition(const Point& position);
237 public: void setRoutingState(uint32_t state);
238 public: void materialize();
239 public: void unmaterialize();
240 public: bool addAlias(const Name& name);
241 public: bool removeAlias(const Name& name);
242 public: void merge(Net* net);
243 public: Net* getClone(Cell* cloneCell);
244
245 // Others
246 // ******
247
248 protected: virtual void _postCreate();
249 protected: virtual void _preDestroy();
250
251 public: virtual void _toJson(JsonWriter*) const;
252 public: virtual void _toJsonSignature(JsonWriter*) const;
253 public: virtual void _toJsonCollections(JsonWriter*) const;
254 public: virtual string _getTypeName() const {return _TName("Net");};
255 public: virtual string _getString() const;
256 public: virtual Record* _getRecord() const;
257 public: NetMainName& _getMainName() { return _mainName; }
258 public: ComponentSet& _getComponentSet() {return _componentSet;};
259 public: RubberSet& _getRubberSet() {return _rubberSet;};
260 public: Net* _getNextOfCellNetMap() const {return _nextOfCellNetMap;};
261
262 public: void _setNextOfCellNetMap(Net* net) {_nextOfCellNetMap = net;};
263
264 public: struct CompareByName {
265 inline bool operator() ( const Net* lhs, const Net* rhs ) const { return lhs->getName() < rhs->getName(); }
266 };
267
268 };
269
270
271 // -------------------------------------------------------------------
272 // Class : "HookKey".
273
274 class HookKey {
275 public:
276 inline HookKey ( unsigned int id, const std::string& tname );
277 inline unsigned int id () const;
278 inline std::string tname () const;
279 private:
280 unsigned int _id;
281 std::string _tname;
282 };
283
284
285 inline HookKey::HookKey ( unsigned int id, const std::string& tname ) : _id(id), _tname(tname) { }
286 inline unsigned int HookKey::id () const { return _id; }
287 inline std::string HookKey::tname () const { return _tname; }
288
289 inline bool operator< ( const HookKey& lhs, const HookKey& rhs )
290 {
291 if (lhs.id() != rhs.id()) return lhs.id() < rhs.id();
292 return lhs.tname() < rhs.tname();
293 }
294
295
296 // -------------------------------------------------------------------
297 // Class : "HookElement".
298
299 class HookElement {
300 public:
301 enum Flags { OpenRingStart = (1<<0)
302 , ClosedRing = (1<<1)
303 };
304 public:
305 inline HookElement ( Hook*, unsigned long flags=0 );
306 inline Hook* hook () const;
307 inline HookElement* next () const;
308 inline void setHook ( Hook* );
309 inline void setNext ( HookElement* );
310 inline unsigned long flags () const;
311 inline HookElement& setFlags ( unsigned long mask );
312 inline HookElement& resetFlags ( unsigned long mask );
313 inline bool issetFlags ( unsigned long mask ) const;
314 private:
315 Hook* _hook;
316 HookElement* _next;
317 unsigned long _flags;
318 };
319
320
321 inline HookElement::HookElement ( Hook* hook, unsigned long flags ) : _hook(hook), _next(NULL), _flags(flags) { }
322 inline Hook* HookElement::hook () const { return _hook; }
323 inline HookElement* HookElement::next () const { return _next; }
324 inline void HookElement::setHook ( Hook* hook ) { _hook = hook; }
325 inline void HookElement::setNext ( HookElement* element ) { _next = element; }
326 inline unsigned long HookElement::flags () const { return _flags; }
327 inline HookElement& HookElement::setFlags ( unsigned long mask ) { _flags |= mask; return *this; }
328 inline HookElement& HookElement::resetFlags ( unsigned long mask ) { _flags &= ~mask; return *this; }
329 inline bool HookElement::issetFlags ( unsigned long mask ) const { return _flags & mask; }
330
331
332 typedef map<HookKey,HookElement> HookLut;
333
334
335 // -------------------------------------------------------------------
336 // Class : "JsonNet".
337
338 class JsonNet : public JsonEntity {
339 public:
340 static bool hookFromString ( std::string s, unsigned int& id, std::string& tname );
341 static void initialize ();
342 JsonNet ( unsigned long flags );
343 virtual ~JsonNet ();
344 virtual string getTypeName () const;
345 virtual JsonNet* clone ( unsigned long ) const;
346 virtual void toData ( JsonStack& );
347 void addHookLink ( Hook*, unsigned int jsonId, const std::string& jsonNext );
348 Hook* getHook ( unsigned int jsonId, const std::string& tname ) const;
349 bool checkRings () const;
350 void buildRings () const;
351 inline void clearHookLinks ();
352 protected:
353 bool _autoMaterialize;
354 Net* _net;
355 HookLut _hooks;
356 };
357
358
359 inline void JsonNet::clearHookLinks () { _hooks.clear(); }
360
361
362 } // Hurricane namespace.
363
364
365 // -------------------------------------------------------------------
366 // Inspector Support for : Net::Type::Code*".
367
368 template<>
369 inline std::string getString<const Hurricane::Net::Type::Code*>
370 ( const Hurricane::Net::Type::Code* object )
371 {
372 switch ( *object ) {
373 case Hurricane::Net::Type::UNDEFINED: return "UNDEFINED";
374 case Hurricane::Net::Type::LOGICAL: return "LOGICAL";
375 case Hurricane::Net::Type::CLOCK: return "CLOCK";
376 case Hurricane::Net::Type::POWER: return "POWER";
377 case Hurricane::Net::Type::GROUND: return "GROUND";
378 case Hurricane::Net::Type::BLOCKAGE: return "BLOCKAGE";
379 case Hurricane::Net::Type::FUSED: return "FUSED";
380 }
381 return "ABNORMAL";
382 }
383
384 template<>
385 inline Hurricane::Record* getRecord<const Hurricane::Net::Type::Code*>
386 ( const Hurricane::Net::Type::Code* object )
387 {
388 Hurricane::Record* record = new Hurricane::Record(getString(object));
389 record->add(getSlot("Code", (unsigned int*)object));
390 return record;
391 }
392
393
394 // -------------------------------------------------------------------
395 // Inspector Support for : "const Net::Direction::Code*".
396
397 template<>
398 inline std::string getString<const Hurricane::Net::Direction::Code*>
399 ( const Hurricane::Net::Direction::Code* object )
400 {
401 std::ostringstream s;
402 s << (((*object) & Hurricane::Net::Direction::DirIn ) ? 'i' : '-');
403 s << (((*object) & Hurricane::Net::Direction::DirOut ) ? 'o' : '-');
404 s << (((*object) & Hurricane::Net::Direction::ConnTristate) ? 't' : '-');
405 s << (((*object) & Hurricane::Net::Direction::ConnWiredOr ) ? 'w' : '-');
406
407 switch ( (int)*object ) {
408 case Hurricane::Net::Direction::UNDEFINED: s << " (UNDEFINED)"; break;
409 case Hurricane::Net::Direction::IN: s << " (IN)"; break;
410 case Hurricane::Net::Direction::OUT: s << " (OUT)"; break;
411 case Hurricane::Net::Direction::INOUT: s << " (INOUT)"; break;
412 case Hurricane::Net::Direction::TRISTATE: s << " (TRISTATE)"; break;
413 case Hurricane::Net::Direction::TRANSCV: s << " (TRANSCV)"; break;
414 case Hurricane::Net::Direction::WOR_OUT: s << " (WOR_OUT)"; break;
415 case Hurricane::Net::Direction::WOR_INOUT: s << " (WOR_INOUT)"; break;
416 }
417 return s.str();
418 }
419
420 template<>
421 inline Hurricane::Record* getRecord<const Hurricane::Net::Direction::Code*>
422 ( const Hurricane::Net::Direction::Code* object )
423 {
424 Hurricane::Record* record = new Hurricane::Record(getString(object));
425 record->add(getSlot("Code", (unsigned int*)object));
426 return record;
427 }
428
429
430 INSPECTOR_P_SUPPORT(Hurricane::Net);
431 INSPECTOR_P_SUPPORT(Hurricane::Net::ComponentSet);
432 INSPECTOR_P_SUPPORT(Hurricane::Net::RubberSet);
433 INSPECTOR_PR_SUPPORT(Hurricane::Net::Type);
434 INSPECTOR_PR_SUPPORT(Hurricane::Net::Direction);
435 IOSTREAM_POINTER_SUPPORT(Hurricane::Net::Type::Code);
436 IOSTREAM_VALUE_SUPPORT(Hurricane::Net::Type::Code);
437 IOSTREAM_POINTER_SUPPORT(Hurricane::Net::Direction::Code);
438 IOSTREAM_VALUE_SUPPORT(Hurricane::Net::Direction::Code);
439
440
441 namespace Hurricane {
442
443 // Force SlotTemplate<> expansion on Net* type.
444 // Because sometimes it didn't happens (?).
445 const SlotTemplate<Net*> dummyNetSlot ( string("dummyNetSlot"), NULL );
446
447 }
448
449 #endif // HURRICANE_NET
450
451
452 // ****************************************************************************************************
453 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
454 // ****************************************************************************************************
Hurricane::Net::getIsGlobalFilter
static NetFilter getIsGlobalFilter()
Hurricane::Net::getIsExternalFilter
static NetFilter getIsExternalFilter()
Hurricane::Net::getType
const Type & getType() const
Definition: Net.h:177
Hurricane::Net::Type::LOGICAL
Definition: Net.h:61
Hurricane::Net::Direction::INOUT
Definition: Net.h:92
Hurricane::Net::getSegments
Segments getSegments() const
Hurricane::Net::getRoutingPads
RoutingPads getRoutingPads() const
Hurricane::Net::Direction::UNDEFINED
Definition: Net.h:89
Hurricane::Net::Inherit
Entity Inherit
Definition: Net.h:54
Hurricane::Net::setGlobal
void setGlobal(bool isGlobal)
Hurricane::Net::getSlavePlugs
Plugs getSlavePlugs() const
Hurricane::Net::setDirection
void setDirection(const Direction &direction)
Hurricane::Net::Direction::ConnTristate
Definition: Net.h:87
Hurricane::Name
Name description (API)
Definition: Name.h:35
Hurricane::Net::isExternal
bool isExternal() const
Definition: Net.h:215
Hurricane::Net::Direction
Definition: Net.h:81
Hurricane::NetFilter
GenericFilter< Net * > NetFilter
Definition: Nets.h:51
Hurricane::DbU::Unit
std::int64_t Unit
Definition: DbU.h:70
Hurricane::Cell
The model (API).
Definition: Cell.h:66
Hurricane::Point
Point description (API)
Definition: Point.h:32
Hurricane::Net::setPosition
void setPosition(const Point &position)
Hurricane::Net::Type::GROUND
Definition: Net.h:61
Hurricane::Net::setExternal
void setExternal(bool isExternal)
Hurricane::Net::getArity
const Arity & getArity() const
Definition: Net.h:176
Hurricane::Net::Direction::DirUndefined
Definition: Net.h:86
Hurricane::Net::Direction::WOR_INOUT
Definition: Net.h:96
Hurricane::GenericCollection
Generic Collection auto-pointer.
Definition: Collection.h:28
Hurricane::Net::Direction::Code
Code
Definition: Net.h:84
Hurricane::Net::getX
const DbU::Unit & getX() const
Definition: Net.h:180
Hurricane::Net::Direction::ConnWiredOr
Definition: Net.h:88
Hurricane::Net::getPads
Pads getPads() const
Hurricane::Net::Type::POWER
Definition: Net.h:61
Hurricane::Net::Direction::TRANSCV
Definition: Net.h:94
Hurricane::Net::getContacts
Contacts getContacts() const
Hurricane::Net::create
static Net * create(Cell *cell, const Name &name)
Hurricane::Net::setName
void setName(Name name)
Hurricane::Net::Direction::OUT
Definition: Net.h:91
Hurricane::Net::materialize
void materialize()
Hurricane::Net::Direction::TRISTATE
Definition: Net.h:93
Hurricane::Net::isLogical
bool isLogical() const
Definition: Net.h:219
Hurricane::Net::Direction::DirIn
Definition: Net.h:84
Hurricane::Net::Type::Code
Code
Definition: Net.h:61
Hurricane::Net::getPlugs
Plugs getPlugs() const
Hurricane::Net::getHorizontals
Horizontals getHorizontals() const
Hurricane::Net::isGlobal
bool isGlobal() const
Definition: Net.h:214
Hurricane::Net::Type
Definition: Net.h:58
Hurricane::Net::getIsClockFilter
static NetFilter getIsClockFilter()
Hurricane::Net::merge
void merge(Net *net)
Hurricane::Net::Direction::DirOut
Definition: Net.h:85
Hurricane::Net::getVerticals
Verticals getVerticals() const
Hurricane::Net::getConnectedSlavePlugs
Plugs getConnectedSlavePlugs() const
Hurricane::Net::Direction::WOR_OUT
Definition: Net.h:95
Entity
Hurricane::Net::getComponents
Components getComponents() const
Definition: Net.h:182
Hurricane::Net::isSupply
bool isSupply() const
Definition: Net.h:223
Hurricane::Net::getRubbers
Rubbers getRubbers() const
Definition: Net.h:183
Hurricane::Net::getIsInternalFilter
static NetFilter getIsInternalFilter()
Hurricane::Net::Arity
unsigned Arity
Definition: Net.h:56
Hurricane::Net::getUnconnectedSlavePlugs
Plugs getUnconnectedSlavePlugs() const
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
Hurricane::Net::Type::UNDEFINED
Definition: Net.h:61
Hurricane::Net::setArity
void setArity(const Arity &arity)
Hurricane::Net::setType
void setType(const Type &type)
Hurricane::Net::getIsSupplyFilter
static NetFilter getIsSupplyFilter()
Hurricane::Net::unmaterialize
void unmaterialize()
Hurricane::Net::Direction::IN
Definition: Net.h:90
Hurricane::Net
Net description (API)
Definition: Net.h:48
Hurricane::Net::isClock
bool isClock() const
Definition: Net.h:220
Hurricane::Net::getName
const Name & getName() const
Definition: Net.h:174
Hurricane::Net::getClone
Net * getClone(Cell *cloneCell)
Hurricane::Net::getPosition
const Point & getPosition() const
Definition: Net.h:179
Hurricane::Net::getDirection
const Direction & getDirection() const
Definition: Net.h:178
Hurricane::Net::getY
const DbU::Unit & getY() const
Definition: Net.h:181
Hurricane::Net::Type::CLOCK
Definition: Net.h:61