Skip to content

Commit a292c4c

Browse files
committed
Compiler: add formatter to printing functions
1 parent 4a7ea49 commit a292c4c

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

compiler/lib/code.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,16 @@ module Print = struct
583583
| Instr of instr
584584
| Last of last
585585

586-
let block annot pc block =
587-
Format.eprintf "==== %d (%a) ====@." pc var_list block.params;
586+
let block f annot pc block =
587+
Format.fprintf f "==== %d (%a) ====@." pc var_list block.params;
588588
List.iter block.body ~f:(fun i ->
589-
Format.eprintf " %s %a@." (annot pc (Instr i)) instr i);
590-
Format.eprintf " %s %a@." (annot pc (Last block.branch)) last block.branch;
591-
Format.eprintf "@."
589+
Format.fprintf f " %s %a@." (annot pc (Instr i)) instr i);
590+
Format.fprintf f " %s %a@." (annot pc (Last block.branch)) last block.branch;
591+
Format.fprintf f "@."
592592

593-
let program annot { start; blocks; _ } =
594-
Format.eprintf "Entry point: %d@.@." start;
595-
Addr.Map.iter (block annot) blocks
593+
let program f annot { start; blocks; _ } =
594+
Format.fprintf f "Entry point: %d@.@." start;
595+
Addr.Map.iter (block f annot) blocks
596596
end
597597

598598
(****)

compiler/lib/code.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ module Print : sig
252252

253253
val instr : Format.formatter -> instr -> unit
254254

255-
val block : (Addr.Map.key -> xinstr -> string) -> int -> block -> unit
255+
val block :
256+
Format.formatter -> (Addr.Map.key -> xinstr -> string) -> int -> block -> unit
256257

257-
val program : (Addr.Map.key -> xinstr -> string) -> program -> unit
258+
val program : Format.formatter -> (Addr.Map.key -> xinstr -> string) -> program -> unit
258259

259260
val last : Format.formatter -> last -> unit
260261

compiler/lib/deadcode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ let f ({ blocks; _ } as p : Code.program) =
290290
}
291291
in
292292
mark_reachable st p.start;
293-
if debug () then Print.program (fun pc xi -> annot st pc xi) p;
293+
if debug () then Print.program Format.err_formatter (fun pc xi -> annot st pc xi) p;
294294
let all_blocks = blocks in
295295
let blocks =
296296
Addr.Map.fold

compiler/lib/driver.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ let exact_calls profile ~deadcode_sentinal p =
141141
| `Cps | `Double_translation -> p
142142

143143
let print p =
144-
if debug () then Code.Print.program (fun _ _ -> "") p;
144+
if debug () then Code.Print.program Format.err_formatter (fun _ _ -> "") p;
145145
p
146146

147147
let rec loop max name round i (p : 'a) : 'a =

compiler/lib/effects.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,13 @@ let subst_bound_in_blocks blocks s =
754754
if debug ()
755755
then (
756756
debug_print "@[<v>block before first subst: @,";
757-
Code.Print.block (fun _ _ -> "") pc block;
757+
Code.Print.block Format.err_formatter (fun _ _ -> "") pc block;
758758
debug_print "@]");
759759
let res = Subst.Including_Binders.block s block in
760760
if debug ()
761761
then (
762762
debug_print "@[<v>block after first subst: @,";
763-
Code.Print.block (fun _ _ -> "") pc res;
763+
Code.Print.block Format.err_formatter (fun _ _ -> "") pc res;
764764
debug_print "@]");
765765
res)
766766
blocks
@@ -861,6 +861,7 @@ let cps_transform ~live_vars ~flow_info ~cps_needed p =
861861
if Addr.Set.mem pc blocks_to_transform then Format.eprintf "CPS@.";
862862
let block = Addr.Map.find pc blocks in
863863
Code.Print.block
864+
Format.err_formatter
864865
(fun _ xi -> Partial_cps_analysis.annot cps_needed xi)
865866
pc
866867
block)
@@ -1129,7 +1130,7 @@ let f ~flow_info ~live_vars p =
11291130
Var.Set.iter (fun v -> debug_print "%s,@ " (Var.to_string v)) cps_needed;
11301131
debug_print "@]@,@]";
11311132
debug_print "@[<v>After lambda lifting...@,";
1132-
Code.Print.program (fun _ _ -> "") p;
1133+
Code.Print.program Format.err_formatter (fun _ _ -> "") p;
11331134
debug_print "@]");
11341135
p, cps_needed)
11351136
else
@@ -1143,6 +1144,6 @@ let f ~flow_info ~live_vars p =
11431144
if debug ()
11441145
then (
11451146
debug_print "@[<v>After CPS transform:@,";
1146-
Code.Print.program (fun _ _ -> "") p;
1147+
Code.Print.program Format.err_formatter (fun _ _ -> "") p;
11471148
debug_print "@]");
11481149
p, trampolined_calls, in_cps

compiler/lib/global_deadcode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@ let f p ~deadcode_sentinal global_info =
573573
if debug ()
574574
then (
575575
Format.eprintf "Before Zeroing:@.";
576-
Code.Print.program (fun _ _ -> "") p;
576+
Code.Print.program Format.err_formatter (fun _ _ -> "") p;
577577
Print.print_uses uses;
578578
Print.print_live_tbl live_table);
579579
(* Zero out dead fields *)
580580
let p = zero p deadcode_sentinal live_table in
581581
if debug ()
582582
then (
583583
Format.eprintf "After Zeroing:@.";
584-
Code.Print.program (fun _ _ -> "") p);
584+
Code.Print.program Format.err_formatter (fun _ _ -> "") p);
585585
if times () then Format.eprintf " global dead code elim.: %a@." Timer.print t;
586586
p

compiler/lib/lambda_lifting_simple.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ let f ~to_lift program =
358358
if debug ()
359359
then (
360360
Format.eprintf "@[<v>Program before lambda lifting:@,";
361-
Code.Print.program (fun _ _ -> "") program;
361+
Code.Print.program Format.err_formatter (fun _ _ -> "") program;
362362
Format.eprintf "@]");
363363
let t = Timer.make () in
364364
let program, liftings = lift ~to_lift ~pc:program.start program in

0 commit comments

Comments
 (0)