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

SCM Repository

[smlnj] Annotation of /sml/branches/SMLNJ/src/MLRISC/util/asm-util.sml
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/MLRISC/util/asm-util.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (view) (download)

1 : monnier 16 (* asm-util.sml
2 :     *
3 :     * COPYRIGHT (c) 1994 AT&T Bell Laboratories.
4 :     *
5 :     * Utility code for generating assembler code.
6 :     *
7 : monnier 113 * $Log$
8 : monnier 16 *)
9 :    
10 :     structure AsmUtil : sig
11 :    
12 :     val itoa : int -> string
13 :    
14 :     val printableString : string -> string
15 :    
16 :     end = struct
17 :    
18 :     val hexDigits = "0123456789abcdef"
19 :    
20 :     val >> = Word.~>>
21 :     val & = Word.andb
22 :    
23 :     infix >> &
24 :    
25 :     val wtoi = Word.toIntX
26 :     val itow = Word.fromInt
27 :    
28 :     local
29 :     fun f (0w0, l) = l
30 :     | f (n, l) = f ((n >> 0w4), String.sub(hexDigits, wtoi (n & 0w15)) :: l)
31 :     in
32 :     fun itoa 0 = "0x0"
33 :     | itoa i = if (i < 0)
34 :     then implode(#"-" :: #"0" :: #"x" :: f(itow(~i), []))
35 :     else implode(#"0" :: #"x" :: f(itow i, []))
36 :     end
37 :    
38 :     (* generates a printable string, including the surrounding quotes and
39 :     * the null termination.
40 :     *)
41 :     fun printableString s = let
42 :     fun isPrint c = ((#" " <= c) andalso (c <= #"~"))
43 :     fun octal i = String.sub(hexDigits, wtoi (i & 0wx7))
44 :     fun mkLegal #"\"" = "\\\""
45 :     | mkLegal #"\\" = "\\\\"
46 :     | mkLegal c = if ((#" " <= c) andalso (c <= #"~"))
47 :     then String.str c
48 :     else let val c' = itow (Char.ord c)
49 :     in
50 :     implode[#"\\", octal(c' >> 0w6), octal(c' >> 0w3), octal c']
51 :     end
52 :     val term = (case (itow(size s) & 0wx3) (* natural word size *)
53 :     of 0w0 => "\000\000\000\000\""
54 :     | 0w1 => "\000\000\000\""
55 :     | 0w2 => "\000\000\""
56 :     | _ => "\000\""
57 :     (* end case *))
58 :     in
59 :     concat("\"" :: (map mkLegal (explode s)) @ [term])
60 :     end
61 :    
62 :     end;
63 :    

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