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 /sml/trunk/src/MLRISC/IR/mlrisc-format-insn.sml
ViewVC logotype

View of /sml/trunk/src/MLRISC/IR/mlrisc-format-insn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (download) (annotate)
Thu Jun 1 18:34:03 2000 UTC (19 years, 3 months ago) by monnier
File size: 1373 byte(s)
bring revisions from the vendor branch to the trunk
(*
 * 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.C.cell -> I.C.cell) -> 
                    I.instruction -> string

end

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

   fun toString an regmap 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 regmap 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