Skip to content

Commit b607422

Browse files
committed
Wasm AST: add br_on_null
1 parent a3745b9 commit b607422

File tree

6 files changed

+14
-2
lines changed

6 files changed

+14
-2
lines changed

compiler/lib-wasm/code_generation.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ let rec is_smi e =
453453
| RefNull _
454454
| Br_on_cast _
455455
| Br_on_cast_fail _
456+
| Br_on_null _ -> false
456457
| Try _ -> false
457458
| BinOp ((F32 _ | F64 _), _, _) | RefTest _ | RefEq _ -> true
458459
| IfExpr (_, _, ift, iff) -> is_smi ift && is_smi iff

compiler/lib-wasm/gc_target.ml

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

compiler/lib-wasm/initialize_locals.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ let rec scan_expression ctx e =
4646
| RefCast (_, e')
4747
| RefTest (_, e')
4848
| Br_on_cast (_, _, _, e')
49-
| Br_on_cast_fail (_, _, _, e') -> scan_expression ctx e'
49+
| Br_on_cast_fail (_, _, _, e')
50+
| Br_on_null (_, e') -> scan_expression ctx e'
5051
| BinOp (_, e', e'')
5152
| ArrayNew (_, e', e'')
5253
| ArrayNewData (_, _, e', e'')

compiler/lib-wasm/wasm_ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ type expression =
164164
| RefNull of heap_type
165165
| Br_on_cast of int * ref_type * ref_type * expression
166166
| Br_on_cast_fail of int * ref_type * ref_type * expression
167+
| Br_on_null of int * expression
167168
| IfExpr of value_type * expression * expression * expression
168169
| Try of func_type * instruction list * (var * int * value_type) list
169170

compiler/lib-wasm/wasm_output.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ end = struct
638638
output_uint ch i;
639639
output_heaptype st.type_names ch typ1.typ;
640640
output_heaptype st.type_names ch typ2.typ
641+
| Br_on_null (i, e') ->
642+
Feature.require gc;
643+
output_expression st ch e';
644+
output_byte ch 0xD5;
645+
output_uint ch i
641646
| IfExpr (typ, e1, e2, e3) ->
642647
output_expression st ch e1;
643648
output_byte ch 0x04;
@@ -871,7 +876,8 @@ end = struct
871876
| RefCast (_, e')
872877
| RefTest (_, e')
873878
| Br_on_cast (_, _, _, e')
874-
| Br_on_cast_fail (_, _, _, e') -> expr_function_references e' set
879+
| Br_on_cast_fail (_, _, _, e')
880+
| Br_on_null (_, e') -> expr_function_references e' set
875881
| BinOp (_, e', e'')
876882
| ArrayNew (_, e', e'')
877883
| ArrayNewData (_, _, e', e'')

compiler/lib-wasm/wat_output.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ let expression_or_instructions ctx st in_function =
436436
:: ref_type st ty'
437437
:: expression e)
438438
]
439+
| Br_on_null (i, e) ->
440+
[ List (Atom "br_on_null" :: Atom (string_of_int i) :: expression e) ]
439441
| IfExpr (ty, cond, ift, iff) ->
440442
[ List
441443
((Atom "if" :: block_type st { params = []; result = [ ty ] })

0 commit comments

Comments
 (0)