-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.sml
79 lines (66 loc) · 1.88 KB
/
tree.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
signature TREE =
sig
type label = Temp.label
type size
datatype stm = SEQ of stm * stm
| LABEL of label
| JUMP of exp * label list
| CJUMP of relop * exp * exp * label * label
| MOVE of exp * exp
| EXP of exp
and exp = BINOP of binop * exp * exp
| MEM of exp
| TEMP of Temp.temp
| ESEQ of stm * exp
| NAME of label
| CONST of int
| CALL of exp * exp list
and binop = PLUS | MINUS | MUL | DIV
| AND | OR | LSHIFT | RSHIFT | ARSHIFT | XOR
and relop = EQ | NE | LT | GT | LE | GE
| ULT | ULE | UGT | UGE
val notRel : relop -> relop
val commute: relop -> relop
end
structure Tree : TREE =
struct
type label=Temp.label
type size = int
datatype stm = SEQ of stm * stm
| LABEL of label
| JUMP of exp * label list
| CJUMP of relop * exp * exp * label * label
| MOVE of exp * exp
| EXP of exp
and exp = BINOP of binop * exp * exp
| MEM of exp
| TEMP of Temp.temp
| ESEQ of stm * exp
| NAME of label
| CONST of int
| CALL of exp * exp list
and binop = PLUS | MINUS | MUL | DIV
| AND | OR | LSHIFT | RSHIFT | ARSHIFT | XOR
and relop = EQ | NE | LT | GT | LE | GE
| ULT | ULE | UGT | UGE
fun notRel EQ = NE
| notRel NE = EQ
| notRel LT = GE
| notRel GT = LE
| notRel LE = GE
| notRel GE = LT
| notRel ULT = UGE
| notRel ULE = UGT
| notRel UGT = ULE
| notRel UGE = ULT
fun commute EQ = EQ
| commute NE = NE
| commute LT = GT
| commute GT = LT
| commute LE = GE
| commute GE = LE
| commute ULT = UGT
| commute ULE = UGE
| commute UGT = ULT
| commute UGE = ULE
end