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 (* I am j4cbo *)
22 | BINOP of binop * exp * exp
24 | CALL of Ast.ident * exp list
28 | LABEL of Label.label
29 | JUMPIFN of exp * Label.label
32 FUNCTION of Ast.ident * stm list
34 type program = func list
38 val pp_exp : exp -> string
39 val pp_stm : stm -> string
40 val pp_program : program -> string
44 structure Tree :> TREE =
47 datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE
48 datatype unop = NEG | BITNOT | BANG
56 | BINOP of binop * exp * exp
58 | CALL of Ast.ident * exp list
62 | LABEL of Label.label
63 | JUMPIFN of exp * Label.label
66 FUNCTION of Ast.ident * stm list
68 type program = func list
75 fun pp_binop ADD = "+"
82 | pp_binop LOGOR = "||"
83 | pp_binop LOGAND = "&&"
84 | pp_binop BITOR = "|"
85 | pp_binop BITAND = "&"
86 | pp_binop BITXOR = "^"
95 | pp_unop BITNOT = "~"
98 fun pp_exp (CONST(x)) = Word32Signed.toString x
99 | pp_exp (TEMP(t)) = Temp.name t
100 | pp_exp (ARG(n)) = "arg#"^Int.toString n
101 | pp_exp (BINOP (binop, e1, e2)) =
102 "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
103 | pp_exp (UNOP (unop, e1)) =
104 pp_unop unop ^ "(" ^ pp_exp e1 ^ ")"
105 | pp_exp (CALL (f, l)) =
106 Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map pp_exp l)) ^ ")"
108 fun pp_stm (MOVE (e1,e2)) =
109 pp_exp e1 ^ " <-- " ^ pp_exp e2
110 | pp_stm (RETURN e) =
116 | pp_stm (JUMPIFN (e, l)) =
117 "jump "^Label.name l^" if! "^pp_exp e
119 fun pp_program (nil) = ""
120 | pp_program (FUNCTION(id, stms)::funcs) =
123 (foldr (fn (a,b) => (pp_stm a) ^ "\n" ^ b) "" stms) ^