annotate gen/classes.cpp @ 142:a123dca8349b trunk

[svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
author lindquist
date Wed, 23 Jan 2008 15:48:19 +0100
parents aeddd4d533b3
children 0636f6269dfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1 #include <sstream>
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
2 #include "gen/llvm.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
3
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
4 #include "mtype.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
5 #include "aggregate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
6 #include "init.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
7 #include "declaration.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
8
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
9 #include "gen/irstate.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
10 #include "gen/tollvm.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
11 #include "gen/arrays.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
12 #include "gen/logger.h"
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
13 #include "gen/classes.h"
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
14 #include "gen/structs.h"
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
15 #include "gen/functions.h"
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
16 #include "gen/runtime.h"
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
17 #include "gen/dvalue.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
18
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
19 #include "ir/irstruct.h"
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
20
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
21 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
22
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
23 static void LLVM_AddBaseClassInterfaces(ClassDeclaration* target, BaseClasses* bcs)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
24 {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
25 // add base class data members first
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
26 for (int j=0; j<bcs->dim; j++)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
27 {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
28 BaseClass* bc = (BaseClass*)(bcs->data[j]);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
29
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
30 // base *classes* might add more interfaces?
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
31 DtoResolveClass(bc->base);
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
32 LLVM_AddBaseClassInterfaces(target, &bc->base->baseclasses);
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
33
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
34 // resolve interfaces while we're at it
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
35 if (bc->base->isInterfaceDeclaration())
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
36 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
37 // don't add twice
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
38 if (target->irStruct->interfaceMap.find(bc->base) == target->irStruct->interfaceMap.end())
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
39 {
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
40 Logger::println("adding interface '%s'", bc->base->toPrettyChars());
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
41 IrInterface* iri = new IrInterface(bc, NULL);
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
42
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
43 // add to map
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
44 target->irStruct->interfaceMap.insert(std::make_pair(bc->base, iri));
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
45 // add to ordered list
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
46 target->irStruct->interfaceVec.push_back(iri);
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
47
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
48 // Fill in vtbl[]
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
49 if (!target->isAbstract()) {
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
50 bc->fillVtbl(target, &bc->vtbl, 0);
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
51 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
52 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
53 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
54 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
55 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
56
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
57 //////////////////////////////////////////////////////////////////////////////////////////
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
58
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
59 static void LLVM_AddBaseClassData(BaseClasses* bcs)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
60 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
61 // add base class data members first
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
62 for (int j=0; j<bcs->dim; j++)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
63 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
64 BaseClass* bc = (BaseClass*)(bcs->data[j]);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
65
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
66 // interfaces never add data fields
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
67 if (bc->base->isInterfaceDeclaration())
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
68 continue;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
69
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
70 // recursively add baseclass data
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
71 LLVM_AddBaseClassData(&bc->base->baseclasses);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
72
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
73 Array* arr = &bc->base->fields;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
74 if (arr->dim == 0)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
75 continue;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
76
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
77 Logger::println("Adding base class members of %s", bc->base->toChars());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
78 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
79
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
80 for (int k=0; k < arr->dim; k++) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
81 VarDeclaration* v = (VarDeclaration*)(arr->data[k]);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
82 v->toObjFile();
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
83 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
84 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
85 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
86
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
87 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
88
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
89 void DtoResolveClass(ClassDeclaration* cd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
90 {
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
91 if (cd->llvmResolved) return;
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
92 cd->llvmResolved = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
93
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
94 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
95 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
96
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
97 // get the TypeClass
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
98 assert(cd->type->ty == Tclass);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
99 TypeClass* ts = (TypeClass*)cd->type;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
100
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
101 // make sure the IrStruct is created
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
102 IrStruct* irstruct = cd->irStruct;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
103 if (!irstruct) {
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
104 irstruct = new IrStruct(ts);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
105 cd->irStruct = irstruct;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
106 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
107
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
108 // resolve the base class
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
109 if (cd->baseClass) {
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
110 DtoResolveClass(cd->baseClass);
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
111 }
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
112
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
113 // resolve interface vtables
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
114 /*if (cd->vtblInterfaces) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
115 Logger::println("Vtbl interfaces for '%s'", cd->toPrettyChars());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
116 LOG_SCOPE;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
117 for (int i=0; i < cd->vtblInterfaces->dim; i++) {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
118 BaseClass *b = (BaseClass *)cd->vtblInterfaces->data[i];
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
119 ClassDeclaration *id = b->base;
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
120 Logger::println("Vtbl interface: '%s'", id->toPrettyChars());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
121 DtoResolveClass(id);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
122 // Fill in vtbl[]
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
123 b->fillVtbl(cd, &b->vtbl, 1);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
124 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
125 }*/
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
126
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
127 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
128 gIR->classes.push_back(cd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
129
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
130 // add vtable
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
131 ts->llvmVtblType = new llvm::PATypeHolder(llvm::OpaqueType::get());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
132 const llvm::Type* vtabty = getPtrToType(ts->llvmVtblType->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
133
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
134 std::vector<const llvm::Type*> fieldtypes;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
135 fieldtypes.push_back(vtabty);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
136
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
137 // add monitor
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
138 fieldtypes.push_back(getPtrToType(llvm::Type::Int8Ty));
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
139
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
140 // add base class data fields first
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
141 LLVM_AddBaseClassData(&cd->baseclasses);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
142
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
143 // then add own members
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
144 for (int k=0; k < cd->members->dim; k++) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
145 Dsymbol* dsym = (Dsymbol*)(cd->members->data[k]);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
146 dsym->toObjFile();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
147 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
148
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
149 // resolve class data fields (possibly unions)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
150 Logger::println("doing class fields");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
151
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
152 if (irstruct->offsets.empty())
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
153 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
154 Logger::println("has no fields");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
155 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
156 else
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
157 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
158 Logger::println("has fields");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
159 unsigned prevsize = (unsigned)-1;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
160 unsigned lastoffset = (unsigned)-1;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
161 const llvm::Type* fieldtype = NULL;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
162 VarDeclaration* fieldinit = NULL;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
163 size_t fieldpad = 0;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
164 int idx = 0;
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
165 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
166 // first iteration
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
167 if (lastoffset == (unsigned)-1) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
168 lastoffset = i->first;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
169 fieldtype = i->second.type;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
170 fieldinit = i->second.var;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
171 prevsize = getABITypeSize(fieldtype);
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
172 i->second.var->irField->index = idx;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
173 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
174 // colliding offset?
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
175 else if (lastoffset == i->first) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
176 size_t s = getABITypeSize(i->second.type);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
177 if (s > prevsize) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
178 fieldpad += s - prevsize;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
179 prevsize = s;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
180 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
181 cd->irStruct->hasUnions = true;
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
182 i->second.var->irField->index = idx;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
183 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
184 // intersecting offset?
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
185 else if (i->first < (lastoffset + prevsize)) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
186 size_t s = getABITypeSize(i->second.type);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
187 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
188 cd->irStruct->hasUnions = true;
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
189 i->second.var->irField->index = idx;
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
190 i->second.var->irField->indexOffset = (i->first - lastoffset) / s;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
191 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
192 // fresh offset
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
193 else {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
194 // commit the field
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
195 fieldtypes.push_back(fieldtype);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
196 irstruct->defaultFields.push_back(fieldinit);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
197 if (fieldpad) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
198 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
199 irstruct->defaultFields.push_back(NULL);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
200 idx++;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
201 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
202
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
203 idx++;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
204
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
205 // start new
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
206 lastoffset = i->first;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
207 fieldtype = i->second.type;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
208 fieldinit = i->second.var;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
209 prevsize = getABITypeSize(fieldtype);
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
210 i->second.var->irField->index = idx;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
211 fieldpad = 0;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
212 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
213 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
214 fieldtypes.push_back(fieldtype);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
215 irstruct->defaultFields.push_back(fieldinit);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
216 if (fieldpad) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
217 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
218 irstruct->defaultFields.push_back(NULL);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
219 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
220 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
221
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
222 // populate interface map
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
223 {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
224 Logger::println("Adding interfaces to '%s'", cd->toPrettyChars());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
225 LOG_SCOPE;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
226 LLVM_AddBaseClassInterfaces(cd, &cd->baseclasses);
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
227 Logger::println("%d interfaces added", cd->irStruct->interfaceVec.size());
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
228 assert(cd->irStruct->interfaceVec.size() == cd->irStruct->interfaceMap.size());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
229 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
230
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
231 // add interface vtables at the end
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
232 int interIdx = (int)fieldtypes.size();
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
233 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
234 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
235 IrInterface* iri = *i;
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
236 ClassDeclaration* id = iri->decl;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
237
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
238 // set vtbl type
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
239 TypeClass* itc = (TypeClass*)id->type;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
240 const llvm::Type* ivtblTy = getPtrToType(itc->llvmVtblType->get());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
241 fieldtypes.push_back(ivtblTy);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
242
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
243 // fix the interface vtable type
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
244 iri->vtblTy = isaStruct(itc->llvmVtblType->get());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
245
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
246 // set index
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
247 iri->index = interIdx++;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
248 }
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
249 Logger::println("%d interface vtables added", cd->irStruct->interfaceVec.size());
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
250 assert(cd->irStruct->interfaceVec.size() == cd->irStruct->interfaceMap.size());
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
251
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
252 // create type
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
253 const llvm::StructType* structtype = llvm::StructType::get(fieldtypes);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
254
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
255 // refine abstract types for stuff like: class C {C next;}
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
256 assert(irstruct->recty != 0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
257 llvm::PATypeHolder& spa = irstruct->recty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
258 llvm::cast<llvm::OpaqueType>(spa.get())->refineAbstractTypeTo(structtype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
259 structtype = isaStruct(spa.get());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
260
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
261 // make it official
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
262 if (!ts->llvmType)
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
263 ts->llvmType = new llvm::PATypeHolder(structtype);
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
264 else
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
265 *ts->llvmType = structtype;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
266 spa = *ts->llvmType;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
267
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
268 // name the type
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
269 gIR->module->addTypeName(cd->mangle(), ts->llvmType->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
270
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
271 // get interface info type
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
272 const llvm::StructType* infoTy = DtoInterfaceInfoType();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
273
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
274 // create vtable type
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
275 llvm::GlobalVariable* svtblVar = 0;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
276 std::vector<const llvm::Type*> sinits_ty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
277
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
278 for (int k=0; k < cd->vtbl.dim; k++)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
279 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
280 Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[k];
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
281 assert(dsym);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
282 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
283
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
284 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
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
285 DtoResolveFunction(fd);
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 115
diff changeset
286 //assert(fd->type->ty == Tfunction);
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 115
diff changeset
287 //TypeFunction* tf = (TypeFunction*)fd->type;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
288 //const llvm::Type* fpty = getPtrToType(tf->llvmType->get());
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 115
diff changeset
289 const llvm::FunctionType* vfty = DtoBaseFunctionType(fd);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
290 const llvm::Type* vfpty = getPtrToType(vfty);
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 115
diff changeset
291 sinits_ty.push_back(vfpty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
292 }
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
293 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
294 Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars());
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
295 const llvm::Type* cinfoty;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
296 if (cd->isInterfaceDeclaration()) {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
297 cinfoty = infoTy;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
298 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
299 else if (cd != ClassDeclaration::classinfo) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
300 cinfoty = ClassDeclaration::classinfo->type->llvmType->get();
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
301 }
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
302 else {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
303 // this is the ClassInfo class, the type is this type
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
304 cinfoty = ts->llvmType->get();
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
305 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
306 const llvm::Type* cty = getPtrToType(cinfoty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
307 sinits_ty.push_back(cty);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
308 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
309 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
310 assert(0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
311 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
312
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
313 assert(!sinits_ty.empty());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
314 const llvm::StructType* svtbl_ty = llvm::StructType::get(sinits_ty);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
315
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
316 std::string styname(cd->mangle());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
317 styname.append("__vtblType");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
318 gIR->module->addTypeName(styname, svtbl_ty);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
319
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
320 // refine for final vtable type
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
321 llvm::cast<llvm::OpaqueType>(ts->llvmVtblType->get())->refineAbstractTypeTo(svtbl_ty);
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
322
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
323 gIR->classes.pop_back();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
324 gIR->structs.pop_back();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
325
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
326 gIR->declareList.push_back(cd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
327 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
328
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
329 //////////////////////////////////////////////////////////////////////////////////////////
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
330
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
331 void DtoDeclareClass(ClassDeclaration* cd)
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
332 {
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
333 if (cd->llvmDeclared) return;
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
334 cd->llvmDeclared = true;
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
335
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
336 Logger::println("DtoDeclareClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
337 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
338
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
339 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
340 TypeClass* ts = (TypeClass*)cd->type;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
341
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
342 assert(cd->irStruct);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
343 IrStruct* irstruct = cd->irStruct;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
344
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
345 gIR->structs.push_back(irstruct);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
346 gIR->classes.push_back(cd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
347
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
348 bool needs_definition = false;
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
349 if (cd->getModule() == gIR->dmodule) {
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
350 needs_definition = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
351 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
352
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
353 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage;
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
354
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
355 // interfaces have no static initializer
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
356 // same goes for abstract classes
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
357 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
358 // vtable
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
359 std::string varname("_D");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
360 varname.append(cd->mangle());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
361 varname.append("6__vtblZ");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
362
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
363 const llvm::StructType* svtbl_ty = isaStruct(ts->llvmVtblType->get());
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
364 cd->irStruct->vtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module);
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
365 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
366
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
367 // get interface info type
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
368 const llvm::StructType* infoTy = DtoInterfaceInfoType();
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
369
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
370 // interface info array
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
371 if (!cd->irStruct->interfaceVec.empty()) {
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
372 // symbol name
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
373 std::string nam = "_D";
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
374 nam.append(cd->mangle());
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
375 nam.append("16__interfaceInfosZ");
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
376 // resolve array type
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
377 const llvm::ArrayType* arrTy = llvm::ArrayType::get(infoTy, cd->irStruct->interfaceVec.size());
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
378 // declare global
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
379 irstruct->interfaceInfosTy = arrTy;
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
380 irstruct->interfaceInfos = new llvm::GlobalVariable(arrTy, true, _linkage, NULL, nam, gIR->module);
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
381 }
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
382
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
383 // interfaces have no static initializer
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
384 // same goes for abstract classes
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
385 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
386 // interface vtables
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
387 unsigned idx = 0;
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
388 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
389 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
390 IrInterface* iri = *i;
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
391 ClassDeclaration* id = iri->decl;
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
392
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
393 std::string nam("_D");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
394 nam.append(cd->mangle());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
395 nam.append("11__interface");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
396 nam.append(id->mangle());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
397 nam.append("6__vtblZ");
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
398
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
399 assert(iri->vtblTy);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
400 iri->vtbl = new llvm::GlobalVariable(iri->vtblTy, true, _linkage, 0, nam, gIR->module);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
401 llvm::Constant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)};
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
402 iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
403 idx++;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
404 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
405
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
406 // init
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
407 std::string initname("_D");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
408 initname.append(cd->mangle());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
409 initname.append("6__initZ");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
410
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
411 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
412 cd->irStruct->init = initvar;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
413 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
414
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
415 gIR->classes.pop_back();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
416 gIR->structs.pop_back();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
417
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
418 gIR->constInitList.push_back(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
419 if (needs_definition)
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
420 gIR->defineList.push_back(cd);
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
421
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
422 // classinfo
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
423 DtoDeclareClassInfo(cd);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
424
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
425 // typeinfo
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
426 if (needs_definition)
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 103
diff changeset
427 cd->type->getTypeInfo(NULL);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
428 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
429
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
430 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
431
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
432 void DtoConstInitClass(ClassDeclaration* cd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
433 {
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
434 if (cd->llvmInitialized) return;
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
435 cd->llvmInitialized = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
436
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
437 if (cd->isInterfaceDeclaration())
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
438 return; // nothing to do
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
439
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
440 Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
441 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
442
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
443 IrStruct* irstruct = cd->irStruct;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
444 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
445 gIR->classes.push_back(cd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
446
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
447 // get the struct (class) type
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
448 assert(cd->type->ty == Tclass);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
449 TypeClass* ts = (TypeClass*)cd->type;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
450 const llvm::StructType* structtype = isaStruct(ts->llvmType->get());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
451 const llvm::StructType* vtbltype = isaStruct(ts->llvmVtblType->get());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
452
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
453 // make sure each offset knows its default initializer
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
454 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
455 {
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
456 IrStruct::Offset* so = &i->second;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
457 llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
458 so->init = finit;
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
459 so->var->irField->constInit = finit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
460 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
461
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
462 // fill out fieldtypes/inits
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
463 std::vector<llvm::Constant*> fieldinits;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
464
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
465 // first field is always the vtable
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
466 if (cd->isAbstract())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
467 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
468 fieldinits.push_back(
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
469 llvm::ConstantPointerNull::get(
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
470 getPtrToType(
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
471 ts->llvmVtblType->get()
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
472 )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
473 )
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
474 );
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
475 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
476 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
477 {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
478 assert(cd->irStruct->vtbl != 0);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
479 fieldinits.push_back(cd->irStruct->vtbl);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
480 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
481
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
482 // then comes monitor
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
483 fieldinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
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
484
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
485 // go through the field inits and build the default initializer
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
486 size_t nfi = irstruct->defaultFields.size();
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
487 for (size_t i=0; i<nfi; ++i) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
488 llvm::Constant* c;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
489 if (irstruct->defaultFields[i]) {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
490 c = irstruct->defaultFields[i]->irField->constInit;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
491 assert(c);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
492 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
493 else {
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
494 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2));
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
495 assert(arrty);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
496 std::vector<llvm::Constant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
497 c = llvm::ConstantArray::get(arrty, vals);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
498 }
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
499 fieldinits.push_back(c);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
500 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
501
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
502 // last comes interface vtables
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
503 const llvm::StructType* infoTy = DtoInterfaceInfoType();
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
504 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
505 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
506 IrInterface* iri = *i;
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
507 iri->infoTy = infoTy;
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
508
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
509 if (cd->isAbstract())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
510 {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
511 fieldinits.push_back(llvm::Constant::getNullValue(structtype->getElementType(iri->index)));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
512 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
513 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
514 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
515 assert(iri->vtbl);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
516 fieldinits.push_back(iri->vtbl);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
517 }
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
518 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
519
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
520 // generate initializer
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
521 #if 0
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
522 //Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n';
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
523 assert(fieldinits.size() == structtype->getNumElements());
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
524 for(size_t i=0; i<structtype->getNumElements(); ++i) {
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
525 Logger::cout() << "s#" << i << " = " << *structtype->getElementType(i) << '\n';
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
526 Logger::cout() << "i#" << i << " = " << *fieldinits[i] << '\n';
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
527 assert(fieldinits[i]->getType() == structtype->getElementType(i));
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
528 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
529 #endif
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
530
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
531 #if 0
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
532 for(size_t i=0; i<fieldinits.size(); ++i) {
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
533 Logger::cout() << "i#" << i << " = " << *fieldinits[i]->getType() << '\n';
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
534 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
535 #endif
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
536
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
537 llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
538 assert(_init);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
539 cd->irStruct->constInit = _init;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
540
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
541 // abstract classes have no static vtable
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
542 // neither do interfaces (on their own, the implementing class supplies the vtable)
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
543 if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
544 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
545 // generate vtable initializer
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
546 std::vector<llvm::Constant*> sinits;
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
547
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
548 for (int k=0; k < cd->vtbl.dim; k++)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
549 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
550 Dsymbol* dsym = (Dsymbol*)cd->vtbl.data[k];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
551 assert(dsym);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
552 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
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
553
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
554 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
555 DtoForceDeclareDsymbol(fd);
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
556 assert(fd->irFunc->func);
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
557 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->irFunc->func);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
558 // cast if necessary (overridden method)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
559 if (c->getType() != vtbltype->getElementType(k))
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
560 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
561 sinits.push_back(c);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
562 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
563 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
564 assert(cd->irStruct->classInfo);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
565 llvm::Constant* c = cd->irStruct->classInfo;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
566 sinits.push_back(c);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
567 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
568 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
569 assert(0);
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
570 }
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
571
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
572 const llvm::StructType* svtbl_ty = isaStruct(ts->llvmVtblType->get());
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
573
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
574 #if 0
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
575 for (size_t i=0; i< sinits.size(); ++i)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
576 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
577 Logger::cout() << "field[" << i << "] = " << *svtbl_ty->getElementType(i) << '\n';
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
578 Logger::cout() << "init [" << i << "] = " << *sinits[i]->getType() << '\n';
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
579 assert(svtbl_ty->getElementType(i) == sinits[i]->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
580 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
581 #endif
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
582
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
583 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
584 cd->irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
585
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
586 // create interface vtable const initalizers
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
587 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
588 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
589 IrInterface* iri = *i;
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
590 BaseClass* b = iri->base;
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
591
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
592 ClassDeclaration* id = iri->decl;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
593 assert(id->type->ty == Tclass);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
594 TypeClass* its = (TypeClass*)id->type;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
595
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
596 const llvm::StructType* ivtbl_ty = isaStruct(its->llvmVtblType->get());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
597
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
598 // generate interface info initializer
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
599 std::vector<llvm::Constant*> infoInits;
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
600
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
601 // classinfo
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
602 assert(id->irStruct->classInfo);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
603 llvm::Constant* c = id->irStruct->classInfo;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
604 infoInits.push_back(c);
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
605
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
606 // vtbl
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
607 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
608 c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
609 c = DtoConstSlice(DtoConstSize_t(b->vtbl.dim), c);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
610 infoInits.push_back(c);
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
611
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
612 // offset
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
613 // generate target independent offset with constGEP
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
614 /*llvm::Value* cidx = DtoConstInt(iri->index);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
615 Logger::cout() << "offset to interface in class type: " << *cd->type->llvmType->get() << '\n';
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
616 size_t ioff = gTargetData->getIndexedOffset(cd->type->llvmType->get(), &cidx, 1);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
617 infoInits.push_back(DtoConstUint(ioff));*/
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
618 assert(iri->index >= 0);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
619 size_t ioff = gTargetData->getStructLayout(isaStruct(cd->type->llvmType->get()))->getElementOffset(iri->index);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
620 infoInits.push_back(DtoConstUint(ioff));
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
621
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
622 // create interface info initializer constant
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
623 iri->infoInit = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(iri->infoTy, infoInits));
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
624
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
625 // generate vtable initializer
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
626 std::vector<llvm::Constant*> iinits;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
627
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
628 // add interface info
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
629 iinits.push_back(iri->info);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
630
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
631 for (int k=1; k < b->vtbl.dim; k++)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
632 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
633 Logger::println("interface vtbl const init nr. %d", k);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
634 Dsymbol* dsym = (Dsymbol*)b->vtbl.data[k];
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
635 assert(dsym);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
636 FuncDeclaration* fd = dsym->isFuncDeclaration();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
637 assert(fd);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
638 DtoForceDeclareDsymbol(fd);
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
639 assert(fd->irFunc->func);
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
640 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->irFunc->func);
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
641
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
642 // we have to bitcast, as the type created in ResolveClass expects a different this type
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
643 c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
644 iinits.push_back(c);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
645 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
646
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
647 #if 0
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
648 for (size_t x=0; x< iinits.size(); ++x)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
649 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
650 Logger::cout() << "field[" << x << "] = " << *ivtbl_ty->getElementType(x) << "\n\n";
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
651 Logger::cout() << "init [" << x << "] = " << *iinits[x] << "\n\n";
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
652 assert(ivtbl_ty->getElementType(x) == iinits[x]->getType());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
653 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
654 #endif
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
655
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
656 llvm::Constant* civtblInit = llvm::ConstantStruct::get(ivtbl_ty, iinits);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
657 iri->vtblInit = llvm::cast<llvm::ConstantStruct>(civtblInit);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
658 }
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
659 }
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
660 // we always generate interfaceinfos as best we can
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
661 /*else
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
662 {
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
663 for (IrStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i)
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
664 {
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
665 ClassDeclaration* id = i->first;
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
666 assert(id->type->ty == Tclass);
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
667 TypeClass* its = (TypeClass*)id->type;
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
668
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
669 IrInterface* iri = i->second;
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
670 BaseClass* b = iri->base;
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
671
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
672 // generate interface info initializer
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
673 std::vector<llvm::Constant*> infoInits;
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
674
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
675 // classinfo
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
676 assert(id->irStruct->classInfo);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
677 llvm::Constant* c = id->irStruct->classInfo;
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
678 infoInits.push_back(c);
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
679
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
680 // vtbl
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
681 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
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
682 c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty));
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
683 infoInits.push_back(c);
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
684
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
685 // offset
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
686 infoInits.push_back(DtoConstInt(0));
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
687
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
688 // create interface info initializer constant
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
689 iri->infoInit = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(iri->infoTy, infoInits));
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
690 }
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
691 }*/
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
692
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
693 gIR->classes.pop_back();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
694 gIR->structs.pop_back();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
695 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
696
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
697 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
698
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
699 void DtoDefineClass(ClassDeclaration* cd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
700 {
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
701 if (cd->llvmDefined) return;
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
702 cd->llvmDefined = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
703
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
704 Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
705 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
706
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
707 // get the struct (class) type
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
708 assert(cd->type->ty == Tclass);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
709 TypeClass* ts = (TypeClass*)cd->type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
710
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
711 if (cd->getModule() == gIR->dmodule) {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
712 // interfaces don't have initializers
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
713 // neither do abstract classes
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
714 if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
715 {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
716 cd->irStruct->init->setInitializer(cd->irStruct->constInit);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
717 cd->irStruct->vtbl->setInitializer(cd->irStruct->constVtbl);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
718
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
719 // initialize interface vtables
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
720 IrStruct* irstruct = cd->irStruct;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
721 std::vector<llvm::Constant*> infoInits;
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
722 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
723 {
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
724 IrInterface* iri = *i;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
725 iri->vtbl->setInitializer(iri->vtblInit);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
726 infoInits.push_back(iri->infoInit);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
727 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
728 // initialize interface info array
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
729 if (!infoInits.empty())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
730 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
731 llvm::Constant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
732 irstruct->interfaceInfos->setInitializer(arrInit);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
733 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
734 }
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
735
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
736 // generate classinfo
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
737 DtoDefineClassInfo(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
738 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
739 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
740
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
741 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
742
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
743 DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
744 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
745 // resolve type
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
746 DtoForceDeclareDsymbol(tc->sym);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
747
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
748 // allocate
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
749 llvm::Value* mem;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
750 if (newexp->onstack)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
751 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
752 mem = new llvm::AllocaInst(DtoType(tc)->getContainedType(0), "newclass_alloca", gIR->topallocapoint());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
753 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
754 else
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
755 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
756 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
757 std::vector<llvm::Value*> args;
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
758 args.push_back(tc->sym->irStruct->classInfo);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
759 mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
760 mem = DtoBitCast(mem, DtoType(tc), "newclass_gc");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
761 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
762
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
763 // init
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
764 DtoInitClass(tc, mem);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
765
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
766 // 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
767 if (newexp->thisexp)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
768 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
769 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
770 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
771 DValue* thisval = newexp->thisexp->toElem(gIR);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
772 size_t idx = 2;
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
773 //idx += tc->sym->irStruct->interfaces.size();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
774 llvm::Value* dst = thisval->getRVal();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
775 llvm::Value* src = DtoGEPi(mem,0,idx,"tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
776 Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n';
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
777 DtoStore(dst, src);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
778 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
779 // set the context for nested classes
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
780 else if (tc->sym->isNested())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
781 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
782 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
783 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
784 size_t idx = 2;
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
785 //idx += tc->sym->irStruct->interfaces.size();
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
786 llvm::Value* nest = gIR->func()->decl->irFunc->nestedVar;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
787 if (!nest)
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
788 nest = gIR->func()->decl->irFunc->thisVar;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
789 assert(nest);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
790 llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
791 nest = DtoBitCast(nest, gep->getType()->getContainedType(0));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
792 DtoStore(nest, gep);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
793 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
794
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
795 // call constructor
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
796 if (newexp->arguments)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
797 return DtoCallClassCtor(tc, newexp->member, newexp->arguments, mem);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
798
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
799 // return default constructed class
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
800 return new DImValue(tc, mem, false);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
801 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
802
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
803 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
804
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
805 void DtoInitClass(TypeClass* tc, llvm::Value* dst)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
806 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
807 size_t presz = 2*getABITypeSize(DtoSize_t());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
808 uint64_t n = getABITypeSize(tc->llvmType->get()) - presz;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
809
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
810 // set vtable field seperately, this might give better optimization
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
811 assert(tc->sym->irStruct->vtbl);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
812 DtoStore(tc->sym->irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl"));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
813
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
814 // monitor always defaults to zero
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
815 llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
816 DtoStore(llvm::Constant::getNullValue(tmp->getType()->getContainedType(0)), tmp);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
817
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
818 // done?
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
819 if (n == 0)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
820 return;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
821
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
822 // copy the rest from the static initializer
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
823 assert(tc->sym->irStruct->init);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
824 assert(dst->getType() == tc->sym->irStruct->init->getType());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
825
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
826 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
827
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
828 llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
829 dstarr = DtoBitCast(dstarr, arrty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
830
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
831 llvm::Value* srcarr = DtoGEPi(tc->sym->irStruct->init,0,2,"tmp");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
832 srcarr = DtoBitCast(srcarr, arrty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
833
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
834 llvm::Function* fn = LLVM_DeclareMemCpy32();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
835 std::vector<llvm::Value*> llargs;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
836 llargs.resize(4);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
837 llargs[0] = dstarr;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
838 llargs[1] = srcarr;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
839 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
840 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
841
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
842 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
843 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
844
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
845 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
846
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
847 DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
848 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
849 Logger::println("Calling constructor");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
850 LOG_SCOPE;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
851
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
852 assert(ctor);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
853 DtoForceDeclareDsymbol(ctor);
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
854 llvm::Function* fn = ctor->irFunc->func;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
855 TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
856
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
857 std::vector<llvm::Value*> ctorargs;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
858 ctorargs.push_back(mem);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
859 for (size_t i=0; i<arguments->dim; ++i)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
860 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
861 Expression* ex = (Expression*)arguments->data[i];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
862 Argument* fnarg = Argument::getNth(tf->parameters, i);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
863 DValue* argval = DtoArgument(fnarg, ex);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
864 llvm::Value* a = argval->getRVal();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
865 const llvm::Type* aty = fn->getFunctionType()->getParamType(i+1);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
866 if (a->getType() != aty)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
867 a = DtoBitCast(a, aty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
868 ctorargs.push_back(a);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
869 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
870 llvm::CallInst* call = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", gIR->scopebb());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
871 call->setCallingConv(DtoCallingConv(LINKd));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
872
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
873 return new DImValue(type, call, false);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
874 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
875
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
876 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
877
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
878 void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
879 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
880 Array* arr = &tc->sym->dtors;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
881 for (size_t i=0; i<arr->dim; i++)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
882 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
883 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i];
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
884 assert(fd->irFunc->func);
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
885 new llvm::CallInst(fd->irFunc->func, instance, "", gIR->scopebb());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
886 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
887 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
888
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
889 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
890
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
891 DValue* DtoCastClass(DValue* val, Type* _to)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
892 {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
893 Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars());
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
894 LOG_SCOPE;
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
895
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
896 Type* to = DtoDType(_to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
897 if (to->ty == Tpointer) {
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
898 const llvm::Type* tolltype = DtoType(_to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
899 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
900 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
901 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
902
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
903 assert(to->ty == Tclass);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
904 TypeClass* tc = (TypeClass*)to;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
905
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
906 Type* from = DtoDType(val->getType());
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
907 TypeClass* fc = (TypeClass*)from;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
908
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
909 if (tc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
910 Logger::println("to interface");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
911 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
912 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
913 return DtoDynamicCastInterface(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
914 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
915 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
916 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
917 return DtoDynamicCastObject(val, _to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
918 }
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
919 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
920 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
921 Logger::println("to object");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
922 int poffset;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
923 if (fc->sym->isInterfaceDeclaration()) {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
924 Logger::println("interface cast");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
925 return DtoCastInterfaceToObject(val, _to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
926 }
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
927 else if (!tc->sym->isInterfaceDeclaration() && tc->sym->isBaseOf(fc->sym,NULL)) {
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
928 Logger::println("static down cast)");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
929 const llvm::Type* tolltype = DtoType(_to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
930 llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
931 return new DImValue(_to, rval);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
932 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
933 else {
138
aeddd4d533b3 [svn r142] minor fix to dynamic casts.
lindquist
parents: 137
diff changeset
934 Logger::println("dynamic up cast");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
935 return DtoDynamicCastObject(val, _to);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
936 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
937 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
938 }
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
939
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
940 //////////////////////////////////////////////////////////////////////////////////////////
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
941
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
942 DValue* DtoDynamicCastObject(DValue* val, Type* _to)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
943 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
944 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
945 // Object _d_dynamic_cast(Object o, ClassInfo c)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
946
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
947 DtoForceDeclareDsymbol(ClassDeclaration::object);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
948 DtoForceDeclareDsymbol(ClassDeclaration::classinfo);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
949
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
950 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
951 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
952
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
953 std::vector<llvm::Value*> args;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
954
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
955 // Object o
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
956 llvm::Value* tmp = val->getRVal();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
957 tmp = DtoBitCast(tmp, funcTy->getParamType(0));
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
958 args.push_back(tmp);
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
959 assert(funcTy->getParamType(0) == tmp->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
960
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
961 // ClassInfo c
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
962 TypeClass* to = (TypeClass*)DtoDType(_to);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
963 DtoForceDeclareDsymbol(to->sym);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
964 assert(to->sym->irStruct->classInfo);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
965 tmp = to->sym->irStruct->classInfo;
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
966 // unfortunately this is needed as the implementation of object differs somehow from the declaration
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
967 // this could happen in user code as well :/
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
968 tmp = DtoBitCast(tmp, funcTy->getParamType(1));
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
969 args.push_back(tmp);
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
970 assert(funcTy->getParamType(1) == tmp->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
971
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
972 // call it
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
973 llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
974
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
975 // cast return value
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
976 ret = DtoBitCast(ret, DtoType(_to));
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
977
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
978 return new DImValue(_to, ret);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
979 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
980
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
981 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
982
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
983 DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
984 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
985 // call:
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
986 // Object _d_toObject(void* p)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
987
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
988 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_toObject");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
989 const llvm::FunctionType* funcTy = func->getFunctionType();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
990
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
991 // void* p
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
992 llvm::Value* tmp = val->getRVal();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
993 tmp = DtoBitCast(tmp, funcTy->getParamType(0));
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
994
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
995 // call it
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
996 llvm::Value* ret = gIR->ir->CreateCall(func, tmp, "tmp");
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
997
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
998 // cast return value
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
999 if (to != NULL)
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1000 ret = DtoBitCast(ret, DtoType(to));
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1001 else
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1002 to = ClassDeclaration::object->type;
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1003
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1004 return new DImValue(to, ret);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1005 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1006
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1007 //////////////////////////////////////////////////////////////////////////////////////////
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1008
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1009 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
1010 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1011 // call:
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1012 // 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
1013
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1014 DtoForceDeclareDsymbol(ClassDeclaration::object);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1015 DtoForceDeclareDsymbol(ClassDeclaration::classinfo);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1016
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1017 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
1018 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
1019
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1020 std::vector<llvm::Value*> args;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1021
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1022 // void* p
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1023 llvm::Value* tmp = val->getRVal();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1024 tmp = DtoBitCast(tmp, funcTy->getParamType(0));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1025 args.push_back(tmp);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1026
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1027 // ClassInfo c
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1028 TypeClass* to = (TypeClass*)DtoDType(_to);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1029 DtoForceDeclareDsymbol(to->sym);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1030 assert(to->sym->irStruct->classInfo);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1031 tmp = to->sym->irStruct->classInfo;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1032 // 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
1033 // this could happen in user code as well :/
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1034 tmp = DtoBitCast(tmp, funcTy->getParamType(1));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1035 args.push_back(tmp);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1036
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1037 // call it
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1038 llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1039
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1040 // cast return value
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1041 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
1042
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1043 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
1044 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1045
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1046 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1047
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1048 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1049 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1050 // start at the bottom of the inheritance chain
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1051 if (cd->baseClass != 0) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1052 unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1053 if (o != (unsigned)-1)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1054 return o;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1055 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1056
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1057 // check this class
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1058 unsigned i;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1059 for (i=0; i<cd->fields.dim; ++i) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1060 VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1061 if (os == vd->offset)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1062 return i+idx;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1063 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1064 idx += i;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1065
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1066 return (unsigned)-1;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1067 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1068
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1069 //////////////////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1070
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1071 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1072 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1073 unsigned idx = 0;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1074 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1075 assert(r != (unsigned)-1 && "Offset not found in any aggregate field");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1076 // vtable is 0, monitor is 1
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1077 r += 2;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1078 // interface offset further
142
a123dca8349b [svn r146] fixed some potential problems with mismatch in order of interfaces in class data layout
lindquist
parents: 138
diff changeset
1079 //r += vtblInterfaces->dim;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1080 // the final index was not pushed
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1081 result.push_back(r);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1082 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1083
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1084 //////////////////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1085
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1086 llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector<unsigned>& idxs)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1087 {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1088 Logger::println("checking for offset %u type %s:", os, t->toChars());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1089 LOG_SCOPE;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1090
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1091 if (idxs.empty())
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1092 idxs.push_back(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1093
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1094 const llvm::Type* llt = getPtrToType(DtoType(t));
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1095 const llvm::Type* st = DtoType(cd->type);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1096 if (ptr->getType() != st) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1097 assert(cd->irStruct->hasUnions);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1098 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1099 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1100
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1101 unsigned dataoffset = 2;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1102
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1103 IrStruct* irstruct = cd->irStruct;
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
1104 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1105 //for (unsigned i=0; i<cd->fields.dim; ++i) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1106 //VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1107 VarDeclaration* vd = i->second.var;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1108 assert(vd);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1109 Type* vdtype = DtoDType(vd->type);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1110 Logger::println("found %u type %s", vd->offset, vdtype->toChars());
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
1111 assert(vd->irField->index >= 0);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1112 if (os == vd->offset && vdtype == t) {
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
1113 idxs.push_back(vd->irField->index + dataoffset);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1114 Logger::cout() << "indexing: " << *ptr << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1115 ptr = DtoGEP(ptr, idxs, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1116 if (ptr->getType() != llt)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1117 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1118 Logger::cout() << "indexing: " << *ptr << '\n';
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
1119 if (vd->irField->indexOffset)
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
1120 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1121 Logger::cout() << "indexing: " << *ptr << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1122 return ptr;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1123 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1124 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1125 TypeStruct* ts = (TypeStruct*)vdtype;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1126 StructDeclaration* ssd = ts->sym;
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
1127 idxs.push_back(vd->irField->index + dataoffset);
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
1128 if (vd->irField->indexOffset) {
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1129 Logger::println("has union field offset");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1130 ptr = DtoGEP(ptr, idxs, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1131 if (ptr->getType() != llt)
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1132 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
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
1133 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1134 std::vector<unsigned> tmp;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1135 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1136 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1137 else {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1138 const llvm::Type* sty = getPtrToType(DtoType(vd->type));
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1139 if (ptr->getType() != sty) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1140 ptr = gIR->ir->CreateBitCast(ptr, sty, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1141 std::vector<unsigned> tmp;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1142 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1143 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1144 else {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1145 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, idxs);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1146 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1147 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1148 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1149 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1150
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1151 assert(0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1152
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1153 size_t llt_sz = getABITypeSize(llt->getContainedType(0));
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1154 assert(os % llt_sz == 0);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1155 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1156 return new llvm::GetElementPtrInst(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb());
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1157 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1158
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1159 //////////////////////////////////////////////////////////////////////////////////////////
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 123
diff changeset
1160
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1161 llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1162 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1163 assert(fdecl->isVirtual());//fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual()));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1164 assert(fdecl->vtblIndex > 0);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1165 assert(DtoDType(inst->getType())->ty == Tclass);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1166
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1167 llvm::Value* vthis = inst->getRVal();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1168 //Logger::cout() << "vthis: " << *vthis << '\n';
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1169
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1170 llvm::Value* funcval;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1171 funcval = DtoGEPi(vthis, 0, 0, "tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1172 funcval = DtoLoad(funcval);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1173 funcval = DtoGEPi(funcval, 0, fdecl->vtblIndex, fdecl->toPrettyChars());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1174 funcval = DtoLoad(funcval);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1175
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1176 //assert(funcval->getType() == DtoType(fdecl->type));
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1177 //cc = DtoCallingConv(fdecl->linkage);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1178
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1179 return funcval;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1180 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1181
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1182 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1183
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1184 void DtoDeclareClassInfo(ClassDeclaration* cd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1185 {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1186 if (cd->irStruct->classDeclared) return;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1187 cd->irStruct->classDeclared = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1188
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
1189 Logger::println("DtoDeclareClassInfo(%s)", cd->toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1190 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1191
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1192 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
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
1193 DtoResolveClass(cinfo);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1194
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1195 std::string gname("_D");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1196 gname.append(cd->mangle());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1197 if (!cd->isInterfaceDeclaration())
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1198 gname.append("7__ClassZ");
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1199 else
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1200 gname.append("11__InterfaceZ");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1201
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
1202 const llvm::Type* st = cinfo->type->llvmType->get();
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
1203
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1204 cd->irStruct->classInfo = new llvm::GlobalVariable(st, true, llvm::GlobalValue::ExternalLinkage, NULL, gname, gIR->module);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1205 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1206
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1207 static llvm::Constant* build_offti_entry(VarDeclaration* vd)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1208 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1209 std::vector<const llvm::Type*> types;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1210 std::vector<llvm::Constant*> inits;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1211
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1212 types.push_back(DtoSize_t());
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1213
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1214 size_t offset = vd->offset; // TODO might not be the true offset
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1215 // dmd only accounts for the vtable, not classinfo or monitor
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1216 if (global.params.is64bit)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1217 offset += 8;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1218 else
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1219 offset += 4;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1220 inits.push_back(DtoConstSize_t(offset));
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1221
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1222 vd->type->getTypeInfo(NULL);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1223 assert(vd->type->vtinfo);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1224 DtoForceDeclareDsymbol(vd->type->vtinfo);
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
1225 llvm::Constant* c = isaConstant(vd->type->vtinfo->getIrValue());
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1226
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1227 const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->llvmType->get());
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 121
diff changeset
1228 //Logger::cout() << "tiTy = " << *tiTy << '\n';
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1229
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1230 types.push_back(tiTy);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1231 inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy));
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1232
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1233 const llvm::StructType* sTy = llvm::StructType::get(types);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1234 return llvm::ConstantStruct::get(sTy, inits);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1235 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1236
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1237 static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* init)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1238 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1239 const llvm::StructType* initTy = isaStruct(init->getType());
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1240 assert(initTy);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1241
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1242 std::vector<llvm::Constant*> arrayInits;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1243 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1244 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1245 if (cd2->members)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1246 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1247 for (size_t i = 0; i < cd2->members->dim; i++)
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1248 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1249 Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1250 if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough?
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1251 {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1252 llvm::Constant* c = build_offti_entry(vd);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1253 assert(c);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1254 arrayInits.push_back(c);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1255 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1256 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1257 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1258 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1259
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1260 size_t ninits = arrayInits.size();
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1261 llvm::Constant* size = DtoConstSize_t(ninits);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1262 llvm::Constant* ptr;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1263
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1264 if (ninits > 0) {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1265 // OffsetTypeInfo type
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1266 std::vector<const llvm::Type*> elemtypes;
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1267 elemtypes.push_back(DtoSize_t());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1268 const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->llvmType->get());
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1269 elemtypes.push_back(tiTy);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1270 const llvm::StructType* sTy = llvm::StructType::get(elemtypes);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1271
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1272 // array type
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1273 const llvm::ArrayType* arrTy = llvm::ArrayType::get(sTy, ninits);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1274 llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1275
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1276 std::string name(cd->type->vtinfo->toChars());
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1277 name.append("__OffsetTypeInfos");
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1278 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,llvm::GlobalValue::InternalLinkage,arrInit,name,gIR->module);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1279 ptr = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(sTy));
110
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1280 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1281 else {
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1282 ptr = llvm::ConstantPointerNull::get(isaPointer(initTy->getElementType(1)));
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1283 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1284
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1285 return DtoConstSlice(size, ptr);
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1286 }
e8da7856a260 [svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents: 106
diff changeset
1287
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1288 static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1289 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1290 // construct the function
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1291 std::vector<const llvm::Type*> paramTypes;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1292 paramTypes.push_back(getPtrToType(cd->type->llvmType->get()));
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1293
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1294 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false);
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1295
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1296 if (cd->dtors.dim == 0) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1297 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty));
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1298 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1299 else if (cd->dtors.dim == 1) {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1300 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0];
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1301 DtoForceDeclareDsymbol(d);
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
1302 assert(d->irFunc->func);
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
1303 return llvm::ConstantExpr::getBitCast(isaConstant(d->irFunc->func), getPtrToType(llvm::Type::Int8Ty));
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1304 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1305
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1306 std::string gname("_D");
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1307 gname.append(cd->mangle());
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1308 gname.append("12__destructorMFZv");
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1309
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1310 llvm::Function* func = new llvm::Function(fnTy, llvm::GlobalValue::InternalLinkage, gname, gIR->module);
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1311 llvm::Value* thisptr = func->arg_begin();
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1312 thisptr->setName("this");
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1313
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1314 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", func);
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1315 LLVMBuilder builder(bb);
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1316
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1317 for (size_t i = 0; i < cd->dtors.dim; i++)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1318 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1319 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i];
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1320 DtoForceDeclareDsymbol(d);
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
1321 assert(d->irFunc->func);
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
1322 builder.CreateCall(d->irFunc->func, thisptr);
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1323 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1324 builder.CreateRetVoid();
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1325
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1326 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty));
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1327 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1328
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1329 static uint build_classinfo_flags(ClassDeclaration* cd)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1330 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1331 // adapted from original dmd code
112
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1332 uint flags = 0;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1333 //flags |= isCOMclass(); // IUnknown
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1334 bool hasOffTi = false;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1335 if (cd->ctor) flags |= 8;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1336 for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1337 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1338 if (cd2->members)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1339 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1340 for (size_t i = 0; i < cd2->members->dim; i++)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1341 {
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1342 Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1343 if (sm->isVarDeclaration()) // is this enough?
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1344 hasOffTi = true;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1345 //printf("sm = %s %s\n", sm->kind(), sm->toChars());
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1346 if (sm->hasPointers())
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1347 goto L2;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1348 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1349 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1350 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1351 flags |= 2; // no pointers
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1352 L2:
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1353 if (hasOffTi)
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1354 flags |= 4;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1355 return flags;
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1356 }
368547b1cbe6 [svn r116] Implemented the ClassInfo.destructor field.
lindquist
parents: 111
diff changeset
1357
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1358 void DtoDefineClassInfo(ClassDeclaration* cd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1359 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1360 // The layout is:
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1361 // {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1362 // void **vptr;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1363 // monitor_t monitor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1364 // byte[] initializer; // static initialization data
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1365 // char[] name; // class name
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1366 // void *[] vtbl;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1367 // Interface[] interfaces;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1368 // ClassInfo *base; // base class
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1369 // void *destructor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1370 // void *invariant; // class invariant
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1371 // uint flags;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1372 // void *deallocator;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1373 // OffsetTypeInfo[] offTi;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1374 // void *defaultConstructor;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1375 // }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1376
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1377 if (cd->irStruct->classDefined) return;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1378 cd->irStruct->classDefined = true;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1379
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
1380 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
1381 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1382
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
1383 assert(cd->type->ty == Tclass);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1384 assert(cd->irStruct->classInfo);
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
1385
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
1386 TypeClass* cdty = (TypeClass*)cd->type;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1387 if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1388 assert(cd->irStruct->init);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1389 assert(cd->irStruct->constInit);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1390 assert(cd->irStruct->vtbl);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1391 assert(cd->irStruct->constVtbl);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1392 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1393
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1394 // holds the list of initializers for llvm
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1395 std::vector<llvm::Constant*> inits;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1396
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1397 ClassDeclaration* cinfo = ClassDeclaration::classinfo;
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
1398 DtoForceConstInitDsymbol(cinfo);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1399 assert(cinfo->irStruct->constInit);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1400
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1401 llvm::Constant* c;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1402
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1403 // own vtable
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1404 c = cinfo->irStruct->constInit->getOperand(0);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1405 assert(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1406 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1407
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1408 // monitor
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1409 c = cinfo->irStruct->constInit->getOperand(1);
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
1410 inits.push_back(c);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1411
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
1412 // byte[] init
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1413 const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1414 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1415 c = cinfo->irStruct->constInit->getOperand(2);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1416 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1417 else {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1418 c = llvm::ConstantExpr::getBitCast(cd->irStruct->init, byteptrty);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1419 assert(!cd->irStruct->constInit->getType()->isAbstract());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1420 size_t initsz = getABITypeSize(cd->irStruct->constInit->getType());
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1421 c = DtoConstSlice(DtoConstSize_t(initsz), c);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1422 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1423 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1424
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1425 // class name
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1426 // from dmd
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1427 char *name = cd->ident->toChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1428 size_t namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1429 if (!(namelen > 9 && memcmp(name, "TypeInfo_", 9) == 0))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1430 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1431 name = cd->toPrettyChars();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1432 namelen = strlen(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1433 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1434 c = DtoConstString(name);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1435 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1436
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1437 // vtbl array
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1438 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1439 c = cinfo->irStruct->constInit->getOperand(4);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1440 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1441 else {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1442 const llvm::Type* byteptrptrty = getPtrToType(byteptrty);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1443 assert(!cd->irStruct->vtbl->getType()->isAbstract());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1444 c = llvm::ConstantExpr::getBitCast(cd->irStruct->vtbl, byteptrptrty);
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1445 assert(!cd->irStruct->constVtbl->getType()->isAbstract());
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1446 size_t vtblsz = cd->irStruct->constVtbl->getType()->getNumElements();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1447 c = DtoConstSlice(DtoConstSize_t(vtblsz), c);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1448 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1449 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1450
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1451 // interfaces array
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1452 IrStruct* irstruct = cd->irStruct;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1453 if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1454 c = cinfo->irStruct->constInit->getOperand(5);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1455 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1456 else {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1457 const llvm::Type* t = cinfo->irStruct->constInit->getOperand(5)->getType()->getContainedType(1);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1458 c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1459 size_t iisz = irstruct->interfaceInfosTy->getNumElements();
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1460 c = DtoConstSlice(DtoConstSize_t(iisz), c);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1461 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1462 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1463
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1464 // base classinfo
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1465 if (cd->baseClass && !cd->isInterfaceDeclaration() && !cd->isAbstract()) {
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
1466 DtoDeclareClassInfo(cd->baseClass);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1467 c = cd->baseClass->irStruct->classInfo;
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
1468 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
1469 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
1470 }
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
1471 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
1472 // null
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1473 c = cinfo->irStruct->constInit->getOperand(6);
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
1474 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
1475 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1476
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1477 // destructor
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1478 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1479 c = cinfo->irStruct->constInit->getOperand(7);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1480 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1481 else {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1482 c = build_class_dtor(cd);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1483 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1484 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1485
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1486 // invariant
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
1487 // TODO
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1488 c = cinfo->irStruct->constInit->getOperand(8);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1489 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1490
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1491 // uint flags
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1492 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1493 c = cinfo->irStruct->constInit->getOperand(9);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1494 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1495 else {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1496 uint flags = build_classinfo_flags(cd);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1497 c = DtoConstUint(flags);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1498 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1499 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1500
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1501 // allocator
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
1502 // TODO
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1503 c = cinfo->irStruct->constInit->getOperand(10);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1504 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1505
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1506 // offset typeinfo
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1507 if (cd->isInterfaceDeclaration() || cd->isAbstract()) {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1508 c = cinfo->irStruct->constInit->getOperand(11);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1509 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1510 else {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1511 c = build_offti_array(cd, cinfo->irStruct->constInit->getOperand(11));
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 112
diff changeset
1512 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1513 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1514
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1515 // default constructor
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1516 if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) {
111
a7ae554ce4f4 [svn r115] Implemented the ClassInfo.defaultConstructor member.
lindquist
parents: 110
diff changeset
1517 DtoForceDeclareDsymbol(cd->defaultCtor);
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
1518 c = isaConstant(cd->defaultCtor->irFunc->func);
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1519 const llvm::Type* toTy = cinfo->irStruct->constInit->getOperand(12)->getType();
117
56a21f3e5d3e [svn r121] Finished ModuleInfo implementation.
lindquist
parents: 115
diff changeset
1520 c = llvm::ConstantExpr::getBitCast(c, toTy);
111
a7ae554ce4f4 [svn r115] Implemented the ClassInfo.defaultConstructor member.
lindquist
parents: 110
diff changeset
1521 }
a7ae554ce4f4 [svn r115] Implemented the ClassInfo.defaultConstructor member.
lindquist
parents: 110
diff changeset
1522 else {
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1523 c = cinfo->irStruct->constInit->getOperand(12);
111
a7ae554ce4f4 [svn r115] Implemented the ClassInfo.defaultConstructor member.
lindquist
parents: 110
diff changeset
1524 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1525 inits.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1526
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1527 /*size_t n = inits.size();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1528 for (size_t i=0; i<n; ++i)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1529 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1530 Logger::cout() << "inits[" << i << "]: " << *inits[i] << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1531 }*/
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1532
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1533 // build the initializer
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1534 const llvm::StructType* st = isaStruct(cinfo->irStruct->constInit->getType());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1535 llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1536 //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1537
137
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1538 cd->irStruct->constClassInfo = finalinit;
ce7b81fb957f [svn r141] fixed more problems with classinfo
lindquist
parents: 136
diff changeset
1539 cd->irStruct->classInfo->setInitializer(finalinit);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents:
diff changeset
1540 }