3 val effect : Tree.exp -> bool
4 val effect_stm : Tree.stm -> bool
8 val pp_exp : Tree.exp -> string
9 val pp_stm : Tree.stm -> string
10 val pp_program : Tree.program -> string
14 structure TreeUtils :> TREEUTILS =
18 (* effect : T.exp -> bool
19 * true iff the given expression has an effect.
21 fun effect (T.CONST _) = false
22 | effect (T.TEMP _) = false
23 | effect (T.ARG _) = false
24 | effect (T.BINOP(T.DIV, _, _)) = true
25 | effect (T.BINOP(T.MOD, _, _)) = true
26 | effect (T.CALL _) = true
27 | effect (T.BINOP(_, a, b)) = (effect a) orelse (effect b)
28 | effect (T.UNOP (_, a)) = effect a
29 | effect (T.MEMORY _) = true
30 | effect (T.ALLOC _) = true
31 | effect (T.COND (a, b, c)) = (effect a) orelse (effect b) orelse (effect c)
32 | effect (T.STMVAR (sl, e)) = true (* Has to be, to be safe <--- jwise is an assclown, he was too lazy to write a effect_stm *)
33 | effect (T.NULLPTR) = false
35 fun effect_stm (T.MOVE (e1,e2)) = effect e1 orelse effect e2
36 | effect_stm (T.RETURN (e1)) = effect e1
37 | effect_stm (T.EFFECT e) = effect e
38 | effect_stm (T.JUMPIFN (e,_)) = effect e
39 | effect_stm _ = false
45 fun pp_binop T.ADD = "+"
46 | pp_binop T.SUB = "-"
47 | pp_binop T.MUL = "*"
48 | pp_binop T.DIV = "/"
49 | pp_binop T.MOD = "%"
50 | pp_binop T.LSH = "<<"
51 | pp_binop T.RSH = ">>"
52 | pp_binop T.LOGOR = "||"
53 | pp_binop T.LOGAND = "&&"
54 | pp_binop T.BITOR = "|"
55 | pp_binop T.BITAND = "&"
56 | pp_binop T.BITXOR = "^"
57 | pp_binop T.NEQ = "!="
58 | pp_binop T.EQ = "=="
59 | pp_binop T.LE = "<="
61 | pp_binop T.GE = ">="
63 | pp_binop T.BE = "[BE]"
65 fun pp_unop T.NEG = "-"
66 | pp_unop T.BITNOT = "~"
67 | pp_unop T.BANG = "!"
69 fun pp_exp (T.CONST(x)) = Word32Signed.toString x
70 | pp_exp (T.TEMP(t)) = Temp.name t
71 | pp_exp (T.ARG(n)) = "arg#"^Int.toString n
72 | pp_exp (T.BINOP (binop, e1, e2)) =
73 "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
74 | pp_exp (T.UNOP (unop, e1)) =
75 pp_unop unop ^ "(" ^ pp_exp e1 ^ ")"
76 | pp_exp (T.CALL (f, l)) =
77 Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn e => pp_exp e) l)) ^ ")"
78 | pp_exp (T.MEMORY (exp)) = "M[" ^ pp_exp exp ^ "]"
79 | pp_exp (T.ALLOC(e)) = "NEW(" ^ pp_exp e ^ ")"
80 | pp_exp (T.COND(c,e1,e2)) = "(" ^ pp_exp c ^ ") ? (" ^ pp_exp e1 ^ ") : (" ^ pp_exp e2 ^ ")"
81 | pp_exp (T.STMVAR(sl,v)) = "({" ^ (foldr (fn (st,s) => (pp_stm st) ^ "; " ^ s) "" sl) ^ (pp_exp v) ^ "})"
82 | pp_exp (T.NULLPTR) = "NULL"
84 and pp_stm (T.MOVE (e1,e2)) =
85 pp_exp e1 ^ " <-- " ^ pp_exp e2
86 | pp_stm (T.RETURN (e)) =
88 | pp_stm (T.EFFECT e) = pp_exp e
89 | pp_stm (T.LABEL l) =
93 | pp_stm (T.JUMPIFN (e, l)) =
94 "jump "^Label.name l^" if! "^pp_exp e
96 fun pp_program (nil) = ""
97 | pp_program (T.FUNCTION(id, stms)::funcs) =
100 (foldr (fn (a,b) => (pp_stm a) ^ "\n" ^ b) "" stms) ^