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 /heap2asm/trunk/heap2asm.sml
ViewVC logotype

Annotation of /heap2asm/trunk/heap2asm.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2130 - (view) (download)

1 : mblume 1747 (* heap2asm.sml
2 :     *
3 :     * Generating an assembly code file corresponding to a heap image.
4 :     *
5 :     * Copyright (c) 2005 by The Fellowship of SML/NJ
6 :     *
7 :     * Author: Matthias Blume (blume@tti-c.org)
8 :     *)
9 :     structure Main: sig
10 :     val main: string * string list -> OS.Process.status
11 :     end = struct
12 :    
13 :     val N = 20
14 :    
15 :     fun one (inf, outf) =
16 :     let val (si, so) = (TextIO.openIn inf, TextIO.openOut outf)
17 :     fun out s = TextIO.output (so, s)
18 :     fun finish n =
19 :     (out ".text\n\t.align 2\n_smlnj_heap_image_len:\n\t.long ";
20 :     out (Int.toString n); out "\n")
21 :     fun line l =
22 :     let val bl = map (Int.toString o ord) (String.explode l)
23 :     in out ("\t.byte " ^ String.concatWith "," bl ^ "\n")
24 :     end
25 :     fun lines n =
26 :     case TextIO.inputN (si, N) of
27 :     "" => finish n
28 :     | l => let val s = size l
29 :     in line l; if s < N then finish (n+s) else lines (n+s)
30 :     end
31 :     in out "\t.globl _smlnj_heap_image\n\
32 :     \\t.globl _smlnj_heap_image_len\n\
33 :     \.text\n\t.align 2\n\
34 :     \_smlnj_heap_image:\n";
35 :     lines 0;
36 :     TextIO.closeIn si; TextIO.closeOut so
37 :     end
38 :    
39 :     fun complain (p, s) =
40 :     (TextIO.output (TextIO.stdErr, concat [p, ": ", s, "\n"]);
41 :     OS.Process.failure)
42 :    
43 :     fun main (p, [inf, outf]) =
44 :     ((one (inf, outf); OS.Process.success)
45 :     handle e => complain (p, "exception: " ^ General.exnMessage e))
46 :     | main (p, _) = complain (p, "usage: " ^ p ^ " heapfile asmfile")
47 :     end

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