1 // *****************************************************************************
2 // *****************************************************************************
3 // Copyright 2013 - 2015, Cadence Design Systems
4 //
5 // This  file  is  part  of  the  Cadence  LEF/DEF  Open   Source
6 // Distribution,  Product Version 5.8.
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 //    you may not use this file except in compliance with the License.
10 //    You may obtain a copy of the License at
11 //
12 //        http://www.apache.org/licenses/LICENSE-2.0
13 //
14 //    Unless required by applicable law or agreed to in writing, software
15 //    distributed under the License is distributed on an "AS IS" BASIS,
16 //    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 //    implied. See the License for the specific language governing
18 //    permissions and limitations under the License.
19 //
20 // For updates, support, or to become part of the LEF/DEF Community,
21 // check www.openeda.org for details.
22 //
23 //  $Author: dell $
24 //  $Revision: #1 $
25 //  $Date: 2017/06/06 $
26 //  $State:  $
27 // *****************************************************************************
28 // *****************************************************************************
29 
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "lex.h"
34 #include "defiBlockage.hpp"
35 #include "defiDebug.hpp"
36 
37 BEGIN_LEFDEF_PARSER_NAMESPACE
38 
39 ////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////
41 //
42 //    defiBlockages
43 //
44 ////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////
46 
defiBlockage(defrData * data)47 defiBlockage::defiBlockage(defrData *data)
48  : defData(data)
49 {
50   Init();
51 }
52 
53 
Init()54 void defiBlockage::Init() {
55   numPolys_ = 0;
56   clear();
57   layerName_ = 0;
58   componentName_ = 0;
59   layerNameLength_ = 0;
60   componentNameLength_ = 0;
61   xl_ = 0;
62   yl_ = 0;
63   xh_ = 0;
64   yh_ = 0;
65   rectsAllocated_ = 0;
66   polysAllocated_ = 0;
67   polygons_ = 0;
68 }
69 
DEF_COPY_CONSTRUCTOR_C(defiBlockage)70 DEF_COPY_CONSTRUCTOR_C( defiBlockage ) {
71   this->Init();
72   DEF_COPY_FUNC( hasLayer_ );
73   DEF_MALLOC_FUNC( layerName_, char, sizeof(char) *
74       (strlen(prev.layerName_) +1));
75 
76   DEF_COPY_FUNC( layerNameLength_ );
77   DEF_COPY_FUNC( hasPlacement_ );
78   DEF_COPY_FUNC( hasComponent_ );
79   DEF_MALLOC_FUNC( componentName_, char, sizeof(char) *
80       (strlen(prev.componentName_) +1));
81 
82   DEF_COPY_FUNC( componentNameLength_ );
83   DEF_COPY_FUNC( hasSlots_ );
84   DEF_COPY_FUNC( hasFills_ );
85   DEF_COPY_FUNC( hasPushdown_ );
86   DEF_COPY_FUNC( hasExceptpgnet_ );
87   DEF_COPY_FUNC( hasSoft_ );
88   DEF_COPY_FUNC( maxDensity_ );
89   DEF_COPY_FUNC( minSpacing_ );
90   DEF_COPY_FUNC( width_ );
91   DEF_COPY_FUNC( numRectangles_ );
92   DEF_COPY_FUNC( rectsAllocated_ );
93   DEF_COPY_FUNC( mask_ );
94 
95   DEF_MALLOC_FUNC( xl_, int, sizeof(int) * numRectangles_ );
96   DEF_MALLOC_FUNC( yl_, int, sizeof(int) * numRectangles_ );
97   DEF_MALLOC_FUNC( xh_, int, sizeof(int) * numRectangles_ );
98   DEF_MALLOC_FUNC( yh_, int, sizeof(int) * numRectangles_ );
99 
100   DEF_COPY_FUNC( numPolys_ );
101   DEF_COPY_FUNC( polysAllocated_ );
102   DEF_MALLOC_FUNC_FOR_2D_POINT ( polygons_, numPolys_ );
103 }
104 
DEF_ASSIGN_OPERATOR_C(defiBlockage)105 DEF_ASSIGN_OPERATOR_C( defiBlockage ) {
106   CHECK_SELF_ASSIGN
107   this->Init();
108   DEF_COPY_FUNC( hasLayer_ );
109   DEF_MALLOC_FUNC( layerName_, char, sizeof(char) *
110       (strlen(prev.layerName_) +1));
111 
112   DEF_COPY_FUNC( layerNameLength_ );
113   DEF_COPY_FUNC( hasPlacement_ );
114   DEF_COPY_FUNC( hasComponent_ );
115   DEF_MALLOC_FUNC( componentName_, char, sizeof(char) *
116       (strlen(prev.componentName_) +1));
117 
118   DEF_COPY_FUNC( componentNameLength_ );
119   DEF_COPY_FUNC( hasSlots_ );
120   DEF_COPY_FUNC( hasFills_ );
121   DEF_COPY_FUNC( hasPushdown_ );
122   DEF_COPY_FUNC( hasExceptpgnet_ );
123   DEF_COPY_FUNC( hasSoft_ );
124   DEF_COPY_FUNC( maxDensity_ );
125   DEF_COPY_FUNC( minSpacing_ );
126   DEF_COPY_FUNC( width_ );
127   DEF_COPY_FUNC( numRectangles_ );
128   DEF_COPY_FUNC( rectsAllocated_ );
129   DEF_COPY_FUNC( mask_ );
130 
131   DEF_MALLOC_FUNC( xl_, int, sizeof(int) * numRectangles_ );
132   DEF_MALLOC_FUNC( yl_, int, sizeof(int) * numRectangles_ );
133   DEF_MALLOC_FUNC( xh_, int, sizeof(int) * numRectangles_ );
134   DEF_MALLOC_FUNC( yh_, int, sizeof(int) * numRectangles_ );
135 
136   DEF_COPY_FUNC( numPolys_ );
137   DEF_COPY_FUNC( polysAllocated_ );
138   DEF_MALLOC_FUNC_FOR_2D_POINT ( polygons_, numPolys_ );
139   return *this;
140 }
141 
~defiBlockage()142 defiBlockage::~defiBlockage() {
143   Destroy();
144 }
145 
146 
clear()147 void defiBlockage::clear() {
148   hasLayer_ = 0;
149   hasPlacement_ = 0;
150   hasComponent_ = 0;
151   hasSlots_ = 0;
152   hasFills_ = 0;
153   hasPushdown_ = 0;
154   hasExceptpgnet_ = 0;
155   hasSoft_ = 0;
156   maxDensity_ = -1;
157   minSpacing_ = -1;
158   width_ = -1;
159   numRectangles_ = 0;
160   mask_ = 0;
161 }
162 
163 
clearPoly()164 void defiBlockage::clearPoly() {
165   struct defiPoints* p;
166   int i;
167 
168   for (i = 0; i < numPolys_; i++) {
169     p = polygons_[i];
170     free((char*)(p->x));
171     free((char*)(p->y));
172     free((char*)(polygons_[i]));
173   }
174   numPolys_ = 0;
175 }
176 
Destroy()177 void defiBlockage::Destroy() {
178   if (layerName_) free(layerName_);
179   if (componentName_) free(componentName_);
180   layerName_ = 0;
181   componentName_ = 0;
182   if (rectsAllocated_) {
183     free((char*)(xl_));
184     free((char*)(yl_));
185     free((char*)(xh_));
186     free((char*)(yh_));
187     rectsAllocated_ = 0;
188     xl_ = 0;
189     yl_ = 0;
190     xh_ = 0;
191     yh_ = 0;
192   }
193   clearPoly();
194   free((char*)(polygons_));
195   polygons_ = 0;
196   clear();
197 }
198 
199 
setLayer(const char * name)200 void defiBlockage::setLayer(const char* name) {
201   int len = strlen(name) + 1;
202   if (layerNameLength_ < len) {
203     if (layerName_) free(layerName_);
204     layerName_ = (char*)malloc(len);
205     layerNameLength_ = len;
206   }
207   strcpy(layerName_, defData->DEFCASE(name));
208   hasLayer_ = 1;
209 }
210 
211 
setPlacement()212 void defiBlockage::setPlacement() {
213 
214   /* 10/29/2001 - Wanda da Rosa, new enhancement */
215   hasPlacement_ = 1;
216   return;
217 }
218 
setComponent(const char * name)219 void defiBlockage::setComponent(const char* name) {
220   int len;
221 
222   /* 10/29/2001 - Wanda da Rosa, component name is required */
223   len = strlen(name) + 1;
224   if (componentNameLength_ < len) {
225     if (componentName_) free(componentName_);
226     componentName_ = (char*)malloc(len);
227     componentNameLength_ = len;
228   }
229   strcpy(componentName_, defData->DEFCASE(name));
230   hasComponent_ = 1;
231 }
232 
setSlots()233 void defiBlockage::setSlots() {
234   hasSlots_ = 1;
235 }
236 
setFills()237 void defiBlockage::setFills() {
238   hasFills_ = 1;
239 }
240 
setPushdown()241 void defiBlockage::setPushdown() {
242   hasPushdown_ = 1;
243 }
244 
245 // 5.7
setExceptpgnet()246 void defiBlockage::setExceptpgnet() {
247   hasExceptpgnet_ = 1;
248 }
249 
250 // 5.7
setSoft()251 void defiBlockage::setSoft() {
252   hasSoft_ = 1;
253 }
254 
255 // 5.7
setPartial(double maxDensity)256 void defiBlockage::setPartial(double maxDensity) {
257   maxDensity_ = maxDensity;
258 }
259 
setSpacing(int minSpacing)260 void defiBlockage::setSpacing(int minSpacing) {
261   minSpacing_ = minSpacing;
262 }
263 
setDesignRuleWidth(int width)264 void defiBlockage::setDesignRuleWidth(int width) {
265   width_ = width;
266 }
267 
setMask(int colorMask)268 void defiBlockage::setMask(int colorMask) {
269   mask_ = colorMask;
270 }
271 
addRect(int xl,int yl,int xh,int yh)272 void defiBlockage::addRect(int xl, int yl, int xh, int yh) {
273   if (numRectangles_ == rectsAllocated_) {
274     int i;
275     int max = rectsAllocated_ = (rectsAllocated_ == 0) ?
276           2 : rectsAllocated_ * 2;
277     int* newxl = (int*)malloc(sizeof(int)*max);
278     int* newyl = (int*)malloc(sizeof(int)*max);
279     int* newxh = (int*)malloc(sizeof(int)*max);
280     int* newyh = (int*)malloc(sizeof(int)*max);
281     for (i = 0; i < numRectangles_; i++) {
282       newxl[i] = xl_[i];
283       newyl[i] = yl_[i];
284       newxh[i] = xh_[i];
285       newyh[i] = yh_[i];
286     }
287     free((char*)(xl_));
288     free((char*)(yl_));
289     free((char*)(xh_));
290     free((char*)(yh_));
291     xl_ = newxl;
292     yl_ = newyl;
293     xh_ = newxh;
294     yh_ = newyh;
295   }
296   xl_[numRectangles_] = xl;
297   yl_[numRectangles_] = yl;
298   xh_[numRectangles_] = xh;
299   yh_[numRectangles_] = yh;
300   numRectangles_ += 1;
301 }
302 
303 
304 // 5.6
addPolygon(defiGeometries * geom)305 void defiBlockage::addPolygon(defiGeometries* geom) {
306   struct defiPoints* p;
307   int x, y;
308   int i;
309 
310   if (numPolys_ == polysAllocated_) {
311     struct defiPoints** poly;
312     polysAllocated_ = (polysAllocated_ == 0) ?
313           2 : polysAllocated_ * 2;
314     poly = (struct defiPoints**)malloc(sizeof(struct defiPoints*) *
315             polysAllocated_);
316     for (i = 0; i < numPolys_; i++)
317       poly[i] = polygons_[i];
318     if (polygons_)
319       free((char*)(polygons_));
320     polygons_ = poly;
321   }
322   p = (struct defiPoints*)malloc(sizeof(struct defiPoints));
323   p->numPoints = geom->numPoints();
324   p->x = (int*)malloc(sizeof(int)*p->numPoints);
325   p->y = (int*)malloc(sizeof(int)*p->numPoints);
326   for (i = 0; i < p->numPoints; i++) {
327     geom->points(i, &x, &y);
328     p->x[i] = x;
329     p->y[i] = y;
330   }
331   polygons_[numPolys_] = p;
332   numPolys_ += 1;
333 }
334 
335 
hasLayer() const336 int defiBlockage::hasLayer() const {
337   return hasLayer_;
338 }
339 
340 
hasPlacement() const341 int defiBlockage::hasPlacement() const {
342   return hasPlacement_;
343 }
344 
345 
hasComponent() const346 int defiBlockage::hasComponent() const {
347   return hasComponent_;
348 }
349 
350 
hasSlots() const351 int defiBlockage::hasSlots() const {
352   return hasSlots_;
353 }
354 
355 
hasFills() const356 int defiBlockage::hasFills() const {
357   return hasFills_;
358 }
359 
360 
hasPushdown() const361 int defiBlockage::hasPushdown() const {
362   return hasPushdown_;
363 }
364 
365 // 5.7
hasExceptpgnet() const366 int defiBlockage::hasExceptpgnet() const {
367   return hasExceptpgnet_;
368 }
369 
370 // 5.7
hasSoft() const371 int defiBlockage::hasSoft() const {
372   return hasSoft_;
373 }
374 
375 // 5.7
hasPartial() const376 int defiBlockage::hasPartial() const {
377   if (maxDensity_ == -1)
378     return 0;
379   return 1;
380 }
381 
382 // 5.7
placementMaxDensity() const383 double defiBlockage::placementMaxDensity() const {
384   return maxDensity_;
385 }
386 
hasSpacing() const387 int defiBlockage::hasSpacing() const {
388   if (minSpacing_ == -1)
389     return 0;
390   return 1;
391 }
392 
393 
hasDesignRuleWidth() const394 int defiBlockage::hasDesignRuleWidth() const {
395   if (width_ == -1)
396     return 0;
397   return 1;
398 }
399 
hasMask() const400 int defiBlockage::hasMask() const {
401     return mask_;
402 }
403 
minSpacing() const404 int defiBlockage::minSpacing() const {
405   return minSpacing_;
406 }
407 
408 
designRuleWidth() const409 int defiBlockage::designRuleWidth() const {
410   return width_;
411 }
412 
mask() const413 int defiBlockage::mask() const {
414   return mask_;
415 }
416 
layerName() const417 const char* defiBlockage::layerName() const {
418   return layerName_;
419 }
420 
421 
layerComponentName() const422 const char* defiBlockage::layerComponentName() const {
423   return componentName_;
424 }
425 
426 
placementComponentName() const427 const char* defiBlockage::placementComponentName() const {
428   return componentName_;
429 }
430 
431 
numRectangles() const432 int defiBlockage::numRectangles() const {
433   return numRectangles_;
434 }
435 
436 
xl(int index) const437 int defiBlockage::xl(int index) const {
438   if (index < 0 || index >= numRectangles_) {
439     defiError(1, 0, "bad index for blockage xl", defData);
440     return 0;
441   }
442   return xl_[index];
443 }
444 
445 
yl(int index) const446 int defiBlockage::yl(int index) const {
447   if (index < 0 || index >= numRectangles_) {
448     defiError(1, 0, "bad index for blockage yl", defData);
449     return 0;
450   }
451   return yl_[index];
452 }
453 
454 
xh(int index) const455 int defiBlockage::xh(int index) const {
456   if (index < 0 || index >= numRectangles_) {
457     defiError(1, 0, "bad index for blockage xh", defData);
458     return 0;
459   }
460   return xh_[index];
461 }
462 
463 
yh(int index) const464 int defiBlockage::yh(int index) const {
465   if (index < 0 || index >= numRectangles_) {
466     defiError(1, 0, "bad index for blockage yh", defData);
467     return 0;
468   }
469   return yh_[index];
470 }
471 
472 
473 // 5.6
numPolygons() const474 int defiBlockage::numPolygons() const {
475   return numPolys_;
476 }
477 
478 
479 // 5.6
getPolygon(int index) const480 struct defiPoints defiBlockage::getPolygon(int index) const {
481   return *(polygons_[index]);
482 }
483 
484 
print(FILE * f) const485 void defiBlockage::print(FILE* f) const {
486   int i, j;
487   struct defiPoints points;
488 
489   if (hasLayer()) {
490     fprintf(f, "- LAYER %s", layerName());
491     if (hasComponent())
492       fprintf(f, " + COMPONENT %s", layerComponentName());
493     if (hasSlots())
494       fprintf(f, " + SLOTS");
495     if (hasFills())
496       fprintf(f, " + FILLS");
497     if (hasPushdown())
498       fprintf(f, " + PUSHDOWN");
499     if (hasExceptpgnet())
500       fprintf(f, " + EXCEPTPGNET");
501     fprintf(f, "\n");
502   }
503   if (hasPlacement()) {
504     fprintf(f, "- PLACEMENT");
505     if (hasComponent())
506       fprintf(f, " + COMPONENT %s", layerComponentName());
507     if (hasPushdown())
508       fprintf(f, " + PUSHDOWN");
509     if (hasSoft())
510       fprintf(f, " + SOFT");
511     if (hasPartial())
512       fprintf(f, " + PARTIAL %f", placementMaxDensity());
513     fprintf(f, "\n");
514   }
515 
516   for (i = 0; i < numRectangles(); i++) {
517     fprintf(f, "   RECT %d %d %d %d\n", xl(i), yl(i), xh(i), yh(i));
518   }
519 
520   for (i = 0; i < numPolygons(); i++) {
521     fprintf(f, "   POLYGON ");
522     points = getPolygon(i);
523     for (j = 0; j < points.numPoints; j++)
524       fprintf(f, "%d %d ", points.x[j], points.y[j]);
525     fprintf(f,"\n");
526   }
527   fprintf(f,"\n");
528 }
529 END_LEFDEF_PARSER_NAMESPACE
530 
531