Skip to content

Commit 2b2cfdb

Browse files
committed
Emit try_table instruction
1 parent e0c625c commit 2b2cfdb

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

compiler/lib/wasm/wa_wasm_output.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,15 +630,16 @@ end = struct
630630
output_byte ch 0x0B
631631
| Try (typ, l, catches) ->
632632
Feature.require exception_handling;
633-
output_byte ch 0x06;
633+
output_byte ch 0x1f;
634634
output_blocktype st.type_names ch typ;
635-
List.iter ~f:(fun i' -> output_instruction st ch i') l;
635+
output_uint ch (List.length catches);
636636
List.iter
637-
~f:(fun (tag, l, ty) ->
638-
output_byte ch 0x07;
637+
~f:(fun (tag, l, _) ->
638+
output_byte ch 0x00;
639639
output_uint ch (Hashtbl.find st.tag_names tag);
640-
output_instruction st ch (Br (l + 1, Some (Pop ty))))
640+
output_uint ch l)
641641
catches;
642+
List.iter ~f:(fun i' -> output_instruction st ch i') l;
642643
output_byte ch 0X0B
643644

644645
and output_instruction st ch i =

compiler/lib/wasm/wa_wat_output.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,13 @@ let expression_or_instructions ctx st in_function =
430430
]
431431
| Try (ty, body, catches) ->
432432
[ List
433-
(Atom "try"
433+
(Atom "try_table"
434434
:: (block_type st ty
435-
@ List (Atom "do" :: instructions body)
436-
:: List.map
437-
~f:(fun (tag, i, ty) ->
438-
List
439-
(Atom "catch"
440-
:: index st.tag_names tag
441-
:: instruction (Wa_ast.Br (i + 1, Some (Pop ty)))))
442-
catches))
435+
@ List.map
436+
~f:(fun (tag, i, _ty) ->
437+
List [ Atom "catch"; index st.tag_names tag; Atom (string_of_int i) ])
438+
catches
439+
@ instructions body))
443440
]
444441
and instruction i =
445442
match i with

0 commit comments

Comments
 (0)