end)
fun pp_oper (REG r) = "%" ^ (regname r)
- | pp_oper (TEMP t) = (Temp.name t) ^ (Temp.sfx (Temp.size t))
+ | pp_oper (TEMP t) = (Temp.name t)
| pp_oper (STACKARG i) = "arg#"^Int.toString i
fun pp_insn pr (MOVLIT (d, w)) = "\tmov"^pr^" "^(pp_oper d)^", #"^(Word.toString w)^"\n"
signature TEMP =
sig
type temp
- datatype size = Byte | Word | Long | Quad
val reset : unit -> unit (* resets temp numbering *)
- val new : string -> size -> temp (* returns a unique new temp *)
+ val new : string -> temp (* returns a unique new temp *)
val name : temp -> string (* returns the name of a temp *)
- val size : temp -> size (* returns the size of a temp *)
val compare : temp * temp -> order (* comparison function *)
val eq : temp * temp -> bool
- val cmpsize : size * size -> order
- val sfx : size -> string
- val sts : int -> size
end
structure Temp :> TEMP =
struct
- datatype size = Byte | Word | Long | Quad
- type temp = int * string * size
+ type temp = int * string
local
val counter = ref 1
in
(* warning: calling reset() may jeopardize uniqueness of temps! *)
fun reset () = ( counter := 1 )
- fun new str size = (!counter, str, size) before ( counter := !counter + 1 )
+ fun new str = (!counter, str) before ( counter := !counter + 1 )
end
- fun sfx Byte = "b"
- | sfx Word = "w"
- | sfx Long = "l"
- | sfx Quad = "q"
-
- fun name (t,s, sz) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]" ^ sfx sz
- fun size (t, s, sz) = sz
- fun compare ((t1,_,_),(t2,_,_)) = Int.compare (t1,t2)
-
- fun eq ((t1,_,_), (t2,_,_)) = t1 = t2
-
- fun cmpsize (Quad,Quad) = EQUAL
- | cmpsize (Quad,_) = GREATER
- | cmpsize (_,Quad) = LESS
- | cmpsize (Long,Long) = EQUAL
- | cmpsize (Long,_) = GREATER
- | cmpsize (_,Long) = LESS
- | cmpsize (Word,Word) = EQUAL
- | cmpsize (Word,_) = GREATER
- | cmpsize (_,Word) = LESS
- | cmpsize (Byte,Byte) = EQUAL
-
- fun sts 8 = Quad
- | sts 4 = Long
- | sts 2 = Word
- | sts 1 = Byte
- | sts _ = raise ErrorMsg.InternalError "Temp.sts: invalid size"
+ fun name (t,s) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]"
+ fun compare ((t1,_),(t2,_)) = Int.compare (t1,t2)
+ fun eq ((t1,_), (t2,_)) = t1 = t2
end
datatype exp =
CONST of Word32.word
| TEMP of Temp.temp
- | ARG of Blarg * Temp.size (* I am j4cbo *)
+ | ARG of Blarg (* I am j4cbo *)
| BINOP of binop * exp * exp
| UNOP of unop * exp
- | CALL of Ast.ident * (exp * Temp.size) list * Temp.size
- | MEMORY of exp * Temp.size
+ | 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 * Temp.size
+ | RETURN of exp
| EFFECT of exp
| LABEL of Label.label
| JUMPIFN of exp * Label.label
datatype exp =
CONST of Word32.word
| TEMP of Temp.temp
- | ARG of Blarg * Temp.size (* I am j4cbo *)
+ | ARG of Blarg (* I am j4cbo *)
| BINOP of binop * exp * exp
| UNOP of unop * exp
- | CALL of Ast.ident * (exp * Temp.size) list * Temp.size
- | MEMORY of exp * Temp.size
+ | 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 * Temp.size
+ | RETURN of exp
| EFFECT of exp
| LABEL of Label.label
| JUMPIFN of exp * Label.label
| effect (T.NULLPTR) = false
fun effect_stm (T.MOVE (e1,e2)) = effect e1 orelse effect e2
- | effect_stm (T.RETURN (e1,e2)) = effect e1 orelse effect e1
+ | effect_stm (T.RETURN (e1)) = effect e1
| effect_stm (T.EFFECT e) = effect e
| effect_stm (T.JUMPIFN (e,_)) = effect e
| effect_stm _ = false
fun pp_exp (T.CONST(x)) = Word32Signed.toString x
| pp_exp (T.TEMP(t)) = Temp.name t
- | pp_exp (T.ARG(n, sz)) = "arg#"^Int.toString n
+ | pp_exp (T.ARG(n)) = "arg#"^Int.toString n
| pp_exp (T.BINOP (binop, e1, e2)) =
"(" ^ pp_exp e1 ^ " " ^ pp_binop binop ^ " " ^ pp_exp e2 ^ ")"
| pp_exp (T.UNOP (unop, e1)) =
pp_unop unop ^ "(" ^ pp_exp e1 ^ ")"
- | pp_exp (T.CALL (f, l, sz)) =
- Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn (e, _) => pp_exp e) l)) ^ ")"
- | pp_exp (T.MEMORY (exp, sz)) = "M(" ^ Temp.sfx sz ^ ")[" ^ pp_exp exp ^ "]"
+ | pp_exp (T.CALL (f, l)) =
+ Symbol.name f ^ "(" ^ (String.concatWith ", " (List.map (fn e => pp_exp e) l)) ^ ")"
+ | pp_exp (T.MEMORY (exp)) = "M[" ^ pp_exp exp ^ "]"
| pp_exp (T.ALLOC(e)) = "NEW(" ^ pp_exp e ^ ")"
| pp_exp (T.COND(c,e1,e2)) = "(" ^ pp_exp c ^ ") ? (" ^ pp_exp e1 ^ ") : (" ^ pp_exp e2 ^ ")"
| pp_exp (T.STMVAR(sl,v)) = "({" ^ (foldr (fn (st,s) => (pp_stm st) ^ "; " ^ s) "" sl) ^ (pp_exp v) ^ "})"
and pp_stm (T.MOVE (e1,e2)) =
pp_exp e1 ^ " <-- " ^ pp_exp e2
- | pp_stm (T.RETURN (e, sz)) =
+ | pp_stm (T.RETURN (e)) =
"return " ^ pp_exp e
| pp_stm (T.EFFECT e) = pp_exp e
| pp_stm (T.LABEL l) =