tab2vmem_gram.y
6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* tab2vmem_gram.y - Grammar for tab2vmem */
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <values.h>
#include "tab2vmem.h"
/*
* tokenString is global holding last ident, string, literal
* shorn of quotes
*/
#define TOKENSIZ 256
#define MAX_NUMBER_LEN 128
typedef union _NameType {
char name[TOKENSIZ];
int ival;
} NameType;
#define YYSTYPE NameType
/* Forward References */
void install(char *);
void install_number(char *, int);
/* globals */
extern FILE *Vecfp; /* memory vectors */
SigDef Signal[MAX_SIGNALS];
ClockDef Clock[MAX_CLOCKS];
int nSigs = 0; /* number of signals */
int nClocks = 0; /* number of signals */
int nVecs = 0; /* number of vectors */
int MemWidth = 0; /* test vector memory width in bits */
static char VecArray[MAX_SIGNALS][MAX_NUMBER_LEN];
static int CurSig = 0; /* current signal */
static int CurEdge = 0; /* current edge timing */
static int CurStrobe = 0; /* current strobe timing */
static int ClkSig = 0; /* clock signal flag */
static int ClkPhase = 0; /* clock phase count */
static int line_num = 0;
static int VectorPhase = 0;
%}
%start Input
/* Reserved Keywords */
/* symbols */
%token tCOLON
%token tEOL
%token tLBRACK
%token tRBRACK
%token tLPAREN
%token tRPAREN
%token tPERCENT
%token tQUOTE
%token tINPUT
%token tOUTPUT
%token tBIDIR
%token tTRI
%token tEDGE
%token tSTROBE
%token tCLOCK
%token tVALID
/* patterns */
%token tNUMBER
%token tHEX
%token tIDENT
%token tJUNK
%%
Input : /* EMPTY */
| Input Statement
;
Statement : tEOL
{
VectorPhase = 1;
}
| Signals tEOL
{
if(!ClkSig)
nSigs++;
else {
ClkSig = 0;
nClocks++;
}
if(nSigs > MAX_SIGNALS)
{
fprintf(stderr,"ERROR: number of signals exceeds max(%d)\n", MAX_SIGNALS);
exit(911);
}
if(nClocks > MAX_CLOCKS)
{
fprintf(stderr,"ERROR: number of clocks exceeds max(%d)\n", MAX_CLOCKS);
exit(911);
}
}
| Vector tEOL
{
int i;
/* do some consistency checks between header and vectors on first vector */
if(nVecs == 0)
{
if(CurSig != nSigs)
{
fprintf(stderr,"ERROR: number of signals in header(%d) doesn't match number of vectors(%d)\n", nSigs, CurSig);
exit(911);
}
for(i = 0; i < nSigs; i++)
{
if((Signal[i].hex_dig && (strlen(VecArray[i]) != Signal[i].hex_dig)) ||
(!Signal[i].hex_dig && (strlen(VecArray[i]) != 1)))
{
fprintf(stderr,"ERROR: length(%d) of vector field %d doesn't match signal definition(%d)\n",
strlen(VecArray[i]), i, Signal[i].hex_dig ? Signal[i].hex_dig : 1);
exit(911);
}
}
}
/* print vectors */
for(i = 0; i < nSigs; i++)
{
fprintf(Vecfp,"%s_", VecArray[i]);
}
fprintf(Vecfp, "\n");
CurSig = 0; /* reset */
nVecs++;
}
;
Signals : InputSig
| OutputSig
| BiDirectionalSig
| ValidSig
| ClockSig
{
ClkSig = 1;
}
| error
{
printf("Signal, Unrecognized signal syntax: %s\n", yylval.name);
}
;
InputSig : SignalName tINPUT
{
Signal[nSigs].type = VMEM_INPUT;
}
| InputSig tEDGE tNUMBER
{
Signal[nSigs].edge = $3.ival;
CurEdge = $3.ival;
}
| InputSig tVALID tIDENT
{
strcpy(Signal[nSigs].val_sig_name, $3.name);
strcat(Signal[nSigs].val_sig_name, "_v");
Signal[nSigs].valid = 1;
}
;
OutputSig : SignalName tOUTPUT
{
Signal[nSigs].type = VMEM_OUTPUT;
}
| OutputSig tSTROBE tNUMBER
{
Signal[nSigs].strobe = $3.ival;
CurStrobe = $3.ival;
}
| OutputSig tVALID tIDENT
{
strcpy(Signal[nSigs].val_sig_name, $3.name);
strcat(Signal[nSigs].val_sig_name, "_v");
Signal[nSigs].valid = 1;
}
;
BiDirectionalSig: SignalName tBIDIR tIDENT tNUMBER
{
strcpy(Signal[nSigs].en_sig_name, $3.name);
Signal[nSigs].type = VMEM_BIDIR;
Signal[nSigs].polarity = $4.ival;
}
| BiDirectionalSig tEDGE tNUMBER
{
Signal[nSigs].edge = $3.ival;
CurEdge = $3.ival;
}
| BiDirectionalSig tSTROBE tNUMBER
{
Signal[nSigs].strobe = $3.ival;
CurStrobe = $3.ival;
}
| BiDirectionalSig tVALID tIDENT
{
strcpy(Signal[nSigs].val_sig_name, $3.name);
strcat(Signal[nSigs].val_sig_name, "_v");
Signal[nSigs].valid = 1;
}
;
ValidSig : SignalName tVALID
{
strcat(Signal[nSigs].sig_name, "_v");
Signal[nSigs].type = VMEM_VALID;
}
| ValidSig tEDGE tNUMBER
{
Signal[nSigs].edge = $3.ival;
CurEdge = $3.ival;
}
;
ClockSig : SignalName tCLOCK tNUMBER tLPAREN tNUMBER tRPAREN
{
/* copy signal name, don't increment signals */
strcpy(Clock[nClocks].sig_name, Signal[nSigs].sig_name);
ClkPhase = 0;
Clock[nClocks].val[ClkPhase] = $3.ival;
Clock[nClocks].time[ClkPhase] = $5.ival;
ClkPhase++;
Clock[nClocks].phases = ClkPhase;
}
| ClockSig tNUMBER tLPAREN tNUMBER tRPAREN
{
/* copy signal name, don't increment signals */
if(ClkPhase > MAX_CLK_PHASES) {
fprintf(stderr,"Error, exceeded max number of clk phases %d\n",
ClkPhase);
exit(911);
}
Clock[nClocks].val[ClkPhase] = $3.ival;
Clock[nClocks].time[ClkPhase] = $5.ival;
ClkPhase++;
Clock[nClocks].phases = ClkPhase;
}
;
SignalName : Bus
{
Signal[nSigs].type = VMEM_INPUT; /* default */
Signal[nSigs].edge = CurEdge; /* default */
Signal[nSigs].strobe = CurStrobe; /* default */
Signal[nSigs].valid = 0;
MemWidth += Signal[nSigs].hex_dig * 4;
}
| tIDENT
{
strcpy(Signal[nSigs].sig_name, $1.name);
Signal[nSigs].size = 1;
Signal[nSigs].msb = 0;
Signal[nSigs].lsb = 0;
Signal[nSigs].hex_dig = 0;
Signal[nSigs].type = VMEM_INPUT; /* default */
Signal[nSigs].edge = CurEdge; /* default */
Signal[nSigs].strobe = CurStrobe; /* default */
Signal[nSigs].valid = 0;
MemWidth += 4;
}
;
Bus : tIDENT tLBRACK tNUMBER tCOLON tNUMBER tRBRACK
{
sprintf(Signal[nSigs].sig_name, "%s\0",$1.name);
Signal[nSigs].msb = $3.ival;
Signal[nSigs].lsb = $5.ival;
Signal[nSigs].size = $3.ival - $5.ival + 1;
Signal[nSigs].hex_dig = (Signal[nSigs].size + 3) / 4;
}
;
Vector : VecNumber
| Vector VecNumber
| error
{
printf("Unrecognized signal syntax: %s\n", yylval.name);
}
;
VecNumber : tNUMBER
{
strcpy(VecArray[CurSig++],$1.name);
}
| tHEX
{
strcpy(VecArray[CurSig++],&($1.name[2]));
}
;
%%
#include "tab2vmem_scan.c"