annotate gen/classes.cpp @ 1252:7c1b55db4ff3

Fixed emitting declarations nested inside interfaces.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Tue, 21 Apr 2009 19:32:22 +0200
parents e1b0c5c74c58
children 752bed475b75
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"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
2
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
3 #include "mtype.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
4 #include "aggregate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
5 #include "init.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
6 #include "declaration.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
7
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
8 #include "gen/irstate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
9 #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: 217
diff changeset
10 #include "gen/llvmhelpers.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
11 #include "gen/arrays.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
12 #include "gen/logger.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
13 #include "gen/classes.h"
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
14 #include "gen/structs.h"
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
15 #include "gen/functions.h"
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
16 #include "gen/runtime.h"
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
17 #include "gen/dvalue.h"
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1149
diff changeset
18 #include "gen/nested.h"
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
19 #include "gen/utils.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
20
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
21 #include "ir/irstruct.h"
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
22 #include "ir/irtypeclass.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
23
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
24 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
25
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
26 // FIXME: this needs to be cleaned up
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
27
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
28 void DtoResolveClass(ClassDeclaration* cd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
29 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
30 // make sure the base classes are processed first
1244
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
31 ArrayIter<BaseClass> base_iter(cd->baseclasses);
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
32 while (base_iter.more())
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
33 {
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
34 BaseClass* bc = base_iter.get();
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
35 if (bc)
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
36 {
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
37 bc->base->codegen(Type::sir);
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
38 }
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
39 base_iter.next();
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
40 }
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
41
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 169
diff changeset
42 if (cd->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 169
diff changeset
43 cd->ir.resolved = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
44
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
45 Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
46 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
47
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
48 // make sure type exists
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
49 DtoType(cd->type);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
50
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
51 // create IrStruct
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
52 assert(cd->ir.irStruct == NULL);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
53 IrStruct* irstruct = new IrStruct(cd);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
54 cd->ir.irStruct = irstruct;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
55
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
56 bool needs_def = mustDefineSymbol(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
57
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
58 // emit the ClassZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
59 LLGlobalVariable* ClassZ = irstruct->getClassInfoSymbol();
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
60
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
61 // interface only emit typeinfo and classinfo
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
62 if (!cd->isInterfaceDeclaration())
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
63 {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
64 // emit the initZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
65 LLGlobalVariable* initZ = irstruct->getInitSymbol();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
66 // emit the vtblZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
67 LLGlobalVariable* vtblZ = irstruct->getVtblSymbol();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
68
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
69 // emit the interfaceInfosZ symbol if necessary
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
70 if (cd->vtblInterfaces && cd->vtblInterfaces->dim > 0)
1229
fafe7c8d6734 Now compiles again, and fixed type of the Interface[N] ClassInfo symbol.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
71 irstruct->getInterfaceArraySymbol(); // initializer is applied when it's built
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
72
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
73 // perform definition
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
74 if (needs_def)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
75 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
76 // set symbol initializers
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
77 initZ->setInitializer(irstruct->getDefaultInit());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
78 vtblZ->setInitializer(irstruct->getVtblInit());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
79 }
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
80 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
81
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
82 // emit members
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
83 if (cd->members)
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
84 {
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
85 ArrayIter<Dsymbol> it(*cd->members);
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
86 while (!it.done())
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
87 {
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
88 Dsymbol* member = it.get();
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
89 if (member)
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
90 member->codegen(Type::sir);
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
91 it.next();
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
92 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
93 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
94
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
95 if (needs_def)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
96 {
1239
ff1b4cc2e9be Make !TypeInfo output lazy unless we need to provide full definitions in general.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1231
diff changeset
97 // emit typeinfo
ff1b4cc2e9be Make !TypeInfo output lazy unless we need to provide full definitions in general.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1231
diff changeset
98 DtoTypeInfoOf(cd->type);
ff1b4cc2e9be Make !TypeInfo output lazy unless we need to provide full definitions in general.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1231
diff changeset
99
ff1b4cc2e9be Make !TypeInfo output lazy unless we need to provide full definitions in general.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1231
diff changeset
100 // define classinfo
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
101 ClassZ->setInitializer(irstruct->getClassInfoInit());
1149
5ebe8224988b Fixed problems introduced by previous commits that prevented Tango from compiling.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
102 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
103 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
104
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
105 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
106
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
107 DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
108 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
109 // resolve type
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
110 tc->sym->codegen(Type::sir);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
111
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
112 // allocate
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
113 LLValue* mem;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
114 if (newexp->onstack)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
115 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 423
diff changeset
116 mem = DtoAlloca(DtoType(tc)->getContainedType(0), ".newclass_alloca");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
117 }
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
118 // custom allocator
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
119 else if (newexp->allocator)
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
120 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
121 newexp->allocator->codegen(Type::sir);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 370
diff changeset
122 DFuncValue dfn(newexp->allocator, newexp->allocator->ir.irFunc->func);
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
123 DValue* res = DtoCallFunction(newexp->loc, NULL, &dfn, newexp->newargs);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 370
diff changeset
124 mem = DtoBitCast(res->getRVal(), DtoType(tc), ".newclass_custom");
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
125 }
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
126 // default allocator
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
127 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
128 {
728
635f91212b78 Change _d_newclass into _d_allocclass. Add initialization to ClassInfo.create.
Christian Kamm <kamm incasoftware de>
parents: 705
diff changeset
129 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocclass");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
130 LLConstant* ci = DtoBitCast(tc->sym->ir.irStruct->getClassInfoSymbol(), DtoType(ClassDeclaration::classinfo->type));
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
131 mem = gIR->CreateCallOrInvoke(fn, ci, ".newclass_gc_alloc").getInstruction();
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 370
diff changeset
132 mem = DtoBitCast(mem, DtoType(tc), ".newclass_gc");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
133 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
134
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
135 // init
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
136 DtoInitClass(tc, mem);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
137
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
138 // init inner-class outer reference
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
139 if (newexp->thisexp)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
140 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
141 Logger::println("Resolving outer class");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
142 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
143 DValue* thisval = newexp->thisexp->toElem(gIR);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
144 size_t idx = tc->sym->vthis->ir.irField->index;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
145 LLValue* src = thisval->getRVal();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
146 LLValue* dst = DtoGEPi(mem,0,idx,"tmp");
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: 618
diff changeset
147 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: 618
diff changeset
148 Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n';
169
2df270e1ba59 [svn r185] Fixed broken nested classes with data members, did DMD change the class layout? tango.text.Regex now compiles.
lindquist
parents: 163
diff changeset
149 DtoStore(src, dst);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
150 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
151 // set the context for nested classes
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
152 else if (tc->sym->isNested() && tc->sym->vthis)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
153 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
154 Logger::println("Resolving nested context");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
155 LOG_SCOPE;
369
7d91d82000ae [svn r390] Make the zero value used when no nested context was created of the correct type.
ChristianK
parents: 363
diff changeset
156
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
157 // get context
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
158 LLValue* nest = DtoNestedContext(loc, tc->sym);
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
159
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
160 // store into right location
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
161 size_t idx = tc->sym->vthis->ir.irField->index;
370
051ab876fe11 [svn r391] Fix classes nested inside functions for real.
ChristianK
parents: 369
diff changeset
162 LLValue* gep = DtoGEPi(mem,0,idx,"tmp");
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
163 DtoStore(DtoBitCast(nest, gep->getType()->getContainedType(0)), gep);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
164 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
165
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
166 // call constructor
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
167 if (newexp->member)
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
168 {
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1013
diff changeset
169 Logger::println("Calling constructor");
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
170 assert(newexp->arguments != NULL);
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
171 newexp->member->codegen(Type::sir);
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 370
diff changeset
172 DFuncValue dfn(newexp->member, newexp->member->ir.irFunc->func, mem);
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
173 return DtoCallFunction(newexp->loc, tc, &dfn, newexp->arguments);
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
174 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
175
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
176 // return default constructed class
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
177 return new DImValue(tc, mem);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
178 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
179
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
180 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
181
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
182 void DtoInitClass(TypeClass* tc, LLValue* dst)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
183 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
184 tc->sym->codegen(Type::sir);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
185
945
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
186 size_t presz = 2*getTypePaddedSize(DtoSize_t());
03d7c4aac654 SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 940
diff changeset
187 uint64_t n = getTypePaddedSize(tc->ir.type->get()) - presz;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
188
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
189 // set vtable field seperately, this might give better optimization
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
190 LLValue* tmp = DtoGEPi(dst,0,0,"vtbl");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
191 LLValue* val = DtoBitCast(tc->sym->ir.irStruct->getVtblSymbol(), tmp->getType()->getContainedType(0));
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
192 DtoStore(val, tmp);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
193
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
194 // monitor always defaults to zero
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
195 tmp = DtoGEPi(dst,0,1,"monitor");
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
196 val = llvm::Constant::getNullValue(tmp->getType()->getContainedType(0));
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
197 DtoStore(val, tmp);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
198
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
199 // done?
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
200 if (n == 0)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
201 return;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
202
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
203 // copy the rest from the static initializer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
204 LLValue* dstarr = DtoGEPi(dst,0,2,"tmp");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
205 LLValue* srcarr = DtoGEPi(tc->sym->ir.irStruct->getInitSymbol(),0,2,"tmp");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
206
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
207 DtoMemCpy(dstarr, srcarr, DtoConstSize_t(n));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
208 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
209
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
210 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
211
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
212 void DtoFinalizeClass(LLValue* inst)
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
213 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
214 // get runtime function
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
215 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_callfinalizer");
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
216 // build args
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
217 LLSmallVector<LLValue*,1> arg;
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
218 arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
219 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
220 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end(), "");
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
221 }
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
222
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
223 //////////////////////////////////////////////////////////////////////////////////////////
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 205
diff changeset
224
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
225 DValue* DtoCastClass(DValue* val, Type* _to)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
226 {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
227 Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars());
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
228 LOG_SCOPE;
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
229
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
230 Type* to = _to->toBasetype();
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
231
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
232 // class -> pointer
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
233 if (to->ty == Tpointer) {
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
234 Logger::println("to pointer");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
235 const LLType* tolltype = DtoType(_to);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
236 LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
237 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
238 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
239 // class -> bool
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
240 else if (to->ty == Tbool) {
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
241 Logger::println("to bool");
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
242 LLValue* llval = val->getRVal();
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
243 LLValue* zero = LLConstant::getNullValue(llval->getType());
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
244 return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp"));
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
245 }
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
246
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
247 // must be class/interface
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
248 assert(to->ty == Tclass);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
249 TypeClass* tc = (TypeClass*)to;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
250
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
251 // from type
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
252 Type* from = val->getType()->toBasetype();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
253 TypeClass* fc = (TypeClass*)from;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
254
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
255 // x -> interface
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
256 if (InterfaceDeclaration* it = tc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
257 Logger::println("to interface");
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
258 // interface -> interface
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
259 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
260 Logger::println("from interface");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
261 return DtoDynamicCastInterface(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
262 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
263 // class -> interface - static cast
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
264 else if (it->isBaseOf(fc->sym,NULL)) {
833
482cd74d1c71 Add all base interfaces to interfaceMap, not just direct parents.
Christian Kamm <kamm incasoftware de>
parents: 825
diff changeset
265 Logger::println("static down cast");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
266
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
267 // get the from class
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
268 ClassDeclaration* cd = fc->sym->isClassDeclaration();
840
a125ada7fd95 more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 839
diff changeset
269 DtoResolveClass(cd); // add this
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
270 IrStruct* irstruct = cd->ir.irStruct;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
271 IrTypeClass* typeclass = fc->irtype->isClass();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
272
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
273 // find interface impl
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
274
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
275 size_t i_index = typeclass->getInterfaceIndex(it);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
276 assert(i_index != ~0 && "requesting interface that is not implemented by this class");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
277
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
278 // offset pointer
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
279 LLValue* v = val->getRVal();
1128
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
280 LLValue* orig = v;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
281 v = DtoGEPi(v, 0, i_index);
1128
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
282 const LLType* ifType = DtoType(_to);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
283 if (Logger::enabled())
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
284 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
285 Logger::cout() << "V = " << *v << std::endl;
1128
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
286 Logger::cout() << "T = " << *ifType << std::endl;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
287 }
1128
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
288 v = DtoBitCast(v, ifType);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
289
1128
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
290 // Check whether the original value was null, and return null if so.
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
291 // Sure we could have jumped over the code above in this case, but
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
292 // it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
293 // should be pretty cheap and perfectly safe even if the original was null.
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
294 LLValue* isNull = gIR->ir->CreateICmpEQ(orig, LLConstant::getNullValue(orig->getType()), ".nullcheck");
83ef1e7cde70 Return null from a static class to interface cast if the class reference was
Frits van Bommel <fvbommel wxs.nl>
parents: 1047
diff changeset
295 v = gIR->ir->CreateSelect(isNull, LLConstant::getNullValue(ifType), v, ".interface");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
296
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
297 // return r-value
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
298 return new DImValue(_to, v);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
299 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
300 // class -> interface
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
301 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
302 Logger::println("from object");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
303 return DtoDynamicCastObject(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
304 }
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
305 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
306 // x -> class
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
307 else {
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
308 Logger::println("to class");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
309 int poffset;
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
310 // interface -> class
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
311 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
312 Logger::println("interface cast");
906
f1ed7fe85138 Casts from interface to class generally need to be dynamic. Fixes #189.
Christian Kamm <kamm incasoftware de>
parents: 840
diff changeset
313 return DtoDynamicCastInterface(val, _to);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
314 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
315 // class -> class - static down cast
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
316 else if (tc->sym->isBaseOf(fc->sym,NULL)) {
906
f1ed7fe85138 Casts from interface to class generally need to be dynamic. Fixes #189.
Christian Kamm <kamm incasoftware de>
parents: 840
diff changeset
317 Logger::println("static down cast");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
318 const LLType* tolltype = DtoType(_to);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
319 LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
320 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
321 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
322 // class -> class - dynamic up cast
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
323 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
324 Logger::println("dynamic up cast");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
325 return DtoDynamicCastObject(val, _to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
326 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
327 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
328 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
329
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
330 //////////////////////////////////////////////////////////////////////////////////////////
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
331
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
332 DValue* DtoDynamicCastObject(DValue* val, Type* _to)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
333 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
334 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
335 // Object _d_dynamic_cast(Object o, ClassInfo c)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
336
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
337 ClassDeclaration::object->codegen(Type::sir);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
338 ClassDeclaration::classinfo->codegen(Type::sir);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
339
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
340 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
341 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
342
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
343 std::vector<LLValue*> args;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
344
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
345 // Object o
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
346 LLValue* obj = val->getRVal();
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
347 obj = DtoBitCast(obj, funcTy->getParamType(0));
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
348 assert(funcTy->getParamType(0) == obj->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
349
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
350 // ClassInfo c
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
351 TypeClass* to = (TypeClass*)_to->toBasetype();
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
352 to->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
353
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
354 LLValue* cinfo = to->sym->ir.irStruct->getClassInfoSymbol();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
355 // unfortunately this is needed as the implementation of object differs somehow from the declaration
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
356 // this could happen in user code as well :/
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
357 cinfo = DtoBitCast(cinfo, funcTy->getParamType(1));
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
358 assert(funcTy->getParamType(1) == cinfo->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
359
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
360 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
361 LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp").getInstruction();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
362
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
363 // cast return value
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
364 ret = DtoBitCast(ret, DtoType(_to));
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
365
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
366 return new DImValue(_to, ret);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
367 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
368
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
369 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
370
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
371 DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
372 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
373 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
374 // Object _d_toObject(void* p)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
375
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
376 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_toObject");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
377 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
378
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
379 // void* p
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
380 LLValue* tmp = val->getRVal();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
381 tmp = DtoBitCast(tmp, funcTy->getParamType(0));
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
382
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
383 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
384 LLValue* ret = gIR->CreateCallOrInvoke(func, tmp, "tmp").getInstruction();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
385
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
386 // cast return value
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
387 if (to != NULL)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
388 ret = DtoBitCast(ret, DtoType(to));
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
389 else
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
390 to = ClassDeclaration::object->type;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
391
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
392 return new DImValue(to, ret);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
393 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
394
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
395 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
396
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
397 DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
398 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
399 // call:
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
400 // Object _d_interface_cast(void* p, ClassInfo c)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
401
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
402 ClassDeclaration::object->codegen(Type::sir);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
403 ClassDeclaration::classinfo->codegen(Type::sir);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
404
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
405 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
406 const llvm::FunctionType* funcTy = func->getFunctionType();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
407
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
408 std::vector<LLValue*> args;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
409
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
410 // void* p
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
411 LLValue* ptr = val->getRVal();
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
412 ptr = DtoBitCast(ptr, funcTy->getParamType(0));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
413
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
414 // ClassInfo c
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
415 TypeClass* to = (TypeClass*)_to->toBasetype();
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
416 to->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
417 LLValue* cinfo = to->sym->ir.irStruct->getClassInfoSymbol();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
418 // unfortunately this is needed as the implementation of object differs somehow from the declaration
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
419 // this could happen in user code as well :/
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
420 cinfo = DtoBitCast(cinfo, funcTy->getParamType(1));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
421
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
422 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
423 LLValue* ret = gIR->CreateCallOrInvoke2(func, ptr, cinfo, "tmp").getInstruction();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
424
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
425 // cast return value
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
426 ret = DtoBitCast(ret, DtoType(_to));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
427
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
428 return new DImValue(_to, ret);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
429 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
430
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
431 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
432
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
433 LLValue* DtoIndexClass(LLValue* src, ClassDeclaration* cd, VarDeclaration* vd)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
434 {
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
435 Logger::println("indexing class field %s:", vd->toPrettyChars());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
436 LOG_SCOPE;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
437
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
438 if (Logger::enabled())
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
439 Logger::cout() << "src: " << *src << '\n';
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
440
839
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
441 // make sure class is resolved
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
442 DtoResolveClass(cd);
162a0502a6b9 Fixed another moreatatime (as opposed to oneatatime) issue with indexing unresolved class.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 837
diff changeset
443
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
444 // vd must be a field
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
445 IrField* field = vd->ir.irField;
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
446 assert(field);
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
447
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
448 // get the start pointer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
449 const LLType* st = DtoType(cd->type);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
450 // cast to the struct type
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
451 src = DtoBitCast(src, st);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
452
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
453 // gep to the index
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
454 if (Logger::enabled())
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
455 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
456 Logger::cout() << "src2: " << *src << '\n';
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
457 Logger::cout() << "index: " << field->index << '\n';
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
458 Logger::cout() << "srctype: " << *src->getType() << '\n';
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
459 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
460 LLValue* val = DtoGEPi(src, 0, field->index);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
461
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
462 // do we need to offset further? (union area)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
463 if (field->unionOffset)
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
464 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
465 // cast to void*
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
466 val = DtoBitCast(val, getVoidPtrType());
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
467 // offset
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
468 val = DtoGEPi1(val, field->unionOffset);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
469 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
470
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
471 // cast it to the right type
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
472 val = DtoBitCast(val, getPtrToType(DtoType(vd->type)));
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
473
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
474 if (Logger::enabled())
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
475 Logger::cout() << "value: " << *val << '\n';
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
476
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 669
diff changeset
477 return val;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
478 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
479
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
480 //////////////////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
481
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
482 LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
483 {
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
484 // sanity checks
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
485 assert(fdecl->isVirtual());
837
331a176c1f4f Removed error on naked, not fully complete, but I'll be doing more work on it during this Christmas, and some things do work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 835
diff changeset
486 assert(!fdecl->isFinal());
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
487 assert(fdecl->vtblIndex > 0); // 0 is always ClassInfo/Interface*
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
488 assert(inst->getType()->toBasetype()->ty == Tclass);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
489
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
490 // get instance
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
491 LLValue* vthis = inst->getRVal();
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: 618
diff changeset
492 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: 618
diff changeset
493 Logger::cout() << "vthis: " << *vthis << '\n';
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
494
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
495 LLValue* funcval = vthis;
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
496 // get the vtbl for objects
1231
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
497 funcval = DtoGEPi(funcval, 0, 0, "tmp");
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
498 // load vtbl ptr
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
499 funcval = DtoLoad(funcval);
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
500 // index vtbl
804
236f4b5eddca Removed use of DMD's toPrettyChars function for providing llvm value names.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 803
diff changeset
501 funcval = DtoGEPi(funcval, 0, fdecl->vtblIndex, fdecl->toChars());
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
502 // load funcptr
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
503 funcval = DtoAlignedLoad(funcval);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
504
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: 618
diff changeset
505 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: 618
diff changeset
506 Logger::cout() << "funcval: " << *funcval << '\n';
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
507
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
508 // cast to final funcptr type
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
509 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type)));
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: 618
diff changeset
510 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: 618
diff changeset
511 Logger::cout() << "funcval casted: " << *funcval << '\n';
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
512
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
513 return funcval;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
514 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
515
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
516 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
517
821
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
518 #if GENERATE_OFFTI
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
519
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
520 // build a single element for the OffsetInfo[] of ClassInfo
835
3afe9f276db7 Added back a bunch of static's to gen/classes.cpp, it's not superfluous, it makes the functions internal to the compilation unit, and we don't call them anywhere else.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 833
diff changeset
521 static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
522 {
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
523 std::vector<LLConstant*> inits(2);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
524
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
525 // size_t offset;
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
526 //
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 268
diff changeset
527 assert(vd->ir.irField);
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
528 // grab the offset from llvm and the formal class type
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
529 size_t offset = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index);
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
530 // offset nested struct/union fields
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
531 offset += vd->ir.irField->unionOffset;
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
532
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
533 // assert that it matches DMD
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
534 Logger::println("offsets: %lu vs %u", offset, vd->offset);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
535 assert(offset == vd->offset);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
536
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
537 inits[0] = DtoConstSize_t(offset);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
538
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
539 // TypeInfo ti;
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
540 inits[1] = DtoTypeInfoOf(vd->type, true);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
541
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
542 // done
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
543 return llvm::ConstantStruct::get(inits);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
544 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
545
835
3afe9f276db7 Added back a bunch of static's to gen/classes.cpp, it's not superfluous, it makes the functions internal to the compilation unit, and we don't call them anywhere else.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 833
diff changeset
546 static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
547 {
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
548 IrStruct* irstruct = cd->ir.irStruct;
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
549
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
550 size_t nvars = irstruct->varDecls.size();
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
551 std::vector<LLConstant*> arrayInits(nvars);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
552
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
553 for (size_t i=0; i<nvars; i++)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
554 {
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
555 arrayInits[i] = build_offti_entry(cd, irstruct->varDecls[i]);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
556 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
557
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
558 LLConstant* size = DtoConstSize_t(nvars);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
559 LLConstant* ptr;
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
560
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
561 if (nvars == 0)
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
562 return LLConstant::getNullValue( arrayT );
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
563
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
564 // array type
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
565 const llvm::ArrayType* arrTy = llvm::ArrayType::get(arrayInits[0]->getType(), nvars);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
566 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
567
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
568 // mangle
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
569 std::string name(cd->type->vtinfo->toChars());
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
570 name.append("__OffsetTypeInfos");
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 147
diff changeset
571
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
572 // create symbol
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
573 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,DtoInternalLinkage(cd),arrInit,name,gIR->module);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
574 ptr = DtoBitCast(gvar, getPtrToType(arrTy->getElementType()));
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
575
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
576 return DtoConstSlice(size, ptr);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
577 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
578
821
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
579 #endif // GENERATE_OFFTI
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
580
835
3afe9f276db7 Added back a bunch of static's to gen/classes.cpp, it's not superfluous, it makes the functions internal to the compilation unit, and we don't call them anywhere else.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 833
diff changeset
581 static LLConstant* build_class_dtor(ClassDeclaration* cd)
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
582 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
583 FuncDeclaration* dtor = cd->dtor;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
584
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
585 // if no destructor emit a null
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
586 if (!dtor)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
587 return getNullPtr(getVoidPtrType());
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
588
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
589 dtor->codegen(Type::sir);
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
590 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty));
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
591 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
592
835
3afe9f276db7 Added back a bunch of static's to gen/classes.cpp, it's not superfluous, it makes the functions internal to the compilation unit, and we don't call them anywhere else.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 833
diff changeset
593 static unsigned build_classinfo_flags(ClassDeclaration* cd)
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
594 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
595 // adapted from original dmd code
285
297690b5d4a5 [svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents: 284
diff changeset
596 unsigned flags = 0;
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
597 //flags |= isCOMclass(); // IUnknown
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
598 bool hasOffTi = false;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
599 if (cd->ctor) flags |= 8;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
600 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
601 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
602 if (cd2->members)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
603 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
604 for (size_t i = 0; i < cd2->members->dim; i++)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
605 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
606 Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 271
diff changeset
607 if (sm->isVarDeclaration() && !sm->isVarDeclaration()->isDataseg()) // is this enough?
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
608 hasOffTi = true;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
609 //printf("sm = %s %s\n", sm->kind(), sm->toChars());
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
610 if (sm->hasPointers())
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
611 goto L2;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
612 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
613 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
614 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
615 flags |= 2; // no pointers
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
616 L2:
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
617 if (hasOffTi)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
618 flags |= 4;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
619 return flags;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
620 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
621
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
622 LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
623 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
624 // The layout is:
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
625 // {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
626 // void **vptr;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
627 // monitor_t monitor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
628 // byte[] initializer; // static initialization data
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
629 // char[] name; // class name
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
630 // void *[] vtbl;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
631 // Interface[] interfaces;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
632 // ClassInfo *base; // base class
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
633 // void *destructor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
634 // void *invariant; // class invariant
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
635 // uint flags;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
636 // void *deallocator;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
637 // OffsetTypeInfo[] offTi;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
638 // void *defaultConstructor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
639 // }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
640
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
641 Logger::println("DtoDefineClassInfo(%s)", cd->toChars());
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
642 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
643
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
644 IrStruct* ir = cd->ir.irStruct;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
645
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
646 assert(cd->type->ty == Tclass);
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
647
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
648 TypeClass* cdty = (TypeClass*)cd->type;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
649
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
650 // holds the list of initializers for llvm
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
651 std::vector<LLConstant*> inits;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
652
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
653 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
654 cinfo->codegen(Type::sir);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
655
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
656 LLConstant* c;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
657
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
658 const LLType* voidPtr = getVoidPtrType();
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
659 const LLType* voidPtrPtr = getPtrToType(voidPtr);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
660
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
661 // own vtable
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
662 c = cinfo->ir.irStruct->getVtblSymbol();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
663 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
664
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
665 // monitor
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
666 c = LLConstant::getNullValue(voidPtr);
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 114
diff changeset
667 inits.push_back(c);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
668
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
669 // byte[] init
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
670 if (cd->isInterfaceDeclaration())
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
671 c = DtoConstSlice(DtoConstSize_t(0), LLConstant::getNullValue(voidPtr));
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
672 else
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
673 {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
674 c = DtoBitCast(ir->getInitSymbol(), voidPtr);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
675 //Logger::cout() << *ir->constInit->getType() << std::endl;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
676 size_t initsz = getTypePaddedSize(ir->getInitSymbol()->getType()->getContainedType(0));
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
677 c = DtoConstSlice(DtoConstSize_t(initsz), c);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
678 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
679 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
680
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
681 // class name
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
682 // from dmd
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
683 char *name = cd->ident->toChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
684 size_t namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
685 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
686 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
687 name = cd->toPrettyChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
688 namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
689 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
690 c = DtoConstString(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
691 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
692
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
693 // vtbl array
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
694 if (cd->isInterfaceDeclaration())
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
695 c = DtoConstSlice(DtoConstSize_t(0), LLConstant::getNullValue(getPtrToType(voidPtr)));
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
696 else {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
697 c = DtoBitCast(ir->getVtblSymbol(), voidPtrPtr);
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
698 c = DtoConstSlice(DtoConstSize_t(cd->vtbl.dim), c);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
699 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
700 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
701
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
702 // interfaces array
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
703 c = ir->getClassInfoInterfaces();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
704 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
705
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
706 // base classinfo
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
707 // interfaces never get a base , just the interfaces[]
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
708 if (cd->baseClass && !cd->isInterfaceDeclaration()) {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
709 c = cd->baseClass->ir.irStruct->getClassInfoSymbol();
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
710 assert(c);
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
711 inits.push_back(c);
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
712 }
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
713 else {
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
714 // null
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
715 c = LLConstant::getNullValue(DtoType(cinfo->type));
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
716 inits.push_back(c);
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
717 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
718
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
719 // destructor
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
720 if (cd->isInterfaceDeclaration())
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
721 c = LLConstant::getNullValue(voidPtr);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
722 else
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
723 c = build_class_dtor(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
724 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
725
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
726 // invariant
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
727 VarDeclaration* invVar = (VarDeclaration*)cinfo->fields.data[6];
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
728 const LLType* invTy = DtoType(invVar->type);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
729 if (cd->inv)
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
730 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
731 cd->inv->codegen(Type::sir);
327
781af50846b2 [svn r348] Switch on class invariants (except in release mode).
ChristianK
parents: 315
diff changeset
732 c = cd->inv->ir.irFunc->func;
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
733 c = DtoBitCast(c, invTy);
327
781af50846b2 [svn r348] Switch on class invariants (except in release mode).
ChristianK
parents: 315
diff changeset
734 }
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
735 else
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
736 c = LLConstant::getNullValue(invTy);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
737 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
738
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
739 // uint flags
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
740 if (cd->isInterfaceDeclaration())
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
741 c = DtoConstUint(0);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
742 else {
285
297690b5d4a5 [svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents: 284
diff changeset
743 unsigned flags = build_classinfo_flags(cd);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
744 c = DtoConstUint(flags);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
745 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
746 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
747
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
748 // deallocator
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
749 if (cd->aggDelete)
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
750 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
751 cd->aggDelete->codegen(Type::sir);
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
752 c = cd->aggDelete->ir.irFunc->func;
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
753 c = DtoBitCast(c, voidPtr);
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 275
diff changeset
754 }
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
755 else
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
756 c = LLConstant::getNullValue(voidPtr);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
757 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
758
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
759 // offset typeinfo
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
760 VarDeclaration* offTiVar = (VarDeclaration*)cinfo->fields.data[9];
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
761 const LLType* offTiTy = DtoType(offTiVar->type);
821
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
762
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
763 #if GENERATE_OFFTI
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
764
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
765 if (cd->isInterfaceDeclaration())
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
766 c = LLConstant::getNullValue(offTiTy);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
767 else
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
768 c = build_offti_array(cd, offTiTy);
821
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
769
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
770 #else // GENERATE_OFFTI
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
771
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
772 c = LLConstant::getNullValue(offTiTy);
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
773
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
774 #endif // GENERATE_OFFTI
8f0b24bc55f0 Added CMake option to disable generation of ClassInfo.offTi arrays, defaults to OFF.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 816
diff changeset
775
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
776 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
777
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
778 // default constructor
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
779 if (cd->defaultCtor)
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
780 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
781 cd->defaultCtor->codegen(Type::sir);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 169
diff changeset
782 c = isaConstant(cd->defaultCtor->ir.irFunc->func);
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
783 c = DtoBitCast(c, voidPtr);
111
a7ae554ce4f4 [svn r115] Implemented the ClassInfo.defaultConstructor member.
lindquist
parents: 110
diff changeset
784 }
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
785 else
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
786 c = LLConstant::getNullValue(voidPtr);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
787 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
788
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: 737
diff changeset
789 #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: 737
diff changeset
790
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 737
diff changeset
791 // xgetMembers
809
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
792 VarDeclaration* xgetVar = (VarDeclaration*)cinfo->fields.data[11];
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
793 const LLType* xgetTy = DtoType(xgetVar->type);
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
794
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
795 // FIXME: fill it out!
69a5e4a6fc0f Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 806
diff changeset
796 inits.push_back( LLConstant::getNullValue(xgetTy) );
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: 737
diff changeset
797 #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: 737
diff changeset
798
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
799 /*size_t n = inits.size();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
800 for (size_t i=0; i<n; ++i)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
801 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
802 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
803 }*/
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
804
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
805 // build the initializer
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
806 LLConstant* finalinit = llvm::ConstantStruct::get(inits);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
807 //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
808 ir->constClassInfo = finalinit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
809
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
810 // sanity check
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
811 assert(finalinit->getType() == ir->classInfo->getType()->getContainedType(0) &&
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
812 "__ClassZ initializer does not match the ClassInfo type");
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
813
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
814
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
815 // return initializer
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
816 return finalinit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
817 }