Mercurial > projects > dang
comparison gen/CodeGen.d @ 101:fea8d61a2451 new_gen
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Wed, 07 May 2008 19:58:13 +0200 |
parents | 7f9240d4ddc1 |
children | 189c049cbfcc |
comparison
equal
deleted
inserted
replaced
100:5f258eaf9517 | 101:fea8d61a2451 |
---|---|
75 createBasicTypes(); | 75 createBasicTypes(); |
76 } | 76 } |
77 | 77 |
78 ~this() | 78 ~this() |
79 { | 79 { |
80 b.dispose(); | 80 // b.dispose(); |
81 } | 81 } |
82 | 82 |
83 void gen(Module mod, uint handle, bool optimize, bool inline) | 83 void gen(Module mod, uint handle, bool optimize, bool inline) |
84 { | 84 { |
85 this.mod = mod; | |
85 // create module | 86 // create module |
86 m = new LLVM.Module("main_module"); | 87 m = new LLVM.Module("main_module"); |
87 scope(exit) m.dispose(); | 88 scope(exit) m.dispose(); |
88 | 89 |
89 table.enterScope; | 90 table.enterScope; |
137 llfunc.addParamAttr(i,ParamAttr.ByVal); | 138 llfunc.addParamAttr(i,ParamAttr.ByVal); |
138 } | 139 } |
139 } | 140 } |
140 }; | 141 }; |
141 auto visitor = new VisitFuncDecls(registerFunc); | 142 auto visitor = new VisitFuncDecls(registerFunc); |
142 visitor.visit(mod); | 143 visitor.visit([mod]); |
143 // Before beginning we move all top level var-decls to the start | 144 // Before beginning we move all top level var-decls to the start |
144 // and then we generate the var-decls first | 145 // and then we generate the var-decls first |
145 // partition is NOT required to be stable, but that should not create | 146 // partition is NOT required to be stable, but that should not create |
146 // any problems. | 147 // any problems. |
147 partition(mod.decls, (Decl d) { return d.declType == DeclType.VarDecl; }); | 148 partition(mod.decls, (Decl d) { return d.declType == DeclType.VarDecl; }); |
317 { | 318 { |
318 Value v = genExpression(arg); | 319 Value v = genExpression(arg); |
319 args ~= v; | 320 args ~= v; |
320 | 321 |
321 } | 322 } |
323 llvm(id.type); | |
322 // BUG: doesn't do implicit type-conversion | 324 // BUG: doesn't do implicit type-conversion |
323 if(callExp.sret) | 325 if(callExp.sret) |
324 return b.buildCall(m.getNamedFunction(id.getMangled), args, ""); | 326 return b.buildCall(m.getNamedFunction(id.getMangled), args, ""); |
325 return b.buildCall(m.getNamedFunction(id.getMangled), args, ".call"); | 327 return b.buildCall(m.getNamedFunction(id.getMangled), args, ".call"); |
326 case ExpType.CastExp: | 328 case ExpType.CastExp: |
703 else | 705 else |
704 params ~= llvm(param); | 706 params ~= llvm(param); |
705 | 707 |
706 Type res = FunctionType.Get(ret_t, params.unsafe()); | 708 Type res = FunctionType.Get(ret_t, params.unsafe()); |
707 type_map[t] = res; | 709 type_map[t] = res; |
708 /* auto llfunc = m.addFunction(res, f.name); | 710 auto id = new Identifier(f.name); |
709 | 711 id.setType(f); |
710 foreach (i, param; f.params) | 712 |
711 if (param.isStruct) | 713 auto f_t = m.getNamedFunction(id.getMangled); |
712 llfunc.addParamAttr(i, ParamAttr.ByVal); | 714 if(f_t is null) |
713 | |
714 if (f.firstParamIsReturnValue) | |
715 { | 715 { |
716 llfunc.removeParamAttr(0, ParamAttr.ByVal); | 716 auto llfunc = m.addFunction(res, id.getMangled); |
717 llfunc.addParamAttr(0, ParamAttr.StructRet); | 717 |
718 foreach (i, param; f.params) | |
719 if (param.isStruct) | |
720 llfunc.addParamAttr(i, ParamAttr.ByVal); | |
721 | |
722 if (f.firstParamIsReturnValue) | |
723 { | |
724 llfunc.removeParamAttr(0, ParamAttr.ByVal); | |
725 llfunc.addParamAttr(0, ParamAttr.StructRet); | |
726 } | |
718 } | 727 } |
719 */ | |
720 return res; | 728 return res; |
721 } | 729 } |
722 else if (auto f = t.asPointer) | 730 else if (auto f = t.asPointer) |
723 { | 731 { |
724 Type res = PointerType.Get(llvm(f.pointerOf)); | 732 Type res = PointerType.Get(llvm(f.pointerOf)); |
751 } | 759 } |
752 | 760 |
753 private: | 761 private: |
754 | 762 |
755 // llvm stuff | 763 // llvm stuff |
764 Module mod; | |
756 LLVM.Module m; | 765 LLVM.Module m; |
757 LLVM.Builder b; | 766 LLVM.Builder b; |
758 Function llvm_memcpy; | 767 Function llvm_memcpy; |
759 Type BytePtr; | 768 Type BytePtr; |
760 Type[DType] type_map; | 769 Type[DType] type_map; |