# HG changeset patch # User Anders Johnsen # Date 1208817117 -7200 # Node ID 9fb190ad81a4c6ff3dfa4655820429dc35231c3c # Parent 1a7a308f75b213204658e2ef111d0fc33a68e3fa Added -O and --inline args to Dang. diff -r 1a7a308f75b2 -r 9fb190ad81a4 dang/compiler.d --- 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); diff -r 1a7a308f75b2 -r 9fb190ad81a4 gen/LLVMGen.d --- 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)