Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / mbkhilo / drive_hilo.c
1 /*
2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - Département ASIM
4 * Universite Pierre et Marie Curie
5 *
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail support : mailto:alliance-support@asim.lip6.fr
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * Alliance VLSI CAD System is distributed in the hope that it will be
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with the GNU C Library; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /*******************************************************************************
25 * mbk : hilo driver, mainly used as format for hardware test machine interface *
26 * written by Alain Greiner in october 1990 *
27 * *
28 * mbk vector support by Fred Petrot, june 1992 *
29 * *
30 * signal names are are prefixed by 'hilosig_' Olivier, September 94 *
31 * instances names are are prefixed by 'hilog_' Olivier, September 94 *
32 * version : 403 *
33 * date : 20 septembre 1994 *
34 *******************************************************************************/
35
36 #include MUT_H
37 #include MLO_H
38 #include <string.h>
39 #include <stdlib.h>
40 #include <ctype.h>
41 /*******************************************************************************
42 * function legal_instance_name : prefixe le nom de l'instance avec "hilo_"
43 * et remplace '[',']' et '.' avec `_`
44 *******************************************************************************/
45 static char *legal_instance_name(s)
46 char *s;
47 {
48 static char buffer[255];
49 int i;
50
51 sprintf(buffer,"hilo_%s",s);
52
53 i = 0;
54 while (buffer[i] != 0) {
55 if ((buffer[i] == '[') || (buffer[i] == ']') || (buffer[i] == '.'))
56 buffer[i] = '_' ;
57 i++;
58 }
59 return buffer;
60 }
61
62 /*******************************************************************************
63 * function legal_signal_name : prefixe le nom du signal avec "hilosig_"
64 * et remplace '[',']',' ' et '.' avec `_`
65 *******************************************************************************/
66 static char *legal_signal_name(s)
67 char *s;
68 {
69 static char buffer[255];
70 int i;
71
72 sprintf(buffer,"hilosig_%s",s);
73
74 i = 0;
75 while (buffer[i] != 0) {
76 if ((buffer[i] == '[') || (buffer[i] == ']') ||
77 (buffer[i] == ' ') || (buffer[i] == '.'))
78 buffer[i] = '_' ;
79 i++;
80 }
81 return buffer;
82 }
83
84 /*******************************************************************************
85 * function busname : returns a legal hilo vector *
86 *******************************************************************************/
87 static char *busname(name)
88 char *name;
89 {
90 static char buffer[255], *s, *t;
91 char one = 1;
92
93 if (!name)
94 return NULL;
95
96 s = name;
97 t = buffer;
98 while (*s) {
99 if (*s == ' ') {
100 if (one) {
101 *t++ = '[';
102 s++;
103 one = 0;
104 } else {
105 *t++ = ']';
106 *t++ = '[';
107 s++;
108 }
109 }
110 *t++ = *s++;
111 }
112 if (!one)
113 *t++ = ']';
114 *t = '\0';
115 return buffer;
116 }
117
118 /*******************************************************************************
119 * function hilosavelofig *
120 *******************************************************************************/
121
122 void hilosavelofig(ptfig)
123 lofig_list *ptfig;
124 {
125 loins_list *ptins = NULL;
126 locon_list *ptcon = NULL;
127 locon_list *ptscan = NULL;
128 locon_list *pt1 = NULL;
129 locon_list *pt2 = NULL;
130 locon_list *pthead = NULL;
131 locon_list *ptsav = NULL;
132 losig_list *ptsig = NULL;
133 losig_list *ptsigdif = NULL;
134 lofig_list *ptnewfig = NULL;
135 FILE *ptfile;
136 char *amatla;
137 char *SigName = NULL;
138 char Buffer[256];
139
140 if ((ptfile = mbkfopen(ptfig->NAME, OUT_LO, WRITE_TEXT)) == NULL)
141 {
142 (void)fprintf(stderr, "*** mbk error ***\n");
143 (void)fprintf(stderr, "cannot open file %s.%s\n", ptfig->NAME, OUT_LO);
144 EXIT(1);
145 }
146
147 /* check signal name unicity */
148
149 for (ptsig = ptfig->LOSIG ; ptsig->NEXT ; ptsig = ptsig->NEXT)
150 {
151 amatla = getsigname(ptsig);
152 for (ptsigdif = ptsig->NEXT ; ptsigdif ; ptsigdif = ptsigdif->NEXT)
153 if(amatla == getsigname(ptsigdif))
154 ptsig->NAMECHAIN = ptsigdif->NAMECHAIN = NULL;
155 }
156
157 /* reverse external connectors & instances */
158
159 ptfig->LOCON = (locon_list *)reverse((chain_list *)ptfig->LOCON);
160 ptfig->LOINS = (loins_list *)reverse((chain_list *)ptfig->LOINS);
161
162 /* restore connector order for instances */
163
164 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT)
165 {
166 pthead = NULL;
167 ptnewfig = getlofig(ptins->FIGNAME, 'P');
168 for (pt1 = ptnewfig->LOCON; pt1; pt1 = pt1->NEXT)
169 {
170 for (pt2 = ptins->LOCON; pt2; pt2 = pt2->NEXT)
171 {
172 if (pt2->NAME == pt1->NAME) break;
173 ptsav = pt2;
174 }
175 if (pt2 == NULL)
176 {
177 (void)fprintf(stderr, "*** mbk error ***\n");
178 (void)fprintf(stderr, "interface discrepancy between ");
179 (void)fprintf(stderr, "instance %s and model %s",
180 ptins->INSNAME, ptins->FIGNAME);
181 (void)fprintf(stderr, " driving file %s.cct\n", ptfig->NAME);
182 EXIT(1);
183 }
184 else if (pt2 == ptins->LOCON)
185 {
186 ptins->LOCON = pt2->NEXT;
187 }
188 else
189 {
190 ptsav->NEXT = pt2->NEXT;
191 }
192 pt2->NEXT = pthead;
193 pthead = pt2;
194 }
195 if (ptins->LOCON != NULL)
196 {
197 (void)fprintf(stderr, "*** mbk error ***\ninterface discrepancy");
198 (void)fprintf(stderr, "between instance %s and", ptins->INSNAME);
199 (void)fprintf(stderr, " model %s", ptins->FIGNAME);
200 (void)fprintf(stderr, " driving file %s.cct\n", ptfig->NAME);
201 EXIT(1);
202 }
203 ptins->LOCON = pthead;
204 }
205
206 (void)fprintf(ptfile, "CIRCUIT %s(\n", ptfig->NAME);
207
208 for (ptcon = ptfig->LOCON; ptcon; ptcon = ptcon->NEXT) {
209 if (mbk_LosigIsVDD(ptcon->SIG)) {
210 (void)fprintf(ptfile, " supply1 %s", busname(ptcon->NAME));
211 }
212 else
213 if (mbk_LosigIsVSS(ptcon->SIG)) {
214 (void)fprintf(ptfile, " supply0 %s", busname(ptcon->NAME));
215 }
216 else {
217 switch (ptcon->DIRECTION)
218 {
219
220 case UNKNOWN :
221 case TRANSCV :
222 case INOUT :
223 (void)fprintf(ptfile, " bidir %s", busname(ptcon->NAME));
224 break;
225 case IN :
226 (void)fprintf(ptfile, " input %s", busname(ptcon->NAME));
227 break;
228 case TRISTATE :
229 case OUT :
230 (void)fprintf(ptfile, " output %s", busname(ptcon->NAME));
231 break;
232 default :
233 (void)fprintf(stdout,"Unknown direction on terminal %s :\n",
234 ptcon->NAME);
235 }
236 }
237 if (ptcon->NEXT != NULL) (void)fputs(",\n", ptfile);
238 }
239
240 (void)fputs(");\n", ptfile);
241
242 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT)
243 {
244 strcpy(Buffer,legal_instance_name(ptins->INSNAME));
245 fprintf(ptfile, "%s %s(\n", ptins->FIGNAME, Buffer);
246 for (ptcon = ptins->LOCON; ptcon; ptcon = ptcon->NEXT)
247 {
248 ptsig = getlosig(ptfig, ptcon->SIG->INDEX);
249 if (ptsig->TYPE == 'I')
250 {
251 SigName = getsigname(ptsig);
252 fprintf(ptfile, " %s", legal_signal_name(SigName));
253 }
254 else
255 {
256 for (ptscan = ptfig->LOCON; ptscan; ptscan = ptscan->NEXT)
257 {
258 if (ptscan->SIG == ptsig) break;
259 }
260 if (ptscan == NULL)
261 {
262 (void)fprintf(stderr, "*** mbk error ***\nno external connec");
263 (void)fprintf(stderr, "tor driving file %s.cct\n", ptfig->NAME);
264 }
265 else
266 {
267 fprintf(ptfile, " %s", busname(ptscan->NAME));
268 }
269 }
270 if (ptcon->NEXT != NULL)
271 {
272 (void)fputs(",\n", ptfile);
273 }
274 }
275 (void)fputs(");\n", ptfile);
276 }
277 (void)fputs("ENDCIRCUIT\n", ptfile);
278 dellofig(ptfig->NAME);
279 (void)fclose(ptfile);
280 }