diff gen/toobj.c @ 55:0ccfae271c45 trunk

[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown. Updates to runtime. Rebuild!
author lindquist
date Wed, 24 Oct 2007 22:18:06 +0200
parents 28e99b04a132
children a9d29e9f1fed
line wrap: on
line diff
--- a/gen/toobj.c	Wed Oct 24 01:37:34 2007 +0200
+++ b/gen/toobj.c	Wed Oct 24 22:18:06 2007 +0200
@@ -646,8 +646,31 @@
         return;
     }
 
+    Type* t = LLVM_DtoDType(type);
+    TypeFunction* f = (TypeFunction*)t;
+
+    bool declareOnly = false;
+    if (TemplateInstance* tinst = parent->isTemplateInstance()) {
+        TemplateDeclaration* tempdecl = tinst->tempdecl;
+        if (tempdecl->llvmInternal == LLVMva_start)
+        {
+            Logger::println("magic va_start found");
+            llvmInternal = LLVMva_start;
+            declareOnly = true;
+        }
+        else if (tempdecl->llvmInternal == LLVMva_arg)
+        {
+            Logger::println("magic va_arg found");
+            llvmInternal = LLVMva_arg;
+            return;
+        }
+    }
+
     llvm::Function* func = LLVM_DtoDeclareFunction(this);
 
+    if (declareOnly)
+        return;
+
     if (!gIR->structs.empty() && gIR->topstruct().queueFuncs) {
         if (!llvmQueued) {
             Logger::println("queueing %s", toChars());
@@ -657,8 +680,6 @@
         return; // we wait with the definition as they might invoke a virtual method and the vtable is not yet complete
     }
 
-    Type* t = LLVM_DtoDType(type);
-    TypeFunction* f = (TypeFunction*)t;
     assert(f->llvmType);
     const llvm::FunctionType* functype = llvm::cast<llvm::FunctionType>(llvmValue->getType()->getContainedType(0));