diff options
Diffstat (limited to 'backend/PrintMach.ml')
-rw-r--r-- | backend/PrintMach.ml | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/backend/PrintMach.ml b/backend/PrintMach.ml index a6a1cc56..03977a66 100644 --- a/backend/PrintMach.ml +++ b/backend/PrintMach.ml @@ -97,29 +97,26 @@ let print_instruction pp i = | Mreturn -> fprintf pp "return@ " -let print_function pp f = - fprintf pp "@[<v 2>f() {@ "; +let print_function pp id f = + fprintf pp "@[<v 2>%s() {@ " (extern_atom id); List.iter (print_instruction pp) f.fn_code; fprintf pp "@;<0 -2>}@]@." -let print_fundef pp fd = +let print_fundef pp (id, fd) = match fd with - | Internal f -> print_function pp f + | Internal f -> print_function pp id f | External _ -> () +let print_program pp prog = + List.iter (print_fundef pp) prog.prog_funct + let destination : string option ref = ref None -let currpp : formatter option ref = ref None -let print_if fd = +let print_if prog = match !destination with | None -> () | Some f -> - let pp = - match !currpp with - | Some pp -> pp - | None -> - let oc = open_out f in - let pp = formatter_of_out_channel oc in - currpp := Some pp; - pp - in print_fundef pp fd + let oc = open_out f in + let pp = formatter_of_out_channel oc in + print_program pp prog; + close_out oc |