-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlfrX.g4
More file actions
executable file
·310 lines (217 loc) · 6 KB
/
lfrX.g4
File metadata and controls
executable file
·310 lines (217 loc) · 6 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
grammar lfrX;
skeleton: module+;
module: moduledefinition body 'endmodule';
moduledefinition: 'module' ID ('(' ioblock ')')? ';';
body: ( statements | distributionBlock)+;
ioblock:
vectorvar (',' vectorvar)*
| explicitIOBlock ( ',' explicitIOBlock)*;
vectorvar: ID vector?;
explicitIOBlock:
'finput' declvar (',' declvar)*
| 'foutput' declvar (',' declvar)*
| 'control' declvar (',' declvar)*;
declvar: vector? ID;
distributionBlock:
'distribute@' '(' sensitivitylist ')' 'begin' distributionBody 'end';
distributionBody: distributeBodyStat+;
distributeBodyStat:
distributionassignstat
| caseBlock
| ifElseBlock;
ifElseBlock: ifBlock elseIfBlock* elseBlock?;
ifBlock: 'if' '(' distributeCondition ')' statementBlock;
elseBlock: 'else' statementBlock;
elseIfBlock:
'else' 'if' '(' distributeCondition ')' statementBlock;
distributeCondition: lhs binary_module_path_operator distvalue;
statementBlock:
'begin' distributionassignstat+ 'end'
| distributionassignstat;
caseBlock: caseBlockHeader casestat+ defaultCaseStat? 'endcase';
caseBlockHeader: 'case' '(' lhs ')';
casestat: distvalue ':' statementBlock;
defaultCaseStat: 'default' ':' statementBlock;
distvalue: number;
distributionassignstat:
lhs '<=' (number | variables | expression) ';'; //TODO: Have a switch->case block
sensitivitylist: signal (',' signal)*;
signal: ID vector?;
statements:
statement ';'
// | (blocks)+ //Uncomment this once we are making the distribute and always blocks
| technologydirectives;
statement:
ioassignstat //This needs ot be replaced by any number different kinds of statements that will
| assignstat
| tempvariablesstat
| literalassignstat
| moduleinstantiationstat;
moduleinstantiationstat:
moduletype instancename '(' instanceioblock ')';
instanceioblock: orderedioblock | unorderedioblock;
orderedioblock: vectorvar (',' vectorvar)*;
unorderedioblock:
explicitinstanceiomapping (',' explicitinstanceiomapping)*;
explicitinstanceiomapping: '.' ID '(' variables ')';
instancename: ID;
moduletype: ID;
tempvariablesstat:
fluiddeclstat
| storagestat
| numvarstat
| signalvarstat
| pumpvarstat;
signalvarstat: 'signal' declvar (',' declvar)*;
fluiddeclstat: 'flow' declvar (',' declvar)*;
storagestat: 'storage' declvar (',' declvar)*;
pumpvarstat: 'pump' declvar (',' declvar)*;
numvarstat: 'number' literalassignstat (',' literalassignstat)*;
assignstat: 'assign' lhs '=' ( bracketexpression | expression);
literalassignstat: ID '=' (bracketexpression | expression);
//TODO: Look up how the grammar is given for Verilog. This will have be to correct for actually solving the logic things
bracketexpression: unary_operator? '(' expression ')';
expression: (bracketexpression | expressionterm) (
binary_operator (bracketexpression | expressionterm)
)*;
expressionterm: unary_operator? variables | number;
logiccondition_operand: (bracketexpression | expressionterm) (
binary_operator (bracketexpression | expressionterm)
)*;
logiccondition:
logiccondition_operand binary_module_path_operator logic_value;
logic_value: number;
vector:
'[' start = Decimal_number (':' end = Decimal_number)? ']';
variables: vectorvar | concatenation;
concatenation: '{' vectorvar (',' vectorvar)* '}' vector?;
lhs: variables;
ioassignstat: explicitIOBlock;
technologydirectives:
performancedirective
| technologymappingdirective
| materialmappingdirective;
technologymappingdirective:
'#MAP' '"' ID+ '"' '"' (
mappingoperator
| assignmode = ('assign' | 'storage' | 'pump')
) '"';
materialmappingdirective: '#MATERIAL' ID materialtype = ID;
mappingoperator: binary_operator | unary_operator;
performancedirective:
'#CONSTRAIN' '"' mappingoperator '"' constraint (
('AND' | 'OR') constraint
)*;
constraint:
ID operator = '=' number unit?
| ID operator = '>' number unit?
| ID operator = '<' number unit?
| ID operator = '>=' number unit?
| ID operator = '<=' number unit?;
unit: ID;
ID: ('a' ..'z' | 'A' ..'Z' | '_') (
'a' ..'z'
| 'A' ..'Z'
| '0' ..'9'
| '_'
)*;
WS: [ \t\r\n]+ -> skip;
One_line_comment: '//' .*? '\r'? '\n' -> channel (HIDDEN);
Block_comment: '/*' .*? '*/' -> channel (HIDDEN);
Import_line: '`' .*? '\r'? '\n' -> channel (HIDDEN);
// Operators - Taken from Verilog2001
unary_operator:
'+'
| '-'
| '!'
| '~'
| '&'
| '~&'
| '|'
| '~|'
| '^'
| '~^'
| '^~';
binary_operator:
'+'
| '-'
| '*'
| '/'
| '%'
| '=='
| '!='
| '==='
| '!=='
| '&&'
| '||'
| '**'
| '<'
| '<='
| '>'
| '>='
| '&'
| '|'
| '^'
| '^~'
| '~^'
| '>>'
| '<<'
| '>>>'
| '<<<';
unary_module_path_operator:
'!'
| '~'
| '&'
| '~&'
| '|'
| '~|'
| '^'
| '~^'
| '^~';
binary_module_path_operator:
'=='
| '!='
| '&&'
| '||'
| '&'
| '|'
| '^'
| '^~'
| '~^';
//Numbers - Taken from the Verilog 2001
number:
Decimal_number
| Octal_number
| Binary_number
| Hex_number
| Real_number;
Real_number:
Unsigned_number '.' Unsigned_number
| Unsigned_number ('.' Unsigned_number)? [eE] ([+-])? Unsigned_number;
Decimal_number:
Unsigned_number
| (Size)? Decimal_base Unsigned_number
| (Size)? Decimal_base X_digit ('_')*
| (Size)? Decimal_base Z_digit ('_')*;
Binary_number: (Size)? Binary_base Binary_value;
Octal_number: (Size)? Octal_base Octal_value;
Hex_number: (Size)? Hex_base Hex_value;
fragment Sign: [+-];
fragment Size: Non_zero_unsigned_number;
fragment Non_zero_unsigned_number:
Non_zero_decimal_digit ('_' | Decimal_digit)*;
fragment Unsigned_number: Decimal_digit ('_' | Decimal_digit)*;
fragment Binary_value: Binary_digit ('_' | Binary_digit)*;
fragment Octal_value: Octal_digit ('_' | Octal_digit)*;
fragment Hex_value: Hex_digit ('_' | Hex_digit)*;
fragment Decimal_base: '\'' [sS]? [dD];
fragment Binary_base: '\'' [sS]? [bB];
fragment Octal_base: '\'' [sS]? [oO];
fragment Hex_base: '\'' [sS]? [hH];
fragment Non_zero_decimal_digit: [1-9];
fragment Decimal_digit: [0-9];
fragment Binary_digit: X_digit | Z_digit | [01];
fragment Octal_digit: X_digit | Z_digit | [0-7];
fragment Hex_digit: X_digit | Z_digit | [0-9a-fA-F];
fragment X_digit: [xX];
fragment Z_digit: [zZ?];