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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/driver/main.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/driver/main.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3432, Sun Nov 15 14:42:04 2015 UTC revision 3506, Fri Dec 18 04:03:54 2015 UTC
# Line 16  Line 16 
16      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)      fun err1 c =  TextIO.output1 (TextIO.stdErr, c)
17      fun errnl s = (err s; err1 #"\n")      fun errnl s = (err s; err1 #"\n")
18    
19      exception ERROR      fun quitWithError srcFile = raise Error.ERROR
   
     fun quitWithError srcFile = raise ERROR  
20    
21    (* check for errors and report them if there are any *)    (* check for errors and report them if there are any *)
22      fun checkForErrors errStrm =      fun checkForErrors errStrm =
# Line 28  Line 26 
26                quitWithError (Error.sourceFile errStrm))                quitWithError (Error.sourceFile errStrm))
27              else ()              else ()
28    
29      (* conditional printing of intermediate forms *)
30        fun dump ctl output message prog = if Controls.get ctl
31              then output (Log.logFile(), message, prog)
32              else ()
33    
34    (* compiler front end (parsing, typechecking, and simplification *)    (* compiler front end (parsing, typechecking, and simplification *)
35      fun frontEnd filename = let      fun frontEnd' (errStrm, filename) = let
           val errStrm = Error.mkErrStream filename  
36            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])            val _ = if OS.FileSys.access(filename, [OS.FileSys.A_READ])
37                  then ()                  then ()
38                  else (                  else (
39                    err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);                    err(concat["source file \"", filename, "\" does not exist or is not readable\n"]);
40                    raise ERROR)                    raise Error.ERROR)
41          (***** PARSING *****)          (***** PARSING *****)
42            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let            val parseTree = PhaseTimer.withTimer Timers.timeParser (fn () => let
43                  val inS = TextIO.openIn filename                  val inS = TextIO.openIn filename
# Line 45  Line 47 
47                    checkForErrors errStrm;                    checkForErrors errStrm;
48                    valOf pt                    valOf pt
49                  end) ()                  end) ()
50            val _ = if Controls.get Ctl.dumpPT            val _ = dump Ctl.dumpPT (ParseTreePP.output errStrm) "" parseTree
                     then ParseTreePP.output (errStrm, Log.logFile(), parseTree)  
                     else ()  
51          (***** TYPECHECKING *****)          (***** TYPECHECKING *****)
52            val _ = PhaseTimer.start Timers.timeTypechecker            val _ = PhaseTimer.start Timers.timeTypechecker
53            val ast = (Typechecker.check errStrm parseTree)            val ast = (Typechecker.check errStrm parseTree)
54            val _ = PhaseTimer.stop Timers.timeTypechecker            val _ = PhaseTimer.stop Timers.timeTypechecker
55            val _ = checkForErrors errStrm            val _ = checkForErrors errStrm
56  (* TODO: check AST for consistency *)  (* TODO: check AST for consistency *)
57            val _ = if Controls.get Ctl.dumpAST            val _ = dump Ctl.dumpAST ASTPP.output "" ast
                     then ASTPP.output (Log.logFile(), ast)  
                     else ()  
58          (***** SIMPLIFY *****)          (***** SIMPLIFY *****)
59  (* TODO *)            val simple = Simplify.transform (errStrm, ast)
60              val _ = dump Ctl.dumpSimple SimplePP.output "after simplify" simple
61              val simple = SimpleOpt.transform simple
62              val _ = dump Ctl.dumpSimple SimplePP.output "after simple optimization" simple
63            in            in
64            (* check for warnings and report if necessary *)            (* check for warnings and report if necessary *)
65              if Error.anyWarnings errStrm              if Error.anyWarnings errStrm
66                then Error.report (TextIO.stdErr, errStrm)                then Error.report (TextIO.stdErr, errStrm)
67                else ();                else ();
68              ()              simple
69              end
70    
71      (* a wrapper around the front-end that handles the Error.ERROR exception and reports
72       * the error messages.
73       *)
74        fun frontEnd filename = let
75              val errStrm = Error.mkErrStream filename
76              fun finish () = (
77                    if Error.anyErrors errStrm
78                      then (
79                        Error.report (TextIO.stdErr, errStrm);
80                        quitWithError (Error.sourceFile errStrm))
81                    else if Error.anyWarnings errStrm
82                      then Error.report (TextIO.stdErr, errStrm)
83                      else ())
84              in
85                (frontEnd' (errStrm, filename) handle exn => (finish (); raise exn))
86                before finish()
87            end            end
88    
89      fun doFile (target : Target.desc, filename) = let      fun doFile (target : Target.desc, filename) = let
# Line 74  Line 93 
93                  (* end case *))                  (* end case *))
94            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename            val simple = PhaseTimer.withTimer Timers.timeFront frontEnd filename
95          (***** TRANSLATION TO HIGH IL*****)          (***** TRANSLATION TO HIGH IL*****)
96              val high = Translate.translate simple
97              val _ = dump Ctl.dumpHighIL HighPP.output "after translate" high
98  (* TODO *)  (* TODO *)
99          (***** HIGH-IL OPTIMIZATION *****)          (***** HIGH-IL OPTIMIZATION *****)
100  (* TODO *)  (* TODO *)
# Line 88  Line 109 
109    
110      fun usage (cmd, long) = TextIO.output(TextIO.stdErr, Options.usage (cmd, long))      fun usage (cmd, long) = TextIO.output(TextIO.stdErr, Options.usage (cmd, long))
111    
112      fun handleExn ERROR = OS.Process.failure      fun handleExn Error.ERROR = OS.Process.failure
113        | handleExn exn = (        | handleExn exn = (
114            err (concat [            err (concat [
115                "uncaught exception ", General.exnName exn,                "uncaught exception ", General.exnName exn,

Legend:
Removed from v.3432  
changed lines
  Added in v.3506

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