annotate gen/classes.cpp @ 1384:68a0e361fdce

Increased RTTIBuilder buffer to 14 constants, to be big enough for !ClassInfo as well as !TypeInfo
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sun, 17 May 2009 16:29:49 +0200
parents f15a2d131ceb
children 0bafe24a329f
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
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
8 #include "gen/dvalue.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
9 #include "gen/irstate.h"
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
10
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/classes.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
13 #include "gen/functions.h"
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
14 #include "gen/llvmhelpers.h"
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
15 #include "gen/logger.h"
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
16 #include "gen/nested.h"
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
17 #include "gen/rttibuilder.h"
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
18 #include "gen/runtime.h"
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
19 #include "gen/structs.h"
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
20 #include "gen/tollvm.h"
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
21 #include "gen/utils.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
22
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
23 #include "ir/irstruct.h"
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
24 #include "ir/irtypeclass.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
25
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
26 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
27
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
28 // 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
29
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
30 void DtoResolveClass(ClassDeclaration* cd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
31 {
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
32 // 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
33 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
34 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
35 {
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 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
37 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
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 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
40 }
e1b0c5c74c58 Resolve all base classes, including interfaces (!) before resolving the class itself.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1239
diff changeset
41 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
42 }
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
43
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 169
diff changeset
44 if (cd->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 169
diff changeset
45 cd->ir.resolved = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
46
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
47 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
48 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
49
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
50 // make sure type exists
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
51 DtoType(cd->type);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
52
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
53 // create IrStruct
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
54 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
55 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
56 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
57
1309
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
58 // make sure all fields really get their ir field
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
59 ArrayIter<VarDeclaration> it(cd->fields);
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
60 for (; !it.done(); it.next())
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
61 {
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
62 VarDeclaration* vd = it.get();
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
63 if (vd->ir.irField == NULL) {
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
64 new IrField(vd);
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
65 } else {
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
66 IF_LOG Logger::println("class field already exists!!!");
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
67 }
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
68 }
0c03ba6f7c24 Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
69
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
70 bool needs_def = mustDefineSymbol(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
71
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
72 // emit the ClassZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
73 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
74
1253
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
75 // emit the interfaceInfosZ symbol if necessary
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
76 if (cd->vtblInterfaces && cd->vtblInterfaces->dim > 0)
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
77 irstruct->getInterfaceArraySymbol(); // initializer is applied when it's built
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
78
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
79 // interface only emit typeinfo and classinfo
1253
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
80 if (cd->isInterfaceDeclaration())
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
81 {
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
82 irstruct->initializeInterface();
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
83 }
752bed475b75 Fixed classinfo.interfaces for .. interfaces!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1252
diff changeset
84 else
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
85 {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
86 // emit the initZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
87 LLGlobalVariable* initZ = irstruct->getInitSymbol();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
88 // emit the vtblZ symbol
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
89 LLGlobalVariable* vtblZ = irstruct->getVtblSymbol();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
90
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
91 // perform definition
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
92 if (needs_def)
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
93 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
94 // set symbol initializers
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
95 initZ->setInitializer(irstruct->getDefaultInit());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
96 vtblZ->setInitializer(irstruct->getVtblInit());
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
97 }
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
98 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
99
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
100 // emit members
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
101 if (cd->members)
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
102 {
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
103 ArrayIter<Dsymbol> it(*cd->members);
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
104 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
105 {
1252
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
106 Dsymbol* member = it.get();
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
107 if (member)
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
108 member->codegen(Type::sir);
7c1b55db4ff3 Fixed emitting declarations nested inside interfaces.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1244
diff changeset
109 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
110 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
111 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
112
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
113 if (needs_def)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
114 {
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
115 // 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
116 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
117
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
118 // define classinfo
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
119 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
120 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
121 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
122
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
123 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
124
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
125 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
126 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
127 // 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
128 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
129
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
130 // allocate
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
131 LLValue* mem;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
132 if (newexp->onstack)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
133 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1309
diff changeset
134 // FIXME align scope class to its largest member
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1309
diff changeset
135 mem = DtoRawAlloca(DtoType(tc)->getContainedType(0), 0, ".newclass_alloca");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
136 }
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
137 // 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
138 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
139 {
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
140 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
141 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
142 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
143 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
144 }
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
145 // default allocator
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
146 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
147 {
728
635f91212b78 Change _d_newclass into _d_allocclass. Add initialization to ClassInfo.create.
Christian Kamm <kamm incasoftware de>
parents: 705
diff changeset
148 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
149 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
150 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
151 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
152 }
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 // init
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
155 DtoInitClass(tc, mem);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
156
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
157 // 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
158 if (newexp->thisexp)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
159 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
160 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
161 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
162 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
163 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
164 LLValue* src = thisval->getRVal();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
165 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
166 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
167 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
168 DtoStore(src, dst);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
169 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
170 // 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
171 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
172 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
173 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
174 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
175
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
176 // 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
177 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
178
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
179 // 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
180 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
181 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
182 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
183 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
184
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
185 // call constructor
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
186 if (newexp->member)
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
187 {
1047
6bb04dbee21f Some calling convention work for x86-64:
Frits van Bommel <fvbommel wxs.nl>
parents: 1013
diff changeset
188 Logger::println("Calling constructor");
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
189 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
190 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
191 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
192 return DtoCallFunction(newexp->loc, tc, &dfn, newexp->arguments);
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
193 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
194
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
195 // 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
196 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
197 }
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 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
200
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
201 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
202 {
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
203 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
204
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1253
diff changeset
205 uint64_t n = tc->sym->structsize - PTRSIZE * 2;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
206
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
207 // 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
208 LLValue* tmp = DtoGEPi(dst,0,0,"vtbl");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
209 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
210 DtoStore(val, tmp);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
211
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
212 // 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
213 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
214 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
215 DtoStore(val, tmp);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
216
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
217 // done?
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
218 if (n == 0)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
219 return;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
220
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
221 // 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
222 LLValue* dstarr = DtoGEPi(dst,0,2,"tmp");
1270
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1262
diff changeset
223
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1262
diff changeset
224 // init symbols might not have valid types
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1262
diff changeset
225 LLValue* initsym = tc->sym->ir.irStruct->getInitSymbol();
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1262
diff changeset
226 initsym = DtoBitCast(initsym, DtoType(tc));
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1262
diff changeset
227 LLValue* srcarr = DtoGEPi(initsym,0,2,"tmp");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
228
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 217
diff changeset
229 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
230 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
231
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
232 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
233
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
234 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
235 {
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
236 // 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
237 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
238 // build args
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
239 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
240 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
241 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
242 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
243 }
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
244
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
245 //////////////////////////////////////////////////////////////////////////////////////////
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
246
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
247 DValue* DtoCastClass(DValue* val, Type* _to)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
248 {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
249 Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars());
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
250 LOG_SCOPE;
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
251
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* 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
253
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
254 // class -> pointer
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
255 if (to->ty == Tpointer) {
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
256 Logger::println("to pointer");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
257 const LLType* tolltype = DtoType(_to);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
258 LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
259 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
260 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
261 // class -> bool
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
262 else if (to->ty == Tbool) {
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
263 Logger::println("to bool");
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
264 LLValue* llval = val->getRVal();
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
265 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
266 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
267 }
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
268
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
269 // must be class/interface
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
270 assert(to->ty == Tclass);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
271 TypeClass* tc = (TypeClass*)to;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
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 // 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
274 Type* from = val->getType()->toBasetype();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
275 TypeClass* fc = (TypeClass*)from;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
276
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
277 // 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
278 if (InterfaceDeclaration* it = tc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
279 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
280 // interface -> interface
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
281 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
282 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
283 return DtoDynamicCastInterface(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
284 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
285 // 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
286 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
287 Logger::println("static down cast");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
288
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
289 // 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
290 ClassDeclaration* cd = fc->sym->isClassDeclaration();
840
a125ada7fd95 more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 839
diff changeset
291 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
292 IrStruct* irstruct = cd->ir.irStruct;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
293 IrTypeClass* typeclass = fc->irtype->isClass();
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
294
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
295 // find interface impl
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
296
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
297 size_t i_index = typeclass->getInterfaceIndex(it);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
298 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
299
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
300 // 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
301 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
302 LLValue* orig = v;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
303 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
304 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
305 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
306 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
307 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
308 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
309 }
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
310 v = DtoBitCast(v, ifType);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
311
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
312 // 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
313 // 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
314 // 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
315 // 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
316 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
317 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
318
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
319 // 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
320 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
321 }
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 -> interface
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
323 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
324 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
325 return DtoDynamicCastObject(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
326 }
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
327 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
328 // x -> class
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
329 else {
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 758
diff changeset
330 Logger::println("to class");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
331 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
332 // interface -> class
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
333 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
334 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
335 return DtoDynamicCastInterface(val, _to);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
336 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
337 // 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
338 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
339 Logger::println("static down cast");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
340 const LLType* tolltype = DtoType(_to);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
341 LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
342 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
343 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
344 // class -> class - dynamic up cast
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
345 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
346 Logger::println("dynamic up cast");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
347 return DtoDynamicCastObject(val, _to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
348 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
349 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
350 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
351
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
352 //////////////////////////////////////////////////////////////////////////////////////////
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
353
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
354 DValue* DtoDynamicCastObject(DValue* val, Type* _to)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
355 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
356 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
357 // Object _d_dynamic_cast(Object o, ClassInfo c)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
358
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
359 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
360 ClassDeclaration::classinfo->codegen(Type::sir);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
361
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
362 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
363 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
364
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
365 std::vector<LLValue*> args;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
366
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
367 // Object o
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
368 LLValue* obj = val->getRVal();
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
369 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
370 assert(funcTy->getParamType(0) == obj->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
371
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
372 // 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
373 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
374 to->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
375
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
376 LLValue* cinfo = to->sym->ir.irStruct->getClassInfoSymbol();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
377 // 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
378 // 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
379 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
380 assert(funcTy->getParamType(1) == cinfo->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
381
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
382 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
383 LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp").getInstruction();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
384
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
385 // cast return value
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
386 ret = DtoBitCast(ret, DtoType(_to));
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
387
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
388 return new DImValue(_to, ret);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
389 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
390
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
391 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
392
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
393 DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
113
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 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
396 // Object _d_toObject(void* p)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
397
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
398 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_toObject");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
399 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
400
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
401 // void* p
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
402 LLValue* tmp = val->getRVal();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
403 tmp = DtoBitCast(tmp, funcTy->getParamType(0));
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
404
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
405 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
406 LLValue* ret = gIR->CreateCallOrInvoke(func, tmp, "tmp").getInstruction();
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
407
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
408 // cast return value
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
409 if (to != NULL)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
410 ret = DtoBitCast(ret, DtoType(to));
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
411 else
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
412 to = ClassDeclaration::object->type;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
413
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
414 return new DImValue(to, ret);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
415 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
416
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
417 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
418
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
419 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
420 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
421 // call:
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
422 // 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
423
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
424 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
425 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
426
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
427 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
428 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
429
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
430 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
431
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
432 // void* p
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
433 LLValue* ptr = val->getRVal();
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
434 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
435
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
436 // 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
437 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
438 to->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
439 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
440 // 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
441 // 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
442 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
443
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
444 // call it
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
445 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
446
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
447 // cast return value
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
448 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
449
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
450 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
451 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
452
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
453 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
454
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
455 LLValue* DtoIndexClass(LLValue* src, ClassDeclaration* cd, VarDeclaration* vd)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
456 {
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
457 Logger::println("indexing class field %s:", vd->toPrettyChars());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
458 LOG_SCOPE;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
459
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
460 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
461 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
462
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
463 // 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
464 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
465
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
466 // 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
467 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
468 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
469
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
470 // get the start pointer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
471 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
472 // 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
473 src = DtoBitCast(src, st);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
474
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
475 // 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
476 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
477 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
478 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
479 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
480 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
481 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
482 LLValue* val = DtoGEPi(src, 0, field->index);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
483
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
484 // 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
485 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
486 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
487 // 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
488 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
489 // offset
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
490 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
491 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
492
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
493 // 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
494 val = DtoBitCast(val, getPtrToType(DtoType(vd->type)));
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
495
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
496 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
497 Logger::cout() << "value: " << *val << '\n';
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
498
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
499 return val;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
500 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
501
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
502 //////////////////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
503
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
504 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
505 {
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
506 // 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
507 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
508 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
509 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
510 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
511
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
512 // get instance
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
513 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
514 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
515 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
516
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
517 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
518 // get the vtbl for objects
1231
212ec2d9d176 Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1229
diff changeset
519 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
520 // load vtbl ptr
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
521 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
522 // 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
523 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
524 // 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
525 funcval = DtoAlignedLoad(funcval);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
526
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
527 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
528 Logger::cout() << "funcval: " << *funcval << '\n';
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
529
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 // cast to final funcptr type
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
531 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
532 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
533 Logger::cout() << "funcval casted: " << *funcval << '\n';
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 192
diff changeset
534
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
535 return funcval;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
536 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
537
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
538 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
539
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
540 #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
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 // 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
543 static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
544 {
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
545 std::vector<LLConstant*> inits(2);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
546
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
547 // 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
548 //
271
1e6e2b5d5bfe [svn r292] Fixed: string switch was broken in several ways.
lindquist
parents: 268
diff changeset
549 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
550 // 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
551 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
552 // 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
553 offset += vd->ir.irField->unionOffset;
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 // 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
556 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
557 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
558
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
559 inits[0] = DtoConstSize_t(offset);
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 // 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
562 inits[1] = DtoTypeInfoOf(vd->type, true);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
563
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
564 // 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
565 return llvm::ConstantStruct::get(inits);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
566 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
567
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
568 static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
569 {
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
570 IrStruct* irstruct = cd->ir.irStruct;
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
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 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
573 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
574
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
575 for (size_t i=0; i<nvars; i++)
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
576 {
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
577 arrayInits[i] = build_offti_entry(cd, irstruct->varDecls[i]);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
578 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
579
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
580 LLConstant* size = DtoConstSize_t(nvars);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
581 LLConstant* ptr;
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
582
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
583 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
584 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
585
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
586 // 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
587 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
588 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits);
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
589
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
590 // 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
591 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
592 name.append("__OffsetTypeInfos");
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 147
diff changeset
593
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
594 // 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
595 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
596 ptr = DtoBitCast(gvar, getPtrToType(arrTy->getElementType()));
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
597
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
598 return DtoConstSlice(size, ptr);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
599 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
600
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
601 #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
602
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
603 static LLConstant* build_class_dtor(ClassDeclaration* cd)
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
604 {
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
605 FuncDeclaration* dtor = cd->dtor;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
606
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
607 // if no destructor emit a null
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
608 if (!dtor)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
609 return getNullPtr(getVoidPtrType());
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
610
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
611 dtor->codegen(Type::sir);
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 244
diff changeset
612 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
613 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
614
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
615 static unsigned build_classinfo_flags(ClassDeclaration* cd)
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
616 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
617 // 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
618 unsigned flags = 0;
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
619 //flags |= isCOMclass(); // IUnknown
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
620 bool hasOffTi = false;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
621 if (cd->ctor) flags |= 8;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
622 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
623 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
624 if (cd2->members)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
625 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
626 for (size_t i = 0; i < cd2->members->dim; i++)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
627 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
628 Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 271
diff changeset
629 if (sm->isVarDeclaration() && !sm->isVarDeclaration()->isDataseg()) // is this enough?
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
630 hasOffTi = true;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
631 //printf("sm = %s %s\n", sm->kind(), sm->toChars());
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
632 if (sm->hasPointers())
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
633 goto L2;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
634 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
635 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
636 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
637 flags |= 2; // no pointers
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
638 L2:
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
639 if (hasOffTi)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
640 flags |= 4;
1368
1fbdfec6ea0d Forgot to set the (ClassInfo.flags & 32) bit added in 1.045.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
641
1fbdfec6ea0d Forgot to set the (ClassInfo.flags & 32) bit added in 1.045.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
642 // always define the typeinfo field.
1fbdfec6ea0d Forgot to set the (ClassInfo.flags & 32) bit added in 1.045.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
643 // why would ever not do this?
1fbdfec6ea0d Forgot to set the (ClassInfo.flags & 32) bit added in 1.045.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
644 flags |= 32;
1fbdfec6ea0d Forgot to set the (ClassInfo.flags & 32) bit added in 1.045.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
645
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
646 return flags;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
647 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
648
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
649 LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
650 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
651 // The layout is:
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
652 // {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
653 // void **vptr;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
654 // monitor_t monitor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
655 // byte[] initializer; // static initialization data
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
656 // char[] name; // class name
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
657 // void *[] vtbl;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
658 // Interface[] interfaces;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
659 // ClassInfo *base; // base class
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
660 // void *destructor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
661 // void *invariant; // class invariant
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
662 // uint flags;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
663 // void *deallocator;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
664 // OffsetTypeInfo[] offTi;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
665 // void *defaultConstructor;
1384
68a0e361fdce Increased RTTIBuilder buffer to 14 constants, to be big enough for !ClassInfo as well as !TypeInfo
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1383
diff changeset
666 // TypeInfo typeinfo; // since dmd 1.045
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
667 // }
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 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
670 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
671
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
672 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
673 TypeClass* cdty = (TypeClass*)cd->type;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
674
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
675 IrStruct* ir = cd->ir.irStruct;
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
676 assert(ir);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
677
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
678 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
679
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
680 // use the rtti builder
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
681 RTTIBuilder b(ClassDeclaration::classinfo);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
682
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 210
diff changeset
683 LLConstant* c;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
684
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
685 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
686 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
687
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
688 // 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
689 if (cd->isInterfaceDeclaration())
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
690 {
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
691 b.push_null_void_array();
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
692 }
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
693 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
694 {
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
695 const LLType* cd_type = cdty->irtype->getPA();
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
696 size_t initsz = getTypePaddedSize(cd_type);
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
697 b.push_void_array(initsz, ir->getInitSymbol());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
698 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
699
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
700 // class name
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
701 // code from dmd
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
702 char *name = cd->ident->toChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
703 size_t namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
704 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
705 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
706 name = cd->toPrettyChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
707 namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
708 }
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
709 b.push_string(name);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
710
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
711 // 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
712 if (cd->isInterfaceDeclaration())
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
713 {
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
714 b.push_array(0, getNullValue(voidPtrPtr));
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
715 }
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
716 else
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
717 {
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
718 c = DtoBitCast(ir->getVtblSymbol(), voidPtrPtr);
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
719 b.push_array(cd->vtbl.dim, c);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
720 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
721
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
722 // interfaces array
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
723 b.push(ir->getClassInfoInterfaces());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
724
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
725 // 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
726 // interfaces never get a base , just the interfaces[]
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
727 if (cd->baseClass && !cd->isInterfaceDeclaration())
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
728 b.push_classinfo(cd->baseClass);
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
729 else
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
730 b.push_null(cinfo->type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
731
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
732 // 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
733 if (cd->isInterfaceDeclaration())
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
734 b.push_null_vp();
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
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
736 b.push(build_class_dtor(cd));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
737
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
738 // 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
739 VarDeclaration* invVar = (VarDeclaration*)cinfo->fields.data[6];
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
740 b.push_funcptr(cd->inv, invVar->type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
741
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
742 // 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
743 if (cd->isInterfaceDeclaration())
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
744 b.push_uint(0);
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
745 else
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
746 b.push_uint(build_classinfo_flags(cd));
100
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
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
749 b.push_funcptr(cd->aggDelete, Type::tvoid->pointerTo());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
750
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
751 // 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
752 VarDeclaration* offTiVar = (VarDeclaration*)cinfo->fields.data[9];
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
753
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
754 #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
755
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
756 if (cd->isInterfaceDeclaration())
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
757 b.push_null(offTiVar->type);
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
758 else
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
759 b.push(build_offti_array(cd, 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
760
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
761 #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
762
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
763 b.push_null(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
764
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
765 #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
766
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
767 // default constructor
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
768 b.push_funcptr(cd->defaultCtor, Type::tvoid->pointerTo());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
769
1367
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
770 // typeinfo - since 1.045
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
771 b.push_typeinfo(cd->type);
1367
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
772
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
773 #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
774
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
775 // 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
776 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
777
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
778 // FIXME: fill it out!
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
779 b.push_null(xgetVar->type);
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
780
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
781 #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
782
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
783 /*size_t n = inits.size();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
784 for (size_t i=0; i<n; ++i)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
785 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
786 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
787 }*/
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
788
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
789 // build the initializer
1383
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
790 LLConstant* finalinit = b.get_constant();
f15a2d131ceb Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1368
diff changeset
791
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
792 //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
793 ir->constClassInfo = finalinit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
794
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
795 // sanity check
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
796 assert(finalinit->getType() == ir->classInfo->getType()->getContainedType(0) &&
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
797 "__ClassZ initializer does not match the ClassInfo 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
798
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
799 // return initializer
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1210
diff changeset
800 return finalinit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
801 }