Skip to content

Commit 87db691

Browse files
committed
Emit try_table instruction
1 parent 9579132 commit 87db691

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
@@ -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/wat_output.ml

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

0 commit comments

Comments
 (0)