comparison gen/naked.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 7e669954db7d
children c749648ed2b8
comparison
equal deleted inserted replaced
987:73ff89728d85 988:2667e3a145be
216 asmblock->retn = 2; 216 asmblock->retn = 2;
217 #if 0 217 #if 0
218 // this is to show how to allocate a temporary for the return value 218 // this is to show how to allocate a temporary for the return value
219 // in case the appropriate multi register constraint isn't supported. 219 // in case the appropriate multi register constraint isn't supported.
220 // this way abi return from inline asm can still be emulated. 220 // this way abi return from inline asm can still be emulated.
221 // note that "$<<out0>>" etc in the asm will translate to the correct
222 // numbered output when the asm block in finalized
221 223
222 // generate asm 224 // generate asm
223 as->out_c = "=*m,=*m,"; 225 as->out_c = "=*m,=*m,";
224 LLValue* tmp = DtoAlloca(llretTy, ".tmp_asm_ret"); 226 LLValue* tmp = DtoAlloca(llretTy, ".tmp_asm_ret");
225 as->out.push_back( tmp ); 227 as->out.push_back( tmp );
229 // fix asmblock 231 // fix asmblock
230 asmblock->retn = 0; 232 asmblock->retn = 0;
231 asmblock->retemu = true; 233 asmblock->retemu = true;
232 asmblock->asmBlock->abiret = tmp; 234 asmblock->asmBlock->abiret = tmp;
233 235
234 // add "ret" stmt 236 // add "ret" stmt at the end of the block
235 asmblock->s.push_back(as); 237 asmblock->s.push_back(as);
236 238
237 // done, we don't want anything pushed in the front of the block 239 // done, we don't want anything pushed in the front of the block
238 return; 240 return;
239 #endif 241 #endif
274 as->out_c = "={st},"; 276 as->out_c = "={st},";
275 } else if (l != LINKd && rt == Type::tcomplex32) { 277 } else if (l != LINKd && rt == Type::tcomplex32) {
276 // LLVM and GCC disagree on how to return {float, float}. 278 // LLVM and GCC disagree on how to return {float, float}.
277 // For compatibility, use the GCC/LLVM-GCC way for extern(C/Windows) 279 // For compatibility, use the GCC/LLVM-GCC way for extern(C/Windows)
278 // extern(C) cfloat -> %xmm0 (extract two floats) 280 // extern(C) cfloat -> %xmm0 (extract two floats)
279 #if 0
280 // Disabled because "regular" extern(C) functions aren't
281 // ABI-compatible with GCC yet.
282 // TODO: enable when "extern(C) cfloat foo();" compiles to "declare { double } @foo();"
283 as->out_c = "={xmm0},"; 281 as->out_c = "={xmm0},";
284 asmblock->retty = LLStructType::get(LLType::DoubleTy, NULL);; 282 asmblock->retty = LLStructType::get(LLType::DoubleTy, NULL);;
285 asmblock->retfixup = &x86_64_cfloatRetFixup; 283 asmblock->retfixup = &x86_64_cfloatRetFixup;
286 #else
287 error(loc, "unimplemented return type '%s' for implicit abi return", rt->toChars());
288 fatal();
289 #endif
290 } else if (rt->iscomplex()) { 284 } else if (rt->iscomplex()) {
291 // cdouble and extern(D) cfloat -> re=%xmm0, im=%xmm1 285 // cdouble and extern(D) cfloat -> re=%xmm0, im=%xmm1
292 as->out_c = "={xmm0},={xmm1},"; 286 as->out_c = "={xmm0},={xmm1},";
293 asmblock->retn = 2; 287 asmblock->retn = 2;
294 } else { 288 } else {