annotate gen/tocall.cpp @ 1149:5ebe8224988b

Fixed problems introduced by previous commits that prevented Tango from compiling.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 23:17:04 +0100
parents 4c20fcc4252b
children a668f4051368
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
2
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
3 #include "mtype.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
4 #include "declaration.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
5
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
6 #include "gen/tollvm.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
7 #include "gen/llvmhelpers.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
8 #include "gen/irstate.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
9 #include "gen/dvalue.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
10 #include "gen/functions.h"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 950
diff changeset
11 #include "gen/abi.h"
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
12
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
14
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
15 //////////////////////////////////////////////////////////////////////////////////////////
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
16
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
17 TypeFunction* DtoTypeFunction(DValue* fnval)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
18 {
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
19 Type* type = fnval->getType()->toBasetype();
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
20 if (type->ty == Tfunction)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
21 {
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
22 return (TypeFunction*)type;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
23 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
24 else if (type->ty == Tdelegate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
25 {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
26 Type* next = type->nextOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
27 assert(next->ty == Tfunction);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
28 return (TypeFunction*)next;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
29 }
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
30
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
31 assert(0 && "cant get TypeFunction* from non lazy/function/delegate");
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
32 return 0;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
33 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
34
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
35 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
36
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
37 unsigned DtoCallingConv(Loc loc, LINK l)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
38 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
39 if (l == LINKc || l == LINKcpp || l == LINKintrinsic)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
40 return llvm::CallingConv::C;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
41 else if (l == LINKd || l == LINKdefault)
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
42 {
782
29f0e5847123 Don't use StdCall on Windows.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
43 //TODO: StdCall is not a good base on Windows due to extra name mangling
29f0e5847123 Don't use StdCall on Windows.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
44 // applied there
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
45 if (global.params.cpu == ARCHx86)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
46 return (global.params.os != OSWindows) ? llvm::CallingConv::X86_StdCall : llvm::CallingConv::C;
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
47 else
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
48 return llvm::CallingConv::Fast;
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
49 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 787
diff changeset
50 // on the other hand, here, it's exactly what we want!!! TODO: right?
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
51 else if (l == LINKwindows)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
52 return llvm::CallingConv::X86_StdCall;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
53 else
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
54 {
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
55 error(loc, "unsupported calling convention");
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
56 fatal();
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
57 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
58 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
59
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
60 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
61
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
62 DValue* DtoVaArg(Loc& loc, Type* type, Expression* valistArg)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
63 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
64 DValue* expelem = valistArg->toElem(gIR);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
65 const LLType* llt = DtoType(type);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
66 if (DtoIsPassedByRef(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
67 llt = getPtrToType(llt);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
68 // issue a warning for broken va_arg instruction.
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
69 if (global.params.cpu != ARCHx86)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
70 warning("%s: va_arg for C variadic functions is probably broken for anything but x86", loc.toChars());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
71 // done
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
72 return new DImValue(type, gIR->ir->CreateVAArg(expelem->getLVal(), llt, "tmp"));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
73 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
74
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
75 //////////////////////////////////////////////////////////////////////////////////////////
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
76
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
77 LLValue* DtoCallableValue(DValue* fn)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
78 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
79 Type* type = fn->getType()->toBasetype();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
80 if (type->ty == Tfunction)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
81 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
82 return fn->getRVal();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
83 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
84 else if (type->ty == Tdelegate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
85 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
86 if (fn->isLVal())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
87 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
88 LLValue* dg = fn->getLVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
89 LLValue* funcptr = DtoGEPi(dg, 0, 1);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
90 return DtoLoad(funcptr);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
91 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
92 else
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
93 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
94 LLValue* dg = fn->getRVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
95 assert(isaStruct(dg));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
96 return gIR->ir->CreateExtractValue(dg, 1, ".funcptr");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
97 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
98 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
99 else
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
100 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
101 assert(0 && "not a callable type");
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
102 return NULL;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
103 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
104 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
105
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
106 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
107
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
108 const LLFunctionType* DtoExtractFunctionType(const LLType* type)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
109 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
110 if (const LLFunctionType* fty = isaFunction(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
111 return fty;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
112 else if (const LLPointerType* pty = isaPointer(type))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
113 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
114 if (const LLFunctionType* fty = isaFunction(pty->getElementType()))
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
115 return fty;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
116 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
117 return NULL;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
118 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
119
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
120 //////////////////////////////////////////////////////////////////////////////////////////
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
121
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
122 void DtoBuildDVarArgList(std::vector<LLValue*>& args, std::vector<llvm::AttributeWithIndex>& attrs, TypeFunction* tf, Expressions* arguments, size_t argidx)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
123 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
124 Logger::println("doing d-style variadic arguments");
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
125
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
126 std::vector<const LLType*> vtypes;
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
127
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
128 // number of non variadic args
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
129 int begin = tf->parameters->dim;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
130 Logger::println("num non vararg params = %d", begin);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
131
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
132 // get n args in arguments list
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
133 size_t n_arguments = arguments ? arguments->dim : 0;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
134
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
135 // build struct with argument types (non variadic args)
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
136 for (int i=begin; i<n_arguments; i++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
137 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
138 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
139 vtypes.push_back(DtoType(argexp->type));
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
140 size_t sz = getTypePaddedSize(vtypes.back());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
141 if (sz < PTRSIZE)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
142 vtypes.back() = DtoSize_t();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
143 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
144 const LLStructType* vtype = LLStructType::get(vtypes);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
145
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
146 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
147 Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
148
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 456
diff changeset
149 LLValue* mem = DtoAlloca(vtype,"_argptr_storage");
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
150
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
151 // store arguments in the struct
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
152 for (int i=begin,k=0; i<n_arguments; i++,k++)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
153 {
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
154 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
155 if (global.params.llvmAnnotate)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
156 DtoAnnotation(argexp->toChars());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
157 LLValue* argdst = DtoGEPi(mem,0,k);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
158 argdst = DtoBitCast(argdst, getPtrToType(DtoType(argexp->type)));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
159 DtoVariadicArgument(argexp, argdst);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
160 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
161
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
162 // build type info array
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
163 const LLType* typeinfotype = DtoType(Type::typeinfo->type);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
164 const LLArrayType* typeinfoarraytype = LLArrayType::get(typeinfotype,vtype->getNumElements());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
165
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
166 llvm::GlobalVariable* typeinfomem =
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
167 new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
168 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
169 Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
170
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
171 std::vector<LLConstant*> vtypeinfos;
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
172 for (int i=begin,k=0; i<n_arguments; i++,k++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
173 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
174 Expression* argexp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
175 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type));
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
176 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
177
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
178 // apply initializer
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
179 LLConstant* tiinits = llvm::ConstantArray::get(typeinfoarraytype, vtypeinfos);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
180 typeinfomem->setInitializer(tiinits);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
181
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
182 // put data in d-array
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
183 std::vector<LLConstant*> pinits;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
184 pinits.push_back(DtoConstSize_t(vtype->getNumElements()));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
185 pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype)));
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
186 const LLType* tiarrty = DtoType(Type::typeinfo->type->arrayOf());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
187 tiinits = llvm::ConstantStruct::get(pinits);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
188 LLValue* typeinfoarrayparam = new llvm::GlobalVariable(tiarrty,
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
189 true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array", gIR->module);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
190
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
191 llvm::AttributeWithIndex Attr;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
192 // specify arguments
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
193 args.push_back(DtoLoad(typeinfoarrayparam));
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
194 if (unsigned atts = tf->fty.arg_arguments->attrs) {
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
195 Attr.Index = argidx;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
196 Attr.Attrs = atts;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
197 attrs.push_back(Attr);
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
198 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
199 ++argidx;
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
200
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
201 args.push_back(gIR->ir->CreateBitCast(mem, getPtrToType(LLType::Int8Ty), "tmp"));
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
202 if (unsigned atts = tf->fty.arg_argptr->attrs) {
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
203 Attr.Index = argidx;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
204 Attr.Attrs = atts;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
205 attrs.push_back(Attr);
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
206 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
207 ++argidx;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
208
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
209 // pass non variadic args
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
210 for (int i=0; i<begin; i++)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
211 {
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
212 Argument* fnarg = Argument::getNth(tf->parameters, i);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
213 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
214 args.push_back(argval->getRVal());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
215
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
216 if (tf->fty.args[i]->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
217 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
218 llvm::AttributeWithIndex Attr;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
219 Attr.Index = argidx;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
220 Attr.Attrs = tf->fty.args[i]->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
221 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
222 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
223
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
224 ++argidx;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
225 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
226 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
227
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
228 // FIXME: this function is a mess !
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
229
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
230 DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* arguments)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
231 {
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
232 if (Logger::enabled()) {
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
233 Logger::println("DtoCallFunction()");
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
234 }
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
235 LOG_SCOPE
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
236
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
237 // the callee D type
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
238 Type* calleeType = fnval->getType();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
239
456
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
240 // if the type has not yet been processed, do so now
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
241 if (calleeType->ir.type == NULL)
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
242 DtoType(calleeType);
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
243
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
244 // get func value if any
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
245 DFuncValue* dfnval = fnval->isFunc();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
246
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
247 // handle special vararg intrinsics
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
248 bool va_intrinsic = (dfnval && dfnval->func && dfnval->func->isVaIntrinsic());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
249
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
250 // get function type info
435
74101be2a553 Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 422
diff changeset
251 TypeFunction* tf = DtoTypeFunction(fnval);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
252
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
253 // misc
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
254 bool retinptr = tf->fty.arg_sret;
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
255 bool thiscall = tf->fty.arg_this;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
256 bool delegatecall = (calleeType->toBasetype()->ty == Tdelegate);
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
257 bool nestedcall = tf->fty.arg_nest;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
258 bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
259
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
260 unsigned callconv = DtoCallingConv(loc, tf->linkage);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
261
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
262 // get callee llvm value
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
263 LLValue* callable = DtoCallableValue(fnval);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
264 const LLFunctionType* callableTy = DtoExtractFunctionType(callable->getType());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
265 assert(callableTy);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
266
839
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 805
diff changeset
267 // if (Logger::enabled())
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 805
diff changeset
268 // Logger::cout() << "callable: " << *callable << '\n';
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
269
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
270 // get n arguments
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
271 size_t n_arguments = arguments ? arguments->dim : 0;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
272
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
273 // get llvm argument iterator, for types
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
274 LLFunctionType::param_iterator argbegin = callableTy->param_begin();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
275 LLFunctionType::param_iterator argiter = argbegin;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
276
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
277 // parameter attributes
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
278 std::vector<llvm::AttributeWithIndex> attrs;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
279 llvm::AttributeWithIndex Attr;
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
280
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
281 // return attrs
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
282 if (tf->fty.ret->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
283 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
284 Attr.Index = 0;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
285 Attr.Attrs = tf->fty.ret->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
286 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
287 }
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
288
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
289 // handle implicit arguments
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
290 std::vector<LLValue*> args;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
291 args.reserve(tf->fty.args.size());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
292
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
293 // return in hidden ptr is first
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
294 if (retinptr)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
295 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 456
diff changeset
296 LLValue* retvar = DtoAlloca(argiter->get()->getContainedType(0), ".rettmp");
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
297 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
298 args.push_back(retvar);
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
299
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
300 // add attrs for hidden ptr
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
301 Attr.Index = 1;
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
302 Attr.Attrs = tf->fty.arg_sret->attrs;
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
303 assert((Attr.Attrs & llvm::Attribute::StructRet) && "Sret arg not sret?");
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
304 attrs.push_back(Attr);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
305 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
306
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
307 // then comes a context argument...
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
308 if(thiscall || delegatecall || nestedcall)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
309 {
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
310 // ... which can be a 'this' argument
488
993b217af574 Error if there is no this in a call requiring this.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
311 if (thiscall && dfnval && dfnval->vthis)
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
312 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
313 LLValue* thisarg = DtoBitCast(dfnval->vthis, argiter->get());
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
314 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
315 args.push_back(thisarg);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
316 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
317 // ... or a delegate context arg
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
318 else if (delegatecall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
319 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
320 LLValue* ctxarg;
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
321 if (fnval->isLVal())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
322 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
323 ctxarg = DtoLoad(DtoGEPi(fnval->getLVal(), 0,0));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
324 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
325 else
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
326 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
327 ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
328 }
1149
5ebe8224988b Fixed problems introduced by previous commits that prevented Tango from compiling.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1117
diff changeset
329 ctxarg = DtoBitCast(ctxarg, argiter->get());
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
330 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
331 args.push_back(ctxarg);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
332 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
333 // ... or a nested function context arg
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
334 else if (nestedcall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
335 {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
336 LLValue* contextptr = DtoNestedContext(loc, dfnval->func);
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
337 contextptr = DtoBitCast(contextptr, getVoidPtrType());
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
338 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
339 args.push_back(contextptr);
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
340 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
341 else
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
342 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
343 error(loc, "Context argument required but none given");
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
344 fatal();
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
345 }
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
346
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
347 // add attributes for context argument
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
348 if (tf->fty.arg_this && tf->fty.arg_this->attrs)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
349 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
350 Attr.Index = retinptr ? 2 : 1;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
351 Attr.Attrs = tf->fty.arg_this->attrs;
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
352 attrs.push_back(Attr);
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
353 }
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
354 else if (tf->fty.arg_nest && tf->fty.arg_nest->attrs)
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
355 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
356 Attr.Index = retinptr ? 2 : 1;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
357 Attr.Attrs = tf->fty.arg_nest->attrs;
1117
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
358 // For delegates, we can't assume 'nest' is noalias and nocapture
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
359 // (like we can with nested functions) since it might actually be
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
360 // a 'this', and thus neither attribute generally applies to it.
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
361 // TODO: don't remove nocapture if it's a "pure" delegate?
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
362 if (delegatecall) {
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
363 Attr.Attrs &= ~(llvm::Attribute::NoAlias | llvm::Attribute::NoCapture);
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
364 }
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
365 // LLVM doesn't like it when no bits are set...
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
366 if (Attr.Attrs)
4c20fcc4252b Fun with parameter attributes: For several of the "synthetic" parameters added
Frits van Bommel <fvbommel wxs.nl>
parents: 1051
diff changeset
367 attrs.push_back(Attr);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
368 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
369 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
370
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
371 // handle the rest of the arguments based on param passing style
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
372
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
373 // variadic instrinsics need some custom casts
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
374 if (va_intrinsic)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
375 {
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 526
diff changeset
376 for (int i=0; i<n_arguments; i++)
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
377 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
378 Expression* exp = (Expression*)arguments->data[i];
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
379 DValue* expelem = exp->toElem(gIR);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
380 // cast to va_list*
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
381 LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType());
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
382 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
383 args.push_back(val);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
384 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
385 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
386
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
387 // d style varargs needs a few more hidden arguments as well as special passing
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
388 else if (dvarargs)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
389 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
390 DtoBuildDVarArgList(args, attrs, tf, arguments, argiter-argbegin+1);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
391 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
392
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
393 // otherwise we're looking at a normal function call
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
394 // or a C style vararg call
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
395 else
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
396 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
397 Logger::println("doing normal arguments");
1050
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
398 if (Logger::enabled()) {
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
399 Logger::println("Arguments so far: (%d)", (int)args.size());
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
400 Logger::indent();
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
401 for (size_t i = 0; i < args.size(); i++) {
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
402 Logger::cout() << *args[i] << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
403 }
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
404 Logger::undent();
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
405 Logger::cout() << "Function type: " << tf->toChars() << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
406 Logger::cout() << "LLVM functype: " << *callable->getType() << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
407 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
408
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
409 size_t n = Argument::dim(tf->parameters);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
410
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
411 LLSmallVector<unsigned, 10> attrptr(n, 0);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
412
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
413 // do formal params
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
414 int beg = argiter-argbegin;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
415 for (int i=0; i<n; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
416 {
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
417 Argument* fnarg = Argument::getNth(tf->parameters, i);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
418 assert(fnarg);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
419 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1030
diff changeset
420
1050
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
421 if (Logger::enabled()) {
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
422 Logger::cout() << "Argument before ABI: " << *argval->getRVal() << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
423 Logger::cout() << "Argument type before ABI: " << *DtoType(argval->getType()) << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
424 }
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
425
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1030
diff changeset
426 // give the ABI a say
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
427 LLValue* arg = tf->fty.putParam(argval->getType(), i, argval);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
428
1050
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
429 if (Logger::enabled()) {
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
430 Logger::cout() << "Argument after ABI: " << *arg << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
431 Logger::cout() << "Argument type after ABI: " << *arg->getType() << '\n';
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
432 }
32ead42679d1 Fix a bug in the X86 ABI. The size of a struct is different from the size of a
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
433
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
434 int j = tf->fty.reverseParams ? beg + n - i - 1 : beg + i;
938
a904cc9bc064 Convert struct arg to integer when passing inreg to make sure LLVM doesn't
Christian Kamm <kamm incasoftware de>
parents: 930
diff changeset
435
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
436 // Hack around LDC assuming structs are in memory:
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
437 // If the function wants a struct, and the argument value is a
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
438 // pointer to a struct, load from it before passing it in.
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
439 if (argval->getType()->ty == Tstruct
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
440 && isaPointer(arg) && !isaPointer(callableTy->getParamType(j))) {
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
441 Logger::println("Loading struct type for function argument");
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
442 arg = DtoLoad(arg);
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
443 }
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
444
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
445 // parameter type mismatch, this is hard to get rid of
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
446 if (arg->getType() != callableTy->getParamType(j))
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
447 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
448 #if 1
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
449 if (Logger::enabled())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
450 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
451 Logger::cout() << "arg: " << *arg << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
452 Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
453 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
454 #endif
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
455 arg = DtoBitCast(arg, callableTy->getParamType(j));
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
456 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
457
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
458 // param attrs
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
459 attrptr[i] = tf->fty.args[i]->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
460
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
461 ++argiter;
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
462 args.push_back(arg);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
463 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
464
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
465 // reverse the relevant params as well as the param attrs
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
466 if (tf->fty.reverseParams)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
467 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
468 std::reverse(args.begin() + beg, args.end());
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
469 std::reverse(attrptr.begin(), attrptr.end());
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
470 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
471
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
472 // add attributes
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
473 for (int i = 0; i < n; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
474 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
475 if (attrptr[i])
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
476 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
477 Attr.Index = beg + i + 1;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
478 Attr.Attrs = attrptr[i];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
479 attrs.push_back(Attr);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
480 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
481 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
482
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
483 // do C varargs
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
484 if (n_arguments > n)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
485 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
486 for (int i=n; i<n_arguments; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
487 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
488 Argument* fnarg = Argument::getNth(tf->parameters, i);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
489 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
490 LLValue* arg = argval->getRVal();
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
491
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
492 // FIXME: do we need any param attrs here ?
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
493
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
494 ++argiter;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
495 args.push_back(arg);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
496 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
497 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
498 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
499
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
500 #if 0
805
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
501 if (Logger::enabled())
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
502 {
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
503 Logger::println("%lu params passed", args.size());
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
504 for (int i=0; i<args.size(); ++i) {
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
505 assert(args[i]);
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
506 Logger::cout() << "arg["<<i<<"] = " << *args[i] << '\n';
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
507 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
508 }
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
509 #endif
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
510
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
511 // void returns cannot not be named
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
512 const char* varname = "";
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
513 if (callableTy->getReturnType() != LLType::VoidTy)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
514 varname = "tmp";
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
515
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
516 #if 0
805
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
517 if (Logger::enabled())
1b23aa1fb1b5 Ensure all logging of llvm values/types is only called when -vv is passed
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 797
diff changeset
518 Logger::cout() << "Calling: " << *callable << '\n';
1030
3ead5c40b7d6 Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
519 #endif
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
520
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
521 // call the function
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
522 LLCallSite call = gIR->CreateCallOrInvoke(callable, args.begin(), args.end(), varname);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
523
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
524 // get return value
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
525 LLValue* retllval = (retinptr) ? args[0] : call.getInstruction();
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
526
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
527 // Ignore ABI for intrinsics
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
528 if (tf->linkage != LINKintrinsic && !retinptr)
1001
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
529 {
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
530 // do abi specific return value fixups
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1030
diff changeset
531 DImValue dretval(tf->next, retllval);
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1050
diff changeset
532 retllval = tf->fty.getRet(tf->next, &dretval);
1001
7a0238db1962 Implement support for intrinsics returning struct types
Frits van Bommel <fvbommel wxs.nl>
parents: 988
diff changeset
533 }
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
534
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
535 // Hack around LDC assuming structs are in memory:
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
536 // If the function returns a struct, and the return value is not a
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
537 // pointer to a struct, store it to a stack slot before continuing.
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
538 if (tf->next->ty == Tstruct && !isaPointer(retllval)) {
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
539 Logger::println("Storing return value to stack slot");
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
540 LLValue* mem = DtoAlloca(retllval->getType());
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
541 DtoStore(retllval, mem);
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
542 retllval = mem;
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
543 }
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1042
diff changeset
544
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
545 // repaint the type if necessary
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
546 if (resulttype)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
547 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
548 Type* rbase = resulttype->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
549 Type* nextbase = tf->nextOf()->toBasetype();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
550 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
551 rbase = rbase->mutableOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
552 nextbase = nextbase->mutableOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
553 #endif
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
554 if (!rbase->equals(nextbase))
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
555 {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 723
diff changeset
556 Logger::println("repainting return value from '%s' to '%s'", tf->nextOf()->toChars(), rbase->toChars());
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
557 switch(rbase->ty)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
558 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
559 case Tarray:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
560 retllval = DtoAggrPaint(retllval, DtoType(rbase));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
561 break;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
562
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
563 case Tclass:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
564 case Taarray:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
565 case Tpointer:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
566 retllval = DtoBitCast(retllval, DtoType(rbase));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
567 break;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
568
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
569 default:
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
570 assert(0 && "unhandled repainting of return value");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
571 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
572 if (Logger::enabled())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
573 Logger::cout() << "final return value: " << *retllval << '\n';
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
574 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
575 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
576
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
577 // set calling convention and parameter attributes
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
578 llvm::AttrListPtr attrlist = llvm::AttrListPtr::get(attrs.begin(), attrs.end());
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
579 if (dfnval && dfnval->func)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
580 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
581 LLFunction* llfunc = llvm::dyn_cast<LLFunction>(dfnval->val);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
582 if (llfunc && llfunc->isIntrinsic()) // override intrinsic attrs
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
583 attrlist = llvm::Intrinsic::getAttributes((llvm::Intrinsic::ID)llfunc->getIntrinsicID());
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
584 else
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
585 call.setCallingConv(callconv);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
586 }
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 347
diff changeset
587 else
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
588 call.setCallingConv(callconv);
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1001
diff changeset
589 call.setAttributes(attrlist);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
590
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
591 // if we are returning through a pointer arg
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
592 // make sure we provide a lvalue back!
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
593 if (retinptr)
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
594 return new DVarValue(resulttype, retllval);
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
595
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
596 return new DImValue(resulttype, retllval);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
597 }