]> Joshua Wise's Git repositories - snipe.git/commitdiff
Emit strings at the end.
authorJoshua Wise <jwise@andrew.cmu.edu>
Sat, 10 Jul 2010 04:58:57 +0000 (00:58 -0400)
committerJoshua Wise <jwise@andrew.cmu.edu>
Sat, 10 Jul 2010 04:58:57 +0000 (00:58 -0400)
top/top.sml
trans/stringref.sml

index 006fa4685af5d4f531d6fe377cabb60c9ebed5a0..6c9f0a2039353686e4bc72c8ef8465ea6ce523bc 100644 (file)
@@ -213,10 +213,22 @@ struct
         val _ = Flag.guard Flags.verbose say "Optimizing whole-program IR..."
         val ir = Optimizer.optimize_ir (!enabledopts) ir
         val _ = Flag.guard Flags.ir (fn () => say (TreeUtils.Print.pp_program ir)) ()
         val _ = Flag.guard Flags.verbose say "Optimizing whole-program IR..."
         val ir = Optimizer.optimize_ir (!enabledopts) ir
         val _ = Flag.guard Flags.ir (fn () => say (TreeUtils.Print.pp_program ir)) ()
-
-        val output = foldr (fn (func, code) => (processir ("calloc" (* lololololol *) :: (Symbol.elems externs)) func) ^ code) 
-          (".file\t\"" ^ source ^ "\"\n.ident\t\"15-411 ASS compiler by czl@ and jwise@\"\n" ^
-           ".ident \"Optimizations enabled: " ^ String.concat (map (fn x => (#shortname x) ^ " ") (!enabledopts)) ^ "\"\n") ir
+        
+        val code = map (fn func => processir ("calloc" (* lololololol *) :: (Symbol.elems externs)) func) ir
+        val strings = map (fn (sn, s) => String.concat (
+                                           [Stringref.name sn, ": .word "] @
+                                           (map (fn c => (Int.toString (ord c)) ^ ", ") (String.explode s)) @ 
+                                           ["0\n"]
+                                         ) ) (Stringref.all ())
+
+        val output =
+          String.concat (
+            ".file\t\"" :: source :: "\"\n" ::
+            ".ident\t\"15-411 ASS compiler by czl@ and jwise@\"\n" ::
+            ".ident \"Optimizations enabled: " :: (map (fn x => (#shortname x) ^ " ") (!enabledopts)) @ [ "\"\n" ] @
+            code @
+            [ ".section .rodata\n" ] @
+            strings )
 
         val afname = stem source ^ ".s"
         val _ = Flag.guard Flags.verbose say ("Writing assembly to " ^ afname ^ " ...")
 
         val afname = stem source ^ ".s"
         val _ = Flag.guard Flags.verbose say ("Writing assembly to " ^ afname ^ " ...")
index f78bd95c71330c11695e6dcf16ee0ba623855799..978d4a36ca572a1bf6fb7d710313bcd5f15fa51d 100644 (file)
@@ -12,6 +12,7 @@ sig
   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 *)
   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 *)
+  val all : unit -> (stringref * string) list
 end
 
 structure Stringref :> STRINGREF = 
 end
 
 structure Stringref :> STRINGREF = 
@@ -25,6 +26,7 @@ struct
     (* 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 )
     (* 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 )
+    fun all () = !strings
   end
 
   fun name t = "S" ^ Int.toString t
   end
 
   fun name t = "S" ^ Int.toString t
This page took 0.025917 seconds and 4 git commands to generate.