CVS: sml-dist/src/heap2asm build,NONE,1.1 heap2asm.cm,NONE,1.1 heap2asm.sml,NONE,1.1

Matthias Blume <[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj.commits
Message-ID <[email protected]>
Update of /cvsroot/smlnj/sml-dist/src/heap2asm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11855/src/heap2asm

Added Files:
	build heap2asm.cm heap2asm.sml 
Log Message:
new experimental heap2exec facility

--- NEW FILE: build ---
#!/bin/sh
#
# build script for heap2asm.
#
# options:
#   -o image		-- specify the name of the heap image, "ml-lex"
#			   is the default.

CMD=$0

ROOT="heap2asm"
HEAP_IMAGE=""
TWOUP=`pwd`/../../
BIN=${INSTALLDIR:-$TWOUP}/bin
BUILD=$BIN/ml-build

#
# process command-line options
#
while [ "$#" != "0" ] ; do
    arg=$1
    shift
    case $arg in
	-o)
	    if [ "$#" = "0" ]; then
		echo "$CMD: must supply image name for -o option"
		exit 1
	    fi
	    HEAP_IMAGE=$1; shift
	    ;;
	*)
	    echo $CMD: invalid argument: $arg
	    exit 1
	    ;;
    esac
done

if [ "$HEAP_IMAGE" = "" ]; then
    HEAP_IMAGE="$ROOT"
fi

"$BUILD" heap2asm.cm Main.main $HEAP_IMAGE

--- NEW FILE: heap2asm.cm ---
(* heap2asm.cm
 *
 *   Generating an assembly code file corresponding to a heap image.
 *
 * Copyright (c) 2005 by The Fellowship of SML/NJ
 *
 * Author: Matthias Blume ([email protected])
 *)
library
	structure Main
is
	$/basis.cm
	heap2asm.sml

--- NEW FILE: heap2asm.sml ---
(* heap2asm.sml
 *
 *   Generating an assembly code file corresponding to a heap image.
 *
 * Copyright (c) 2005 by The Fellowship of SML/NJ
 *
 * Author: Matthias Blume ([email protected])
 *)
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")
		end
	    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)
			 end
	in out "\t.globl _smlnj_heap_image\n\
	       \\t.globl _smlnj_heap_image_len\n\
	       \.text\n\t.align 2\n\
	       \_smlnj_heap_image:\n";
	   lines 0;
	   TextIO.closeIn si; TextIO.closeOut so
	end

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

    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")
end



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.