annotate gen/structs.cpp @ 213:7816aafeea3c trunk

[svn r229] Updated the object.d implementation to the latest Tango. Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array. Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 . Cleaned up some type code. Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant. Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
author lindquist
date Fri, 30 May 2008 19:32:04 +0200
parents 9d44ec83acd1
children 0806379a5eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
1 #include <algorithm>
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
2
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
3 #include "gen/llvm.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
4
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
5 #include "mtype.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
6 #include "aggregate.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
7 #include "init.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
8 #include "declaration.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
9
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
10 #include "gen/irstate.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
11 #include "gen/tollvm.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
12 #include "gen/arrays.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
14 #include "gen/structs.h"
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
15
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
16 #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
17
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
18 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
19
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
20 const LLType* DtoStructType(Type* t)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
21 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
22 assert(0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
23 std::vector<const LLType*> types;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
24 return llvm::StructType::get(types);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
25 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
26
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
27 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
28
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
29 LLValue* DtoStructZeroInit(LLValue* v)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
30 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
31 assert(gIR);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
32 uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
33 //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
34 const LLType* sarrty = getPtrToType(llvm::Type::Int8Ty);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
35
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
36 LLValue* sarr = DtoBitCast(v, sarrty);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
37
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
38 llvm::Function* fn = LLVM_DeclareMemSet32();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
39 assert(fn);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
40 std::vector<LLValue*> llargs;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
41 llargs.resize(4);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
42 llargs[0] = sarr;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
43 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
44 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
45 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
46
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
47 LLValue* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
48
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
49 return ret;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
50 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
51
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
52 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
53
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
54 LLValue* DtoStructCopy(LLValue* dst, LLValue* src)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
55 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
56 Logger::cout() << "dst = " << *dst << " src = " << *src << '\n';
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
57 assert(dst->getType() == src->getType());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
58 assert(gIR);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
59
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
60 uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
61 //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
62 const LLType* arrty = getPtrToType(llvm::Type::Int8Ty);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
63
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
64 LLValue* dstarr = DtoBitCast(dst,arrty);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
65 LLValue* srcarr = DtoBitCast(src,arrty);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
66
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
67 llvm::Function* fn = LLVM_DeclareMemCpy32();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
68 std::vector<LLValue*> llargs;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
69 llargs.resize(4);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
70 llargs[0] = dstarr;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
71 llargs[1] = srcarr;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
72 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
73 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
74
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
75 return llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
76 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
77
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
78 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
79 LLConstant* DtoConstStructInitializer(StructInitializer* si)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
80 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
81 Logger::println("DtoConstStructInitializer: %s", si->toChars());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
82 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
83
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
84 TypeStruct* ts = (TypeStruct*)si->ad->type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
85
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
86 const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
87 Logger::cout() << "llvm struct type: " << *structtype << '\n';
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
89 assert(si->value.dim == si->vars.dim);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
90
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
91 std::vector<DUnionIdx> inits;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
92 for (int i = 0; i < si->value.dim; ++i)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
93 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
94 Initializer* ini = (Initializer*)si->value.data[i];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
95 assert(ini);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
96 VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
97 assert(vd);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
98 LLConstant* v = DtoConstInitializer(vd->type, ini);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
99 inits.push_back(DUnionIdx(vd->ir.irField->index, vd->ir.irField->indexOffset, v));
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
100 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
101
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
102 DtoConstInitStruct((StructDeclaration*)si->ad);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
103 return si->ad->ir.irStruct->dunion->getConst(inits);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
104 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
105
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
106 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
107
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
108 LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
109 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
110 Logger::println("checking for offset %u type %s:", os, t->toChars());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
111 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
112
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
113 if (idxs.empty())
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
114 idxs.push_back(0);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
115
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
116 const LLType* llt = getPtrToType(DtoType(t));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
117 const LLType* st = getPtrToType(DtoType(sd->type));
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
118 if (ptr->getType() != st) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
119 assert(sd->ir.irStruct->hasUnions);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
120 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
121 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
122
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
123 for (unsigned i=0; i<sd->fields.dim; ++i) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
124 VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
125 Type* vdtype = DtoDType(vd->type);
169
2df270e1ba59 [svn r185] Fixed broken nested classes with data members, did DMD change the class layout? tango.text.Regex now compiles.
lindquist
parents: 157
diff changeset
126 //Logger::println("found %u type %s", vd->offset, vdtype->toChars());
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
127 assert(vd->ir.irField->index >= 0);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
128 if (os == vd->offset && vdtype == t) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
129 idxs.push_back(vd->ir.irField->index);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
130 ptr = DtoGEP(ptr, idxs, "tmp");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
131 if (ptr->getType() != llt)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
132 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
133 if (vd->ir.irField->indexOffset)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
134 ptr = llvm::GetElementPtrInst::Create(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
135 return ptr;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
136 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
137 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
138 TypeStruct* ts = (TypeStruct*)vdtype;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
139 StructDeclaration* ssd = ts->sym;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
140 idxs.push_back(vd->ir.irField->index);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
141 if (vd->ir.irField->indexOffset) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
142 Logger::println("has union field offset");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
143 ptr = DtoGEP(ptr, idxs, "tmp");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
144 if (ptr->getType() != llt)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
145 ptr = DtoBitCast(ptr, llt);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
146 ptr = llvm::GetElementPtrInst::Create(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
147 std::vector<unsigned> tmp;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
148 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
149 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
150 else {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
151 const LLType* sty = getPtrToType(DtoType(vd->type));
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
152 if (ptr->getType() != sty) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
153 ptr = DtoBitCast(ptr, sty);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
154 std::vector<unsigned> tmp;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
155 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
156 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
157 else {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
158 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, idxs);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
159 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
160 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
161 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
162 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
163
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
164 size_t llt_sz = getTypeStoreSize(llt->getContainedType(0));
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
165 assert(os % llt_sz == 0);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
166 ptr = DtoBitCast(ptr, llt);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 173
diff changeset
167 return llvm::GetElementPtrInst::Create(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
168 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
169
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
170 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
171
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
172 void DtoResolveStruct(StructDeclaration* sd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
173 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
174 if (sd->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
175 sd->ir.resolved = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
176
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
177 Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
178 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
179
171
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
180 if (sd->prot() == PROTprivate && sd->getModule() != gIR->dmodule)
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
181 Logger::println("using a private struct from outside its module");
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
182
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
183 TypeStruct* ts = (TypeStruct*)DtoDType(sd->type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
184
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
185 IrStruct* irstruct = new IrStruct(ts);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
186 sd->ir.irStruct = irstruct;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
187 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
188
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
189 // fields
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
190 Array* arr = &sd->fields;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
191 for (int k=0; k < arr->dim; k++) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
192 VarDeclaration* v = (VarDeclaration*)arr->data[k];
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
193 v->toObjFile();
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
194 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
195
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
196 bool thisModule = false;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
197 if (sd->getModule() == gIR->dmodule)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
198 thisModule = true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
199
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
200 // methods
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
201 arr = sd->members;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
202 for (int k=0; k < arr->dim; k++) {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
203 Dsymbol* s = (Dsymbol*)arr->data[k];
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
204 if (FuncDeclaration* fd = s->isFuncDeclaration()) {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
205 if (thisModule || (fd->prot() != PROTprivate)) {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
206 fd->toObjFile();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
207 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
208 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
209 else if (s->isAttribDeclaration()) {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
210 s->toObjFile();
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
211 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
212 else {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
213 Logger::println("Ignoring dsymbol '%s' in this->members of kind '%s'", s->toPrettyChars(), s->kind());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
214 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
215 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
216
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
217 /*for (int k=0; k < sd->members->dim; k++) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
218 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
219 dsym->toObjFile();
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
220 }*/
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
221
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
222 Logger::println("doing struct fields");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
223
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
224 const llvm::StructType* structtype = 0;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
225 std::vector<const LLType*> fieldtypes;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
226
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
227 if (irstruct->offsets.empty())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
228 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
229 Logger::println("has no fields");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
230 fieldtypes.push_back(llvm::Type::Int8Ty);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
231 structtype = llvm::StructType::get(fieldtypes);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
232 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
233 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
234 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
235 Logger::println("has fields");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
236 unsigned prevsize = (unsigned)-1;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
237 unsigned lastoffset = (unsigned)-1;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
238 const LLType* fieldtype = NULL;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
239 VarDeclaration* fieldinit = NULL;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
240 size_t fieldpad = 0;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
241 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
242 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
243 // first iteration
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
244 if (lastoffset == (unsigned)-1) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
245 lastoffset = i->first;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
246 assert(lastoffset == 0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
247 fieldtype = i->second.type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
248 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
249 prevsize = getABITypeSize(fieldtype);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
250 i->second.var->ir.irField->index = idx;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
251 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
252 // colliding offset?
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
253 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
254 size_t s = getABITypeSize(i->second.type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
255 if (s > prevsize) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
256 fieldpad += s - prevsize;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
257 prevsize = s;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
258 }
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
259 sd->ir.irStruct->hasUnions = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
260 i->second.var->ir.irField->index = idx;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
261 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
262 // intersecting offset?
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
263 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
264 size_t s = getABITypeSize(i->second.type);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
265 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
266 sd->ir.irStruct->hasUnions = true;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
267 i->second.var->ir.irField->index = idx;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
268 i->second.var->ir.irField->indexOffset = (i->first - lastoffset) / s;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
269 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
270 // fresh offset
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
271 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
272 // commit the field
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
273 fieldtypes.push_back(fieldtype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
274 irstruct->defaultFields.push_back(fieldinit);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
275 if (fieldpad) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
276 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
277 irstruct->defaultFields.push_back(NULL);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
278 idx++;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
279 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
280
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
281 idx++;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
282
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
283 // start new
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
284 lastoffset = i->first;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
285 fieldtype = i->second.type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
286 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
287 prevsize = getABITypeSize(fieldtype);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
288 i->second.var->ir.irField->index = idx;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
289 fieldpad = 0;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
290 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
291 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
292 fieldtypes.push_back(fieldtype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
293 irstruct->defaultFields.push_back(fieldinit);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
294 if (fieldpad) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
295 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad));
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
296 irstruct->defaultFields.push_back(NULL);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
297 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
298
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
299 Logger::println("creating struct type");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
300 structtype = llvm::StructType::get(fieldtypes);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
301 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
302
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
303 // refine abstract types for stuff like: struct S{S* next;}
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
304 if (irstruct->recty != 0)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
305 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
306 llvm::PATypeHolder& pa = irstruct->recty;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
307 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
308 structtype = isaStruct(pa.get());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
309 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
310
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
311 assert(ts->ir.type == 0);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
312 ts->ir.type = new llvm::PATypeHolder(structtype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
313
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
314 if (sd->parent->isModule()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
315 gIR->module->addTypeName(sd->mangle(),structtype);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
316 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
317
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
318 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
319
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 gIR->declareList.push_back(sd);
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 }
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 //////////////////////////////////////////////////////////////////////////////////////////
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
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 void DtoDeclareStruct(StructDeclaration* sd)
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 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
327 if (sd->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
328 sd->ir.declared = 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
329
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
330 Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->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
331 LOG_SCOPE;
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 TypeStruct* ts = (TypeStruct*)DtoDType(sd->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
334
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
335 std::string initname("_D");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
336 initname.append(sd->mangle());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
337 initname.append("6__initZ");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
338
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 137
diff changeset
339 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
340 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->ir.type->get(), true, _linkage, NULL, initname, gIR->module);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
341 sd->ir.irStruct->init = initvar;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
342
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
343 gIR->constInitList.push_back(sd);
171
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
344 if (DtoIsTemplateInstance(sd) || sd->getModule() == gIR->dmodule)
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->defineList.push_back(sd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
346 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
347
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
348 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
349
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
350 void DtoConstInitStruct(StructDeclaration* sd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
351 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
352 if (sd->ir.initialized) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
353 sd->ir.initialized = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
354
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
355 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
356 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
357
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
358 IrStruct* irstruct = sd->ir.irStruct;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
359 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
360
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
361 // 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
362 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
363 {
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
364 IrStruct::Offset* so = &i->second;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
365 LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
366 so->init = finit;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
367 so->var->ir.irField->constInit = finit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
368 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
369
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
370 const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
371
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
372 // go through the field inits and build the default initializer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
373 std::vector<LLConstant*> fieldinits_ll;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
374 size_t nfi = irstruct->defaultFields.size();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
375 for (size_t i=0; i<nfi; ++i) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
376 LLConstant* c;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
377 if (irstruct->defaultFields[i] != NULL) {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
378 c = irstruct->defaultFields[i]->ir.irField->constInit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
379 assert(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
380 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
381 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
382 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
383 std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
384 c = llvm::ConstantArray::get(arrty, vals);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
385 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
386 fieldinits_ll.push_back(c);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
387 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
388
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
389 // generate the union mapper
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
390 sd->ir.irStruct->dunion = new DUnion; // uses gIR->topstruct()
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
391
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
392 // always generate the constant initalizer
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
393 if (!sd->zeroInit) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
394 Logger::println("Not zero initialized");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
395 //assert(tk == gIR->gIR->topstruct()().size());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
396 #ifndef LLVMD_NO_LOGGER
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
397 Logger::cout() << "struct type: " << *structtype << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
398 for (size_t k=0; k<fieldinits_ll.size(); ++k) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
399 Logger::cout() << "Type:" << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
400 Logger::cout() << *fieldinits_ll[k]->getType() << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
401 Logger::cout() << "Value:" << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
402 Logger::cout() << *fieldinits_ll[k] << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
403 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
404 Logger::cout() << "Initializer printed" << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
405 #endif
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
406 sd->ir.irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
407 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
408 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
409 Logger::println("Zero initialized");
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
410 sd->ir.irStruct->constInit = llvm::ConstantAggregateZero::get(structtype);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
411 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
412
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
413 gIR->structs.pop_back();
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
414
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
415 // emit typeinfo
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
416 if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo)
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
417 sd->type->getTypeInfo(NULL);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
418 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
419
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
420 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
421
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
422 void DtoDefineStruct(StructDeclaration* sd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
423 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
424 if (sd->ir.defined) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
425 sd->ir.defined = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
426
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
427 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
428 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
429
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
430 assert(sd->type->ty == Tstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
431 TypeStruct* ts = (TypeStruct*)sd->type;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
432 sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
433
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
434 sd->ir.DModule = gIR->dmodule;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
435 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
436
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
437 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
438 //////////////////////////// D UNION HELPER CLASS ////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
439 //////////////////////////////////////////////////////////////////////////////////////////
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
440
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
441 DUnion::DUnion()
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
442 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
443 DUnionField* f = NULL;
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
444 IrStruct* topstruct = gIR->topstruct();
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
445 bool unions = false;
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
446 for (IrStruct::OffsetMap::iterator i=topstruct->offsets.begin(); i!=topstruct->offsets.end(); ++i)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
447 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
448 unsigned o = i->first;
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
449 IrStruct::Offset* so = &i->second;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
450 const LLType* ft = so->init->getType();
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
451 size_t sz = getABITypeSize(ft);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
452 if (f == NULL) { // new field
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
453 fields.push_back(DUnionField());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
454 f = &fields.back();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
455 f->size = sz;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
456 f->offset = o;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
457 f->init = so->init;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
458 f->initsize = sz;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
459 f->types.push_back(ft);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
460 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
461 else if (o == f->offset) { // same offset
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
462 if (sz > f->size)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
463 f->size = sz;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
464 f->types.push_back(ft);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
465 unions = true;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
466 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
467 else if (o < f->offset+f->size) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
468 assert((o+sz) <= (f->offset+f->size));
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
469 unions = true;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
470 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
471 else {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
472 fields.push_back(DUnionField());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
473 f = &fields.back();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
474 f->size = sz;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
475 f->offset = o;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
476 f->init = so->init;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
477 f->initsize = sz;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
478 f->types.push_back(ft);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
479 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
480 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
481
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 102
diff changeset
482 /*{
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
483 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
484 Logger::println("******** DUnion BEGIN");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
485 size_t n = fields.size();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
486 for (size_t i=0; i<n; ++i) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
487 Logger::cout()<<"field #"<<i<<" offset: "<<fields[i].offset<<" size: "<<fields[i].size<<'('<<fields[i].initsize<<")\n";
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
488 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
489 size_t nt = fields[i].types.size();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
490 for (size_t j=0; j<nt; ++j) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
491 Logger::cout()<<*fields[i].types[j]<<'\n';
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
492 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
493 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
494 Logger::println("******** DUnion END");
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 102
diff changeset
495 }*/
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
496 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
497
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
498 static void push_nulls(size_t nbytes, std::vector<LLConstant*>& out)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
499 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
500 assert(nbytes > 0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
501 std::vector<LLConstant*> i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
502 out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, nbytes), i));
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
503 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
504
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
505 LLConstant* DUnion::getConst(std::vector<DUnionIdx>& in)
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
506 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
507 std::sort(in.begin(), in.end());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
508 std::vector<LLConstant*> out;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
509
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
510 size_t nin = in.size();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
511 size_t nfields = fields.size();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
512
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
513 size_t fi = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
514 size_t last = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
515 size_t ii = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
516 size_t os = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
517
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
518 for(;;)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
519 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
520 if (fi == nfields) break;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
521
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
522 bool nextSame = (ii+1 < nin) && (in[ii+1].idx == fi);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
523
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
524 if (ii < nin && fi == in[ii].idx)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
525 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
526 size_t s = getABITypeSize(in[ii].c->getType());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
527 if (in[ii].idx == last)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
528 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
529 size_t nos = in[ii].idxos * s;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
530 if (nos && nos-os) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
531 assert(nos >= os);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
532 push_nulls(nos-os, out);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
533 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
534 os = nos + s;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
535 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
536 else
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
537 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
538 os = s;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
539 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
540 out.push_back(in[ii].c);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
541 ii++;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
542 if (!nextSame)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
543 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
544 if (os < fields[fi].size)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
545 push_nulls(fields[fi].size - os, out);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
546 os = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
547 last = fi++;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
548 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
549 continue;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
550 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
551
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
552 // default initialize if necessary
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
553 if (ii == nin || fi < in[ii].idx)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
554 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
555 DUnionField& f = fields[fi];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
556 out.push_back(f.init);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
557 if (f.initsize < f.size)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
558 push_nulls(f.size - f.initsize, out);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
559 last = fi++;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
560 os = 0;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
561 continue;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
562 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
563 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
564
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 205
diff changeset
565 std::vector<const LLType*> tys;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
566 size_t nout = out.size();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
567 for (size_t i=0; i<nout; ++i)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
568 tys.push_back(out[i]->getType());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
569
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
570 const llvm::StructType* st = llvm::StructType::get(tys);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
571 return llvm::ConstantStruct::get(st, out);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
572 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
573
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
574
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
575
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
576
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
577
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
578
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
579
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
580
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
581
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
582
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
583
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
584
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
585
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
586
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
587
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
588
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
589
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
590
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
591
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
592
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
593