diff gen/CodeGen.d @ 86:29f486ccc203 new_gen

Fixed a bug that made arrays as params fail big time
author Anders Johnsen <skabet@gmail.com>
date Fri, 02 May 2008 21:21:18 +0200
parents 9375bd975730
children 9a35a973175a
line wrap: on
line diff
--- a/gen/CodeGen.d	Fri May 02 20:18:50 2008 +0200
+++ b/gen/CodeGen.d	Fri May 02 21:21:18 2008 +0200
@@ -83,12 +83,17 @@
                 Type[] param_types;
                 foreach (i, p; fd.funcArgs)
                 {
-                    DType t = p.env.findType(p.varType);
-                    if(auto st = cast(DStruct)t)
+                    DType t = p.env.find(p.identifier).type;
+                    if(auto st = t.asStruct)
                     {
                         Type pointer = PointerType.Get(llvm(st));
                         param_types ~= pointer;
                     }
+                    if(auto ar = t.asArray)
+                    {
+                        Type pointer = PointerType.Get(llvm(ar));
+                        param_types ~= pointer;
+                    }
                     else
                         param_types ~= llvm(t);
                 }
@@ -105,13 +110,17 @@
                     if(i == 0 && fd.sret)
                         llfunc.addParamAttr(0, ParamAttr.StructRet);
 
-                    DType t = p.env.findType(p.varType);
-                    if(auto st = cast(DStruct)t)
+                    DType t = p.env.find(p.identifier).type;
+                    if(auto st = t.asStruct)
                     {
                         if(i == 0 && fd.sret)
                             continue;
                         llfunc.addParamAttr(i,ParamAttr.ByVal);
                     }
+                    else if(auto ar = t.asArray)
+                    {
+                        llfunc.addParamAttr(i,ParamAttr.ByVal);
+                    }
                 }
             };
         auto visitor = new VisitFuncDecls(registerFunc);
@@ -152,6 +161,7 @@
                 auto func_t = cast(FunctionType)func_tp.elementType();
                 auto ret_t = func_t.returnType();
 
+
                 auto bb = llfunc.appendBasicBlock("entry");
                 b.positionAtEnd(bb);
 
@@ -316,7 +326,7 @@
             case ExpType.Identifier:
                 auto identifier = cast(Identifier)exp;
                 auto sym = exp.env.find(identifier);
-                if(sym.type.isStruct)
+                if(sym.type.isStruct || sym.type.isArray)
                     return table.find(sym.id.get);
                 else
                     return b.buildLoad(table.find(sym.id.get), sym.id.get);
@@ -675,6 +685,8 @@
             foreach(param; f.params)
                 if (param.isStruct)
                     params ~= PointerType.Get(llvm(param));
+                else if (param.isArray)
+                    params ~= PointerType.Get(llvm(param));
                 else
                     params ~= llvm(param);