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 <stdlib.h>
32 #include "lex.h"
33 #include "defiTimingDisable.hpp"
34 #include "defiDebug.hpp"
35 
36 BEGIN_LEFDEF_PARSER_NAMESPACE
37 
38 
39 //////////////////////////////////////////////
40 //////////////////////////////////////////////
41 //
42 //   defiTimingDisable
43 //
44 //////////////////////////////////////////////
45 //////////////////////////////////////////////
46 
47 
defiTimingDisable(defrData * data)48 defiTimingDisable::defiTimingDisable(defrData *data)
49  : defData(data)
50 {
51   Init();
52 }
53 
54 
Init()55 void defiTimingDisable::Init() {
56   fromInst_ = 0;
57   fromInstLength_ = 0;
58   toInst_ = 0;
59   toInstLength_ = 0;
60   toPin_ = 0;
61   toPinLength_ = 0;
62   fromPin_ = 0;
63   fromPinLength_ = 0;
64 }
65 
66 
~defiTimingDisable()67 defiTimingDisable::~defiTimingDisable() {
68   Destroy();
69 }
70 
71 
Destroy()72 void defiTimingDisable::Destroy() {
73 
74   clear();
75 
76   if (fromInst_) free(fromInst_);
77   fromInst_ = 0;
78   fromInstLength_ = 0;
79 
80   if (toInst_) free(toInst_);
81   toInst_ = 0;
82   toInstLength_ = 0;
83 
84   if (toPin_) free(toPin_);
85   toPin_ = 0;
86   toPinLength_ = 0;
87 
88   if (fromPin_) free(fromPin_);
89   fromPin_ = 0;
90   fromPinLength_ = 0;
91 
92 }
93 
94 
clear()95 void defiTimingDisable::clear() {
96   hasFromTo_ = 0;
97   hasThru_ = 0;
98   hasMacro_ = 0;
99   hasReentrantPathsFlag_ = 0;
100 }
101 
102 
setReentrantPathsFlag()103 void defiTimingDisable::setReentrantPathsFlag() {
104   hasReentrantPathsFlag_ = 1;
105 }
106 
107 
setFromTo(const char * fromInst,const char * fromPin,const char * toInst,const char * toPin)108 void defiTimingDisable::setFromTo(const char* fromInst, const char* fromPin,
109 	 const char* toInst, const char* toPin) {
110   int len;
111 
112   clear();
113   hasFromTo_ = 1;
114 
115   len = strlen(fromInst) + 1;
116   if (len > fromInstLength_) {
117     if (fromInst_) free(fromInst_);
118     fromInstLength_ = len;
119     fromInst_ = (char*)malloc(len);
120   }
121   strcpy(fromInst_,defData->DEFCASE(fromInst));
122 
123   len = strlen(fromPin) + 1;
124   if (len > fromPinLength_) {
125     if (fromPin_) free(fromPin_);
126     fromPinLength_ = len;
127     fromPin_ = (char*)malloc(len);
128   }
129   strcpy(fromPin_,defData->DEFCASE(fromPin));
130 
131   len = strlen(toInst) + 1;
132   if (len > toInstLength_) {
133     if (toInst_) free(toInst_);
134     toInstLength_ = len;
135     toInst_ = (char*)malloc(len);
136   }
137   strcpy(toInst_, toInst);
138 
139   len = strlen(toPin) + 1;
140   if (len > toPinLength_) {
141     if (toPin_) free(toPin_);
142     toPinLength_ = len;
143     toPin_ = (char*)malloc(len);
144   }
145   strcpy(toPin_, toPin);
146 
147 }
148 
149 
setThru(const char * fromInst,const char * fromPin)150 void defiTimingDisable::setThru(const char* fromInst, const char* fromPin) {
151   int len;
152 
153   clear();
154   hasThru_ = 1;
155 
156   len = strlen(fromInst) + 1;
157   if (len > fromInstLength_) {
158     if (fromInst_) free(fromInst_);
159     fromInstLength_ = len;
160     fromInst_ = (char*)malloc(len);
161   }
162   strcpy(fromInst_,defData->DEFCASE(fromInst));
163 
164   len = strlen(fromPin) + 1;
165   if (len > fromPinLength_) {
166     if (fromPin_) free(fromPin_);
167     fromPinLength_ = len;
168     fromPin_ = (char*)malloc(len);
169   }
170   strcpy(fromPin_,defData->DEFCASE(fromPin));
171 
172 }
173 
174 
setMacroFromTo(const char * fromPin,const char * toPin)175 void defiTimingDisable::setMacroFromTo(const char* fromPin, const char* toPin) {
176   int len;
177 
178   clear();
179   hasFromTo_ = 1;
180 
181   len = strlen(fromPin) + 1;
182   if (len > fromPinLength_) {
183     if (fromPin_) free(fromPin_);
184     fromPinLength_ = len;
185     fromPin_ = (char*)malloc(len);
186   }
187   strcpy(fromPin_,defData->DEFCASE(fromPin));
188 
189   len = strlen(toPin) + 1;
190   if (len > toPinLength_) {
191     if (toPin_) free(toPin_);
192     toPinLength_ = len;
193     toPin_ = (char*)malloc(len);
194   }
195   strcpy(toPin_,defData->DEFCASE(toPin));
196 
197 }
198 
199 
setMacroThru(const char * thru)200 void defiTimingDisable::setMacroThru(const char* thru) {
201   int len;
202 
203   clear();
204 
205   hasThru_ = 1;
206 
207   len = strlen(thru) + 1;
208   if (len > fromPinLength_) {
209     if (fromPin_) free(fromPin_);
210     fromPinLength_ = len;
211     fromPin_ = (char*)malloc(len);
212   }
213   strcpy(fromPin_,defData->DEFCASE(thru));
214 
215 }
216 
217 
setMacro(const char * name)218 void defiTimingDisable::setMacro(const char* name) {
219   int len;
220 
221   // hasThru_ or hasFromTo_ was already set.
222   // clear() was already called.
223   hasMacro_ = 1;
224 
225   len = strlen(name) + 1;
226   if (len > fromInstLength_) {
227     if (fromInst_) free(fromInst_);
228     fromInstLength_ = len;
229     fromInst_ = (char*)malloc(len);
230   }
231   strcpy(fromInst_,defData->DEFCASE(name));
232 }
233 
234 
print(FILE * f) const235 void defiTimingDisable::print(FILE* f) const {
236 
237   if (hasMacroFromTo()) {
238     fprintf(f, "TimingDisable macro '%s' thru '%s'\n",
239 	fromInst_, fromPin_);
240 
241   } else if (hasMacroThru()) {
242     fprintf(f, "TimingDisable macro '%s' from '%s' to '%s'\n",
243 	fromInst_, fromPin_, toPin_);
244 
245   } else if (hasFromTo()) {
246     fprintf(f, "TimingDisable from '%s' '%s'  to '%s' '%s'\n",
247       fromInst_, fromPin_, toInst_, toPin_);
248 
249   } else if (hasThru()) {
250     fprintf(f, "TimingDisable thru '%s' '%s'\n",
251       fromInst_, fromPin_);
252 
253   } else {
254     defiError(0, 6170, "ERROR (DEFPARS-6170): The TimingDisable type is invalid. The valid types are FROMPIN, & THRUPIN. Specify the valid type and then try again.", defData);
255   }
256 }
257 
258 
hasReentrantPathsFlag() const259 int defiTimingDisable::hasReentrantPathsFlag() const {
260   return hasReentrantPathsFlag_;
261 }
262 
263 
hasMacroFromTo() const264 int defiTimingDisable::hasMacroFromTo() const {
265   return (hasMacro_ && hasFromTo_) ? 1 : 0;
266 }
267 
268 
hasMacroThru() const269 int defiTimingDisable::hasMacroThru() const {
270   return (hasMacro_ && hasThru_) ? 1 : 0;
271 }
272 
273 
hasThru() const274 int defiTimingDisable::hasThru() const {
275   return (hasMacro_ == 0 && hasThru_) ? 1 : 0;
276 }
277 
278 
hasFromTo() const279 int defiTimingDisable::hasFromTo() const {
280   return (hasMacro_ == 0 && hasFromTo_) ? 1 : 0;
281 }
282 
283 
toPin() const284 const char* defiTimingDisable::toPin() const {
285   return toPin_;
286 }
287 
288 
fromPin() const289 const char* defiTimingDisable::fromPin() const {
290   return fromPin_;
291 }
292 
293 
toInst() const294 const char* defiTimingDisable::toInst() const {
295   return toInst_;
296 }
297 
298 
fromInst() const299 const char* defiTimingDisable::fromInst() const {
300   return fromInst_;
301 }
302 
303 
macroName() const304 const char* defiTimingDisable::macroName() const {
305   return fromInst_;
306 }
307 
308 
thruPin() const309 const char* defiTimingDisable::thruPin() const {
310   return fromPin_;
311 }
312 
313 
thruInst() const314 const char* defiTimingDisable::thruInst() const {
315   return fromInst_;
316 }
317 
318 
319 END_LEFDEF_PARSER_NAMESPACE
320 
321