| 1 | open Format |
| 2 | open Sorts |
| 3 | open Names |
| 4 | open Vmemitcodes |
| 5 | open Values |
| 6 | open Vmvalues |
| 7 | |
| 8 | let ppripos (ri,pos) = |
| 9 | (match ri with |
| 10 | | Reloc_annot a -> |
| 11 | print_string "switch\n" |
| 12 | | Reloc_const _ -> |
| 13 | print_string "structured constant\n" |
| 14 | | Reloc_getglobal kn -> |
| 15 | print_string ("getglob "^(Constant.to_string kn)^"\n") |
| 16 | | Reloc_caml_prim op -> |
| 17 | print_string ("caml primitive "^ CPrimitives.to_string @@ Vmbytecodes.caml_prim_to_prim op) |
| 18 | ); |
| 19 | print_flush () |
| 20 | |
| 21 | let ppsort = function |
| 22 | | SProp -> print_string "SProp" |
| 23 | | Set -> print_string "Set" |
| 24 | | Prop -> print_string "Prop" |
| 25 | | Type _ -> print_string "Type" |
| 26 | | QSort _ -> print_string "QSort" |
| 27 | |
| 28 | let print_idkey idk = |
| 29 | match idk with |
| 30 | | ConstKey sp -> |
| 31 | print_string "Cons("; |
| 32 | print_string (Constant.to_string sp); |
| 33 | print_string ")" |
| 34 | | VarKey id -> print_string (Id.to_string id) |
| 35 | | RelKey i -> print_string "~";print_int i |
| 36 | | EvarKey evk -> |
| 37 | print_string "Evar("; |
| 38 | print_int (Evar.repr evk); |
| 39 | print_string ")" |
| 40 | |
| 41 | let rec ppzipper z = |
| 42 | match z with |
| 43 | | Zapp args -> |
| 44 | let n = nargs args in |
| 45 | open_hbox (); |
| 46 | for i = 0 to n-2 do |
| 47 | ppvalues (arg args i);print_string ";";print_space() |
| 48 | done; |
| 49 | if n-1 >= 0 then ppvalues (arg args (n-1)); |
| 50 | close_box() |
| 51 | | Zfix _ -> print_string "Zfix" |
| 52 | | Zswitch _ -> print_string "Zswitch" |
| 53 | | Zproj _ -> print_string "Zproj" |
| 54 | |
| 55 | and ppstack s = |
| 56 | open_hovbox 0; |
| 57 | print_string "["; |
| 58 | List.iter (fun z -> ppzipper z;print_string " | ") s; |
| 59 | print_string "]"; |
| 60 | close_box() |
| 61 | |
| 62 | and ppatom a = |
| 63 | match a with |
| 64 | | Aid idk -> print_idkey idk |
| 65 | | Asort u -> print_string "Sort(...)" |
| 66 | | Aind(sp,i) -> print_string "Ind("; |
| 67 | print_string (MutInd.to_string sp); |
| 68 | print_string ","; print_int i; |
| 69 | print_string ")" |
| 70 | |
| 71 | and ppwhd whd = |
| 72 | match whd with |
| 73 | | Vprod _ -> print_string "product" |
| 74 | | Vfun _ -> print_string "function" |
| 75 | | Vfix _ -> print_string "vfix" |
| 76 | | Vcofix _ -> print_string "cofix" |
| 77 | | Vconst i -> print_string "C(";print_int i;print_string")" |
| 78 | | Vblock b -> ppvblock b |
| 79 | | Vint64 i -> printf "int64(%LiL)" i |
| 80 | | Vfloat64 f -> printf "float64(%.17g)" f |
| 81 | | Vstring s -> printf "string(%S)" (Pstring.to_string s) |
| 82 | | Varray t -> ppvarray t |
| 83 | | Vaccu (a, s) -> |
| 84 | open_hbox();ppatom a;close_box(); |
| 85 | print_string"@";ppstack s |
| 86 | |
| 87 | and ppvblock b = |
| 88 | open_hbox(); |
| 89 | print_string "Cb(";print_int (btag b); |
| 90 | let n = bsize b in |
| 91 | for i = 0 to n -1 do |
| 92 | print_string ",";ppvalues (bfield b i) |
| 93 | done; |
| 94 | print_string")"; |
| 95 | close_box() |
| 96 | |
| 97 | and ppvarray t = |
| 98 | let length = Parray.length_int t in |
| 99 | open_hbox(); |
| 100 | print_string "[|"; |
| 101 | for i = 0 to length - 2 do |
| 102 | ppvalues (Parray.get t (Uint63.of_int i)); |
| 103 | print_string "; " |
| 104 | done; |
| 105 | ppvalues (Parray.get t (Uint63.of_int (length - 1))); |
| 106 | print_string " | "; |
| 107 | ppvalues (Parray.default t); |
| 108 | print_string " |]"; |
| 109 | close_box() |
| 110 | |
| 111 | and ppvalues v = |
| 112 | open_hovbox 0;ppwhd (whd_val v);close_box(); |
| 113 | print_flush() |