File: DBtech.c

package info (click to toggle)
magic 8.3.105%2Bds.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 17,128 kB
  • sloc: ansic: 175,615; sh: 7,634; tcl: 4,536; lisp: 2,554; makefile: 946; cpp: 587; python: 389; csh: 148; awk: 140
file content (509 lines) | stat: -rw-r--r-- 14,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/*
 * DBtech.c --
 *
 * Technology initialization for the database module.
 * This file handles overall initialization, construction
 * of the general-purpose exported TileTypeBitMasks, and
 * the "connect" section.
 *
 *     *********************************************************************
 *     * Copyright (C) 1985, 1990 Regents of the University of California. *
 *     * Permission to use, copy, modify, and distribute this              *
 *     * software and its documentation for any purpose and without        *
 *     * fee is hereby granted, provided that the above copyright          *
 *     * notice appear in all copies.  The University of California        *
 *     * makes no representations about the suitability of this            *
 *     * software for any purpose.  It is provided "as is" without         *
 *     * express or implied warranty.  Export of this software outside     *
 *     * of the United States of America may require an export license.    *
 *     *********************************************************************
 */

#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/database/DBtech.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
#endif  /* not lint */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "utils/magic.h"
#include "utils/geometry.h"
#include "utils/utils.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"
#include "database/databaseInt.h"
#include "utils/tech.h"
#include "textio/textio.h"
#include "utils/malloc.h"

/* Name of this technology */
char *DBTechName = 0;
char *DBTechVersion = 0;
char *DBTechDescription = 0;

/* Connectivity */
TileTypeBitMask	 DBConnectTbl[NT];
TileTypeBitMask	 DBNotConnectTbl[NT];
PlaneMask	 DBConnPlanes[NT];
PlaneMask	 DBAllConnPlanes[NT];

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechInit --
 *
 * Clear technology description information for database module.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 * ----------------------------------------------------------------------------
 */

void
DBTechInit()
{
    /* StrDup() takes care of reallocating DBTechName */

    /* TECH_FORMAT_VERSION is defined in utils/tech.h,	*/
    /* and should be 27, the last version to be		*/
    /* included as part of the tech filename suffix.	*/

    TechFormatVersion = TECH_FORMAT_VERSION;

    /* Initialization of bezier coefficients for font vectors */
    DBFontInitCurves();
}


/*
 * ----------------------------------------------------------------------------
 *
 * DBTechSetTech --
 *
 * Set the name for the technology.
 *
 * Results:
 *	Returns FALSE if there were an improper number of
 *	tokens on the line.
 *
 * Side effects:
 *	Sets DBTechName to the name of the technology.
 *
 * ----------------------------------------------------------------------------
 */

    /*ARGSUSED*/
bool
DBTechSetTech(sectionName, argc, argv)
    char *sectionName;
    int argc;
    char *argv[];
{
    if (argc != 1)
    {
	if (argc == 2)
	{
	    if (strncmp(argv[0], "format", 6) == 0 ||
			strncmp(argv[0], "version", 7) == 0)
	    {
		if (StrIsInt(argv[1]))
		{
		    TechFormatVersion = atoi(argv[1]);
		    return TRUE;
		}
		else
		{
		    TechError("Bad format version number. . . assuming %d\n",
				TECH_FORMAT_VERSION);
		    return TRUE;
		}
	    }
	}
	TechError("Badly formed technology name\n");
	return FALSE;
    }
    (void) StrDup(&DBTechName, argv[0]);
    return TRUE;
}

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechInitVersion --
 *
 *	Clean up memory allocated by the "version" section
 *
 * ----------------------------------------------------------------------------
 */

void
DBTechInitVersion()
{
    /* StrDup() takes care of reallocating DBTechVersion and	*/
    /* DBTechDescription.					*/
}

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechSetVersion --
 *
 * Set the version number & description for the technology.
 *
 * Results:
 *	Returns FALSE if there were an improper number of
 *	tokens on the line.
 *
 * Side effects:
 *	Sets DBTechVersion and DBTechDescription.
 *
 * ----------------------------------------------------------------------------
 */

    /*ARGSUSED*/
bool
DBTechSetVersion(sectionName, argc, argv)
    char *sectionName;
    int argc;
    char *argv[];
{
    char *contline;
    int n, slen;

    if (argc < 2) goto usage;
    if (strcmp(argv[0], "version") == 0)
    {
	(void) StrDup(&DBTechVersion, argv[1]);
	for (n = 2; n < argc; n++)
	{
	    slen = strlen(DBTechVersion);
	    contline = mallocMagic(strlen(argv[n]) + slen + 1);
	    sprintf(contline, "%s\n%s", DBTechVersion, argv[n]);
	    freeMagic(DBTechVersion);
	    DBTechVersion = contline;
	}
	return TRUE;
    }
    if (strcmp(argv[0], "description") == 0)
    {
	(void) StrDup(&DBTechDescription, argv[1]);
	for (n = 2; n < argc; n++)
	{
	    slen = strlen(DBTechDescription);
	    contline = mallocMagic(strlen(argv[n]) + slen + 1);
	    sprintf(contline, "%s\n%s", DBTechDescription, argv[n]);
	    freeMagic(DBTechDescription);
	    DBTechDescription = contline;
	}
	return TRUE;
    }
    if (strcmp(argv[0], "requires") == 0)
    {
	/* Version requirement check.  If the techfile has "requires" followed
	 * by a magic version number in the form [magic-]<major>.<minor>.<revision>,
	 * then the version of magic is checked against this, and the tech
	 * loading will fail if there is a version incompatibility.
	 */

	int major, minor, rev;
	int rmajor, rminor, rrev;
	bool goodversion = FALSE;
	char *vstring;

	vstring = argv[1];
	while ((*vstring != '\0') && !isdigit(*vstring)) vstring++;

	major = minor = rev = 0;
	rmajor = rminor = rrev = 0;
	
	if (sscanf(vstring, "%d.%d.%d", &rmajor, &rminor, &rrev) == 0)
	{
	    TechError("Badly formed magic version string, should be major.minor.rev\n");
	    return FALSE;
	}
	sscanf(MagicVersion, "%d.%d", &major, &minor);
	sscanf(MagicRevision, "%d", &rev);
	if (major > rmajor)
	    goodversion = TRUE;
	else if (major == rmajor)
	{
	    if (minor > rminor)
		goodversion = TRUE;
	    else if (minor == rminor)
	    {
		if (rev >= rrev)
		    goodversion = TRUE;
	    }
	}
	if (goodversion == FALSE)
	{
	    TechError("Error:  Magic version %d.%d.%d is required by this "
		    "techfile, but this version of magic is %d.%d.%d.\n",
		    rmajor, rminor, rrev, major, minor, rev);
	    return FALSE;
	}
	return TRUE;
    }

usage:
    TechError("Badly formed version line\n"
	    "Usage: {version text}|{description text}|{requires text}\n");
    return FALSE;
}

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechInitConnect --
 *
 * Initialize the connectivity tables.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Initializes DBConnectTbl[], DBConnPlanes[], and DBAllConnPlanes[].
 *
 * ----------------------------------------------------------------------------
 */

void
DBTechInitConnect()
{
    int i;

    for (i = 0; i < TT_MAXTYPES; i++)
    {
	TTMaskSetOnlyType(&DBConnectTbl[i], i);
	DBConnPlanes[i] = 0;
	DBAllConnPlanes[i] = 0;
    }
}

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechAddConnect --
 *
 * Add connectivity information.
 * Record the fact that material of the types in the comma-separated
 * list types1 connects to material of the types in the list types2.
 *
 * Results:
 *	TRUE if successful, FALSE on error
 *
 * Side effects:
 *	Updates DBConnectTbl[].
 *
 * ----------------------------------------------------------------------------
 */

    /*ARGSUSED*/
bool
DBTechAddConnect(sectionName, argc, argv)
    char *sectionName;
    int argc;
    char *argv[];
{
    TileTypeBitMask types1, types2;
    TileType t1, t2;

    if (argc != 2)
    {
	TechError("Line must contain exactly 2 lists of types\n");
	return FALSE;
    }

    DBTechNoisyNameMask(argv[0], &types1);
    DBTechNoisyNameMask(argv[1], &types2);
    for (t1 = 0; t1 < DBNumTypes; t1++)
	if (TTMaskHasType(&types1, t1))
	    for (t2 = 0; t2 < DBNumTypes; t2++)
		if (TTMaskHasType(&types2, t2))
		{
		    TTMaskSetType(&DBConnectTbl[t1], t2);
		    TTMaskSetType(&DBConnectTbl[t2], t1);
		}


    return TRUE;
}

/*
 * ----------------------------------------------------------------------------
 *
 * DBTechFinalConnect --
 *
 * Postprocessing for the connectivity information.
 * Modify DBConnectTbl[] so that:
 *
 *	(1) Any type connecting to one of the images of a contact
 *	    connects to all images of the contact.
 *	(2) Each image of a contact connects to the union of what
 *	    all the images connect to.
 *
 * Modify DBConnPlanes[] so that only types belonging to a contact
 * appear to connect to any plane other than their own.
 *
 * Constructs DBAllConnPlanes, which will be non-zero for those planes
 * to which each type connects, exclusive of that type's home plane and
 * those planes to which it connects as a contact.
 *
 * Create DBNotConnectTbl[], the complement of DBConnectTbl[].
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Modifies DBConnPlanes[], DBAllConnPlanes[], and DBConnectTbl[]
 *	as above.
 *
 * ----------------------------------------------------------------------------
 */

void
DBTechFinalConnect()
{
    /* TileTypeBitMask saveConnect[TT_MAXTYPES]; */
    TileTypeBitMask *cMask, *rMask;
    TileType base, s;
    LayerInfo *lp, *ls;
    int n;

    for (s = 0; s < DBNumTypes; s++)
	DBConnPlanes[s] = 0;

    /*
     * Each stacked contact type must necessarily connect to its
     * residual contact types, and the connecting types of those
     * contacts.  Each stacked contact type also connects to
     * other contact types that share (first) residues.
     */
    for (base = DBNumUserLayers; base < DBNumTypes; base++)
    {
	TileTypeBitMask *smask, *rmask = DBResidueMask(base), cmask;
	TTMaskSetMask(&DBConnectTbl[base], rmask);
	for (s = TT_TECHDEPBASE; s < DBNumUserLayers; s++)
	    if (TTMaskHasType(rmask, s))
		TTMaskSetMask(&DBConnectTbl[base], &DBConnectTbl[s]);

	/* Only need to start above "base";  the mirror-image	*/
	/* connection is ensured by the code below.		*/

	for (s = base + 1; s < DBNumTypes; s++)
	{
	    smask = DBResidueMask(s);
	    TTMaskAndMask3(&cmask, smask, rmask);
	    if (!TTMaskIsZero(&cmask))
		TTMaskSetType(&DBConnectTbl[base], s);
	}
    }

    /* Make the connectivity matrix symmetric */
    for (base = TT_TECHDEPBASE; base < DBNumTypes; base++)
	for (s = TT_TECHDEPBASE; s < DBNumTypes; s++)
	    if (TTMaskHasType(&DBConnectTbl[base], s))
		TTMaskSetType(&DBConnectTbl[s], base);

    /* Construct DBNotConnectTbl[] */
    /* For purposes of connectivity searching, this is not exactly the	*/
    /* complement of DBConnectTbl[].  For non-contact layers, it is.	*/
    /* For contact images, we compute differently to account for	*/
    /* contacts being stacked by having different parts in different	*/
    /* cells, which requires a different mask.				*/

    for (base = 0; base < TT_MAXTYPES; base++)
	TTMaskCom2(&DBNotConnectTbl[base], &DBConnectTbl[base]);

    for (n = 0; n < dbNumContacts; n++)
    {
	lp = dbContactInfo[n];
	TTMaskSetOnlyType(&DBNotConnectTbl[lp->l_type], lp->l_type);
	rMask = DBResidueMask(lp->l_type);

	/* Different contact types may share residues.		*/
	/* Use TTMaskIntersect(), not TTMaskEqual()---types	*/
	/* which otherwise stack may be in separate cells.	*/

	for (s = 0; s < dbNumContacts; s++)
	{
	    ls = dbContactInfo[s];
	    cMask = DBResidueMask(ls->l_type);
	    if (TTMaskIntersect(rMask, cMask))
		TTMaskSetType(&DBNotConnectTbl[lp->l_type], ls->l_type);
	}

	/* The mask of contact types must include all stacked contacts */

	for (base = DBNumUserLayers; base < DBNumTypes; base++)
	{
	    cMask = DBResidueMask(base);
	    if (TTMaskHasType(cMask, lp->l_type))
		TTMaskSetType(&DBNotConnectTbl[lp->l_type], base);
	}

	/* Note that everything above counted for all the	*/
	/* connecting types.  Invert this to get non-connecting	*/
	/* types.						*/

	TTMaskCom(&DBNotConnectTbl[lp->l_type]);
    }

    /*
     * DBConnPlanes[] is nonzero only for contact images, for which
     * it shows the planes connected to an image.  It is the
     * responsibility of the routine examining this value to exclude
     * the plane being searched, if necessary.
     */
    for (n = 0; n < dbNumContacts; n++)
    {
	lp = dbContactInfo[n];
	DBConnPlanes[lp->l_type] = lp->l_pmask;
    }

    /*
     * Now finally construct DBAllConnPlanes, which will be non-zero
     * for those planes to which each type 'base' connects, exclusive
     * of its home plane and those planes to which it connects as a
     * contact.
     *
     * Note that DBAllConnPlanes() is used to check for connectivity
     * (e.g., during extraction) where connections are made where no
     * contact exists.  This is VERY compute-intensive, so adding
     * planes unnecessarily must be avoided at all costs.  Consider
     * that a better alternative might be to designate layers that
     * connect to other planes as contacts themselves (such as
     * nsd, which connects to nwell) and restrict the "connect" section
     * to types in a plane (such as poly and transistor).
     */

    for (base = TT_TECHDEPBASE; base < DBNumTypes; base++)
    {
	TileTypeBitMask baseConnList;

	/* For one, remove all contact types from the list of	*/
	/* connecting types.  Otherwise, simple connect		*/
	/* expressions like "*m1 *m1" have the unintended	*/
	/* consequence of connecting the metal2 plane (because	*/
	/* via contains m1) to the active plane (because active	*/
	/* contacts also contain m1).				*/

	baseConnList = DBConnectTbl[base];
	for (s = 0; s < dbNumContacts; s++)
	{
	    ls = dbContactInfo[s];
	    TTMaskClearType(&baseConnList, ls->l_type);
	}

	DBAllConnPlanes[base] = DBTechTypesToPlanes(&baseConnList);
	DBAllConnPlanes[base] &= ~(PlaneNumToMaskBit(DBPlane(base)));
	DBAllConnPlanes[base] &= ~DBConnPlanes[base];
    }
}