annotate gen/tocall.cpp @ 526:642f6fa854e5

First step towards D abi compliance. Framepointer elimination is now disabled for functions using inline asm (with a hack from aKor).
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 19 Aug 2008 20:18:01 +0200
parents 993b217af574
children d30c40f1128d
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"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
11
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
12 #include "gen/logger.h"
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
13
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
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
16 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
17 {
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
18 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
19 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
20 {
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
21 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
22 }
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 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
24 {
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 assert(type->next->ty == Tfunction);
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
26 return (TypeFunction*)type->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
27 }
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
28
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
29 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
30 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
31 }
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
32
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 unsigned DtoCallingConv(LINK l)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
36 {
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
37 if (l == LINKc || l == LINKcpp)
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
38 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
39 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
40 {
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
41 if (global.params.cpu == ARCHx86)
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
42 return llvm::CallingConv::X86_StdCall;
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
43 else
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
44 return llvm::CallingConv::Fast;
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 488
diff changeset
45 }
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
46 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
47 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
48 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
49 assert(0 && "Unsupported calling convention");
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
50 }
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
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 //////////////////////////////////////////////////////////////////////////////////////////
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
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
54 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
55 {
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
56 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
57 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
58 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
59 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
60 // 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
61 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
62 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
63 // 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
64 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
65 }
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
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 //////////////////////////////////////////////////////////////////////////////////////////
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
68
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
69 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
70 {
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 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
72 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
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 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
75 }
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
76 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
77 {
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 LLValue* dg = fn->getRVal();
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
79 Logger::cout() << "delegate: " << *dg << '\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
80 LLValue* funcptr = DtoGEPi(dg, 0, 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
81 return DtoLoad(funcptr);
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 }
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 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
84 {
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 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
86 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
87 }
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
88 }
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
89
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
90 //////////////////////////////////////////////////////////////////////////////////////////
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
91
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
92 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
93 {
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
94 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
95 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
96 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
97 {
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 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
99 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
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 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
102 }
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 void DtoBuildDVarArgList(std::vector<LLValue*>& args, llvm::PAListPtr& palist, TypeFunction* tf, Expressions* arguments, size_t 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
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 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
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 std::vector<const LLType*> vtypes;
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
111
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
112 // 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
113 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
114 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
115
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 // build struct with argument types (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
117 for (int i=begin; i<arguments->dim; 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
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 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
120 vtypes.push_back(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
121 size_t sz = getABITypeSize(vtypes.back());
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
122 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
123 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
124 }
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 const LLStructType* vtype = LLStructType::get(vtypes);
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 Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n';
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
127 LLValue* mem = DtoAlloca(vtype,"_argptr_storage");
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
128
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
129 // store arguments in the struct
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 for (int i=begin,k=0; i<arguments->dim; i++,k++)
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
131 {
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
132 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
133 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
134 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
135 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
136 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
137 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
138 }
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
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
140 // 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
141 assert(Type::typeinfo->ir.irStruct->constInit);
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 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
143 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
144
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
145 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
146 new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", 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
147 Logger::cout() << "_arguments storage: " << *typeinfomem << '\n';
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
148
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
149 std::vector<LLConstant*> 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
150 for (int i=begin,k=0; i<arguments->dim; i++,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
151 {
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
152 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
153 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type));
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
154 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
155
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
156 // 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
157 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
158 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
159
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 // 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168
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
169 // specify 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
170 args.push_back(typeinfoarrayparam);
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 ++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
172 args.push_back(gIR->ir->CreateBitCast(mem, getPtrToType(LLType::Int8Ty), "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
173 ++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
174
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 // 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
176 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
177 {
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
178 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
179 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
180 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
181
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
182 if (fnarg->llvmAttrs)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
183 palist = palist.addAttr(argidx, fnarg->llvmAttrs);
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
184
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 ++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
186 }
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 }
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
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
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
190 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
191 {
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 // 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
193 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
194
456
b975f29b7256 Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents: 454
diff changeset
195 // 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
196 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
197 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
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 // 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
200 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
201
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
202 // 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
203 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
204
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
205 // 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
206 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
207
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 // misc
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
209 bool retinptr = tf->retInPtr;
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
210 bool thiscall = tf->usesThis;
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
211 bool delegatecall = (calleeType->toBasetype()->ty == Tdelegate);
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
212 bool nestedcall = tf->usesNest;
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 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
214
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 unsigned callconv = DtoCallingConv(tf->linkage);
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
216
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
217 // 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
218 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
219 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
220 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
221
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
222 // 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
223 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
224 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
225
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
226 // parameter attributes
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
227 llvm::PAListPtr palist;
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
228
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
229 // return attrs
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
230 if (tf->retAttrs)
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
231 palist = palist.addAttr(0, tf->retAttrs);
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
232
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
233 // 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
234 std::vector<LLValue*> 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
235
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
236 // 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
237 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
238 {
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
239 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
240 ++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
241 args.push_back(retvar);
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
242 palist = palist.addAttr(1, llvm::ParamAttr::StructRet);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
243 }
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
244
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
245 // 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
246 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
247 {
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
248 // ... 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
249 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
250 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
251 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
252 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
253 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
254 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
255 // ... 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
256 else if (delegatecall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
257 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
258 LLValue* ctxarg = DtoLoad(DtoGEPi(fnval->getRVal(), 0,0));
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
259 assert(ctxarg->getType() == argiter->get());
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
260 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
261 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
262 }
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
263 // ... 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
264 else if (nestedcall)
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
265 {
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
266 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
267 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
268 ++argiter;
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
269 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
270 }
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
271 else
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
272 {
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
273 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
274 fatal();
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
275 }
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
276 }
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
277
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
278 // 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
279
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
280 // 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
281 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
282 {
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
283 size_t n = arguments->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
284 for (int i=0; i<n; 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
285 {
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
286 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
287 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
288 // 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
289 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
290 ++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
291 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
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 }
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
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 // 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
296 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
297 {
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 DtoBuildDVarArgList(args, palist, tf, arguments, argiter-argbegin+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
299 }
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
300
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
301 // otherwise we're looking at a normal function call
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
302 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
303 {
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
304 Logger::println("doing normal 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
305 for (int i=0; i<arguments->dim; 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
306 int j = 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
307 Argument* fnarg = Argument::getNth(tf->parameters, 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
308 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
309 LLValue* arg = argval->getRVal();
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
310 if (fnarg) // can fnarg ever be null in this block?
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
311 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
312 if (arg->getType() != callableTy->getParamType(j))
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
313 arg = DtoBitCast(arg, callableTy->getParamType(j));
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
314 if (fnarg->llvmAttrs)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
315 palist = palist.addAttr(j+1, fnarg->llvmAttrs);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
316 }
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
317 ++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
318 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
319 }
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
320 }
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
321
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
322 #if 0
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
323 Logger::println("%d params passed", n);
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
324 for (int i=0; i<args.size(); ++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
325 assert(args[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
326 Logger::cout() << "arg["<<i<<"] = " << *args[i] << '\n';
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
327 }
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
328 #endif
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
329
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
330 // 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
331 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
332 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
333 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
334
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
335 //Logger::cout() << "Calling: " << *funcval << '\n';
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
336
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
337 // call the function
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
338 CallOrInvoke* call = gIR->CreateCallOrInvoke(callable, args.begin(), args.end(), 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
339
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
340 // get return 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
341 LLValue* retllval = (retinptr) ? args[0] : call->get();
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
342
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
343 // if the type of retllval is abstract, refine to concrete
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
344 if (retllval->getType()->isAbstract())
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
345 retllval = DtoBitCast(retllval, getPtrToType(DtoType(resulttype)), "retval");
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
346
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
347 // set calling convention and parameter attributes
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
348 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
349 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
350 LLFunction* llfunc = llvm::dyn_cast<LLFunction>(dfnval->val);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
351 if (llfunc && llfunc->isIntrinsic())
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
352 palist = llvm::Intrinsic::getParamAttrs((llvm::Intrinsic::ID)llfunc->getIntrinsicID());
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
353 else
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
354 call->setCallingConv(callconv);
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
355 }
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
356 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
357 call->setCallingConv(callconv);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
358 call->setParamAttrs(palist);
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
359
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
360 return new DImValue(resulttype, retllval);
347
6057fdf797d8 [svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff changeset
361 }
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
362
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
363
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
364
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
365
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
366
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
367
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
368
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
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
372
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
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