1 /****************************************************************************/
3 /* Chaine de CAO & VLSI AVERTEC */
5 /* Produit : Structural Verilog Compiler */
6 /* Fichier : mgl_util.c */
8 /* (c) copyright 2000 AVERTEC */
9 /* Tous droits reserves */
11 /* Auteur(s) : Anthony LESTER */
14 /****************************************************************************/
25 #include "mgl_parse.h"
27 #include "mgl_error.h"
29 static struct dct_entry
*MGL_DCEHED
; /* free dct_entry's head */
30 static struct dct_recrd
*MGL_DCRHED
; /* free dct_recrd's head */
32 static struct dct_entry
*mgl_addent(struct dct_entry
*head
, char *key
);
33 static struct dct_recrd
*mgl_addrcd(struct dct_recrd
*head
, char *key
);
35 // copie de mbk_util.c
36 #define HASH_MULT 314159
37 #define HASH_PRIME 516595003
39 static int HASH_FUNC(char *inputname
, char *name
, int code
)
43 /*if (CASE_SENSITIVE == 'N') *name = tolowertable[(int)*inputname++];
44 else*/ *name
= *inputname
++;
45 code
+= (code
^ (code
>> 1)) + HASH_MULT
* (unsigned char) *name
++;
46 while (code
>= HASH_PRIME
)
57 /* ###--------------------------------------------------------------### */
58 /* function : mgl_deltab */
59 /* ###--------------------------------------------------------------### */
62 mgl_deltab(struct dct_entry
**head
, char *key_str
, char *ctx_str
)
66 struct dct_entry
*entry_pnt
;
67 struct dct_entry
*last_entry
= NULL
;
68 struct dct_recrd
*recrd_pnt
;
69 struct dct_recrd
*last_recrd
= NULL
;
72 // par Fabrice le 11/2/2002
73 //index = (int) key_str % MGL_HSZDFN;
74 index
=HASH_FUNC(key_str
, name
, 0);
75 entry_pnt
= head
[index
];
77 while (entry_pnt
!= NULL
) {
78 if (entry_pnt
->key
== key_str
) {
82 last_entry
= entry_pnt
;
83 entry_pnt
= entry_pnt
->next
;
88 recrd_pnt
= entry_pnt
->data
;
89 while (recrd_pnt
!= NULL
) {
90 if (recrd_pnt
->key
== ctx_str
) {
94 last_recrd
= recrd_pnt
;
95 recrd_pnt
= recrd_pnt
->next
;
99 if (last_recrd
== NULL
)
100 entry_pnt
->data
= recrd_pnt
->next
;
102 last_recrd
->next
= recrd_pnt
->next
;
104 recrd_pnt
->next
= MGL_DCRHED
;
105 MGL_DCRHED
= recrd_pnt
;
107 if (entry_pnt
->data
== NULL
) {
108 if (last_entry
== NULL
)
109 head
[index
] = entry_pnt
->next
;
111 last_entry
->next
= entry_pnt
->next
;
113 entry_pnt
->next
= MGL_DCEHED
;
114 MGL_DCEHED
= entry_pnt
;
120 /* ###--------------------------------------------------------------### */
121 /* function : mgl_initab */
122 /* ###--------------------------------------------------------------### */
126 struct dct_entry
**head
;
129 head
= (struct dct_entry
**)
130 mbkalloc(sizeof(struct dct_entry
*) * MGL_HSZDFN
);
132 for (i
= 0; i
< MGL_HSZDFN
; i
++)
138 /* ###--------------------------------------------------------------### */
139 /* function : mgl_addtab */
140 /* ###--------------------------------------------------------------### */
142 mgl_addtab(struct dct_entry
**head
, char *key_str
, char *ctx_str
, int field
, long valu
)
146 struct dct_entry
*entry_pnt
;
147 struct dct_recrd
*recrd_pnt
;
150 // par Fabrice le 11/2/2002
151 //index = (int) key_str % MGL_HSZDFN;
152 index
=HASH_FUNC(key_str
, name
, 0);
154 entry_pnt
= head
[index
];
156 while (entry_pnt
!= NULL
) {
157 if (entry_pnt
->key
== key_str
) {
161 entry_pnt
= entry_pnt
->next
;
165 head
[index
] = mgl_addent(head
[index
], key_str
);
166 entry_pnt
= head
[index
];
170 recrd_pnt
= entry_pnt
->data
;
171 while (recrd_pnt
!= NULL
) {
172 if (recrd_pnt
->key
== ctx_str
) {
176 recrd_pnt
= recrd_pnt
->next
;
180 entry_pnt
->data
= mgl_addrcd(entry_pnt
->data
, ctx_str
);
181 recrd_pnt
= entry_pnt
->data
;
186 recrd_pnt
->fd0_val
= valu
;
189 recrd_pnt
->fd1_val
= valu
;
192 recrd_pnt
->fd2_val
= valu
;
195 recrd_pnt
->fd3_val
= valu
;
198 recrd_pnt
->fd4_val
= valu
;
201 recrd_pnt
->fd5_val
= valu
;
204 recrd_pnt
->fd6_val
= valu
;
207 recrd_pnt
->pnt_val
= valu
;
213 /* ###--------------------------------------------------------------### */
214 /* function : mgl_chktab */
215 /* ###--------------------------------------------------------------### */
217 mgl_chktab(struct dct_entry
**head
, char *key_str
, char *ctx_str
, int field
)
221 struct dct_entry
*entry_pnt
;
222 struct dct_recrd
*recrd_pnt
;
225 // par Fabrice le 11/2/2002
226 // entry_pnt = head[(int) key_str % MGL_HSZDFN];
227 entry_pnt
= head
[HASH_FUNC(key_str
, name
, 0)];
229 while (entry_pnt
!= NULL
) {
230 if (entry_pnt
->key
== key_str
) {
234 entry_pnt
= entry_pnt
->next
;
239 recrd_pnt
= entry_pnt
->data
;
240 while (recrd_pnt
!= NULL
) {
241 if (recrd_pnt
->key
== ctx_str
) {
245 recrd_pnt
= recrd_pnt
->next
;
250 valu
= recrd_pnt
->fd0_val
;
253 valu
= recrd_pnt
->fd1_val
;
256 valu
= recrd_pnt
->fd2_val
;
259 valu
= recrd_pnt
->fd3_val
;
262 valu
= recrd_pnt
->fd4_val
;
265 valu
= recrd_pnt
->fd5_val
;
268 valu
= recrd_pnt
->fd6_val
;
271 valu
= recrd_pnt
->pnt_val
;
280 /* ###--------------------------------------------------------------### */
281 /* function : mgl_fretab */
282 /* ###--------------------------------------------------------------### */
284 mgl_fretab(struct dct_entry
**pt_hash
)
286 struct dct_entry
*pt_entry
;
287 struct dct_entry
*pt_nxtentry
;
288 struct dct_recrd
*pt_record
;
291 if (pt_hash
!= NULL
) {
292 for (i
= 0; i
< MGL_HSZDFN
; i
++) {
293 if ((pt_entry
= pt_hash
[i
]) != NULL
) {
294 while (pt_entry
!= NULL
) {
295 pt_record
= pt_entry
->data
;
297 while (pt_record
->next
!= NULL
)
298 pt_record
= pt_record
->next
;
300 pt_record
->next
= MGL_DCRHED
;
301 MGL_DCRHED
= pt_entry
->data
;
303 pt_nxtentry
= pt_entry
->next
;
304 pt_entry
->next
= MGL_DCEHED
;
305 MGL_DCEHED
= pt_entry
;
306 pt_entry
= pt_nxtentry
;
314 /* ###--------------------------------------------------------------### */
315 /* function : mgl_addent */
316 /* ###--------------------------------------------------------------### */
317 static struct dct_entry
*
318 mgl_addent(struct dct_entry
*head
, char *key
)
320 struct dct_entry
*entry
;
323 if (MGL_DCEHED
== NULL
) {
324 MGL_DCEHED
= (struct dct_entry
*) mbkalloc(sizeof(struct dct_entry
) * MGL_ALODFN
);
327 for (i
= 1; i
< MGL_ALODFN
; i
++) {
328 entry
->next
= entry
+ 1;
335 MGL_DCEHED
= MGL_DCEHED
->next
;
344 /* ###--------------------------------------------------------------### */
345 /* function : mgl_addrcd */
346 /* ###--------------------------------------------------------------### */
347 static struct dct_recrd
*
348 mgl_addrcd(struct dct_recrd
*head
, char *key
)
350 struct dct_recrd
*recrd
;
353 if (MGL_DCRHED
== NULL
) {
354 MGL_DCRHED
= (struct dct_recrd
*) mbkalloc(sizeof(struct dct_recrd
) * MGL_ALODFN
);
357 for (i
= 1; i
< MGL_ALODFN
; i
++) {
358 recrd
->next
= recrd
+ 1;
365 MGL_DCRHED
= MGL_DCRHED
->next
;
381 /* ###--------------------------------------------------------------### */
382 /* function : mgl_avers */
383 /* ###--------------------------------------------------------------### */
387 return ("-- V 1.0 --");
390 /* ###--------------------------------------------------------------### */
391 /* function : mgl_vlgname */
392 /* ###--------------------------------------------------------------### */
394 mgl_vlgname(char *name
)
400 int i
, j
, flag
, number
;
401 static struct dct_entry
**namtab
= NULL
;
404 namtab
= mgl_initab();
406 tmp_name
= namealloc(name
);
407 new_name
= (char *) mgl_chktab(namtab
, tmp_name
, NULL
, MGL_PNTDFN
);
409 if (mgl_chktab(namtab
, tmp_name
, NULL
, MGL_NAMDFN
) == 0) {
414 while (tmp_name
[i
] != '\0') {
415 buffer
[j
] = tmp_name
[i
];
416 if (((tmp_name
[i
] >= 'a') && (tmp_name
[i
] <= 'z')) ||
417 ((tmp_name
[i
] >= 'A') && (tmp_name
[i
] <= 'Z')) ||
418 ((tmp_name
[i
] >= '0') && (tmp_name
[i
] <= '9') && (i
!= 0)) ||
419 ((tmp_name
[i
] == '(') || (tmp_name
[i
] == ')'))) {
422 else if ((tmp_name
[i
] >= '0') && (tmp_name
[i
] <= '9') && (i
== 0)) {
423 strcpy(&buffer
[j
], "noname");
425 buffer
[j
] = tmp_name
[i
];
436 if (buffer
[j
- 1] == '_')
439 new_name
= namealloc(buffer
);
442 while (mgl_chktab(namtab
, new_name
, NULL
, MGL_NEWDFN
) != 0) {
444 sprintf(buffer
, "%s_%d", new_name
, number
++);
446 new_name
= namealloc(buffer
);
448 mgl_addtab(namtab
, new_name
, NULL
, MGL_NEWDFN
, 1);
449 mgl_addtab(namtab
, tmp_name
, NULL
, MGL_PNTDFN
, (long) new_name
);
450 mgl_addtab(namtab
, tmp_name
, NULL
, MGL_NAMDFN
, 1);
457 /* ###--------------------------------------------------------------### */
458 /* function : mgl_treatname */
459 /* ###--------------------------------------------------------------### */
461 mgl_treatname(char *name
, char *new_name
)
465 /* Transformation des blancs en parentheses */
466 strcpy(new_name
, name
);
467 blank_space
= strchr(new_name
, ' ');
468 if (blank_space
!= NULL
) {
470 blank_space
= strchr(new_name
, '\0');
471 /* Transformation du dernier caractere en ) */
472 if (blank_space
!= NULL
) {
478 strcpy(new_name
, mgl_vlgname(new_name
));
481 /* ###--------------------------------------------------------------### */
482 /* function : mgl_vectnam */
483 /* ###--------------------------------------------------------------### */
485 mgl_vectnam(void *pt_list
, int *left
, int *right
, char **name
, char type
)
495 /* Case losig_list */
497 ptsig
= (losig_list
*) pt_list
;
498 if (ptsig
->TYPE
== 'I') {
500 sig_name
= getsigname(ptsig
);
501 *name
= (char *) mbkalloc(strlen(sig_name
) + 1);
502 strcpy(*name
, sig_name
);
503 blank_space
= strchr(*name
, ' ');
504 if (blank_space
!= NULL
) {
505 strcpy(number
, blank_space
);
506 *right
= atoi(number
);
512 if (ptsig
->NEXT
!= NULL
) {
513 strcpy(name_tmp
, getsigname(ptsig
->NEXT
));
514 blank_space
= strchr(name_tmp
, ' ');
515 if (blank_space
!= NULL
) {
516 strcpy(number
, blank_space
);
518 if (!strcmp(*name
, name_tmp
)) {
519 *left
= atoi(number
);
538 ptcon
= (locon_list
*) pt_list
;
539 /* Extract the name and number of an element */
541 sig_name
= ptcon
->NAME
;
542 *name
= (char *) mbkalloc(strlen(sig_name
) + 1);
543 strcpy(*name
, sig_name
);
544 blank_space
= strchr(*name
, ' ');
545 if (blank_space
!= NULL
) {
546 strcpy(number
, blank_space
);
547 *right
= atoi(number
);
553 if (ptcon
->NEXT
!= NULL
) {
554 strcpy(name_tmp
, ptcon
->NEXT
->NAME
);
555 blank_space
= strchr(name_tmp
, ' ');
556 if (blank_space
!= NULL
) {
557 strcpy(number
, blank_space
);
559 if (!strcmp(*name
, name_tmp
)) {
560 *right
= atoi(number
);
571 /* To avoid Warning from GCC */
575 /* ###--------------------------------------------------------------### */
576 /* function : mgl_fill */
577 /* content : Fill a lofig of mode 'P' with another lofig of mode 'A' */
578 /* ###--------------------------------------------------------------### */
580 mgl_fill(struct lofig
*lofig_P
, struct lofig
*lofig_A
)
582 struct locon
*ptlocon_P
, *ptlocon_A
;
583 struct chain
*ptchain
;
584 struct lofig
*ptlofig
;
585 struct losig
*ptlosig
;
588 ptchain
= lofig_P
->MODELCHAIN
;
589 lofig_P
->MODELCHAIN
= lofig_A
->MODELCHAIN
;
592 ptlocon_P
= lofig_P
->LOCON
;
593 ptlocon_A
= lofig_A
->LOCON
;
595 while (ptlocon_A
!= NULL
) {
596 if (ptlocon_A
->NAME
== ptlocon_P
->NAME
) {
597 ptlocon_P
->SIG
= ptlocon_A
->SIG
;
602 "\n*** mbk error *** bad consistency in figure %s,\n external interface are different\n",
605 ptlocon_A
= ptlocon_A
->NEXT
;
606 ptlocon_P
= ptlocon_P
->NEXT
;
610 ptlosig
= lofig_P
->LOSIG
;
611 lofig_P
->LOSIG
= lofig_A
->LOSIG
;
614 lofig_P
->LOINS
= lofig_A
->LOINS
;
617 lofig_P
->LOTRS
= lofig_A
->LOTRS
;
620 lofig_P
->USER
= lofig_A
->USER
;
625 /* Freeing the memory zone unusable */
629 while (lofig_A
->LOCON
!= NULL
) {
630 dellocon(lofig_A
, lofig_A
->LOCON
->NAME
);
633 ptlofig
= addlofig(" bidon");
634 ptlofig
->LOSIG
= ptlosig
;
635 dellofig(ptlofig
->NAME
);
640 /* ###--------------------------------------------------------------### */
641 /* function : mgl_addlosig */
642 /* description : create one or more losig structures (for an array a */
643 /* losig is created for each bit) */
644 /* called func. : addlosig, addchain */
645 /* ###--------------------------------------------------------------### */
648 mgl_addlosig(lofig_list
*ptfig
, int index
, char type
, char ptype
, char *name
, int left
, int right
)
653 struct chain
*pt_chlst
;
656 if ((left
== -1) && (right
== -1)) {
657 pt_chlst
= addchain(NULL
, name
);
658 ptsig
= addlosig(ptfig
, index
, pt_chlst
, type
);
661 ptsig
->USER
= addptype(ptsig
->USER
, ptype
, NULL
);
664 if (left
>= right
) /* array */
667 for (i
= left
; i
!= (right
+ inc
); i
+= inc
) {
668 if (MBK_DEVECT
) sprintf(extname
, "%s %d", name
, i
);
669 else sprintf(extname
, "%s[%d]", name
, i
);
670 pt_chlst
= addchain(NULL
, extname
);
671 ptsig
= addlosig(ptfig
, index
, pt_chlst
, type
);
674 ptsig
->USER
= addptype(ptsig
->USER
, ptype
, NULL
);
682 /* ###--------------------------------------------------------------### */
683 /* function : mgl_addlocon */
684 /* description : create one or more locon structures (for an array a */
685 /* locon is created for each bit) */
686 /* called func. : addlocon, addchain */
687 /* ###--------------------------------------------------------------### */
690 mgl_addlocon(lofig_list
*ptfig
, losig_list
*ptsig
, char dir
, char *name
, int left
, int right
)
696 struct locon
*ptcontmp
;
698 if ((left
== -1) && (right
== -1)) {
699 ptcon
= addlocon(ptfig
, name
, ptsig
, dir
);
705 for (i
= left
; i
!= (right
+ inc
); i
+= inc
) {
706 if (MBK_DEVECT
) sprintf(extname
, "%s %d", name
, i
);
707 else sprintf(extname
, "%s[%d]", name
, i
);
708 ptcon
= addlocon(ptfig
, extname
, NULL
, dir
);
713 for (i
= left
; i
!= (right
+ inc
); i
+= inc
) {
714 ptcontmp
->SIG
= ptsig
;
715 ptcontmp
= ptcontmp
->NEXT
;
723 /* ###--------------------------------------------------------------### */
724 /* function : mgl_orientlocon */
725 /* description : create one or more locon structures (for an array a */
726 /* locon is created for each bit) */
727 /* called func. : addlocon, addchain */
728 /* ###--------------------------------------------------------------### */
730 void mgl_clean_lorcnet(lofig_list
*ptfig
)
734 for (ls
=ptfig
->LOSIG
; ls
!=NULL
; ls
=ls
->NEXT
)
736 if (ls
->PRCN
) freelorcnet(ls
);
742 mgl_orientlocon(lofig_list
*ptfig
, char dir
, char *name
, int left
, int right
)
749 if ((left
== -1) && (right
== -1)) {
750 ptcon
= getlocon(ptfig
, name
);
751 ptcon
->DIRECTION
= dir
;
757 for (i
= left
; i
!= (right
+ inc
); i
+= inc
) {
758 if (MBK_DEVECT
) sprintf(extname
, "%s %d", name
, i
);
759 else sprintf(extname
, "%s[%d]", name
, i
);
760 ptcon
= getlocon(ptfig
, extname
);
761 ptcon
->DIRECTION
= dir
;
767 /* ###--------------------------------------------------------------### */
768 /* function : mgl_getlosig */
769 /* ###--------------------------------------------------------------### */
772 mgl_getlosig(lofig_list
*ptfig
, char *name
, struct dct_entry
**hshtab
, mgl_scompcontext
*context
)
778 int left
, right
, index
;
781 if ((radical
= vectorradical(name
)) == name
) {
782 ptlosig
= (losig_list
*)mgl_chktab(hshtab
, name
, ptfig
->NAME
, MGL_PNTDFN
);
785 ptlosig
= (losig_list
*)mgl_chktab(hshtab
, radical
, ptfig
->NAME
, MGL_PNTDFN
);
786 left
= mgl_chktab(hshtab
, radical
, ptfig
->NAME
, MGL_LFTDFN
);
787 right
= mgl_chktab(hshtab
, radical
, ptfig
->NAME
, MGL_RGTDFN
);
788 index
= vectorindex(name
);
790 sprintf(extname
, "%s[%d]", radical
, index
);
791 name
= namealloc(extname
);
793 if ((index
<= left
&& index
>= right
) || (index
<= right
&& index
>= left
)) {
794 count
= abs(index
- right
);
795 while (count
-- > 0 && ptlosig
!= NULL
) ptlosig
= ptlosig
->NEXT
;
797 else avt_errmsg(MGL_ERRMSG
, "005", AVT_ERROR
, name
, context
->LINENUM
);
798 if (ptlosig
== NULL
|| ptlosig
->NAMECHAIN
->DATA
!= name
) {
799 ptcon
= getlocon(ptfig
, name
);
801 ptlosig
= ptcon
->SIG
;
803 else ptlosig
= mbk_quickly_getlosigbyname(ptfig
, name
);
809 /* ###--------------------------------------------------------------### */
810 /* function : mgl_addloins */
811 /* ###--------------------------------------------------------------### */
814 mgl_addloins(struct lofig
*ptfig
, char *modelname
, char *insname
, chain_list
*loconnames
, chain_list
*sigchain
)
818 chain_list
*ptchain
, *ptchain1
;
820 ptloins
= (loins_list
*)mbkalloc(sizeof(loins_list
));
822 ptloins
->INSNAME
= insname
;
823 ptloins
->FIGNAME
= modelname
;
824 ptloins
->LOCON
= NULL
;
825 ptloins
->USER
= NULL
;
826 ptloins
->NEXT
= ptfig
->LOINS
;
827 ptfig
->LOINS
= ptloins
;
829 /* update model list */
830 for (ptchain
= ptfig
->MODELCHAIN
; ptchain
; ptchain
= ptchain
->NEXT
)
831 if (ptchain
->DATA
== (void *)modelname
)
835 ptfig
->MODELCHAIN
= addchain(ptfig
->MODELCHAIN
, (void *)modelname
);
837 for (ptchain
= sigchain
, ptchain1
= loconnames
; ptchain
&& ptchain1
; ptchain
= ptchain
->NEXT
, ptchain1
= ptchain1
->NEXT
) {
838 ptlocon
= (locon_list
*)mbkalloc(sizeof(locon_list
));
839 ptlocon
->NAME
= (char *)ptchain1
->DATA
;
840 ptlocon
->DIRECTION
= UNKNOWN
;
842 ptlocon
->SIG
= (losig_list
*)ptchain
->DATA
;
843 ptlocon
->ROOT
= ptloins
;
844 ptlocon
->USER
= NULL
;
845 ptlocon
->PNODE
= NULL
;
846 ptlocon
->NEXT
= ptloins
->LOCON
;
847 ptloins
->LOCON
= ptlocon
;
853 /* ###--------------------------------------------------------------### */
854 /* function : mgl_assign */
855 /* ###--------------------------------------------------------------### */
858 mgl_assign(lofig_list
*ptfig
, char *lident
, char *rident
, struct dct_entry
**hshtab
, mgl_scompcontext
*context
)
862 losig_list
*pttempsig
;
867 ptlsig
= (losig_list
*)mgl_getlosig(ptfig
, lident
, hshtab
, context
);
868 ptrsig
= (losig_list
*)mgl_getlosig(ptfig
, rident
, hshtab
, context
);
869 /* quietly give-up if signal does not exist */
870 if (ptlsig
== NULL
|| ptrsig
== NULL
) return;
872 if (ptrsig
->TYPE
== EXTERNAL
&& ptlsig
->TYPE
== EXTERNAL
) {
873 fprintf(stderr
, "Warning : external signals '%s' and '%s' have been merged\n", lident
, rident
);
874 ptrsig
->NAMECHAIN
= append(ptrsig
->NAMECHAIN
, ptlsig
->NAMECHAIN
);
875 ptlsig
->NAMECHAIN
= NULL
;
878 /* swap if rhs is external */
879 if (ptrsig
->TYPE
== EXTERNAL
) {
885 /* change rsig to external if lsig external */
886 if (ptlsig
->TYPE
== EXTERNAL
) ptrsig
->TYPE
= EXTERNAL
;
888 /* merge names unless external */
889 if (ptrsig
->TYPE
== EXTERNAL
) {
890 freechain(ptrsig
->NAMECHAIN
);
891 ptrsig
->NAMECHAIN
= ptlsig
->NAMECHAIN
;
894 ptrsig
->NAMECHAIN
= append(ptrsig
->NAMECHAIN
, ptlsig
->NAMECHAIN
);
896 ptlsig
->NAMECHAIN
= NULL
;
899 /* merge connectors */
900 ptluser
= getptype(ptlsig
->USER
, LOFIGCHAIN
);
901 if (ptluser
!= NULL
) {
902 for (ptchain
= (chain_list
*)ptluser
->DATA
; ptchain
; ptchain
= ptchain
->NEXT
) {
903 ((locon_list
*)ptchain
->DATA
)->SIG
= ptrsig
;
905 ptruser
= getptype(ptrsig
->USER
, LOFIGCHAIN
);
906 ptruser
->DATA
= append((chain_list
*)ptruser
->DATA
, (chain_list
*)ptluser
->DATA
);
907 ptlsig
->USER
= delptype(ptlsig
->USER
, LOFIGCHAIN
);
913 /* ###--------------------------------------------------------------### */
914 /* function : mgl_sortsig */
915 /* ###--------------------------------------------------------------### */
917 /* Reorder signals to match model. First try order or reverse order */
918 /* matching. If that fails then we apply the popular n^2 technique */
921 mgl_sortsig(lofig_list
*ptmodel
, char *insname
, chain_list
*loconnames
, chain_list
*sigchain
, lofig_list
*ptfig
, int *ptindex
)
923 locon_list
*ptmodelcon
;
924 losig_list
*ptnewsig
;
925 chain_list
*ptchain
, *ptchain1
;
926 chain_list
*reschain
= NULL
;
928 int i
=0, j
=0, reversed
=0;
930 for (ptchain
= sigchain
; ptchain
!= NULL
; ptchain
= ptchain
->NEXT
) i
++;
931 for (ptchain
= loconnames
; ptchain
!= NULL
; ptchain
= ptchain
->NEXT
) {
936 fputs("*** mbk error ***\n", stderr
);
937 fputs("mgl_sortsig : inconsistency between connectors", stderr
);
938 fprintf(stderr
, " and signals in instance '%s'\n", insname
);
944 if (sigchain
!= NULL
) {
945 if (ptmodel
->LOCON
!= NULL
&& ptmodel
->LOCON
->NAME
!= (char *)loconnames
->DATA
) {
946 loconnames
= reverse(loconnames
);
947 sigchain
= reverse(sigchain
);
952 for (ptmodelcon
= ptmodel
->LOCON
, ptchain
= loconnames
;
953 ptmodelcon
!= NULL
&& ptchain
!= NULL
;
954 ptmodelcon
= ptmodelcon
->NEXT
, ptchain
= ptchain
->NEXT
) {
955 if (ptmodelcon
->NAME
!= (char *)ptchain
->DATA
) break;
958 /* order matching fails so try name matching */
959 if (ptmodelcon
!= NULL
|| ptchain
!= NULL
) {
960 for (ptmodelcon
= ptmodel
->LOCON
; ptmodelcon
!= NULL
; ptmodelcon
= ptmodelcon
->NEXT
) i
++;
961 for (ptchain
= loconnames
; ptchain
!= NULL
; ptchain
= ptchain
->NEXT
) j
++;
964 fputs("*** mbk error ***\n", stderr
);
965 fputs("mgl_sortsig : connector number inconsistency between model", stderr
);
966 fprintf(stderr
, " '%s' and instance '%s'\n", ptmodel
->NAME
, insname
);
969 for (ptmodelcon
= ptmodel
->LOCON
; ptmodelcon
!= NULL
; ptmodelcon
= ptmodelcon
->NEXT
) {
970 for (ptchain
= loconnames
, ptchain1
= sigchain
; ptchain
; ptchain
= ptchain
->NEXT
, ptchain1
= ptchain1
->NEXT
) {
971 if ((char *)ptchain
->DATA
== ptmodelcon
->NAME
) {
972 reschain
= addchain(reschain
, ptchain1
->DATA
);
976 if (ptchain
== NULL
) {
977 sprintf(buffer
, "%s_%s", insname
, ptmodelcon
->NAME
);
978 ptnewsig
= addlosig(ptfig
, *ptindex
, addchain(NULL
, namealloc(buffer
)), 'I');
980 reschain
= addchain(reschain
, ptnewsig
);
984 reschain
= reverse(reschain
);
986 else reschain
= sigchain
;
990 loconnames
= reverse(loconnames
);
995 /* ###--------------------------------------------------------------### */
996 /* function : mgl_getloconrange */
997 /* ###--------------------------------------------------------------### */
1000 mgl_getloconrange(locon_list
*ptheadlocon
, char *name
, int *left
, int *right
)
1002 locon_list
*ptlocon
;
1007 for (ptlocon
= ptheadlocon
; ptlocon
; ptlocon
= ptlocon
->NEXT
) {
1008 if (strcmp(vectorradical(ptlocon
->NAME
), name
) == 0) match
= 1;
1011 index
= vectorindex(ptlocon
->NAME
);
1012 if (*right
== -1) *right
= index
;
1018 /* ###--------------------------------------------------------------### */
1019 /* function : mgl_givevdd */
1020 /* ###--------------------------------------------------------------### */
1022 /* Identify a VDD signal on module interface or create a VDD local */
1023 /* to the instance */
1026 mgl_givevdd(lofig_list
*ptfig
, char *insname
, int *ptindex
)
1028 locon_list
*ptlocon
;
1029 losig_list
*ptnewsig
;
1032 for (ptlocon
= ptfig
->LOCON
; ptlocon
; ptlocon
= ptlocon
->NEXT
) {
1033 if (mbk_LosigIsVDD(ptlocon
->SIG
)) return ptlocon
->SIG
;
1036 sprintf(buffer
, "%s_vdd", insname
);
1037 ptnewsig
= addlosig(ptfig
, *ptindex
, addchain(NULL
, namealloc(buffer
)), 'I');
1038 mbk_SetLosigVDD(ptnewsig
);
1044 /* ###--------------------------------------------------------------### */
1045 /* function : mgl_givevss */
1046 /* ###--------------------------------------------------------------### */
1048 /* Identify a VSS signal on module interface or create a VDD local */
1049 /* to the instance */
1052 mgl_givevss(lofig_list
*ptfig
, char *insname
, int *ptindex
)
1054 locon_list
*ptlocon
;
1055 losig_list
*ptnewsig
;
1058 for (ptlocon
= ptfig
->LOCON
; ptlocon
; ptlocon
= ptlocon
->NEXT
) {
1059 if (mbk_LosigIsVSS(ptlocon
->SIG
)) return ptlocon
->SIG
;
1062 sprintf(buffer
, "%s_vss", insname
);
1063 ptnewsig
= addlosig(ptfig
, *ptindex
, addchain(NULL
, namealloc(buffer
)), 'I');
1064 mbk_SetLosigVSS(ptnewsig
);