-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverilog.y
367 lines (354 loc) · 13.3 KB
/
verilog.y
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Copyright (c) 2020 The Connectal Project
// Original author: John Ankcorn
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
%skeleton "lalr1.cc"
%require "3.0"
%debug
%defines
%define parser_class_name {Parser}
%code requires{
class Driver;
class Scanner;
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# endif
}
%parse-param { Scanner &scanner }
%parse-param { Driver &driver }
%define api.value.type variant
%define parse.assert
%token END 0 "end of file"
%token ENDSOURCE "end parse marker"
%token yaFLOATNUM "FLOATING-POINT NUMBER"
%token yaID__LEX "IDENTIFIER-in-lex"
%token yaINTNUM "INTEGER NUMBER"
%token yaSTRING "STRING"
%token yaID__ETC "IDENTIFIER"
%token yENDMODULE "endmodule"
%token yINOUT "inout"
%token yINPUT "input"
%token yMODULE "module"
%token yOUTPUT "output"
%token yWIRE "wire"
%token yASSIGN "assign"
%locations
%%
source_text: // ==IEEE: source_text
ENDSOURCE /* empty */
| descriptionList ENDSOURCE
;
descriptionList: // IEEE: part of source_text
description
| descriptionList description
;
description: // ==IEEE: description
module_declaration
| error
;
package_or_generate_item_declaration: // ==IEEE: package_or_generate_item_declaration
net_declaration
| ';'
;
module_declaration: // ==IEEE: module_declaration
modFront importsAndParametersE portsStarE ';'
module_itemListE yENDMODULE endLabelE { createModule(); }
;
modFront:
yMODULE lifetimeE idAny { startModule(); }
;
importsAndParametersE: // IEEE: common part of module_declaration, interface_declaration, program_declaration
parameter_port_listE
;
parameter_value_assignmentE: // IEEE: [ parameter_value_assignment ]
/* empty */
| '#' '(' cellparamList ')'
;
parameter_port_listE: // IEEE: parameter_port_list + empty == parameter_value_assignment
/* empty */
| '#' '(' ')'
;
portsStarE: // IEEE: .* + list_of_ports + list_of_port_declarations + empty
/* empty */
| '(' ')'
| '(' list_of_ports ')'
;
list_of_ports: // IEEE: list_of_ports + list_of_port_declarations
port
| list_of_ports ',' port
;
port: // ==IEEE: port
portDirNetE signingE rangeList portSig variable_dimensionListE sigAttrListE { createPort(); }
| portDirNetE /*implicit*/ portSig variable_dimensionListE sigAttrListE { createPort(); }
| portDirNetE /*implicit*/ '.' portSig '(' portAssignExpr ')' sigAttrListE { currentPort.expr = tokenExpr; createPort(); }
;
portAssignExpr:
expr { currentPort.expr = tokenExpr; }
portDirNetE: // IEEE: part of port, optional net type and/or direction
/* empty */ { clearRange(); }
| port_direction { clearRange(); }
| port_direction net_type { clearRange(); }
| net_type { clearRange(); } // net_type calls VARNET
;
port_declNetE: // IEEE: part of port_declaration, optional net type
/* empty */
| net_type // net_type calls VARNET
;
portSig:
id/*port*/ { setPortName(); }
;
net_declaration: // IEEE: net_declaration - excluding implict
net_declarationFront netSigList ';'
;
net_declarationFront: // IEEE: beginning of net_declaration
net_declRESET net_type strengthSpecE net_scalaredE net_dataType
;
net_declRESET: /* empty */ ;
net_scalaredE: /* empty */ ;
net_dataType:
signingE rangeList delayE
| /*implicit*/ delayE
;
net_type: // ==IEEE: net_type
yWIRE { setNetType(); }
;
port_direction: // ==IEEE: port_direction + tf_port_direction
yINPUT { setModulePortDirection(); }
| yOUTPUT { setModulePortDirection(); }
| yINOUT { setModulePortDirection(); }
;
port_directionReset: // IEEE: port_direction that starts a port_declaraiton
yINPUT { setPortDirection(); }
| yOUTPUT { setPortDirection(); }
| yINOUT { setPortDirection(); }
;
port_declaration: // ==IEEE: port_declaration
port_directionReset port_declNetE signingE rangeList
list_of_variable_decl_assignments
| port_directionReset port_declNetE /*implicit*/
list_of_variable_decl_assignments
;
signingE: /*empty*/ ; // IEEE: signing - plus empty
list_of_variable_decl_assignments: // ==IEEE: list_of_variable_decl_assignments
variable_decl_assignment
| list_of_variable_decl_assignments ',' variable_decl_assignment
;
variable_decl_assignment: // ==IEEE: variable_decl_assignment
variableDecl variable_dimensionListE sigAttrListE { createVarDecl(); }
;
variableDecl:
id { setVarDecl(); }
;
variable_dimensionListE: // IEEE: variable_dimension + empty
/*empty*/
| variable_dimensionList
;
variable_dimensionList: // IEEE: variable_dimension + empty
variable_dimension
| variable_dimensionList variable_dimension
;
variable_dimension: // ==IEEE: variable_dimension
anyrange { setVariableDimension(); }
| '[' constExpr { setVariableDimension(); } ']'
;
module_itemListE: // IEEE: Part of module_declaration
/* empty */
| module_itemList
;
module_itemList: // IEEE: Part of module_declaration
module_item
| module_itemList module_item
;
module_item: // ==IEEE: module_item
port_declaration ';'
| non_port_module_item
;
non_port_module_item: // ==IEEE: non_port_module_item
module_or_generate_item
;
module_or_generate_item: // ==IEEE: module_or_generate_item
module_common_item
;
module_common_item: // ==IEEE: module_common_item
module_or_generate_item_declaration
| etcInst
| continuous_assign
;
continuous_assign: // IEEE: continuous_assign
yASSIGN delayE assignList ';'
;
module_or_generate_item_declaration: // ==IEEE: module_or_generate_item_declaration
package_or_generate_item_declaration
;
assignList:
assignOne
| assignList ',' assignOne
;
assignOne:
variable_lvalue '=' expr { currentModule.assigns.push_back(AssignInfo{idDotted, tokenExpr}); }
;
delayE: /* empty */ ;
netSigList: // IEEE: list_of_port_identifiers
netSig
| netSigList ',' netSig
;
netSig: // IEEE: net_decl_assignment - one element from list_of_port_identifiers
netId sigAttrListE { createNet(); }
| netId variable_dimensionList sigAttrListE { createNet(); }
;
netId:
id/*new-net*/ { setNetId(); }
;
sigAttrListE: /* empty */ ;
rangeList: // IEEE: {packed_dimension}
anyrange
| rangeList anyrange
;
anyrange:
'[' constExpr { setRange1(); } ':' constExpr ']' { setRange(); }
;
etcInst: // IEEE: module_instantiation + gate_instantiation + udp_instantiation
instDecl
;
instDecl:
objectId parameter_value_assignmentE instnameList ';'
;
objectId:
id { setObjectId(); }
;
instnameList:
instnameParen
| instnameList ',' instnameParen
;
instnameParen:
instanceId instRangeE '(' cellpinList ')' { createInstance(); }
| instanceId instRangeE { createInstance(); }
;
instanceId:
id { setInstance(); }
;
instRangeE:
/* empty */
| '[' constExpr ']' { setRange(); }
| '[' constExpr { setRange1(); } ':' constExpr ']' { setRange(); }
;
cellparamList:
cellparamItList
;
cellpinList:
cellpinItList
;
cellparamItList: // IEEE: list_of_parameter_assignmente
cellparamItemE
| cellparamItList ',' cellparamItemE
;
cellpinItList: // IEEE: list_of_port_connections
cellpinItemE
| cellpinItList ',' cellpinItemE
;
cellparamItemE: // IEEE: named_parameter_assignment + empty
/* empty: ',,' is legal */
| '.' idAny { setParam(); }
| '.' idAny '(' ')' { setParam(); }
| '.' idAny '(' expr ')'{ setParam(); }
| expr { setParam(); }
;
cellpinItemE: // IEEE: named_port_connection + empty
/* empty: ',,' is legal */
| '.' idAny { setPin(); }
| '.' idAny '(' ')' { setPin(); }
| '.' idAny '(' expr ')' { setPin(); }
| expr { setPin(); }
;
lifetimeE: /* empty */ ; // IEEE: [lifetime]
constExpr:
expr
;
expr: // IEEE: part of expression/constant_expression/primary
yaINTNUM
| yaFLOATNUM
| strAsInt
| '(' expr ')'
| '_' '(' expr ')'
| exprOkLvalue
;
exprOkLvalue: // expression that's also OK to use as a variable_lvalue
exprScope
| startCate cateList '}' { finishCateList(); }
;
startCate:
'{' { startCateList(); }
;
exprScope: // scope and variable for use to inside an expression
idArrayed
| //~l~
expr '.' idArrayed
;
cateList:
stream_expression
| cateList ',' stream_expression
;
stream_expression: // ==IEEE: stream_expression
expr { addCateList(); }
;
strengthSpecE: /* empty */ ; // IEEE: drive_strength + pullup_strength + pulldown_strength + charge_strength - plus empty
id:
yaID__ETC
;
idAny: // Any kind of identifier
yaID__ETC { setIdAny(); }
;
variable_lvalue: // IEEE: variable_lvalue or net_lvalue
idClassSel
| '{' variable_lvalueConcList '}'
// | streaming_concatenation
;
variable_lvalueConcList: // IEEE: part of variable_lvalue: '{' variable_lvalue { ',' variable_lvalue } '}'
variable_lvalue
| variable_lvalueConcList ',' variable_lvalue
;
idClassSel: // Misc Ref to dotted, and/or arrayed, and/or bit-ranged variable
idDotted
;
idDotted:
idDottedMore
;
idDottedMore:
idArrayed { idDotted = tokenExpr; }
| idDottedMore '.' idArrayed { idDotted += "." + tokenExpr; }
;
idArrayed: // IEEE: id + select
idArrayItem { finishArrayed(0); }
| idArrayed '[' expr ']' { finishArrayed(1); }
| idArrayed '[' constExpr { setRange1(); } ':' constExpr ']' { finishArrayed(2); }
;
idArrayItem:
id { setIdArrayed(); }
;
strAsInt:
yaSTRING
;
endLabelE:
/* empty */
| ':' idAny
;
%%