diff dang/compiler.d @ 89:a49bb982a7b0 new_gen

Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
author Anders Johnsen <skabet@gmail.com>
date Sun, 04 May 2008 20:27:01 +0200
parents eb5b2c719a39
children 4b6d8563e943
line wrap: on
line diff
--- a/dang/compiler.d	Sun May 04 18:13:46 2008 +0200
+++ b/dang/compiler.d	Sun May 04 20:27:01 2008 +0200
@@ -2,7 +2,9 @@
 
 import tango.io.Stdout,
        tango.core.Signal,
+       tango.sys.Process,
        tango.time.StopWatch,
+       tango.io.FileConduit,
        tango.io.FilePath;
 
 import lexer.Lexer,
@@ -10,6 +12,8 @@
 
 import basic.SourceManager;
 
+import basic.Message;
+
 import ast.Decl;
 
 import tools.AstPrinter,
@@ -85,6 +89,10 @@
     bool optimize = false;
     bool inline = false;
 
+
+    SourceManager src_mgr = new SourceManager;
+    MessageHandler messages = new MessageHandler(src_mgr);
+
     argParse.addOption(["-h", "--help"], Opt.Action.Help)
         .help("Show this help message");
 
@@ -94,10 +102,12 @@
     argParse.addOption(["--ast-dump-code"],
             "what-to-do", Opt.Action.StoreConst, "code")
         .help("Output the AST as code");
-
     argParse.addOption(["--gen-llvm"],
             "what-to-do", Opt.Action.StoreConst, "gen-llvm")
         .help("Compile to LLVM code (default)");
+    argParse.addOption(["-c"],
+            "what-to-do", Opt.Action.StoreConst, "compile")
+        .help("Compile to .o or executeable");
 
     argParse.addOption(
             ["-O","--optimize"], {
@@ -131,9 +141,19 @@
             (Decl[] decls, SourceManager sm) {
                 StopWatch w; w.start;
                 auto llvmGen = new CodeGen();
-                llvmGen.gen(decls, optimize, inline);
+                auto file = new FileConduit("out.bc");
+                llvmGen.gen(decls, file.fileHandle, optimize, inline);
                 timings ~= Measurement("Generating LLVM bytecode", w.stop);
             });
+    else if (what == "compile")
+        postParse.attach(
+            (Decl[] decls, SourceManager sm) {
+                StopWatch w; w.start;
+                auto llvmGen = new CodeGen();
+                auto llc = new Process("llc");
+                llvmGen.gen(decls, llc.stdin.fileHandle, optimize, inline);
+                timings ~= Measurement("Generating assemble bytecode", w.stop);
+            });
     else if (what == "dot")
         postParse.attach(
             (Decl[] decls, SourceManager sm) {
@@ -150,9 +170,6 @@
                 print.print(decls);
                 timings ~= Measurement("Converting AST to text", w.stop);
             });
-
-    SourceManager src_mgr = new SourceManager;
-
     StopWatch total;
     total.start;
     foreach (file; filesToHandle)
@@ -160,18 +177,18 @@
         preLex(file);
 
         auto start = src_mgr.addFile(file);
-        Stdout(file).newline;
-        auto lexer = new Lexer(start, src_mgr);
+        auto lexer = new Lexer(start, src_mgr, messages);
         postLex(lexer);
 
         preParse(lexer);
 
         StopWatch watch;
         watch.start;
-        auto parser = new Parser;
+        auto parser = new Parser(messages);
         auto action = new AstAction(src_mgr);
         auto decls = cast(Decl[])parser.parse(src_mgr, lexer, action);
         timings ~= Measurement("Lex + Parse", watch.stop);
+        messages.checkErrors();
 
         StopWatch watch2;
         watch.start;