@@ -32,6 +32,7 @@ module Generate (Target : Wa_target_sig.S) = struct
3232 type ctx =
3333 { live : int array
3434 ; in_cps : Effects .in_cps
35+ ; deadcode_sentinal : Var .t
3536 ; blocks : block Addr.Map .t
3637 ; closures : Wa_closure_conversion .closure Var.Map .t
3738 ; global_context : Wa_code_generation .context
@@ -209,7 +210,10 @@ module Generate (Target : Wa_target_sig.S) = struct
209210 let * closure = load f in
210211 return (W. Call (apply, args @ [ closure ]))
211212 | Block (tag , a , _ , _ ) ->
212- Memory. allocate ~tag (List. map ~f: (fun x -> `Var x) (Array. to_list a))
213+ Memory. allocate
214+ ~deadcode_sentinal: ctx.deadcode_sentinal
215+ ~tag
216+ (List. map ~f: (fun x -> `Var x) (Array. to_list a))
213217 | Field (x , n , Non_float) -> Memory. field (load x) n
214218 | Field (x , n , Float) ->
215219 Memory. float_array_get
@@ -633,7 +637,7 @@ module Generate (Target : Wa_target_sig.S) = struct
633637 l
634638 ~init: (return [] )
635639 in
636- Memory. allocate ~tag: 0 l
640+ Memory. allocate ~tag: 0 ~deadcode_sentinal: ctx.deadcode_sentinal l
637641 | Extern name , l -> (
638642 let name = Primitive. resolve name in
639643 try
@@ -1088,14 +1092,22 @@ module Generate (Target : Wa_target_sig.S) = struct
10881092 ~should_export
10891093 ~warn_on_unhandled_effect
10901094*)
1095+ ~deadcode_sentinal
10911096 ~debug =
10921097 global_context.unit_name < - unit_name;
10931098 let p, closures = Wa_closure_conversion. f p in
10941099 (*
10951100 Code.Print.program (fun _ _ -> "") p;
10961101*)
10971102 let ctx =
1098- { live = live_vars; in_cps; blocks = p.blocks; closures; global_context; debug }
1103+ { live = live_vars
1104+ ; in_cps
1105+ ; deadcode_sentinal
1106+ ; blocks = p.blocks
1107+ ; closures
1108+ ; global_context
1109+ ; debug
1110+ }
10991111 in
11001112 let toplevel_name = Var. fresh_n " toplevel" in
11011113 let functions =
@@ -1198,10 +1210,10 @@ let fix_switch_branches p =
11981210
11991211let start () = make_context ~value_type: Wa_gc_target.Value. value
12001212
1201- let f ~context ~unit_name p ~live_vars ~in_cps ~debug =
1213+ let f ~context ~unit_name p ~live_vars ~in_cps ~deadcode_sentinal ~ debug =
12021214 let p = if Config.Flag. effects () then fix_switch_branches p else p in
12031215 let module G = Generate (Wa_gc_target ) in
1204- G. f ~context ~unit_name ~live_vars ~in_cps ~debug p
1216+ G. f ~context ~unit_name ~live_vars ~in_cps ~deadcode_sentinal ~ debug p
12051217
12061218let add_start_function =
12071219 let module G = Generate (Wa_gc_target ) in
0 commit comments