changeset 40:9fb190ad81a4 new_gen

Added -O and --inline args to Dang.
author Anders Johnsen <skabet@gmail.com>
date Tue, 22 Apr 2008 00:31:57 +0200
parents 1a7a308f75b2
children f977aa28eb32
files dang/compiler.d gen/LLVMGen.d
diffstat 2 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dang/compiler.d	Mon Apr 21 22:47:12 2008 +0200
+++ b/dang/compiler.d	Tue Apr 22 00:31:57 2008 +0200
@@ -73,6 +73,9 @@
 
     auto argParse = new OptionParser;
 
+    bool optimize = false;
+    bool inline = false;
+
     argParse.addOption(
             ["-h", "--help"],{
                 argParse.helpText();
@@ -112,13 +115,25 @@
 
     argParse.addOption(
             ["--gen-llvm"], {
-                postParse.attach(
+/*                postParse.attach(
                     (Decl[] decls, DataSource src) {
                         auto llvmGen = new LLVMGen();
                         llvmGen.gen(decls);
-                    });
+                    }); */
+            }
+    ).help("Compile to LLVM code (default)");
+
+    argParse.addOption(
+            ["-O","--optimize"], {
+                optimize = true;
             }
-    ).help("Compile to LLVM code");
+    ).help("Optimize code when compiling to LLVM");
+
+    argParse.addOption(
+            ["--inline"], {
+                inline = true;
+            }
+    ).help("Inline functions when compiling to LLVM");
 
     auto options = argParse.parse(args);
 
@@ -133,6 +148,12 @@
         return;
     }
 
+    postParse.attach(
+        (Decl[] decls, DataSource src) {
+            auto llvmGen = new LLVMGen();
+                llvmGen.gen(decls, optimize, inline);
+            });
+
     foreach(file ; filesToHandle)
     {
         preLex(file);
--- a/gen/LLVMGen.d	Mon Apr 21 22:47:12 2008 +0200
+++ b/gen/LLVMGen.d	Tue Apr 22 00:31:57 2008 +0200
@@ -54,7 +54,7 @@
         b.dispose();
     }
 
-    void gen(Decl[] decls)
+    void gen(Decl[] decls, bool optimize, bool inline)
     {
         // create module
         m = new Module("main_module");
@@ -96,9 +96,10 @@
         m.verify(err);
         Stderr(err).newline;
 
-        // m.optimize(true);
+        if(optimize)
+            m.optimize(inline);
 
-        m.writeBitcodeToFile("test.bc");
+        m.writeBitcodeToFile("out.bc");
     }
 
     void genRootDecl(Decl decl)