1#!/usr/bin/nawk -f
2# awk script to replace sim2spice!
3# Drew Wingard   June, 1988
4# modified by Peter Lim and Stefanos Sidiropoulos
5#
6#  The awk script allows spice simulation of layout from Stanford BiCMOS
7#  Technology. To use this awk script,
8#     1. generate a <block>.ext file from magic using ":ext"
9#     2. run ext2sim to generate <block>.sim file
10#     3. use sim2spi <block>.sim > <block>.spi to generate a spice deck.
11#     4. edit the generate spice deck as needed
12#
13# In order to recognize bipolars the ext2simBiCMOS program should be used
14# (this is no longer true --- Tim 10/10/97
15# (modified by Tim Edwards for bipolar handling w/magic 6.5.1)
16#
17# Areas and perimeters are calculated if the right ext2sim version is used
18BEGIN{
19	trimSubs = 1;
20	cnum = 1 ; bnum = 1 ; num = 1 ;
21	rnum = 1 ; xnum = 1; lumpResnum = 1 ;
22	print "* Extracted spice deck"  ;
23	print "* for su-bicmos you should get the .sim file using ext2simBiCMOS"
24	units = 1.0 ; # in microns
25}
26$1 == "|" 	{
27		   if ( $2 == "units:" ) units = $3 / 100 ;
28		   printf "* Units: %f, Technology: %s\n", units, $5;
29		}
30$1 ~ /^\|$/	{ scale = 1  }
31$1 ~ /^[Cc]$/	{ print "C"cnum , $2 , $3 , $4"fF" ; cnum = cnum + 1}
32$1 ~ /^p$/	{
33		  subs = "Vdd"
34		  if ( NF > 8 ) {
35			n = split($9, arr, "[=,]" );
36			subs = substr(arr[n],3,length(arr[n]));
37			if ( trimSubs ) {
38				l = length(subs);
39				if ( substr(subs,l,1) == "!" )
40					subs = substr(subs,1,l-1);
41			}
42		  	n = split($10, arr, "[=_,]");
43			ps = arr[n];
44			as = arr[n-2];
45		  	n = split($11, arr, "[=_,]");
46			pd = arr[n];
47			ad = arr[n-2];
48		  }
49		  print "M"num , $4 , $2 , $3 , subs, " PMOS W=" $6*units \
50		  "U L=" $5*units "U "
51		  print "+ AD=" ad*units*units"P PD=" pd*units"U"\
52		         " AS=" as*units*units"P PS=" ps*units"U"
53		  num = num + 1}
54$1 ~ /^w$/	{
55		printf "Xcap%d %s %s wcap w=%fu l=%fu\n", xnum, $2, $3, \
56			$5*units,  $6*units;
57		xnum = xnum + 1;
58		}
59$1 ~ /^n$/	{
60		  subs = "Gnd"
61		  if ( NF > 8 ) {
62			n = split($9, arr, "[=,]" );
63			subs = substr(arr[n],3,length(arr[n]));
64			if ( trimSubs ) {
65				l = length(subs);
66				if ( substr(subs,l,1) == "!" )
67					subs = substr(subs,1,l-1);
68			}
69		  	n = split($10, arr, "[=_,]");
70			ps = arr[n];
71			as = arr[n-2];
72		  	n = split($11, arr, "[=_,]");
73			pd = arr[n];
74			ad = arr[n-2];
75		  }
76		  print "M"num , $4 , $2 , $3 , subs, " NMOS W=" $6*units \
77		        "U L=" $5*units "U "
78		  print "+ AD=" ad*units*units"P PD=" pd*units"U"\
79		         " AS=" as*units*units"P PS=" ps*units"U"
80		  num = num + 1}
81
82$1 ~ /^b$/	{ print "Q"bnum , $3 , $4 , $2 " npn"
83		  bnum = bnum + 1}
84$1 ~ /^q$/	{ print "Q"bnum , $4 , $2 , $3 " 0 b1.6 " $6 - 1.6
85		  bnum = bnum + 1}
86$1 ~ /^r$/      { print "r"rnum , $2 , $3 , $4
87		  rnum = rnum + 1}
88$1 ~ /^R$/      { printf "ERROR: %s (lumped resistor not supported)\n", $0; }
89