Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/src/compiler/driver/main.sml
ViewVC logotype

View of /trunk/src/compiler/driver/main.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (download) (annotate)
Sat Jul 24 15:38:08 2010 UTC (8 years, 10 months ago) by jhr
File size: 1709 byte(s)
  Adding simplify pass to driver
(* main.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Main : sig

    val main : (string * string list) -> OS.Process.status

    val test : string -> unit

  end = struct

    fun err s = TextIO.output (TextIO.stdErr, s)
    fun err1 c =  TextIO.output1 (TextIO.stdErr, c)
    fun errnl s = (err s; err1 #"\n")

    fun quitWithError () = raise Fail "error"

  (* check for errors and report them if there are any *)
    fun checkForErrors errStrm = (
	  Error.report (TextIO.stdErr, errStrm);
	  if Error.anyErrors errStrm
	    then quitWithError ()
	    else ())

    fun doFile filename = let
	  val errStrm = Error.mkErrStream filename
	  val inS = TextIO.openIn filename
	  val checkTypes = Typechecker.check errStrm
	  in
	    case Parser.parseFile (errStrm, inS)
	     of NONE => (checkForErrors errStrm; quitWithError ())
	      | SOME pt => let
		  val _ = checkForErrors errStrm
		  val ast = (checkTypes pt) handle Typechecker.Error => AST.Program[]
		  val _ = checkForErrors errStrm
		  val _ = ASTPP.output (TextIO.stdOut, ast) (* DEBUG *)
		  val simple = Simplify.transform ast
		  in
(*
		    SimplePP.output (TextIO.stdOut, ast) (* DEBUG *)
*)()
		  end
	    (* end case *);
	    TextIO.closeIn inS
	  end

    fun main (name: string, args: string list) =
	  (List.app doFile args; OS.Process.success)
	handle exn => (
	  err (concat [
	      "uncaught exception ", General.exnName exn, " [", General.exnMessage exn, "]\n"]);
	      List.app (fn s => err (concat ["  raised at ", s, "\n"]))
		(SMLofNJ.exnHistory exn);
	      quitWithError())

    fun test file = (main ("", [file]); print "** Success!!\n")

  end

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