# Hurricane Documentation

# Hurricane VLSI Database

Query.h
1 // -*- C++ -*-
2 //
3 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
4 //
5 // This file is part of Hurricane.
6 //
7 // Hurricane is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as
9 // 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
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
14 // TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the Lesser GNU General Public
18 // License along with Hurricane. If not, see
19 // <http://www.gnu.org/licenses/>.
20 //
21 // +-----------------------------------------------------------------+
22 // | H U R R I C A N E |
23 // | V L S I B a c k e n d D a t a - B a s e |
24 // | |
25 // | Author : Jean-Paul CHAPUT |
26 // | E-mail : Jean-Paul.Chaput@lip6.fr |
27 // | =============================================================== |
28 // | C++ Header : "./hurricane/Query.h" |
29 // +-----------------------------------------------------------------+
30
31
32 #pragma once
33 #include <vector>
34 #include "hurricane/Commons.h"
35 #include "hurricane/Box.h"
36 #include "hurricane/Transformation.h"
37 #include "hurricane/Cell.h"
38 #include "hurricane/Instance.h"
39
40
41 namespace Hurricane {
42
43 class BasicLayer;
44 class Go;
45 class QueryStack;
46
47
48 // -------------------------------------------------------------------
49 // Slave Class : "QueryState".
50
51 class QueryState {
52 private:
53 inline QueryState ( Locator<Instance*>* locator );
54 inline QueryState ( Locator<Instance*>* locator
55 , const Box& area
56 , const Transformation& transformation
57 , const Path& path
58 );
59 QueryState ( const QueryState& );
60 QueryState& operator= ( const QueryState& );
61 inline ~QueryState ();
62 private:
63 Locator<Instance*>* _locator;
64 Box _area;
65 Transformation _transformation;
66 Path _path;
67
68 friend class QueryStack;
69 };
70
71
72 // QueryState Inline Functions.
73
74
75 inline QueryState::QueryState ( Locator<Instance*>* locator )
76 : _locator (locator)
77 , _area ()
78 , _transformation()
79 , _path ()
80 { }
81
82
83 inline QueryState::QueryState ( Locator<Instance*>* locator
84 , const Box& area
85 , const Transformation& transformation
86 , const Path& path
87 )
88 : _locator (locator)
89 , _area (area)
90 , _transformation(transformation)
91 , _path (path)
92 { }
93
94
95 inline QueryState::~QueryState ()
96 {
97 if ( _locator ) delete _locator;
98 }
99
100
101 // -------------------------------------------------------------------
102 // Class : "QueryStack".
103
104
105 class QueryStack : public vector<QueryState*> {
106 public:
107 // Constructor & destructor.
108 QueryStack ();
109 ~QueryStack ();
110 // Accessors.
111 inline Cell* getTopCell ();
112 inline const Box& getTopArea () const;
113 inline const Transformation& getTopTransformation () const;
114 inline unsigned int getStartLevel () const;
115 inline unsigned int getStopLevel () const;
116 inline Cell* getMasterCell ();
117 inline Instance* getInstance ();
118 inline const Box& getArea () const;
119 inline DbU::Unit getThreshold () const;
120 inline const Transformation& getTransformation () const;
121 inline const Path& getPath () const;
122 //inline const Tabulation& getTab () const;
123 // Modifiers.
124 inline void setTopCell ( Cell* cell );
125 inline void setTopArea ( const Box& area );
126 inline void setTopTransformation ( const Transformation& transformation );
127 inline void setThreshold ( DbU::Unit threshold );
128 inline void setStartLevel ( unsigned int level );
129 inline void setStopLevel ( unsigned int level );
130 inline void init ();
131 inline void updateTransformation ();
132 inline bool levelDown ();
133 inline void levelUp ();
134 inline void levelProgress ();
135 inline bool levelCompleted ();
136 inline void progress ( bool init=false );
137
138 protected:
139 // Internal: Attributes.
140 // Tabulation _tab;
141 Cell* _topCell;
142 Box _topArea;
143 DbU::Unit _threshold;
144 Transformation _topTransformation;
145 unsigned int _startLevel;
146 unsigned int _stopLevel;
147
148 private:
149 // Internal: Constructors.
150 QueryStack ( const QueryStack& );
151 QueryStack& operator= ( const QueryStack& );
152 };
153
154
155 // QueryStack Inline Functions.
156
157
158 inline Cell* QueryStack::getTopCell () { return _topCell; }
159 inline const Box& QueryStack::getTopArea () const { return _topArea; }
160 inline const Transformation& QueryStack::getTopTransformation () const { return _topTransformation; }
161 inline DbU::Unit QueryStack::getThreshold () const { return _threshold; }
162 inline unsigned int QueryStack::getStartLevel () const { return _startLevel; }
163 inline unsigned int QueryStack::getStopLevel () const { return _stopLevel; }
164 inline const Box& QueryStack::getArea () const { return back()->_area; }
165 inline const Transformation& QueryStack::getTransformation () const { return back()->_transformation; }
166 inline const Path& QueryStack::getPath () const { return back()->_path; }
167 //inline const Tabulation& QueryStack::getTab () const { return _tab; }
168
169
170 inline Instance* QueryStack::getInstance ()
171 {
172 if ( levelCompleted() ) return NULL;
173 return back()->_locator->getElement();
174 }
175
176
177 inline Cell* QueryStack::getMasterCell ()
178 {
179 if ( size() == 1 ) return _topCell;
180 if ( !getInstance() ) return NULL;
181 return getInstance()->getMasterCell();
182 }
183
184
185 inline void QueryStack::setTopCell ( Cell* cell ) { _topCell = cell; }
186 inline void QueryStack::setTopArea ( const Box& area ) { _topArea = area; }
187 inline void QueryStack::setTopTransformation ( const Transformation& transformation ) { _topTransformation = transformation; }
188 inline void QueryStack::setThreshold ( DbU::Unit threshold ) { _threshold = threshold; }
189 inline void QueryStack::setStartLevel ( unsigned int level ) { _startLevel = level; }
190 inline void QueryStack::setStopLevel ( unsigned int level ) { _stopLevel = level; }
191
192
193 inline void QueryStack::init ()
194 {
195 while ( !empty() ) levelUp();
196
197 push_back ( new QueryState(NULL,_topArea,_topTransformation,Path()) );
198 //_tab++;
199
200 progress ( true );
201 }
202
203
204 inline void QueryStack::updateTransformation ()
205 {
206 QueryState* child = *(rbegin() );
207 QueryState* parent = *(rbegin()+1);
208 Instance* instance = child->_locator->getElement();
209
210 //cerr << "Processing " << instance << endl;
211
212 child->_area = parent->_area;
213 child->_transformation = instance->getTransformation ();
214
215 instance->getTransformation().getInvert().applyOn ( child->_area );
216 parent->_transformation.applyOn ( child->_transformation );
217
218 //child->_path = Path ( Path(parent->_path,instance->getCell()->getShuntedPath()) , instance );
219 child->_path = Path ( parent->_path, instance );
220 }
221
222
223 inline bool QueryStack::levelDown ()
224 {
225 if ( size() > _stopLevel ) return false;
226
227 //cerr << "QueryStack::levelDown(): t:" << DbU::getValueString(getThreshold()) << endl;
228 Locator<Instance*>* locator =
229 getMasterCell()->getInstancesUnder(getArea(),getThreshold()).getLocator();
230
231 if ( locator->isValid() ) {
232 push_back ( new QueryState ( locator ) );
233
234 updateTransformation ();
235 //_tab++;
236
237 return true;
238 } else
239 delete locator;
240
241 //cerr << " Aborting level down" << endl;
242 return false;
243 }
244
245
246 inline void QueryStack::levelUp ()
247 {
248 delete back ();
249 pop_back ();
250 //_tab--;
251 }
252
253
254 inline bool QueryStack::levelCompleted ()
255 {
256 if ( !back()->_locator || !back()->_locator->isValid () ) return true;
257 return false;
258 }
259
260
261 inline void QueryStack::levelProgress ()
262 {
263 if ( levelCompleted() ) return;
264
265 back()->_locator->progress ();
266 if ( !back()->_locator->isValid() ) return;
267
268 updateTransformation ();
269 }
270
271
272 inline void QueryStack::progress ( bool init )
273 {
274 if ( !init ) levelProgress ();
275 else {
276 if ( !levelDown() && ( size() > _startLevel ) )
277 return;
278 }
279
280 while ( !empty() ) {
281 if ( levelCompleted() ) {
282 levelUp ();
283 } else {
284 if ( levelDown() ) continue;
285 }
286
287 if ( size() > _startLevel ) return;
288 if ( empty() ) break;
289 levelProgress ();
290 }
291 }
292
293
294 // -------------------------------------------------------------------
295 // Class : "Query".
296
297 class Query {
298 public:
299 typedef Hurricane::Mask<int> Mask;
300 public:
301 // Types.
302 enum QueryFilter { DoMasterCells = 1
303 , DoTerminalCells = 2
304 , DoComponents = 4
305 , DoMarkers = 8
306 , DoRubbers = 16
307 , DoExtensionGos = 32
308 , DoAll = DoMasterCells
309 | DoTerminalCells
310 | DoComponents
311 | DoMarkers
312 | DoRubbers
313 | DoExtensionGos
314 };
315 public:
316 // Constructors & Destructors.
317 Query ();
318 virtual ~Query ();
319 // Accessors.
320 inline unsigned int getStartLevel () const;
321 inline unsigned int getStopLevel () const;
322 inline size_t getDepth () const;
323 inline const Transformation& getTransformation () const;
324 inline const Box& getArea () const;
325 inline DbU::Unit getThreshold () const;
326 inline const BasicLayer* getBasicLayer () const;
327 inline Cell* getMasterCell ();
328 inline Instance* getInstance ();
329 inline Path getPath () const;
330 //inline const Tabulation& getTab () const;
331 virtual bool hasGoCallback () const;
332 virtual bool hasMarkerCallback () const;
333 virtual bool hasRubberCallback () const;
334 virtual bool hasExtensionGoCallback () const;
335 virtual bool hasMasterCellCallback () const;
336 virtual void goCallback ( Go* ) = 0;
337 virtual void markerCallback ( Marker* );
338 virtual void rubberCallback ( Rubber* );
339 virtual void extensionGoCallback ( Go* ) = 0;
340 virtual void masterCellCallback () = 0;
341 // Modifiers.
342 void setQuery ( Cell* cell
343 , const Box& area
344 , const Transformation& transformation
345 , const BasicLayer* basicLayer
346 , ExtensionSlice::Mask extensionMask
347 , Mask filter
348 , DbU::Unit threshold=0
349 );
350 inline void setCell ( Cell* cell );
351 inline void setArea ( const Box& area );
352 inline void setThreshold ( DbU::Unit threshold );
353 inline void setTransformation ( const Transformation& transformation );
354 virtual void setBasicLayer ( const BasicLayer* basicLayer );
355 inline void setExtensionMask ( ExtensionSlice::Mask mode );
356 inline void setFilter ( Mask mode );
357 inline void setStartLevel ( unsigned int level );
358 inline void setStopLevel ( unsigned int level );
359 virtual void doQuery ();
360
361 protected:
362 // Internal: Attributes.
363 QueryStack _stack;
364 const BasicLayer* _basicLayer;
365 ExtensionSlice::Mask _extensionMask;
366 Mask _filter;
367 };
368
369
370 // Query Inline Functions.
371
372 inline void Query::setCell ( Cell* cell ) { _stack.setTopCell(cell); }
373 inline void Query::setArea ( const Box& area ) { _stack.setTopArea(area); }
374 inline void Query::setThreshold ( DbU::Unit threshold ) { _stack.setThreshold(threshold); }
375 inline void Query::setTransformation ( const Transformation& transformation ) { _stack.setTopTransformation(transformation); }
376 inline void Query::setFilter ( Mask filter ) { _filter = filter; }
377 inline void Query::setExtensionMask ( ExtensionSlice::Mask mask ) { _extensionMask = mask; }
378 inline void Query::setStartLevel ( unsigned int level ) { _stack.setStartLevel(level); }
379 inline void Query::setStopLevel ( unsigned int level ) { _stack.setStopLevel(level); }
380
381 inline unsigned int Query::getStartLevel () const { return _stack.getStartLevel(); }
382 inline unsigned int Query::getStopLevel () const { return _stack.getStopLevel(); }
383 inline size_t Query::getDepth () const { return _stack.size(); }
384 inline const Box& Query::getArea () const { return _stack.getArea(); }
385 inline const Transformation& Query::getTransformation () const { return _stack.getTransformation(); }
386 inline Path Query::getPath () const { return _stack.getPath(); }
387 inline const BasicLayer* Query::getBasicLayer () const { return _basicLayer; }
388 inline Cell* Query::getMasterCell () { return _stack.getMasterCell(); }
389 inline Instance* Query::getInstance () { return _stack.getInstance(); }
390 //inline const Tabulation& Query::getTab () const { return _stack.getTab(); }
391
392
393 } // Hurricane namespace.
Hurricane::Path
Path description (API)
Definition: Path.h:37
Hurricane::Query::DoComponents
Definition: Query.h:304
Hurricane::Go
Go description (API)
Definition: Go.h:36
Hurricane::Query::getStopLevel
unsigned int getStopLevel() const
Definition: Query.h:382
Hurricane::BasicLayer
BasicLayer description (API)
Definition: BasicLayer.h:44
Hurricane::Query::setStartLevel
void setStartLevel(unsigned int level)
Definition: Query.h:378
Hurricane::Query::getArea
const Box & getArea() const
Definition: Query.h:384
Hurricane::Query::DoExtensionGos
Definition: Query.h:307
Hurricane::Query::getInstance
Instance * getInstance()
Definition: Query.h:389
Hurricane::Query
Query description (API)
Definition: Query.h:297
Hurricane::Query::setBasicLayer
virtual void setBasicLayer(const BasicLayer *basicLayer)
Hurricane::Query::~Query
virtual ~Query()
Hurricane::Query::Query
Query()
Hurricane::DbU::Unit
std::int64_t Unit
Definition: DbU.h:70
Hurricane::Cell
The model (API).
Definition: Cell.h:66
Hurricane::Query::DoTerminalCells
Definition: Query.h:303
Hurricane::Query::markerCallback
virtual void markerCallback(Marker *)
Hurricane::Query::setArea
void setArea(const Box &area)
Definition: Query.h:373
Hurricane::Query::hasGoCallback
virtual bool hasGoCallback() const
Hurricane::Query::setQuery
void setQuery(Cell *cell, const Box &area, const Transformation &transformation, const BasicLayer *basicLayer, ExtensionSlice::Mask extensionMask, Mask filter, DbU::Unit threshold=0)
Hurricane::Query::DoMarkers
Definition: Query.h:305
Hurricane::Query::getStartLevel
unsigned int getStartLevel() const
Definition: Query.h:381
Hurricane::Query::setStopLevel
void setStopLevel(unsigned int level)
Definition: Query.h:379
Hurricane::Transformation
Transformation description (API)
Definition: Transformation.h:32
Hurricane::Query::getDepth
size_t getDepth() const
Definition: Query.h:383
Hurricane::Query::rubberCallback
virtual void rubberCallback(Rubber *)
Hurricane::Query::setFilter
void setFilter(Mask mode)
Definition: Query.h:376
Hurricane::Query::DoRubbers
Definition: Query.h:306
Hurricane::Query::getPath
Path getPath() const
Definition: Query.h:386
Hurricane::Box
Box description (API)
Definition: Box.h:31
Hurricane::Instance
Instance description (API)
Definition: Instance.h:37
Hurricane::Query::setCell
void setCell(Cell *cell)
Definition: Query.h:372
Hurricane::Query::hasMarkerCallback
virtual bool hasMarkerCallback() const
Hurricane::Query::getBasicLayer
const BasicLayer * getBasicLayer() const
Definition: Query.h:387
Hurricane::Query::hasExtensionGoCallback
virtual bool hasExtensionGoCallback() const
Hurricane::Query::masterCellCallback
virtual void masterCellCallback()=0
Hurricane::Query::extensionGoCallback
virtual void extensionGoCallback(Go *)=0
Hurricane::Query::getMasterCell
Cell * getMasterCell()
Definition: Query.h:388
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
Hurricane::Query::setTransformation
void setTransformation(const Transformation &transformation)
Definition: Query.h:375
Hurricane::Query::doQuery
virtual void doQuery()
Hurricane::Query::goCallback
virtual void goCallback(Go *)=0
Hurricane::Query::DoMasterCells
Definition: Query.h:302
Hurricane::Query::QueryFilter
QueryFilter
Definition: Query.h:302
Hurricane::Query::hasRubberCallback
virtual bool hasRubberCallback() const
Hurricane::Query::setExtensionMask
void setExtensionMask(ExtensionSlice::Mask mode)
Definition: Query.h:377
Hurricane::Query::hasMasterCellCallback
virtual bool hasMasterCellCallback() const
Hurricane::Rubber
Rubber description (API)
Definition: Rubber.h:36
Hurricane::Query::DoAll
Definition: Query.h:308
Hurricane::Query::getTransformation
const Transformation & getTransformation() const
Definition: Query.h:385