1 /***************************************************************************
2 SCED - Schematic Capture Editor
3 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
4 Copyright 1990 Regents of the University of California.  All rights reserved.
5 Authors: 1981 Giles C. Billingsley, Ken Keller  (parts of KIC layout editor)
6          1992 Stephen R. Whiteley
7 ****************************************************************************/
8 
9 /*
10  * CD package data structures.
11  *
12  */
13 
14 #include <stdio.h>
15 #include <math.h>
16 #include "cdmacs.h"
17 #include "cdprpty.h"
18 
19 #define CDDelete CDDeleteObjectDesc
20 
21 #define FILENAMESIZE      32    /* maximum size of a file name */
22 
23 /*
24  * Values routines return in StatusInt of CDOpen, CDBeginMakeCall,
25  * CDTo, CDFrom, or CDParseCIF.
26  */
27 #define CDPARSEFAILED      1    /* (FATAL) parse failed */
28 #define CDOLDSYMBOL        2    /* symbol already exists in database */
29 #define CDNEWSYMBOL        3    /* (empty) symbol not in search path */
30 #define CDSUCCEEDED        4    /* new symbol(s) found in search path */
31 
32 /*
33  * Valid arguments to CDError().
34  */
35 #define CDMALLOCFAILED    11    /* (FATAL) out of memory */
36 #define CDBADBOX          12    /* zero width or length box */
37 #define CDXFORMSTACKFULL  13    /* transform stack overflow */
38 #define CDBADPATH         14    /* bad directory name in search path */
39 
40 /*
41  * Types of geometries
42  */
43 #define CDSYMBOLCALL      'c'
44 #define CDPOLYGON         'p'
45 #define CDROUNDFLASH      'r'
46 #define CDLABEL           'l'
47 #define CDWIRE            'w'
48 #define CDBOX             'b'
49 
50 /*
51  * Types of transformations
52  */
53 #define CDMIRRORX         'x'    /* mirror in the direction of x */
54 #define CDMIRRORY         'y'    /* mirror in the direction of y */
55 #define CDROTATE          'r'    /* rotate by vector X,Y */
56 #define CDTRANSLATE       't'    /* translate to X,Y */
57 
58 /*
59  * CD Control flags; See struct d below.
60  */
61 #define DCONTROLCDOPEN    'o'
62 #define DCONTROLPCIF      'p'
63 #define DCONTROLCDTO      't'
64 #define DCONTROLVANILLA   'v'
65 
66 /*
67  * Coordinate system with 1 micron features and 1 cm dice.
68  * Remember that there are 100 CIF units per micron.
69  */
70 #define CDINFINITY        100000000L
71 
72 /*
73  * These are the numbers that CD uses to determine which bin an object
74  * resides in.  They should reflect the average size of a layout being
75  * edited by KIC.  KIC will not fail if the numbers are too small.
76  * Anything outside of this window is placed in the residual bin.
77  * If these numbers become too large, CDIntersect() must use floating
78  * point calculations.
79  */
80 #define CDBINMAXX        500000L
81 #define CDBINMAXY        500000L
82 #define CDBINMINX        (-CDBINMAXX)
83 #define CDBINMINY        (-CDBINMAXY)
84 
85 /*
86  * PLEASE NOTE
87  * ^^^^^^^^^^^
88  * Because a char is used as the layer fields, the absolute maximum
89  * number of layers is 127.  The may be increase by recompiling
90  * KIC and CD with the Layer typed as ints.
91  */
92 #define CDNUMBINS        10
93 #define CDNUMLAYERS      35
94 
95 /*
96  * Number of symbols stored in the symbol table for any given CIF file.
97  */
98 #define CDNUMREMEMBER    1000
99 
100 /*
101  * Storage for diagnostics of CDError().
102  */
103 extern char *CDStatusString;
104 extern int  CDStatusInt;
105 
106 /*
107  * Master list desc.
108  */
109 struct m {
110     long mLeft,mBottom,mRight,mTop;
111     char *mName;
112     struct m *mPred,*mSucc;
113     int mReferenceCount;
114 };
115 
116 /*
117  * Symbol desc.
118  */
119 struct s {
120     long sLeft,sBottom,sRight,sTop;
121     long sA,sB;
122     char *sName;
123     /*
124      * One bin foe each layer.  Layer 0 is for call descs.
125      * Each bin points to a double linked list of object descs.
126      * Bin[.][0][0] are the RESIDUAL bins--Bin[.][0][1] and Bin[.][1][0]
127      * are unused TUNABLE.  NumBins should be as big as it can be.
128      * For 20 layers and 100 bins per layer,
129      * the data structure becomes 2000 words.
130      */
131     struct o ***sBin[CDNUMLAYERS+1];
132     struct m *sMasterList;
133     struct prpty *sPrptyList;
134     char  *sHY;  /* hypertext entry list */
135     short sInfo;
136     short sBBValid;
137 };
138 
139 /*
140  * Object desc.
141  */
142 struct o {
143     long oLeft,oBottom,oRight,oTop;
144     struct o *oRep;
145     struct o *oPred,*oSucc;
146     struct prpty *oPrptyList;
147     short oInfo;
148     char oType;
149     char oLayer;
150 };
151 
152 /*
153  * Polygon desc.
154  */
155 struct po {
156     struct p *poPath;
157 };
158 
159 /*
160  * Round flash desc.
161  */
162 struct r {
163     long rWidth,rX,rY;
164 };
165 
166 /*
167  * Wire desc.
168  */
169 struct w {
170     long wWidth;
171     struct p *wPath;
172 };
173 
174 /*
175  * Call desc.
176  */
177 struct c {
178     long cDX,cDY;        /* center to center array spacing */
179     struct t *cT;        /* Pointer to transformation descriptor. */
180     struct m *cMaster;   /* Pointer to master list descriptor. */
181     short cNumX,cNumY;   /* Array parameters. */
182     int cNum;
183 };
184 
185 /*
186  * Transform desc.
187  * If MX, tType == CDMIRRORX.
188  * If MY, tType == CDMIRRORX.
189  * If R,  tType == CDROTATE, tX == XDirection, tY == YDirection.
190  * If T,  tType == CDTRANSLATE, tX == TX, tY = TY;
191  */
192 struct t {
193     long tX,tY;
194     struct t *tSucc;
195     char tType;
196 };
197 
198 /*
199  * Label desc.
200  */
201 struct la {
202     long laX,laY;
203     char *laLabel;
204     char laXform;
205     /* laXform bits:
206      * 0-1, 0-no rotation, 1-90, 2-180, 3-270.
207      * 2, mirror y
208      * 3, mirror x
209      */
210 };
211 
212 /*
213  * Linked path structure
214  */
215 struct p {
216     long pX,pY;
217     struct p *pSucc;
218 };
219 
220 /*
221  * Generator desc.
222  * Search Bin[Layer][0][0] first.
223  * Then Bin[Layer][BeginX..EndX][BeginY..EndY].
224  * Bin[Layer][X][Y] is the current bin.
225  * Pointer points to the current desc in the current bin.
226  */
227 struct g {
228     long  gLeft,gBottom,gRight,gTop;
229     long  gBeginX,gX,gEndX,gBeginY,gY,gEndY;
230     struct o *gPointer;
231     int gLayer;
232 };
233 
234 /*
235  * CD's current parameter struct
236  */
237 struct d {
238 
239     /* Current parameters for symbol being parsed in CDOpen. */
240     int  dNumX,dNumY;
241     long dDX,dDY;
242 
243     /* Scale factors for CDTo and CDFrom. */
244     long dA,dB;
245 
246     /* Symbol scale factors. */
247     long dDSA,dDSB;
248 
249     struct o *dPointer;
250     struct s *dSymbolDesc;
251     struct s *dRootCellDesc;
252 
253     FILE *dSymbolFileDesc;
254 
255     /*
256      * Fields used in CDTo follow.
257      */
258 
259     /* True if parsing root symbol. */
260     int dRoot;
261 
262     /* Root's file desc. */
263     FILE *dRootFileDesc;
264 
265     /* Current property list for symbol being parsed */
266     struct prpty *dPrptyList;
267 
268     /*
269      * Symbol name table.
270      * Big arrays are allocated in CDInit().
271      */
272     char (*dSymTabNames)[FILENAMESIZE];
273     int  *dSymTabNumbers;
274     int  dNumSymbolTable;
275 
276     /*
277      * Because CIF files may have FORWARD references, CDTo must pass
278      * over the CIF file TWICE.
279      * On the first pass, it just fills up the symbol name table.
280      * On the second pass, it does the translation to KIC format.
281      */
282     int dFirstPass;
283 
284     /*
285      * True if debugging.
286      */
287     int dDebug;
288     int dNumSymbolsAllocated;
289 
290     /*
291      * DCONTROLCDOPEN  => CD is in CDOpen
292      * DCONTROLPCIF    => CD is in CDOpen and parsing CIF rather than kic
293      * DCONTROLCDTO    => CD is in CDTo
294      * DCONTROLVANILLA => CD is in none of the above
295      */
296     char dControl;
297 
298     /*
299      * dProgram == 'h' if IGS gened it.
300      *          == 'i' if Icarus gened it.
301      *          == 's' if Sif gened it.
302      *          == 'n' if none of the above.
303      */
304     char dProgram;
305     char dSymbolName[FILENAMESIZE];
306 };
307 extern struct d CDDesc;
308 
309 /*
310  * CD layer table
311  */
312 struct l {
313     char lTechnology;
314     char lMask[3];
315     /*True if CDFrom should output layer.*/
316     char lCDFrom;
317 };
318 extern struct l CDLayer[CDNUMLAYERS+1];
319 
320 /*
321  * Hash table of symbol descs keyed on symbol's name.
322  */
323 struct bu {
324     struct s *buSymbolDesc;
325     struct bu *buPred;
326     struct bu *buSucc;
327 };
328 extern struct bu *CDSymbolTable[CDNUMLAYERS+1];
329 
330 #include "cdext.h"
331