SCM Repository
Annotation of /sml/trunk/src/MLRISC/util/asm-util.sml
Parent Directory
|
Revision Log
Revision 93 -
(view)
(download)
Original Path: sml/branches/SMLNJ/src/MLRISC/util/asm-util.sml
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 : | * $Log: asm-util.sml,v $ | ||
8 : | monnier | 93 | * Revision 1.1.1.1 1998/04/08 18:39:02 george |
9 : | * Version 110.5 | ||
10 : | monnier | 16 | * |
11 : | *) | ||
12 : | |||
13 : | structure AsmUtil : sig | ||
14 : | |||
15 : | val itoa : int -> string | ||
16 : | |||
17 : | val printableString : string -> string | ||
18 : | |||
19 : | end = struct | ||
20 : | |||
21 : | val hexDigits = "0123456789abcdef" | ||
22 : | |||
23 : | val >> = Word.~>> | ||
24 : | val & = Word.andb | ||
25 : | |||
26 : | infix >> & | ||
27 : | |||
28 : | val wtoi = Word.toIntX | ||
29 : | val itow = Word.fromInt | ||
30 : | |||
31 : | local | ||
32 : | fun f (0w0, l) = l | ||
33 : | | f (n, l) = f ((n >> 0w4), String.sub(hexDigits, wtoi (n & 0w15)) :: l) | ||
34 : | in | ||
35 : | fun itoa 0 = "0x0" | ||
36 : | | itoa i = if (i < 0) | ||
37 : | then implode(#"-" :: #"0" :: #"x" :: f(itow(~i), [])) | ||
38 : | else implode(#"0" :: #"x" :: f(itow i, [])) | ||
39 : | end | ||
40 : | |||
41 : | (* generates a printable string, including the surrounding quotes and | ||
42 : | * the null termination. | ||
43 : | *) | ||
44 : | fun printableString s = let | ||
45 : | fun isPrint c = ((#" " <= c) andalso (c <= #"~")) | ||
46 : | fun octal i = String.sub(hexDigits, wtoi (i & 0wx7)) | ||
47 : | fun mkLegal #"\"" = "\\\"" | ||
48 : | | mkLegal #"\\" = "\\\\" | ||
49 : | | mkLegal c = if ((#" " <= c) andalso (c <= #"~")) | ||
50 : | then String.str c | ||
51 : | else let val c' = itow (Char.ord c) | ||
52 : | in | ||
53 : | implode[#"\\", octal(c' >> 0w6), octal(c' >> 0w3), octal c'] | ||
54 : | end | ||
55 : | val term = (case (itow(size s) & 0wx3) (* natural word size *) | ||
56 : | of 0w0 => "\000\000\000\000\"" | ||
57 : | | 0w1 => "\000\000\000\"" | ||
58 : | | 0w2 => "\000\000\"" | ||
59 : | | _ => "\000\"" | ||
60 : | (* end case *)) | ||
61 : | in | ||
62 : | concat("\"" :: (map mkLegal (explode s)) @ [term]) | ||
63 : | end | ||
64 : | |||
65 : | end; | ||
66 : |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |