aboutsummaryrefslogtreecommitdiffstats
path: root/src/bourdoncle/PrintLoops.ml
blob: f70f075c8ab8f95b6fdbe811e65f9e7a82593514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open Camlcoq

let indent i = String.make (2 * i) ' '

let rec print_bourdoncle i pp =
  function
  | Bourdoncle.I n ->
     Printf.fprintf pp "%sI %d\n" (indent i) (P.to_int n)
  | Bourdoncle.L (h, b) ->
    Printf.fprintf pp "%sL %d\n" (indent i) (P.to_int h);
    List.iter (fun a -> Printf.fprintf pp "%a" (print_bourdoncle (i+1)) a) b

let print_if optdest loop =
  match !optdest with
  | None -> ()
  | Some f ->
    let oc = open_out f in
    print_bourdoncle 0 oc loop;
    close_out oc

let destination_loops : string option ref = ref None
let print_loops = print_if destination_loops