forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printlinear.ml
85 lines (79 loc) · 2.97 KB
/
printlinear.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Pretty-printing of linearized machine code *)
open Format
open Mach
open Printmach
open Linearize
let label ppf l =
Format.fprintf ppf "L%i" l
let instr ppf i =
begin match i.desc with
| Lend -> ()
| Lprologue ->
fprintf ppf "prologue"
| Lop op ->
begin match op with
| Ialloc _ | Icall_ind _ | Icall_imm _ | Iextcall _ ->
fprintf ppf "@[<1>{%a}@]@," regsetaddr i.live
| _ -> ()
end;
operation op i.arg ppf i.res
| Lreloadretaddr ->
fprintf ppf "reload retaddr"
| Lreturn ->
fprintf ppf "return %a" regs i.arg
| Llabel lbl ->
fprintf ppf "%a:" label lbl
| Lbranch lbl ->
fprintf ppf "goto %a" label lbl
| Lcondbranch(tst, lbl) ->
fprintf ppf "if %a goto %a" (test tst) i.arg label lbl
| Lcondbranch3(lbl0, lbl1, lbl2) ->
fprintf ppf "switch3 %a" reg i.arg.(0);
let case n = function
| None -> ()
| Some lbl ->
fprintf ppf "@,case %i: goto %a" n label lbl in
case 0 lbl0; case 1 lbl1; case 2 lbl2;
fprintf ppf "@,endswitch"
| Lswitch lblv ->
fprintf ppf "switch %a" reg i.arg.(0);
for i = 0 to Array.length lblv - 1 do
fprintf ppf "case %i: goto %a" i label lblv.(i)
done;
fprintf ppf "@,endswitch"
| Lentertrap ->
fprintf ppf "enter trap"
| Lpushtrap { lbl_handler; } ->
fprintf ppf "push trap %a" label lbl_handler
| Lpoptrap ->
fprintf ppf "pop trap"
| Lraise k ->
fprintf ppf "%a %a" Printcmm.raise_kind k reg i.arg.(0)
end;
if not (Debuginfo.is_none i.dbg) then
fprintf ppf " %s" (Debuginfo.to_string i.dbg)
let rec all_instr ppf i =
match i.desc with
| Lend -> ()
| _ -> fprintf ppf "%a@,%a" instr i all_instr i.next
let fundecl ppf f =
let dbg =
if Debuginfo.is_none f.fun_dbg then
""
else
" " ^ Debuginfo.to_string f.fun_dbg in
fprintf ppf "@[<v 2>%s:%s@,%a@]" f.fun_name dbg all_instr f.fun_body