@@ -373,16 +373,12 @@ align_opt :
373
373
374
374
/* Instructions & Expressions */
375
375
376
- instr_list :
377
- | /* empty */ { fun c -> [] }
378
- | instr1 instr_list { fun c -> $1 c @ $2 c }
379
- | select_instr_instr_list { $1 }
380
- | call_instr_instr_list { $1 }
381
-
382
- instr1 :
376
+ instr :
383
377
| plain_instr { let at = at () in fun c -> [$1 c @@ at] }
378
+ | select_instr_instr { fun c -> let e, es = $1 c in e :: es }
379
+ | call_instr_instr { fun c -> let e, es = $1 c in e :: es }
384
380
| block_instr { let at = at () in fun c -> [$1 c @@ at] }
385
- | expr { $1 } /* Sugar */
381
+ | expr { $1 } /* Sugar */
386
382
387
383
plain_instr :
388
384
| UNREACHABLE { fun c -> unreachable }
@@ -455,51 +451,89 @@ plain_instr :
455
451
| VEC_REPLACE NAT { let at = at () in fun c -> $1 (vec_lane_index $2 at) }
456
452
457
453
458
- select_instr_instr_list :
459
- | SELECT select_instr_results_instr_list
454
+ select_instr :
455
+ | SELECT select_instr_results
456
+ { let at = at () in fun c -> let b, ts = $2 in
457
+ select (if b then (Some ts) else None) @@ at }
458
+
459
+ select_instr_results :
460
+ | LPAR RESULT value_type_list RPAR select_instr_results
461
+ { let _, ts = $5 in true, $3 @ ts }
462
+ | /* empty */
463
+ { false, [] }
464
+
465
+ select_instr_instr :
466
+ | SELECT select_instr_results_instr
460
467
{ let at1 = ati 1 in
461
468
fun c -> let b, ts, es = $2 c in
462
- ( select (if b then (Some ts) else None) @@ at1) :: es }
469
+ select (if b then (Some ts) else None) @@ at1, es }
463
470
464
- select_instr_results_instr_list :
465
- | LPAR RESULT value_type_list RPAR select_instr_results_instr_list
471
+ select_instr_results_instr :
472
+ | LPAR RESULT value_type_list RPAR select_instr_results_instr
466
473
{ fun c -> let _, ts, es = $5 c in true, $3 @ ts, es }
467
- | instr_list
474
+ | instr
468
475
{ fun c -> false, [], $1 c }
469
476
470
477
471
- call_instr_instr_list :
472
- | CALL_INDIRECT var call_instr_type_instr_list
478
+ call_instr :
479
+ | CALL_INDIRECT var call_instr_type
480
+ { let at = at () in fun c -> call_indirect ($2 c table) ($3 c) @@ at }
481
+ | CALL_INDIRECT call_instr_type /* Sugar */
482
+ { let at = at () in fun c -> call_indirect (0l @@ at) ($2 c) @@ at }
483
+
484
+ call_instr_type :
485
+ | type_use call_instr_params
486
+ { let at1 = ati 1 in
487
+ fun c ->
488
+ match $2 c with
489
+ | FuncType ([], []) -> $1 c type_
490
+ | ft -> inline_type_explicit c ($1 c type_) ft at1 }
491
+ | call_instr_params
492
+ { let at = at () in fun c -> inline_type c ($1 c) at }
493
+
494
+ call_instr_params :
495
+ | LPAR PARAM value_type_list RPAR call_instr_params
496
+ { fun c -> let FuncType (ts1, ts2) = $5 c in FuncType ($3 @ ts1, ts2) }
497
+ | call_instr_results
498
+ { fun c -> FuncType ([], $1 c) }
499
+
500
+ call_instr_results :
501
+ | LPAR RESULT value_type_list RPAR call_instr_results
502
+ { fun c -> $3 @ $5 c }
503
+ | /* empty */
504
+ { fun c -> [] }
505
+
506
+
507
+ call_instr_instr :
508
+ | CALL_INDIRECT var call_instr_type_instr
473
509
{ let at1 = ati 1 in
474
- fun c -> let x, es = $3 c in
475
- (call_indirect ($2 c table) x @@ at1) :: es }
476
- | CALL_INDIRECT call_instr_type_instr_list /* Sugar */
510
+ fun c -> let x, es = $3 c in call_indirect ($2 c table) x @@ at1, es }
511
+ | CALL_INDIRECT call_instr_type_instr /* Sugar */
477
512
{ let at1 = ati 1 in
478
- fun c -> let x, es = $2 c in
479
- (call_indirect (0l @@ at1) x @@ at1) :: es }
513
+ fun c -> let x, es = $2 c in call_indirect (0l @@ at1) x @@ at1, es }
480
514
481
- call_instr_type_instr_list :
482
- | type_use call_instr_params_instr_list
515
+ call_instr_type_instr :
516
+ | type_use call_instr_params_instr
483
517
{ let at1 = ati 1 in
484
518
fun c ->
485
519
match $2 c with
486
520
| FuncType ([], []), es -> $1 c type_, es
487
521
| ft, es -> inline_type_explicit c ($1 c type_) ft at1, es }
488
- | call_instr_params_instr_list
522
+ | call_instr_params_instr
489
523
{ let at = at () in
490
524
fun c -> let ft, es = $1 c in inline_type c ft at, es }
491
525
492
- call_instr_params_instr_list :
493
- | LPAR PARAM value_type_list RPAR call_instr_params_instr_list
526
+ call_instr_params_instr :
527
+ | LPAR PARAM value_type_list RPAR call_instr_params_instr
494
528
{ fun c ->
495
529
let FuncType (ts1, ts2), es = $5 c in FuncType ($3 @ ts1, ts2), es }
496
- | call_instr_results_instr_list
530
+ | call_instr_results_instr
497
531
{ fun c -> let ts, es = $1 c in FuncType ([], ts), es }
498
532
499
- call_instr_results_instr_list :
500
- | LPAR RESULT value_type_list RPAR call_instr_results_instr_list
533
+ call_instr_results_instr :
534
+ | LPAR RESULT value_type_list RPAR call_instr_results_instr
501
535
{ fun c -> let ts, es = $5 c in $3 @ ts, es }
502
- | instr_list
536
+ | instr
503
537
{ fun c -> [], $1 c }
504
538
505
539
@@ -710,6 +744,12 @@ try_ :
710
744
| LPAR DO instr_list RPAR handler
711
745
{ fun bt c c' -> $5 bt ($3 c') c c' }
712
746
747
+ instr_list :
748
+ | /* empty */ { fun c -> [] }
749
+ | select_instr { fun c -> [$1 c] }
750
+ | call_instr { fun c -> [$1 c] }
751
+ | instr instr_list { fun c -> $1 c @ $2 c }
752
+
713
753
expr_list :
714
754
| /* empty */ { fun c -> [] }
715
755
| expr expr_list { fun c -> $1 c @ $2 c }
0 commit comments