X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/1144856ba9d6018d9922c6ede7e97779a0fe6373..f285fa8903ee50118b6d92150c18cb3a32f52ed2:/trans/temp.sml diff --git a/trans/temp.sml b/trans/temp.sml index 1092dfc..bd311c4 100644 --- a/trans/temp.sml +++ b/trans/temp.sml @@ -8,18 +8,23 @@ signature TEMP = sig type temp + datatype size = Byte | Word | Long | Quad - val reset : unit -> unit (* resets temp numbering *) - val new : string -> int -> temp (* returns a unique new temp *) - val name : temp -> string (* returns the name of a temp *) - val size : temp -> int (* returns the size of a temp *) + val reset : unit -> unit (* resets temp numbering *) + val new : string -> size -> 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 - type temp = int * string * int + datatype size = Byte | Word | Long | Quad + type temp = int * string * size local val counter = ref 1 @@ -29,9 +34,32 @@ struct fun new str size = (!counter, str, size) before ( counter := !counter + 1 ) end - fun name (t,s, sz) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]" + 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" + end