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 367 - (download) (annotate)
Thu Sep 30 21:20:13 2010 UTC (9 years, 1 month ago) by jhr
File size: 2854 byte(s)
  Added HighIL to MidIL translation phase
(* 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

    structure HighPP = SSAPPFn (HighIL)
    structure MidPP = SSAPPFn (MidIL)

    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 (Log.logFile(), ast) (* DEBUG *)
		  val simple = Simplify.transform ast
		  val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *)
		  val highIL = Translate.translate simple
		  val _ = HighPP.output (Log.logFile(), "HighIL after translation", highIL) (* DEBUG *)
		  val highIL = HighOptimizer.optimize highIL
		  val _ = HighPP.output (Log.logFile(), "HighIL after optimization", highIL) (* DEBUG *)
		  val midIL = HighToMid.translate highIL
		  val _ = MidPP.output (Log.logFile(), "MidIL after translation", midIL) (* DEBUG *)
		  in
		    ()
		  end
	    (* end case *);
	    TextIO.closeIn inS
	  end

    fun doOptions args = let
	  val log = ref false
	  val defs = ref []
	  fun doOpts [file] = {log = !log, defs = !defs, file = file}
	    | doOpts ("-log"::r) = (log := true; doOpts r)
	    | doOpts (opt::r) = 
		if Inputs.isCmdLineInput opt
		  then (defs := opt :: !defs; doOpts r)
		  else (
		    err(concat["invalid command-line input \"", opt, "\"\n"]);
		    quitWithError())
	  in
	    doOpts args
	  end

    fun main (name: string, args: string list) = let
	  val {log, defs, file} = doOptions args
	  val {base, ...} = OS.Path.splitBaseExt file
	  in
	    if Inputs.initFromArgs defs
	      then (Log.init(base ^ ".log"); doFile file; 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())
	      else (err "invalid command-line inputs\n"; quitWithError())
	  end

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

  end

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