Skip to content

Commit c2414b3

Browse files
committed
Wasm AST: add br_on_null
1 parent 03f41d2 commit c2414b3

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

compiler/lib-wasm/code_generation.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ let rec is_smi e =
474474
| RefNull _
475475
| Br_on_cast _
476476
| Br_on_cast_fail _
477+
| Br_on_null _
477478
| Try _
478479
| ExternConvertAny _ -> false
479480
| BinOp ((F32 _ | F64 _), _, _) | RefTest _ | RefEq _ -> true

compiler/lib-wasm/gc_target.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ module Value = struct
528528
| Call_ref _
529529
| Br_on_cast _
530530
| Br_on_cast_fail _
531+
| Br_on_null _
531532
| Try _ -> false
532533
| IfExpr (_, e1, e2, e3) -> effect_free e1 && effect_free e2 && effect_free e3
533534
| ArrayNewFixed (_, l) | StructNew (_, l) -> List.for_all ~f:effect_free l

compiler/lib-wasm/initialize_locals.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let rec scan_expression ctx e =
4747
| RefTest (_, e')
4848
| Br_on_cast (_, _, _, e')
4949
| Br_on_cast_fail (_, _, _, e')
50+
| Br_on_null (_, e') -> scan_expression ctx e'
5051
| ExternConvertAny e' -> scan_expression ctx e'
5152
| BinOp (_, e', e'')
5253
| ArrayNew (_, e', e'')

compiler/lib-wasm/wasm_ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ type expression =
167167
| RefNull of heap_type
168168
| Br_on_cast of int * ref_type * ref_type * expression
169169
| Br_on_cast_fail of int * ref_type * ref_type * expression
170+
| Br_on_null of int * expression
170171
| IfExpr of value_type * expression * expression * expression
171172
| Try of func_type * instruction list * (var * int * value_type) list
172173
| ExternConvertAny of expression

compiler/lib-wasm/wasm_output.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ end = struct
645645
output_uint ch i;
646646
output_heaptype st.type_names ch typ1.typ;
647647
output_heaptype st.type_names ch typ2.typ
648+
| Br_on_null (i, e') ->
649+
Feature.require gc;
650+
output_expression st ch e';
651+
output_byte ch 0xD5;
652+
output_uint ch i
648653
| IfExpr (typ, e1, e2, e3) ->
649654
output_expression st ch e1;
650655
output_byte ch 0x04;
@@ -885,6 +890,7 @@ end = struct
885890
| RefTest (_, e')
886891
| Br_on_cast (_, _, _, e')
887892
| Br_on_cast_fail (_, _, _, e')
893+
| Br_on_null (_, e') -> expr_function_references e' set
888894
| ExternConvertAny e' -> expr_function_references e' set
889895
| BinOp (_, e', e'')
890896
| ArrayNew (_, e', e'')

compiler/lib-wasm/wat_output.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ let expression_or_instructions ctx st in_function =
452452
:: ref_type st ty'
453453
:: expression e)
454454
]
455+
| Br_on_null (i, e) ->
456+
[ List (Atom "br_on_null" :: Atom (string_of_int i) :: expression e) ]
455457
| IfExpr (ty, cond, ift, iff) ->
456458
[ List
457459
((Atom "if" :: block_type st { params = []; result = [ ty ] })

0 commit comments

Comments
 (0)