]> Joshua Wise's Git repositories - snipe.git/blobdiff - trans/temp.sml
Initial import of l5c
[snipe.git] / trans / temp.sml
index 13411f1ab76e16c38a986059439f3a45802009a7..bd311c4a08176cb88b0b8175029a31d1d078e549 100644 (file)
@@ -1,4 +1,4 @@
-(* L2 Compiler
+(* L3 Compiler
  * Temporaries
  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
  * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
@@ -8,26 +8,58 @@
 signature TEMP = 
 sig
   type temp
+  datatype size = Byte | Word | Long | Quad
 
-  val reset : unit -> unit     (* resets temp numbering *)
-  val new : unit -> temp       (* returns a unique new temp *)
-  val name : temp -> string    (* returns the name 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
+  datatype size = Byte | Word | Long | Quad
+  type temp = int * string * size
 
   local
     val counter = ref 1
   in
     (* warning: calling reset() may jeopardize uniqueness of temps! *)
     fun reset () = ( counter := 1 )
-    fun new () = !counter before ( counter := !counter + 1 )
+    fun new str size = (!counter, str, size) before ( counter := !counter + 1 )
   end
 
-  fun name t = "+t" ^ Int.toString t
-                     
-  fun compare (t1,t2) = Int.compare (t1,t2)
+  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
This page took 0.024666 seconds and 4 git commands to generate.