1 /*
2  * extflat.h --
3  *
4  * Internal definitions for the procedures to flatten hierarchical
5  * (.ext) circuit extraction files.
6  *
7  *     *********************************************************************
8  *     * Copyright (C) 1985, 1990 Regents of the University of California. *
9  *     * Permission to use, copy, modify, and distribute this              *
10  *     * software and its documentation for any purpose and without        *
11  *     * fee is hereby granted, provided that the above copyright          *
12  *     * notice appear in all copies.  The University of California        *
13  *     * makes no representations about the suitability of this            *
14  *     * software for any purpose.  It is provided "as is" without         *
15  *     * express or implied warranty.  Export of this software outside     *
16  *     * of the United States of America may require an export license.    *
17  *     *********************************************************************
18  *
19  * rcsid $Header: /usr/cvsroot/magic-8.0/extflat/extflat.h,v 1.2 2008/12/03 14:12:09 tim Exp $
20  */
21 
22 #ifndef _EXTFLAT_H
23 #define _EXTFLAT_H
24 
25 #include "utils/magic.h"
26 
27 typedef unsigned char U_char;
28 
29 /*
30  * Arguments to EFFlatBuild().
31  */
32 #define	EF_FLATNODES		0x01	/* Flatten nodes */
33 #define	EF_FLATCAPS		0x02	/* Flatten capacitors */
34 #define	EF_FLATRESISTS		0x04	/* Flatten resistors */
35 #define	EF_FLATDISTS		0x08	/* Flatten distances */
36 #define	EF_NOFLATSUBCKT		0x10	/* Don't flatten standard cells */
37 #define	EF_NONAMEMERGE		0x20	/* Don't merge unconnected nets	*/
38 					/* with the same name.		*/
39 
40 /* Flags to control output of node names.  Stored in EFOutputFlags */
41 #define EF_TRIM_MASK		0x1f	/* Mask for handling name trimming */
42 #define	EF_TRIMGLOB		0x01	/* Delete trailing '!' from names */
43 #define	EF_TRIMLOCAL		0x02	/* Delete trailing '#' from names */
44 #define EF_CONVERTCOMMA		0x04	/* Change ',' to '|' in names, else remove */
45 #define EF_CONVERTEQUAL		0x08	/* Change '=' to ':' in names, else remove */
46 #define EF_CONVERTBRACKETS	0x10	/* Change '[' and ']' to '_' in names */
47 
48 #define EF_SHORT_MASK		0x60	/* Mask for handling port shorts */
49 #define EF_SHORT_NONE		0x00	/* Shorted ports are merged */
50 #define EF_SHORT_R		0x20	/* Shorted ports separated with 0 ohm resistor */
51 #define EF_SHORT_V		0x40	/* Shorted ports separated with 0 volt source */
52 
53 /*
54  * capacitance type now set to float
55  */
56 typedef float EFCapValue;
57 
58 /* ------------------------ Hierarchical names ------------------------ */
59 
60 /*
61  * One of the biggest consumers of memory space when flattening a circuit
62  * are the full hierarchical names of all nodes.  Most of this space is
63  * wasted since it's redundant.  Also, a lot of time is spent comparing
64  * long names whose initial components are identical.
65  *
66  * The following structure allows hierarchical names to be represented
67  * with sharing.  Names are represented as a sequence of components,
68  * from the lowest level of the hierarchy pointing back toward the root.
69  * Hence, comparisons are likely to detect differences between names
70  * early on.  Second, many children can share the same parent, so
71  * storage space should be comparable to that needed for an unflattened
72  * hierarchy (with arrays flattened, however).
73  */
74 typedef struct hiername
75 {
76     struct hiername	*hn_parent;	/* Back-pointer toward root */
77     int			 hn_hash;	/* For speed in hashing */
78     char		 hn_name[4];	/* String is allocated here */
79 } HierName;
80 
81 /*
82  * Size of a HierName big enough to hold a string containing
83  * n bytes (not including the NULL byte).
84  */
85 #define	HIERNAMESIZE(n)	((n) + sizeof (HierName) - 3)
86 
87 /* Indicates where the HierName was allocated: passed to EFHNFree() */
88 #define	HN_ALLOC	0	/* Normal name (FromStr) */
89 #define	HN_CONCAT	1	/* Concatenation of two HierNames */
90 #define HN_GLOBAL	2	/* Global name */
91 #define HN_FROMUSE	3	/* From a cell use */
92 
93 /* ----------------------- Node attribute lists ----------------------- */
94 
95 typedef struct efattr
96 {
97     struct efattr	*efa_next;	/* Next in list */
98     Rect		 efa_loc;	/* Location of attr label */
99     int			 efa_type;	/* Tile type attr attached to */
100     char		 efa_text[4];	/* String is allocated here */
101 } EFAttr;
102 
103 /*
104  * Size of an EFAttr big enough to hold a string containing
105  * n bytes (not including the NULL byte).
106  */
107 #define	ATTRSIZE(n)	((n) + sizeof (EFAttr) - 3)
108 
109 /* ------------------- Hierarchical and flat nodes -------------------- */
110 
111 /*
112  * Each entry in the a nodename hash table points to a EFNodeName.
113  * Several EFNodeNames may point to the same EFNode.  Such EFNodeNames
114  * are linked into a NULL-terminated list by the name_next pointers.
115  * The first name in this list, pointed to by the efnode_name field of
116  * the EFNode they all point to, is the canonical name for this node.
117  *
118  * The name_hier field points to the HierName for this node, which
119  * will have only a single component for EFNodes within a Def, but
120  * multiple components for hierarchical node names.
121  */
122 typedef struct efnn
123 {
124     struct efnode	*efnn_node;	/* Corresponding node */
125     struct efnn		*efnn_next;	/* Next name for this node */
126     HierName		*efnn_hier;	/* HierName for this node */
127     int			 efnn_port;	/* Port number for this node */
128     unsigned char	 efnn_refc;	/* #times referenced in hash */
129 } EFNodeName;
130 
131 /*
132  * Both hierarchical and flat nodes use the same structure.  Hierarchical
133  * nodes appear along with each cell def.  Flat nodes are pointed to by
134  * the global hash table.
135  *
136  * Hierarchical nodes are linked in a doubly-linked list with all
137  * other nodes in the same cell, and flat nodes are similarly linked
138  * with all other flat nodes in the circuit.  The list is doubly
139  * linked to allow nodes to be deleted easily when it is necessary
140  * to merge two nodes into a single node.
141  *
142  * There is a third way in which a node can exist if only its name is
143  * of interest, namely as an EFNodeHdr.  The first part of an EFNode
144  * is an EFNodeHdr.
145  */
146 
147     /* Represents perimeter and area for a resistance class */
148 typedef struct
149 {
150     int		 pa_area;
151     int		 pa_perim;
152 } EFPerimArea;
153 
154 typedef struct efnhdr
155 {
156     int		 efnhdr_flags;	/* See below */
157     EFNodeName	*efnhdr_name;	/* Canonical name for this node, this is a ptr
158 				 * to the first element in a null-terminated
159 				 * list of all the EFNodeNames for this node.
160 				 */
161     struct efnhdr *efnhdr_next;	/* Next node in list */
162     struct efnhdr *efnhdr_prev;	/* Previous node in list */
163 } EFNodeHdr;
164 
165 /* Node flags */
166     /*
167      * If set, this node was killed and neither it nor anything connected
168      * to it should be output.  There should have been a new, identical
169      * structure in the input that was connected to the new node.
170      */
171 #define	EF_KILLED	0x01
172 
173     /*
174      * If set, this node was allocated as a substrate terminal for a
175      * dev, and so should be automatically merged with nodes of the
176      * same name after all nodes have been flattened, rather than
177      * complaining about it being unconnected.
178      */
179 #define	EF_DEVTERM	0x02
180 
181     /*
182      * This can be used as a general-purpose flag.  It is used by
183      * the LEF module to indicate that a node is a "special" net.
184      */
185 #define EF_SPECIAL	0x04
186     /*
187      * If set, this node is a subcircuit port and should be treated
188      * accordingly when writing netlist output.  The port number is
189      * encoded in the efNodeName structure, since there may be
190      * multiple ports per node (for example, a thru route).
191      */
192 #define EF_PORT		0x08
193     /*
194      * Flag ports of a top-level cell in addition to setting EF_PORT
195      */
196 #define EF_TOP_PORT	0x10
197     /*
198      * This is used when a node is a substrate node with a local
199      * node name, making it an implicitly-defined port.  It differs
200      * from EF_DEVTERM in that EF_DEVTERM includes global substrate
201      * nodes, which are not declared ports.
202      */
203 #define EF_SUBS_PORT	0x20
204     /*
205      * EF_SUBS_NODE is defined for substrate nodes defined in the
206      * .ext file.
207      */
208 #define EF_SUBS_NODE	0x40
209 
210 extern int efNumResistClasses;	/* Number of resistance classes in efResists */
211 
212 typedef struct efnode
213 {
214     EFNodeHdr	 efnode_hdr;	/* See above */
215 #define	efnode_name	efnode_hdr.efnhdr_name
216 #define	efnode_next	efnode_hdr.efnhdr_next
217 #define	efnode_prev	efnode_hdr.efnhdr_prev
218 #define	efnode_flags	efnode_hdr.efnhdr_flags
219 
220     EFCapValue	 efnode_cap;	/* Total capacitance to ground for this node */
221     int		 efnode_type;	/* Index into type table for node */
222     int		 efnode_num;	/* Number of items in efnode_hdr list */
223     Rect	 efnode_loc;	/* Location of a 1x1 rect contained in this
224 				 * node.  This information is provided in the
225 				 * .ext file so it will be easy to map between
226 				 * node names and locations.
227 				 */
228     EFAttr	*efnode_attrs;	/* Node attribute list */
229     ClientData	 efnode_client;	/* For hire */
230     EFPerimArea	 efnode_pa[1];	/* Dummy; each node actually has
231 				 * efNumResistClasses array elements
232 				 * allocated to it.
233 				 */
234 } EFNode;
235 
236 /* -------------------------- Devices ----------------------------- */
237 
238 /*
239  * Each device can contain several terminals.
240  * Each terminal is described by the following structure.
241  * We use a EFNode pointer for the terminal to which a device connects;
242  * this assumes that devices appear after all the nodes for a cell.
243  */
244 typedef struct devterm
245 {
246     EFNode	*dterm_node;	/* Node to which we're connected */
247     char	*dterm_attrs;	/* Attribute list */
248     int		 dterm_length;	/* Length of terminal connection to gate */
249     int		 dterm_perim;	/* Terminal perimeter if passed as a param */
250     int		 dterm_area;	/* Terminal area if passed as a param */
251 } DevTerm;
252 
253 /*
254  * Device itself.
255  * The dev_substrate and dev_type pointers are actually pointer into shared
256  * tables of names, rather than being individually allocated for each
257  * transistor.
258  */
259 
260 typedef struct parm
261 {
262     char	 parm_type[2];
263     char	*parm_name;
264     double	 parm_scale;
265     struct parm	*parm_next;
266 } DevParam;
267 
268 typedef struct dev
269 {
270     struct dev	*dev_next;	/* Next device in def */
271     U_char	 dev_class;	/* Device class (see extract/extract.h) */
272     U_char	 dev_type;	/* Index into device type table */
273     U_char	 dev_nterm;	/* Number of terminals in device */
274     EFNode	*dev_subsnode;	/* Substrate node */
275     Rect	 dev_rect;	/* 1x1 rectangle inside device */
276 
277     /* Most device types use only one or two of these, but subcircuits	*/
278     /* may keep all values to pass along as parameters.			*/
279     float	 dev_cap;	/* Capacitance for class "cap" or subckt */
280     float	 dev_res;	/* Resistance for class "res" or subckt */
281     int		 dev_area;
282     int		 dev_perim;
283     int		 dev_length;
284     int		 dev_width;
285     DevParam	 *dev_params;	/* List of subcircuit parameters to output */
286     DevTerm	 dev_terms[1];	/* Terminals.  The actual number will depend
287 				 * on dev_nterm above, so the size of this
288 				 * structure will vary.
289 				 */
290 } Dev;
291 
292 /* Size of a Dev structure for 'n' terminals (including the "gate") */
293 #define	DevSize(n)	(sizeof (Dev) + ((n)-1)*sizeof (DevTerm))
294 
295 /* -------------------------------------------------------------------- */
296 
297 /*
298  * A big number, used for thresholds for capacitance and resistance
299  * when no processing is desired (NOTE:  Probably should be using
300  * C99 "INFINITY" here instead).
301  */
302 #define	INFINITE_THRESHOLD	(((unsigned int) (~0)) >> 1)
303 #define	INFINITE_THRESHOLD_F	((EFCapValue)(1.0E38))
304 #define IS_FINITE_F(a)		(((EFCapValue)(a)) != INFINITE_THRESHOLD_F)
305 
306 /* Max filename length */
307 #define	FNSIZE		1024
308 
309 
310 extern float EFScale;		/* Scale factor to multiply all coords by */
311 extern char *EFTech;		/* Technology of extracted circuit */
312 extern char *EFStyle;           /* Extraction style of extracted circuit */
313 extern char *EFSearchPath;	/* Path to search for .ext files */
314 extern char *EFLibPath;		/* Library search path */
315 extern char *EFVersion;		/* Version of extractor we work with */
316 extern char *EFArgTech;		/* Tech file given as command line argument */
317 extern bool  EFCompat;		/* Subtrate backwards-compatibility mode */
318 
319     /*
320      * Thresholds used by various extflat clients to filter out
321      * unwanted resistors and capacitors.  Resistance is in milliohms,
322      * capacitance in attofarads.
323      */
324 extern int EFResistThreshold;
325 extern EFCapValue EFCapThreshold;
326 
327     /* Table of transistor types */
328 extern char *EFDevTypes[];
329 extern int EFDevNumTypes;
330 
331     /* Table of Magic layers */
332 extern char *EFLayerNames[];
333 extern int EFLayerNumNames;
334 
335     /* Output control flags */
336 extern int EFOutputFlags;
337 
338 /* -------------------------- Exported procedures --------------------- */
339 
340 extern char *EFArgs();
341 
342     /* HierName manipulation */
343 extern HashEntry *EFHNLook();
344 extern HashEntry *EFHNConcatLook();
345 extern HierName *EFHNConcat();
346 extern HierName *EFStrToHN();
347 extern char *EFHNToStr();
348 extern int EFGetPortMax();
349 
350 /* ------------------------- constants used by clients -------------- */
351 
352 /*
353  * ANSI C definitions of arguments to EFvisit procedures
354  */
355 
356 /* - left for documentation purposes
357 
358 typedef int (*capproc)(HierName *, HierName *, double, ClientData );
359 
360 extern int EFVisitCaps(capproc, ClientData );
361 
362 typedef int (*nodeproc)(EFNode *, int , double, ClientData );
363 
364 extern int EFVisitNodes(nodeproc , ClientData );
365 
366 extern int EFReadFile(char *);
367 
368 */
369 
370 #endif /* _EXTFLAT_H */
371