vsig_gram.y
3.71 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
/* vsig_gram.y - Grammar for vsig */
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <values.h>
#include "vsig.h"
/*
* tokenString is global holding last ident, string, literal
* shorn of quotes
*/
#define TOKENSIZ 256
typedef union _NameType {
char name[TOKENSIZ];
int ival;
} NameType;
#define YYSTYPE NameType
/* Forward References */
void install(char *);
void install_number(char *, int);
void print_vsig( void );
/* globals */
extern FILE *Vecfp; /* memory vectors */
extern char *yysptr;
int EverynVecs = 20; /* number of vectors before printing */
static SigDef Signal[MAX_SIGNALS];
static int nSigs = 0; /* number of signals */
static int nVecs = 0; /* number of vectors */
static int CurSig = 0; /* current signal */
static int ClkSig = 0; /* clock signal flag */
static int line_num = 0;
static int *VecArray = NULL;
%}
%start Input
/* Reserved Keywords */
/* symbols */
%token tCOLON
%token tEOL
%token tLBRACK
%token tRBRACK
%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
{
if(VecArray == NULL)
VecArray = (int *) malloc(nSigs*sizeof(int));
}
| Signal tEOL
{
if(!ClkSig)
nSigs++;
else
ClkSig = 0;
}
| Vector tEOL
{
int i;
if(!(nVecs % EverynVecs))
print_vsig();
fprintf(Vecfp," ");
for(i = 0; i < nSigs; i++) {
if(Signal[i].hex_dig)
fprintf(Vecfp,"0x%0*x ", (Signal[i].size+3) / 4, VecArray[i]);
else
fprintf(Vecfp,"%0x ", VecArray[i]);
}
fprintf(Vecfp, "\n");
CurSig = 0; /* reset */
nVecs++;
}
;
Signal : Bus
{
}
| 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 tINPUT
{
}
| Signal tOUTPUT
{
}
| Signal tBIDIR tIDENT tNUMBER
{
}
| Signal tVALID
{
}
| Signal tVALID tIDENT
{
}
| Signal tCLOCK tNUMBER tNUMBER
{
ClkSig = 1;
}
| Signal tEDGE tNUMBER
{
}
| Signal tSTROBE tNUMBER
{
}
| error
{
printf("Unrecognized signal syntax: %s\n", yylval.name);
}
;
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
{
VecArray[CurSig++] = $1.ival;
}
| Vector VecNumber
{
VecArray[CurSig++] = $2.ival;
}
;
VecNumber : tNUMBER
| tHEX
;
%%
#include "vsig_scan.c"
void
print_vsig( void )
{
int i,j,k;
int stop[MAX_SIGNALS];
/* print signal names vertically */
for(i = 0; i < nSigs; i++)
stop[i] = 0;
if(nSigs > 0)
{
for(j = 0; 1; j++)
{
fprintf(Vecfp,"# ");
for(i = 0; i < nSigs; i++)
{
if(stop[i] == 0)
{
if(Signal[i].sig_name[j] == 0)
{
stop[i] = 1;
fprintf(Vecfp," ");
}
else
fprintf(Vecfp,"%c",Signal[i].sig_name[j]);
}
else
fprintf(Vecfp," ");
if(Signal[i].hex_dig)
fprintf(Vecfp," ");
for(k = 0; k < (Signal[i].size+3)/4; k++)
fprintf(Vecfp," ");
}
fprintf(Vecfp,"\n");
for(i = 0; i < nSigs; i++)
if(stop[i]==0)
break;
if(i == nSigs)
break;
}
}
}