Mercurial > projects > ldc
annotate gen/classes.cpp @ 1629:b07d683ba4d0
Disable appending a dchar to a char or wchar array for now.
See [1605] for details.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 06 Jan 2010 19:53:35 +0100 |
parents | def7a1d494fd |
children |
rev | line source |
---|---|
100 | 1 #include "gen/llvm.h" |
2 | |
3 #include "mtype.h" | |
4 #include "aggregate.h" | |
5 #include "init.h" | |
6 #include "declaration.h" | |
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 | 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 | 11 #include "gen/arrays.h" |
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 | 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 | 25 |
26 ////////////////////////////////////////////////////////////////////////////////////////// | |
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 | 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 | 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 | 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 | 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 | 121 } |
122 | |
123 ////////////////////////////////////////////////////////////////////////////////////////// | |
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 | 186 if (newexp->member) |
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 | 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 | 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"); |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
214 val = LLConstant::getNullValue(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
|
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 | 247 DValue* DtoCastClass(DValue* val, Type* _to) |
248 { | |
138 | 249 Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars()); |
250 LOG_SCOPE; | |
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 | 255 if (to->ty == Tpointer) { |
1389
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
256 IF_LOG 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 | 259 return new DImValue(_to, rval); |
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) { |
1389
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
263 IF_LOG Logger::println("to bool"); |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
264 LLValue* llval = val->getRVal(); |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
265 LLValue* zero = LLConstant::getNullValue(llval->getType()); |
778
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 } |
1389
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
268 // class -> integer |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
269 else if (to->isintegral()) { |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
270 IF_LOG Logger::println("to %s", to->toChars()); |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
271 |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
272 // get class ptr |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
273 LLValue* v = val->getRVal(); |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
274 // cast to size_t |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
275 v = gIR->ir->CreatePtrToInt(v, DtoSize_t(), ""); |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
276 // cast to the final int type |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
277 DImValue im(Type::tsize_t, v); |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
278 Loc loc; |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
279 return DtoCastInt(loc, &im, _to); |
0bafe24a329f
Fixed class -> integer casts.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1384
diff
changeset
|
280 } |
114 | 281 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
282 // must be class/interface |
114 | 283 assert(to->ty == Tclass); |
284 TypeClass* tc = (TypeClass*)to; | |
285 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
286 // 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
|
287 Type* from = val->getType()->toBasetype(); |
114 | 288 TypeClass* fc = (TypeClass*)from; |
289 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
290 // 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
|
291 if (InterfaceDeclaration* it = tc->sym->isInterfaceDeclaration()) { |
138 | 292 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
|
293 // interface -> interface |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
294 if (fc->sym->isInterfaceDeclaration()) { |
138 | 295 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
|
296 return DtoDynamicCastInterface(val, _to); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
297 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
298 // 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
|
299 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
|
300 Logger::println("static down cast"); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
301 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
302 // 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
|
303 ClassDeclaration* cd = fc->sym->isClassDeclaration(); |
840
a125ada7fd95
more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
839
diff
changeset
|
304 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
|
305 IrStruct* irstruct = cd->ir.irStruct; |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
306 IrTypeClass* typeclass = fc->irtype->isClass(); |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
307 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
308 // find interface impl |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
309 |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
310 size_t i_index = typeclass->getInterfaceIndex(it); |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
311 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
|
312 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
313 // 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
|
314 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
|
315 LLValue* orig = v; |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
320 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
|
321 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
|
322 } |
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
|
323 v = DtoBitCast(v, ifType); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
324 |
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
|
325 // 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
|
326 // 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
|
327 // 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
|
328 // should be pretty cheap and perfectly safe even if the original was null. |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
329 LLValue* isNull = gIR->ir->CreateICmpEQ(orig, LLConstant::getNullValue(orig->getType()), ".nullcheck"); |
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
330 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
|
331 |
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 // 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
|
333 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
|
334 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
335 // class -> interface |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
336 else { |
138 | 337 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
|
338 return DtoDynamicCastObject(val, _to); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
339 } |
114 | 340 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
341 // x -> class |
114 | 342 else { |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
343 Logger::println("to class"); |
114 | 344 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
|
345 // interface -> class |
114 | 346 if (fc->sym->isInterfaceDeclaration()) { |
138 | 347 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
|
348 return DtoDynamicCastInterface(val, _to); |
114 | 349 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
350 // 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
|
351 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
|
352 Logger::println("static down cast"); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
353 const LLType* tolltype = DtoType(_to); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
354 LLValue* rval = DtoBitCast(val->getRVal(), tolltype); |
114 | 355 return new DImValue(_to, rval); |
356 } | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
357 // class -> class - dynamic up cast |
114 | 358 else { |
138 | 359 Logger::println("dynamic up cast"); |
114 | 360 return DtoDynamicCastObject(val, _to); |
361 } | |
362 } | |
363 } | |
364 | |
365 ////////////////////////////////////////////////////////////////////////////////////////// | |
366 | |
367 DValue* DtoDynamicCastObject(DValue* val, Type* _to) | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
368 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
369 // call: |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
370 // Object _d_dynamic_cast(Object o, ClassInfo c) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
371 |
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
|
372 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
|
373 ClassDeclaration::classinfo->codegen(Type::sir); |
114 | 374 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
375 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast"); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
376 const llvm::FunctionType* funcTy = func->getFunctionType(); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
377 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
378 std::vector<LLValue*> args; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
379 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
380 // Object o |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
381 LLValue* obj = val->getRVal(); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
382 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
|
383 assert(funcTy->getParamType(0) == obj->getType()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
384 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
385 // 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
|
386 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
|
387 to->sym->codegen(Type::sir); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
388 |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
389 LLValue* cinfo = to->sym->ir.irStruct->getClassInfoSymbol(); |
114 | 390 // unfortunately this is needed as the implementation of object differs somehow from the declaration |
391 // 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
|
392 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
|
393 assert(funcTy->getParamType(1) == cinfo->getType()); |
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 it |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
396 LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp").getInstruction(); |
114 | 397 |
398 // cast return value | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
399 ret = DtoBitCast(ret, DtoType(_to)); |
114 | 400 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
401 return new DImValue(_to, ret); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
402 } |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
403 |
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 |
114 | 406 DValue* DtoCastInterfaceToObject(DValue* val, Type* to) |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
407 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
408 // call: |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
409 // Object _d_toObject(void* p) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
410 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
411 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_toObject"); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
412 const llvm::FunctionType* funcTy = func->getFunctionType(); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
413 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
414 // void* p |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
415 LLValue* tmp = val->getRVal(); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
416 tmp = DtoBitCast(tmp, funcTy->getParamType(0)); |
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 // call it |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
419 LLValue* ret = gIR->CreateCallOrInvoke(func, tmp, "tmp").getInstruction(); |
114 | 420 |
421 // cast return value | |
422 if (to != NULL) | |
423 ret = DtoBitCast(ret, DtoType(to)); | |
424 else | |
425 to = ClassDeclaration::object->type; | |
426 | |
427 return new DImValue(to, ret); | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
428 } |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
429 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
430 ////////////////////////////////////////////////////////////////////////////////////////// |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
431 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
432 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
|
433 { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
434 // call: |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
435 // 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
|
436 |
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
|
437 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
|
438 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
|
439 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
440 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
|
441 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
|
442 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
443 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
|
444 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
445 // void* p |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
446 LLValue* ptr = val->getRVal(); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
447 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
|
448 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
449 // 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
|
450 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
|
451 to->sym->codegen(Type::sir); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
452 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
|
453 // 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
|
454 // 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
|
455 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
|
456 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
457 // call it |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
458 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
|
459 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
460 // cast return value |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
461 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
|
462 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
463 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
|
464 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
465 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
466 ////////////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
467 |
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
|
468 LLValue* DtoIndexClass(LLValue* src, ClassDeclaration* cd, VarDeclaration* vd) |
132 | 469 { |
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
|
470 Logger::println("indexing class field %s:", vd->toPrettyChars()); |
132 | 471 LOG_SCOPE; |
472 | |
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 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
|
474 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
|
475 |
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
|
476 // 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
|
477 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
|
478 |
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
|
479 // 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
|
480 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
|
481 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
|
482 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
483 // get the start pointer |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
484 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
|
485 // 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
|
486 src = DtoBitCast(src, st); |
132 | 487 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
488 // gep to the index |
1463 | 489 #if 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
|
490 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
|
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 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
|
493 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
|
494 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
|
495 } |
1463 | 496 #endif |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
497 LLValue* val = DtoGEPi(src, 0, field->index); |
132 | 498 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
499 // 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
|
500 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
|
501 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
502 // 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
|
503 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
|
504 // offset |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
505 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
|
506 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
507 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
508 // 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
|
509 val = DtoBitCast(val, getPtrToType(DtoType(vd->type))); |
132 | 510 |
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
|
511 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
|
512 Logger::cout() << "value: " << *val << '\n'; |
132 | 513 |
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
|
514 return val; |
132 | 515 } |
516 | |
517 ////////////////////////////////////////////////////////////////////////////////////////// | |
518 | |
1434
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
519 LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl, char* name) |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
520 { |
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
|
521 // 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 |
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
|
527 // get instance |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
532 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
|
533 // get the vtbl for objects |
1231
212ec2d9d176
Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1229
diff
changeset
|
534 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
|
535 // load vtbl ptr |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
536 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
|
537 // index vtbl |
1434
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
538 std::string vtblname = name; |
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
539 vtblname.append("@vtbl"); |
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
540 funcval = DtoGEPi(funcval, 0, fdecl->vtblIndex, vtblname.c_str()); |
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
|
541 // 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
|
542 funcval = DtoAlignedLoad(funcval); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
543 |
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
|
544 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
|
545 Logger::cout() << "funcval: " << *funcval << '\n'; |
193
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
192
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 // cast to final funcptr type |
193
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
192
diff
changeset
|
548 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); |
1434
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
549 |
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
550 // postpone naming until after casting to get the name in call instructions |
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
551 funcval->setName(name); |
5d0c043ff131
Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents:
1391
diff
changeset
|
552 |
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
|
553 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
|
554 Logger::cout() << "funcval casted: " << *funcval << '\n'; |
193
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
192
diff
changeset
|
555 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
556 return funcval; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
557 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
558 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
559 ////////////////////////////////////////////////////////////////////////////////////////// |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
560 |
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
|
561 #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
|
562 |
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
|
563 // 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
|
564 static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
565 { |
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
|
566 std::vector<LLConstant*> inits(2); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
567 |
809
69a5e4a6fc0f
Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
806
diff
changeset
|
568 // 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
|
569 // |
271
1e6e2b5d5bfe
[svn r292] Fixed: string switch was broken in several ways.
lindquist
parents:
268
diff
changeset
|
570 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
|
571 // 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
|
572 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
|
573 // 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
|
574 offset += vd->ir.irField->unionOffset; |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
575 |
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
|
576 // 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
|
577 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
|
578 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
|
579 |
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 inits[0] = DtoConstSize_t(offset); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
581 |
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
|
582 // 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
|
583 inits[1] = DtoTypeInfoOf(vd->type, true); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
584 |
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
|
585 // 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
|
586 return llvm::ConstantStruct::get(inits); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
587 } |
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
588 |
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
|
589 static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT) |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
590 { |
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
|
591 IrStruct* irstruct = cd->ir.irStruct; |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
592 |
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
|
593 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
|
594 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
|
595 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
596 for (size_t i=0; i<nvars; i++) |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
597 { |
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
|
598 arrayInits[i] = build_offti_entry(cd, irstruct->varDecls[i]); |
110
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 |
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
|
601 LLConstant* size = DtoConstSize_t(nvars); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
602 LLConstant* ptr; |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
603 |
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
|
604 if (nvars == 0) |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
605 return LLConstant::getNullValue( arrayT ); |
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
|
606 |
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
|
607 // 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
|
608 const llvm::ArrayType* arrTy = llvm::ArrayType::get(arrayInits[0]->getType(), nvars); |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1535
diff
changeset
|
609 LLConstant* arrInit = LLConstantArray::get(arrTy, arrayInits); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
610 |
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
|
611 // 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
|
612 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
|
613 name.append("__OffsetTypeInfos"); |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
147
diff
changeset
|
614 |
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
|
615 // 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
|
616 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
|
617 ptr = DtoBitCast(gvar, getPtrToType(arrTy->getElementType())); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
618 |
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
619 return DtoConstSlice(size, ptr); |
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
620 } |
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
106
diff
changeset
|
621 |
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
|
622 #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
|
623 |
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
|
624 static LLConstant* build_class_dtor(ClassDeclaration* cd) |
112
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
625 { |
268
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
626 FuncDeclaration* dtor = cd->dtor; |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
627 |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
628 // if no destructor emit a null |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
629 if (!dtor) |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
630 return getNullPtr(getVoidPtrType()); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
244
diff
changeset
|
631 |
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
|
632 dtor->codegen(Type::sir); |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
633 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::getInt8Ty(gIR->context()))); |
112
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 |
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
|
636 static unsigned build_classinfo_flags(ClassDeclaration* cd) |
112
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
637 { |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
638 // 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
|
639 unsigned flags = 0; |
112
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
640 //flags |= isCOMclass(); // IUnknown |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
641 bool hasOffTi = false; |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
642 if (cd->ctor) flags |= 8; |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
643 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass) |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
644 { |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
645 if (cd2->members) |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
646 { |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
647 for (size_t i = 0; i < cd2->members->dim; i++) |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
648 { |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
649 Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
271
diff
changeset
|
650 if (sm->isVarDeclaration() && !sm->isVarDeclaration()->isDataseg()) // is this enough? |
112
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
651 hasOffTi = true; |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
652 //printf("sm = %s %s\n", sm->kind(), sm->toChars()); |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
653 if (sm->hasPointers()) |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
654 goto L2; |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
655 } |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
656 } |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
657 } |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
658 flags |= 2; // no pointers |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
659 L2: |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
660 if (hasOffTi) |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
661 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
|
662 |
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
|
663 // 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
|
664 // 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
|
665 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
|
666 |
112
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
667 return flags; |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
668 } |
368547b1cbe6
[svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents:
111
diff
changeset
|
669 |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
670 LLConstant* DtoDefineClassInfo(ClassDeclaration* cd) |
100 | 671 { |
672 // The layout is: | |
673 // { | |
674 // void **vptr; | |
675 // monitor_t monitor; | |
676 // byte[] initializer; // static initialization data | |
677 // char[] name; // class name | |
678 // void *[] vtbl; | |
679 // Interface[] interfaces; | |
680 // ClassInfo *base; // base class | |
681 // void *destructor; | |
682 // void *invariant; // class invariant | |
683 // uint flags; | |
684 // void *deallocator; | |
685 // OffsetTypeInfo[] offTi; | |
686 // void *defaultConstructor; | |
1463 | 687 // version(D_Version2) |
688 // const(MemberInfo[]) function(string) xgetMembers; | |
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
|
689 // TypeInfo typeinfo; // since dmd 1.045 |
100 | 690 // } |
691 | |
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
|
692 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
|
693 LOG_SCOPE; |
100 | 694 |
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
|
695 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
|
696 TypeClass* cdty = (TypeClass*)cd->type; |
100 | 697 |
1383
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
698 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
|
699 assert(ir); |
100 | 700 |
701 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
|
702 |
1453 | 703 #if DMDV2 |
704 if (cinfo->fields.dim != 13) | |
705 #else | |
1391
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
706 if (cinfo->fields.dim != 12) |
1453 | 707 #endif |
1391
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
708 { |
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
709 error("object.d ClassInfo class is incorrect"); |
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
710 fatal(); |
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
711 } |
3af4ad55a004
Added simple check for ClassInfo change introduced in DMD 1.045, it must have 12 fields.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1389
diff
changeset
|
712 |
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 // 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
|
714 RTTIBuilder b(ClassDeclaration::classinfo); |
100 | 715 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
210
diff
changeset
|
716 LLConstant* c; |
100 | 717 |
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
|
718 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
|
719 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
|
720 |
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
|
721 // 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
|
722 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
|
723 { |
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
724 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
|
725 } |
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 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
|
727 { |
1383
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
728 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
|
729 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
|
730 b.push_void_array(initsz, ir->getInitSymbol()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
731 } |
100 | 732 |
733 // 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
|
734 // code from dmd |
1577
e4f7b5d9c68a
DMD 2.032 Merge.
Robert Clipsham <robert@octarineparrot.com>
parents:
1571
diff
changeset
|
735 const char *name = cd->ident->toChars(); |
100 | 736 size_t namelen = strlen(name); |
737 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0)) | |
738 { | |
739 name = cd->toPrettyChars(); | |
740 namelen = strlen(name); | |
741 } | |
1383
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
742 b.push_string(name); |
100 | 743 |
744 // 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
|
745 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
|
746 { |
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
747 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
|
748 } |
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
749 else |
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
750 { |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
751 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
|
752 b.push_array(cd->vtbl.dim, c); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
753 } |
100 | 754 |
755 // 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
|
756 b.push(ir->getClassInfoInterfaces()); |
100 | 757 |
758 // 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
|
759 // 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
|
760 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
|
761 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
|
762 else |
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(cinfo->type); |
100 | 764 |
765 // 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
|
766 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
|
767 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
|
768 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
|
769 b.push(build_class_dtor(cd)); |
100 | 770 |
771 // 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
|
772 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
|
773 b.push_funcptr(cd->inv, invVar->type); |
100 | 774 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
112
diff
changeset
|
775 // 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
|
776 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
|
777 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
|
778 else |
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_uint(build_classinfo_flags(cd)); |
100 | 780 |
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
|
781 // 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
|
782 b.push_funcptr(cd->aggDelete, Type::tvoid->pointerTo()); |
100 | 783 |
784 // 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
|
785 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
|
786 |
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
|
787 #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
|
788 |
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
|
789 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
|
790 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
|
791 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
|
792 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
|
793 |
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
|
794 #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
|
795 |
1383
f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1368
diff
changeset
|
796 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
|
797 |
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
|
798 #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
|
799 |
100 | 800 // 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
|
801 b.push_funcptr(cd->defaultCtor, Type::tvoid->pointerTo()); |
100 | 802 |
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
|
803 #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
|
804 |
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
|
805 // 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
|
806 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
|
807 |
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
|
808 // 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
|
809 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
|
810 |
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
|
811 #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
|
812 |
1463 | 813 // typeinfo - since 1.045 |
814 b.push_typeinfo(cd->type); | |
815 | |
100 | 816 /*size_t n = inits.size(); |
817 for (size_t i=0; i<n; ++i) | |
818 { | |
819 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n'; | |
820 }*/ | |
821 | |
822 // 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
|
823 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
|
824 |
100 | 825 //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
|
826 ir->constClassInfo = finalinit; |
100 | 827 |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
828 // sanity check |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
829 assert(finalinit->getType() == ir->classInfo->getType()->getContainedType(0) && |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
830 "__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
|
831 |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
832 // return initializer |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1210
diff
changeset
|
833 return finalinit; |
100 | 834 } |