Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / api / beg / beg_API.c
1 #include <string.h>
2
3 #include AVT_H
4 #include MUT_H
5 #include MLO_H
6 #include BEH_H
7 #include BVL_H
8 #include BHL_H
9 #include BEG_H
10 #include BEF_H
11 #include GEN_H
12 #include LOG_H
13
14 #define API_USE_REAL_TYPES
15 #include "gen_API.h"
16 #include "beg_API.h"
17 #define AVTWIG_AVOID_CONFLICT
18 #include "mbk_API.h"
19
20
21 static ht *BEG_MODELHT = NULL;
22
23 static char *BEGAPI_PREFIX = NULL;
24 static int BEGAPI_INDEX = -1;
25 static int BEG_TRACE = 0;
26 static befig_list *BEGAPI_BEFIG = NULL;
27 static ht *BEGAPI_DONEHT = NULL;
28
29 static int BEGAPI_USEFILES = 0;
30
31 static int BEGAPI_DRIVE_CORRESP;
32 static int BEGAPI_DRIVE_ALL_BEH;
33 static ht *BEGAPI_MODELTABLE = NULL;
34
35 static int DEACTIVATE_BEG = 0, BEG_QUICK_MODE=1;
36 static char *BEG_FORCED_NAME=NULL;
37 static chain_list *RECUR_STACK=NULL;
38 void begRenameSignalsFromModel();
39 static void begAutoCreateCorrespOnBlackbox(befig_list *bf, lofig_list *lf);
40
41 #include "beg_API_correspondance.h"
42
43
44 static long getbiablflag(long val)
45 {
46 long nval=0;
47 if (val & 2) nval|=BEH_CND_WEAK;
48 if (val & 4) nval|=BEH_CND_STRONG;
49 if (val & 8) nval|=BEH_CND_PULL;
50 return nval;
51 }
52
53 static long getsigflag(long val)
54 {
55 long nval=0;
56 if (val & 1) nval|=BEH_FLAG_NORMAL;
57 return nval;
58 }
59
60 /**************************************************************************************/
61
62 void beg_API_AtLoad_Initialize() // commentaire pour desactiver l'ajout de token
63 {
64 char *str;
65
66 if (V_BOOL_TAB[__API_DRIVE_CORRESP].VALUE)
67 {
68 mbv_useAdvancedNameAllocator();
69 begInitCorrespondance();
70 BEGAPI_DRIVE_CORRESP = 1;
71 }
72 else
73 BEGAPI_DRIVE_CORRESP = 0;
74
75 str = V_STR_TAB[__API_DRIVE_ALL_BEH].VALUE;
76 if (str && !strcasecmp(str,"yes"))
77 BEGAPI_DRIVE_ALL_BEH = 1;
78 else if (str && !strcasecmp(str,"onlymodel"))
79 {
80 BEGAPI_DRIVE_ALL_BEH = 1;
81 BEGAPI_MODELTABLE = addht(50);
82 }
83 else
84 BEGAPI_DRIVE_ALL_BEH = 0;
85 }
86
87 /**************************************************************************************/
88
89 void
90 beg_API_Action_Initialize() // commentaire pour desactiver l'ajout de token
91 {
92 BEG_FORCED_NAME = NULL;
93 DEACTIVATE_BEG = 0;
94 }
95
96
97 void beg_API_TopLevel(long list) // commentaire pour desactiver l'ajout de token
98 {
99 int res;
100 char buf[2048];
101
102 strcpy(buf,"");
103
104 res=check_instances_connections(GENIUS_GLOBAL_LOFIG, buf);
105 /* if (res)
106 {
107 avt_error("begapi", 1, AVT_WAR,
108 "Functional errors could appear if using the beg_API\n"
109 "reason: %s\n",
110 buf
111 );
112 }*/
113 DEACTIVATE_BEG=(long)RECUR_STACK->DATA; RECUR_STACK=delchain(RECUR_STACK, RECUR_STACK);
114 BEG_FORCED_NAME = (char *)RECUR_STACK->DATA; RECUR_STACK=delchain(RECUR_STACK, RECUR_STACK);
115 }
116 /*
117 void
118 beg_API_Action_Terminate() // commentaire pour desactiver l'ajout de token
119 {
120
121 }
122 */
123 /**************************************************************************************/
124
125 void
126 beg_API_Restart() // commentaire pour desactiver l'ajout de token
127 {
128 chain_list *ptchain, *refchain;
129 char *varname;
130
131 RECUR_STACK=addchain(RECUR_STACK, BEG_FORCED_NAME);
132 RECUR_STACK=addchain(RECUR_STACK, (void *)(long)DEACTIVATE_BEG);
133
134 if (BEG_MODELHT != NULL) {
135 delht(BEG_MODELHT);
136 BEG_MODELHT = NULL;
137 }
138 #if 0
139 if (BEGAPI_INTVARLIST != NULL) {
140 for (ptchain = BEGAPI_INTVARLIST; ptchain; ptchain = ptchain->NEXT) {
141 varname = (char *)ptchain->DATA;
142 refchain = (chain_list *)gethtitem(BEGAPI_INTVARHT, varname);
143 freechain(refchain);
144 }
145 freechain(BEGAPI_INTVARLIST);
146 BEGAPI_INTVARLIST = NULL;
147 delht(BEGAPI_INTVARHT);
148 BEGAPI_INTVARHT = NULL;
149 }
150 #endif
151 }
152
153 /**************************************************************************************/
154
155 static befig_list * begGetModel(char *name)
156 {
157 befig_list *ptbefig = NULL;
158
159 if (BEG_MODELHT != NULL) {
160 ptbefig = (befig_list *)gethtitem(BEG_MODELHT, name);
161 if (ptbefig == (befig_list *)EMPTYHT) ptbefig = NULL;
162 }
163 return ptbefig;
164 }
165
166 /**************************************************************************************/
167
168 static int BEG_CHECK_EXISTENCE(char *name)
169 {
170
171 if (begGetModel(namealloc(name))!=NULL)
172 DEACTIVATE_BEG=1;
173 else
174 DEACTIVATE_BEG=0;
175 return DEACTIVATE_BEG;
176 }
177
178 befig_list *begModelToInstance(char *instance, char *model)
179 {
180 befig_list *ptinsbefig;
181
182 ptinsbefig = begGetModel(instance);
183 if (ptinsbefig == NULL)
184 {
185 ptinsbefig = begGetModel(model);
186 if (ptinsbefig != NULL)
187 {
188 ptinsbefig = beg_duplicate(ptinsbefig, instance);
189 }
190 }
191 return ptinsbefig;
192 }
193
194 static char *_BegGetName()
195 {
196 if (BEG_FORCED_NAME!=NULL) return BEG_FORCED_NAME;
197 if (!BEG_QUICK_MODE)
198 return gns_GetCurrentInstance();
199 else
200 return gns_GetCurrentModel();
201 }
202
203 /**************************************************************************************/
204
205 static void
206 begRefDriver(char *varname, biabl_list *ptdriver)
207 {
208 chain_list *varchain;
209 ptdriver->TIMEVAR=namealloc(varname);
210 #if 0
211 if (BEGAPI_INTVARHT == NULL) BEGAPI_INTVARHT = addht(20);
212 if ((varchain = (chain_list *)gethtitem(BEGAPI_INTVARHT, namealloc(varname))) != (void *)EMPTYHT) {
213 varchain = addchain(varchain, ptdriver);
214 sethtitem(BEGAPI_INTVARHT, namealloc(varname), (long)varchain);
215 }
216 else {
217 addhtitem(BEGAPI_INTVARHT, namealloc(varname), (long)addchain(NULL, ptdriver));
218 BEGAPI_INTVARLIST = addchain(BEGAPI_INTVARLIST, namealloc(varname));
219 }
220 #endif
221 }
222
223 /**************************************************************************************/
224
225 static char *
226 begRadical(char *name)
227 {
228 char buf[1024];
229 char *pt;
230
231 strcpy(buf, name);
232 if ((pt = strchr(buf, ' ')) != NULL) *pt = 0;
233 return namealloc(buf);
234 }
235
236 /**************************************************************************************/
237
238 static void
239 begTranslate(BEG_OBJ ptbegobj, BEG_OBJ ptportobj, int shift, char *name)
240 {
241 vectbiabl_list *ptvecbiabl;
242 biabl_list *ptbiabl;
243 loop_list *ptloop;
244 berin_list *ptberin;
245
246 if (ptbegobj && gethtitem(BEGAPI_DONEHT, ptbegobj) == EMPTYHT) {
247 addhtitem(BEGAPI_DONEHT, ptbegobj, 0);
248 ptvecbiabl = beg_getVectBiabl(ptbegobj);
249 beg_newLeft(ptbegobj, beg_getLeft(ptbegobj)+shift);
250 beg_newRight(ptbegobj, beg_getRight(ptbegobj)+shift);
251 for (;ptvecbiabl; ptvecbiabl = ptvecbiabl->NEXT) {
252 if (ptvecbiabl->LEFT >= 0) ptvecbiabl->LEFT += shift;
253 if (ptvecbiabl->RIGHT >= 0) ptvecbiabl->RIGHT += shift;
254 for (ptbiabl = ptvecbiabl->BIABL; ptbiabl; ptbiabl = ptbiabl->NEXT) {
255 ptloop = beh_getloop(ptbiabl);
256 for (;ptloop; ptloop = ptloop->NEXT) {
257 if (ptloop->INDEX != NULL) {
258 ptloop->INDEX = shiftExprStr(ptloop->INDEX, shift);
259 }
260 }
261 }
262 }
263 }
264 if (ptportobj && gethtitem(BEGAPI_DONEHT, ptportobj) == EMPTYHT) {
265 addhtitem(BEGAPI_DONEHT, ptportobj, 0);
266 ptvecbiabl = beg_getVectBiabl(ptportobj);
267 beg_newLeft(ptportobj, beg_getLeft(ptportobj)+shift);
268 beg_newRight(ptportobj, beg_getRight(ptportobj)+shift);
269 for (;ptvecbiabl; ptvecbiabl = ptvecbiabl->NEXT) {
270 if (ptvecbiabl->LEFT >= 0) ptvecbiabl->LEFT += shift;
271 if (ptvecbiabl->RIGHT >= 0) ptvecbiabl->RIGHT += shift;
272 for (ptbiabl = ptvecbiabl->BIABL; ptbiabl; ptbiabl = ptbiabl->NEXT) {
273 ptloop = beh_getloop(ptbiabl);
274 for (;ptloop; ptloop = ptloop->NEXT) {
275 if (ptloop->INDEX != NULL) {
276 ptloop->INDEX = shiftExprStr(ptloop->INDEX, shift);
277 }
278 }
279 }
280 }
281 }
282 ptberin = beg_getBerinByName(BEGAPI_BEFIG, name);
283 if (ptberin && gethtitem(BEGAPI_DONEHT, ptberin) == EMPTYHT) {
284 addhtitem(BEGAPI_DONEHT, ptberin, 0);
285 ptberin->LEFT += shift;
286 ptberin->RIGHT += shift;
287 }
288 }
289
290 /**************************************************************************************/
291 static int mode=0;
292
293 void begSwitchMode()
294 {
295 mode=(mode+1) & 1;
296 }
297
298 static char *
299 begNameWrap(char *name)
300 {
301 char buf[1024];
302 BEG_OBJ ptbegobj;
303 BEG_OBJ ptportobj;
304 int shift;
305
306 if (strncasecmp(name,"ext@",4)==0) return name;
307
308 buf[0] = 0;
309 if (strchr(name, ' ') == NULL) {
310 ptbegobj = beg_getObjByName(BEGAPI_BEFIG, name, &ptportobj);
311 if (((ptbegobj != NULL && beg_isVect(ptbegobj)) || (ptportobj != NULL && beg_isVect(ptportobj))) && BEGAPI_INDEX >= 0) {
312 if (ptbegobj) shift = BEGAPI_INDEX * (abs(beg_getLeft(ptbegobj) - beg_getRight(ptbegobj)) + 1);
313 else shift = BEGAPI_INDEX * (abs(beg_getLeft(ptportobj) - beg_getRight(ptportobj)) + 1);
314 if (shift > 0) begTranslate(ptbegobj, ptportobj, shift, name);
315 sprintf(buf, "%s.%s", BEGAPI_PREFIX, name);
316 return namealloc(buf);
317 }
318 else {
319 if (ptbegobj == NULL && ptportobj == NULL && name != BEGAPI_BEFIG->NAME) {
320 avt_errmsg(BEG_API_ERRMSG, "001", AVT_WARNING, name, BEGAPI_BEFIG->NAME);
321 // avt_error("begapi", 1, AVT_WAR, "name '%s' does not exist in figure '%s'\n", name, BEGAPI_BEFIG->NAME);
322 }
323 if (BEGAPI_INDEX >= 0) {
324 sprintf(buf, "%s.%s %d", BEGAPI_PREFIX, name, BEGAPI_INDEX);
325 }
326 else {
327 sprintf(buf, "%s.%s", BEGAPI_PREFIX, name);
328 }
329 return namealloc(buf);
330 }
331 }
332 else {
333 if (BEGAPI_INDEX >= 0) {
334 sprintf(buf, "%s.%s", BEGAPI_PREFIX, name);
335 ptbegobj = beg_getObjByName(BEGAPI_BEFIG, begRadical(name), &ptportobj);
336 if (ptbegobj != NULL || ptportobj != NULL) {
337 if (ptbegobj) shift = BEGAPI_INDEX * (abs(beg_getLeft(ptbegobj) - beg_getRight(ptbegobj)) + 1);
338 else shift = BEGAPI_INDEX * (abs(beg_getLeft(ptportobj) - beg_getRight(ptportobj)) + 1);
339 if (shift > 0) return renameVectAtom(buf, NULL, shift);
340 }
341 else if (ptbegobj == NULL && ptportobj == NULL && name != BEGAPI_BEFIG->NAME) {
342 avt_errmsg(BEG_API_ERRMSG, "001", AVT_WARNING, name, BEGAPI_BEFIG->NAME);
343 // avt_error("begapi", 1, AVT_WAR, "name '%s' does not exist in figure '%s'\n", name, BEGAPI_BEFIG->NAME);
344 }
345 return namealloc(buf);
346 }
347 else {
348 sprintf(buf, "%s.%s", BEGAPI_PREFIX, name);
349 return namealloc(buf);
350 }
351 }
352 }
353
354 static inline int inrange(int num, int left, int right)
355 {
356 if (left<right && num>=left && num<=right)
357 return 1;
358 else if (left>=right && num>=right && num<=left)
359 return 1;
360 return 0;
361 }
362
363 static void begAutoCreateCorrespOnBlackbox(befig_list *bf, lofig_list *lf)
364 {
365 BEG_OBJ ptbegobj;
366 BEG_OBJ ptportobj;
367 losig_list *ls;
368 char *name;
369 ht *corresp_ht;
370 int index;
371
372 if (BEGAPI_DRIVE_CORRESP)
373 {
374 corresp_ht = begGetCorrespHTCreate(gns_GetCurrentInstance()/*bf->NAME*/);
375
376 for (ls = lf->LOSIG; ls != NULL; ls = ls->NEXT)
377 {
378 name = gen_losigname(ls);
379 if (strchr(name, ' ') == NULL)
380 {
381 ptbegobj = beg_getObjByName(bf, name, &ptportobj);
382 if (ptbegobj != NULL)
383 begAddCorrespName(corresp_ht,name, name);
384 }
385 else
386 {
387 index = vectorindex(name);
388 ptbegobj = beg_getObjByName(bf,vectorradical(name),&ptportobj);
389 if (ptbegobj != NULL &&
390 inrange(index,beg_getLeft(ptbegobj),beg_getRight(ptbegobj)))
391 begAddCorrespName(corresp_ht,name,name);
392 }
393 }
394 begUpdateCorresp(corresp_ht);
395 }
396 }
397
398 /**************************************************************************************/
399
400 befig_list *begLoadBefig(char *name)
401 {
402 name = NULL; // WARNING PREVENTION
403
404 return NULL;
405 }
406
407 /**************************************************************************************/
408
409 void
410 begSaveModel(void)
411 {
412 befig_list *ptbefig;
413 char *name, *insname;
414
415 name=_BegGetName();
416 /*
417 if (BEGAPI_DRIVE_CORRESP)
418 {
419 insname=gns_GetCurrentInstance();
420 if (name!=insname)
421 {
422 if ((ptbefig = begGetModel(insname))==NULL)
423 if ((ptbefig = begGetModel(name))==NULL)
424 ptbefig = beg_get_befig(BEG_NOVERIF);
425 bvl_drivecorresp(insname, ptbefig);
426 }
427 }
428 */
429 if (DEACTIVATE_BEG) return;
430
431 ptbefig = beg_get_befig(BEG_NOVERIF);
432 if (ptbefig != NULL) savebefig(ptbefig, 0);
433 }
434
435 /**************************************************************************************/
436
437 static void _begKeepModel(int mode)
438 {
439 befig_list *ptbefig;
440 lofig_list *lf;
441
442 if (BEGAPI_DRIVE_ALL_BEH)
443 {
444 if (!BEGAPI_MODELTABLE)
445 begSaveModel();
446 else if (gethtitem(BEGAPI_MODELTABLE,CUR_CORRESP_TABLE->GENIUS_FIGNAME)
447 == EMPTYHT)
448 {
449 addhtitem(BEGAPI_MODELTABLE,CUR_CORRESP_TABLE->GENIUS_FIGNAME,0);
450 begSaveModel();
451 }
452 }
453
454 if (!DEACTIVATE_BEG)
455 {
456 ptbefig = beg_get_befig(BEG_NOVERIF);
457
458 if (BEG_MODELHT == NULL)
459 BEG_MODELHT = addht(20);
460 addhtitem(BEG_MODELHT,ptbefig->NAME,(long)ptbefig);
461 }
462
463 if (mode==1 && CUR_CORRESP_TABLE->FLAGS & LOINS_IS_BLACKBOX)
464 {
465 lf = gns_GetBlackboxNetlist(CUR_CORRESP_TABLE->GENIUS_FIGNAME);
466 begAutoCreateCorrespOnBlackbox(ptbefig, lf);
467 }
468
469 if (gns_IsTopLevel())
470 begRenameSignalsFromModel();
471
472 }
473
474 void
475 begKeepModel(void)
476 {
477 _begKeepModel(1);
478 }
479
480 /**************************************************************************************/
481
482 /**************************************************************************************/
483
484 void
485 begDestroyModel(void)
486 {
487 if (DEACTIVATE_BEG) return;
488 beg_freeBefig();
489 }
490
491 /**************************************************************************************/
492
493 char *
494 begVectorize(char *radical, int index)
495 {
496 char temp[1024];
497
498 sprintf(temp, "%s(%d)", radical, index);
499 return namealloc(temp);
500 }
501
502 /**************************************************************************************/
503
504 char *
505 begVarVectorize(char *radical, char *var)
506 {
507 char temp[1024];
508
509 sprintf(temp, "%s(%s)", radical, var);
510 return namealloc(temp);
511 }
512
513 /**************************************************************************************/
514
515 char *
516 begVectorRange(char *radical, int left, int right)
517 {
518 char temp[1024];
519
520 sprintf(temp, "%s(%d:%d)", radical, left, right);
521 return namealloc(temp);
522 }
523
524 /**************************************************************************************/
525
526 void
527 begCreateModel(char *name)
528 {
529 if (BEG_CHECK_EXISTENCE(name)) return;
530 BEG_FORCED_NAME=namealloc(name);
531 beg_def_befig(name);
532 }
533
534 /**************************************************************************************/
535
536 void
537 begCreatePort(char *name, char direction)
538 {
539 if (DEACTIVATE_BEG) return;
540 beg_def_por(name, direction);
541 }
542
543 /**************************************************************************************/
544
545 void
546 begCreateModelFromConnectors(char *name, chain_list *ptloconlist)
547 {
548 befig_list *ptbefig;
549 locon_list *ptlocon;
550 chain_list *ptchain;
551 chain_list *ptprevchain;
552 char *basename;
553 char temp[1024];
554 char direction;
555 int left, right, index;
556 ht *corresp_ht;
557
558 if (BEG_CHECK_EXISTENCE(name) && BEGAPI_DRIVE_CORRESP==0) return;
559
560 if (BEG_TRACE)
561 fprintf (stdout, "\nbegCreateModelFromConnectors ('%s')\n", name);
562
563 if (!DEACTIVATE_BEG)
564 {
565 if ((ptbefig = beg_get_befigByName(name))!=NULL)
566 beg_delBefig(ptbefig);
567 beg_def_befig(name);
568 ptbefig = beg_get_befig(BEG_NOVERIF);
569 }
570
571 if (BEGAPI_DRIVE_CORRESP)
572 corresp_ht = begGetCorrespHTCreate(gns_GetCurrentInstance()/*ptbefig->NAME*/);
573 else
574 corresp_ht = NULL;
575
576 for (ptchain = ptloconlist; ptchain; ptchain = ptchain->NEXT) {
577 ptlocon = (locon_list *)ptchain->DATA;
578 if ((index = vectorindex(ptlocon->NAME)) == -1) {
579 gns_GetModelSignalRange(ptlocon->NAME, &left, &right);
580 if (left != -1)
581 {
582 sprintf(temp,"%s(%d:%d)",ptlocon->NAME,left,right);
583 begTraceAndCorresp(corresp_ht,ptlocon->NAME,left,right,
584 BEG_TRACE,BEGAPI_DRIVE_CORRESP);
585 }
586 else
587 {
588 sprintf(temp, "%s", ptlocon->NAME);
589 begTraceAndCorresp(corresp_ht,ptlocon->NAME,-1,-1,
590 BEG_TRACE,BEGAPI_DRIVE_CORRESP);
591 }
592 }
593 else
594 {
595 ptprevchain = ptchain;
596 basename = vectorradical(ptlocon->NAME);
597 left = index;
598
599 for (; ptchain; ptchain = ptchain->NEXT)
600 {
601 ptlocon = (locon_list *)ptchain->DATA;
602 if (vectorradical(ptlocon->NAME) != basename)
603 break;
604 right = vectorindex(ptlocon->NAME);
605 ptprevchain = ptchain;
606 begTraceAndCorresp(corresp_ht,vectorradical(ptlocon->NAME),
607 right,right,
608 BEG_TRACE,BEGAPI_DRIVE_CORRESP);
609 }
610 ptchain = ptprevchain;
611 sprintf(temp, "%s(%d:%d)", basename, left, right);
612 }
613
614 if (ptlocon->DIRECTION == 'D' || ptlocon->DIRECTION == 'S')
615 direction = 'I';
616 else
617 direction = ptlocon->DIRECTION;
618
619 if (!DEACTIVATE_BEG)
620 beg_def_por(namealloc(temp), direction);
621 }
622 if (BEGAPI_DRIVE_CORRESP) {
623 for (ptchain = ptloconlist; ptchain; ptchain = ptchain->NEXT) {
624 ptlocon = (locon_list *)ptchain->DATA;
625 begAddCorresp(gns_GetCurrentInstance(), ptlocon->NAME);
626 }
627 }
628 }
629
630 /**************************************************************************************/
631
632 void begCreateModelInterface(char *name)
633 {
634 chain_list *connectors;
635
636 if (BEG_CHECK_EXISTENCE(name)==0)
637 {
638 begCreateModel(name);
639 name=_BegGetName();
640 connectors = gns_GetModelConnectorList();
641 begCreateModelFromConnectors(name, connectors);
642 freechain(connectors);
643 }
644 }
645
646 void begCreateInterface()
647 {
648 chain_list *connectors;
649 char *name;
650
651 name=_BegGetName();
652 connectors = gns_GetModelConnectorList();
653 begCreateModelFromConnectors(name, connectors);
654 freechain(connectors);
655 }
656
657 /**************************************************************************************/
658
659 void
660 begAddInstanceModel(loins_list *instance, ht *corTbl)
661 {
662 befig_list *befig;
663 locon_list *ptlocon;
664 bepor_list *ptbepor;
665 berin_list *ptberin;
666 bevectpor_list *ptbevectpor;
667 lofig_list *pthierlofig;
668 ht *berinht;
669 ht *loconht;
670 int left, right, shift;
671 char *insname;
672 char *newname;
673 char *leftsigname;
674 chain_list *before_change, *after_change;
675 ptype_list *ptype;
676 ht *corTblIns = NULL;
677 CorrespondingInstance *ci;
678
679 if (DEACTIVATE_BEG && BEGAPI_DRIVE_CORRESP==0) return;
680
681 ci=gns_GetCorrespondingInstance(instance->INSNAME);
682 insname = gns_GetCorrespondingInstanceName(ci);
683 befig = begModelToInstance(insname, ci->CRT->GENIUS_FIGNAME);
684 if (befig == NULL)
685 {
686 fprintf(stderr,"%s: BegApi: Model for instance '%s' does not exist\n", gen_info(), insname);
687 return;
688 }
689
690 corTblIns = begGetCorrespHT(befig->NAME);
691 /*
692 if ((ptype = getptype (befig->USER, BEG_CORRESP_PTYPE)))
693 corTblIns = (ht*)((chain_list*)ptype->DATA)->DATA;
694 */
695 pthierlofig = CUR_HIER_LOFIG; //gns_GetNetlist();
696 if (befig == NULL && BEGAPI_USEFILES)
697 {
698 befig = begLoadBefig(instance->FIGNAME);
699 if (befig != NULL)
700 befig->NAME = insname;
701 }
702 BEGAPI_BEFIG = befig;
703 BEGAPI_INDEX = gns_GetInstanceLoopIndex(instance, &BEGAPI_PREFIX);
704 if (BEGAPI_INDEX != -1)
705 {
706 gns_GetInstanceLoopRange(pthierlofig, instance, &left, &right);
707 if (left != -1 && left == right)
708 BEGAPI_INDEX = -1;
709 }
710 if (mode==1)
711 {
712 BEGAPI_PREFIX = instance->INSNAME;
713 }
714
715 berinht = addht(20);
716 loconht = addht(20);
717
718 if (befig)
719 {
720 for (ptbepor = befig->BEPOR; ptbepor; ptbepor = ptbepor->NEXT)
721 {
722 ptlocon = gns_GetInstanceConnector(instance, ptbepor->NAME);
723 addhtitem(loconht, ptbepor, (long)ptlocon);
724 }
725 for (ptbevectpor = befig->BEVECTPOR; ptbevectpor; ptbevectpor = ptbevectpor->NEXT)
726 {
727 ptlocon = gns_GetInstanceConnector(instance, gns_Vectorize(ptbevectpor->NAME, ptbevectpor->LEFT));
728 addhtitem(loconht, ptbevectpor, (long)ptlocon);
729 }
730
731 /* prefix internal nodes with instance name and rename ports according to rule port map */
732
733 if (BEGAPI_DRIVE_CORRESP) /* trace changes */
734 before_change = begGetNames(befig);
735 else
736 before_change = NULL;
737
738 BEGAPI_DONEHT = addht(40);
739 beh_namewrap(befig,begNameWrap);
740 delht(BEGAPI_DONEHT);
741 BEGAPI_DONEHT = NULL;
742
743 for (ptberin = befig->BERIN; ptberin; ptberin = ptberin->NEXT)
744 addhtitem(berinht,ptberin->NAME,(long)ptberin);
745
746 for (ptbepor = befig->BEPOR; ptbepor; ptbepor = ptbepor->NEXT)
747 {
748 if (!(ptlocon = (locon_list *)gethtitem(loconht, ptbepor)))
749 {
750 char buf[1024];
751
752 sscanf(ptbepor->NAME,"%*[^.].%s",buf);
753 newname = namealloc(buf);
754 }
755 else
756 newname = (char *)ptlocon->SIG->NAMECHAIN->DATA;
757 ptberin = (berin_list *)gethtitem(berinht, ptbepor->NAME);
758 if (ptberin == (berin_list *)EMPTYHT)
759 ptberin = NULL;
760 beh_renameport(befig,ptbepor,ptberin,newname);
761 }
762
763 for (ptbevectpor = befig->BEVECTPOR; ptbevectpor; ptbevectpor = ptbevectpor->NEXT)
764 {
765 left = ptbevectpor->LEFT;
766 ptlocon = (locon_list *)gethtitem(loconht, ptbevectpor);
767 leftsigname = (char *)ptlocon->SIG->NAMECHAIN->DATA;
768 shift = vectorindex(leftsigname) - left;
769 ptberin = (berin_list *)gethtitem(berinht, ptbevectpor->NAME);
770 if (ptberin == (berin_list *)EMPTYHT)
771 ptberin = NULL;
772 newname = vectorradical(leftsigname);
773 beh_renamevectport(befig, ptbevectpor, ptberin, newname, shift);
774 }
775
776 if (BEGAPI_DRIVE_CORRESP)
777 {
778 after_change = begGetNames(befig);
779 if (corTblIns!=NULL)
780 begUpdateChanges(corTblIns,corTbl,before_change,after_change);
781 else
782 avt_errmsg(BEG_API_ERRMSG, "002", AVT_WARNING, insname);
783 // avt_error("begapi", 6, AVT_WAR,"could not find correspondance for instance '%s'\n",insname);
784 before_change = NULL;
785 after_change = NULL;
786 }
787 else
788 after_change = NULL;
789
790 if (corTblIns)
791 {
792 mbv_freeht(corTblIns); //delht(corTblIns);
793 begGetCorrespHTUnlink(befig->NAME);
794 }
795 /* if (befig->USER)
796 befig->USER = delptype(befig->USER,BEG_CORRESP_PTYPE);
797 */
798 freechain(before_change);
799 freechain(after_change);
800
801 /* merge into figure under construction */
802 if (!DEACTIVATE_BEG)
803 beg_eat_figure(befig);
804 else
805 beh_frebefig(befig);
806 }
807 delht(berinht);
808 delht(loconht);
809 }
810
811 /*}}}************************************************************************/
812 /*{{{ */
813 /* */
814 /* */
815 /****************************************************************************/
816 static void addInstance(loins_list *loins, ht *corht, ht *fight, ht *sight)
817 {
818 // in this case fight and sight are unused and should be NULL so
819 fight = NULL;
820 sight = NULL;
821 begAddInstanceModel(loins,corht);
822 }
823
824 /*}}}************************************************************************/
825 /*{{{ */
826 /* */
827 /* */
828 /****************************************************************************/
829 void begAddAllInstanceModels(int compact)
830 {
831 lofig_list *hierlofig;
832 befig_list *befig;
833 int mode=1;
834 char *name, *insname;
835
836 if (DEACTIVATE_BEG && BEGAPI_DRIVE_CORRESP==0) return;
837
838 if (DEACTIVATE_BEG)
839 mode|=DISABLE_CREATE_BEH;
840
841 if (BEGAPI_DRIVE_CORRESP==0)
842 mode|=DISABLE_CREATE_COR;
843
844 if (!compact)
845 mode|=DISABLE_COMPACT;
846
847 name=_BegGetName();
848 if ((befig = begGetModel(name))==NULL)
849 befig = beg_get_befig(BEG_NOVERIF);
850
851 hierlofig = CUR_HIER_LOFIG; //gns_GetNetlist();
852 // befig = beg_get_befig(BEG_NOVERIF);
853 beg_addAllInstances(gns_GetCurrentInstance(), befig,hierlofig->LOINS,NULL,NULL,mode,addInstance);
854 }
855
856 /*}}}************************************************************************/
857 /*{{{ */
858 /* */
859 /* */
860 /****************************************************************************/
861 char *createName(char *name, int i, char *prefix)
862 {
863 char buf[1024];
864
865 if (strncasecmp(name,"ext@",4)==0) return namealloc(name);
866 if (prefix)
867 if (i > -1)
868 sprintf(buf,"%s.%s %d",prefix,name,i);
869 else
870 sprintf(buf,"%s.%s",prefix,name);
871 else if (i > -1)
872 sprintf(buf,"%s %d",name,i);
873 else
874 sprintf(buf,"%s",name);
875
876 return namealloc(buf);
877 }
878
879 /*}}}************************************************************************/
880 /*{{{ */
881 /* */
882 /* */
883 /****************************************************************************/
884 static void putCorList4Yagle(befig_list *befig, char *prefix)
885 {
886 locon_list *locon;
887 losig_list *sig;
888 char *unprefixed_name, *model_name, *circuit_name;
889 int left, right, inc, i;
890 chain_list *loconlist, *chainx;
891 ptype_list *renamed;
892
893 loconlist = gns_GetModelConnectorList();
894 renamed = NULL;
895 for (chainx = loconlist; chainx; chainx = chainx->NEXT)
896 {
897 locon = (locon_list *)chainx->DATA;
898 gns_GetModelSignalRange(locon->NAME,&left,&right);
899 if (left != -1)
900 {
901 inc = (right >= left) ? 1 : -1;
902 for (i = left; i != right+inc; i += inc)
903 {
904 unprefixed_name = createName(locon->NAME,i,NULL);
905
906 sig = gns_GetCorrespondingSignal(unprefixed_name);
907 if (prefix != NULL)
908 model_name = createName(locon->NAME,i,prefix);
909 else
910 model_name = unprefixed_name;
911
912 circuit_name = sig->NAMECHAIN->DATA;
913 renamed = addptype(renamed,(long)model_name,circuit_name);
914 }
915 }
916 else
917 {
918 sig = gns_GetCorrespondingSignal(locon->NAME);
919 if (prefix != NULL)
920 model_name = createName(locon->NAME,-1,prefix);
921 else
922 model_name = locon->NAME;
923
924 circuit_name = sig->NAMECHAIN->DATA;
925 renamed = addptype(renamed,(long)model_name,circuit_name);
926 }
927 }
928 befig->USER = addptype(befig->USER,BEG_RENAME_LIST,renamed);
929
930 freechain(loconlist);
931 }
932
933 /*}}}************************************************************************/
934 /*{{{ */
935 /* */
936 /* */
937 /****************************************************************************/
938 void begRenameSignalsFromModel(void)
939 {
940 chain_list *before_change, *after_change;
941 befig_list *ptbefig;
942 ptype_list *ptype;
943 char *prefix = NULL;
944 ht *corresp_ht, *new_corresp_ht;
945
946 ptbefig = begModelToInstance(gns_GetCurrentInstance(),
947 gns_GetCurrentModel());
948 if (ptbefig == NULL)
949 return;
950
951 addhtitem(BEG_MODELHT, ptbefig->NAME, (long)ptbefig);
952
953 if (BEGAPI_DRIVE_CORRESP)
954 {
955 corresp_ht=begGetCorrespHT(ptbefig->NAME);
956 new_corresp_ht = addht(BEGAPI_HT_BASE);
957 begGetCorrespHTRelink(ptbefig->NAME, new_corresp_ht);
958 /* if ((ptype = getptype(ptbefig->USER,BEG_CORRESP_PTYPE)))
959 {
960 corresp_ht = (ht*)((chain_list*)ptype->DATA)->DATA;
961 new_corresp_ht = addht(BEGAPI_HT_BASE);
962 ((chain_list*)ptype->DATA)->DATA = new_corresp_ht;
963 }
964 */
965 before_change = begGetNames(ptbefig);
966 }
967
968 if (ptbefig != NULL)
969 {
970 prefix = ptbefig->NAME;
971 BEGAPI_PREFIX = prefix;
972 BEGAPI_INDEX = -1;
973 BEGAPI_BEFIG = ptbefig;
974 beh_namewrap(ptbefig,begNameWrap);
975 ptbefig->NAME = prefix;
976 }
977
978 if (BEGAPI_DRIVE_CORRESP)
979 {
980 after_change = begGetNames(ptbefig);
981 begUpdateChanges(corresp_ht,new_corresp_ht,before_change,after_change);
982 before_change = NULL;
983 after_change = NULL;
984 mbv_freeht(corresp_ht); //delht(corresp_ht);
985 }
986
987 putCorList4Yagle(ptbefig,prefix);
988 }
989
990 /**************************************************************************************/
991
992 #define tops(x) (int)(x>=0.9?x+0.5:x*1e12+0.5)
993 void
994 begAssign_sub(char *name, char *expr, double delay, double delayr, double delayf, char *delayvar, int flags)
995 {
996 delayvar = NULL; // WARNING PREVENTION
997
998 if (DEACTIVATE_BEG && BEGAPI_DRIVE_CORRESP==0) return;
999
1000 if (BEG_TRACE)
1001 fprintf(stdout," signal %s <%s>\n",name,
1002 gns_GetSignalName(gns_GetCorrespondingSignal(name)));
1003
1004 if (BEGAPI_DRIVE_CORRESP)
1005 begAddCorresp(gns_GetCurrentInstance(), name);
1006
1007 if (!DEACTIVATE_BEG)
1008 beg_def_sig(name, expr, tops(delay),tops(delayr),tops(delayf), getbiablflag(flags));
1009 }
1010 void
1011 begAssign(char *name, char *expr, int delay, char *delayvar)
1012 {
1013 begAssign_sub(name, expr, delay*1e-12, 0, 0, delayvar, 0);
1014 }
1015
1016 /**************************************************************************************/
1017
1018 void
1019 begAddBusDriver_sub(char *name, char *condition, char *value, double delay, double delayr, double delayf, char *delayvar, int flags)
1020 {
1021 biabl_list *ptbiabl;
1022
1023 if (BEG_TRACE)
1024 fprintf(stdout, " signal %s <%s>\n",name,
1025 gns_GetSignalName(gns_GetCorrespondingSignal(name)));
1026
1027 if (BEGAPI_DRIVE_CORRESP)
1028 begAddCorresp(gns_GetCurrentInstance(), name);
1029
1030 if (DEACTIVATE_BEG) return;
1031
1032 ptbiabl = beg_def_process(name, condition, value, tops(delay), tops(delayr), tops(delayf), BEG_BUS,getsigflag(flags)|BEH_FLAG_FORCEBUS,getbiablflag(flags));
1033 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1034 begRefDriver(delayvar, ptbiabl);
1035 }
1036 /* biabl_list *ptbiabl;
1037
1038 ptbiabl = beg_def_mux(name, condition, NULL, value, delay);
1039 if (delayvar != NULL) {
1040 begRefDriver(delayvar, ptbiabl);
1041 }*/
1042 }
1043 void
1044 begAddBusDriver(char *name, char *condition, char *value, int delay, char *delayvar)
1045 {
1046 begAddBusDriver_sub(name, condition, value, delay*1e-12, 0, 0, delayvar, 0);
1047 }
1048
1049 /**************************************************************************************/
1050
1051 void
1052 begAddBusElse_sub(char *name, char *condition, char *value, double delay, double delayr, double delayf, char *delayvar, int flags)
1053 {
1054 biabl_list *ptbiabl;
1055
1056 if (BEG_TRACE)
1057 fprintf(stdout, " signal %s <%s>\n",name,
1058 gns_GetSignalName(gns_GetCorrespondingSignal(name)));
1059
1060 if (BEGAPI_DRIVE_CORRESP)
1061 begAddCorresp(gns_GetCurrentInstance(), name);
1062
1063 if (DEACTIVATE_BEG) return;
1064
1065 ptbiabl = beg_def_process(name, condition, value, tops(delay), tops(delayr), tops(delayf), BEG_BUS|BEG_PRE,getsigflag(flags)|BEH_FLAG_FORCEBUS,getbiablflag(flags));
1066 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1067 begRefDriver(delayvar, ptbiabl);
1068 }
1069 }
1070 void
1071 begAddBusElse(char *name, char *condition, char *value, int delay, char *delayvar)
1072 {
1073 begAddBusElse_sub(name, condition, value, delay*1e-12, 0, 0, delayvar, 0);
1074 }
1075 /**************************************************************************************/
1076
1077 void
1078 begAddSelectDriver(char *name, char *select, char *when ,char *value, int delay, char *delayvar)
1079 {
1080 biabl_list *ptbiabl;
1081
1082 if (DEACTIVATE_BEG) return;
1083
1084 ptbiabl = beg_def_mux(name, select, when, value, delay,0,0);
1085 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1086 begRefDriver(delayvar, ptbiabl);
1087 }
1088 }
1089
1090 /**************************************************************************************/
1091 void
1092 begAddBusDriverLoop(char *name, char *condition, char *value, char *loopvar, int delay, char *delayvar)
1093 {
1094 biabl_list *ptbiabl;
1095
1096 if (DEACTIVATE_BEG) return;
1097
1098 ptbiabl = beg_def_loop(name, condition, value, loopvar, delay, 0,0,0);
1099 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1100 begRefDriver(delayvar, ptbiabl);
1101 }
1102 }
1103
1104 /**************************************************************************************/
1105 void
1106 begAddBusDriverDoubleLoop(char *name, char *condition, char *value, char *loopvar1, char *loopvar2, int delay, char *delayvar)
1107 {
1108 biabl_list *ptbiabl;
1109
1110 if (DEACTIVATE_BEG) return;
1111
1112 ptbiabl = beg_def_biloop(name, condition, value, loopvar1, loopvar2, delay, 0,0,0);
1113 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1114 begRefDriver(delayvar, ptbiabl);
1115 }
1116 }
1117
1118 /**************************************************************************************/
1119
1120 void
1121 begAddMemDriver_sub(char *name, char *condition, char *value, double delay, double delayr, double delayf, char *delayvar,int flags)
1122 {
1123 biabl_list *ptbiabl;
1124
1125 if (BEG_TRACE)
1126 fprintf(stdout, " signal %s <%s>\n",name,
1127 gns_GetSignalName(gns_GetCorrespondingSignal(name)));
1128
1129 if (BEGAPI_DRIVE_CORRESP)
1130 begAddCorresp(gns_GetCurrentInstance(), name);
1131
1132 if (DEACTIVATE_BEG) return;
1133
1134 ptbiabl = beg_def_process(name, condition, value, tops(delay), tops(delayr), tops(delayf), BEG_REG,getsigflag(flags),getbiablflag(flags));
1135 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1136 begRefDriver(delayvar, ptbiabl);
1137 }
1138 }
1139
1140 void
1141 begAddMemDriver(char *name, char *condition, char *value, int delay, char *delayvar)
1142 {
1143 begAddMemDriver_sub(name, condition, value, delay*1e-12, 0, 0, delayvar, 0);
1144 }
1145 /**************************************************************************************/
1146
1147 void
1148 begAddMemDriverLoop(char *name, char *condition, char *value, char *loopvar, int delay, char *delayvar)
1149 {
1150 biabl_list *ptbiabl;
1151
1152 if (DEACTIVATE_BEG) return;
1153
1154 ptbiabl = beg_def_loop(name, condition, value, loopvar, delay, BEG_REG,0,0);
1155 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1156 begRefDriver(delayvar, ptbiabl);
1157 }
1158 }
1159
1160 /**************************************************************************************/
1161
1162 void
1163 begAddMemDriverDoubleLoop(char *name, char *condition, char *value, char *loopvar1, char *loopvar2, int delay, char *delayvar)
1164 {
1165 biabl_list *ptbiabl;
1166
1167 if (DEACTIVATE_BEG) return;
1168
1169 ptbiabl = beg_def_biloop(name, condition, value, loopvar1, loopvar2, delay, BEG_REG,0,0);
1170 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1171 begRefDriver(delayvar, ptbiabl);
1172 }
1173 }
1174
1175 /**************************************************************************************/
1176
1177 void
1178 begAddMemElse_sub(char *name, char *condition, char *value, double delay, double delayr, double delayf, char *delayvar, int flags)
1179 {
1180 biabl_list *ptbiabl;
1181
1182 if (BEG_TRACE)
1183 fprintf(stdout, " signal %s <%s>\n",name,
1184 gns_GetSignalName(gns_GetCorrespondingSignal(name)));
1185
1186 if (BEGAPI_DRIVE_CORRESP)
1187 begAddCorresp(gns_GetCurrentInstance(), name);
1188
1189 if (DEACTIVATE_BEG) return;
1190
1191 ptbiabl = beg_def_process(name, condition, value, tops(delay), tops(delayr), tops(delayf), BEG_REG|BEG_PRE,getsigflag(flags),getbiablflag(flags));
1192 if (delayvar != NULL && strcmp(delayvar,"NULL")!=0) {
1193 begRefDriver(delayvar, ptbiabl);
1194 }
1195 }
1196
1197 void
1198 begAddMemElse(char *name, char *condition, char *value, int delay, char *delayvar)
1199 {
1200
1201 begAddMemElse_sub(name, condition, value, delay*1e-12, 0, 0, delayvar, 0);
1202 }
1203 /**************************************************************************************/
1204
1205 void
1206 begAddWarningCheck(char *testexpr, char *message)
1207 {
1208 if (DEACTIVATE_BEG) return;
1209
1210 beg_assertion(testexpr, message, 'W', NULL);
1211 }
1212
1213 /**************************************************************************************/
1214
1215 void
1216 begAddErrorCheck(char *testexpr, char *message)
1217 {
1218 if (DEACTIVATE_BEG) return;
1219
1220 beg_assertion(testexpr, message, 'E', NULL);
1221 }
1222
1223 /**************************************************************************************/
1224
1225 void
1226 begSort()
1227 {
1228 if (DEACTIVATE_BEG) return;
1229
1230 beg_sort();
1231 }
1232
1233 /**************************************************************************************/
1234
1235 void
1236 begCompact()
1237 {
1238 chain_list *ptchain, *ptchain0;
1239 chain_list *refchain, *newrefchain;
1240 biabl_list *ptdriver;
1241 char *varname;
1242
1243 if (DEACTIVATE_BEG) return;
1244
1245 beg_compact();
1246 #if 0
1247 for (ptchain = BEGAPI_INTVARLIST; ptchain; ptchain = ptchain->NEXT) {
1248 varname = (char *)ptchain->DATA;
1249 refchain = (chain_list *)gethtitem(BEGAPI_INTVARHT, varname);
1250 newrefchain = NULL;
1251 for (ptchain0 = refchain; ptchain0; ptchain0 = ptchain0->NEXT) {
1252 ptdriver = (biabl_list *)ptchain0->DATA;
1253 if (!beg_isDeletedBiabl(ptdriver)) newrefchain = addchain(newrefchain, ptdriver);
1254 }
1255 freechain(refchain);
1256 sethtitem(BEGAPI_INTVARHT, varname, (long)newrefchain);
1257 }
1258 #endif
1259 }
1260
1261 /**************************************************************************************/
1262
1263 void
1264 begSetDelay(char *varname, int value)
1265 {
1266 chain_list *varchain;
1267 biabl_list *ptdriver;
1268
1269 if (DEACTIVATE_BEG) return;
1270
1271 if (BEH_TIMEVARS==NULL) BEH_TIMEVARS=addht(32);
1272 if (value<0) value=0;
1273 addhtitem(BEH_TIMEVARS, namealloc(varname), (long)value);
1274
1275 #if 0
1276 if ((varchain = (chain_list *)gethtitem(BEGAPI_INTVARHT, namealloc(varname))) != (void *)EMPTYHT) {
1277 for (;varchain; varchain = varchain->NEXT) {
1278 ptdriver = (biabl_list *)varchain->DATA;
1279 ptdriver->TIME = value;
1280 }
1281 }
1282 else {
1283 avt_errmsg(BEG_API_ERRMSG, "003", AVT_WARNING, varname);
1284 // avt_error("begapi", 2, AVT_WAR, "delay variable '%s' does not exist\n", varname);
1285 }
1286 #endif
1287 }
1288
1289 /**************************************************************************************/
1290
1291 void
1292 begBuildModel()
1293 {
1294 char *name;
1295
1296 name=_BegGetName();
1297 if (BEG_CHECK_EXISTENCE(name)==0)
1298 {
1299 begCreateModelInterface(name);
1300 begAddAllInstanceModels(0);
1301 }
1302 else
1303 begAddAllInstanceModels(0);
1304 begKeepModel();
1305 }
1306
1307 /**************************************************************************************/
1308
1309 void
1310 begBuildModelUsingFiles(char *name)
1311 {
1312 BEGAPI_USEFILES = 1;
1313 begBuildModel(name);
1314 BEGAPI_USEFILES = 0;
1315 }
1316
1317 /**************************************************************************************/
1318
1319 void
1320 begBuildCompactModel()
1321 {
1322 char *name;
1323 name=_BegGetName();
1324 if (BEG_CHECK_EXISTENCE(name)==0)
1325 {
1326 begCreateModelInterface(name);
1327 begAddAllInstanceModels(1);
1328 begSort();
1329 begCompact();
1330 }
1331 else
1332 begAddAllInstanceModels(1);
1333 begKeepModel();
1334 }
1335
1336 /**************************************************************************************/
1337
1338 void
1339 begBuildCompactModelUsingFiles(char *name)
1340 {
1341 BEGAPI_USEFILES = 1;
1342 begBuildCompactModel(name);
1343 BEGAPI_USEFILES = 0;
1344 }
1345
1346 /**************************************************************************************/
1347
1348 void
1349 begBiterize()
1350 {
1351 befig_list *ptbefig;
1352 char figname[1024], *name;
1353
1354 if (DEACTIVATE_BEG) return;
1355
1356 ptbefig = beg_get_befig(BEG_NOVERIF);
1357 if (ptbefig != NULL)
1358 {
1359 name = ptbefig->NAME;
1360 ptbefig = beh_duplicate(ptbefig);
1361 sprintf(figname,"%s_duplicated",name);
1362 ptbefig->NAME = namealloc(figname);
1363 savebefig(ptbefig, 0);
1364
1365 beh_biterize(ptbefig);
1366 sprintf(figname,"%s_biterized",name);
1367 ptbefig->NAME = namealloc(figname);
1368 savebefig(ptbefig, 0);
1369
1370 beh_frebefig(ptbefig);
1371 }
1372 }
1373
1374 /**************************************************************************************/
1375
1376 void begExport(char *name)
1377 {
1378 befig_list *bf, *bf0;
1379
1380 name=namealloc(name);
1381
1382 if (begGetModel(name)==NULL) {
1383 bf0=beg_get_befig(BEG_NOVERIF);
1384 if (bf0!=NULL) {
1385 bf=beh_duplicate(bf0);
1386 if (BEGAPI_DRIVE_CORRESP)
1387 begTransfertCorresp(name, gns_GetCurrentInstance(), 0);
1388
1389 bf->NAME=name;
1390 // savebefig(bf, 0);
1391 addhtitem(BEG_MODELHT, bf->NAME, (long)bf);
1392 }
1393 else
1394 avt_errmsg(BEG_API_ERRMSG, "004", AVT_WARNING, name);
1395 // avt_error("begapi", 5, AVT_WAR,"could not export behaviour '%s'. Current instance behaviour is not created yet\n",name);
1396 }
1397 else
1398 avt_errmsg(BEG_API_ERRMSG, "005", AVT_WARNING, name);
1399 // avt_error("begapi", 4, AVT_WAR,"behaviour '%s' already exists\n",name);
1400 }
1401
1402 /**************************************************************************************/
1403
1404 void begImport(char *name)
1405 {
1406 befig_list *bf, *bf0;
1407 int update=0;
1408 char *mname;
1409
1410 name=namealloc(name);
1411 mname=_BegGetName();
1412
1413 if (BEGAPI_DRIVE_CORRESP)
1414 {
1415 if (CUR_CORRESP_TABLE->FLAGS & LOINS_IS_BLACKBOX) update=1;
1416 begTransfertCorresp(gns_GetCurrentInstance(), name, update);
1417 }
1418
1419 if (BEG_CHECK_EXISTENCE(mname))
1420 {
1421 _begKeepModel(0);
1422 return;
1423 }
1424
1425 if ((bf0=begGetModel(name))!=NULL)
1426 {
1427 begCreateInterface();
1428 bf=beh_duplicate(bf0);
1429 // to avoid destruction of the model correspondance table
1430 bf->NAME=namealloc("temporary_figure_for_import");
1431 // savebefig(bf, 0);
1432 beg_eat_figure(bf);
1433 _begKeepModel(0);
1434 }
1435 else
1436 avt_errmsg(BEG_API_ERRMSG, "006", AVT_WARNING, name);
1437 // avt_error("begapi", 3, AVT_WAR,"could not import behaviour '%s'. It does not exist\n",name);
1438 }
1439
1440 /**************************************************************************************/