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