SCM Repository
View of /trunk/src/compiler/driver/main.sml
Parent Directory
|
Revision Log
Revision 460 -
(download)
(annotate)
Wed Oct 27 16:11:13 2010 UTC (11 years, 8 months ago) by jhr
File size: 3737 byte(s)
Wed Oct 27 16:11:13 2010 UTC (11 years, 8 months ago) by jhr
File size: 3737 byte(s)
Working on mid-to-low translation
(* main.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.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) structure LowPP = SSAPPFn (LowIL) fun err s = TextIO.output (TextIO.stdErr, s) fun err1 c = TextIO.output1 (TextIO.stdErr, c) fun errnl s = (err s; err1 #"\n") exception ERROR fun quitWithError srcFile = raise Fail("Error in compiling " ^ srcFile) (* check for errors and report them if there are any *) fun checkForErrors errStrm = ( Error.report (TextIO.stdErr, errStrm); if Error.anyErrors errStrm then quitWithError (Error.sourceFile errStrm) else ()) fun doFile filename = let val errStrm = Error.mkErrStream filename val inS = TextIO.openIn filename val checkTypes = Typechecker.check errStrm (***** PARSING *****) val parseTree = let val pt = Parser.parseFile (errStrm, inS) in TextIO.closeIn inS; checkForErrors errStrm; valOf pt end val _ = checkForErrors errStrm (***** TYPECHECKING *****) val ast = (checkTypes parseTree) handle Typechecker.Error => AST.Program[] val _ = checkForErrors errStrm val _ = ASTPP.output (Log.logFile(), ast) (* DEBUG *) (***** SIMPLIFY *****) val simple = Simplify.transform ast val _ = SimplePP.output (Log.logFile(), simple) (* DEBUG *) (***** TRANSLATION TO HIGH IL*****) val highIL = Translate.translate simple val _ = ( (* DEBUG *) HighPP.output (Log.logFile(), "HighIL after translation", highIL); if CheckHighIL.check ("after translation", highIL) then quitWithError filename else ()) (***** HIGH-IL OPTIMIZATION *****) val highIL = HighOptimizer.optimize highIL val _ = ( (* DEBUG *) HighPP.output (Log.logFile(), "HighIL after optimization", highIL); if CheckHighIL.check ("after optimization", highIL) then quitWithError filename else ()) (***** TRANSLATION TO MID IL *****) val midIL = HighToMid.translate highIL val _ = ( (* DEBUG *) MidPP.output (Log.logFile(), "MidIL after translation", midIL); if CheckMidIL.check ("after translation", midIL) then quitWithError filename else ()) (***** TRANSLATION TO LOW IL *****) val lowIL = MidToLow.translate midIL val _ = ( (* DEBUG *) LowPP.output (Log.logFile(), "LowIL after translation", lowIL); if CheckLowIL.check ("after translation", lowIL) then quitWithError filename else ()) in () (* FIXME *) 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"]); raise ERROR) 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); OS.Process.failure) else (err "invalid command-line inputs\n"; OS.Process.failure) end handle ERROR => OS.Process.failure fun test file = (main ("", [file]); print "** Success!!\n") end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |