diff gen/naked.cpp @ 945:03d7c4aac654

SWITCHED TO LLVM 2.5 ! Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel. Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple. Fixed return calling convention for complex numbers, ST and ST(1) were switched around. Added some testcases. I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 08 Feb 2009 05:26:54 +0100
parents 9bab304ed531
children b2d27ddf8f45
line wrap: on
line diff
--- a/gen/naked.cpp	Sun Feb 08 05:14:24 2009 +0100
+++ b/gen/naked.cpp	Sun Feb 08 05:26:54 2009 +0100
@@ -9,6 +9,7 @@
 #include "gen/logger.h"
 #include "gen/irstate.h"
 #include "gen/llvmhelpers.h"
+#include "gen/tollvm.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
@@ -164,3 +165,63 @@
 
     gIR->functions.pop_back();
 }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
+{
+    Logger::println("emitABIReturnAsmStmt(%s)", fdecl->mangle());
+    LOG_SCOPE;
+
+    IRAsmStmt* as = new IRAsmStmt;
+
+    const LLType* llretTy = DtoType(fdecl->type->nextOf());
+    asmblock->retty = llretTy;
+    asmblock->retn = 1;
+
+    // x86
+    if (global.params.cpu == ARCHx86)
+    {
+        LINK l = fdecl->linkage;
+        assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
+
+        Type* rt = fdecl->type->nextOf()->toBasetype();
+        if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
+        {
+            if (rt->size() == 8) {
+                as->out_c = "=A,";
+            } else {
+                as->out_c = "={ax},";
+            }
+        }
+        else if (rt->isfloating())
+        {
+            if (rt->iscomplex()) {
+                as->out_c = "={st},={st(1)},";
+                asmblock->retn = 2;
+            } else {
+                as->out_c = "={st},";
+            }
+        }
+        else if (rt->ty == Tarray || rt->ty == Tdelegate)
+        {
+            as->out_c = "={ax},={dx},";
+            asmblock->retn = 2;
+        }
+        else
+        {
+            error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
+            fatal();
+        }
+    }
+
+    // unsupported
+    else
+    {
+        error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple);
+        fatal();
+    }
+
+    // return values always go in the front
+    asmblock->s.push_front(as);
+}