-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.sml
70 lines (57 loc) · 1.65 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
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(GE) = LT
| notRel(LE) = GT
| notRel(GT) = LE
| notRel(ULT) = UGE
| notRel(UGE) = ULT
| notRel(ULE) = UGT
| notRel(UGT) = ULE
end
structure Tr = Tree