X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/1144856ba9d6018d9922c6ede7e97779a0fe6373..HEAD:/trans/tree.sml?ds=sidebyside diff --git a/trans/tree.sml b/trans/tree.sml index d3e8c0d..dbd0efc 100644 --- a/trans/tree.sml +++ b/trans/tree.sml @@ -9,8 +9,7 @@ signature TREE = sig - - datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE + datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE | BE datatype unop = NEG | BITNOT | BANG type Blarg = int @@ -18,16 +17,19 @@ sig datatype exp = CONST of Word32.word | TEMP of Temp.temp - | ARG of Blarg * int (* I am j4cbo *) + | ARG of Blarg * Temp.size (* I am j4cbo *) | BINOP of binop * exp * exp | UNOP of unop * exp - | CALL of Ast.ident * (exp * int) list * int - | MEMORY of exp + | CALL of Ast.ident * (exp * Temp.size) list * Temp.size + | MEMORY of exp * Temp.size | ALLOC of exp + | COND of exp * exp * exp + | STMVAR of stm list * exp + | NULLPTR and stm = - MOVE of exp * exp * int - | RETURN of exp * int - | EFFECT of exp * int + MOVE of exp * exp + | RETURN of exp * Temp.size + | EFFECT of exp | LABEL of Label.label | JUMPIFN of exp * Label.label | JUMP of Label.label @@ -35,19 +37,11 @@ sig FUNCTION of Ast.ident * stm list type program = func list - - structure Print : - sig - val pp_exp : exp -> string - val pp_stm : stm -> string - val pp_program : program -> string - end end structure Tree :> TREE = struct - - datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE + datatype binop = ADD | SUB | MUL | DIV | MOD | LSH | RSH | LOGOR | LOGAND | BITOR | BITAND | BITXOR | NEQ | EQ | LT | GT | LE | GE | BE datatype unop = NEG | BITNOT | BANG type Blarg = int @@ -55,16 +49,19 @@ struct datatype exp = CONST of Word32.word | TEMP of Temp.temp - | ARG of Blarg * int + | ARG of Blarg * Temp.size (* I am j4cbo *) | BINOP of binop * exp * exp | UNOP of unop * exp - | CALL of Ast.ident * (exp * int) list * int - | MEMORY of exp + | CALL of Ast.ident * (exp * Temp.size) list * Temp.size + | MEMORY of exp * Temp.size | ALLOC of exp + | COND of exp * exp * exp + | STMVAR of stm list * exp + | NULLPTR and stm = - MOVE of exp * exp * int - | RETURN of exp * int - | EFFECT of exp * int + MOVE of exp * exp + | RETURN of exp * Temp.size + | EFFECT of exp | LABEL of Label.label | JUMPIFN of exp * Label.label | JUMP of Label.label @@ -72,65 +69,4 @@ struct FUNCTION of Ast.ident * stm list type program = func list - - structure Print = - struct - - exception Aaaasssssss - - fun pp_binop ADD = "+" - | pp_binop SUB = "-" - | pp_binop MUL = "*" - | pp_binop DIV = "/" - | pp_binop MOD = "%" - | pp_binop LSH = "<<" - | pp_binop RSH = ">>" - | pp_binop LOGOR = "||" - | pp_binop LOGAND = "&&" - | pp_binop BITOR = "|" - | pp_binop BITAND = "&" - | pp_binop BITXOR = "^" - | pp_binop NEQ = "!=" - | pp_binop EQ = "==" - | pp_binop LE = "<=" - | pp_binop LT = "<" - | pp_binop GE = ">=" - | pp_binop GT = ">" - - fun pp_unop NEG = "-" - | pp_unop BITNOT = "~" - | pp_unop BANG = "!" - - fun pp_exp (CONST(x)) = Word32Signed.toString x - | pp_exp (TEMP(t)) = Temp.name t - | pp_exp (ARG(n, sz)) = "arg#"^Int.toString n - | pp_exp (BINOP (binop, e1, e2)) = - "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")" - | pp_exp (UNOP (unop, e1)) = - pp_unop unop ^ "(" ^ pp_exp e1 ^ ")" - | pp_exp (CALL (f, l, sz)) = - Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn (e, _) => pp_exp e) l)) ^ ")" - | pp_exp (MEMORY exp) = "M[" ^ pp_exp exp ^ "]" - | pp_exp (ALLOC(e)) = "NEW(" ^ pp_exp e ^ ")" - - fun pp_stm (MOVE (e1,e2, sz)) = - pp_exp e1 ^ " <-- " ^ pp_exp e2 - | pp_stm (RETURN (e, sz)) = - "return " ^ pp_exp e - | pp_stm (EFFECT (e, sz)) = pp_exp e - | pp_stm (LABEL l) = - Label.name l ^ ":" - | pp_stm (JUMP l) = - "jump "^Label.name l - | pp_stm (JUMPIFN (e, l)) = - "jump "^Label.name l^" if! "^pp_exp e - - fun pp_program (nil) = "" - | pp_program (FUNCTION(id, stms)::funcs) = - (Symbol.name id) ^ - "\n{\n" ^ - (foldr (fn (a,b) => (pp_stm a) ^ "\n" ^ b) "" stms) ^ - "}\n" ^ - pp_program funcs - end end