Mercurial > projects > dang
diff gen/CodeGen.d @ 94:48bb2287c035 new_gen
Added Modules. Right now it's very simple - will grow with time and need.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 06 May 2008 16:24:14 +0200 |
parents | 621cedba53ea |
children | 438e6ed4cda1 |
line wrap: on
line diff
--- a/gen/CodeGen.d Mon May 05 20:53:13 2008 +0200 +++ b/gen/CodeGen.d Tue May 06 16:24:14 2008 +0200 @@ -4,9 +4,10 @@ Int = tango.text.convert.Integer; import tango.core.Array : find, partition; -import llvm.llvm; +import LLVM = llvm.llvm; -import ast.Decl, +import ast.Module, + ast.Decl, ast.Stmt, ast.Exp; @@ -18,6 +19,20 @@ import sema.Scope, sema.Visitor; +alias LLVM.Value Value; +alias LLVM.Type Type; +alias LLVM.Function Function; +alias LLVM.PointerType PointerType; +alias LLVM.FunctionType FunctionType; +alias LLVM.IntPredicate IntPredicate; +alias LLVM.ParamAttr ParamAttr; +alias LLVM.ConstantInt ConstantInt; +alias LLVM.GlobalVariable GlobalVariable; +alias LLVM.IntegerType IntegerType; +alias LLVM.BasicBlock BasicBlock; +alias LLVM.StructType StructType; +alias LLVM.ArrayType ArrayType; + private char[] genBuildCmp(char[] p) { return ` @@ -41,7 +56,7 @@ this() { alias BinaryExp.Operator op; - b = new Builder; + b = new LLVM.Builder; opToLLVM = [ op.Add : &b.buildAdd, @@ -65,10 +80,10 @@ b.dispose(); } - void gen(Decl[] decls, uint handle, bool optimize, bool inline) + void gen(Module mod, uint handle, bool optimize, bool inline) { // create module - m = new Module("main_module"); + m = new LLVM.Module("main_module"); scope(exit) m.dispose(); table.enterScope; @@ -124,14 +139,14 @@ } }; auto visitor = new VisitFuncDecls(registerFunc); - visitor.visit(decls); + visitor.visit(mod); // Before beginning we move all top level var-decls to the start // and then we generate the var-decls first // partition is NOT required to be stable, but that should not create // any problems. - partition(decls, (Decl d) { return d.declType == DeclType.VarDecl; }); + partition(mod.decls, (Decl d) { return d.declType == DeclType.VarDecl; }); - foreach (decl; decls) + foreach (decl; mod.decls) genRootDecl(decl); table.leaveScope; @@ -738,8 +753,8 @@ private: // llvm stuff - Module m; - Builder b; + LLVM.Module m; + LLVM.Builder b; Function llvm_memcpy; Type BytePtr; Type[DType] type_map; @@ -759,9 +774,9 @@ this.dg = dg; } - override void visit(Decl[] decls) + override void visitModule(Module m) { - foreach (decl; decls) + foreach (decl; m.decls) if (auto f = cast(FuncDecl)decl) dg(f); }