diff gen/functions.cpp @ 131:5825d48b27d1 trunk

[svn r135] * Merged DMD 1.025 * * Fixed a minor linking order mishap * * Added an command line option -annotate * * Fixed some problems with running optimizations * * Added std.stdio and dependencies to lphobos (still not 100% working, but compiles and links) * * Fixed problems with passing aggregate types to variadic functions * * Added initial code towards full GC support, currently based on malloc and friends, not all the runtime calls the GC yet for memory * * Fixed problems with resolving nested function context pointers for some heavily nested cases * * Redid function argument passing + other minor code cleanups, still lots to do on this end... *
author lindquist
date Fri, 04 Jan 2008 01:38:42 +0100
parents 8096ba7082db
children 1700239cab2e
line wrap: on
line diff
--- a/gen/functions.cpp	Fri Dec 28 23:52:40 2007 +0100
+++ b/gen/functions.cpp	Fri Jan 04 01:38:42 2008 +0100
@@ -16,6 +16,7 @@
 #include "gen/functions.h"
 #include "gen/todebug.h"
 #include "gen/classes.h"
+#include "gen/dvalue.h"
 
 const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
 {
@@ -90,13 +91,6 @@
         Type* argT = DtoDType(arg->type);
         assert(argT);
 
-        if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
-            //assert(arg->vardecl);
-            //arg->vardecl->refparam = true;
-        }
-        else
-            arg->llvmCopy = true;
-
         const llvm::Type* at = DtoType(argT);
         if (isaStruct(at)) {
             Logger::println("struct param");
@@ -114,8 +108,8 @@
             paramvec.push_back(llvm::PointerType::get(at));
         }
         else {
-            if (!arg->llvmCopy) {
-                Logger::println("ref param");
+            if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
+                Logger::println("by ref param");
                 at = llvm::PointerType::get(at);
             }
             else {
@@ -509,8 +503,8 @@
                 if (global.params.symdebug) DtoDwarfFuncStart(fd);
 
                 llvm::Value* parentNested = NULL;
-                if (FuncDeclaration* fd2 = fd->toParent()->isFuncDeclaration()) {
-                    if (!fd->isStatic())
+                if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
+                    if (!fd->isStatic()) // huh?
                         parentNested = fd2->llvmNested;
                 }
 
@@ -722,3 +716,47 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
+
+DValue* DtoArgument(Argument* fnarg, Expression* argexp)
+{
+    Logger::println("DtoArgument");
+    LOG_SCOPE;
+
+    DValue* arg = argexp->toElem(gIR);
+
+    // ref/out arg
+    if (fnarg && ((fnarg->storageClass & STCref) || (fnarg->storageClass & STCout)))
+    {
+        if (arg->isVar() || arg->isLRValue())
+            arg = new DImValue(argexp->type, arg->getLVal(), false);
+        else
+            arg = new DImValue(argexp->type, arg->getRVal(), false);
+    }
+    // aggregate arg
+    else if (DtoIsPassedByRef(argexp->type))
+    {
+        llvm::Value* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint());
+        DVarValue* vv = new DVarValue(argexp->type, alloc, true);
+        DtoAssign(vv, arg);
+        arg = vv;
+    }
+    // normal arg (basic/value type)
+    else
+    {
+        // nothing to do
+    }
+
+    return arg;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+void DtoVariadicArgument(Expression* argexp, llvm::Value* dst)
+{
+    Logger::println("DtoVariadicArgument");
+    LOG_SCOPE;
+    DVarValue* vv = new DVarValue(argexp->type, dst, true);
+    DtoAssign(vv, argexp->toElem(gIR));
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////