@@ -36,7 +36,7 @@ module Generate (Target : Target_sig.S) = struct
36
36
{ live : int array
37
37
; in_cps : Effects .in_cps
38
38
; deadcode_sentinal : Var .t
39
- ; blocks : block Addr.Map .t
39
+ ; p : program
40
40
; closures : Closure_conversion .closure Var.Map .t
41
41
; global_context : Code_generation .context
42
42
}
@@ -830,7 +830,7 @@ module Generate (Target : Target_sig.S) = struct
830
830
Code. traverse
831
831
{ fold = fold_children_skip_try_body }
832
832
(fun pc n ->
833
- let block = Addr.Map. find pc p.blocks in
833
+ let block = Code. block pc p in
834
834
List. fold_left
835
835
~f: (fun n i ->
836
836
match i with
@@ -863,7 +863,7 @@ module Generate (Target : Target_sig.S) = struct
863
863
~init: n
864
864
block.body)
865
865
pc
866
- p.blocks
866
+ p
867
867
(false , false )
868
868
869
869
let wrap_with_handler needed pc handler ~result_typ ~fall_through ~context body =
@@ -914,18 +914,18 @@ module Generate (Target : Target_sig.S) = struct
914
914
((pc , _ ) as cont )
915
915
cloc
916
916
acc =
917
- let g = Structure. build_graph ctx.blocks pc in
917
+ let g = Structure. build_graph ctx.p pc in
918
918
let dom = Structure. dominator_tree g in
919
919
let rec translate_tree result_typ fall_through pc context =
920
- let block = Addr.Map. find pc ctx.blocks in
920
+ let block = Code. block pc ctx.p in
921
921
let keep_ouside pc' =
922
922
match block.branch with
923
923
| Switch _ -> true
924
924
| Cond (_ , (pc1 , _ ), (pc2 , _ )) when pc' = pc1 && pc' = pc2 -> true
925
925
| _ -> Structure. is_merge_node g pc'
926
926
in
927
927
let code ~context =
928
- let block = Addr.Map. find pc ctx.blocks in
928
+ let block = Code. block pc ctx.p in
929
929
let * () = translate_instrs ctx context block.body in
930
930
translate_node_within
931
931
~result_typ
@@ -960,7 +960,7 @@ module Generate (Target : Target_sig.S) = struct
960
960
if
961
961
(not (List. is_empty rem))
962
962
||
963
- let block = Addr.Map. find pc ctx.blocks in
963
+ let block = Code. block pc ctx.p in
964
964
match block.branch with
965
965
| Cond _ | Pushtrap _ -> false (* ZZZ also some Switch*)
966
966
| _ -> true
@@ -970,7 +970,7 @@ module Generate (Target : Target_sig.S) = struct
970
970
in
971
971
translate_tree result_typ fall_through pc' context
972
972
| [] -> (
973
- let block = Addr.Map. find pc ctx.blocks in
973
+ let block = Code. block pc ctx.p in
974
974
let branch = block.branch in
975
975
match branch with
976
976
| Branch cont -> translate_branch result_typ fall_through pc cont context
@@ -1028,7 +1028,7 @@ module Generate (Target : Target_sig.S) = struct
1028
1028
if List. is_empty args
1029
1029
then return ()
1030
1030
else
1031
- let block = Addr.Map. find dst ctx.blocks in
1031
+ let block = Code. block dst ctx.p in
1032
1032
parallel_renaming block.params args
1033
1033
in
1034
1034
match fall_through with
@@ -1077,7 +1077,7 @@ module Generate (Target : Target_sig.S) = struct
1077
1077
~param_names
1078
1078
~body:
1079
1079
(let * () =
1080
- let block = Addr.Map. find pc ctx.blocks in
1080
+ let block = Code. block pc ctx.p in
1081
1081
match block.body with
1082
1082
| Event start_loc :: _ -> event start_loc
1083
1083
| _ -> no_event
@@ -1190,13 +1190,7 @@ module Generate (Target : Target_sig.S) = struct
1190
1190
Code.Print.program (fun _ _ -> "") p;
1191
1191
*)
1192
1192
let ctx =
1193
- { live = live_vars
1194
- ; in_cps
1195
- ; deadcode_sentinal
1196
- ; blocks = p.blocks
1197
- ; closures
1198
- ; global_context
1199
- }
1193
+ { live = live_vars; in_cps; deadcode_sentinal; p; closures; global_context }
1200
1194
in
1201
1195
let toplevel_name = Var. fresh_n " toplevel" in
1202
1196
let functions =
@@ -1275,16 +1269,12 @@ let fix_switch_branches p =
1275
1269
with
1276
1270
| Some x -> x
1277
1271
| None ->
1278
- let pc' = ! p'.free_pc in
1272
+ let pc' = Code. free_pc ! p' in
1279
1273
p' :=
1280
- { ! p' with
1281
- blocks =
1282
- Addr.Map. add
1283
- pc'
1284
- { params = [] ; body = [] ; branch = Branch cont }
1285
- ! p'.blocks
1286
- ; free_pc = pc' + 1
1287
- };
1274
+ Code. add_block
1275
+ pc'
1276
+ { params = [] ; body = [] ; branch = Branch cont }
1277
+ ! p';
1288
1278
updates := Addr.Map. add pc ((args, pc') :: l) ! updates;
1289
1279
pc')
1290
1280
, [] ))
@@ -1295,7 +1285,7 @@ let fix_switch_branches p =
1295
1285
match block.branch with
1296
1286
| Switch (_ , l ) -> fix_branches l
1297
1287
| _ -> () )
1298
- p .blocks;
1288
+ ( Code . blocks p) ;
1299
1289
! p'
1300
1290
1301
1291
module G = Generate (Gc_target )
0 commit comments