-
Notifications
You must be signed in to change notification settings - Fork 0
/
tigerit.sml
60 lines (53 loc) · 1.82 KB
/
tigerit.sml
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
structure tigerit =
struct
open tigertab
open tigertree
fun tree s0 =
let fun say s = s
fun sayln s = s^"\n"
fun indent 0 = ""
| indent i = " "^indent(i-1)
fun stm(SEQ(a,b),d) =
indent(d)^sayln("SEQ(")^stm(a,d+1)^
sayln(",")^stm(b,d+1)^say(")")
| stm(LABEL lab, d) = indent(d)^say("LABEL ")^say(lab)
| stm(JUMP (e,_), d) = indent(d)^say("JUMP(")^exp(e,d+1)^say(")")
| stm(CJUMP(r,a,b,t,f),d) = indent(d)^say("CJUMP(")^
relop(r)^sayln(",")^
exp(a,d+1)^sayln(",")^exp(b,d+1)^sayln(",")^
indent(d+1)^say(t)^say(",")^say(f)^say(")")
| stm(MOVE(a,b),d) = indent(d)^sayln("MOVE(")^exp(a,d+1)^
sayln(",")^exp(b,d+1)^say(")")
| stm(EXP e, d) = indent(d)^sayln("EXP(")^exp(e,d+1)^say(")")
and exp(BINOP(p,a,b),d) = indent(d)^say("BINOP(")^binop(p)^sayln(",")^
exp(a,d+1)^sayln(",")^exp(b,d+1)^say(")")
| exp(MEM(e),d) = indent(d)^sayln("MEM(")^exp(e,d+1)^say(")")
| exp(TEMP t, d) = indent(d)^say("TEMP ")^say(t)
| exp(ESEQ(s,e),d) = indent(d)^sayln("ESEQ(")^stm(s,d+1)^sayln(",")^
exp(e,d+1)^say(")")
| exp(NAME lab, d) = indent(d)^say("NAME ")^say(lab)
| exp(CONST i, d) = indent(d)^say("CONST ")^say(Int.toString i)
| exp(CALL(e,el),d) = indent(d)^sayln("CALL(")^(exp(e,d+1))^
concat(map (fn a => sayln(",")^exp(a,d+2)) el)^say(")")
and binop PLUS = say "PLUS"
| binop MINUS = say "MINUS"
| binop MUL = say "MUL"
| binop DIV = say "DIV"
| binop AND = say "AND"
| binop OR = say "OR"
| binop LSHIFT = say "LSHIFT"
| binop RSHIFT = say "RSHIFT"
| binop ARSHIFT = say "ARSHIFT"
| binop XOR = say "XOR"
and relop EQ = say "EQ"
| relop NE = say "NE"
| relop LT = say "LT"
| relop GT = say "GT"
| relop LE = say "LE"
| relop GE = say "GE"
| relop ULT = say "ULT"
| relop ULE = say "ULE"
| relop UGT = say "UGT"
| relop UGE = say "UGE"
in stm(s0,0)^sayln("") end
end