3  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
 
   4  * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
 
   5  * Modified: Frank Pfenning <fp@cs.cmu.edu>
 
  11   datatype size = Byte | Word | Long | Quad
 
  13   val reset : unit -> unit           (* resets temp numbering *)
 
  14   val new : string -> size -> temp   (* returns a unique new temp *)
 
  15   val name : temp -> string          (* returns the name of a temp *)
 
  16   val size : temp -> size            (* returns the size of a temp *)
 
  17   val compare : temp * temp -> order (* comparison function *)
 
  18   val eq : temp * temp -> bool
 
  19   val cmpsize : size * size -> order
 
  20   val sfx : size -> string
 
  24 structure Temp :> TEMP = 
 
  26   datatype size = Byte | Word | Long | Quad
 
  27   type temp = int * string * size
 
  32     (* warning: calling reset() may jeopardize uniqueness of temps! *)
 
  33     fun reset () = ( counter := 1 )
 
  34     fun new str size = (!counter, str, size) before ( counter := !counter + 1 )
 
  42   fun name (t,s, sz) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]" ^ sfx sz
 
  43   fun size (t, s, sz) = sz
 
  44   fun compare ((t1,_,_),(t2,_,_)) = Int.compare (t1,t2)
 
  46   fun eq ((t1,_,_), (t2,_,_)) = t1 = t2
 
  48   fun cmpsize (Quad,Quad) = EQUAL
 
  49     | cmpsize (Quad,_) = GREATER
 
  50     | cmpsize (_,Quad) = LESS
 
  51     | cmpsize (Long,Long) = EQUAL
 
  52     | cmpsize (Long,_) = GREATER
 
  53     | cmpsize (_,Long) = LESS
 
  54     | cmpsize (Word,Word) = EQUAL
 
  55     | cmpsize (Word,_) = GREATER
 
  56     | cmpsize (_,Word) = LESS
 
  57     | cmpsize (Byte,Byte) = EQUAL
 
  63     | sts _ = raise ErrorMsg.InternalError "Temp.sts: invalid size"