annotate gen/functions.cpp @ 1051:dc608dc33081

Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the same LDC call.
author Christian Kamm <kamm incasoftware de>
date Sat, 07 Mar 2009 14:25:30 +0100
parents afe271b0e271
children 802d508f66f1
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"
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
23 #include "gen/abi.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
24
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
25 const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
26 {
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
27 if (Logger::enabled())
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
28 Logger::println("DtoFunctionType(%s)", type->toChars());
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
29 LOG_SCOPE
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
30 // sanity check
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
31 assert(type->ty == Tfunction);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
32 TypeFunction* f = (TypeFunction*)type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
33
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
34 // already built ?
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
35 if (type->ir.type != NULL) {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
36 //assert(f->fty != NULL);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
37 return llvm::cast<llvm::FunctionType>(type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
38 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
39
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
40 // Tell the ABI we're resolving a new function type
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
41 gABI->newFunctionType(f);
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
42
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
43 // start new ir funcTy
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
44 f->fty.reset();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
45
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
46 // llvm idx counter
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
47 size_t lidx = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
48
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
49 // main needs a little special handling
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
50 if (ismain)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
51 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
52 f->fty.ret = new IrFuncTyArg(Type::tint32, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
53 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
54 // sane return value
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
55 else
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
56 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
57 Type* rt = f->next;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
58 unsigned a = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
59 // sret return
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
60 if (gABI->returnInArg(f))
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
61 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
62 f->fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attribute::StructRet);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
63 rt = Type::tvoid;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
64 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
65 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
66 // sext/zext return
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
67 else if (unsigned se = DtoShouldExtend(rt))
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
68 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
69 a = se;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
70 }
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
71 f->fty.ret = new IrFuncTyArg(rt, false, a);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
72 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
73 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
74
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
75 // member functions
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
76 if (thistype)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
77 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
78 bool toref = (thistype->toBasetype()->ty == Tstruct);
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
79 f->fty.arg_this = new IrFuncTyArg(thistype, toref);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
80 lidx++;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
81 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
82
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
83 // and nested functions
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
84 else if (nesttype)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
85 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
86 f->fty.arg_nest = new IrFuncTyArg(nesttype, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
87 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
88 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
89
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
90 // vararg functions are special too
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
91 if (f->varargs)
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
92 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
93 if (f->linkage == LINKd)
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
94 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
95 // d style with hidden args
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
96 // 2 (array) is handled by the frontend
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
97 if (f->varargs == 1)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
98 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
99 // _arguments
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
100 f->fty.arg_arguments = new IrFuncTyArg(Type::typeinfo->type->arrayOf(), false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
101 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
102 // _argptr
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
103 f->fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
104 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
105 }
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 225
diff changeset
106 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
107 else if (f->linkage == LINKc)
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
108 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
109 f->fty.c_vararg = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
110 }
988
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
111 else
2667e3a145be - Fixed LLVM style CL args for D2.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 958
diff changeset
112 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
113 type->error(0, "invalid linkage for variadic function");
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
114 fatal();
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
115 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
116 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
117
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
118 // if this _Dmain() doesn't have an argument, we force it to have one
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
119 int nargs = Argument::dim(f->parameters);
930
7985bb036db4 Follow the D ABI and pass the last arg in a register if it is a struct that fits.
Christian Kamm <kamm incasoftware de>
parents: 920
diff changeset
120
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
121 if (ismain && nargs == 0)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
122 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
123 Type* mainargs = Type::tchar->arrayOf()->arrayOf();
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
124 f->fty.args.push_back(new IrFuncTyArg(mainargs, false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
125 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
126 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
127 // add explicit parameters
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
128 else for (int i = 0; i < nargs; i++)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
129 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
130 // get argument
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
131 Argument* arg = Argument::getNth(f->parameters, i);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
132
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
133 // reference semantics? ref, out and static arrays are
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
134 bool byref = (arg->storageClass & (STCref|STCout)) || (arg->type->toBasetype()->ty == Tsarray);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
135
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
136 Type* argtype = arg->type;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
137 unsigned a = 0;
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
138
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
139 // handle lazy args
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
140 if (arg->storageClass & STClazy)
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
141 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
142 Logger::println("lazy param");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
143 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
144 TypeDelegate *ltd = new TypeDelegate(ltf);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
145 argtype = ltd;
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
146 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
147 // byval
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
148 else if (gABI->passByVal(argtype))
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
149 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
150 if (!byref) a |= llvm::Attribute::ByVal;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
151 byref = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
152 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
153 // sext/zext
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
154 else if (!byref)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
155 {
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
156 a |= DtoShouldExtend(argtype);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
157 }
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
158
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
159 f->fty.args.push_back(new IrFuncTyArg(argtype, byref, a));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
160 lidx++;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
161 }
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
162
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
163 // let the abi rewrite the types as necesary
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
164 gABI->rewriteFunctionType(f);
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
165
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
166 // Tell the ABI we're done with this function type
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
167 gABI->doneWithFunctionType();
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
168
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
169 // build the function type
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
170 std::vector<const LLType*> argtypes;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
171 argtypes.reserve(lidx);
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
172
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
173 if (f->fty.arg_sret) argtypes.push_back(f->fty.arg_sret->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
174 if (f->fty.arg_this) argtypes.push_back(f->fty.arg_this->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
175 if (f->fty.arg_nest) argtypes.push_back(f->fty.arg_nest->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
176 if (f->fty.arg_arguments) argtypes.push_back(f->fty.arg_arguments->ltype);
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
177 if (f->fty.arg_argptr) argtypes.push_back(f->fty.arg_argptr->ltype);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
178
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
179 size_t beg = argtypes.size();
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
180 size_t nargs2 = f->fty.args.size();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
181 for (size_t i = 0; i < nargs2; i++)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
182 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
183 argtypes.push_back(f->fty.args[i]->ltype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
184 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
185
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
186 // reverse params?
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
187 if (f->fty.reverseParams && nargs2 > 1)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
188 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
189 std::reverse(argtypes.begin() + beg, argtypes.end());
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
190 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
191
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
192 llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
193 f->ir.type = new llvm::PATypeHolder(functype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
194
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
195 Logger::cout() << "Final function type: " << *functype << "\n";
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
196
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
197 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
198 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
199
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
200 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
201
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
202 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
203 {
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
204 // type has already been resolved
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
205 if (fdecl->type->ir.type != 0) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
206 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
207 }
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
208
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
209 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
210 const llvm::FunctionType* fty = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
211
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
212 // create new ir funcTy
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
213 f->fty.reset();
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
214 f->fty.ret = new IrFuncTyArg(Type::tvoid, false);
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
215
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
216 f->fty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
217
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
218 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
219 fty = GET_INTRINSIC_DECL(vastart)->getFunctionType();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
220 else if (fdecl->llvmInternal == LLVMva_copy) {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
221 fty = GET_INTRINSIC_DECL(vacopy)->getFunctionType();
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
222 f->fty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false));
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
223 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
224 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
225 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
226 assert(fty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
227
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
228 f->ir.type = new llvm::PATypeHolder(fty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
229 return fty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
230 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
231
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
232 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
233
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
234 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
235 {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
236 // 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
237 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
238 return DtoVaFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
239
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
240 // 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
241 if (fdecl->type->ir.type != 0)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
242 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
243
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
244 Type *dthis=0, *dnest=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
245
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
246 if (fdecl->needThis()) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
247 if (AggregateDeclaration* ad = fdecl->isMember2()) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
248 Logger::println("isMember = this is: %s", ad->type->toChars());
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
249 dthis = ad->type;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
250 const LLType* thisty = DtoType(dthis);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
251 //Logger::cout() << "this llvm type: " << *thisty << '\n';
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
252 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->type->ir.type->get()))
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
253 thisty = getPtrToType(thisty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
254 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
255 else {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
256 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
257 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
258 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
259 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
260 else if (fdecl->isNested()) {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
261 dnest = Type::tvoid->pointerTo();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
262 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
263
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
264 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, dthis, dnest, fdecl->isMain());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
265
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
266 return functype;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
267 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
268
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
269 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
270
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
271 static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
272 {
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
273 TypeFunction* f = (TypeFunction*)fdecl->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
274 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
275 llvm::Function* func = 0;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
276
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
277 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
278 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
279 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
280 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
281 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
282 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
283 assert(func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
284
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
285 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
286 return func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
287 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
288
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
289 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
290
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
291 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
292 {
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
293 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
294 return; // ignore declaration completely
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
295 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
296
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
297 // 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
298 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
299 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
300 if (fdecl->prot() == PROTprivate)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
301 return;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
302 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
303
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
304 if (fdecl->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
305 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
306
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
307 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
308 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
309
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
310 //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
311
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
312 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
313 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
314 {
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
315 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
316 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
317 {
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
318 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
319 fdecl->llvmInternal = LLVMva_arg;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
320 fdecl->ir.declared = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
321 fdecl->ir.initialized = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
322 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
323 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
324 }
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
325 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
326 {
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
327 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
328 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
329 }
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
330 else if (tempdecl->llvmInternal == LLVMintrinsic)
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
331 {
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
332 Logger::println("overloaded intrinsic found");
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
333 fdecl->llvmInternal = LLVMintrinsic;
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
334 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
335 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
336 ((TypeFunction*)fdecl->type)->linkage = LINKintrinsic;
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 526
diff changeset
337 }
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 }
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
339
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 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
341
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
342 // queue declaration
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
343 if (!fdecl->isAbstract())
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
344 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
345 }
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 //////////////////////////////////////////////////////////////////////////////////////////
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
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
349 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
350 {
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
351 int funcNumArgs = func->getArgumentList().size();
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
352
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
353 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
354 llvm::AttributeWithIndex PAWI;
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
355
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
356 int idx = 0;
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
357
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
358 // handle implicit args
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
359 #define ADD_PA(X) \
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
360 if (f->fty.X) { \
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
361 if (f->fty.X->attrs) { \
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
362 PAWI.Index = idx; \
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
363 PAWI.Attrs = f->fty.X->attrs; \
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
364 attrs.push_back(PAWI); \
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
365 } \
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
366 idx++; \
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
367 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
368
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
369 ADD_PA(ret)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
370 ADD_PA(arg_sret)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
371 ADD_PA(arg_this)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
372 ADD_PA(arg_nest)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
373 ADD_PA(arg_arguments)
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
374 ADD_PA(arg_argptr)
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
375
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
376 #undef ADD_PA
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
377
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
378 // 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
379 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
380 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
381
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
382 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
383 {
454
283d113d4753 Added generation of the llvm 'sret' parameter attribute where applicable.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
384 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
385 assert(fnarg);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
386
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
387 attrptr[k] = f->fty.args[k]->attrs;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
388 }
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
389
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
390 // reverse params?
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
391 if (f->fty.reverseParams)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
392 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
393 std::reverse(attrptr.begin(), attrptr.end());
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
394 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
395
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
396 // 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
397 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
398 {
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
399 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
400 {
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
401 PAWI.Index = idx+i;
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
402 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
403 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
404 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
405 }
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
406
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
407 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
408 func->setAttributes(attrlist);
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
409 }
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
410
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
411 //////////////////////////////////////////////////////////////////////////////////////////
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
412
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
413 void DtoDeclareFunction(FuncDeclaration* fdecl)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
414 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
415 if (fdecl->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
416 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
417
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
418 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
419 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
420
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
421 //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
422
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
423 // intrinsic sanity check
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
424 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
425 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
426 fatal();
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
427 }
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
428
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
429 // 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
430 Type* t = fdecl->type->toBasetype();
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
431 TypeFunction* f = (TypeFunction*)t;
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
432
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
433 bool declareOnly = !mustDefineSymbol(fdecl);
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
434
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
435 if (fdecl->llvmInternal == LLVMva_start)
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
436 declareOnly = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
437
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
438 if (!fdecl->ir.irFunc) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
439 fdecl->ir.irFunc = new IrFunction(fdecl);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
440 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
441
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
442 // 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
443 const char* mangled_name;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
444 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
445 mangled_name = fdecl->intrinsicName.c_str();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
446 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
447 mangled_name = fdecl->mangle();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
448
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
449 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
450 if (fdecl->isVaIntrinsic())
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
451 vafunc = DtoDeclareVaFunction(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
452
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
453 // construct function
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
454 const llvm::FunctionType* functype = DtoFunctionType(fdecl);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
455 llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
456 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
457 func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
458
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
459 // add func to IRFunc
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
460 fdecl->ir.irFunc->func = func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
461
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
462 // calling convention
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
463 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
933
d3a6f1a96731 Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 930
diff changeset
464 func->setCallingConv(DtoCallingConv(fdecl->loc, f->linkage));
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
465 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
466 func->setCallingConv(llvm::CallingConv::C);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
467
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
468 fdecl->ir.irFunc->func = func;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
469 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
470
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
471 // 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
472 if (!fdecl->isIntrinsic()) {
240
0db62b770a49 [svn r257] Fixed: array .sort and .reverse runtime code was incorrect.
lindquist
parents: 234
diff changeset
473 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
474 }
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
475
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
476 // main
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
477 if (fdecl->isMain()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
478 gIR->mainFunc = func;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
479 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
480
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
481 // static ctor
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
482 if (fdecl->isStaticCtorDeclaration()) {
958
89729c76b8ff Static ctors/dtors added via template mixins should not be added to modules
Christian Kamm <kamm incasoftware de>
parents: 947
diff changeset
483 if (mustDefineSymbol(fdecl)) {
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
484 gIR->ctors.push_back(fdecl);
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
485 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
486 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
487 // static dtor
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
488 else if (fdecl->isStaticDtorDeclaration()) {
958
89729c76b8ff Static ctors/dtors added via template mixins should not be added to modules
Christian Kamm <kamm incasoftware de>
parents: 947
diff changeset
489 if (mustDefineSymbol(fdecl)) {
934
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
490 gIR->dtors.push_back(fdecl);
b56f3571c450 Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 933
diff changeset
491 }
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
492 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 113
diff changeset
493
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
494 // we never reference parameters of function prototypes
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
495 std::string str;
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
496 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
497 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
498 // 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
499 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
500
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
501 if (f->fty.arg_sret) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
502 iarg->setName(".sret_arg");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
503 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
504 ++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
505 }
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
506
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
507 if (f->fty.arg_this) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
508 iarg->setName(".this_arg");
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
509 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
510 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
511 ++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
512 }
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
513 else if (f->fty.arg_nest) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
514 iarg->setName(".nest_arg");
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
515 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
516 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
517 ++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
518 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
519
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
520 if (f->fty.arg_argptr) {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
521 iarg->setName("._arguments");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
522 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
523 ++iarg;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
524 iarg->setName("._argptr");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
525 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
526 ++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
527 }
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 117
diff changeset
528
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
529 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
530
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
531 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
532 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
533 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
534 {
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
535 Dsymbol* argsym;
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
536 if (f->fty.reverseParams)
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
537 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
538 else
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
539 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
540
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
541 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
542 assert(argvd);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
543 assert(!argvd->ir.irLocal);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
544 argvd->ir.irLocal = new IrLocal(argvd);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
545 argvd->ir.irLocal->value = iarg;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
546
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
547 str = argvd->ident->toChars();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
548 str.append("_arg");
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
549 iarg->setName(str);
723
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
550
55f6c2e454d7 Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
551 k++;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
552 }
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 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
554 {
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
555 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
556 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
557 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
558 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
559
830
504a21e81a46 Only run unittests contained directly in the module.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
560 if (fdecl->isUnitTestDeclaration() && !declareOnly)
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
561 gIR->unitTests.push_back(fdecl);
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 119
diff changeset
562
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
563 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
564 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
565 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
566 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
567
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
568 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
569 Logger::cout() << "func decl: " << *func << '\n';
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
570 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
571
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
572 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
573
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
574 // FIXME: this isn't too pretty!
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
575
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
576 void DtoDefineFunction(FuncDeclaration* fd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
577 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
578 if (fd->ir.defined) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
579 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
580
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
581 assert(fd->ir.declared);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
582
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
583 if (Logger::enabled())
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1045
diff changeset
584 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
585 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
586
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
587 // if this function is naked, we take over right away! no standard processing!
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
588 if (fd->naked)
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
589 {
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
590 DtoDefineNakedFunction(fd);
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
591 return;
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
592 }
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
593
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
594 // debug info
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
595 if (global.params.symdebug) {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
596 fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
597 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
598
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
599 Type* t = fd->type->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
600 TypeFunction* f = (TypeFunction*)t;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
601 assert(f->ir.type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
602
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
603 llvm::Function* func = fd->ir.irFunc->func;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
604 const llvm::FunctionType* functype = func->getFunctionType();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
605
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
606 // sanity check
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 939
diff changeset
607 assert(mustDefineSymbol(fd));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
608
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
609 // 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
610 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
611
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
612 // 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
613 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
614 return;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
615
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
616 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
617 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
618 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
619 gIR->functions.push_back(irfunction);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
620
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
621 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
622 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
623
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
624 std::string entryname("entry");
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
625
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
626 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
627 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endentry",func);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
628
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
629 //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
630 gIR->scopes.push_back(IRScope(beginbb, endbb));
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
631
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
632 // 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
633 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
634 irfunction->allocapoint = allocaPoint;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
635
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 449
diff changeset
636 // 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
637 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
638
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
639 // 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
640 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
641 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
642 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
643 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
644 }
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
645
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
646 // 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
647 // this this eliminates a bunch of inline asm related issues.
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 838
diff changeset
648 if (fd->inlineAsm)
526
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
649 {
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
650 // 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
651 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
652 gIR->ir->CreateCall(hack, "");
642f6fa854e5 First step towards D abi compliance.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 523
diff changeset
653 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
654
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
655 // give the 'this' argument storage and debug info
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
656 if (f->fty.arg_this)
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
657 {
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
658 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
659 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
660
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
661 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
662 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
663 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
664
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
665 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
666 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
667 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
668
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
669 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
670 DtoDwarfLocalVariable(thismem, fd->vthis);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
671
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
672 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
673 if (fd->vthis->nestedrefs.dim)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
674 #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
675 if (fd->vthis->nestedref)
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
676 #endif
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
677 {
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
678 fd->nestedVars.insert(fd->vthis);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
679 }
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
680 }
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
681
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
682 // 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
683 // 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
684 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
685 {
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
686 size_t n = f->fty.args.size();
1024
9167d492cbc2 Abstracted more (most) ABI details out of the normal codegen.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1018
diff changeset
687 assert(n == fd->parameters->dim);
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 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
689 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
690 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
691 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
692 assert(vd);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
693
930
7985bb036db4 Follow the D ABI and pass the last arg in a register if it is a struct that fits.
Christian Kamm <kamm incasoftware de>
parents: 920
diff changeset
694 IrLocal* irloc = vd->ir.irLocal;
7985bb036db4 Follow the D ABI and pass the last arg in a register if it is a struct that fits.
Christian Kamm <kamm incasoftware de>
parents: 920
diff changeset
695 assert(irloc);
7985bb036db4 Follow the D ABI and pass the last arg in a register if it is a struct that fits.
Christian Kamm <kamm incasoftware de>
parents: 920
diff changeset
696
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
697 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
698 if (vd->nestedrefs.dim)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
699 #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
700 if (vd->nestedref)
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
701 #endif
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
702 {
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 fd->nestedVars.insert(vd);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
704 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
705
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
706 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
707 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
708
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
709 if (!refout && (!f->fty.args[i]->byref || lazy))
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
710 {
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
711 // alloca a stack slot for this first class value arg
1045
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
712 const LLType* argt;
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
713 if (lazy)
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
714 argt = irloc->value->getType();
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
715 else
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
716 argt = DtoType(vd->type);
a91d6fc600cd Fixed lazy arguments again.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1042
diff changeset
717 LLValue* mem = DtoAlloca(argt, vd->ident->toChars());
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
718
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
719 // let the abi transform the argument back first
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
720 DImValue arg_dval(vd->type, irloc->value);
1051
dc608dc33081 Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
Christian Kamm <kamm incasoftware de>
parents: 1049
diff changeset
721 f->fty.getParam(vd->type, i, &arg_dval, mem);
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
722
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
723 // set the arg var value to the alloca
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
724 irloc->value = mem;
254
8187884566fa [svn r271] Fixed debug info for implicit 'this' param.
lindquist
parents: 250
diff changeset
725 }
1042
45af482e3832 Updated ABI handling to be more flexible with regard to reusing lvalues and allocating fewer temporaries.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1024
diff changeset
726
752
2d7bcfa68128 Enable function parameter debug info for a wider range of args.
Christian Kamm <kamm incasoftware de>
parents: 739
diff changeset
727 if (global.params.symdebug && !(isaArgument(irloc->value) && !isaArgument(irloc->value)->hasByValAttr()) && !refout)
2d7bcfa68128 Enable function parameter debug info for a wider range of args.
Christian Kamm <kamm incasoftware de>
parents: 739
diff changeset
728 DtoDwarfLocalVariable(irloc->value, vd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
729 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
730 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
731
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
732 // need result variable? (nested)
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
733 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
734 if (fd->vresult && fd->vresult->nestedrefs.dim) {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
735 #else
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
736 if (fd->vresult && fd->vresult->nestedref) {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
737 #endif
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
738 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
739 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
740 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
741
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
742 // 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
743 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
744 {
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
745 Logger::println("has nested frame");
838
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
746 // start with adding all enclosing parent frames until a static parent is reached
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
747 int nparelems = 0;
838
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
748 if (!fd->isStatic())
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
749 {
838
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
750 Dsymbol* par = fd->toParent2();
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
751 while (par)
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
752 {
838
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
753 if (FuncDeclaration* parfd = par->isFuncDeclaration())
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
754 {
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
755 nparelems += parfd->nestedVars.size();
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
756 // stop at first static
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
757 if (parfd->isStatic())
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
758 break;
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
759 }
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
760 else if (ClassDeclaration* parcd = par->isClassDeclaration())
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
761 {
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
762 // nothing needed
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
763 }
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
764 else
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
765 {
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
766 break;
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
767 }
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
768
94ba810ea2b0 Fixed problem with nested function inside static nested function. see mini/compile_nested2.d. fixes #143 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
769 par = par->toParent2();
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
770 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
771 }
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
772 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
773
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 // 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
775 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
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 // 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
778 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
779
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 // 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
781 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
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 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
784 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
785 {
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 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
787 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
788 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
789 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
790 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
791 assert(cd->vthis);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
792 src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".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
793 }
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 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
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
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 // 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
798 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
799
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 // 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
801 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
802 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
803 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
804 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
805 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
806 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
807
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 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
809 {
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 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
811 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
812 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
813 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
814 }
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
815 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
816 {
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 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
818 }
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
819
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 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
821 }
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
822
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
823 // fixup nested result variable
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
824 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
825 if (fd->vresult && fd->vresult->nestedrefs.dim) {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
826 #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
827 if (fd->vresult && fd->vresult->nestedref) {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 752
diff changeset
828 #endif
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
829 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
830 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
831 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
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 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
834 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
835
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
836 // 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
837 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
838 {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
839 // _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
840 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
841 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
842 fd->ir.irFunc->_argptr = argptrmem;
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
843
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
844 // _arguments
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 632
diff changeset
845 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
846 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
847 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
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 // 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
851 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
852
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
853 // TODO: clean up this mess
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
854
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
855 // std::cout << *func << std::endl;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
856
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
857 // 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
858 // 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
859 if (!gIR->scopereturned()) {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
860 // 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
861 if (global.params.symdebug) DtoDwarfFuncEnd(fd);
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
862 if (func->getReturnType() == LLType::VoidTy) {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
863 llvm::ReturnInst::Create(gIR->scopebb());
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
864 }
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
865 else {
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
866 if (!fd->isMain())
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
867 {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
868 AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
869 if (asmb) {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
870 assert(asmb->abiret);
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
871 llvm::ReturnInst::Create(asmb->abiret, gIR->scopebb());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
872 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
873 else {
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
874 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
875 }
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
876 }
428
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
877 else
8b7cee241e91 Enable insertion of missing terminator instruction for main.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
878 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
879 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
880 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
881
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
882 // std::cout << *func << std::endl;
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
883
244
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
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
895 gIR->functions.pop_back();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 241
diff changeset
896
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
897 // std::cout << *func << std::endl;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
898 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
899
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
900 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
901
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
902 const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
903 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
904 Dsymbol* parent = fdecl->toParent();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
905 ClassDeclaration* cd = parent->isClassDeclaration();
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
906 assert(cd);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
907
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
908 FuncDeclaration* f = fdecl;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
909
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
910 while (cd)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
911 {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
912 ClassDeclaration* base = cd->baseClass;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
913 if (!base)
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
914 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
915 FuncDeclaration* f2 = base->findFunc(fdecl->ident, (TypeFunction*)fdecl->type);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
916 if (f2) {
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
917 f = f2;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
918 cd = base;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
919 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
920 else
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
921 break;
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
922 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
923
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
924 DtoResolveDsymbol(f);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
925 return llvm::cast<llvm::FunctionType>(DtoType(f->type));
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
926 }
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
927
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 116
diff changeset
928 //////////////////////////////////////////////////////////////////////////////////////////
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
929
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
930 DValue* DtoArgument(Argument* fnarg, Expression* argexp)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
931 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
932 Logger::println("DtoArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
933 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
934
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
935 DValue* arg = argexp->toElem(gIR);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
936
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
937 // 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
938 if (fnarg && (fnarg->storageClass & (STCref | STCout)))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
939 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
940 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
941 arg = new DImValue(argexp->type, arg->getLVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
942 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
943 arg = new DImValue(argexp->type, arg->getRVal());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
944 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
945 // lazy arg
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
946 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
947 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
948 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
949 assert(!arg->isLVal());
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
950 return arg;
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
951 }
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
952 // 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
953 else if (DtoIsPassedByRef(argexp->type) && (arg->isSlice() || arg->isNull()))
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
954 {
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
955 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
956 DVarValue* vv = new DVarValue(argexp->type, alloc);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
957 DtoAssign(argexp->loc, vv, arg);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
958 arg = vv;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
959 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
960
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
961 return arg;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
962 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
963
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
964 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
965
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
966 void DtoVariadicArgument(Expression* argexp, LLValue* dst)
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
967 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
968 Logger::println("DtoVariadicArgument");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
969 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
970 DVarValue vv(argexp->type, dst);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 379
diff changeset
971 DtoAssign(argexp->loc, &vv, argexp->toElem(gIR));
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
972 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
973
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
974 //////////////////////////////////////////////////////////////////////////////////////////
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
975
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
976 bool FuncDeclaration::isIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
977 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
978 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
979 }
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
980
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
981 bool FuncDeclaration::isVaIntrinsic()
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
982 {
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
983 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
984 llvmInternal == LLVMva_copy ||
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
985 llvmInternal == LLVMva_end);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
986 }