home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / Include / cd.h < prev    next >
C/C++ Source or Header  |  1988-01-28  |  9KB  |  422 lines

  1. /*
  2.  * cd.h
  3.  *
  4.  * Copyright -C- 1981 Kenneth H. Keller, Giles C. Billingsley
  5.  * sccsid "%W%  %G%"
  6.  *
  7.  *     CD is a CIF database package that was developed by the integrated
  8.  * circuits group of the Electronics Research Laboratory and the
  9.  * Department of Electrical Engineering and Computer Sciences at
  10.  * the University of California, Berkeley, California.  The programs in
  11.  * CD are available free of charge to any interested party.
  12.  * The sale, resale, or use of these programs for profit without the
  13.  * express written consent of the Department of Electrical Engineering
  14.  * and Computer Sciences, University of California, Berkeley, California,
  15.  * is forbidden.
  16.  */
  17.  
  18.  
  19. /*
  20.  * CD package data structures.
  21.  *  
  22.  * Giles Billingsley
  23.  * Ken Keller
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <math.h>
  28. #include "nmalloc.h"
  29. #include "macros.h"
  30. #include "xforms.h"
  31.  
  32. #ifdef vms
  33. #define    void    int
  34. #endif
  35.  
  36. #define    CDDelete    CDDeleteObjectDesc
  37.  
  38. #define FILENAMESIZE    16        /* maximum size of a file name */
  39.  
  40. /*
  41.  * Values routines return in StatusInt of CDOpen, CDBeginMakeCall,
  42.  * CDTo, CDFrom, or CDParseCIF.
  43.  */
  44. #define    CDPARSEFAILED        1    /* (FATAL) parse failed */
  45. #define    CDOLDSYMBOL        2    /* symbol already exists in database */
  46. #define    CDNEWSYMBOL        3    /* (empty) symbol not in search path */
  47. #define    CDSUCCEEDED        4    /* new symbol(s) found in search path */
  48.  
  49. /*
  50.  * Valid arguments to CDError().
  51.  */
  52. #define    CDMALLOCFAILED        11    /* (FATAL) out of memory */
  53. #define CDBADBOX        12    /* zero width or length box */
  54. #define    CDXFORMSTACKFULL    13    /* transform stack overflow */
  55. #define CDBADPATH        14    /* bad directory name in search path */
  56.  
  57. /*
  58.  * Types of geometries
  59.  */
  60. #define CDSYMBOLCALL        'c'
  61. #define CDPOLYGON        'p'
  62. #define CDROUNDFLASH        'r'
  63. #define CDLABEL            'l'
  64. #define CDWIRE            'w'
  65. #define CDBOX            'b'
  66.  
  67. /*
  68.  * Types of transformations
  69.  */
  70. #define    CDMIRRORX        'x'    /* mirror in the direction of x */
  71. #define    CDMIRRORY        'y'    /* mirror in the direction of y */
  72. #define    CDROTATE        'r'    /* rotate by vector X,Y */
  73. #define    CDTRANSLATE        't'    /* translate to X,Y */
  74.  
  75. /*
  76.  * CD Control flags; See struct d below.
  77.  */
  78. #define DCONTROLCDOPEN        'o'
  79. #define DCONTROLPCIF        'p'
  80. #define DCONTROLCDTO        't'
  81. #define DCONTROLVANILLA        'v'
  82.  
  83. /*
  84.  * Coordinate system with 1 micron features and 1 cm dice.
  85.  * Remember that there are 100 CIF units per micron.
  86.  */
  87. #define INFINITY        100000000
  88.  
  89. /*
  90.  * These are the numbers that CD uses to determine which bin an object
  91.  * resides in.  They should reflect the average size of a layout being
  92.  * edited by KIC.  KIC will not fail if the numbers are too small.
  93.  * Anything outside of this window is placed in the residual bin.
  94.  * If these numbers become too large, CDIntersect() must use floating
  95.  * point calculations.
  96.  */
  97. #define CDBINMAXX        500000
  98. #define CDBINMAXY        500000
  99. #define CDBINMINX        (-CDBINMAXX)
  100. #define CDBINMINY        (-CDBINMAXY)
  101.  
  102. /*
  103.  * PLEASE NOTE
  104.  * ^^^^^^^^^^^
  105.  * Because a char is used as the layer and info fields, the absolute
  106.  * maximum number of layers is 117.  The may be increase by recompiling
  107.  * kic with the Layer and Info fields typed as ints.
  108.  */
  109. #define CDNUMBINS        10
  110. #define CDNUMLAYERS        35
  111.  
  112. /*
  113.  * Number of symbols stored in the symbol table for any given CIF file.
  114.  */
  115. #define CDNUMREMEMBER        1000
  116.  
  117. /*
  118.  * Storage for diagnostics of CDError().
  119.  */
  120. extern char *CDStatusString;
  121. extern int  CDStatusInt;
  122.  
  123. /*
  124.  * Master list desc.
  125.  */
  126. struct m {
  127.     int mReferenceCount;
  128.     int mLeft,mBottom,mRight,mTop; 
  129.     char *mName;
  130.     struct m *mPred,*mSucc;
  131.     };
  132.  
  133.  
  134. /*
  135.  * Propety List desc.
  136.  */
  137. struct prpty {
  138.     int prpty_Value;
  139.     char *prpty_String;
  140.     struct prpty *prpty_Succ;
  141.     };
  142.  
  143.  
  144. /*
  145.  * Symbol desc.
  146.  */
  147. struct s {
  148.     int sLeft,sBottom,sRight,sTop; 
  149.     int sBBValid;
  150.     int sA,sB;
  151.     char *sName;
  152.     short sInfo;
  153.     /*
  154.      * One bin foe each layer.  Layer 0 is for call descs. 
  155.      * Each bin points to a double linked list of object descs. 
  156.      * Bin[.][0][0] are the RESIDUAL bins--Bin[.][0][1] and Bin[.][1][0]
  157.      * are unused TUNABLE.  NumBins should be as big as it can be.
  158.      * For 20 layers and 100 bins per layer,
  159.      * the data structure becomes 2000 words. 
  160.      */
  161.     struct o ***sBin[CDNUMLAYERS+1];
  162.     struct m *sMasterList;
  163.     struct prpty *sPrptyList;
  164.     };
  165.  
  166.  
  167. /*
  168.  * Object desc.
  169.  */
  170. struct o {
  171.     int oLeft,oBottom,oRight,oTop;
  172.     char oType;
  173.     char oLayer;
  174.     short oInfo;
  175.     struct o *oRep;
  176.     struct o *oPred,*oSucc;
  177.     struct prpty *oPrptyList;
  178.     };
  179.  
  180.  
  181. /*
  182.  * Polygon desc.
  183.  */
  184. struct po {
  185.     struct p *poPath; 
  186.     };
  187.  
  188.  
  189. /*
  190.  * Round flash desc.
  191.  */
  192. struct r {
  193.     int rWidth,rX,rY;
  194.     };
  195.  
  196.  
  197. /*
  198.  * Wire desc.
  199.  */
  200. struct w {
  201.     int wWidth;
  202.     struct p *wPath;
  203.     }; 
  204.  
  205.  
  206. /*
  207.  * Call desc.
  208.  */
  209. struct c {
  210.     int cNum;
  211.     /* Pointer to transformation descriptor. */
  212.     struct t *cT;
  213.     /* Pointer to master list descriptor. */
  214.     struct m *cMaster;
  215.     /* Array parameters. */
  216.     int cNumX,cNumY,cDX,cDY;
  217.     };
  218.  
  219.  
  220. /*
  221.  * Transform desc.
  222.  * If MX, tType == CDMIRRORX.
  223.  * If MY, tType == CDMIRRORX.
  224.  * If R, tType == CDROTATE, tX == XDirection, tY == YDirection.
  225.  * If T, tType == CDTRANSLATE, tX == TX, tY = TY;
  226.  */
  227. struct t {
  228.     char tType;
  229.     int tX,tY;
  230.     struct t *tSucc;
  231.     };
  232.  
  233.  
  234. /*
  235.  * Label desc.
  236.  */
  237. struct la {
  238.     char *laLabel;
  239.     int laX,laY;
  240.     };
  241.  
  242.  
  243. /*
  244.  * Linked path structure
  245.  */
  246. struct p {
  247.     int pX,pY;
  248.     struct p *pSucc;
  249.     };
  250.  
  251.  
  252. /*
  253.  * Generator desc.
  254.  * Search Bin[Layer][0][0] first.
  255.  * Then Bin[Layer][BeginX..EndX][BeginY..EndY].
  256.  * Bin[Layer][X][Y] is the current bin. 
  257.  * Pointer points to the current desc in the current bin. 
  258.  */
  259. struct g {
  260.     int  gLeft,gBottom,gRight,gTop;
  261.     int  gBeginX,gX,gEndX,gBeginY,gY,gEndY;
  262.     char gLayer;
  263.     struct o *gPointer;
  264.     };
  265.  
  266.  
  267. /*
  268.  * CD's current parameter struct
  269.  */
  270. struct d {
  271.     /*
  272.      * DCONTROLCDOPEN denotes CD is in CDOpen
  273.      * DCONTROLPCIF denotes CD is in CDOpen and parsing CIF rather than kic
  274.      * DCONTROLCDTO denotes CD is in CDTo
  275.      * DCONTROLVANILLA denotes CD is in none of the above
  276.      */
  277.     char dControl;
  278.  
  279.     /* Current parameters for symbol being parsed in CDOpen. */
  280.     int  dNumX,dDX,dNumY,dDY;
  281.  
  282.     /* Scale factors for CDTo and CDFrom. */
  283.     int dA,dB;
  284.  
  285.     /* Symbol scale factors. */
  286.     int dDSA,dDSB;
  287.  
  288.     struct o *dPointer;
  289.     struct s *dSymbolDesc;
  290.     struct s *dRootCellDesc;
  291.  
  292.     /* UNIX file names are limited to 14 characters */
  293.     char dSymbolName[FILENAMESIZE];
  294.     FILE *dSymbolFileDesc;
  295.  
  296.     /*
  297.      * Fields used in CDTo follow.
  298.      */
  299.  
  300.     /* True if parsing root symbol. */
  301.     int dRoot;
  302.  
  303.     /* Root's file desc. */
  304.     FILE *dRootFileDesc;
  305.  
  306.     /* Current property list for symbol being parsed */
  307.     struct prpty *dPrptyList;
  308.  
  309.     /*
  310.      * dProgram == 'h' if IGS gened it.
  311.      *          == 'i' if Icarus gened it.
  312.      *          == 's' if Sif gened it.
  313.      *          == 'n' if none of the above.
  314.      */
  315.     char dProgram;
  316.  
  317.     /*
  318.      * Symbol name table.
  319.      * 16 comes from the fact that a UNIX file name is only 14 characters
  320.      * long and each symbol name is a UNIX file name.  VMS file names are
  321.      * smaller.
  322.      */
  323.     char dSymTabNames[CDNUMREMEMBER][FILENAMESIZE]; 
  324.     int  dSymTabNumbers[CDNUMREMEMBER]; 
  325.     int  dNumSymbolTable;
  326.  
  327.     /*
  328.      * Because CIF files may have FORWARD references, CDTo must pass
  329.      * over the CIF file TWICE. 
  330.      * On the first pass, it just fills up the symbol name table.
  331.      * On the second pass, it does the translation to KIC format.
  332.      */
  333.     int dFirstPass;
  334.  
  335.     /*
  336.      * True if debugging.
  337.      */
  338.     int dDebug;
  339.     int dNumSymbolsAllocated;
  340.     }
  341. CDDesc;
  342.  
  343.  
  344. /*
  345.  * CD layer table
  346.  */
  347. struct l
  348.     {
  349.     char lTechnology;
  350.     char lMask[3];
  351.     /*True if CDFrom should output layer.*/
  352.     char lCDFrom;
  353.     }
  354. CDLayer[CDNUMLAYERS+1];
  355.  
  356.  
  357. /*
  358.  * Hash table of symbol descs keyed on symbol's name.
  359.  */
  360. struct bu 
  361.     {
  362.     struct s *buSymbolDesc;
  363.     struct bu *buPred;
  364.     struct bu *buSucc;
  365.     };
  366. struct bu *CDSymbolTable[CDNUMLAYERS+1];
  367.  
  368. /*
  369.  * Ousterhout's file name package.
  370.  */
  371. FILE *POpen();
  372. char *PGetPath();
  373.  
  374. /*
  375.  * CD routines
  376.  */
  377. extern void CDInit();
  378. extern void CDSetLayer();
  379. extern void CDDebug();
  380. extern void CDSymbol();
  381. extern void CDCheckPath();
  382. extern void CDDeleteObjectDesc();
  383. extern void CDCall();
  384. extern void CDBox();
  385. extern void CDLabel();
  386. extern void CDPolygon();
  387. extern void CDWire();
  388. extern void CDRoundFlash();
  389. extern void CDInfo();
  390. extern void CDSetInfo();
  391. extern void CDProperty();
  392. extern void CDType();
  393. extern void CDIntersect();
  394. extern void CDGen();
  395. extern void CDInitTGen();
  396. extern void CDTGen();
  397. extern int CDBB();
  398. extern int CDOpen();
  399. extern int CDPath();
  400. extern int CDClose();
  401. extern int CDReflect();
  402. extern int CDPatchInstances();
  403. extern int CDAddProperty();
  404. extern int CDRemoveProperty();
  405. extern int CDMakeBox();
  406. extern int CDMakeLabel();
  407. extern int CDMakePolygon();
  408. extern int CDMakeWire();
  409. extern int CDMakeRoundFlash();
  410. extern int CDBeginMakeCall();
  411. extern int CDT();
  412. extern int CDEndMakeCall();
  413. extern int CDInsertObjectDesc();
  414. extern int CDInitGen();
  415. extern int CDUpdate();
  416. extern int CDGenCIF();
  417. extern int CDTo();
  418. extern int CDFrom();
  419. extern int CDParseCIF();
  420. extern int CDUnmark();
  421. extern int CDError();
  422.