Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /MLRISC/trunk/visualization/mlrisc-format-insn.sml
ViewVC logotype

View of /MLRISC/trunk/visualization/mlrisc-format-insn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2126 - (download) (annotate)
Thu Nov 2 16:11:29 2006 UTC (12 years, 7 months ago) by blume
File size: 1312 byte(s)
moved MLRISC to toplevel
(*
 * This just provide a very simple pretty printing function.
 * It is used for visualization.
 *
 * -- Allen 
 * 
 *)

signature FORMAT_INSTRUCTION =
sig
   structure I  : INSTRUCTIONS

   val toString : Annotations.annotations -> I.instruction -> string

end

functor FormatInstruction(Asm : INSTRUCTION_EMITTER) : FORMAT_INSTRUCTION =
struct
   structure I = Asm.I

   fun toString an insn =
   let val buffer = StringOutStream.mkStreamBuf()
       val S      = StringOutStream.openStringOut buffer
       val ()     = AsmStream.withStream S 
                     (fn insn => 
                      let val Asm.S.STREAM{emit,...} = Asm.makeStream an
                      in emit insn
                      end) insn
       val text   = StringOutStream.getString buffer
       fun isSpace #" "  = true
         | isSpace #"\t" = true
         | isSpace _     = false
       val text   = foldr (fn (x,"") => x | (x,y) => x^" "^y) ""
                          (String.tokens isSpace text)
       fun stripNL "" = ""
         | stripNL s =
       let fun f(0) = ""
             | f(i) = 
               case String.sub(s,i) of
                 #"\n" => f(i-1)
               | #" "  => f(i-1)
               | _     => String.extract(s,0,SOME(i+1))
       in  f(size s - 1) end  
   in  stripNL text end

end


root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0