Skip to content

Commit

Permalink
Emit try_table instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Nov 5, 2024
1 parent 1d65876 commit edf4da9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 6 additions & 5 deletions compiler/lib-wasm/wa_wasm_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,16 @@ end = struct
output_byte ch 0x0B
| Try (typ, l, catches) ->
Feature.require exception_handling;
output_byte ch 0x06;
output_byte ch 0x1f;
output_blocktype st.type_names ch typ;
List.iter ~f:(fun i' -> output_instruction st ch i') l;
output_uint ch (List.length catches);
List.iter
~f:(fun (tag, l, ty) ->
output_byte ch 0x07;
~f:(fun (tag, l, _) ->
output_byte ch 0x00;
output_uint ch (Hashtbl.find st.tag_names tag);
output_instruction st ch (Br (l + 1, Some (Pop ty))))
output_uint ch l)
catches;
List.iter ~f:(fun i' -> output_instruction st ch i') l;
output_byte ch 0X0B

and output_instruction st ch i =
Expand Down
17 changes: 6 additions & 11 deletions compiler/lib-wasm/wa_wat_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,13 @@ let expression_or_instructions ctx st in_function =
]
| Try (ty, body, catches) ->
[ List
(Atom "try"
(Atom "try_table"
:: (block_type st ty
@ List (Atom "do" :: instructions body)
:: List.map
~f:(fun (tag, i, ty) ->
List
(Atom "catch"
:: index st.tag_names tag
:: (instruction
(Wa_ast.Event Wa_code_generation.hidden_location)
@ instruction (Wa_ast.Br (i + 1, Some (Pop ty))))))
catches))
@ List.map
~f:(fun (tag, i, _ty) ->
List [ Atom "catch"; index st.tag_names tag; Atom (string_of_int i) ])
catches
@ instructions body))
]
and instruction i =
match i with
Expand Down

0 comments on commit edf4da9

Please sign in to comment.