diff gen/functions.cpp @ 988:2667e3a145be

- Fixed LLVM style CL args for D2. - Moved main() into its own file gen/main.cpp - Fixed basic cross compilation - removed the option for setting OS - added support for llc's mattr, mcpu and mtriple switches - added basic ABI abstraction for return value rewrites, it's not perfect and will probably be completely rewritten once I get to handling parameter rewrites as well. - x86-64 extern(C) abi for cfloat returns now match (llvm-)gcc.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Thu, 26 Feb 2009 14:11:49 +0100
parents 89729c76b8ff
children 7a0238db1962
line wrap: on
line diff
--- a/gen/functions.cpp	Wed Feb 25 19:30:06 2009 +0100
+++ b/gen/functions.cpp	Thu Feb 26 14:11:49 2009 +0100
@@ -20,6 +20,7 @@
 #include "gen/todebug.h"
 #include "gen/classes.h"
 #include "gen/dvalue.h"
+#include "gen/abi.h"
 
 #include <algorithm>
 
@@ -53,40 +54,49 @@
     // parameter types
     std::vector<const LLType*> paramvec;
 
+    // special case main
     if (ismain)
     {
         rettype = LLType::Int32Ty;
         actualRettype = rettype;
         if (Argument::dim(f->parameters) == 0)
         {
-        const LLType* arrTy = DtoArrayType(LLType::Int8Ty);
-        const LLType* arrArrTy = DtoArrayType(arrTy);
-        paramvec.push_back(arrArrTy);
+            const LLType* arrTy = DtoArrayType(LLType::Int8Ty);
+            const LLType* arrArrTy = DtoArrayType(arrTy);
+            paramvec.push_back(arrArrTy);
         }
     }
-    else{
+    // default handling
+    else
+    {
         assert(rt);
-        if (DtoIsReturnedInArg(rt)) {
+        if (gABI->returnInArg(rt))
+        {
             rettype = getPtrToType(DtoType(rt));
             actualRettype = LLType::VoidTy;
             f->retInPtr = retinptr = true;
         }
-        else {
+        else
+        {
             rettype = DtoType(rt);
-            actualRettype = rettype;
+            // do abi specific transformations
+            actualRettype = gABI->getRetType(f, rettype);
         }
 
+        // FIXME: should probably be part of the abi
         if (unsigned ea = DtoShouldExtend(rt))
         {
             f->retAttrs |= ea;
         }
     }
 
+    // build up parameter list
     if (retinptr) {
         //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n';
         paramvec.push_back(rettype);
     }
 
+    // this/context param
     if (thistype) {
         paramvec.push_back(thistype);
         usesthis = true;
@@ -96,6 +106,7 @@
         usesnest = true;
     }
 
+    // dstyle vararg
     if (dVararg) {
         paramvec.push_back(DtoType(Type::typeinfo->type->arrayOf())); // _arguments
         paramvec.push_back(getVoidPtrType()); // _argptr