-
Notifications
You must be signed in to change notification settings - Fork 2
/
instruction.ml
77 lines (74 loc) · 2.28 KB
/
instruction.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
open Lambda
open Syntax
type zinc_instruction =
| Kaccess of int
| Kapply
| Kbranch of int
| Kbranchif of int
| Kbranchifnot of int
| Kcur of int
| Kdummy of int
| Kendlet of int
| Kgetglobal of long_ident
| Kgrab
| Klabel of int
| Klet
| Kmakeblock of constr_tag * int
| Kpoptrap
| Kprim of prim
| Kpush
| Kpushmark
| Kpushtrap of int
| Kquote of struct_constant
| Kreturn
| Ksetglobal of long_ident
| Kswitch of int array
| Ktermapply
| Ktest of bool_test * int (* branch if *)
| Kupdate of int
let show_zinc =
let output_long_ident () id = string_of_long_ident id in
let output_label () = function
| -1 -> ""
| i -> Printf.sprintf "(%d)" i
in
function
| Kaccess i -> Printf.sprintf "Kaccess(%d)" i
| Kapply -> "Kapply"
| Kbranch l -> Printf.sprintf "Kbranch%a" output_label l
| Kbranchif l -> Printf.sprintf "Kbranchif%a" output_label l
| Kbranchifnot l -> Printf.sprintf "Kbranchifnot%a" output_label l
| Kcur l -> Printf.sprintf "Kcur%a" output_label l
| Kdummy i -> Printf.sprintf "Kdummy(%d)" i
| Kendlet i -> Printf.sprintf "Kendlet(%d)" i
| Kgetglobal l -> Printf.sprintf "Kgetglobal(%a)" output_long_ident l
| Kgrab -> "Kgrab"
| Klabel l -> Printf.sprintf "Klabel%a" output_label l
| Klet -> "Klet"
| Kmakeblock(tag,cnt) -> Printf.sprintf "Kmakeblock((%s),%d)" (show_tag tag) cnt
| Kpoptrap -> "Kpoptrap"
| Kprim prim -> "Kprim(" ^ show_prim prim ^ ")"
| Kpush -> "Kpush"
| Kpushmark -> "Kpushmark"
| Kpushtrap l -> Printf.sprintf "Kpushtrap(%d)" l
| Kquote c -> Printf.sprintf "Kquote(%a)" (fun () c ->
match c with
| Const_base c -> show_constant c
| Const_block t -> Printf.sprintf "tag %d" t) c
| Kreturn -> "Kreturn"
| Ksetglobal l -> Printf.sprintf "Ksetglobal(%a)" output_long_ident l
| Kswitch ls ->
let buf = Buffer.create 0 in
Array.iteri (fun i l ->
if i > 0 then
Buffer.add_string buf "; ";
Buffer.add_string buf (string_of_int l)
) ls;
"Kswitch[" ^ Buffer.contents buf ^ "]"
| Ktermapply -> "Ktermapply"
| Ktest(tst,l) -> Printf.sprintf "Ktest(%s,%d)" (show_bool_test tst) l
| Kupdate i -> Printf.sprintf "Kupdate(%d)" i
let dump_zinc cs =
List.iter (fun c ->
print_string (show_zinc c);
print_char ' ') cs