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

View of /heap2asm/trunk/heap2asm.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1747 - (download) (annotate)
Fri Jan 14 23:53:21 2005 UTC (16 years, 10 months ago) by mblume
Original Path: sml/trunk/src/heap2asm/heap2asm.sml
File size: 1377 byte(s)
new experimental heap2exec facility
(* heap2asm.sml
 *   Generating an assembly code file corresponding to a heap image.
 * Copyright (c) 2005 by The Fellowship of SML/NJ
 * Author: Matthias Blume (blume@tti-c.org)
structure Main: sig
    val main: string * string list -> OS.Process.status
end = struct

    val N = 20

    fun one (inf, outf) =
	let val (si, so) = (TextIO.openIn inf, TextIO.openOut outf)
	    fun out s = TextIO.output (so, s)
	    fun finish n =
		(out ".text\n\t.align 2\n_smlnj_heap_image_len:\n\t.long ";
		 out (Int.toString n); out "\n")
	    fun line l =
		let val bl = map (Int.toString o ord) (String.explode l)
		in out ("\t.byte " ^ String.concatWith "," bl ^ "\n")
	    fun lines n =
		case TextIO.inputN (si, N) of
		    "" => finish n
		  | l => let val s = size l
			 in line l; if s < N then finish (n+s) else lines (n+s)
	in out "\t.globl _smlnj_heap_image\n\
	       \\t.globl _smlnj_heap_image_len\n\
	       \.text\n\t.align 2\n\
	   lines 0;
	   TextIO.closeIn si; TextIO.closeOut so

    fun complain (p, s) =
	(TextIO.output (TextIO.stdErr, concat [p, ": ", s, "\n"]);

    fun main (p, [inf, outf]) =
	((one (inf, outf); OS.Process.success)
	 handle e => complain (p, "exception: " ^ General.exnMessage e))
      | main (p, _) = complain (p, "usage: " ^ p ^ " heapfile asmfile")

ViewVC Help
Powered by ViewVC 1.0.0