1 /* objlist.h -- core allocation, list generation by regexps */ 2 3 #ifndef _OBJLIST_H 4 #define _OBJLIST_H 5 6 #ifndef _HASH_H 7 #include "hash.h" 8 #endif 9 10 #define SEPARATOR "/" 11 #define INSTANCE_DELIMITER "#" 12 #define PORT_DELIMITER "." 13 #define PHYSICALPIN "(" 14 #define ENDPHYSICALPIN ")" 15 16 #define PORT (-1) 17 #define GLOBAL (-2) 18 #define UNIQUEGLOBAL (-3) 19 #define PROPERTY (-4) /* For element properties; e.g., length, width */ 20 #define ALLELEMENTS (-5) /* for doing searches; e.g., Fanout() */ 21 #define ALLOBJECTS (-6) /* for doing searches; e.g., Fanout() */ 22 #define UNKNOWN (-7) /* for error checking */ 23 #define NODE 0 24 #define FIRSTPIN 1 25 #define IsPort(a) ((a)->type == PORT) 26 #define IsNonProxyPort(a) (((a)->type == PORT) && ((a)->model.port != PROXY)) 27 #define IsGlobal(a) (((a)->type == GLOBAL) || ((a)->type == UNIQUEGLOBAL)) 28 29 #define PROXY (0) /* Used in model.port record of ports */ 30 31 #define NO_CONNECT 1 /* Use in object list to flag an isolated net */ 32 33 /* Lists of device properties. Order is defined at the time of */ 34 /* the cell definition; values are sorted at the time instances */ 35 /* are read. */ 36 37 /* Part 1a: Define the types of tokens used in an expression */ 38 39 #define TOK_NONE 0 40 #define TOK_DOUBLE 1 41 #define TOK_STRING 2 42 #define TOK_MULTIPLY 3 43 #define TOK_DIVIDE 4 44 #define TOK_PLUS 5 45 #define TOK_MINUS 6 46 #define TOK_FUNC_OPEN 7 47 #define TOK_FUNC_CLOSE 8 48 #define TOK_GT 9 49 #define TOK_LT 10 50 #define TOK_GE 11 51 #define TOK_LE 12 52 #define TOK_EQ 13 53 #define TOK_NE 14 54 #define TOK_GROUP_OPEN 15 55 #define TOK_GROUP_CLOSE 16 56 #define TOK_FUNC_IF 17 57 #define TOK_FUNC_THEN 18 58 #define TOK_FUNC_ELSE 19 59 #define TOK_SGL_QUOTE 20 60 #define TOK_DBL_QUOTE 21 61 62 /* Part 1b: Stack structure used to hold expressions in tokenized form */ 63 64 struct tokstack { 65 int toktype; 66 union { 67 double dvalue; 68 char *string; 69 } data; 70 struct tokstack *next; 71 struct tokstack *last; 72 }; 73 74 /* Part 1c: Define the types of property values */ 75 76 #define PROP_STRING 0 77 #define PROP_EXPRESSION 1 /* Same as STRING, handled differently */ 78 #define PROP_INTEGER 2 79 #define PROP_DOUBLE 3 80 #define PROP_VALUE 4 /* Same as DOUBLE, handled differently */ 81 #define PROP_ENDLIST 5 /* End of the property record. */ 82 83 /* Part 1d: Linked list of values for temporary unordered storage when */ 84 /* reading a netlist. Values are string only, to be promoted later if */ 85 /* needed. */ 86 87 struct keyvalue { 88 char *key; 89 char *value; 90 struct keyvalue *next; 91 }; 92 93 /* Part 2: Values (corresponding to the keys, and kept in the instance record) */ 94 95 struct valuelist { 96 char *key; 97 unsigned char type; /* string, integer, double, value, expression */ 98 union { 99 char *string; 100 double dval; 101 int ival; 102 struct tokstack *stack; /* expression in tokenized form */ 103 } value; 104 }; 105 106 /* Part 3: Keys & Defaults (kept in the cell record as a hash table) */ 107 108 #define MERGE_NONE 0x00 /* Property does not change when devices merge */ 109 110 #define MERGE_P_ADD 0x01 /* Properties sum with device parallel merge */ 111 #define MERGE_P_PAR 0x02 /* Properties add in parallel with parallel merge */ 112 #define MERGE_P_CRIT 0x04 /* This property enables parallel merging */ 113 #define MERGE_P_XCRIT 0x08 /* Old "critical" behavior (deprecated) */ 114 115 #define MERGE_S_ADD 0x10 /* Properties sum with device series merge */ 116 #define MERGE_S_PAR 0x20 /* Properties add in parallel with series merge */ 117 #define MERGE_S_CRIT 0x40 /* This property enables series merging */ 118 #define MERGE_S_XCRIT 0x80 /* Old "critical" behavior (deprecated) */ 119 120 #define MERGE_P_MASK (MERGE_P_ADD | MERGE_P_PAR | MERGE_P_CRIT | MERGE_P_XCRIT) 121 #define MERGE_S_MASK (MERGE_S_ADD | MERGE_S_PAR | MERGE_S_CRIT | MERGE_S_XCRIT) 122 #define MERGE_ALL_MASK (MERGE_P_MASK | MERGE_S_MASK) 123 124 /* Although the above are flags, "ADD" and "PAR" are mutually exclusive. */ 125 126 /* Note: A "critical" merge means that the property causes the number of */ 127 /* devices to change. e.g., transistor width is critical; transistor drain */ 128 /* area sums when devices are merged, but does not change the number of devices.*/ 129 /* More than one property can be critical. e.g., width and number of fingers. */ 130 /* Also it is possible for a property (e.g., "value") to be critical for both */ 131 /* series and parallel merging. */ 132 133 struct property { 134 char *key; /* name of the property */ 135 unsigned char idx; /* index into valuelist */ 136 unsigned char type; /* string, integer, double, value, expression */ 137 unsigned char merge; /* how property changes when devices are merged */ 138 union { 139 char *string; 140 double dval; 141 int ival; 142 struct tokstack *stack; 143 } pdefault; /* Default value */ 144 union { 145 double dval; 146 int ival; 147 } slop; /* slop allowance in property */ 148 }; 149 150 /*-------------------------------*/ 151 /* list of objects within a cell */ 152 /*-------------------------------*/ 153 154 struct objlist { 155 char *name; /* unique name for the port/node/pin/property */ 156 int type; /* -1 for port, 0 for internal node, 157 else index of the pin on element */ 158 union { 159 char *class; /* name of element class; nullstr for nodes */ 160 int port; /* Port number, if type is a port */ 161 } model; 162 union { 163 char *name; /* unique name for the instance, or */ 164 /* (string) value of property for properties */ 165 struct valuelist *props; /* Property record */ 166 } instance; 167 unsigned char flags; /* Used by NODE type to flag isolated net */ 168 int node; /* the electrical node number of the port/node/pin */ 169 struct objlist *next; 170 }; 171 172 extern struct objlist *LastPlaced; 173 174 /* Record structure for maintaining lists of cell classes to ignore */ 175 176 struct IgnoreList { 177 char *class; 178 int file; 179 unsigned char type; 180 struct IgnoreList *next; 181 }; 182 183 /* Types used by IgnoreList above */ 184 185 #define IGNORE_NONE (unsigned char)0 186 #define IGNORE_CLASS (unsigned char)1 187 #define IGNORE_SHORTED (unsigned char)2 188 189 /* Record structure for handling pin permutations in a cell */ 190 /* Linked list structure allows multiple permutations per cell. */ 191 192 struct Permutation { 193 char *pin1; 194 char *pin2; 195 struct Permutation *next; 196 }; 197 198 #define OBJHASHSIZE 42073 /* the size of the object and instance hash lists */ 199 /* prime numbers are good choices as hash sizes */ 200 201 /* cell definition for hash table */ 202 /* NOTE: "file" must come first for the hash matching by name and file */ 203 204 struct nlist { 205 int file; /* internally ordered file to which cell belongs, or -1 */ 206 char *name; 207 int number; /* number of instances defined */ 208 int dumped; /* instance count, and general-purpose marker */ 209 unsigned char flags; 210 unsigned char class; 211 unsigned long classhash; /* randomized hash value for cell class */ 212 struct Permutation *permutes; /* list of permuting pins */ 213 struct objlist *cell; 214 struct hashdict objdict; /* hash table of object names */ 215 struct hashdict instdict; /* hash table of instance names */ 216 struct hashdict propdict; /* hash table of property keys */ 217 struct objlist **nodename_cache; 218 long nodename_cache_maxnodenum; /* largest node number in cache */ 219 void *embedding; /* this will be cast to the appropriate data structure */ 220 struct nlist *next; 221 }; 222 223 /* Defined nlist structure flags */ 224 225 #define CELL_MATCHED 0x01 /* cell matched to another */ 226 #define CELL_NOCASE 0x02 /* cell is case-insensitive (e.g., SPICE) */ 227 #define CELL_TOP 0x04 /* cell is a top-level cell */ 228 #define CELL_PLACEHOLDER 0x08 /* cell is a placeholder cell */ 229 #define CELL_PROPSMATCHED 0x10 /* properties matched to matching cell */ 230 #define CELL_DUPLICATE 0x20 /* cell has a duplicate */ 231 232 /* Flags for combination allowances and prohibitions */ 233 234 #define COMB_SERIES 0x40 235 #define COMB_NO_PARALLEL 0x80 236 237 extern struct nlist *CurrentCell; 238 extern struct objlist *CurrentTail; 239 extern void AddToCurrentCell(struct objlist *ob); 240 extern void AddToCurrentCellNoHash(struct objlist *ob); 241 extern void AddInstanceToCurrentCell(struct objlist *ob); 242 extern void FreeObject(struct objlist *ob); 243 extern void FreeObjectAndHash(struct objlist *ob, struct nlist *ptr); 244 extern void FreePorts(char *cellname); 245 extern struct IgnoreList *ClassIgnore; 246 247 extern int NumberOfPorts(char *cellname, int file); 248 extern struct objlist *InstanceNumber(struct nlist *tp, int inst); 249 250 extern struct objlist *List(char *list_template); 251 extern struct objlist *ListExact(char *list_template); 252 extern struct objlist *ListCat(struct objlist *ls1, struct objlist *ls2); 253 extern int ListLen(struct objlist *head); 254 extern int ListLength(char *list_template); 255 extern struct nlist *LookupPrematchedClass(struct nlist *, int); 256 extern struct objlist *LookupObject(char *name, struct nlist *WhichCell); 257 extern struct objlist *LookupInstance(char *name, struct nlist *WhichCell); 258 extern struct objlist *CopyObjList(struct objlist *oldlist, unsigned char doforall); 259 extern void UpdateNodeNumbers(struct objlist *lst, int from, int to); 260 261 /* Function pointer to List or ListExact, allowing regular expressions */ 262 /* to be enabled/disabled. */ 263 264 extern struct objlist * (*ListPtr)(); 265 266 extern void PrintCellHashTable(int full, int file); 267 extern struct nlist *LookupCell(char *s); 268 extern struct nlist *LookupCellFile(char *s, int f); 269 extern struct nlist *InstallInCellHashTable(char *name, int f); 270 extern void InitCellHashTable(void); 271 extern void ClearDumpedList(void); 272 extern int RecurseCellHashTable(int (*foo)(struct hashlist *np)); 273 extern int RecurseCellFileHashTable(int (*foo)(struct hashlist *, int), int); 274 extern struct nlist *RecurseCellHashTable2(struct nlist *(*foo)(struct hashlist *, 275 void *), void *); 276 extern struct nlist *FirstCell(void); 277 extern struct nlist *NextCell(void); 278 279 extern char *NodeName(struct nlist *tp, int node); 280 extern char *NodeAlias(struct nlist *tp, struct objlist *ob); 281 extern void FreeNodeNames(struct nlist *tp); 282 extern void CacheNodeNames(struct nlist *tp); 283 284 285 /* enable the following line to debug the core allocator */ 286 /* #define DEBUG_GARBAGE */ 287 288 #ifdef DEBUG_GARBAGE 289 extern struct objlist *GetObject(void); 290 extern struct keyvalue *NewKeyValue(void); 291 extern struct property *NewProperty(void); 292 extern struct valuelist *NewPropValue(int entries); 293 extern void FreeString(char *foo); 294 extern char *strsave(char *s); 295 #else /* not DEBUG_GARBAGE */ 296 #define GetObject() ((struct objlist*)CALLOC(1,sizeof(struct objlist))) 297 #define NewProperty() ((struct property*)CALLOC(1,sizeof(struct property))) 298 #define NewPropValue(a) ((struct valuelist*)CALLOC((a),sizeof(struct valuelist))) 299 #define NewKeyValue() ((struct keyvalue*)CALLOC(1,sizeof(struct keyvalue))) 300 #define FreeString(a) (FREE(a)) 301 #define strsave(a) (STRDUP(a)) 302 #endif /* not DEBUG_GARBAGE */ 303 304 extern int freeprop(struct hashlist *p); 305 306 extern int match(char *, char *); 307 extern int matchnocase(char *, char *); 308 extern int matchfile(char *, char *, int, int); 309 extern int matchfilenocase(char *, char *, int, int); 310 311 extern void GarbageCollect(void); 312 extern void InitGarbageCollection(void); 313 extern void AddToGarbageList(struct objlist *head); 314 315 extern void DeleteProperties(struct keyvalue **topptr); 316 extern void AddProperty(struct keyvalue **topptr, char *key, char *value); 317 extern void AddScaledProperty(struct keyvalue **topptr, char *key, char *value, double scale); 318 extern void DeleteProperties(struct keyvalue **topptr); 319 extern struct objlist *LinkProperties(char *model, struct keyvalue *topptr); 320 321 extern void ClassDelete(char *class, int file); 322 extern void RemoveShorted(char *class, int file); 323 extern void CellRehash(char *name, char *newname, int file); 324 325 /* defined in netgen.c */ 326 extern int ConvertStringToInteger(char *string, int *ival); 327 328 #ifdef HAVE_MALLINFO 329 void PrintMemoryStats(void); 330 #endif 331 332 #endif /* _OBJLIST_H */ 333 334 335 336