comparison 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
comparison
equal deleted inserted replaced
944:eb310635d80e 945:03d7c4aac654
7 #include <cassert> 7 #include <cassert>
8 8
9 #include "gen/logger.h" 9 #include "gen/logger.h"
10 #include "gen/irstate.h" 10 #include "gen/irstate.h"
11 #include "gen/llvmhelpers.h" 11 #include "gen/llvmhelpers.h"
12 #include "gen/tollvm.h"
12 13
13 ////////////////////////////////////////////////////////////////////////////////////////// 14 //////////////////////////////////////////////////////////////////////////////////////////
14 15
15 void Statement::toNakedIR(IRState *p) 16 void Statement::toNakedIR(IRState *p)
16 { 17 {
162 gIR->module->appendModuleInlineAsm(asmstr.str()); 163 gIR->module->appendModuleInlineAsm(asmstr.str());
163 asmstr.str(""); 164 asmstr.str("");
164 165
165 gIR->functions.pop_back(); 166 gIR->functions.pop_back();
166 } 167 }
168
169 //////////////////////////////////////////////////////////////////////////////////////////
170
171 void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
172 {
173 Logger::println("emitABIReturnAsmStmt(%s)", fdecl->mangle());
174 LOG_SCOPE;
175
176 IRAsmStmt* as = new IRAsmStmt;
177
178 const LLType* llretTy = DtoType(fdecl->type->nextOf());
179 asmblock->retty = llretTy;
180 asmblock->retn = 1;
181
182 // x86
183 if (global.params.cpu == ARCHx86)
184 {
185 LINK l = fdecl->linkage;
186 assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
187
188 Type* rt = fdecl->type->nextOf()->toBasetype();
189 if (rt->isintegral() || rt->ty == Tpointer || rt->ty == Tclass || rt->ty == Taarray)
190 {
191 if (rt->size() == 8) {
192 as->out_c = "=A,";
193 } else {
194 as->out_c = "={ax},";
195 }
196 }
197 else if (rt->isfloating())
198 {
199 if (rt->iscomplex()) {
200 as->out_c = "={st},={st(1)},";
201 asmblock->retn = 2;
202 } else {
203 as->out_c = "={st},";
204 }
205 }
206 else if (rt->ty == Tarray || rt->ty == Tdelegate)
207 {
208 as->out_c = "={ax},={dx},";
209 asmblock->retn = 2;
210 }
211 else
212 {
213 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
214 fatal();
215 }
216 }
217
218 // unsupported
219 else
220 {
221 error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple);
222 fatal();
223 }
224
225 // return values always go in the front
226 asmblock->s.push_front(as);
227 }