1/* 2 * database.h -- 3 * 4 * Definitions for the database module. 5 * This file defines everything that is visible to clients 6 * outside the database module. 7 * 8 * ********************************************************************* 9 * * Copyright (C) 1985, 1990 Regents of the University of California. * 10 * * Permission to use, copy, modify, and distribute this * 11 * * software and its documentation for any purpose and without * 12 * * fee is hereby granted, provided that the above copyright * 13 * * notice appear in all copies. The University of California * 14 * * makes no representations about the suitability of this * 15 * * software for any purpose. It is provided "as is" without * 16 * * express or implied warranty. Export of this software outside * 17 * * of the United States of America may require an export license. * 18 * ********************************************************************* 19 * 20 * Needs to include: magic.h, tile.h 21 * 22 * rcsid "$Header: /usr/cvsroot/magic-8.0/database/database.h.in,v 1.8 2010/08/25 17:33:55 tim Exp $" 23 */ 24 25#ifndef _DATABASE_H 26#define _DATABASE_H 27 28#ifndef _TILES_H 29#include "tiles/tile.h" 30#endif /* _TILES_H */ 31 32#ifndef _HASH_H 33#include "utils/hash.h" 34#endif /* _HASH_H */ 35 36#ifndef _STACK_H 37#include "utils/stack.h" 38#endif /* _STACK_H */ 39 40#ifndef _BPLANE_H 41#include "bplane/bplane.h" 42#endif /* _BPLANE_H */ 43 44/* ----------------------- Tunable constants -------------------------- */ 45 46#define MAXPLANES 64 /* Maximum number of planes per cell */ 47 48 /* 49 * The "unnamed" cell. 50 * This is visible only within Magic, and just determines the 51 * name by which the initial cell-without-a-name appears. 52 */ 53#define UNNAMED "(UNNAMED)" 54 55/* --------------------- Tile types and masks ------------------------- */ 56 57typedef int TileType; 58 59/* 60 * Tile types are small integers (currently from 0 to TT_MAXTYPES-1). 61 * They are used in constructing TileTypeBitMask bitmasks with the 62 * operators defined below. A TileTypeBitMask contains one bit for 63 * each possible TileType. 64 * 65 * A negative value of TileType implies an error condition when received 66 * from a routine returning a TileType. Care should be taken to ensure 67 * that a negative TileType is never used to index an array! 68 * 69 * The last TT_RESERVEDTYPES tile types are reserved for use by clients. 70 * Because unsigned chars are used to hold tile types (PaintResultType), 71 * this number should not be increased without changing the definition 72 * of PaintResultType later in this file. 73 * 74 * (Magic v.7.1) Macros are generated by script scripts/makedbh, 75 * with each macro appropriately constructed for the value of 76 * TT_MAXTYPES. 77 * 78 * Each addition of a word to the bitmask increases computation 79 * time on all plane operations in magic! Choose the smallest number 80 * required for the technology files used. The obvious reasonable values 81 * to choose are 96, 192, 256, or 512, corresponding to word array sizes 82 * of 3, 6, 8, and 16, respectively. 83 */ 84 85#define TT_MAXTYPES 256 /* See above! */ 86#define TT_RESERVEDTYPES 2 /* See above! */ 87 88/* 89 * Note that the value of 5 for TT_WORDSHIFT effectively requires that 90 * bits-per-word equal 32 or havoc is likely to result. 91 */ 92 93#define TT_BPW (8 * sizeof (unsigned int)) 94#define TT_WORDMASK (TT_BPW - 1) 95#define TT_WORDSHIFT 5 /* LOG2(TT_BPW) */ 96#define TT_MASKWORDS ((TT_MAXTYPES + TT_BPW - 1) / TT_BPW) 97 98typedef struct 99{ 100 unsigned int tt_words[TT_MASKWORDS]; 101} TileTypeBitMask; 102 103/* 104 * Here's a brief note about how to interpret TileTypeBitMasks: 105 * The default TT_MAXTYPES = 256 translates to 8 words. As an 106 * example, to examine TileTypeBitMask DBConnectTbl[65] 107 * (in this example DBTypeLongNameTbl[65]="metal1"). In gdb, 108 * use "print /x DBConnectTbl[65]" to get: 109 * 110 * $2 = {tt_words = {0x59800000, 0xc8cc22a6, 0x8000003b, 0xff800008, \ 111 * 0x38f, 0x0, 0x0, 0x0}} 112 * 113 * The first word represents types 0-31 (lsb to msb, respectively), 114 * the second work represents types 32-63, and so forth. From this 115 * result we see that metal1 (type 65) connects to types 23, 24, 27, 116 * 28, and 30 (from the 1st word), 33, 34, 37, 39, 41, and so on. 117 * A quick check of DBTypeLongNameTbl[] shows that these types are 118 * ndc, pdc, psc, nsc, and so forth. 119 */ 120 121/* 122 * Although some tile types are assigned on a technology-specific basis, 123 * certain types are independent of the technology used, and are 124 * defined below: 125 */ 126#define TT_SPACE 0 /* Space tile */ 127#define TT_PAINTBASE 1 /* First non-space type */ 128#define TT_CHECKPAINT 1 /* DRC -- paint has changed */ 129#define TT_CHECKSUBCELL 2 /* DRC -- subcells have changed */ 130#define TT_ERROR_P 3 /* DRC -- paint error */ 131#define TT_ERROR_S 4 /* DRC -- subcell error */ 132#define TT_ERROR_PS 5 /* DRC -- */ 133#define TT_MAGNET 6 /* magnet for interactive router */ 134#define TT_FENCE 7 /* fence for interactive router */ 135#define TT_ROTATE 8 /* rotate for interactive router */ 136#define TT_SELECTBASE TT_MAGNET /* First selectable type */ 137#define TT_TECHDEPBASE 9 /* First technology-dependent type */ 138 139#define TT_DIAGONAL 0x40000000 /* Bit set for non-manhattan tiles */ 140#define TT_SIDE 0x20000000 /* Temporary bit set: 1 = right */ 141#define TT_DIRECTION 0x10000000 /* Bit set for tile split direction */ 142#define TT_LEFTMASK 0x00003fff /* Type for left side of split */ 143#define TT_RIGHTMASK 0x0fffc000 /* Type for right side of split */ 144 145/* Pseudo type signifying unexpanded subcells. Never painted. - Only 146 used in a few places, e.g. TouchingTypes() and mzrouter spacing arrays. 147 */ 148#define TT_SUBCELL TT_MAXTYPES 149 150/* The following type is used in the paint result tables to save space. */ 151#if TT_MAXTYPES > 256 152typedef unsigned short PaintResultType; 153#else 154typedef unsigned char PaintResultType; 155#endif 156 157/* Which word in a mask contains the bit for type 't'? */ 158#define ttWord(t) ((t) >> TT_WORDSHIFT) 159 160/* Which bit in the above word is for type 't'? */ 161#define ttBit(t) ((t) & TT_WORDMASK) 162 163/* Mask for above word with only bit 't' set */ 164#define ttMask(t) ((unsigned int)1 << ttBit(t)) 165 166/* Operations for manipulating TileTypeBitMasks */ 167#define TTMaskSetType(m, t) ((m)->tt_words[ttWord(t)] |= ttMask(t)) 168#define TTMaskClearType(m, t) ((m)->tt_words[ttWord(t)] &= ~ttMask(t)) 169#define TTMaskHasType(m, t) (((m)->tt_words[ttWord(t)] & ttMask(t)) != 0) 170#define TTMaskSetOnlyType(m, t) (TTMaskZero(m), TTMaskSetType(m, t)) 171 172/* ---------------------- Planes and masks ---------------------------- */ 173/* 174 * Plane numbers are also small integers. Certain planes are 175 * technology-specific, but others are always present independent 176 * of the technology used. 177 * 178 * Note that the CELL plane and the DRC_CHECK plane are invisible 179 * as far as normal painting operations are concerned, but that the 180 * DRC_CHECK plane does get written out to the .cad file. 181 * 182 * The following macros are used for converting between plane numbers 183 * and masks of same. 184 */ 185#if (MAXPLANES <= 32) 186 #define PlaneMask int 187#else 188 #define PlaneMask dlong 189#endif 190 191#define PlaneNumToMaskBit(p) ((PlaneMask)1 << (p)) 192#define PlaneMaskHasPlane(m, p) (((m) & PlaneNumToMaskBit(p)) != 0) 193 194 195#define PL_MAXTYPES MAXPLANES /* Maximum number of planes per cell */ 196#define PL_ROUTER 0 /* Used by the router and plow modules */ 197#define PL_DRC_CHECK 1 /* DRC plane for CHECK tiles */ 198#define PL_DRC_ERROR 2 /* DRC plane for ERROR tiles */ 199#define PL_M_HINT 3 /* magnet hints for irouter */ 200#define PL_F_HINT 4 /* fence hints for irouter */ 201#define PL_R_HINT 5 /* rotate hints for irouter */ 202#define PL_SELECTBASE PL_M_HINT /* First plane with selectable types */ 203#define PL_TECHDEPBASE 6 /* First technology-dependent plane */ 204#define PL_PAINTBASE 1 /* Base of paint planes */ 205 206/* --------------------------- Labels --------------------------------- */ 207 208/* 209 * The body of a tile may have a list of labels associated with it. 210 * Each label contains a location that indicates the point at which the 211 * label is supposed to appear attached. This location must be within 212 * the tile on whose list the label appears. 213 * 214 * Note that structure parts lab_size, lab_rotate, lab_bbox, 215 * and lab_offset are all used only by the outline fonts, when 216 * the value of lab_font is not -1. 217 */ 218 219typedef struct label 220{ 221 TileType lab_type; /* Type of material to which this label 222 * is attached. This material, or 223 * other materials that connect it, 224 * must be present everywhere under 225 * the area of the label (Magic 226 * enforces this). If there isn't 227 * any such material, lab_type is 228 * TT_SPACE. 229 */ 230 Rect lab_rect; /* Area of paint to which label is 231 * attached. 232 */ 233 Point lab_corners[4]; /* The four corners of the label. Values 234 * are in (database units / 8), and 235 * indicate the relative distance from 236 * the center of lab_rect. 237 */ 238 Rect lab_bbox; /* Area of the label itself, in surface 239 * coordinates (if font is not -1). This 240 * is derived from lab_corners[] and 241 * cached in lab_bbox; 242 */ 243 int lab_just; /* Justification (GEO_NORTH, etc.) */ 244 signed char lab_font; /* Font used for label. -1 is the default 245 * X11 font; other values are indexes into 246 * the font tables. 247 */ 248 int lab_size; /* Scale of font relative to database, 249 * in (database units / 8) 250 */ 251 short lab_rotate; /* Rotation of label, in degrees */ 252 Point lab_offset; /* Offset relative to origin point, in 253 * units of (database units / 8) 254 */ 255 unsigned short lab_flags; /* Information, especially for 256 * marking port labels 257 */ 258 unsigned int lab_port; /* Port number, if label is a port */ 259 struct label *lab_next; /* Next label in list */ 260 char lab_text[4]; /* Actual text of label. This field 261 * is just a place-holder: the actual 262 * field will be large enough to 263 * contain the label name. This 264 * MUST be the last field in the 265 * structure. 266 */ 267} Label; 268 269/* 270 * Label flags bit fields 271 */ 272 273#define PORT_DIR_MASK 0x00000f /* Mask of all port directions */ 274#define PORT_DIR_NORTH 0x000001 /* Port allows connection to north */ 275#define PORT_DIR_EAST 0x000002 /* Port allows connection to east */ 276#define PORT_DIR_SOUTH 0x000004 /* Port allows connection to south */ 277#define PORT_DIR_WEST 0x000008 /* Port allows connection to west */ 278 279#define PORT_CLASS_MASK 0x070 /* Mask of all port classes */ 280#define PORT_CLASS_DEFAULT 0x000 /* Port takes default class */ 281#define PORT_CLASS_INPUT 0x010 /* Port is a digital input */ 282#define PORT_CLASS_OUTPUT 0x020 /* Port is a digital output */ 283#define PORT_CLASS_TRISTATE 0x030 /* Port is a tri-state output */ 284#define PORT_CLASS_BIDIRECTIONAL 0x040 /* Port is analog or digital */ 285 /* bidirectional */ 286#define PORT_CLASS_FEEDTHROUGH 0x050 /* Port touches no active */ 287 /* devices */ 288 289#define PORT_USE_MASK 0x0780 /* Mask of all port uses */ 290#define PORT_USE_DEFAULT 0x0000 /* Port takes default use */ 291#define PORT_USE_SIGNAL 0x0080 /* Port is a digital signal */ 292#define PORT_USE_ANALOG 0x0100 /* Port is an analog signal */ 293#define PORT_USE_POWER 0x0180 /* Port is a power rail */ 294#define PORT_USE_GROUND 0x0200 /* Port is a ground rail */ 295#define PORT_USE_CLOCK 0x0280 /* Port is a digital clock */ 296#define PORT_USE_RESET 0x0300 /* Port is a digital reset */ 297#define PORT_USE_SCAN 0x0380 /* Port is a digital scan */ 298#define PORT_USE_TIEOFF 0x0400 /* Port is a tie-off */ 299 300#define PORT_SHAPE_MASK 0x1800 /* Mask of all port shapes */ 301#define PORT_SHAPE_DEFAULT 0x0000 /* Port takes default shape */ 302#define PORT_SHAPE_ABUT 0x0800 /* Port is an abutment shape */ 303#define PORT_SHAPE_RING 0x1000 /* Port is a ring shape */ 304#define PORT_SHAPE_THRU 0x1800 /* Port is a feedthrough shape */ 305 306#define PORT_VISITED 0x2000 /* Bit for checking if a port */ 307 /* has been previously visited. */ 308 309#define LABEL_STICKY 0x4000 /* Label does not change layers */ 310#define LABEL_GENERATE 0x8000 /* Auto-generated label */ 311 312/* 313 * Macros for dealing with label rectangles. 314 */ 315 316#define LABELTOUCHPOINT(p, r) \ 317 ((p)->p_x >= (r)->r_xbot && (p)->p_x <= (r)->r_xtop \ 318 && (p)->p_y >= (r)->r_ybot && (p)->p_y <= (r)->r_ytop) 319 320/* ------------------- Cell definitions and uses ---------------------- */ 321 322/* 323 * There are two structures used for cells: 324 * 325 * CellDef -- one for the definition of the cell 326 * CellUse -- one for each instantiation of the cell. 327 * 328 * The CellDef is shared by all of the CellUses of that cell. 329 */ 330 331typedef struct celldef 332{ 333 unsigned int cd_flags; /* See definitions below */ 334 Rect cd_bbox; /* Bounding box for cell */ 335 Rect cd_extended; /* Bounding box, including labels */ 336 char *cd_file; /* File containing cell definition */ 337#ifdef FILE_LOCKS 338 int cd_fd; /* File descriptor for obtaining and 339 * holding advisory locks. 340 */ 341#endif 342 char *cd_name; /* Name of cell */ 343 struct celluse *cd_parents; /* NULL-terminated list of all uses */ 344 BPlane *cd_cellPlane; /* Instance locations */ 345 Plane *cd_planes[MAXPLANES]; /* Tiles */ 346 ClientData cd_client; /* This space for rent */ 347 int cd_timestamp; /* Unique integer identifying last 348 * time that paint, labels, or subcell 349 * placements changed in this def. 350 */ 351 Label *cd_labels; /* Label list for this cell */ 352 Label *cd_lastLabel; /* Last label in list for this cell. */ 353 char *cd_technology; /* Name of technology for this cell 354 * (Not yet used.) 355 */ 356 ClientData cd_props; /* Private data used to maintain 357 * lists of properties. Properties 358 * are name-value pairs and provide 359 * a flexible way of extending the 360 * data that is stored in a CellDef. 361 */ 362 ClientData cd_filler; /* UNUSED */ 363 HashTable cd_idHash; /* Maps cell use ids to cell uses. 364 * Indexed by cell use id; value 365 * is a pointer to the CellUse. 366 */ 367 TileTypeBitMask cd_types; /* Types of tiles in the cell */ 368} CellDef; 369 370/* 371 * Cell definition flags: 372 * CDAVAILABLE means cell has been loaded from disk into main store. 373 * CDMODIFIED means cell has been changed since last write to disk. 374 * This bit applies only to the real contents of the cell (paint, 375 * labels, and subcell placements), and not to hint information 376 * like child bounding box guesses and child timestamps. 377 * CDNOTFOUND means we failed to find the cell on disk once, so 378 * don't give any more error messages about it. 379 * CDINTERNAL means that this cell is used internally by Magic (e.g. 380 * for DRC checking or channel decomposition or selection) and 381 * has nothing to do with the user's layout. Many things don't 382 * apply to internal cells (such as design-rule checking). 383 * CDGETNEWSTAMP means the cell has been modified since the 384 * last time a timestamp was assigned to it, so it needs 385 * to have a new stamp assigned. 386 * CDSTAMPSCHANGED means that a timestamp has changed in one or 387 * more children of this cell. 388 * CDBOXESCHANGED means that bounding boxes of one or more children 389 * have changed. 390 * CDFIXEDBBOX means that this cell has been declared to be a 391 * pre-extracted subcircuit, so the bounding box should not 392 * be altered. 393 * CDNOEDIT means that the cell cannot be edited because its file 394 * is read-only or (if FILE_LOCKS enabled) locked by another user. 395 * CDPROCESSED means that the cell bounding box has been calculated 396 * and should not be calculated again. 397 * CDFLATGDS is set when the "calma flatten" option is chosen and 398 * a cell is small and does not call any instances itself. 399 * The flag is used to identify the cell and remove it after GDS 400 * input processing. 401 * CDFLATTENED is set when a cell marked CDFLATGDS is used. Cells 402 * that are never used are not removed after processing. 403 * CDPROCESSEDGDS is set when the cell read from the GDS stream file 404 * is added to the magic database. The flag is used to identify 405 * whether the cell has been processed when forcing the GDS 406 * stream data to be read in post-order. 407 * CDVENDORGDS indicates that the cell was read from a GDS stream 408 * with the option "gds readonly true". 409 * CDVISITED indicates that at least one instance of the cell was 410 * already output during a file write. 411 * CDDEREFERENCE is a flag indicating that when loading or expanding 412 * children of a cell, the path should be ignored and the cell 413 * path should be searched for the location. 414 */ 415 416#define CDAVAILABLE 0x0001 417#define CDMODIFIED 0x0002 418#define CDNOTFOUND 0x0004 419#define CDINTERNAL 0x0008 420#define CDGETNEWSTAMP 0x0010 421#define CDSTAMPSCHANGED 0x0020 422#define CDBOXESCHANGED 0x0040 423#define CDFIXEDBBOX 0x0080 424#define CDNOEDIT 0x0100 425#define CDPROCESSED 0x0200 426#define CDFLATGDS 0x0400 427#define CDFLATTENED 0x0800 428#define CDPROCESSEDGDS 0x1000 429#define CDVENDORGDS 0x2000 430#define CDVISITED 0x4000 431#define CDDEREFERENCE 0x8000 432 433/* 434 * Description of an array. 435 * The bounds xlo .. xhi and ylo .. yhi are transformed versions 436 * of the bounds xlo' .. xhi' and ylo' .. yhi' supplied by the 437 * user: 438 * 439 * User supplies: 440 * xlo' index of leftmost array element in root coordinates 441 * xhi' index of rightmost array element in root coordinates 442 * ylo' index of bottommost array element in root coordinates 443 * yhi' index of topmost array element in root coordinates 444 * 445 * There is no constraint on the order of any of these indices; xlo' may 446 * be less than, equal to, or greater than xhi', and similarly for ylo' 447 * and yhi'. 448 * 449 * In addition, the separations xsep and ysep are transformed versions 450 * of the separations xsep' and ysep' supplied by the user: 451 * 452 * User supplies: 453 * xsep' (positive) X spacing between array elements in root coords 454 * ysep' (positive) Y spacing between array elements in root coords 455 * 456 * When the array is made via DBMakeArray, both the indices and the spacings 457 * are transformed down to the coordinates of the CellDef that is the child 458 * of the use containing the ArrayInfo. 459 * 460 * The significance of the various values is as follows: the [xlo, ylo] 461 * element of the array is gotten by transforming the celldef by the 462 * transformation in the celluse. the [x, y] element is gotten by 463 * transforming the celldef by xsep*abs(x-xlo) in x, ysep*abs(y-ylo) in 464 * y, and then transforming by the transformation in the celluse. 465 */ 466 467typedef struct 468{ 469 int ar_xlo, ar_xhi; /* Inclusive low/high X bounds */ 470 int ar_ylo, ar_yhi; /* Inclusive low/high Y bounds */ 471 int ar_xsep, ar_ysep; /* X,Y sep between array elements */ 472} ArrayInfo; 473 474/* 475 * Since a cell may be used in an orientation different from that 476 * in which it was defined, each cell use contains a transform 477 * that will generate coordinates in the world of the parent from 478 * the coordinates in the world of the child. Cells may also be 479 * arrayed. Note: arraying occurs before the transformation, then 480 * the entire array is transformed. 481 */ 482 483typedef struct celluse 484{ 485 /* Binning plane element struct header---must go first! */ 486 void *cu_bpLinks[BP_NUM_LINKS]; /* link fields */ 487 Rect cu_bbox; /* Bounding box of this use, with 488 * arraying taken into account, in 489 * coordinates of the parent def. 490 */ 491 /* End of BPlane header */ 492 493 Rect cu_extended; /* Bounding box of this use, including 494 * the area of rendered text labels. 495 */ 496 unsigned int cu_expandMask; /* Mask of windows in which this use 497 * is expanded. 498 */ 499 unsigned char cu_flags; /* See definitions below */ 500 Transform cu_transform; /* Transform to parent coordinates */ 501 char *cu_id; /* Unique identifier of this use */ 502 ArrayInfo cu_array; /* Arraying information */ 503 CellDef *cu_def; /* The definition of the cell */ 504 struct celluse *cu_nextuse; /* Next in list of uses of our def, 505 * or NULL for end of list. 506 */ 507 CellDef *cu_parent; /* Cell def containing this use */ 508 ClientData cu_client; /* This space for rent */ 509} CellUse; 510 511/* CellUse flags */ 512/* CU_LOCKED means that the cell use is locked, and cannot be 513 * moved, copied, edited, rotated, etc. 514 */ 515#define CU_LOCKED 0x01 516/* CU_SELECT_* are used only with the select cell def. They indicate 517 * that the selection has been made via a "select chunk" 518 * or "select net" command, and should be treated accordingly. 519 */ 520#define CU_SELECT_NET 0x02 521#define CU_SELECT_CHUNK 0x04 522/* CU_SUB_EXTRACTED is a temporary flag indicating that the substrate 523 * of the use has been extracted and the extraction 524 * does not need to be repeated for this use. 525 */ 526#define CU_SUB_EXTRACTED 0x08 527 528/* Character prefix used to denote a locked cell use in a .mag file */ 529#define CULOCKCHAR '*' 530 531#define cu_xlo cu_array.ar_xlo 532#define cu_ylo cu_array.ar_ylo 533#define cu_xhi cu_array.ar_xhi 534#define cu_yhi cu_array.ar_yhi 535#define cu_xsep cu_array.ar_xsep 536#define cu_ysep cu_array.ar_ysep 537 538/* 539 * xMask special values. Note that the usual form of xMask specifies 540 * a single-bit value (1, 2, 4, etc.) representing one window from 541 * which a command originated. Any number that is not a power of 2 542 * may be used to define a special criterion for determining whether 543 * or not to descend into a cell during a tree search, in routine 544 * DBDescendSubcell(). 545 */ 546 547#define CU_DESCEND_ALL 0 /* Descend all subcells */ 548#define CU_DESCEND_SPECIAL 0x0003 /* Descend marked subcells only */ 549#define CU_DESCEND_NO_SUBCKT 0x0005 /* Descend no subcircuits */ 550#define CU_DESCEND_NO_VENDOR 0x0006 /* Descend no vendor-GDS subcells */ 551#define CU_DESCEND_NO_LOCK 0x0007 /* Descend unlocked subcells only */ 552#define CU_DESCEND_NONE 0x0009 /* Descend no subcells */ 553 554/* 555 * Declare tile type structure for non-manhattan geometry 556 */ 557 558typedef struct diagonaltilebody 559{ 560 TileType type_l; 561 TileType type_r; 562 unsigned char split_dir; /* (0 = /, 1 = \) */ 563} DiagonalTileBody; 564 565/* 566 * Structure containing painting information to be passed to the paint 567 * procedure when a diagonal tile is encountered. 568 */ 569 570typedef struct diag_info 571{ 572 PaintResultType *resultTbl; 573 bool dir; 574 bool side; 575} DiagInfo; 576 577/* This would normally go in geometry.h except that it uses TileType. */ 578/* Used in selOps.c but also passed back to CmdRS.c for select command. */ 579 580typedef struct extRectList 581{ 582 TileType r_type; 583 Rect r_r; 584 struct extRectList *r_next; 585} ExtRectList; 586 587/* -------------------- Search context information -------------------- */ 588 589/* Search contexts are used in hierarchical searches */ 590typedef struct 591{ 592 CellUse *scx_use; /* Pointer to cell use currently searched */ 593 int scx_x, scx_y; /* X and Y array elementS if scx_use is array */ 594 Rect scx_area; /* Area searched in scx_use->cu_def coords */ 595 Transform scx_trans; /* Composite transform from coordinates 596 * of the cell use (scx_use) all the way 597 * back to those of the "root" of the 598 * search. 599 */ 600} SearchContext; 601 602/* ------------------- Pathname of a terminal (label) ----------------- */ 603 604/* The following structure is used to build hierarchical label names */ 605typedef struct 606{ 607 char *tp_first; /* Pointer to first character in pathname */ 608 char *tp_next; /* Pointer to next character to be filled in */ 609 char *tp_last; /* Pointer to last available character slot 610 * in pathname. 611 */ 612} TerminalPath; 613 614/* --------------- Contexts for hierarchical tile searches ------------ */ 615 616/* 617 * The TreeContext is the glue which holds together the SearchContext 618 * of a given search (which varies depending on where in the search we 619 * happen to be) and the TreeFilter (see below) which does not. 620 */ 621typedef struct treeContext 622{ 623 SearchContext *tc_scx; /* Search context (varies) */ 624 int tc_plane; /* Current plane of search */ 625 struct treeFilter *tc_filter; /* Constant search criteria */ 626} TreeContext; 627 628/* 629 * The TreeFilter is that portion of the argument to the 630 * filter procedures associated with tree searches that does 631 * not change during the entire search, but serves mainly to 632 * pass the search criteria down to the filter functions. 633 */ 634typedef struct treeFilter 635{ 636 int (*tf_func)(); /* Client's filter function */ 637 ClientData tf_arg; /* Client's argument to pass to filter */ 638 TileTypeBitMask *tf_mask; /* Only process tiles with these types */ 639 int tf_xmask; /* Expand mask */ 640 PlaneMask tf_planes; /* Mask of planes which will be visited */ 641 TileType tf_dinfo; /* Info for processing triangular areas */ 642 unsigned char tf_flags; /* Flags to apply to search (see below) */ 643 TerminalPath *tf_tpath; /* Buffer to hold hierarchical label names */ 644} TreeFilter; 645 646/* Definition of tf_flags values */ 647 648#define TF_LABEL_DISPLAY 0x01 /* Search for labels using the area 649 * of the label itself 650 */ 651#define TF_LABEL_ATTACH 0x02 /* Search for labels using the area 652 * of paint to which the label is 653 * attached 654 */ 655#define TF_LABEL_ATTACH_NOT_NE 0x04 /* Same as above, ignore tile NE corner */ 656#define TF_LABEL_ATTACH_NOT_NW 0x08 /* Same as above, ignore tile NW corner */ 657#define TF_LABEL_ATTACH_NOT_SE 0x10 /* Same as above, ignore tile SE corner */ 658#define TF_LABEL_ATTACH_NOT_SW 0x20 /* Same as above, ignore tile SW corner */ 659#define TF_LABEL_ATTACH_CORNER 0x3C /* Mask of the four types above */ 660 661/* To do: Make the tpath entries dynamically allocated */ 662#define FLATTERMSIZE 4096 /* Used for generating flattened labels */ 663 664/* ------------ Information used in connectivity searches --------------*/ 665 666/* The following structure is used to hold several pieces of information 667 * that must be passed through multiple levels of search function. This 668 * structure is used by DBSrConnect, DBTreeCopyConnect, SimTreeCopyConnect, 669 * and DBTreeCopyConnectDCS. 670 */ 671 672struct conSrArg 673{ 674 CellDef *csa_def; /* Definition being searched. */ 675 int csa_pNum; /* Index of plane being searched */ 676 TileTypeBitMask *csa_connect; /* Table indicating what connects 677 * to what. 678 */ 679 int (*csa_clientFunc)(); /* Client function to call. */ 680 ClientData csa_clientData; /* Argument for clientFunc. */ 681 bool csa_clear; /* FALSE means pass 1, TRUE 682 * means pass 2. 683 */ 684 Rect csa_bounds; /* Area that limits search. */ 685}; 686 687typedef struct 688{ 689 Rect area; /* Area to process */ 690 TileTypeBitMask *connectMask; /* Connection mask for search */ 691 TileType dinfo; /* Info about triangular search areas */ 692} conSrArea; 693 694struct conSrArg2 695{ 696 CellUse *csa2_use; /* Destination use */ 697 TileTypeBitMask *csa2_connect; /* Table indicating what connects 698 * to what. 699 */ 700 SearchContext *csa2_topscx; /* Original top-level search context */ 701 int csa2_xMask; /* Cell window mask for search */ 702 Rect *csa2_bounds; /* Area that limits the search */ 703 704 Stack *csa2_stack; /* Stack of full csa2_list entries */ 705 conSrArea *csa2_list; /* List of areas to process */ 706 int csa2_top; /* Index of next area to process */ 707 int csa2_lasttop; /* Previous top index */ 708}; 709 710#define CSA2_LIST_SIZE 65536 /* Number of entries per list */ 711 712/* -------------- Undo information passed to DBPaintPlane ------------- */ 713 714typedef struct 715{ 716 CellDef *pu_def; /* Cell definition being modified */ 717 int pu_pNum; /* Index of plane within cell def */ 718} PaintUndoInfo; 719 720/* ---------------------- Codes for paint/erase ----------------------- */ 721 722 /* The following are obsolete and will go away */ 723#define ERASE 0 /* Erase type from existing tiles */ 724#define PAINT 1 /* Paint type over existing tiles */ 725#define WRITE 2 /* Write type unconditionally */ 726 727/* ---------------------- Codes for cell printing ---------------------- */ 728 729#define SELF 0 730#define PARENTS 1 731#define CHILDREN 2 732#define CHILDINST 3 733#define ALLCELLS 4 734#define TOPCELLS 5 735#define MODIFIED 6 736#define OTHER 7 737 738/* -------------------- More codes for painting ------------------------*/ 739 740#define PAINT_NORMAL 0 /* Normal paint procedure */ 741#define PAINT_MARK 1 /* Mark tiles that are painted */ 742#define PAINT_XOR 2 /* Use with XOR function to prevent double-painting */ 743 744/* -------------------- Exported procedure headers -------------------- */ 745 746 /* Painting/erasing */ 747extern void DBPaint(); 748extern void DBErase(); 749extern int DBSrPaintArea(); 750extern int DBPaintPlane0(); 751extern int DBPaintPlaneActive(); 752extern int DBPaintPlaneWrapper(); 753extern int DBPaintPlaneMark(); 754extern int DBPaintPlaneXor(); 755extern int DBPaintPlaneByProc(); 756extern int DBPaintPlaneMergeOnce(); 757extern void DBPaintMask(); 758extern void DBEraseMask(); 759extern void DBClearPaintPlane(); 760extern void DBLockContact(); 761extern void DBUnlockContact(); 762 763#define DBPaintPlane(a, b, c, d) DBPaintPlane0(a, b, c, d, PAINT_NORMAL) 764#define DBMergeNMTiles(a, b, c) DBMergeNMTiles0(a, b, c, FALSE) 765 766extern int DBNMPaintPlane0(); 767#define DBNMPaintPlane(a, b, c, d, e) DBNMPaintPlane0(a, b, c, d, e, PAINT_NORMAL) 768 769 /* I/O */ 770extern bool DBCellRead(); 771extern bool DBTestOpen(); 772extern char *DBGetTech(); 773extern bool DBCellWrite(); 774extern int DBCellReadArea(); 775extern void DBFileRecovery(); 776extern bool DBWriteBackup(); 777extern bool DBReadBackup(); 778extern void DBRemoveBackup(); 779extern void DBPathSubstitute(); 780 781 /* Labels */ 782extern Label *DBPutLabel(); 783extern Label *DBPutFontLabel(); 784extern void DBFontLabelSetBBox(); 785extern bool DBEraseGlobLabel(); 786extern bool DBEraseLabel(); 787extern void DBEraseLabelAll(); 788extern void DBEraseLabelsByContent(); 789extern void DBRemoveLabel(); 790extern void DBReOrientLabel(); 791extern void DBAdjustLabels(); 792 793 /* Technology initialization */ 794extern void DBTechInit(); 795extern bool DBTechSetTech(); 796extern void DBTechInitVersion(); 797extern bool DBTechSetVersion(); 798extern bool DBTechAddPlane(); 799extern bool DBTechAddType(); 800extern bool DBTechAddAlias(); 801extern void DBTechFinalType(); 802extern bool DBTechAddConnect(); 803extern bool DBTechAddContact(); 804extern bool DBTechAddCompose(); 805extern TileType DBTechNameType(), DBTechNoisyNameType(); 806extern int DBTechNamePlane(), DBTechNoisyNamePlane(); 807extern PlaneMask DBTechNameMask(), DBTechNoisyNameMask(); 808extern PlaneMask DBTechTypesToPlanes(); 809extern bool DBTechTypesOnPlane(); 810extern void DBTechInitPlane(); 811extern void DBTypeInit(); 812extern void DBTechInitType(); 813extern void DBTechInitCompose(); 814extern void DBTechFinalCompose(); 815extern void DBTechInitContact(); 816extern void DBTechFinalContact(); 817extern void DBTechFinalConnect(); 818extern void DBTechInitConnect(); 819extern bool DBIsContact(); 820 821 /* Cell symbol table */ 822extern void DBCellInit(); 823extern void DBCellPrint(); 824extern void DBUsePrint(); 825extern void DBTopPrint(); 826extern CellDef *DBCellLookDef(); 827extern CellDef *DBCellNewDef(); 828extern CellDef *DBCellDefAlloc(); 829extern bool DBCellRenameDef(); 830extern bool DBCellDeleteDef(); 831extern void DBCellDefFree(); 832extern int DBCellSrDefs(); 833extern CellUse *DBCellNewUse(); 834extern bool DBCellDeleteUse(); 835extern CellUse *DBCellFindDup(); 836extern void DBLockUse(); 837extern void DBUnlockUse(); 838extern void DBOrientUse(); 839extern void DBAbutmentUse(); 840 841 /* Cell selection */ 842extern CellUse *DBSelectCell(); 843extern CellUse *DBFindUse(); 844 845 /* Insertion/deletion of cell uses into the cell tile plane of a parent */ 846extern void DBPlaceCell(); 847extern void DBPlaceCellNoModify(); 848extern void DBDeleteCell(); 849extern void DBDeleteCellNoModify(); 850extern void DBClearCellPlane(); 851 852 /* Insertion/deletion of cell uses into the name space of a parent */ 853extern bool DBLinkCell(); 854extern void DBUnlinkCell(); 855 856 /* Deletion of cell defs */ 857extern void DBUndoReset(); 858 859 /* Bounding boxes and arrays */ 860extern bool DBBoundPlane(); 861extern void DBComputeUseBbox(); 862extern void DBReComputeBbox(); 863extern void DBReComputeBboxVert(); 864extern void DBMakeArray(); 865extern void DBSetArray(); 866extern void DBSetTrans(); 867extern void DBArrayOverlap(); 868extern void DBComputeArrayArea(); 869extern Transform *DBGetArrayTransform(); 870extern char *DBPrintUseId(); 871 872 /* Massive copying */ 873extern void DBCellCopyPaint(); 874extern void DBCellCopyAllPaint(); 875extern void DBCellCheckCopyAllPaint(); 876extern void DBCellCopyLabels(); 877extern void DBCellCopyAllLabels(); 878extern void DBCellCopyGlobLabels(); 879extern void DBCellCopyCells(); 880extern void DBCellCopyAllCells(); 881extern Plane *DBCellGenerateSubstrate(); 882 883 /* Contact image handling */ 884extern TileType DBPlaneToResidue(); 885extern TileType DBTechFindStacking(); 886extern bool DBIsContact(); 887extern TileTypeBitMask *DBResidueMask(); 888extern void DBFullResidueMask(); 889 890 /* Miscellaneous */ 891extern void DBCellClearDef(); 892extern void DBCellCopyDefBody(); 893extern void DBExpandAll(), DBExpand(); 894extern bool DBIsAncestor(); 895extern void DBCellSetAvail(); 896extern void DBCellClearAvail(); 897extern bool DBCellGetModified(); 898extern void DBCellSetModified(); 899extern void DBFixMismatch(); 900extern void DBTreeCopyConnect(); 901extern void DBSeeTypesAll(); 902extern void DBUpdateStamps(); 903extern void DBEnumerateTypes(); 904extern Plane *DBNewPlane(); 905 906extern PaintResultType (*DBNewPaintTable())[TT_MAXTYPES][TT_MAXTYPES]; 907typedef int (*IntProc)(); 908IntProc DBNewPaintPlane(); 909 910 /* Diagnostic */ 911extern void DBTechPrintTypes(); 912extern void DBTechPrintCanonicalType(); 913 914 /* Deallocation */ 915extern void DBClearCellPlane(); 916extern void DBClearPaintPlane(); 917extern void DBFreeCellPlane(); 918extern void DBFreePaintPlane(); 919 920 /* Cell properties */ 921extern void DBPropPut(); 922extern ClientData DBPropGet(); 923extern int DBPropEnum(); 924extern void DBPropClearAll(); 925 926 /* Searching */ 927extern int DBTreeSrTiles(); 928extern int DBTreeSrUniqueTiles(); 929extern int DBNoTreeSrTiles(); 930extern int DBTreeSrLabels(); 931extern int DBTreeSrCells(); 932extern int DBSrRoots(); 933extern int DBCellEnum(); 934extern int DBArraySr(); 935extern bool DBNearestLabel(); 936extern int DBSrLabelLoc(); 937extern TileType DBTransformDiagonal(); 938 939/* -------------------------- Layer locking ------------------------------*/ 940 941extern TileTypeBitMask DBActiveLayerBits; /* Layers that are locked */ 942extern TileTypeBitMask DBTechActiveLayerBits; /* Layers that are marked as 943 * locked in the techfile 944 */ 945 946#define LOCKLAYERCHAR '-' /* Layer names beginning with this are locked */ 947#define LockedLayer(tiletype) (!TTMaskHasType(&DBActiveLayerBits, tiletype)) 948 949/* ---------- Internal units to Lambda conversion factor ---------------- */ 950 951extern int DBLambda[2]; 952 953/* -------------------- Exported magic file suffix -------------------- */ 954 955extern char *DBSuffix; /* Suffix appended to all Magic cell names */ 956 957/* -------------------- User Interface Stuff -------------------------- */ 958 959extern bool DBVerbose; /* If FALSE, don't print warning messages */ 960 961/* ------------------ Exported technology variables ------------------- */ 962 963/*** 964 *** The following variables should be considered 965 *** read-only to all clients of the database module. 966 ***/ 967 968 /* Name, version, and description of the current technology */ 969extern char *DBTechName; 970extern char *DBTechVersion; 971extern char *DBTechDescription; 972 973 /* 974 * Predefined masks of tile types. 975 * The number of built-in types is just TT_TECHDEPBASE. 976 */ 977extern TileTypeBitMask DBZeroTypeBits; /* All zeroes */ 978extern TileTypeBitMask DBAllTypeBits; /* All ones */ 979extern TileTypeBitMask DBBuiltinLayerBits; /* All built-in types */ 980extern TileTypeBitMask DBAllButSpaceBits; /* All but space */ 981extern TileTypeBitMask DBAllButSpaceAndDRCBits; /* All but space and drc */ 982extern TileTypeBitMask DBSpaceBits; /* Space only */ 983 984 /* 985 * Number of tile types, including those specied by the technology 986 * file and those built-in to Magic, but not including those automatically 987 * generated to represent contact images. Also, a mask of those 988 * types contained in the technology file. 989 */ 990extern int DBNumUserLayers; 991extern TileTypeBitMask DBUserLayerBits; /* Including space */ 992 993 /* Total number of Magic tile types in this technology */ 994extern int DBNumTypes; 995 996 /* Total number of tile planes */ 997extern int DBNumPlanes; 998 999/* Abbreviations */ 1000#define NT TT_MAXTYPES 1001#define NP PL_MAXTYPES 1002 1003 /* Alias names for groups of types defined in the tech file */ 1004extern HashTable DBTypeAliasTable; 1005 1006 /* Gives the official long name of each plane: */ 1007extern char *DBPlaneLongNameTbl[NP]; 1008 1009 /* Gives a short name for each plane: */ 1010extern char *DBPlaneShortName(); 1011 1012 /* Gives for each plane a mask of all tile types stored in that plane: */ 1013extern TileTypeBitMask DBPlaneTypes[NP]; 1014 1015 /* Similar to DBPlaneTypes[], but no type appears on more than one plane. 1016 * Effectively, the reverse lookup of DBPlane(type) (DBTypePlaneTbl[type]). 1017 */ 1018extern TileTypeBitMask DBHomePlaneTypes[NP]; 1019 1020 /* Gives a TileTypeBitMask for everything that connects to a type. 1021 * Bit x is set in mask DBConnectTbl[y] if any image of x connects 1022 * to any image of y. 1023 */ 1024extern TileTypeBitMask DBConnectTbl[NT]; 1025 1026 /* Complement of above: everything not connected to a type */ 1027extern TileTypeBitMask DBNotConnectTbl[NT]; 1028 1029 /* 1030 * Gives a TileTypeBitMask of all types that correspond to a given 1031 * layer. Used for contacts that have images in more than one 1032 * plane. 1033 */ 1034extern TileTypeBitMask DBLayerTypeMaskTbl[NT]; 1035 1036 /* 1037 * Gives a plane mask of all planes that have tiles that connect to 1038 * tiles of a given type. This is only used for contacts; it tells 1039 * which other planes contain images of the contact. A tile's own 1040 * plane is never included in its plane mask. Non-contact types 1041 * always have 0 DBConnPlanes entries. 1042 */ 1043extern PlaneMask DBConnPlanes[NT]; 1044 1045 /* 1046 * Similar to DBConnPlanes[], but this time it is non-zero 1047 * for those planes to which each type connects, exclusive 1048 * of its home plane and those planes to which it connects as a 1049 * contact. These planes needn't be adjacent. For example, a 1050 * p-well is connected to p-substrate diffusion that overlaps it; 1051 * also, p well contacts connect to a p-well. This information 1052 * is currently used only in the circuit extractor. 1053 */ 1054extern PlaneMask DBAllConnPlanes[NT]; 1055 1056 /* 1057 * Each TileType has a home plane. The TileType only appears on 1058 * its home plane. The only exception is TT_SPACE, which can appear 1059 * on any plane. (For debugging, there may be other cases). 1060 * 1061 * DBTypePlaneTbl gives the home plane for a given TileType, 1062 * and DBTypePlaneMaskTbl gives a mask of the planes on which 1063 * it appears (all planes for TT_SPACE, one plane for others). 1064 */ 1065extern int DBTypePlaneTbl[TT_MAXTYPES]; 1066extern PlaneMask DBTypePlaneMaskTbl[TT_MAXTYPES]; 1067 1068 /* Gives the long name for each tile type: */ 1069extern char *DBTypeLongNameTbl[TT_MAXTYPES]; 1070 1071 /* Gives a short name for a tile type: */ 1072extern char *DBTypeShortName(); 1073 1074 /* 1075 * The following give masks of all planes that may be affected 1076 * when material of a given type is painted/erased: 1077 */ 1078extern PlaneMask DBTypePaintPlanesTbl[TT_MAXTYPES]; 1079extern PlaneMask DBTypeErasePlanesTbl[TT_MAXTYPES]; 1080 1081 /* 1082 * Gives the resulting tile type when one tile type is painted over 1083 * another in a given plane: 1084 * 1085 * newType = DBPaintResult[pNum][paintType][oldType] 1086 */ 1087extern PaintResultType DBPaintResultTbl[NP][NT][NT]; 1088 1089 /* 1090 * Gives the resulting tile type when one tile type is erased over 1091 * another in a given plane: 1092 * 1093 * newType = DBEraseResult[pNum][paintType][oldType] 1094 */ 1095extern PaintResultType DBEraseResultTbl[NP][NT][NT]; 1096 1097 /* 1098 * A simple table using TT_CHECKPAINT, which does not exist on 1099 * paintable planes, to force a paint result that is always a 1100 * tiletype that does not exist on the plane. Used for generating 1101 * non-Manhattan geometry. 1102 */ 1103extern PaintResultType DBSpecialResultTbl[NT]; 1104 1105 /* 1106 * Gives the resulting tile type when one tile type is 'written' 1107 * over a given plane. This corresponds to the case where the 1108 * written type replaces the old tile without regard to the type 1109 * of the old tile. 1110 * 1111 * paintType = DBWriteResultTbl[paintType][oldType] 1112 */ 1113extern PaintResultType DBWriteResultTbl[NT][NT]; 1114 1115/* --------------------- Exported macros ------------------------------ */ 1116 1117 /* 1118 * Macros for reading the paint/erase tables: 1119 * resultType = DBStdPaintEntry(oldType, paintType, planeNum) 1120 * resultType = DBStdEraseEntry(oldType, paintType, planeNum) 1121 */ 1122#define DBStdPaintEntry(h,t,p) (DBPaintResultTbl[p][t][h]) 1123#define DBStdEraseEntry(h,t,p) (DBEraseResultTbl[p][t][h]) 1124 1125 /* 1126 * Macros for constructing the pointer to pass to DBPaintPlane 1127 * as the result table. 1128 */ 1129#define DBStdPaintTbl(t,p) (&DBPaintResultTbl[p][t][0]) 1130#define DBStdEraseTbl(t,p) (&DBEraseResultTbl[p][t][0]) 1131#define DBStdWriteTbl(t) (&DBWriteResultTbl[t][0]) 1132#define DBSpecialPaintTbl (&DBSpecialResultTbl[0]) 1133 1134 /* 1135 * int DBPlane(type) TileType type; 1136 * Returns the home plane of 'type'. 1137 */ 1138#define DBPlane(type) (DBTypePlaneTbl[type]) 1139 1140 /* 1141 * char *DBTypeLongName(type) TileType type; 1142 * Returns the long name of 'type'. 1143 */ 1144#define DBTypeLongName(type) (DBTypeLongNameTbl[type]) 1145 1146 /* 1147 * char *DBPlaneLongName(p) int p; 1148 * Returns the long name of plane 'plane'. 1149 */ 1150#define DBPlaneLongName(p) (DBPlaneLongNameTbl[p]) 1151 1152 /* 1153 * bool DBConnectsTo(t1, t2) TileType t1, t2; 1154 * Returns TRUE if types 't1' and 't2' are electrically connected. 1155 */ 1156#define DBConnectsTo(t1, t2) (TTMaskHasType(&DBConnectTbl[t1], t2)) 1157 1158 /* 1159 * bool DBTypesOnSamePlane(t1, t2) TileType t1, t2; 1160 * Returns TRUE if types 't1' and 't2' exist on the same plane. 1161 */ 1162#define DBTypesOnSamePlane(t1, t2) \ 1163 (DBTypePlaneMaskTbl[t1] & DBTypePlaneMaskTbl[t2]) 1164 1165 /* 1166 * bool DBPaintOnPlane(t, p) TileType t; int p; 1167 * bool DBEraseOnPlane(t, p) TileType t; int p; 1168 * 1169 * Return TRUE if tile type 't' has any effect on plane 'p' 1170 * when being painted/erased. 1171 */ 1172#define DBPaintOnPlane(t, p) (PlaneMaskHasPlane(DBTypePaintPlanesTbl[t], p)) 1173#define DBEraseOnPlane(t, p) (PlaneMaskHasPlane(DBTypeErasePlanesTbl[t], p)) 1174 1175 /* 1176 * bool DBPaintOnTypePlanes(t1, t2) TileType t1, t2; 1177 * bool DBEraseOnTypePlanes(t1, t2) TileType t1, t2; 1178 * 1179 * Return TRUE if tile type 't1' has any effect on planes defined 1180 * for type 't2' when being painted/erased. 1181 */ 1182#define DBPaintOnTypePlanes(t1, t2) \ 1183 (DBTypePaintPlanesTbl[t1] & DBTypePlaneMaskTbl[t2]) 1184#define DBEraseOnTypePlanes(t1, t2) \ 1185 (DBTypePaintPlanesTbl[t1] & DBTypePlaneMaskTbl[t2]) 1186 1187 /* 1188 * bool DBTypeOnPlane(t, p) TileType t; int p; 1189 * Returns TRUE if tile type 't' exists on plane 'p'. 1190 */ 1191#define DBTypeOnPlane(t, p) (PlaneMaskHasPlane(DBTypePlaneMaskTbl[t], p)) 1192 1193/* --------- Tile types and masks (auto-generated by makedbh) ------------ */ 1194 1195