X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/12aa4087bee3e70f170d7457794921de4e385227..4a34fbf0834d02dd913bf872e45b3285aafce641:/trans/tree.sml?ds=inline diff --git a/trans/tree.sml b/trans/tree.sml index 1cfc4eb..2111fc1 100644 --- a/trans/tree.sml +++ b/trans/tree.sml @@ -1,68 +1,72 @@ -(* L1 Compiler +(* L3 Compiler * IR Trees * Author: Kaustuv Chaudhuri * Modified: Alex Vaynberg * Modified: Frank Pfenning + * Modified: Joshua Wise + * Modified: Chris Lu *) signature TREE = sig + 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 - datatype binop = ADD | SUB | MUL | DIV | MOD + type Blarg = int datatype exp = CONST of Word32.word | TEMP of Temp.temp + | ARG of Blarg (* I am j4cbo *) | BINOP of binop * exp * exp + | UNOP of unop * exp + | CALL of Ast.ident * exp list + | MEMORY of exp + | ALLOC of exp + | COND of exp * exp * exp + | STMVAR of stm list * exp + | NULLPTR and stm = MOVE of exp * exp | RETURN of exp + | EFFECT of exp + | LABEL of Label.label + | JUMPIFN of exp * Label.label + | JUMP of Label.label + and func = + FUNCTION of Ast.ident * stm list - type program = stm list - - structure Print : - sig - val pp_exp : exp -> string - val pp_stm : stm -> string - val pp_program : program -> string - end + type program = func list 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 | BE + datatype unop = NEG | BITNOT | BANG - datatype binop = ADD | SUB | MUL | DIV | MOD + type Blarg = int datatype exp = CONST of Word32.word | TEMP of Temp.temp + | ARG of Blarg (* I am j4cbo *) | BINOP of binop * exp * exp + | UNOP of unop * exp + | CALL of Ast.ident * exp list + | MEMORY of exp + | ALLOC of exp + | COND of exp * exp * exp + | STMVAR of stm list * exp + | NULLPTR and stm = MOVE of exp * exp | RETURN of exp + | EFFECT of exp + | LABEL of Label.label + | JUMPIFN of exp * Label.label + | JUMP of Label.label + and func = + FUNCTION of Ast.ident * stm list - type program = stm list - - structure Print = - struct - - fun pp_binop ADD = "+" - | pp_binop SUB = "-" - | pp_binop MUL = "*" - | pp_binop DIV = "/" - | pp_binop MOD = "%" - - fun pp_exp (CONST(x)) = Word32Signed.toString x - | pp_exp (TEMP(t)) = Temp.name t - | pp_exp (BINOP (binop, e1, e2)) = - "(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")" - - fun pp_stm (MOVE (e1,e2)) = - pp_exp e1 ^ " <-- " ^ pp_exp e2 - | pp_stm (RETURN e) = - "return " ^ pp_exp e - - fun pp_program (nil) = "" - | pp_program (stm::stms) = pp_stm stm ^ "\n" ^ pp_program stms - end + type program = func list end