]> Joshua Wise's Git repositories - snipe.git/commitdiff
Add strings to the IR
authorJoshua Wise <jwise@andrew.cmu.edu>
Sat, 10 Jul 2010 04:33:56 +0000 (00:33 -0400)
committerJoshua Wise <jwise@andrew.cmu.edu>
Sat, 10 Jul 2010 04:33:56 +0000 (00:33 -0400)
sources.cm
trans/stringref.sml [new file with mode: 0644]
trans/trans.sml
trans/tree.sml
trans/treeutils.sml

index edf6e4929acc06a0ddac0db6b5a3e2e659b4ddec..3ab39304c56b3408145375d3fc3111eaf95c01f3 100644 (file)
@@ -26,6 +26,7 @@ Group is
 
        trans/temp.sml
         trans/label.sml
+       trans/stringref.sml
        trans/tree.sml
        trans/treeutils.sml
        trans/trans.sml
diff --git a/trans/stringref.sml b/trans/stringref.sml
new file mode 100644 (file)
index 0000000..f78bd95
--- /dev/null
@@ -0,0 +1,33 @@
+(* L3 Compiler
+ * Stringreforaries
+ * Like temporaries, except more different
+ * Author: Joshua Wise <jwise@cs.cmu.edu>
+ *)
+
+signature STRINGREF = 
+sig
+  type stringref
+
+  val reset : unit -> unit     (* resets stringref numbering *)
+  val new : string -> stringref        (* returns a unique new stringref *)
+  val name : stringref -> string       (* returns the name of a stringref *)
+  val compare : stringref * stringref -> order (* comparison function *)
+end
+
+structure Stringref :> STRINGREF = 
+struct
+  type stringref = int
+
+  local
+    val counter = ref 1
+    val strings = ref []
+  in
+    (* warning: calling reset() may jeopardize uniqueness of stringrefs! *)
+    fun reset () = ( counter := 1 ; strings := [] )
+    fun new (s : string) = !counter before ( strings := (!counter, s) :: !strings ; counter := !counter + 1 )
+  end
+
+  fun name t = "S" ^ Int.toString t
+                     
+  fun compare (t1,t2) = Int.compare (t1,t2)
+end
index 73968d9c36cf0f20df3007576d5ded04e0835b4a..0ec657403bf018b7f01007fc62bf87719ed52518 100644 (file)
@@ -98,6 +98,7 @@ struct
         (* after type-checking, id must be declared; do not guard lookup *)
             T.TEMP (Symbol.look' env id)
         | trans_exp env vartypes (A.ConstExp c) = T.CONST(c)
+        | trans_exp env vartypes (A.StringExp s) = T.STRING(Stringref.new s)
         | trans_exp env vartypes (A.OpExp(oper, [e1, e2])) =
             T.BINOP(trans_oper oper, trans_exp env vartypes e1, trans_exp env vartypes e2)
         | trans_exp env vartypes (A.OpExp(oper, [e])) =
index 2111fc19f666758fa1680f3c211e509438935564..d03180ed7129860b3a9086200866c725852d8173 100644 (file)
@@ -23,6 +23,7 @@ sig
     | CALL of Ast.ident * exp list
     | MEMORY of exp
     | ALLOC of exp
+    | STRING of Stringref.stringref
     | COND of exp * exp * exp
     | STMVAR of stm list * exp
     | NULLPTR
@@ -55,6 +56,7 @@ struct
     | CALL of Ast.ident * exp list
     | MEMORY of exp
     | ALLOC of exp
+    | STRING of Stringref.stringref
     | COND of exp * exp * exp
     | STMVAR of stm list * exp
     | NULLPTR
index ec6be4d40e3de9e9ee50eed92304ecb0224318a5..a15b1a31f06195dc89f1d646809c2db896d906a9 100644 (file)
@@ -28,6 +28,7 @@ struct
     | effect (T.UNOP (_, a)) = effect a
     | effect (T.MEMORY _) = true
     | effect (T.ALLOC _) = true
+    | effect (T.STRING _) = false
     | effect (T.COND (a, b, c)) = (effect a) orelse (effect b) orelse (effect c)
     | effect (T.STMVAR (sl, e)) = true (* Has to be, to be safe <--- jwise is an assclown, he was too lazy to write a effect_stm *)
     | effect (T.NULLPTR) = false
@@ -77,6 +78,7 @@ struct
           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.STRING(s)) = "STRING(" ^ (Stringref.name s) ^ ")"
       | 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) ^ "})"
       | pp_exp (T.NULLPTR) = "NULL"
This page took 0.031107 seconds and 4 git commands to generate.