Skip to content

Commit 2cbb817

Browse files
committed
Emit try_table instruction
1 parent bb3b65c commit 2cbb817

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

compiler/lib-wasm/wasm_output.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,16 @@ end = struct
648648
output_byte ch 0x0B
649649
| Try (typ, l, catches) ->
650650
Feature.require exception_handling;
651-
output_byte ch 0x06;
651+
output_byte ch 0x1f;
652652
output_blocktype st.type_names ch typ;
653-
List.iter ~f:(fun i' -> output_instruction st ch i') l;
653+
output_uint ch (List.length catches);
654654
List.iter
655-
~f:(fun (tag, l, ty) ->
656-
output_byte ch 0x07;
655+
~f:(fun (tag, l, _) ->
656+
output_byte ch 0x00;
657657
output_uint ch (Hashtbl.find st.tag_names tag);
658-
output_instruction st ch (Br (l + 1, Some (Pop ty))))
658+
output_uint ch l)
659659
catches;
660+
List.iter ~f:(fun i' -> output_instruction st ch i') l;
660661
output_byte ch 0X0B
661662

662663
and output_instruction st ch i =

compiler/lib-wasm/wat_output.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,13 @@ let expression_or_instructions ctx st in_function =
445445
]
446446
| Try (ty, body, catches) ->
447447
[ List
448-
(Atom "try"
448+
(Atom "try_table"
449449
:: (block_type st ty
450-
@ List (Atom "do" :: instructions body)
451-
:: List.map
452-
~f:(fun (tag, i, ty) ->
453-
List
454-
(Atom "catch"
455-
:: index st.tag_names tag
456-
:: (instruction (Wasm_ast.Event Code_generation.hidden_location)
457-
@ instruction (Wasm_ast.Br (i + 1, Some (Pop ty))))))
458-
catches))
450+
@ List.map
451+
~f:(fun (tag, i, _ty) ->
452+
List [ Atom "catch"; index st.tag_names tag; Atom (string_of_int i) ])
453+
catches
454+
@ instructions body))
459455
]
460456
and instruction i =
461457
match i with

0 commit comments

Comments
 (0)