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 * Modified: Joshua Wise <jwise>
7 * Modified: Chris Lu <czl>
13 datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE
14 datatype unop = NEG | BITNOT | BANG
21 | ARG of Blarg * int (* I am j4cbo *)
22 | BINOP of binop * exp * exp
24 | CALL of Ast.ident * (exp * int) list * int
28 MOVE of exp * exp * int
31 | LABEL of Label.label
32 | JUMPIFN of exp * Label.label
35 FUNCTION of Ast.ident * stm list
37 type program = func list
41 val pp_exp : exp -> string
42 val pp_stm : stm -> string
43 val pp_program : program -> string
47 structure Tree :> TREE =
50 datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE
51 datatype unop = NEG | BITNOT | BANG
59 | BINOP of binop * exp * exp
61 | CALL of Ast.ident * (exp * int) list * int
65 MOVE of exp * exp * int
68 | LABEL of Label.label
69 | JUMPIFN of exp * Label.label
72 FUNCTION of Ast.ident * stm list
74 type program = func list
81 fun pp_binop ADD = "+"
88 | pp_binop LOGOR = "||"
89 | pp_binop LOGAND = "&&"
90 | pp_binop BITOR = "|"
91 | pp_binop BITAND = "&"
92 | pp_binop BITXOR = "^"
100 fun pp_unop NEG = "-"
101 | pp_unop BITNOT = "~"
104 fun pp_exp (CONST(x)) = Word32Signed.toString x
105 | pp_exp (TEMP(t)) = Temp.name t
106 | pp_exp (ARG(n, sz)) = "arg#"^Int.toString n
107 | pp_exp (BINOP (binop, e1, e2)) =
108 "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
109 | pp_exp (UNOP (unop, e1)) =
110 pp_unop unop ^ "(" ^ pp_exp e1 ^ ")"
111 | pp_exp (CALL (f, l, sz)) =
112 Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn (e, _) => pp_exp e) l)) ^ ")"
113 | pp_exp (MEMORY exp) = "M[" ^ pp_exp exp ^ "]"
114 | pp_exp (ALLOC(e)) = "NEW(" ^ pp_exp e ^ ")"
116 fun pp_stm (MOVE (e1,e2, sz)) =
117 pp_exp e1 ^ " <-- " ^ pp_exp e2
118 | pp_stm (RETURN (e, sz)) =
120 | pp_stm (EFFECT (e, sz)) = pp_exp e
125 | pp_stm (JUMPIFN (e, l)) =
126 "jump "^Label.name l^" if! "^pp_exp e
128 fun pp_program (nil) = ""
129 | pp_program (FUNCTION(id, stms)::funcs) =
132 (foldr (fn (a,b) => (pp_stm a) ^ "\n" ^ b) "" stms) ^