Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / yagle / genius / gen_globals.c
1 #include AVT_H
2 #include GEN_H
3
4 chain_list *ALL_LOINS;
5 chain_list *ALL_LOTRS;
6 chain_list *ALL_HIERARCHY_LOTRS;
7 chain_list *ALL_SWAPS;
8 lofig_list *current_lofig;
9 ptype_list *ALL_ENV, *GEN_USER;
10 lofig_list *CUR_HIER_LOFIG;
11 corresp_t *CUR_CORRESP_TABLE;
12 ALL_FOR_GNS *LATEST_GNS_RUN;
13 lofig_list *GENIUS_GLOBAL_LOFIG;
14 ht *GNS_TEMPLATE_HT;
15 lofig_list *GEN_HEAD_LOFIG = NULL;
16 ht *GEN_HT_LOFIG = NULL;
17
18 chain_list *reject_list;
19
20 static mbkContext *EXTERNAL_LOFIGS;
21
22 lofig_list *(*external_getlofig)(char *name);
23
24 mbkContext *genius_external_getcontext()
25 {
26 return EXTERNAL_LOFIGS;
27 }
28
29 void genius_external_setcontext(mbkContext *ctx)
30 {
31 EXTERNAL_LOFIGS=ctx;
32 }
33
34 lofig_list *genius_external_getlofig(char *name)
35 {
36 lofig_list *lf;
37 mbkSwitchContext(EXTERNAL_LOFIGS);
38 lf=getlofig(name, 'A');
39 mbkSwitchContext(EXTERNAL_LOFIGS);
40 return lf;
41 }
42
43 typedef struct
44 {
45 ht *oHT;
46 lofig_list *oHL;
47 corresp_t *oCT;
48 lofig_list *oCHL;
49 lofig_list *oMAINLF;
50 ptype_list *var;
51 mbkContext *oldctx;
52 mbkContext newcontext;
53 lofig_list *(*tmpfunc)(char *name);
54 ht *templateht;
55 } __ctx;
56
57 static chain_list *__ctx_chain=NULL;
58
59
60 lofig_list *gen_getlofig (char *name)
61 {
62 lofig_list *head_lofig, *fig;
63 ht *ht_lofig;
64
65 // Contextualize HEAD_LOFIG ___________________________
66
67 head_lofig = HEAD_LOFIG;
68 HEAD_LOFIG = GEN_HEAD_LOFIG;
69
70 ht_lofig = HT_LOFIG;
71 HT_LOFIG = GEN_HT_LOFIG;
72
73 fig = getloadedlofig (name);
74
75 // Release HEAD_LOFIG _________________________________
76
77 GEN_HEAD_LOFIG = HEAD_LOFIG;
78 HEAD_LOFIG = head_lofig;
79
80 GEN_HT_LOFIG = HT_LOFIG;
81 HT_LOFIG = ht_lofig;
82
83 return fig;
84 }
85
86 void in_genius_context_of(ALL_FOR_GNS *all, subinst_t *sins)
87 {
88 ptype_list *var;
89 corresp_t *table;
90 char temp[1024];
91 __ctx *tmp;
92
93
94 tmp=(__ctx *)mbkalloc(sizeof(__ctx));
95 tmp->oHT=GEN_HT_LOFIG; tmp->oHL=GEN_HEAD_LOFIG;
96 tmp->oCHL=CUR_HIER_LOFIG; tmp->oCT=CUR_CORRESP_TABLE;
97 tmp->oMAINLF=GENIUS_GLOBAL_LOFIG; tmp->var=ALL_ENV;
98 tmp->oldctx=genius_external_getcontext();
99 tmp->newcontext.HT_LOFIG=HT_LOFIG;
100 tmp->newcontext.HEAD_LOFIG=HEAD_LOFIG;
101 tmp->tmpfunc=external_getlofig;
102 tmp->templateht=GNS_TEMPLATE_HT;
103
104 external_getlofig=genius_external_getlofig;
105 genius_external_setcontext(&all->external_ctx);
106
107 __ctx_chain=addchain(__ctx_chain, tmp);
108
109 table=sins->CRT;
110 var=table->VAR;
111 var=addptype(var, (long)table->GENIUS_FIGNAME, namealloc("model"));
112 var=addptype(var, (long)table->GENIUS_INSNAME, namealloc("instance"));
113
114 if (table->ARCHISTART==0)
115 var=addptype(var, (long)table->FIGNAME, namealloc("archi"));
116 else
117 {
118 strncpy(temp, &table->GENIUS_FIGNAME[(int)table->ARCHISTART], table->ARCHILENGTH);
119 temp[(int)table->ARCHILENGTH]='\0';
120 var=addptype(var, (long)namealloc(temp), namealloc("archi"));
121 }
122
123 GENIUS_GLOBAL_LOFIG=all->GLOBAL_LOFIG;
124 GEN_HEAD_LOFIG = all->HIER_HEAD_LOFIG;
125 GEN_HT_LOFIG = all->HIER_HT_LOFIG;
126 CUR_HIER_LOFIG=gen_getlofig(table->GENIUS_FIGNAME);
127 CUR_CORRESP_TABLE=table;
128 GEN_USER=NULL;
129 ALL_ENV=var;
130 GNS_TEMPLATE_HT=all->TEMPLATE_HT;
131 current_lofig=NULL;
132 }
133
134 void out_genius_context_of()
135 {
136 __ctx *tmp;
137 chain_list *cl;
138 if (__ctx_chain==NULL) return;
139
140 tmp=(__ctx *)__ctx_chain->DATA;
141 ALL_ENV->NEXT->NEXT->NEXT=NULL;
142 freeptype(ALL_ENV);
143 external_getlofig=tmp->tmpfunc;
144 genius_external_setcontext(tmp->oldctx);
145 GEN_HT_LOFIG=tmp->oHT; GEN_HEAD_LOFIG=tmp->oHL;
146 CUR_HIER_LOFIG=tmp->oCHL; CUR_CORRESP_TABLE=tmp->oCT;
147 GENIUS_GLOBAL_LOFIG=tmp->oMAINLF; ALL_ENV=tmp->var;
148 GNS_TEMPLATE_HT=tmp->templateht;
149 mbkfree(tmp);
150 cl=__ctx_chain; __ctx_chain=__ctx_chain->NEXT;
151 cl->NEXT=NULL;
152 freechain(cl);
153 }
154
155 char *gen_makeinstancename (char *s)
156 {
157 int i, j;
158 static char temp[200];
159
160 for (i = 0, j = 0; s[i] != '\0'; i++) {
161 if (s[i] != ' ' && s[i] != ')' && s[i] != ']')
162 temp[j++] = s[i];
163 }
164 temp[j] = '\0';
165
166 for (i = 0; i < j; i++)
167 if (temp[i] == '[' || temp[i] == '(')
168 temp[i] = '_';
169
170 return temp;
171 }
172
173 chain_list *gen_hierarchical_split (char *name)
174 {
175 char *s, *start = name;
176 chain_list *cl = NULL;
177
178 s = strchr (start, '.');
179
180 while (s) {
181 *s = '\0';
182 cl = addchain (cl, namealloc (start));
183 *s = '.';
184 start = s + 1;
185 s = strchr (start, '.');
186 }
187 cl = addchain (cl, namealloc (start));
188
189 return reverse (cl);
190 }
191 chain_list *gen_goto (chain_list * arbo, corresp_t ** crt, int tag)
192 {
193 corresp_t *crt0, *level;
194 subinst_t *cl;
195 level = *crt;
196 while (arbo->NEXT != NULL) {
197 for (cl = level->SUBINSTS; cl != NULL; cl = cl->NEXT) {
198 crt0 = cl->CRT;
199 if (cl->INSNAME == arbo->DATA)
200 break;
201 }
202 if (cl == NULL || (cl->FLAGS & LOINS_IS_BLACKBOX)!=0)
203 {
204 if (tag==0)
205 return NULL;
206 return arbo;
207 }
208 arbo = arbo->NEXT;
209 level = crt0;
210 }
211 *crt = level;
212 return arbo;
213 }
214
215 static char *repack(chain_list *lst, char *buf)
216 {
217 strcpy(buf,"");
218 while (lst!=NULL)
219 {
220 strcat(buf, lst->DATA);
221 if (lst->NEXT!=NULL)
222 strcat(buf, ".");
223 lst=lst->NEXT;
224 }
225 return buf;
226 }
227
228 lotrs_list *_gen_GetCorrespondingTransistor(char *name, corresp_t * level, int mode)
229 {
230 chain_list *arbo, *mainarbo;
231 long entry;
232 char *trname;
233 char buf[200];
234
235 mainarbo = arbo = gen_hierarchical_split (gen_makeinstancename (name));
236
237 arbo = gen_goto (arbo, &level, 1);
238 if (arbo == NULL) {
239 freechain (mainarbo);
240 if (!mode) avt_errmsg(GNS_ERRMSG, "036", AVT_ERROR, gen_info (), name);
241 //fprintf (stderr, "%s: gns_GetCorrespondingTransistor() can't go thru '%s'\n", gen_info (), name);
242 return NULL;
243 }
244
245 if (level->TRANSISTORS!=NULL)
246 {
247 if (arbo->NEXT==NULL) trname=arbo->DATA;
248 else trname=namealloc(repack(arbo, buf));
249
250 entry=gethtitem(level->TRANSISTORS, trname);
251
252 freechain (mainarbo);
253 if (entry!=EMPTYHT) return (lotrs_list *)entry;
254 }
255 if (!mode) avt_errmsg(GNS_ERRMSG, "006", AVT_ERROR, gen_info (), name);
256 //fprintf (stderr, "%s: gns_GetCorrespondingTransistor() can't find transistor '%s' in model\n", gen_info (), name);
257 return NULL;
258 }
259
260 lotrs_list *gen_GetCorrespondingTransistor(char *name, corresp_t * level)
261 {
262 return _gen_GetCorrespondingTransistor(name, level, 0); // display errors
263 }
264
265 subinst_t *gen_GetCorrespondingInstance (char *name, corresp_t * level)
266 {
267 subinst_t *cl;
268 corresp_t *crt;
269 chain_list *arbo, *mainarbo;
270 char buf[200];
271 char *insname;
272
273 mainarbo = arbo = gen_hierarchical_split (gen_makeinstancename (name));
274
275 arbo = gen_goto (arbo, &level, 1);
276 if (arbo == NULL) {
277 freechain (mainarbo);
278 avt_errmsg(GNS_ERRMSG, "036", AVT_FATAL, gen_info (), name);
279 //fprintf (stderr, "%s: gns_GetCorrespondingInstance() can't go thru '%s'\n", gen_info (), name);
280 EXIT (1);
281 }
282
283 if (arbo->NEXT==NULL) insname=arbo->DATA;
284 else insname=namealloc(repack(arbo, buf));
285
286 for (cl = level->SUBINSTS; cl != NULL; cl = cl->NEXT) {
287 crt = cl->CRT;
288 if (cl->INSNAME == insname) {
289 freechain (mainarbo);
290 return cl;
291 }
292 }
293 freechain (mainarbo);
294 avt_errmsg(GNS_ERRMSG, "037", AVT_ERROR, gen_info (), name);
295 //fprintf (stderr, "%s: gns_GetCorrespondingInstance() can't find instance '%s' in model\n", gen_info (), name);
296 return NULL;
297 }
298
299 subinst_t *gen_get_hier_instance(ALL_FOR_GNS *all, char *hiername)
300 {
301 char temp[1024], *c, *nm;
302 subinst_t *sins;
303 strcpy(temp, hiername);
304 c=strchr(temp,'.');
305 if (c!=NULL)
306 {
307 *c='\0';
308 }
309 nm=namealloc(temp);
310 for (sins=all->TOP_LEVEL_SUBINST; sins!=NULL && sins->INSNAME!=nm; sins=sins->NEXT) ;
311 if (c==NULL || sins==NULL) return sins;
312 return gen_GetCorrespondingInstance(&c[1], sins->CRT);
313 }
314
315 int is_genius_instance(lofig_list *lf, char *name)
316 {
317 if (LATEST_GNS_RUN==NULL) return 0;
318 if (LATEST_GNS_RUN->GLOBAL_LOFIG!=lf) return 0;
319 if (gen_get_hier_instance(LATEST_GNS_RUN, name)!=NULL) return 1;
320 return 0;
321 }
322
323 HierLofigInfo *gethierlofiginfo(lofig_list *lf)
324 {
325 ptype_list *p;
326 HierLofigInfo *hli;
327
328 if ((p=getptype(lf->USER, HIER_LOFIG_INFO_PTYPE))!=NULL)
329 return (HierLofigInfo *)p->DATA;
330
331 hli=(HierLofigInfo *)mbkalloc(sizeof(HierLofigInfo));
332 hli->BUILD_TTV=NULL;
333 hli->BUILD_BEH=NULL;
334 hli->ARCS=addht(16);
335 lf->USER=addptype(lf->USER, HIER_LOFIG_INFO_PTYPE, hli);
336 return hli;
337 }
338
339 ArcInfo *getarcinfo(HierLofigInfo *hli, char *name)
340 {
341 long l;
342 ArcInfo *ai;
343 if ((l=gethtitem(hli->ARCS, name))!=EMPTYHT)
344 return (ArcInfo *)l;
345
346 ai=(ArcInfo *)mbkalloc(sizeof(ArcInfo));
347 ai->arc_name=name;
348 ai->MODEL=NULL;
349 ai->SIM=NULL;
350 ai->ENV=NULL;
351 ai->CTK_ENV=NULL;
352 addhtitem(hli->ARCS, name, (long)ai);
353 return ai;
354 }
355
356 ht *gen_get_losig_ht(lofig_list *lf)
357 {
358 ht *sight;
359 ptype_list *pt;
360 losig_list *ls;
361
362 if ((pt=getptype(lf->USER, GEN_HIERLOFIG_LOSIG_HT))!=NULL)
363 return (ht *)pt->DATA;
364
365 sight=addht(1024);
366
367 for (ls=lf->LOSIG; ls!=NULL; ls=ls->NEXT)
368 addhtitem(sight, ls->NAMECHAIN->DATA, (long)ls);
369
370 lf->USER=addptype(lf->USER, GEN_HIERLOFIG_LOSIG_HT, sight);
371
372 return sight;
373 }
374
375 void destroy_genius_context(ALL_FOR_GNS *all)
376 {
377 /* ptype_list *var;
378 corresp_t *table;
379 char temp[1024];
380 __ctx *tmp;
381
382
383 tmp=(__ctx *)mbkalloc(sizeof(__ctx));
384 tmp->oHT=GEN_HT_LOFIG; tmp->oHL=GEN_HEAD_LOFIG;
385 tmp->oCHL=CUR_HIER_LOFIG; tmp->oCT=CUR_CORRESP_TABLE;
386 tmp->oMAINLF=GENIUS_GLOBAL_LOFIG; tmp->var=ALL_ENV;
387 tmp->oldctx=genius_external_getcontext();
388 tmp->newcontext.HT_LOFIG=HT_LOFIG;
389 tmp->newcontext.HEAD_LOFIG=HEAD_LOFIG;
390 tmp->tmpfunc=external_getlofig;
391 tmp->templateht=GNS_TEMPLATE_HT;
392
393 external_getlofig=genius_external_getlofig;
394 genius_external_setcontext(&tmp->newcontext);
395
396 __ctx_chain=addchain(__ctx_chain, tmp);
397
398 table=sins->CRT;
399 var=table->VAR;
400 var=addptype(var, (long)table->GENIUS_FIGNAME, namealloc("model"));
401 var=addptype(var, (long)table->GENIUS_INSNAME, namealloc("instance"));
402
403 if (table->ARCHISTART==0)
404 var=addptype(var, (long)table->FIGNAME, namealloc("archi"));
405 else
406 {
407 strncpy(temp, &table->GENIUS_FIGNAME[(int)table->ARCHISTART], table->ARCHILENGTH);
408 temp[(int)table->ARCHILENGTH]='\0';
409 var=addptype(var, (long)namealloc(temp), namealloc("archi"));
410 }
411
412 GENIUS_GLOBAL_LOFIG=all->GLOBAL_LOFIG;
413 GEN_HEAD_LOFIG = all->HIER_HEAD_LOFIG;
414 GEN_HT_LOFIG = all->HIER_HT_LOFIG;
415 CUR_HIER_LOFIG=gen_getlofig(table->GENIUS_FIGNAME);
416 CUR_CORRESP_TABLE=table;
417 GEN_USER=NULL;
418 ALL_ENV=var;
419 GNS_TEMPLATE_HT=all->TEMPLATE_HT;
420 current_lofig=NULL;
421 // le external aussi
422 */
423
424 all = NULL;
425 }
426