1 /* subckt_translator.c : quick hack to enable subckt files to work in standard "magic" characterization flow
9 #include "makeutils.lib/debug.h"
10 #include "parsers.lib/scanner.h"
11 #include "netlist.lib/netlist_spice.h"
25 int is_power(char *name
)
27 if(strcasecmp(name
,"vdd")==0) return 1;
31 int is_ground(char *name
)
33 if(strcasecmp(name
,"gnd")==0) return 1;
34 if(strcasecmp(name
,"vss")==0) return 1;
38 int is_input(char *name
)
42 if(tolower(name
[0])<='f') return 1;
46 int is_output(char *name
)
63 void dumprest(FILE *fp
, card_t
*cp
)
65 for(;cp
!=NULL
;cp
=cp
->next
)
66 { /* just dump the rest verbatim */
67 fprintf(fp
," %s",cp
->str
);
68 if(cp
->val
!=NULL
) fprintf(fp
,"=%s",cp
->val
);
72 void generate_stuff(spice_t
*spice
, FILE *fp_pins
, FILE *fp_flat
)
74 subckt_t
*ckt
,**cktpp
;
80 subckts
=spice_list_subckt(spice
->ckt
);
81 list_iterate(&subckts
,i
,cktpp
)
85 fprintf(fp_pins
,"\n\n");
86 fprintf(fp_pins
,"cell: c%i %s\n",i
,ckt
->name
);
87 fprintf(fp_pins
,"area: %i\n",ckt
->nm
); /* estimate area by transitor count */
88 for(j
=0;j
<ckt
->ndefn
;j
++)
94 fprintf(fp_pins
,"input: %s\n",nn
);
96 else if(is_output(nn
))
98 fprintf(fp_pins
,"out: %s\n",nn
);
100 else if(is_power(nn
))
102 fprintf(fp_pins
,"vdd: %s\n", nn
);
104 else if(is_ground(nn
))
106 fprintf(fp_pins
,"vss: %s\n", nn
);
108 else fprintf(fp_pins
,"#error pin %s\n",nn
);
113 fprintf(fp_flat
,"\n\n*\n*\n* subckt %s \n\n",ckt
->name
);
114 for(j
=0;j
<ckt
->nm
;j
++)
116 fprintf(fp_flat
,"M%i c%i_%s c%i_%s c%i_%s c%i_%s ",
117 uniq
++,i
,node(ckt
->m
[j
].nodes
[0]),i
,node(ckt
->m
[j
].nodes
[1]),
118 i
,node(ckt
->m
[j
].nodes
[2]),i
,node(ckt
->m
[j
].nodes
[3]));
120 dumprest(fp_flat
,ckt
->m
[j
].rest
);
121 fprintf(fp_flat
,"\n");
122 /* fprintf(fp_flat," l=%g w=%lf pd=%lf ps=%lf ad=%lf as=%lf \n", */
124 for(j
=0;j
<ckt
->nc
;j
++)
126 fprintf(fp_flat
,"C%i c%i_%s c%i_%s ",
127 uniq
++,i
,node(ckt
->c
[j
].nodes
[0]),i
,node(ckt
->c
[j
].nodes
[1]));
128 dumprest(fp_flat
,ckt
->c
[j
].rest
);
129 fprintf(fp_flat
,"\n");
132 for(j
=0;j
<ckt
->nr
;j
++)
134 fprintf(fp_flat
,"R%i c%i_%s c%i_%s ",
135 uniq
++,i
,node(ckt
->r
[j
].nodes
[0]),i
,node(ckt
->r
[j
].nodes
[1]));
136 dumprest(fp_flat
,ckt
->r
[j
].rest
);
137 fprintf(fp_flat
,"\n");
147 int main(int argc
, char **argv
)
149 char *subckt_filename
=NULL
;
150 char *pins_output
=NULL
;
151 char *flat_spice
=NULL
;
154 FILE *fp
,*fp_pins
,*fp_flat
;
160 char *arg
=(i
<argc
)?(argv
[i
+1]):NULL
;
166 { subckt_filename
=arg
; i
++; continue; }
170 { pins_output
=arg
; i
++; continue; }
174 { flat_spice
=arg
; i
++; continue; }
177 fprintf(stderr
,"Invalid command line option %s %s, skipping\n",cmd
,arg
);
179 if((subckt_filename
==NULL
))
181 fprintf(stderr
,"Usage: translator -i input_subckt_file"
182 " -o output_flat_file -p output_pins_file\n");
188 fp
=fopen(subckt_filename
,"rt");
189 scanner_input_newfp(&scan
,fp
);
190 spice
=spice_new(&scan
);
192 if(pins_output
!=NULL
)
193 fp_pins
=fopen(pins_output
,"w");
197 fp_flat
=fopen(flat_spice
,"w");
201 generate_stuff(spice
,fp_pins
,fp_flat
);
202 if(fp_pins
!=NULL
)fclose(fp_pins
);
203 if(fp_flat
!=NULL
)fclose(fp_flat
);