Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / api / ttv / ttv_API_util.c
1 /****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI AVERTEC */
4 /* */
5 /* Produit : AVERTEC global tools */
6 /* Fichier : ttv_API_util.c */
7 /* */
8 /* © copyright 2004 AVERTEC */
9 /* Tous droits reserves */
10 /* */
11 /* Auteur(s) : Antony PINTO */
12 /* */
13 /****************************************************************************/
14
15 #include <dirent.h>
16 #include <stddef.h>
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include <dirent.h>
20
21 #include BCK_H
22 #include STM_H
23 #include TTV_H
24 #include MLU_H
25 #include MUT_H
26 #include INF_H
27 #include EFG_H
28 #include TAS_H
29 #include TRC_H
30 #include YAG_H
31 #include MCC_H
32 #include INF_H
33 #define API_USE_REAL_TYPES
34 #include "ttv_API_LOCAL.h"
35 #include "ttv_API.h"
36 #include "ttv_API_util.h"
37
38 /****************************************************************************/
39 /*{{{ */
40 /****************************************************************************/
41 /*{{{ isSameNode() */
42 /* */
43 /* Compare 2 ttv path */
44 /* */
45 /****************************************************************************/
46 static int
47 isSameNode(ttvcritic_list *x, ttvcritic_list *y)
48 {
49 return (!strcmp(x->NAME,y->NAME) &&
50 (x->SLOPE == y->SLOPE) &&
51 (x->DELAY == y->DELAY) &&
52 (x->TYPE == y->TYPE) &&
53 (x->SNODE == y->SNODE));
54 }
55
56 /*}}}************************************************************************/
57 /*{{{ pathIsInside() */
58 /* */
59 /* detect if a pth is included onto a longer path */
60 /* */
61 /****************************************************************************/
62 static int
63 pathIsInside(ttvpath_list* sp,ttvpath_list *lp)
64 {
65 chain_list *x, *y;
66 ttvcritic_list *sc, *lc;
67 int res;
68
69 if (sp && lp)
70 {
71 res = 1;
72
73 x = ttv_GetPathDetail(sp);
74 y = ttv_GetPathDetail(lp);
75
76 sc = x->DATA;
77 for ( ; y; y = y->NEXT)
78 {
79 lc = y->DATA;
80 if (!strcmp(lc->NAME,sc->NAME))
81 break;
82 }
83
84 if (y)
85 for ( ; x && y && res; x = x->NEXT, y = y->NEXT)
86 {
87 res = isSameNode(x->DATA,y->DATA);
88 //if (!res) printf("differences\n");
89 }
90
91 if (!y && x)
92 return 0;
93 else
94 return res;
95 }
96 else
97 return 0;
98 }
99
100 /*}}}************************************************************************/
101 /*{{{ ttv_RemoveIncludedSmallerPath() */
102 /* */
103 /* remove included path */
104 /* */
105 /****************************************************************************/
106 chain_list *
107 ttv_RemoveIncludedSmallerPath(chain_list *lpl, chain_list *spl)
108 {
109 chain_list *x, *y, hd, *prev;
110 int res;
111
112 hd.NEXT = spl;
113 prev = &hd;
114
115 if (lpl && spl)
116 for (x = prev->NEXT; x; )
117 {
118 //res = 0;
119 for (y = lpl; y; y = y->NEXT)
120 if ((res = pathIsInside(x->DATA,y->DATA)))
121 break;
122 if (res)
123 {
124 x = delchain(x,x);
125 prev->NEXT = x;
126 }
127 else
128 {
129 x = x->NEXT;
130 prev = prev->NEXT;
131 }
132 }
133
134 return hd.NEXT;
135 }
136
137 /*}}}************************************************************************/
138
139 cnsfig_list *ttvutil_cnsload(char *figname, inffig_list *ifl)
140 {
141 cnsfig_list *cf;
142 char *where;
143 if ((cf=getloadedcnsfig(figname))==NULL)
144 {
145 cnsenv();
146 where=filepath (figname,"cns");
147 if (where!=NULL)
148 {
149 avt_log(LOGFILEACCESS, 0, "Loading Cone netlist \"%s\"\n", where);
150 //avt_error("library", -1, AVT_INFO, "loading CNS '¤2%s¤.'\n", where);
151 cf=getcnsfig(figname, NULL);
152 cns_addmultivoltage(ifl, cf);
153 }
154 }
155 return cf;
156 }
157
158 char ttv_getUorD(char dir)
159 {
160 if (tolower(dir) == 'u' || tolower(dir) == 'r') return 'u';
161 else if (tolower(dir) == 'd' || tolower(dir) == 'f') return 'd';
162 return dir;
163 }
164
165 int ttv_DirectionToIndex(char dir)
166 {
167 if (tolower(dir) == 'u' || tolower(dir) == 'r') return TTVAPI_UP;
168 else if (tolower(dir) == 'd' || tolower(dir) == 'f') return TTVAPI_DN;
169 else if (dir == '?') return TTVAPI_EITHER;
170 return TTVAPI_NONE;
171 }
172
173 void ttv_DirectionStringToIndices(char *dir, int *a, int *b)
174 {
175 *a = ttv_DirectionToIndex(dir[0]);
176 *b = ttv_DirectionToIndex(dir[1]);
177 }
178
179 int ttv_DirectionStringToIndicesHZ(char *dir)
180 {
181 if (dir[1]!='\0')
182 {
183 if (tolower(dir[2])=='z') return TTV_API_ONLY_HZ;
184 else if (tolower(dir[2])=='/') return TTV_API_ONLY_NOTHZ;
185 }
186 return 0;
187 }
188
189