diff 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
line wrap: on
line diff
--- a/gen/CodeGen.d	Tue May 06 22:49:43 2008 +0200
+++ b/gen/CodeGen.d	Wed May 07 19:58:13 2008 +0200
@@ -77,11 +77,12 @@
 
     ~this()
     {
-        b.dispose();
+//        b.dispose();
     }
 
     void gen(Module mod, uint handle, bool optimize, bool inline)
     {
+        this.mod = mod;
         // create module
         m = new LLVM.Module("main_module");
         scope(exit) m.dispose();
@@ -139,7 +140,7 @@
                 }
             };
         auto visitor = new VisitFuncDecls(registerFunc);
-        visitor.visit(mod);
+        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
@@ -319,6 +320,7 @@
                     args ~= v;
 
                 }
+                llvm(id.type);
                 // BUG: doesn't do implicit type-conversion
                 if(callExp.sret)
                     return b.buildCall(m.getNamedFunction(id.getMangled), args, "");
@@ -705,18 +707,24 @@
 
             Type res = FunctionType.Get(ret_t, params.unsafe());
             type_map[t] = res;
-/*            auto llfunc = m.addFunction(res, f.name);
-            
-            foreach (i, param; f.params)
-                if (param.isStruct)
-                    llfunc.addParamAttr(i, ParamAttr.ByVal);
+            auto id = new Identifier(f.name);
+            id.setType(f);
+
+            auto f_t = m.getNamedFunction(id.getMangled);
+            if(f_t is null)
+            {
+                auto llfunc = m.addFunction(res, id.getMangled);
 
-            if (f.firstParamIsReturnValue)
-            {
-                llfunc.removeParamAttr(0, ParamAttr.ByVal);
-                llfunc.addParamAttr(0, ParamAttr.StructRet);
+                foreach (i, param; f.params)
+                    if (param.isStruct)
+                        llfunc.addParamAttr(i, ParamAttr.ByVal);
+
+                if (f.firstParamIsReturnValue)
+                {
+                    llfunc.removeParamAttr(0, ParamAttr.ByVal);
+                    llfunc.addParamAttr(0, ParamAttr.StructRet);
+                }
             }
-*/
             return res;
         }
         else if (auto f = t.asPointer)
@@ -753,6 +761,7 @@
 private:
 
     // llvm stuff
+    Module mod;
     LLVM.Module m;
     LLVM.Builder b;
     Function llvm_memcpy;