annotate gen/functions.cpp @ 723:55f6c2e454d7

Implemented correct parameter order according to x86-32 ABI documentation. Changed AA types to just a void* .
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 25 Oct 2008 06:03:28 +0200
parents e177ae483f8e
children 6de2ed4f0abe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 258
diff changeset
2 #include "llvm/Support/CFG.h"
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
3 #include "llvm/Intrinsics.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
4
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
5 #include "mtype.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
6 #include "aggregate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
7 #include "init.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
8 #include "declaration.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
9 #include "template.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
10 #include "module.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
11 #include "statement.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
12
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
13 #include "gen/irstate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
14 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
15 #include "gen/llvmhelpers.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
16 #include "gen/runtime.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
17 #include "gen/arrays.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
18 #include "gen/logger.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
19 #include "gen/functions.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
20 #include "gen/todebug.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
21 #include "gen/classes.h"
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
22 #include "gen/dvalue.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
23
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
24 #include <algorithm>
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
25
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
26 const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, const LLType* nesttype, bool ismain)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
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: 428
diff changeset
28 assert(type->ty == Tfunction);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
29 TypeFunction* f = (TypeFunction*)type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
30
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
31 if (type->ir.type != NULL) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
32 return llvm::cast<llvm::FunctionType>(type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
33 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
34
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
35 bool typesafeVararg = false;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
36 bool arrayVararg = false;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
37 if (f->linkage == LINKd)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
38 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
39 if (f->varargs == 1)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
40 typesafeVararg = true;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
41 else if (f->varargs == 2)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
42 arrayVararg = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
43 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
44
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
45 // return value type
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
46 const LLType* rettype;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
47 const LLType* actualRettype;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
48 Type* rt = f->next;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
49 bool retinptr = false;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
50 bool usesthis = false;
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
51 bool usesnest = false;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
52
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
53 // parameter types
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
54 std::vector<const LLType*> paramvec;
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
55
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
56 if (ismain)
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
57 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
58 rettype = LLType::Int32Ty;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
59 actualRettype = rettype;
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
60 if (Argument::dim(f->parameters) == 0)
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
61 {
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
62 const LLType* arrTy = DtoArrayType(LLType::Int8Ty);
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
63 const LLType* arrArrTy = DtoArrayType(arrTy);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
64 paramvec.push_back(arrArrTy);
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
65 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
66 }
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
67 else{
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
68 assert(rt);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
69 if (DtoIsReturnedInArg(rt)) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
70 rettype = getPtrToType(DtoType(rt));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
71 actualRettype = LLType::VoidTy;
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
72 f->retInPtr = retinptr = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
73 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
74 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
75 rettype = DtoType(rt);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
76 actualRettype = rettype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
77 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
78
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
79 if (unsigned ea = DtoShouldExtend(rt))
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
80 {
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
81 f->retAttrs |= ea;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
82 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
83 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
84
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
85 if (retinptr) {
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
86 //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n';
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
87 paramvec.push_back(rettype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
88 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
89
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
90 if (thistype) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
91 paramvec.push_back(thistype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
92 usesthis = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
93 }
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
94 else if (nesttype) {
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
95 paramvec.push_back(nesttype);
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
96 usesnest = true;
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
97 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
98
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
99 if (typesafeVararg) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
100 ClassDeclaration* ti = Type::typeinfo;
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 334
diff changeset
101 ti->toObjFile(0); // TODO: multiobj
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
102 DtoForceConstInitDsymbol(ti);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
103 assert(ti->ir.irStruct->constInit);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
104 std::vector<const LLType*> types;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
105 types.push_back(DtoSize_t());
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
106 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType())));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
107 const LLType* t1 = llvm::StructType::get(types);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
108 paramvec.push_back(t1);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
109 paramvec.push_back(getPtrToType(LLType::Int8Ty));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
110 }
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
111 else if (arrayVararg)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
112 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
113 // do nothing?
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
114 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
115
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
116 // number of formal params
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
117 size_t n = Argument::dim(f->parameters);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
118
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
119 // on x86 we need to reverse the formal params in some cases to match the ABI
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
120 if (global.params.cpu == ARCHx86)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
121 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
122 // more than one formal arg,
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
123 // extern(D) linkage
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
124 // not a D-style vararg
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
125 if (n > 1 && f->linkage == LINKd && !typesafeVararg)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
126 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
127 f->reverseParams = true;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
128 f->reverseIndex = paramvec.size();
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
129 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
130 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
131
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
132
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
133 for (int i=0; i < n; ++i) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
134 Argument* arg = Argument::getNth(f->parameters, i);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
135 // ensure scalar
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
136 Type* argT = arg->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
137 assert(argT);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
138
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
139 bool refOrOut = ((arg->storageClass & STCref) || (arg->storageClass & STCout));
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
140
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
141 const LLType* at = DtoType(argT);
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: 546
diff changeset
142
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
143 // handle lazy args
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
144 if (arg->storageClass & STClazy)
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
145 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
146 Logger::println("lazy param");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
147 TypeFunction *ltf = new TypeFunction(NULL, arg->type, 0, LINKd);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
148 TypeDelegate *ltd = new TypeDelegate(ltf);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
149 at = DtoType(ltd);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
150 paramvec.push_back(at);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
151 }
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
152 // opaque types need special handling
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
153 else if (llvm::isa<llvm::OpaqueType>(at)) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
154 Logger::println("opaque param");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
155 assert(argT->ty == Tstruct || argT->ty == Tclass);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
156 paramvec.push_back(getPtrToType(at));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
157 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
158 // structs are passed as a reference, but by value
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
159 else if (argT->ty == Tstruct) {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
160 Logger::println("struct param");
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
161 if (!refOrOut)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
162 arg->llvmAttrs |= llvm::Attribute::ByVal;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
163 paramvec.push_back(getPtrToType(at));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
164 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
165 // static arrays are passed directly by reference
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
166 else if (argT->ty == Tsarray)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
167 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
168 Logger::println("static array param");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
169 at = getPtrToType(at);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
170 paramvec.push_back(at);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
171 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
172 // firstclass ' ref/out ' parameter
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
173 else if (refOrOut) {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
174 Logger::println("ref/out param");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
175 at = getPtrToType(at);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
176 paramvec.push_back(at);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
177 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
178 // firstclass ' in ' parameter
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
179 else {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
180 Logger::println("in param");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
181 if (unsigned ea = DtoShouldExtend(argT))
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
182 arg->llvmAttrs |= ea;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
183 paramvec.push_back(at);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
184 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
185 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
186
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
187 // reverse params?
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
188 if (f->reverseParams)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
189 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
190 std::reverse(paramvec.begin() + f->reverseIndex, paramvec.end());
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
191 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
192
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
193 // construct function type
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
194 bool isvararg = !(typesafeVararg || arrayVararg) && f->varargs;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
195 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
196
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
197 // tell first param to be passed in a register if we can
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
198 // ONLY extern(D) functions !
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
199 if ((n > 0 || usesthis || usesnest) && f->linkage == LINKd)
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
200 {
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
201 // FIXME: Only x86 right now ...
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
202 if (global.params.cpu == ARCHx86)
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
203 {
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
204 // pass first param in EAX if it fits, is not floating point and is not a 3 byte struct.
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
205 // FIXME: struct are not passed in EAX yet
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
206
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
207 // if there is a implicit context parameter, pass it in EAX
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
208 if (usesthis || usesnest)
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
209 {
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
210 f->thisAttrs |= llvm::Attribute::InReg;
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
211 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
212 // otherwise check the first formal parameter
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
213 else
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
214 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
215 int inreg = f->reverseParams ? n - 1 : 0;
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
216 Argument* arg = Argument::getNth(f->parameters, 0);
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
217 Type* t = arg->type->toBasetype();
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
218
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
219 // 32bit ints, pointers, classes and static arrays are candidate for being passed in EAX
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
220 if ((arg->storageClass & STCin) &&
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
221 ((t->isscalar() && !t->isfloating()) || t->ty == Tclass || t->ty == Tsarray) &&
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
222 (t->size() <= PTRSIZE))
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
223 {
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
224 arg->llvmAttrs |= llvm::Attribute::InReg;
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
225 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
226 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
227 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
228 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
229
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
230 // done
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
231 f->retInPtr = 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
232 f->usesThis = usesthis;
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
233 f->usesNest = usesnest;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
234
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
235 f->ir.type = new llvm::PATypeHolder(functype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
236
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
237 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
238 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
239
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
240 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
241
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
242 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
243 {
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
244 // type has already been resolved
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
245 if (fdecl->type->ir.type != 0) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
246 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
247 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
248
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
249 TypeFunction* f = (TypeFunction*)fdecl->type;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
250 const llvm::FunctionType* fty = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
251
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
252 if (fdecl->llvmInternal == LLVMva_start)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
253 fty = GET_INTRINSIC_DECL(vastart)->getFunctionType();
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
254 else if (fdecl->llvmInternal == LLVMva_copy)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
255 fty = GET_INTRINSIC_DECL(vacopy)->getFunctionType();
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
256 else if (fdecl->llvmInternal == LLVMva_end)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
257 fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
258 assert(fty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
259
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
260 f->ir.type = new llvm::PATypeHolder(fty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
261 return fty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
262 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
263
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
264 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
265
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
266 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
267 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
268 // handle for C vararg intrinsics
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
269 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
270 return DtoVaFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
271
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
272 // type has already been resolved
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
273 if (fdecl->type->ir.type != 0)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
274 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
275
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
276 const LLType* thisty = 0;
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
277 const LLType* nestty = 0;
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
278
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
279 if (fdecl->needThis()) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
280 if (AggregateDeclaration* ad = fdecl->isMember2()) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
281 Logger::println("isMember = this is: %s", ad->type->toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
282 thisty = DtoType(ad->type);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
283 //Logger::cout() << "this llvm type: " << *thisty << '\n';
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
284 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->recty.get()))
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
285 thisty = getPtrToType(thisty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
286 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
287 else {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
288 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
289 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
290 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
291 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
292 else if (fdecl->isNested()) {
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
293 nestty = getPtrToType(LLType::Int8Ty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
294 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
295
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
296 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, nestty, fdecl->isMain());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
297
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
298 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
299 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
300
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
301 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
302
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
303 static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
304 {
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
305 TypeFunction* f = (TypeFunction*)fdecl->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
306 const llvm::FunctionType* fty = DtoVaFunctionType(fdecl);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
307 llvm::Function* func = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
308
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
309 if (fdecl->llvmInternal == LLVMva_start)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
310 func = GET_INTRINSIC_DECL(vastart);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
311 else if (fdecl->llvmInternal == LLVMva_copy)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
312 func = GET_INTRINSIC_DECL(vacopy);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
313 else if (fdecl->llvmInternal == LLVMva_end)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
314 func = GET_INTRINSIC_DECL(vaend);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
315 assert(func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
316
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
317 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
318 return func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
319 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
320
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
321 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
322
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
323 void DtoResolveFunction(FuncDeclaration* fdecl)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
324 {
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
325 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
326 return; // ignore declaration completely
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
327 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
328
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
329 // is imported and we don't have access?
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
330 if (fdecl->getModule() != gIR->dmodule)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
331 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
332 if (fdecl->prot() == PROTprivate)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
333 return;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
334 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
335
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
336 if (fdecl->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
337 fdecl->ir.resolved = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
338
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
339 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
340 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
341
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
342 //printf("resolve function: %s\n", fdecl->toPrettyChars());
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
343
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
344 if (fdecl->parent)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
345 if (TemplateInstance* tinst = fdecl->parent->isTemplateInstance())
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
346 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
347 TemplateDeclaration* tempdecl = tinst->tempdecl;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
348 if (tempdecl->llvmInternal == LLVMva_arg)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
349 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
350 Logger::println("magic va_arg found");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
351 fdecl->llvmInternal = LLVMva_arg;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
352 fdecl->ir.declared = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
353 fdecl->ir.initialized = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
354 fdecl->ir.defined = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
355 return; // this gets mapped to an instruction so a declaration makes no sence
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
356 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
357 else if (tempdecl->llvmInternal == LLVMva_start)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
358 {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
359 Logger::println("magic va_start found");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
360 fdecl->llvmInternal = LLVMva_start;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
361 }
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
362 else if (tempdecl->llvmInternal == LLVMintrinsic)
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
363 {
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
364 Logger::println("overloaded intrinsic found");
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
365 fdecl->llvmInternal = LLVMintrinsic;
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
366 DtoOverloadedIntrinsicName(tinst, tempdecl, fdecl->intrinsicName);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
367 fdecl->linkage = LINKintrinsic;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
368 ((TypeFunction*)fdecl->type)->linkage = LINKintrinsic;
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
369 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
370 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
371
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
372 DtoFunctionType(fdecl);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
373
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
374 // queue declaration
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
375 if (!fdecl->isAbstract())
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
376 gIR->declareList.push_back(fdecl);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
377 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
378
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
379 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
380
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
381 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
382 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
383 int llidx = 0;
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
384 if (f->retInPtr) ++llidx;
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
385 if (f->usesThis) ++llidx;
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
386 else if (f->usesNest) ++llidx;
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
387 if (f->linkage == LINKd && f->varargs == 1)
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
388 llidx += 2;
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
389
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
390 int funcNumArgs = func->getArgumentList().size();
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
391
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
392 LLSmallVector<llvm::AttributeWithIndex, 9> attrs;
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 622
diff changeset
393 llvm::AttributeWithIndex PAWI;
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
394
446
7a67dedbf933 Fixed param attrs for return values (not really broken, but would be if more return attrs were added)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
395 // set return value attrs if any
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
396 if (f->retAttrs)
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
397 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
398 PAWI.Index = 0;
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
399 PAWI.Attrs = f->retAttrs;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
400 attrs.push_back(PAWI);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
401 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
402
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
403 // set sret param
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
404 if (f->retInPtr)
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
405 {
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
406 PAWI.Index = 1;
632
df196c8dea26 Updated to latest LLVM trunk, function notes have been removed and merged with parameter attributes, which have been renamed to just attributes. Nothing seems to have broke!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 622
diff changeset
407 PAWI.Attrs = llvm::Attribute::StructRet;
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
408 attrs.push_back(PAWI);
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
409 }
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
410
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
411 // set this/nest param attrs
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
412 if (f->thisAttrs)
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
413 {
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
414 PAWI.Index = f->retInPtr ? 2 : 1;
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
415 PAWI.Attrs = f->thisAttrs;
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
416 attrs.push_back(PAWI);
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
417 }
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
418
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
419 // set attrs on the rest of the arguments
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
420 size_t n = Argument::dim(f->parameters);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
421 assert(funcNumArgs >= n); // main might mismatch, for the implicit char[][] arg
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
422
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
423 LLSmallVector<unsigned,8> attrptr(n, 0);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
424
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
425 for (size_t k = 0; k < n; ++k)
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
426 {
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
427 Argument* fnarg = Argument::getNth(f->parameters, k);
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
428 assert(fnarg);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
429
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
430 attrptr[k] = fnarg->llvmAttrs;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
431 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
432
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
433 // reverse params?
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
434 if (f->reverseParams)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
435 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
436 std::reverse(attrptr.begin(), attrptr.end());
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
437 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
438
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
439 // build rest of attrs list
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
440 for (int i = 0; i < n; i++)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
441 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
442 if (attrptr[i])
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
443 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
444 PAWI.Index = llidx+i+1;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
445 PAWI.Attrs = attrptr[i];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
446 attrs.push_back(PAWI);
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
447 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
448 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
449
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
450 llvm::AttrListPtr attrlist = llvm::AttrListPtr::get(attrs.begin(), attrs.end());
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
451 func->setAttributes(attrlist);
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
452 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
453
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
454 //////////////////////////////////////////////////////////////////////////////////////////
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
455
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
456 void DtoDeclareFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
457 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
458 if (fdecl->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
459 fdecl->ir.declared = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
460
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
461 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
462 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
463
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
464 //printf("declare function: %s\n", fdecl->toPrettyChars());
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
465
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
466 // intrinsic sanity check
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
467 if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) {
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
468 error(fdecl->loc, "intrinsics cannot have function bodies");
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
469 fatal();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
470 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
471
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
472 // get TypeFunction*
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
473 Type* t = fdecl->type->toBasetype();
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
474 TypeFunction* f = (TypeFunction*)t;
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
475
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
476 bool declareOnly = false;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
477 bool templInst = fdecl->parent && DtoIsTemplateInstance(fdecl->parent);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
478 if (!templInst && fdecl->getModule() != gIR->dmodule)
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 139
diff changeset
479 {
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 139
diff changeset
480 Logger::println("not template instance, and not in this module. declare only!");
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 139
diff changeset
481 Logger::println("current module: %s", gIR->dmodule->ident->toChars());
378
d8234836b40f Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents: 363
diff changeset
482 if(fdecl->getModule())
d8234836b40f Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents: 363
diff changeset
483 Logger::println("func module: %s", fdecl->getModule()->ident->toChars());
379
d632801b15f0 Introducing opaque type to dmd frontent to be used with certain runtime array
Christian Kamm <kamm incasoftware de>
parents: 378
diff changeset
484 else {
d632801b15f0 Introducing opaque type to dmd frontent to be used with certain runtime array
Christian Kamm <kamm incasoftware de>
parents: 378
diff changeset
485 Logger::println("func not in a module, is runtime");
d632801b15f0 Introducing opaque type to dmd frontent to be used with certain runtime array
Christian Kamm <kamm incasoftware de>
parents: 378
diff changeset
486 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
487 declareOnly = true;
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 139
diff changeset
488 }
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
489 else if (fdecl->llvmInternal == LLVMva_start)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
490 declareOnly = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
491
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
492 if (!fdecl->ir.irFunc) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
493 fdecl->ir.irFunc = new IrFunction(fdecl);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
494 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
495
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
496 // mangled name
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
497 const char* mangled_name;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
498 if (fdecl->llvmInternal == LLVMintrinsic)
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
499 mangled_name = fdecl->intrinsicName.c_str();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
500 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
501 mangled_name = fdecl->mangle();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
502
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
503 llvm::Function* vafunc = 0;
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
504 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
505 vafunc = DtoDeclareVaFunction(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
506
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
507 // construct function
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
508 const llvm::FunctionType* functype = DtoFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
509 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
510 if (!func)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
511 func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
512
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
513 // add func to IRFunc
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
514 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
515
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
516 // calling convention
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
517 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
518 func->setCallingConv(DtoCallingConv(f->linkage));
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
519 else // fall back to C, it should be the right thing to do
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
520 func->setCallingConv(llvm::CallingConv::C);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
521
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
522 fdecl->ir.irFunc->func = func;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
523 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
524
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
525 // parameter attributes
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
526 if (!fdecl->isIntrinsic()) {
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
527 set_param_attrs(f, func, fdecl);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
528 }
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
529
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
530 // main
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
531 if (fdecl->isMain()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
532 gIR->mainFunc = func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
533 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
534
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
535 // static ctor
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
536 if (fdecl->isStaticCtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
537 gIR->ctors.push_back(fdecl);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
538 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
539 // static dtor
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
540 else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
541 gIR->dtors.push_back(fdecl);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
542 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
543
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
544 // we never reference parameters of function prototypes
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
545 if (!declareOnly)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
546 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
547 // name parameters
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
548 llvm::Function::arg_iterator iarg = func->arg_begin();
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
549
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
550 if (f->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
551 iarg->setName(".sretarg");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
552 fdecl->ir.irFunc->retArg = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
553 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
554 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
555
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
556 if (f->usesThis) {
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
557 iarg->setName("this");
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
558 fdecl->ir.irFunc->thisArg = iarg;
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
559 assert(fdecl->ir.irFunc->thisArg);
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
560 ++iarg;
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
561 }
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
562 else if (f->usesNest) {
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
563 iarg->setName(".nest");
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
564 fdecl->ir.irFunc->nestArg = iarg;
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
565 assert(fdecl->ir.irFunc->nestArg);
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
566 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
567 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
568
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
569 if (f->linkage == LINKd && f->varargs == 1) {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
570 iarg->setName("_arguments");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
571 fdecl->ir.irFunc->_arguments = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
572 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
573 iarg->setName("_argptr");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
574 fdecl->ir.irFunc->_argptr = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
575 ++iarg;
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
576 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
577
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
578 int k = 0;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
579
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
580 for (; iarg != func->arg_end(); ++iarg)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
581 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
582 if (fdecl->parameters && fdecl->parameters->dim > k)
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
583 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
584 Dsymbol* argsym;
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
585 if (f->reverseParams)
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
586 argsym = (Dsymbol*)fdecl->parameters->data[fdecl->parameters->dim-k-1];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
587 else
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
588 argsym = (Dsymbol*)fdecl->parameters->data[k];
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
589
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
590 VarDeclaration* argvd = argsym->isVarDeclaration();
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
591 assert(argvd);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
592 assert(!argvd->ir.irLocal);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
593 argvd->ir.irLocal = new IrLocal(argvd);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
594 argvd->ir.irLocal->value = iarg;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
595 iarg->setName(argvd->ident->toChars());
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
596
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
597 k++;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
598 }
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
599 else
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
600 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
601 iarg->setName("unnamed");
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
602 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
603 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
604 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
605
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
606 if (fdecl->isUnitTestDeclaration())
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
607 gIR->unitTests.push_back(fdecl);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
608
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
609 if (!declareOnly)
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
610 gIR->defineList.push_back(fdecl);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
611 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
612 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
613
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
614 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
615 Logger::cout() << "func decl: " << *func << '\n';
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
616 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
617
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
618 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
619
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
620 void DtoDefineFunc(FuncDeclaration* fd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
621 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
622 if (fd->ir.defined) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
623 fd->ir.defined = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
624
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
625 assert(fd->ir.declared);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
626
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
627 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
628 LOG_SCOPE;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
629
546
406aee3416bb Removed D_InlineAsm and D_InlineAsm_X86 versions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 527
diff changeset
630 // error on naked
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
631 if (fd->naked)
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
632 {
546
406aee3416bb Removed D_InlineAsm and D_InlineAsm_X86 versions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 527
diff changeset
633 fd->error("naked is not supported");
406aee3416bb Removed D_InlineAsm and D_InlineAsm_X86 versions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 527
diff changeset
634 fatal();
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
635 }
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
636
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
637 // debug info
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
638 if (global.params.symdebug) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
639 Module* mo = fd->getModule();
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 245
diff changeset
640 fd->ir.irFunc->dwarfSubProg = DtoDwarfSubProgram(fd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
641 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
642
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
643 Type* t = fd->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
644 TypeFunction* f = (TypeFunction*)t;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
645 assert(f->ir.type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
646
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
647 llvm::Function* func = fd->ir.irFunc->func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
648 const llvm::FunctionType* functype = func->getFunctionType();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
649
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
650 // only members of the current module or template instances maybe be defined
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
651 if (!(fd->getModule() == gIR->dmodule || DtoIsTemplateInstance(fd->parent)))
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
652 return;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
653
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
654 // set module owner
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
655 fd->ir.DModule = gIR->dmodule;
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
656
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
657 // is there a body?
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
658 if (fd->fbody == NULL)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
659 return;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
660
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
661 Logger::println("Doing function body for: %s", fd->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
662 assert(fd->ir.irFunc);
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
663 IrFunction* irfunction = fd->ir.irFunc;
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
664 gIR->functions.push_back(irfunction);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
665
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
666 if (fd->isMain())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
667 gIR->emitMain = true;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
668
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
669 std::string entryname("entry_");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
670 entryname.append(fd->toPrettyChars());
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
671
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
672 llvm::BasicBlock* beginbb = llvm::BasicBlock::Create(entryname,func);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
673 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
674
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
675 //assert(gIR->scopes.empty());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
676 gIR->scopes.push_back(IRScope(beginbb, endbb));
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
677
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
678 // create alloca point
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
679 llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb);
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
680 irfunction->allocapoint = allocaPoint;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
681
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
682 // debug info - after all allocas, but before any llvm.dbg.declare etc
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
683 if (global.params.symdebug) DtoDwarfFuncStart(fd);
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
684
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
685 // need result variable?
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
686 if (fd->vresult) {
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
687 Logger::println("vresult value");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
688 fd->vresult->ir.irLocal = new IrLocal(fd->vresult);
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
689 fd->vresult->ir.irLocal->value = DtoAlloca(DtoType(fd->vresult->type), "function_vresult");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
690 }
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
691
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
692 // this hack makes sure the frame pointer elimination optimization is disabled.
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
693 // this this eliminates a bunch of inline asm related issues.
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
694 // naked must always eliminate the framepointer however...
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
695 if (fd->inlineAsm && !fd->naked)
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
696 {
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
697 // emit a call to llvm_eh_unwind_init
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
698 LLFunction* hack = GET_INTRINSIC_DECL(eh_unwind_init);
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
699 gIR->ir->CreateCall(hack, "");
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
700 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
701
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
702 // give the 'this' argument storage and debug info
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
703 if (f->usesThis)
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
704 {
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
705 LLValue* thisvar = irfunction->thisArg;
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
706 assert(thisvar);
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
707
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
708 LLValue* thismem = DtoAlloca(thisvar->getType(), ".this");
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
709 DtoStore(thisvar, thismem);
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
710 irfunction->thisArg = thismem;
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
711
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
712 assert(!fd->vthis->ir.irLocal);
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
713 fd->vthis->ir.irLocal = new IrLocal(fd->vthis);
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
714 fd->vthis->ir.irLocal->value = thismem;
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
715
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
716 if (global.params.symdebug)
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
717 DtoDwarfLocalVariable(thismem, fd->vthis);
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
718
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
719 if (fd->vthis->nestedref)
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
720 fd->nestedVars.insert(fd->vthis);
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
721 }
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
722
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
723 // give arguments storage
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
724 // and debug info
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
725 if (fd->parameters)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
726 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
727 size_t n = fd->parameters->dim;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
728 for (int i=0; i < n; ++i)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
729 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
730 Dsymbol* argsym = (Dsymbol*)fd->parameters->data[i];
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
731 VarDeclaration* vd = argsym->isVarDeclaration();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
732 assert(vd);
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
733
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
734 if (vd->nestedref)
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
735 fd->nestedVars.insert(vd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
736
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
737 IrLocal* irloc = vd->ir.irLocal;
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
738 assert(irloc);
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
739
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
740 bool refout = vd->storage_class & (STCref | STCout);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
741 bool lazy = vd->storage_class & STClazy;
457
d82ebdba4191 Fixed debug info and lazy arguments.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 455
diff changeset
742
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
743 if (refout)
449
56265fa07c7d Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 446
diff changeset
744 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
745 continue;
449
56265fa07c7d Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 446
diff changeset
746 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
747 else if (!lazy && DtoIsPassedByRef(vd->type))
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
748 {
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
749 LLValue* vdirval = irloc->value;
455
d3d3519b72e8 Fixed inserting an AA entry with 'this' as key.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 454
diff changeset
750 if (global.params.symdebug && !(isaArgument(vdirval) && !isaArgument(vdirval)->hasByValAttr()))
d3d3519b72e8 Fixed inserting an AA entry with 'this' as key.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 454
diff changeset
751 DtoDwarfLocalVariable(vdirval, vd);
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
752 continue;
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
753 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
754
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
755 LLValue* a = irloc->value;
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
756 LLValue* v = DtoAlloca(a->getType(), "."+a->getName());
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
757 DtoStore(a,v);
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 457
diff changeset
758 irloc->value = v;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
759 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
760 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
761
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
762 // need result variable? (nested)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
763 if (fd->vresult && fd->vresult->nestedref) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
764 Logger::println("nested vresult value: %s", fd->vresult->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
765 fd->nestedVars.insert(fd->vresult);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
766 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
767
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
768 // construct nested variables array
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
769 if (!fd->nestedVars.empty())
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
770 {
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
771 Logger::println("has nested frame");
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
772 // start with add all enclosing parent frames
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
773 int nparelems = 0;
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
774 Dsymbol* par = fd->toParent2();
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
775 while (par)
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
776 {
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
777 if (FuncDeclaration* parfd = par->isFuncDeclaration())
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
778 {
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
779 nparelems += parfd->nestedVars.size();
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
780 }
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
781 else if (ClassDeclaration* parcd = par->isClassDeclaration())
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
782 {
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
783 // nothing needed
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
784 }
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
785 else
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
786 {
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
787 break;
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
788 }
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
789 par = par->toParent2();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
790 }
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
791 int nelems = fd->nestedVars.size() + nparelems;
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
792
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
793 // make array type for nested vars
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
794 const LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
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
795
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
796 // alloca it
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
797 LLValue* nestedVars = DtoAlloca(nestedVarsTy, ".nested_vars");
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
798
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
799 // copy parent frame into beginning
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
800 if (nparelems)
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
801 {
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
802 LLValue* src = irfunction->nestArg;
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
803 if (!src)
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
804 {
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
805 assert(irfunction->thisArg);
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
806 assert(fd->isMember2());
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
807 LLValue* thisval = DtoLoad(irfunction->thisArg);
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
808 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
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
809 assert(cd);
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
810 assert(cd->vthis);
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
811 src = DtoLoad(DtoGEPi(thisval, 0,2+cd->vthis->ir.irField->index, ".vthis"));
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
812 }
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
813 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE));
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
814 }
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
815
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
816 // store in IrFunction
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
817 irfunction->nestedVar = nestedVars;
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
818
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
819 // go through all nested vars and assign indices
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
820 int idx = nparelems;
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
821 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
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
822 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
823 VarDeclaration* vd = *i;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
824 if (!vd->ir.irLocal)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
825 vd->ir.irLocal = new IrLocal(vd);
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
826
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
827 if (vd->isParameter())
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
828 {
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
829 Logger::println("nested param: %s", vd->toChars());
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
830 LLValue* gep = DtoGEPi(nestedVars, 0, idx);
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
831 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
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
832 DtoStore(val, gep);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
833 }
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
834 else
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
835 {
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
836 Logger::println("nested var: %s", vd->toChars());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
837 }
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
838
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
839 vd->ir.irLocal->nestedIndex = idx++;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
840 }
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
841
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
842 // fixup nested result variable
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
843 if (fd->vresult && fd->vresult->nestedref) {
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
844 Logger::println("nested vresult value: %s", fd->vresult->toChars());
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
845 LLValue* gep = DtoGEPi(nestedVars, 0, fd->vresult->ir.irLocal->nestedIndex);
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
846 LLValue* val = DtoBitCast(fd->vresult->ir.irLocal->value, getVoidPtrType());
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
847 DtoStore(val, gep);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
848 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
849 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
850
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
851 // copy _argptr and _arguments to a memory location
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
852 if (f->linkage == LINKd && f->varargs == 1)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
853 {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
854 // _argptr
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
855 LLValue* argptrmem = DtoAlloca(fd->ir.irFunc->_argptr->getType(), "_argptr_mem");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
856 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
857 fd->ir.irFunc->_argptr = argptrmem;
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
858
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
859 // _arguments
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
860 LLValue* argumentsmem = DtoAlloca(fd->ir.irFunc->_arguments->getType(), "_arguments_mem");
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
861 new llvm::StoreInst(fd->ir.irFunc->_arguments, argumentsmem, gIR->scopebb());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
862 fd->ir.irFunc->_arguments = argumentsmem;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
863 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
864
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
865 // output function body
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
866 fd->fbody->toIR(gIR);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
867
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
868 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
869 // in automatically, so we do it here.
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
870 if (!gIR->scopereturned()) {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
871 // pass the previous block into this block
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
872 if (global.params.symdebug) DtoDwarfFuncEnd(fd);
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
873 if (func->getReturnType() == LLType::VoidTy) {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
874 llvm::ReturnInst::Create(gIR->scopebb());
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
875 }
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
876 else {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
877 if (!fd->isMain())
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
878 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
879 else
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
880 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
881 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
882 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
883
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
884 // erase alloca point
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
885 allocaPoint->eraseFromParent();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
886 allocaPoint = 0;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
887 gIR->func()->allocapoint = 0;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
888
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
889 gIR->scopes.pop_back();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
890
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
891 // get rid of the endentry block, it's never used
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
892 assert(!func->getBasicBlockList().empty());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
893 func->getBasicBlockList().pop_back();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
894
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
895 // if the last block is empty now, it must be unreachable or it's a bug somewhere else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
896 // would be nice to figure out how to assert that this is correct
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
897 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 275
diff changeset
898 if (lastbb->empty())
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 275
diff changeset
899 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 258
diff changeset
900 new llvm::UnreachableInst(lastbb);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
901 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
902
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
903 // if the last block is not terminated we return a null value or void
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
904 // for some unknown reason this is needed when a void main() has a inline asm block ...
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
905 // this should be harmless for well formed code!
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
906 lastbb = &func->getBasicBlockList().back();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
907 if (!lastbb->getTerminator())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
908 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
909 Logger::println("adding missing return statement");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
910 if (func->getReturnType() == LLType::VoidTy)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
911 llvm::ReturnInst::Create(lastbb);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
912 else
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
913 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
914 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
915
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
916 gIR->functions.pop_back();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
917 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
918
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
919 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
920
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
921 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
922 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
923 Dsymbol* parent = fdecl->toParent();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
924 ClassDeclaration* cd = parent->isClassDeclaration();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
925 assert(cd);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
926
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
927 FuncDeclaration* f = fdecl;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
928
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
929 while (cd)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
930 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
931 ClassDeclaration* base = cd->baseClass;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
932 if (!base)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
933 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
934 FuncDeclaration* f2 = base->findFunc(fdecl->ident, (TypeFunction*)fdecl->type);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
935 if (f2) {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
936 f = f2;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
937 cd = base;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
938 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
939 else
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
940 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
941 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
942
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
943 DtoResolveDsymbol(f);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
944 return llvm::cast<llvm::FunctionType>(DtoType(f->type));
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
945 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
946
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
947 //////////////////////////////////////////////////////////////////////////////////////////
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
948
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
949 DValue* DtoArgument(Argument* fnarg, Expression* argexp)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
950 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
951 Logger::println("DtoArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
952 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
953
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
954 DValue* arg = argexp->toElem(gIR);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
955
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
956 // ref/out arg
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
957 if (fnarg && (fnarg->storageClass & (STCref | STCout)))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
958 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
959 if (arg->isVar() || arg->isLRValue())
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
960 arg = new DImValue(argexp->type, arg->getLVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
961 else
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
962 arg = new DImValue(argexp->type, arg->getRVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
963 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
964 // lazy arg
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
965 else if (fnarg && (fnarg->storageClass & STClazy))
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
966 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
967 assert(argexp->type->toBasetype()->ty == Tdelegate);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
968 assert(!arg->isLVal());
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
969 return arg;
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
970 }
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
971 // byval arg, but expr has no storage yet
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: 546
diff changeset
972 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull()))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
973 {
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
974 LLValue* alloc = DtoAlloca(DtoType(argexp->type), ".tmp_arg");
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: 546
diff changeset
975 DVarValue* vv = new DVarValue(argexp->type, alloc);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
976 DtoAssign(argexp->loc, vv, arg);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
977 arg = vv;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
978 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
979
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
980 return arg;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
981 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
982
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
983 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
984
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
985 void DtoVariadicArgument(Expression* argexp, LLValue* dst)
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
986 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
987 Logger::println("DtoVariadicArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
988 LOG_SCOPE;
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: 546
diff changeset
989 DVarValue vv(argexp->type, dst);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
990 DtoAssign(argexp->loc, &vv, argexp->toElem(gIR));
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
991 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
992
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
993 //////////////////////////////////////////////////////////////////////////////////////////
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
994
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
995 bool FuncDeclaration::isIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
996 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
997 return (llvmInternal == LLVMintrinsic || isVaIntrinsic());
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
998 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
999
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1000 bool FuncDeclaration::isVaIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1001 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1002 return (llvmInternal == LLVMva_start ||
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1003 llvmInternal == LLVMva_copy ||
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1004 llvmInternal == LLVMva_end);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
1005 }