idlc 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,675 @@
1
+ # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2
+ # SPDX-License-Identifier: BSD-3-Clause-Clear
3
+
4
+ # grammar for the ISA Description Language
5
+
6
+ grammar Idl
7
+ rule isa
8
+ space*
9
+ '%version:' space+ version_string space+
10
+ definitions:(
11
+ include_statement
12
+ /
13
+ global_definition
14
+ /
15
+ enum_definition
16
+ /
17
+ bitfield_definition
18
+ /
19
+ struct_definition
20
+ /
21
+ function_definition
22
+ /
23
+ fetch
24
+ /
25
+ space+
26
+ )* <Idl::IsaSyntaxNode>
27
+ end
28
+
29
+ rule include_statement
30
+ 'include' space+ string space+ <Idl::IncludeStatementSyntaxNode>
31
+ end
32
+
33
+ # declaring a global variable or constant
34
+ rule global_definition
35
+ const:('const'? space+)? single_declaration_with_initialization space* ';' <Idl::GlobalWithInitializationSyntaxNode>
36
+ /
37
+ declaration space* ';' <GlobalSyntaxNode>
38
+ end
39
+
40
+ rule enum_definition
41
+ 'generated' space+ 'enum' space+ type_name space* ';' <Idl::BuiltinEnumDefinitionSyntaxNode>
42
+ /
43
+ 'enum' space+ type_name space+ '{' space*
44
+ e:(type_name space+ i:(int space+)?)+ space*
45
+ '}' <Idl::EnumDefinitionSyntaxNode>
46
+ end
47
+
48
+ rule enum_ref
49
+ enum_class:type_name space* '::' space* member:type_name <EnumRefSyntaxNode>
50
+ end
51
+
52
+ rule bitfield_definition
53
+ 'bitfield' space* '(' space* int space* ')' space* type_name space* '{' space*
54
+ e:(field_name space+ range:(int lsb:(space* '-' space* int)?) space+)+ space*
55
+ '}' <Idl::BitfieldDefinitionSyntaxNode>
56
+ end
57
+
58
+ rule struct_definition
59
+ 'struct' space* type_name space* '{' space*
60
+ member:(type_name space+ id space* ';' space*)+
61
+ '}' <Idl::StructDefinitionSyntaxNode>
62
+ end
63
+
64
+ rule version_string
65
+ [0-9]+ '.' [0-9]+
66
+ end
67
+
68
+ rule int
69
+ # verilog style: explicit bit width
70
+ (([0-9]+)/'MXLEN')? "'" 'b' [0-1xX] [0-1_xX]* <Idl::IntLiteralSyntaxNode> /
71
+ (([0-9]+)/'MXLEN')? "'" 'o' [0-7xX] [0-7_xX]* <Idl::IntLiteralSyntaxNode> /
72
+ (([0-9]+)/'MXLEN')? "'" 'd'? [0-9] [0-9_]* <Idl::IntLiteralSyntaxNode> /
73
+ (([0-9]+)/'MXLEN')? "'" 'h' [0-9a-fA-FxX] [0-9a-fA-F_xX]* <Idl::IntLiteralSyntaxNode> /
74
+
75
+ # verilog style: explicit bit width, signed
76
+ (([0-9]+)/'MXLEN')? "'" 'sb' [0-1xX] [0-1_xX]* <Idl::IntLiteralSyntaxNode> /
77
+ (([0-9]+)/'MXLEN')? "'" 'so' [0-7xX] [0-7_xX]* <Idl::IntLiteralSyntaxNode> /
78
+ (([0-9]+)/'MXLEN')? "'" 's' 'd'? [0-9] [0-9_]* <Idl::IntLiteralSyntaxNode> /
79
+ (([0-9]+)/'MXLEN')? "'" 'sh' [0-9a-fA-FxX] [0-9a-fA-F_xX]* <Idl::IntLiteralSyntaxNode> /
80
+
81
+ # c++ style: signed
82
+ '0b' [0-1] [0-1_]* 's' <Idl::IntLiteralSyntaxNode> /
83
+ '0' [0-7] [0-7_]* 's' <Idl::IntLiteralSyntaxNode> /
84
+ [1-9] [0-9]* 's' <Idl::IntLiteralSyntaxNode> /
85
+ '0x' [0-9a-fA-F] [0-9a-fA-F_]* 's' <Idl::IntLiteralSyntaxNode> /
86
+
87
+ # c++ style: unsigned
88
+ '0b' [0-1] [0-1_]* <Idl::IntLiteralSyntaxNode> /
89
+ '0' [0-7] [0-7_]* <Idl::IntLiteralSyntaxNode> /
90
+ [1-9] [0-9]* <Idl::IntLiteralSyntaxNode> /
91
+ '0x' [0-9a-fA-F] [0-9a-fA-F_]* <Idl::IntLiteralSyntaxNode> /
92
+
93
+ # special case: just a single 0
94
+ '0' 's'? <Idl::IntLiteralSyntaxNode>
95
+ end
96
+
97
+ rule p0_binary_operator
98
+ # highest priority binary operators
99
+ '/' # division with ignored remainder
100
+ / '%' # remainder
101
+ / '`*' # widening multiplication
102
+ / '*' # multiplication with ignored upper half
103
+ end
104
+
105
+ rule p1_binary_operator
106
+ '`+' # widening addition
107
+ / '`-' # widening subtraction
108
+ / '+' # addition with ignored overflow
109
+ / '-' # subtraction with ignored overflow
110
+ end
111
+
112
+ rule p2_binary_operator
113
+ '`<<' # widening left shift (only valid when shift amount is constant)
114
+ / '<<' # left shift
115
+ / '>>>' # arithmetic right shift
116
+ / '>>' # logical left shift
117
+ end
118
+
119
+ rule p3_binary_operator
120
+ '<=' /
121
+ '>=' /
122
+ '<' /
123
+ '>'
124
+ end
125
+
126
+ # when parsing inside a Bits<N> type expression, we disallow the '>' character
127
+ # if you need it for an expression, enclose the expression in ()
128
+ rule p3_template_binary_operator
129
+ '<=' /
130
+ '<'
131
+ end
132
+
133
+ rule p4_binary_operator
134
+ '!=' /
135
+ '=='
136
+ end
137
+
138
+ rule p5_binary_operator
139
+ '&' !'&' # bitwise AND
140
+ end
141
+
142
+ rule p6_binary_operator
143
+ '^' # bitwise XOR
144
+ end
145
+
146
+ rule p7_binary_operator
147
+ '|' !'|' # bitwise OR
148
+ end
149
+
150
+ rule p8_binary_operator
151
+ '&&' # logical AND
152
+ end
153
+
154
+ rule p9_binary_operator
155
+ '||' # logical OR
156
+ end
157
+
158
+ rule unary_operator
159
+ '~' / '-' / '!'
160
+ end
161
+
162
+ rule p0_binary_expression
163
+ l:unary_expression r:(space* op:p0_binary_operator space* r:unary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
164
+ /
165
+ unary_expression
166
+ end
167
+
168
+ rule p1_binary_expression
169
+ l:p0_binary_expression r:(space* op:p1_binary_operator space* r:p0_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
170
+ /
171
+ p0_binary_expression
172
+ end
173
+
174
+ rule p2_binary_expression
175
+ l:p1_binary_expression r:(space* op:p2_binary_operator space* r:p1_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
176
+ /
177
+ p1_binary_expression
178
+ end
179
+
180
+ rule p3_binary_expression
181
+ l:p2_binary_expression r:(space* op:p3_binary_operator space* r:p2_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
182
+ /
183
+ p2_binary_expression
184
+ end
185
+
186
+ rule template_safe_p3_binary_expression
187
+ l:p2_binary_expression r:(space* op:p3_template_binary_operator space* r:p2_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
188
+ /
189
+ p2_binary_expression
190
+ end
191
+
192
+ rule p4_binary_expression
193
+ l:p3_binary_expression r:(space* op:p4_binary_operator space* r:p3_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
194
+ /
195
+ p3_binary_expression
196
+ end
197
+
198
+ rule template_safe_p4_binary_expression
199
+ l:template_safe_p3_binary_expression r:(space* op:p4_binary_operator space* r:p3_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
200
+ /
201
+ template_safe_p3_binary_expression
202
+ end
203
+
204
+ rule p5_binary_expression
205
+ l:p4_binary_expression r:(space* op:p5_binary_operator space* r:p4_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
206
+ /
207
+ p4_binary_expression
208
+ end
209
+
210
+ rule template_safe_p5_binary_expression
211
+ l:template_safe_p4_binary_expression r:(space* op:p5_binary_operator space* r:p4_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
212
+ /
213
+ template_safe_p4_binary_expression
214
+ end
215
+
216
+ rule p6_binary_expression
217
+ l:p5_binary_expression r:(space* op:p6_binary_operator space* r:p5_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
218
+ /
219
+ p5_binary_expression
220
+ end
221
+
222
+ rule template_safe_p6_binary_expression
223
+ l:template_safe_p5_binary_expression r:(space* op:p6_binary_operator space* r:p5_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
224
+ /
225
+ template_safe_p5_binary_expression
226
+ end
227
+
228
+ rule p7_binary_expression
229
+ l:p6_binary_expression r:(space* op:p7_binary_operator space* r:p6_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
230
+ /
231
+ p6_binary_expression
232
+ end
233
+
234
+ rule template_safe_p7_binary_expression
235
+ l:template_safe_p6_binary_expression r:(space* op:p7_binary_operator space* r:p6_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
236
+ /
237
+ template_safe_p6_binary_expression
238
+ end
239
+
240
+ rule p8_binary_expression
241
+ l:p7_binary_expression r:(space* op:p8_binary_operator space* r:p7_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
242
+ /
243
+ p7_binary_expression
244
+ end
245
+
246
+ rule template_safe_p8_binary_expression
247
+ l:template_safe_p7_binary_expression r:(space* op:p8_binary_operator space* r:p7_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
248
+ /
249
+ template_safe_p7_binary_expression
250
+ end
251
+
252
+ rule p9_binary_expression
253
+ l:p8_binary_expression r:(space* op:p9_binary_operator space* r:p8_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
254
+ /
255
+ p8_binary_expression
256
+ end
257
+
258
+ rule template_safe_p9_binary_expression
259
+ l:template_safe_p8_binary_expression r:(space* op:p9_binary_operator space* r:p8_binary_expression)+ <Idl::BinaryExpressionRightSyntaxNode>
260
+ /
261
+ template_safe_p8_binary_expression
262
+ end
263
+
264
+ rule paren_expression
265
+ '(' space* e:expression space* ')' <Idl::ParenExpressionSyntaxNode>
266
+ end
267
+
268
+ rule replication_expression
269
+ # verilog-style replication
270
+ '{' space* n:expression space* '{' space* v:expression space* '}' space* '}' <Idl::ReplicationExpressionSyntaxNode>
271
+ end
272
+
273
+ rule concatenation_expression
274
+ # verilog-style concatenation
275
+ '{' space* first:expression rest:(space* ',' space* expression)* space* '}' <Idl::ConcatenationExpressionSyntaxNode>
276
+ end
277
+
278
+ rule csr_field_access_expression
279
+ # CSR field access
280
+ csr:csr_register_access_expression space* '.' space* csr_field_name <Idl::CsrFieldReadExpressionSyntaxNode>
281
+ end
282
+
283
+ rule csr_register_access_expression
284
+ # CSR register access
285
+ 'CSR' space* '[' space* csr_name space* ']' <Idl::CsrReadExpressionSyntaxNode>
286
+ end
287
+
288
+ rule field_access_eligible_expression
289
+ paren_expression
290
+ /
291
+ function_call # Ast is assigned in function_call rule
292
+ /
293
+ rval # must come last!
294
+ end
295
+
296
+ rule field_access_expression
297
+ field_access_eligible_expression space* '.' space* field_name <Idl::FieldAccessExpressionSyntaxNode>
298
+ end
299
+
300
+ # expression that can accept an array index operator (expr[])
301
+ rule ary_eligible_expression
302
+ enum_to_a
303
+ /
304
+ paren_expression
305
+ /
306
+ replication_expression
307
+ /
308
+ concatenation_expression
309
+ /
310
+ field_access_expression
311
+ /
312
+ function_call # Ast is assigned in function_call rule
313
+ /
314
+ csr_field_access_expression
315
+ /
316
+ bits_cast
317
+ /
318
+ rval # must come last!
319
+ end
320
+
321
+ rule ary_access
322
+ a:ary_eligible_expression space* brackets:('[' space* msb:(expression space* ':' space*)? lsb:expression space* ']' space*)+ <Idl::AryAccessSyntaxNode>
323
+ end
324
+
325
+ rule post_dec
326
+ rval space* '--' <Idl::PostDecrementExpressionSyntaxNode>
327
+ end
328
+
329
+ rule post_inc
330
+ rval space* '++' <Idl::PostIncrementExpressionSyntaxNode>
331
+ end
332
+
333
+ rule bits_cast
334
+ '$bits' space* '(' space*
335
+ expr:(
336
+ csr_register_access_expression
337
+ /
338
+ enum_ref
339
+ /
340
+ expression
341
+ )
342
+ space* ')' <Idl::BitsCastSyntaxNode>
343
+ end
344
+
345
+ rule enum_to_a
346
+ '$enum_to_a' space* '(' space* type_name ')' <Idl::EnumArrayCastSyntaxNode>
347
+ end
348
+
349
+ rule unary_expression
350
+ 'true' <Idl::TrueExpressionSyntaxNode>
351
+ /
352
+ 'false' <Idl::FalseExpressionSyntaxNode>
353
+ /
354
+ '[' space* first:expression rest:(space* ',' space* expression)* space* ']' <Idl::ArrayLiteralSyntaxNode>
355
+ /
356
+ ary_access
357
+ /
358
+ # get the width (N) of a Bits type. Mostly just useful for writing tests and checking types
359
+ '$width' space* '(' space* expression space* ')' <Idl::WidthRevealSyntaxNode>
360
+ /
361
+ '$signed' space* '(' space* expression space* ')' <Idl::SignCastSyntaxNode>
362
+ /
363
+ bits_cast
364
+ /
365
+ '$enum_size' space* '(' space* type_name ')' <Idl::EnumSizeSyntaxNode>
366
+ /
367
+ '$enum_element_size' space* '(' space* type_name ')' <Idl::EnumElementSizeSyntaxNode>
368
+ /
369
+ enum_to_a
370
+ /
371
+ '$enum' space* '(' space* type_name space* ',' space* expression space* ')' <Idl::EnumCastSyntaxNode>
372
+ /
373
+ '$array_size' space* '(' space* expression ')' <Idl::ArraySizeSyntaxNode>
374
+ /
375
+ '$array_includes?' space* '(' space* ary:ary_eligible_expression space* ',' space* value:expression space* ')' <Idl::ArrayIncludesSyntaxNode>
376
+ /
377
+ paren_expression
378
+ /
379
+ o:unary_operator space* e:unary_expression <Idl::UnaryOperatorExpressionSyntaxNode>
380
+ /
381
+ post_dec
382
+ /
383
+ post_inc
384
+ /
385
+ replication_expression
386
+ /
387
+ concatenation_expression
388
+ /
389
+ field_access_expression
390
+ /
391
+ function_call # Ast is assigned in function_call rule
392
+ /
393
+ csr_field_access_expression
394
+ /
395
+ enum_ref
396
+ /
397
+ rval # must come last
398
+ end
399
+
400
+ rule ternary_expression
401
+ e:p9_binary_expression space* '?' space* t:expression space* ':' space* f:expression <Idl::TernaryOperatorExpressionSyntaxNode>
402
+ end
403
+
404
+ rule template_safe_ternary_expression
405
+ e:template_safe_p9_binary_expression space* '?' space* t:expression space* ':' space* f:expression <Idl::TernaryOperatorExpressionSyntaxNode>
406
+ end
407
+
408
+ rule implication_expression
409
+ '(' space* antecedent:p9_binary_expression? space* '->' space* consequent:p9_binary_expression space* ')'? <Idl::ImplicationExpressionSyntaxNode>
410
+ /
411
+ antecedent:p9_binary_expression? space* '->' space* consequent:p9_binary_expression <Idl::ImplicationExpressionSyntaxNode>
412
+ end
413
+
414
+ rule implication_for_loop
415
+ 'for' space* '(' space* for_loop_iteration_variable_declaration space* ';' space* condition:expression space* ';' space* action:(assignment / post_inc / post_dec) space* ')' space* '{' space*
416
+ stmts:(s:(implication_statement / implication_for_loop) space*)+
417
+ '}' <Idl::ForLoopSyntaxNode>
418
+ end
419
+
420
+ rule implication_statement
421
+ implication_expression space* ';' <Idl::ImplicationStatementSyntaxNode>
422
+ end
423
+
424
+ rule constraint_body
425
+ space* b:(i:(implication_statement / implication_for_loop) space*)+ <Idl::ConstraintBodySyntaxNode>
426
+ end
427
+
428
+ rule expression
429
+ (
430
+ ternary_expression
431
+ /
432
+ p9_binary_expression
433
+ )
434
+ end
435
+
436
+
437
+ rule template_safe_expression
438
+ (
439
+ template_safe_ternary_expression
440
+ /
441
+ template_safe_p9_binary_expression
442
+ )
443
+ end
444
+
445
+ rule function_call
446
+ csr:csr_register_access_expression space* '.' space* 'sw_write' space* '(' space* expression space* ')' <Idl::CsrSoftwareWriteSyntaxNode>
447
+ /
448
+ csr:csr_register_access_expression space* '.' space* function_name space* '(' space* function_arg_list space* ')' <Idl::CsrFunctionCallSyntaxNode>
449
+ /
450
+ function_name space* '(' space* function_arg_list space* ')' <Idl::FunctionCallExpressionSyntaxNode>
451
+ end
452
+
453
+ rule function_name
454
+ [a-zA-Z] [a-zA-Z0-9_]* '?'?
455
+ end
456
+
457
+ rule function_arg_list
458
+ first:expression? rest:(space* ',' space* expression)*
459
+ end
460
+
461
+ rule body_function_definition
462
+ type:('external' space+)? 'function' space+ function_name space* '{' space*
463
+ ret:('returns' space+ first:type_name rest:(space* ',' space* type_name)* space+)?
464
+ args:(
465
+ 'arguments' space+
466
+ first:single_declaration
467
+ rest:(space* ',' space* single_declaration)*
468
+ space+
469
+ )?
470
+ 'description' space* '{' space*
471
+ desc:([^}] / "\n")+
472
+ '}' space*
473
+ body_block:(
474
+ 'body' space* '{' space*
475
+ function_body space*
476
+ '}' space*
477
+ )
478
+ '}' <Idl::FunctionDefSyntaxNode>
479
+ end
480
+
481
+ rule builtin_function_definition
482
+ type:('builtin' / 'generated') space+ 'function' space+ function_name space* '{' space*
483
+ # templates are not supported for builtins
484
+ ret:('returns' space+ first:type_name space+)?
485
+ args:(
486
+ 'arguments' space+
487
+ first:single_declaration
488
+ rest:(space* ',' space* single_declaration)*
489
+ space+
490
+ )?
491
+ 'description' space* '{' space*
492
+ desc:([^}] / "\n")+
493
+ '}' space*
494
+ '}' <Idl::FunctionDefSyntaxNode>
495
+ end
496
+
497
+ rule fetch
498
+ 'fetch' space* '{' space*
499
+ function_body space*
500
+ '}' <Idl::FetchSyntaxNode>
501
+ end
502
+
503
+ rule function_definition
504
+ builtin_function_definition / body_function_definition
505
+ end
506
+
507
+ rule rval
508
+ (int / builtin_read_only_var / builtin_read_write_var / string / id)
509
+ end
510
+
511
+ rule assignment
512
+ '(' first:(id / dontcare_lvalue) space* rest:(',' space* var:(id / dontcare_lvalue) space*)+ ')' space* '=' space* function_call <Idl::MultiVariableAssignmentSyntaxNode> /
513
+ single_declaration_with_initialization /
514
+ '$pc' space* '=' space* rval:expression <Idl::PcAssignmentSyntaxNode> /
515
+ var:id space* '=' space* rval:expression <Idl::VariableAssignmentSyntaxNode> /
516
+ # note: there is no full CSR assignment (must assign fields)
517
+ csr_field_access_expression space* '=' space* rval:expression <Idl::CsrFieldAssignmentSyntaxNode> /
518
+ id space* '.' space* field_name space* '=' space* rval:expression <Idl::FieldAssignmentSyntaxNode> /
519
+ var:ary_eligible_expression space* '[' space* msb:expression space* ':' space* lsb:expression space* ']' space* '=' space* rval:expression <Idl::AryRangeAssignmentSyntaxNode> /
520
+ var:ary_eligible_expression space* '[' space* idx:expression space* ']' space* '=' space* rval:expression <Idl::AryElementAssignmentSyntaxNode>
521
+ end
522
+
523
+ rule ary_size_decl
524
+ '[' space* expression space* ']'
525
+ end
526
+
527
+ rule single_declaration_with_initialization
528
+ type_name space+ id space* ary_size:ary_size_decl? space* '=' space* rval:expression <Idl::VariableDeclarationWithInitializationSyntaxNode>
529
+ end
530
+
531
+ # same as single_declaration_with_initialization, but treated specially for semantics (iteration variable can be treated as const even if it's written to, as long as it would be const in a loop unrolling)
532
+ rule for_loop_iteration_variable_declaration
533
+ type_name space+ id space* ary_size:ary_size_decl? space* '=' space* rval:expression <Idl::ForLoopIterationVariableDeclarationSyntaxNode>
534
+ end
535
+
536
+ rule declaration
537
+ type_name space+ first:id space* rest:(space* ',' space* id)+ space* <Idl::MultiVariableDeclarationSyntaxNode>
538
+ /
539
+ single_declaration
540
+ end
541
+
542
+ rule single_declaration
543
+ type_name space+ id ary_size:(space* ary_size_decl)? <Idl::VariableDeclarationSyntaxNode>
544
+ end
545
+
546
+ rule statement
547
+ a:(function_call / assignment) space* 'if' space* expression space* ';' <Idl::ConditionalStatementSyntaxNode>
548
+ /
549
+ a:(function_call / assignment / declaration) space* ';' <Idl::StatementSyntaxNode>
550
+ end
551
+
552
+ rule dontcare_lvalue
553
+ '-' <Idl::DontCareLvalueSyntaxNode>
554
+ end
555
+
556
+ rule dontcare_return
557
+ '-' <Idl::DontCareReturnSyntaxNode>
558
+ end
559
+
560
+ rule return_expression
561
+ 'return' vals:(first:(space+ e:(expression/dontcare_return))? rest:(space* ',' space* e:(expression/dontcare_return))*) <Idl::ReturnExpressionSyntaxNode>
562
+ end
563
+
564
+ rule return_statement
565
+ return_expression space* 'if' space* expression space* ';' <Idl::ConditionalReturnStatementSyntaxNode>
566
+ /
567
+ return_expression space* ';' <Idl::ReturnStatementSyntaxNode>
568
+ end
569
+
570
+ rule function_if_block
571
+ 'if' space* '(' space* if_cond:expression space* ')' space* '{' space*
572
+ if_body:(e:(return_statement / statement / function_if_block / for_loop) space*)+
573
+ '}'
574
+ elseifs:(
575
+ space* 'else' space+ 'if' space* '(' space* expression space* ')' space* '{' space*
576
+ body:(e:(return_statement / statement / function_if_block / for_loop) space*)+
577
+ '}'
578
+ )*
579
+ final_else:(
580
+ space* 'else' space* '{' space*
581
+ body:(e:(return_statement / statement / function_if_block / for_loop) space*)+
582
+ '}'
583
+ )? <Idl::IfSyntaxNode>
584
+ end
585
+
586
+ rule execute_if_block
587
+ 'if' space* '(' space* if_cond:expression space* ')' space* '{' space*
588
+ if_body:(e:(statement / execute_if_block / for_loop) space*)+
589
+ '}'
590
+ elseifs:(
591
+ space* 'else' space+ 'if' space* '(' space* expression space* ')' space* '{' space*
592
+ body:(e:(statement / execute_if_block / for_loop) space*)+
593
+ '}'
594
+ )*
595
+ final_else:(
596
+ space* 'else' space* '{' space*
597
+ body:(e:(statement / execute_if_block / for_loop) space*)+
598
+ '}'
599
+ )? <Idl::IfSyntaxNode>
600
+ end
601
+
602
+ rule for_loop
603
+ 'for' space* '(' space* for_loop_iteration_variable_declaration space* ';' space* condition:expression space* ';' space* action:(assignment / post_inc / post_dec) space* ')' space* '{' space*
604
+ stmts:(s:(return_statement / statement / function_if_block / for_loop) space*)+
605
+ '}' space* <Idl::ForLoopSyntaxNode>
606
+ end
607
+
608
+ rule field_name
609
+ [a-zA-Z] [a-zA-Z0-9_]*
610
+ end
611
+
612
+ rule type_name
613
+ (
614
+ 'Bits' space* '<' space* i:template_safe_expression space* '>' ![A-Za-z0-9]
615
+ /
616
+ [A-Z] [A-Za-z0-9_]*
617
+ ) <Idl::TypeNameSyntaxNode>
618
+ end
619
+
620
+ rule comment
621
+ '#' content:(!"\n" .)* "\n" # <Idl::CommentSyntaxNode>
622
+ end
623
+
624
+ rule function_statement
625
+ (return_statement/statement/function_if_block/for_loop)
626
+ end
627
+
628
+ rule function_body
629
+ space* func_stmt_list:(choice:function_statement space*)* <Idl::FunctionBodySyntaxNode>
630
+ end
631
+
632
+ rule instruction_operation
633
+ space* op_stmt_list:(choice:(statement/execute_if_block/for_loop) space*)* <Idl::InstructionOperationSyntaxNode>
634
+ end
635
+
636
+ rule id
637
+ # we purposely omit _ from the starting character so that tools can safely use such names
638
+ # without worrying about name collisions
639
+ [A-Za-z] [A-Za-z_0-9]* <Idl::IdSyntaxNode>
640
+ end
641
+
642
+ rule builtin_read_only_var
643
+ "$encoding" <Idl::BuiltinVariableSyntaxNode>
644
+ end
645
+
646
+ rule builtin_read_write_var
647
+ "$pc" <Idl::BuiltinVariableSyntaxNode>
648
+ end
649
+
650
+ rule csr_name
651
+ [a-z] [a-z0-9_.]*
652
+ end
653
+
654
+ rule csr_field_name
655
+ [a-zA-Z] ([a-zA-Z0-9])*
656
+ end
657
+
658
+ rule var_write
659
+ 'CSR' space* '[' space* csr_name space* ']' <Idl::CsrWriteSyntaxNode>
660
+ /
661
+ id
662
+ end
663
+
664
+ rule string
665
+ # doesn't handle any escaping of quotes; if we ever need it, that can change later
666
+ '"' (!'"' .)* '"' <Idl::StringLiteralSyntaxNode>
667
+ end
668
+
669
+ rule space
670
+ ([ \n] / comment) {
671
+ def space? = true
672
+ }
673
+ end
674
+
675
+ end