]> Joshua Wise's Git repositories - snipe.git/blame_incremental - trans/tree.sml
Initial import of l1c
[snipe.git] / trans / tree.sml
... / ...
CommitLineData
1(* L1 Compiler
2 * IR Trees
3 * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
4 * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
5 * Modified: Frank Pfenning <fp@cs.cmu.edu>
6 *)
7
8signature TREE =
9sig
10
11 datatype binop = ADD | SUB | MUL | DIV | MOD
12
13 datatype exp =
14 CONST of Word32.word
15 | TEMP of Temp.temp
16 | BINOP of binop * exp * exp
17 and stm =
18 MOVE of exp * exp
19 | RETURN of exp
20
21 type program = stm list
22
23 structure Print :
24 sig
25 val pp_exp : exp -> string
26 val pp_stm : stm -> string
27 val pp_program : program -> string
28 end
29end
30
31structure Tree :> TREE =
32struct
33
34 datatype binop = ADD | SUB | MUL | DIV | MOD
35
36 datatype exp =
37 CONST of Word32.word
38 | TEMP of Temp.temp
39 | BINOP of binop * exp * exp
40 and stm =
41 MOVE of exp * exp
42 | RETURN of exp
43
44 type program = stm list
45
46 structure Print =
47 struct
48
49 fun pp_binop ADD = "+"
50 | pp_binop SUB = "-"
51 | pp_binop MUL = "*"
52 | pp_binop DIV = "/"
53 | pp_binop MOD = "%"
54
55 fun pp_exp (CONST(x)) = Word32Signed.toString x
56 | pp_exp (TEMP(t)) = Temp.name t
57 | pp_exp (BINOP (binop, e1, e2)) =
58 "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
59
60 fun pp_stm (MOVE (e1,e2)) =
61 pp_exp e1 ^ " <-- " ^ pp_exp e2
62 | pp_stm (RETURN e) =
63 "return " ^ pp_exp e
64
65 fun pp_program (nil) = ""
66 | pp_program (stm::stms) = pp_stm stm ^ "\n" ^ pp_program stms
67 end
68end
This page took 0.026226 seconds and 4 git commands to generate.