Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / api / genius / gen_API.c
1 #include <stdarg.h>
2
3 #include AVT_H
4 #include GEN_H
5 #include MSL_H
6 #define API_USE_REAL_TYPES
7 #include "gen_API_netlist.h"
8 #include "gen_API.h"
9
10 static mbkContext gen_api_ctx[32];
11 /*lofig_list *gen_api_head_lofig;
12 ht *gen_api_ht_lofig;*/
13 static int recur=0;
14
15 void gen_API_Action_Initialize ()// commentaire pour desactiver l'ajout de token
16 {
17 char *str;
18
19 // Contextualize HEAD_LOFIG ___________________________
20
21 gen_api_ctx[recur].HEAD_LOFIG=GEN_HEAD_LOFIG;
22 gen_api_ctx[recur].HT_LOFIG=GEN_HT_LOFIG;
23
24 mbkSwitchContext(&gen_api_ctx[recur]);
25
26 recur++;
27 /*
28 gen_api_head_lofig = HEAD_LOFIG;
29 HEAD_LOFIG = GEN_HEAD_LOFIG;
30
31 gen_api_ht_lofig = HT_LOFIG;
32 HT_LOFIG = GEN_HT_LOFIG;
33 */
34 if ((str = avt_gethashvar ("GEN_SEPAR")))
35 GEN_SEPAR = str[0];
36 else
37 GEN_SEPAR = '.';
38
39 // Global variables initialization
40 /* if (TRANS_TO_SUPPRESS) {
41 freechain (TRANS_TO_SUPPRESS);
42 TRANS_TO_SUPPRESS = NULL;
43 }*/
44 }
45
46 // Release HEAD_LOFIG _________________________________
47
48 void gen_API_Action_Terminate ()// commentaire pour desactiver l'ajout de token
49 {
50 recur--;
51 if (recur<0) avt_fprintf(stderr,"¤6internal_error in gen_API¤.");
52
53 mbkSwitchContext(&gen_api_ctx[recur]);
54 /*
55 GEN_HEAD_LOFIG = HEAD_LOFIG;
56 HEAD_LOFIG = gen_api_head_lofig;
57
58 GEN_HT_LOFIG = HT_LOFIG;
59 HT_LOFIG = gen_api_ht_lofig;
60 */
61 }
62 //_____________________________________________________________________________
63 //_____________________________________________________________________________
64
65 lofig_list *gns_GetNetlist ()
66 {
67 gen_rcenv ();
68
69 gen_update_loins (CUR_HIER_LOFIG, CUR_CORRESP_TABLE);
70 gen_update_transistors (CUR_HIER_LOFIG, CUR_CORRESP_TABLE);
71 return CUR_HIER_LOFIG;
72 }
73
74 lofig_list *gns_GetInstanceNetlist (char *name)
75 {
76 CorrespondingInstance *xi;
77 lofig_list *lf, *duplf;
78 gen_rcenv ();
79 xi=gns_GetCorrespondingInstance(name);
80 if (xi==NULL) return NULL;
81 lf=gen_getlofig(xi->CRT->GENIUS_FIGNAME);
82 duplf=rduplofig(lf);
83 lofigchain(duplf);
84 gen_update_loins(duplf, xi->CRT);
85 gen_update_transistors (duplf, xi->CRT);
86 duplf->USER=addptype(duplf->USER, GEN_ORIG_INS_CORRESP_PTYPE, xi->CRT);
87 return duplf;
88 }
89
90 lofig_list *gns_DuplicateNetlist (lofig_list *lf)
91 {
92 lofig_list *duplf;
93 duplf=rduplofig(lf);
94 lofigchain(duplf);
95 return duplf;
96 }
97 //_____________________________________________________________________________
98 //_____________________________________________________________________________
99
100 void gns_DumpCorrespTable ()
101 {
102 FILE *f;
103 char buf[1024];
104
105 sprintf (buf, "%s.dic", CUR_HIER_LOFIG->NAME);
106 if ((f = fopen (buf, "w+"))) gen_drive_corresp_htable (f, buf, NULL, 1, CUR_CORRESP_TABLE);
107 }
108
109 // Fonctions de correspondance et de nommage _____________________________________
110
111 //_____________________________________________________________________________
112 //_____________________________________________________________________________
113
114 void gns_ViewLo (Netlist *ptfig)
115 {
116 if (!ptfig) return;
117
118 viewlofig ((lofig_list*)ptfig);
119 }
120
121 //_____________________________________________________________________________
122
123 void gns_DriveNetlist (Netlist *ptfig, char *format, char *path, char *name)
124 {
125 char prev_out_lo[5];
126 char *prev_work_lib = WORK_LIB;
127 char *oldname;
128
129 if (!ptfig) return;
130
131 if (name!=NULL)
132 {
133 oldname=ptfig->NAME;
134 ptfig->NAME=namealloc(name);
135 }
136
137 strcpy (prev_out_lo, OUT_LO);
138 WORK_LIB = path;
139
140 if (!strcasecmp (format, "spice")) {
141 strcpy (OUT_LO, "spi");
142 savelofig ((lofig_list*)ptfig);
143 }
144 else if (!strcasecmp (format, "vhdl")) {
145 strcpy (OUT_LO, "vhd");
146 savelofig ((lofig_list*)ptfig);
147 }
148 else if (!strcasecmp (format, "al")) {
149 strcpy (OUT_LO, "al");
150 savelofig ((lofig_list*)ptfig);
151 }
152 else if (!strcasecmp (format, "verilog")) {
153 strcpy (OUT_LO, "vlg");
154 savelofig ((lofig_list*)ptfig);
155 }
156 else
157 fprintf (stderr, "Supported formats are 'spice', 'vhdl' and 'verilog'\n");
158
159 WORK_LIB = prev_work_lib;
160 strcpy (OUT_LO, prev_out_lo);
161
162 if (name!=NULL)
163 ptfig->NAME=oldname;
164 }
165
166 //_____________________________________________________________________________
167
168 extern chain_list *expansedloins, *originalloins;
169
170 //_____________________________________________________________________________
171
172 //_____________________________________________________________________________
173
174 char *gns_GetInstanceName(loins_list *li)
175 {
176 return li->INSNAME;
177 }
178
179 //_____________________________________________________________________________
180
181
182
183 //_____________________________________________________________________________
184
185 char *gns_GetInstanceModelName(loins_list *li)
186 {
187 return li->FIGNAME;
188 }
189
190 //_____________________________________________________________________________
191
192 void gns_GetModelSignalRange(char *name, int *left, int *right)
193 {
194 chain_list *arbo;
195 losig_list *modells;
196 ptype_list *p;
197 tree_list *tree;
198 // ht *sight;
199 long l;
200
201 if (current_lofig==NULL)
202 {
203 fprintf(stderr,"%s: Can't call gns_GetSignalRange() outside genius recognition process\n",gen_info());
204 EXIT(1);
205 }
206 arbo=gen_hierarchical_split(gen_makesignalname(name));
207 if (arbo->NEXT!=NULL)
208 {
209 freechain(arbo);
210 fprintf(stderr,"%s: gns_GetSignalRange() called with a hierarchical name '%s'\n",gen_info(),name);
211 EXIT(1);
212 }
213
214 // sight=gen_get_losig_ht(current_lofig);
215
216 modells=mbk_quickly_getlosigbyname(current_lofig, vectorradical((char *)arbo->DATA));
217 if (modells==NULL)
218 modells=mbk_quickly_getlosigbyname(current_lofig, (char *)arbo->DATA);
219 /*
220 if ((l=gethtitem(sight, vectorradical((char *)arbo->DATA)))!=EMPTYHT
221 || (l=gethtitem(sight, (char *)arbo->DATA))!=EMPTYHT
222 )
223 modells=(losig_list *)l;
224 else
225 modells=NULL;
226 */
227 /*
228 for (modells=current_lofig->LOSIG;
229 modells!=NULL && modells->NAMECHAIN->DATA!=vectorradical((char *)arbo->DATA);
230 modells=modells->NEXT) ;
231
232 if (modells==NULL && current_lofig->LOINS==NULL)
233 {
234 for (modells=current_lofig->LOSIG;
235 modells!=NULL && modells->NAMECHAIN->DATA!=(char *)arbo->DATA;
236 modells=modells->NEXT) ;
237 }
238 */
239 freechain(arbo);
240
241 if (modells!=NULL)
242 {
243 if (!current_lofig->LOINS)
244 {
245 *left=*right=-1;
246 return;
247 }
248 p=getptype(modells->USER, GEN_REAL_RANGE_PTYPE);
249 if (p==NULL)
250 EXIT(49);
251 tree=(tree_list *)p->DATA;
252
253 if (tree==NULL)
254 *left=*right=-1;
255 else
256 if (gen_is_token_to (TOKEN(tree)) || gen_is_token_downto (TOKEN(tree)))
257 {
258 *left=Eval_Exp_VHDL(tree->NEXT->DATA, ALL_ENV);
259 *right=Eval_Exp_VHDL(tree->NEXT->NEXT->DATA, ALL_ENV);
260 }
261 else
262 *left=*right=-1;
263
264 return;
265 }
266
267 fprintf(stderr,"%s: gns_GetSignalRange() can't find signal '%s' in model\n",gen_info(),name);
268 EXIT(1);
269 }
270
271 //_____________________________________________________________________________
272
273 chain_list *gns_GetModelConnectorList()
274 {
275 chain_list *lst;
276 locon_list *lc;
277
278 if (current_lofig==NULL)
279 {
280 fprintf(stderr,"%s: Can't call gns_GetConnectorList() at the end of genius process\n",gen_info());
281 EXIT(1);
282 }
283
284 for (lc=current_lofig->LOCON, lst=NULL; lc!=NULL; lc=lc->NEXT)
285 {
286 lst=addchain(lst, lc);
287 }
288
289 lst=reverse(lst);
290
291 return lst;
292 }
293
294 //_____________________________________________________________________________
295
296 chain_list *gns_GetConnectorList(lofig_list *lf)
297 {
298 chain_list *lst;
299 locon_list *lc;
300
301 for (lc=lf->LOCON, lst=NULL; lc!=NULL; lc=lc->NEXT)
302 lst=addchain(lst, lc);
303
304 return lst;
305 }
306
307 //_____________________________________________________________________________
308
309 char *gns_GetConnectorName(locon_list *lc)
310 {
311 return lc->NAME;
312 }
313
314 //_____________________________________________________________________________
315
316 losig_list *gns_GetConnectorSignal(locon_list *lc)
317 {
318 return lc->SIG;
319 }
320
321 //_____________________________________________________________________________
322
323 char *gns_GetConnectorDirection(locon_list *lc)
324 {
325 switch(lc->DIRECTION)
326 {
327 case IN: return namealloc("in");
328 case OUT: return namealloc("out");
329 case INOUT: return namealloc("inout");
330 case UNKNOWN: return namealloc("linkage");
331 case TRISTATE:
332 case TRANSCV: return namealloc("mux_bit");
333 }
334 return namealloc("linkage");
335 }
336
337 //_____________________________________________________________________________
338
339 char *gns_Vectorize(char *name, int index)
340 {
341 char temp[1024];
342 sprintf(temp,"%s(%d)",name,index);
343 return namealloc(temp);
344 }
345
346 //_____________________________________________________________________________
347
348 char *gns_Vectorize2D(char *name, int index0, int index1)
349 {
350 char temp[1024];
351 sprintf(temp,"%s(%d)(%d)",name,index0,index1);
352 return namealloc(temp);
353 }
354
355 //_____________________________________________________________________________
356
357 chain_list *gns_GetModelSignalList()
358 {
359 chain_list *lst;
360 losig_list *ls;
361
362 if (current_lofig==NULL)
363 {
364 fprintf(stderr,"%s: Can't call gns_GetModelSignalList() at the end of genius process\n",gen_info());
365 EXIT(1);
366 }
367
368 for (ls=current_lofig->LOSIG, lst=NULL; ls!=NULL; ls=ls->NEXT)
369 lst=addchain(lst, ls);
370
371 lst=reverse(lst);
372
373 return lst;
374 }
375
376 //_____________________________________________________________________________
377
378 char *gns_GetSignalName(losig_list *ls)
379 {
380 if (!ls)
381 {
382 fprintf (stderr, "Error in 'gns_GetSignalName', parameter 'ls' is NULL\n");
383 return NULL;
384 }
385
386 if (vectorindex((char *)ls->NAMECHAIN->DATA)==-1)
387 return (char *)ls->NAMECHAIN->DATA;
388 return gns_Vectorize(vectorradical((char *)ls->NAMECHAIN->DATA), vectorindex((char *)ls->NAMECHAIN->DATA));
389 }
390
391 //_____________________________________________________________________________
392
393 int gns_IsSignalExternal(losig_list *ls)
394 {
395 return ls->TYPE=='E';
396 }
397
398 //_____________________________________________________________________________
399
400 chain_list *gns_GetInstanceConnectorList(loins_list *ls)
401 {
402 chain_list *lst;
403 locon_list *lc;
404
405 if (current_lofig==NULL)
406 {
407 fprintf(stderr,"%s: Can't call gns_GetConnectorList() at the end of genius process\n",gen_info());
408 EXIT(1);
409 }
410
411
412 for (lc=ls->LOCON, lst=NULL; lc!=NULL; lc=lc->NEXT)
413 lst=addchain(lst, lc);
414
415 if (getptype(ls->USER, GEN_FOUNDINS_PTYPE)!=NULL)
416 lst=reverse(lst);
417
418 return lst;
419 }
420
421 locon_list *gns_GetInstanceConnector(loins_list *ls, char *name)
422 {
423 chain_list *lst, *arbo;
424 locon_list *lc;
425
426 arbo=gen_hierarchical_split(gen_makesignalname(name));
427 if (arbo->NEXT!=NULL)
428 {
429 freechain(arbo);
430 fprintf(stderr,"%s: gns_GetInstanceConnector() called with a hierarchical name '%s'\n",gen_info(),name);
431 EXIT(1);
432 }
433 for (lc=ls->LOCON, lst=NULL; lc!=NULL; lc=lc->NEXT)
434 {
435 if (vectorradical(lc->NAME)==vectorradical((char *)arbo->DATA)
436 && vectorindex(lc->NAME)==vectorindex((char *)arbo->DATA))
437 {
438 freechain(arbo);
439 return lc;
440 }
441 }
442
443 freechain(arbo);
444 fprintf(stderr,"%s: gns_GetInstanceConnector() can't find connector '%s' for instance\n",gen_info(),name);
445 return NULL;
446 }
447
448 loins_list *gns_GetInstance(lofig_list *lf, char *name)
449 {
450 loins_list *li;
451
452 name=namealloc(gen_makeinstancename(name));
453
454 for (li=lf->LOINS; li!=NULL && li->INSNAME!=name; li=li->NEXT) ;
455
456 return li;
457 }
458
459 //_____________________________________________________________________________
460
461 chain_list *gns_GetAllCorrespondingInstances()
462 {
463 chain_list *lst;
464 subinst_t *cl;
465
466 for (cl=CUR_CORRESP_TABLE->SUBINSTS, lst=NULL; cl!=NULL; cl=cl->NEXT)
467 lst=addchain(lst, cl);
468
469 return lst;
470 }
471
472 //_____________________________________________________________________________
473
474 chain_list *gns_GetAllCorrespondingTransistors()
475 {
476 return GetAllHTElems(CUR_CORRESP_TABLE->TRANSISTORS);
477 }
478
479 //_____________________________________________________________________________
480
481 chain_list *gns_GetAllCorrespondingInstanceModels()
482 {
483 chain_list *lst, *cl, *cl1;
484 subinst_t *si;
485
486 cl=gns_GetAllCorrespondingInstances();
487 while (cl!=NULL)
488 {
489 si=(subinst_t *)cl->DATA;
490 for (cl1=lst; cl1!=NULL && cl1->DATA!=si->CRT->GENIUS_FIGNAME; cl1=cl1->NEXT) ;
491 if (cl1==NULL)
492 lst=addchain(lst, si->CRT->GENIUS_FIGNAME);
493 cl=cl->NEXT;
494 }
495
496 return lst;
497 }
498
499 //_____________________________________________________________________________
500
501 //_____________________________________________________________________________
502
503 locon_list *gns_GetTransistorGrid(lotrs_list *lt)
504 {
505 return lt->GRID;
506 }
507
508 //_____________________________________________________________________________
509
510 locon_list *gns_GetTransistorDrain(lotrs_list *lt)
511 {
512 return lt->DRAIN;
513 }
514
515 //_____________________________________________________________________________
516
517 locon_list *gns_GetTransistorSource(lotrs_list *lt)
518 {
519 return lt->SOURCE;
520 }
521
522 //_____________________________________________________________________________
523
524 char gns_GetTransistorType(lotrs_list *lt)
525 {
526 if (MLO_IS_TRANSN(lt->TYPE)) return 'n';
527 return 'p';
528 }
529
530 //_____________________________________________________________________________
531
532 char *gns_GetTransistorTypeName(lotrs_list *lt)
533 {
534 return getlotrsmodel(lt);
535 }
536
537 //_____________________________________________________________________________
538
539 double gns_GetTransistorParameter(char *name, lotrs_list *lt)
540 {
541 if (strcasecmp(name,"w")==0)
542 return ((double)lt->WIDTH/SCALE_X)*1e-6;
543 if (strcasecmp(name,"l")==0)
544 return ((double)lt->LENGTH/SCALE_X)*1e-6;
545
546 if (strcasecmp(name,"as")==0)
547 {
548 if (lt->XS<0) return -1;
549 else return ((double) lt->XS * lt->WIDTH / ( SCALE_X * SCALE_X ))*1e-12;
550 }
551 if (strcasecmp(name,"ad")==0)
552 {
553 if (lt->XD<0) return -1;
554 else return ((double) lt->XD * lt->WIDTH / ( SCALE_X * SCALE_X ))*1e-12;
555 }
556 if (strcasecmp(name,"ps")==0)
557 {
558 if (lt->PS<0) return -1;
559 else return ((double) lt->PS/SCALE_X)*1e-6;
560 }
561 if (strcasecmp(name,"pd")==0)
562 {
563 if (lt->PD<0) return -1;
564 else return ((double) lt->PD/SCALE_X)*1e-6;
565 }
566
567 if (strcasecmp(name,"x")==0)
568 return ((double) lt->X);
569 if (strcasecmp(name,"y")==0)
570 return ((double) lt->Y);
571
572 fprintf(stderr,"%s: gns_GetTransistorParameter() can't find parameter '%s' for transistor\n",gen_info(),name);
573 return 0.0;
574 }
575
576 //_____________________________________________________________________________
577
578 char *gns_GetTransistorName(lotrs_list *lt)
579 {
580 return lt->TRNAME==NULL?namealloc("??"):lt->TRNAME;
581 }
582
583 //_____________________________________________________________________________
584
585 chain_list *gns_GetAllTransistorsConnectedtoSignal(losig_list *ls)
586 {
587 chain_list *lst, *cl;
588 locon_list *lc;
589
590 for (cl=getptype(ls->USER, LOFIGCHAIN)->DATA, lst=NULL; cl!=NULL; cl=cl->NEXT)
591 {
592 lc=(locon_list *)cl->DATA;
593 if (lc->TYPE=='T')
594 {
595 lst=addchain(lst, lc->ROOT);
596 }
597 }
598
599 return lst;
600 }
601
602 //_____________________________________________________________________________
603
604 locon_list *gns_GetExternalConnectorOfSignal(losig_list *ls)
605 {
606 chain_list *cl;
607 locon_list *lc;
608
609 for (cl=getptype(ls->USER, LOFIGCHAIN)->DATA; cl!=NULL; cl=cl->NEXT)
610 {
611 lc=(locon_list *)cl->DATA;
612 if (lc->TYPE=='E')
613 {
614 return lc;
615 }
616 }
617
618 return NULL;
619 }
620
621 //_____________________________________________________________________________
622
623 int gns_VectorIndex(char *name)
624 {
625 return vectorindex(name);
626 }
627
628 //_____________________________________________________________________________
629
630 char *gns_VectorRadical(char *name)
631 {
632 return vectorradical(namealloc(name));
633 }
634
635 //_____________________________________________________________________________
636
637 char *gns_CreateVhdlName(char *name)
638 {
639 return bvl_vhdlname(name);
640 }
641
642 //_____________________________________________________________________________
643
644 void gns_ChangeInstanceModelName(loins_list *li, char *name)
645 {
646 if (li==NULL)
647 {
648 addhtitem(NEW_LOINS_NAMES_HT, CUR_CORRESP_TABLE->GENIUS_INSNAME, (long)namealloc(name));
649 }
650 else
651 {
652 li->FIGNAME=namealloc(name);
653 }
654 }
655
656 //_____________________________________________________________________________
657
658 locon_list *gns_GetConnector (lofig_list *netlist, char *con_name)
659 {
660 return gen_get_connector (netlist, con_name);
661 }
662
663 //_____________________________________________________________________________
664
665 double gns_GetConnectorCapa (locon_list *lc)
666 {
667 locon_list *ptcon;
668 chain_list *ch;
669 double capa = 0.0;
670
671 if (lc->DIRECTION != 'I') return 0.0;
672
673 for (ch = gen_get_lofigchain (lc->SIG); ch; ch = ch->NEXT) {
674 ptcon = (locon_list*)ch->DATA;
675 if (ptcon->TYPE != 'T' || ptcon->NAME == lc->NAME) continue;
676 capa += gen_get_transistor_capa (ptcon);
677 }
678
679 return capa;
680 }
681
682
683 //_____________________________________________________________________________
684
685 lotrs_list *gns_GetTransistor (lofig_list *netlist, char *tr_name)
686 {
687 return gen_get_transistor (netlist, tr_name);
688 }
689
690 //_____________________________________________________________________________
691
692 lotrs_list *gns_GetCorrespondingTransistor (char *name)
693 {
694 return gen_GetCorrespondingTransistor(name, CUR_CORRESP_TABLE);
695 // return gen_corresp_trs (gen_makeinstancename(name), CUR_CORRESP_TABLE);
696 }
697
698 //_____________________________________________________________________________
699
700 losig_list *gns_GetCorrespondingSignal (char *name)
701 {
702 return gen_corresp_sig (gen_makesignalname(name), CUR_CORRESP_TABLE);
703 }
704
705 //_____________________________________________________________________________
706
707 losig_list *gns_GetSignal (lofig_list *netlist, char *signame)
708 {
709 lofig_list *head_lofig;
710 ht *ht_lofig;
711 losig_list *sig;
712
713 if (!netlist) {
714 fprintf (stderr, "Error in 'gns_GetSignal', parameter 'netlist' is NULL\n");
715 return NULL;
716 }
717
718 if (!signame) {
719 fprintf (stderr, "Error in 'gns_GetSignal', parameter 'signame' is NULL\n");
720 return NULL;
721 }
722
723 // Contextualize HEAD_LOFIG ___________________________
724 head_lofig = HEAD_LOFIG;
725 HEAD_LOFIG = GEN_HEAD_LOFIG;
726 ht_lofig = HT_LOFIG;
727 HT_LOFIG = GEN_HT_LOFIG;
728
729 // Function call ______________________________________
730 sig = gen_get_signal (netlist, signame);
731
732 // Release HEAD_LOFIG _________________________________
733 GEN_HEAD_LOFIG = HEAD_LOFIG;
734 HEAD_LOFIG = head_lofig;
735 GEN_HT_LOFIG = HT_LOFIG;
736 HT_LOFIG = ht_lofig;
737
738 return sig;
739 }
740
741
742 subinst_t *gns_GetCorrespondingInstance(char *name)
743 {
744 return gen_GetCorrespondingInstance(name, CUR_CORRESP_TABLE);
745 }
746 /*
747 lotrs_list *gns_GetCorrespondingTransistor(char *name)
748 {
749 return gen_GetCorrespondingTransistor(name, CUR_CORRESP_TABLE);
750 }
751 */
752 losig_list *gns_GetCorrespondingInstanceConnectorSignal(subinst_t *subins, char *name)
753 {
754 loins_list *loins_in_model;
755 locon_list *lc;
756 losig_list *ls;
757 char *conname;
758
759 conname=namealloc(gen_makesignalname(name));
760 loins_in_model=gen_findinstance(CUR_HIER_LOFIG, subins->INSNAME);
761 if (loins_in_model==NULL) return NULL;
762 for (lc=loins_in_model->LOCON; lc!=NULL && lc->NAME!=conname; lc=lc->NEXT) ;
763 if (lc==NULL) return NULL;
764 ls=gen_corresp_sig (gen_losigname(lc->SIG), CUR_CORRESP_TABLE);
765 if (ls==NULL) return NULL;
766 return ls;
767 }
768
769 char *gns_GetCorrespondingInstanceName(subinst_t *subins)
770 {
771 return subins->CRT->GENIUS_INSNAME;
772 }
773
774 char *gns_GetCorrespondingInstanceModelName(subinst_t *subins)
775 {
776 return subins->CRT->GENIUS_FIGNAME;
777 }
778 /*
779 chain_list *gns_GetAllCorrespondingInstances()
780 {
781 return dupchainlst(CUR_CORRESP_TABLE->SUBINSTS);
782 }
783 */
784
785 char *gen_change_hier_divider (char *name, char divider)
786 {
787 char buf[4096];
788 int i;
789
790 for (i = 0; name[i] != '\0'; i++) {
791 if (name[i] == SEPAR)
792 buf[i] = divider;
793 else
794 buf[i] = name[i];
795 }
796
797 buf[i] = '\0';
798
799 return namealloc (buf);
800
801 }
802
803 void gns_ChangeHierarchyDivider (lofig_list *netlist, char divider)
804 {
805 lotrs_list *pttrs;
806 losig_list *ptsig;
807
808 for (pttrs = netlist->LOTRS; pttrs; pttrs = pttrs->NEXT)
809 pttrs->TRNAME = gen_change_hier_divider (pttrs->TRNAME, divider);
810
811 for (ptsig = netlist->LOSIG; ptsig; ptsig = ptsig->NEXT)
812 ptsig->NAMECHAIN->DATA = gen_change_hier_divider ((char*)ptsig->NAMECHAIN->DATA, divider);
813 }
814
815 int gns_GetGeneric(char *name)
816 {
817 return gen_getvariable(name);
818 }
819
820 char *gns_GetCurrentArchi()
821 {
822 return gen_getarchi();
823 }
824
825 char *gns_GetCurrentModel()
826 {
827 return gen_getmodel();
828 }
829
830 char *gns_GetCurrentInstance()
831 {
832 return gen_getinstancename();
833 }
834
835
836 void ASSOCIATE_BEHAVIOUR(void *func)
837 {
838 APICallFunc *cf=(APICallFunc *)func;
839 t_arg *ret;
840 HierLofigInfo *hli=gethierlofiginfo(CUR_HIER_LOFIG);
841
842 if (hli->BUILD_BEH==NULL)
843 {
844 // ajout a la lofig hierarchique de l'info
845 hli->BUILD_BEH=cf;
846 //
847 if (APIExecAPICallFunc(APIGetExecutionContext(), cf, &ret, 0)) EXIT(1);
848 if (ret!=NULL)
849 {
850 APIFreeTARG(ret);
851 }
852 }
853 else
854 {
855 APIFreeTARGS(cf->ARGS);
856 mbkfree(cf);
857 }
858 }
859
860 void *callfunc(char *funcname, ...)
861 {
862 va_list ap;
863 int i, nb;
864 APICallFunc *acf;
865 libgetargfunc_type libfunc;
866 char fname[1024];
867 t_arg **tab;
868
869 sprintf(fname, "wrap_getargs_%s",funcname);
870
871 libfunc=(libgetargfunc_type)GetDynamicFunction(fname);
872
873 if (libfunc==NULL)
874 {
875 fprintf(stderr,"callfunc: function '%s' can't be found in the dynamic libraries\n",fname);
876 EXIT(3);
877 }
878
879 libfunc(&tab, &nb);
880
881 va_start(ap, funcname);
882 for (i = 0; i < nb; i++)
883 {
884 if (tab[i]->POINTER>0)
885 {
886 if (tab[i]->POINTER==1 && strcmp(tab[i]->TYPE,"char")==0)
887 *(void **)tab[i]->VALUE = sensitive_namealloc(va_arg(ap, void *));
888 else
889 {
890 fprintf(stderr,"callfunc: only 'char *' pointer type can be used in function call\n");
891 EXIT(3);
892 }
893 /**(void **)tab[i]->VALUE = sensitive_namealloc(va_arg(ap, void *));*/
894 }
895 else
896 if (strcmp(tab[i]->TYPE,"char")==0)
897 *(char *)tab[i]->VALUE = va_arg(ap, int);
898 else if (strcmp(tab[i]->TYPE,"int")==0)
899 *(int *)tab[i]->VALUE = va_arg(ap, int);
900 else if (strcmp(tab[i]->TYPE,"long")==0)
901 *(long *)tab[i]->VALUE = va_arg(ap, long);
902 else if (strcmp(tab[i]->TYPE,"double")==0)
903 *(double *)tab[i]->VALUE = va_arg(ap, double);
904 }
905 va_end(ap);
906
907 acf=(APICallFunc *)mbkalloc(sizeof(APICallFunc));
908 acf->NAME=sensitive_namealloc(funcname);
909 acf->ARGS=APIPrepareFunctionARGS(NULL, tab, nb, NULL);
910 return acf;
911 }
912
913 void *callfunc_tcl(char *funcname, chain_list *args)
914 {
915 int i, nb=countchain(args);
916 APICallFunc *acf;
917 t_arg **tab;
918 chain_list *cl;
919
920 acf=(APICallFunc *)mbkalloc(sizeof(APICallFunc));
921 acf->NAME=sensitive_namealloc(funcname);
922 acf->ARGS=NULL;
923 if (nb>0)
924 {
925 char buf[20];
926 tab=mbkalloc(sizeof (t_arg *)*nb);
927 for (i = 0, cl=args; i < nb; i++, cl=cl->NEXT)
928 {
929 sprintf(buf,"arg%d",i);
930 tab[i]=APINewTARG("char", 1, namealloc(buf));
931 *(void **)tab[i]->VALUE = sensitive_namealloc((char *)cl->DATA);
932 }
933 acf->ARGS=APIPrepareFunctionARGS(NULL, tab, nb, NULL);
934 mbkfree(tab);
935 }
936 return acf;
937 }
938
939 void gns_DriveSpiceNetlistGroup(chain_list *cl, char *filename)
940 {
941 int failed=0;
942 char oldSPI_VECTOR[64];
943 char temp[1024];
944
945 strcpy(oldSPI_VECTOR, SPI_VECTOR);
946 strcpy(SPI_VECTOR, "[]");
947
948 if (!failed)
949 {
950 FILE *f;
951 if ((f=mbkfopen(filename, NULL, WRITE_TEXT))!=NULL)
952 {
953 sprintf(temp,"'%s'", filename);
954 spiceprintdate(temp, f);
955 spicesavelofigsinfile(cl, f);
956 }
957 else
958 fprintf(stderr, "could not openfile '%s'\n", filename);
959 }
960
961 strcpy(SPI_VECTOR, oldSPI_VECTOR);
962 }
963
964 int gns_IsTopLevel()
965 {
966 if (CUR_CORRESP_TABLE->FLAGS & LOINS_IS_TOPLEVEL) return 1;
967 return 0;
968 }
969
970 char *_equiv(char *name)
971 {
972 template_corresp *tc;
973 char res[1024], *c;
974
975 tc=gen_get_template_corresp(GNS_TEMPLATE_HT, CUR_CORRESP_TABLE->FIGNAME);
976 if (tc!=NULL)
977 {
978 if (gen_find_template_corresp(GNS_TEMPLATE_HT, tc->defines, name, res)==0)
979 return namealloc(res);
980 }
981
982 c=strrchr(name,'.');
983 if (c==NULL) return namealloc(name);
984 return namealloc(c+1);
985 }
986
987 void gns_REJECT_INSTANCE()
988 {
989 long k;
990 char *curins;
991
992 curins=gns_GetCurrentInstance();
993 if ((k=gethtitem(LOINS_LIST_CONTROL, curins))==EMPTYHT) k=0;
994 k&=~KEEP_INSTANCE;
995 addhtitem(LOINS_LIST_CONTROL, curins, k);
996 }
997
998 void gns_KEEP_INSTANCE()
999 {
1000 long k;
1001 char *curins;
1002
1003 curins=gns_GetCurrentInstance();
1004 if ((k=gethtitem(LOINS_LIST_CONTROL, curins))==EMPTYHT) k=0;
1005 k|=KEEP_INSTANCE;
1006 addhtitem(LOINS_LIST_CONTROL, curins, k);
1007 }
1008
1009 void gns_REJECT_MODEL()
1010 {
1011 long k;
1012 char *curmodel;
1013
1014 curmodel=gns_GetCurrentModel();
1015 if ((k=gethtitem(LOINS_LIST_CONTROL, curmodel))==EMPTYHT) k=0;
1016 k&=~KEEP_INSTANCE;
1017 addhtitem(LOINS_LIST_CONTROL, curmodel, k);
1018 }
1019
1020 void gns_KEEP_MODEL()
1021 {
1022 long k;
1023 char *curmodel;
1024
1025 curmodel=gns_GetCurrentModel();
1026 if ((k=gethtitem(LOINS_LIST_CONTROL, curmodel))==EMPTYHT) k=0;
1027 k|=KEEP_INSTANCE;
1028 addhtitem(LOINS_LIST_CONTROL, curmodel, k);
1029 }
1030
1031 char *gns_GetWorkingFigureName()
1032 {
1033 return LATEST_GNS_RUN->FIGNAME;
1034 }
1035
1036 int gns_IsVss(losig_list *sig)
1037 {
1038 return mbk_LosigIsVSS(sig);
1039 }
1040
1041 int gns_IsVdd(losig_list *sig)
1042 {
1043 return mbk_LosigIsVDD(sig);
1044 }
1045
1046 int gns_IsBlackBox()
1047 {
1048 return (CUR_CORRESP_TABLE->FLAGS & LOINS_IS_BLACKBOX)!=0;
1049 }