Mercurial > projects > ldc
annotate gen/tocall.cpp @ 598:13ff06605226
To prevert source-overwriting in the future, forbit output files with the same
name as the source file.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 14 Sep 2008 22:49:19 +0200 |
parents | fbb1a366cfbc |
children | 26fce59fe80a |
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 |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
116 // get n args in arguments list |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
117 size_t n_arguments = arguments ? arguments->dim : 0; |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
118 |
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
|
119 // build struct with argument types (non variadic args) |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
120 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
|
121 { |
ac1fcc138e42
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 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 } |
ac1fcc138e42
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 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
|
129 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
|
130 LLValue* mem = DtoAlloca(vtype,"_argptr_storage"); |
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 // store arguments in the struct |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
133 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
|
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 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 } |
ac1fcc138e42
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 |
ac1fcc138e42
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 // 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
|
144 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
|
145 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
|
146 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
|
147 |
ac1fcc138e42
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 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
|
149 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
|
150 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
|
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 std::vector<LLConstant*> vtypeinfos; |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
153 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
|
154 { |
ac1fcc138e42
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 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
|
156 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type)); |
347
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
157 } |
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
158 |
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
|
159 // 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
|
160 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
|
161 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
|
162 |
ac1fcc138e42
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 // 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 |
ac1fcc138e42
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 // 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
|
173 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
|
174 ++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
|
175 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
|
176 ++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
|
177 |
ac1fcc138e42
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 // 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
|
179 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
|
180 { |
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
185 if (fnarg->llvmAttrs) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
186 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
|
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 ++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
|
189 } |
ac1fcc138e42
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 } |
ac1fcc138e42
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 |
422
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
193 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
|
194 { |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
347
diff
changeset
|
195 // 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
|
196 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
|
197 |
456
b975f29b7256
Make sure DtoType has been run on the DType before assembling a call.
Christian Kamm <kamm incasoftware de>
parents:
454
diff
changeset
|
198 // 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
|
199 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
|
200 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
|
201 |
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
|
202 // 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
|
203 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
|
204 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
205 // 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
|
206 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
|
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 // 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
|
209 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
|
210 |
ac1fcc138e42
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 // 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 |
ac1fcc138e42
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 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
|
219 |
ac1fcc138e42
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 // 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
|
221 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
|
222 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
|
223 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
|
224 |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
225 // get n arguments |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
226 size_t n_arguments = arguments ? arguments->dim : 0; |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
227 |
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
|
228 // 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
|
229 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
|
230 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
|
231 |
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 // 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
|
233 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
|
234 |
283d113d4753
Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
235 // 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
|
236 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
|
237 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
|
238 |
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
|
239 // 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
|
240 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
|
241 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
347
diff
changeset
|
242 // 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
|
243 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
|
244 { |
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
|
245 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
|
246 ++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
|
247 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
|
248 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
|
249 } |
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
250 |
422
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
251 // 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
|
252 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
|
253 { |
422
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
254 // ... 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
|
255 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
|
256 { |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
257 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
|
258 ++argiter; |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
259 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
|
260 } |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
261 // ... 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
|
262 else if (delegatecall) |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
263 { |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
264 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
|
265 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
|
266 ++argiter; |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
267 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
|
268 } |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
269 // ... 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
|
270 else if (nestedcall) |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
271 { |
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
|
272 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
|
273 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
|
274 ++argiter; |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
275 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
|
276 } |
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
|
277 else |
422
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
278 { |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
279 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
|
280 fatal(); |
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
281 } |
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
|
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 |
ac1fcc138e42
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 // 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
|
285 |
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
|
286 // 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
|
287 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
|
288 { |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
289 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
|
290 { |
ac1fcc138e42
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 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
|
292 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
|
293 // 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
|
294 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
|
295 ++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
|
296 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
|
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 } |
ac1fcc138e42
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 // 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
|
301 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
|
302 { |
ac1fcc138e42
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 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
|
304 } |
ac1fcc138e42
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 |
ac1fcc138e42
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 // 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
|
307 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
|
308 { |
ac1fcc138e42
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 Logger::println("doing normal arguments"); |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
526
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 { |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
530
diff
changeset
|
317 Logger::cout() << "arg: " << *arg << '\n'; |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
530
diff
changeset
|
318 Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n'; |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
319 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
|
320 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
|
321 if (fnarg->llvmAttrs) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
322 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
|
323 } |
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
|
324 ++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
|
325 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
|
326 } |
ac1fcc138e42
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 |
ac1fcc138e42
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 #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
|
330 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
|
331 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
|
332 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
|
333 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
|
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 #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
|
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 // 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
|
338 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
|
339 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
|
340 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
|
341 |
ac1fcc138e42
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 //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
|
343 |
ac1fcc138e42
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 // 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
|
345 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
|
346 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
347
diff
changeset
|
347 // 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
|
348 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
|
349 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
347
diff
changeset
|
350 // 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
|
351 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
|
352 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
|
353 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
354 // 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
|
355 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
|
356 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
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 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
|
364 call->setCallingConv(callconv); |
347
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
365 call->setParamAttrs(palist); |
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
diff
changeset
|
366 |
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
|
367 return new DImValue(resulttype, retllval); |
347
6057fdf797d8
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
lindquist
parents:
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 |
ac1fcc138e42
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 |
ac1fcc138e42
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 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
347
diff
changeset
|
376 |
ac1fcc138e42
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 |
ac1fcc138e42
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 |
ac1fcc138e42
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 |
ac1fcc138e42
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 |