Mercurial > projects > ldc
annotate gen/structs.cpp @ 473:373489eeaf90
Applied downs' lphobos update
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 04 Aug 2008 19:28:49 +0200 |
parents | 56265fa07c7d |
children | a34078905d01 |
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" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
12 #include "gen/llvmhelpers.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
13 #include "gen/arrays.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
14 #include "gen/logger.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
15 #include "gen/structs.h" |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
16 #include "gen/dvalue.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
17 |
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
|
18 #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
|
19 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
20 ////////////////////////////////////////////////////////////////////////////////////////// |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
21 LLConstant* DtoConstStructInitializer(StructInitializer* si) |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
22 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
23 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
|
24 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
25 |
449
56265fa07c7d
Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
26 assert(si->ad); |
100 | 27 TypeStruct* ts = (TypeStruct*)si->ad->type; |
28 | |
449
56265fa07c7d
Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
29 DtoResolveDsymbol(si->ad); |
56265fa07c7d
Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
30 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
31 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
|
32 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
|
33 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
34 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
|
35 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
36 std::vector<DUnionIdx> inits; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
37 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
|
38 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
39 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
|
40 assert(ini); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
41 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
|
42 assert(vd); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
43 LLConstant* v = DtoConstInitializer(vd->type, ini); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
44 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
|
45 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
46 |
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
|
47 DtoConstInitStruct((StructDeclaration*)si->ad); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
48 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
|
49 } |
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 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
53 LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, DStructIndexVector& idxs) |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
54 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
55 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
|
56 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
57 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
58 if (idxs.empty()) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
59 idxs.push_back(0); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
60 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
61 const LLType* llt = getPtrToType(DtoType(t)); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
62 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
|
63 if (ptr->getType() != st) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
64 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
|
65 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
|
66 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
67 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 //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
|
72 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
|
73 if (os == vd->offset && vdtype == t) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
74 idxs.push_back(vd->ir.irField->index); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
75 ptr = DtoGEPi(ptr, idxs, "tmp"); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
76 if (ptr->getType() != llt) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
77 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
78 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
|
79 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
|
80 return ptr; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
81 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
82 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
|
83 TypeStruct* ts = (TypeStruct*)vdtype; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
84 StructDeclaration* ssd = ts->sym; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
85 idxs.push_back(vd->ir.irField->index); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
86 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
|
87 Logger::println("has union field offset"); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
88 ptr = DtoGEPi(ptr, idxs, "tmp"); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
89 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
|
90 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
|
91 ptr = llvm::GetElementPtrInst::Create(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb()); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
92 DStructIndexVector tmp; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
93 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
|
94 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
95 else { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
96 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
|
97 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
|
98 ptr = DtoBitCast(ptr, sty); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
99 DStructIndexVector tmp; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
100 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
|
101 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
102 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
103 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
|
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 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
108 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 } |
100 | 114 |
115 ////////////////////////////////////////////////////////////////////////////////////////// | |
116 | |
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
|
117 void DtoResolveStruct(StructDeclaration* sd) |
100 | 118 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
119 if (sd->ir.resolved) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
120 sd->ir.resolved = true; |
100 | 121 |
132 | 122 Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 123 LOG_SCOPE; |
124 | |
171
95f07e3f8bb9
[svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents:
169
diff
changeset
|
125 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
|
126 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
|
127 |
100 | 128 TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); |
129 | |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
130 bool ispacked = (ts->alignsize() == 1); |
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
131 |
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
|
132 IrStruct* irstruct = new IrStruct(ts); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
133 sd->ir.irStruct = irstruct; |
100 | 134 gIR->structs.push_back(irstruct); |
135 | |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
136 irstruct->packed = ispacked; |
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
137 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
138 // fields |
132 | 139 Array* arr = &sd->fields; |
140 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
|
141 VarDeclaration* v = (VarDeclaration*)arr->data[k]; |
336 | 142 v->toObjFile(0); // TODO: multiobj |
132 | 143 } |
144 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
145 bool thisModule = false; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
146 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
|
147 thisModule = true; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
148 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
149 // methods |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
150 arr = sd->members; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 if (thisModule || (fd->prot() != PROTprivate)) { |
336 | 155 fd->toObjFile(0); // TODO: multiobj |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
156 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
157 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
158 else if (s->isAttribDeclaration()) { |
336 | 159 s->toObjFile(0); // TODO: multiobj |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
160 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
161 else { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
162 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
|
163 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
164 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
165 |
132 | 166 /*for (int k=0; k < sd->members->dim; k++) { |
100 | 167 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]); |
168 dsym->toObjFile(); | |
132 | 169 }*/ |
100 | 170 |
171 Logger::println("doing struct fields"); | |
172 | |
173 const llvm::StructType* structtype = 0; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
174 std::vector<const LLType*> fieldtypes; |
100 | 175 |
176 if (irstruct->offsets.empty()) | |
177 { | |
178 Logger::println("has no fields"); | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
179 fieldtypes.push_back(LLType::Int8Ty); |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
180 structtype = llvm::StructType::get(fieldtypes, ispacked); |
100 | 181 } |
182 else | |
183 { | |
184 Logger::println("has fields"); | |
185 unsigned prevsize = (unsigned)-1; | |
186 unsigned lastoffset = (unsigned)-1; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
187 const LLType* fieldtype = NULL; |
100 | 188 VarDeclaration* fieldinit = NULL; |
189 size_t fieldpad = 0; | |
190 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
|
191 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { |
100 | 192 // first iteration |
193 if (lastoffset == (unsigned)-1) { | |
194 lastoffset = i->first; | |
195 assert(lastoffset == 0); | |
196 fieldtype = i->second.type; | |
197 fieldinit = i->second.var; | |
351
f273f5c58a9a
[svn r372] Fixed extern(C++) handling now same as DMD, which is to treat it like extern(C).
lindquist
parents:
345
diff
changeset
|
198 prevsize = fieldinit->type->size(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
199 i->second.var->ir.irField->index = idx; |
100 | 200 } |
201 // colliding offset? | |
202 else if (lastoffset == i->first) { | |
351
f273f5c58a9a
[svn r372] Fixed extern(C++) handling now same as DMD, which is to treat it like extern(C).
lindquist
parents:
345
diff
changeset
|
203 size_t s = i->second.var->type->size(); |
100 | 204 if (s > prevsize) { |
205 fieldpad += s - prevsize; | |
206 prevsize = s; | |
207 } | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
208 sd->ir.irStruct->hasUnions = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
209 i->second.var->ir.irField->index = idx; |
100 | 210 } |
211 // intersecting offset? | |
212 else if (i->first < (lastoffset + prevsize)) { | |
351
f273f5c58a9a
[svn r372] Fixed extern(C++) handling now same as DMD, which is to treat it like extern(C).
lindquist
parents:
345
diff
changeset
|
213 size_t s = i->second.var->type->size(); |
100 | 214 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
|
215 sd->ir.irStruct->hasUnions = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
216 i->second.var->ir.irField->index = idx; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
217 i->second.var->ir.irField->indexOffset = (i->first - lastoffset) / s; |
100 | 218 } |
219 // fresh offset | |
220 else { | |
221 // commit the field | |
222 fieldtypes.push_back(fieldtype); | |
223 irstruct->defaultFields.push_back(fieldinit); | |
224 if (fieldpad) { | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
225 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
100 | 226 irstruct->defaultFields.push_back(NULL); |
227 idx++; | |
228 } | |
229 | |
230 idx++; | |
231 | |
232 // start new | |
233 lastoffset = i->first; | |
234 fieldtype = i->second.type; | |
235 fieldinit = i->second.var; | |
351
f273f5c58a9a
[svn r372] Fixed extern(C++) handling now same as DMD, which is to treat it like extern(C).
lindquist
parents:
345
diff
changeset
|
236 prevsize = fieldinit->type->size(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
237 i->second.var->ir.irField->index = idx; |
100 | 238 fieldpad = 0; |
239 } | |
240 } | |
241 fieldtypes.push_back(fieldtype); | |
242 irstruct->defaultFields.push_back(fieldinit); | |
243 if (fieldpad) { | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
244 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
100 | 245 irstruct->defaultFields.push_back(NULL); |
246 } | |
247 | |
248 Logger::println("creating struct type"); | |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
249 structtype = llvm::StructType::get(fieldtypes, ispacked); |
100 | 250 } |
251 | |
252 // refine abstract types for stuff like: struct S{S* next;} | |
253 if (irstruct->recty != 0) | |
254 { | |
255 llvm::PATypeHolder& pa = irstruct->recty; | |
256 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
257 structtype = isaStruct(pa.get()); | |
258 } | |
259 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
260 assert(ts->ir.type == 0); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
261 ts->ir.type = new llvm::PATypeHolder(structtype); |
100 | 262 |
263 if (sd->parent->isModule()) { | |
264 gIR->module->addTypeName(sd->mangle(),structtype); | |
265 } | |
266 | |
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
|
267 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
|
268 |
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
|
269 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
|
270 } |
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
|
271 |
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
|
272 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
273 |
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
|
274 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
|
275 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
276 if (sd->ir.declared) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
277 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
|
278 |
132 | 279 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
|
280 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
|
281 |
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
|
282 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
|
283 |
100 | 284 std::string initname("_D"); |
285 initname.append(sd->mangle()); | |
286 initname.append("6__initZ"); | |
287 | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
137
diff
changeset
|
288 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
289 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
|
290 sd->ir.irStruct->init = initvar; |
100 | 291 |
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
|
292 gIR->constInitList.push_back(sd); |
171
95f07e3f8bb9
[svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents:
169
diff
changeset
|
293 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
|
294 gIR->defineList.push_back(sd); |
100 | 295 } |
296 | |
297 ////////////////////////////////////////////////////////////////////////////////////////// | |
298 | |
299 void DtoConstInitStruct(StructDeclaration* sd) | |
300 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
301 if (sd->ir.initialized) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
302 sd->ir.initialized = true; |
100 | 303 |
132 | 304 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 305 LOG_SCOPE; |
306 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
307 IrStruct* irstruct = sd->ir.irStruct; |
100 | 308 gIR->structs.push_back(irstruct); |
309 | |
310 // 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
|
311 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) |
100 | 312 { |
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
|
313 IrStruct::Offset* so = &i->second; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
314 LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); |
100 | 315 so->init = finit; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
316 so->var->ir.irField->constInit = finit; |
100 | 317 } |
318 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
319 const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get()); |
100 | 320 |
321 // 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
|
322 std::vector<LLConstant*> fieldinits_ll; |
100 | 323 size_t nfi = irstruct->defaultFields.size(); |
324 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
|
325 LLConstant* c; |
100 | 326 if (irstruct->defaultFields[i] != NULL) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
327 c = irstruct->defaultFields[i]->ir.irField->constInit; |
100 | 328 assert(c); |
329 } | |
330 else { | |
331 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i)); | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
332 std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(LLType::Int8Ty, 0, false)); |
100 | 333 c = llvm::ConstantArray::get(arrty, vals); |
334 } | |
335 fieldinits_ll.push_back(c); | |
336 } | |
337 | |
338 // generate the union mapper | |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
339 sd->ir.irStruct->dunion = new DUnion(); // uses gIR->topstruct() |
100 | 340 |
341 // always generate the constant initalizer | |
342 if (!sd->zeroInit) { | |
343 Logger::println("Not zero initialized"); | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
344 #if 0 |
100 | 345 //assert(tk == gIR->gIR->topstruct()().size()); |
346 #ifndef LLVMD_NO_LOGGER | |
347 Logger::cout() << "struct type: " << *structtype << '\n'; | |
348 for (size_t k=0; k<fieldinits_ll.size(); ++k) { | |
349 Logger::cout() << "Type:" << '\n'; | |
350 Logger::cout() << *fieldinits_ll[k]->getType() << '\n'; | |
351 Logger::cout() << "Value:" << '\n'; | |
352 Logger::cout() << *fieldinits_ll[k] << '\n'; | |
353 } | |
354 Logger::cout() << "Initializer printed" << '\n'; | |
355 #endif | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
356 #endif |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
357 sd->ir.irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll); |
100 | 358 } |
359 else { | |
360 Logger::println("Zero initialized"); | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
361 sd->ir.irStruct->constInit = llvm::ConstantAggregateZero::get(structtype); |
100 | 362 } |
363 | |
364 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
|
365 |
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
|
366 // emit typeinfo |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
435
diff
changeset
|
367 if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMno_typeinfo) |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
368 DtoTypeInfoOf(sd->type, false); |
100 | 369 } |
370 | |
371 ////////////////////////////////////////////////////////////////////////////////////////// | |
372 | |
373 void DtoDefineStruct(StructDeclaration* sd) | |
374 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
375 if (sd->ir.defined) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
376 sd->ir.defined = true; |
100 | 377 |
132 | 378 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 379 LOG_SCOPE; |
380 | |
381 assert(sd->type->ty == Tstruct); | |
382 TypeStruct* ts = (TypeStruct*)sd->type; | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
383 sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit); |
100 | 384 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
385 sd->ir.DModule = gIR->dmodule; |
100 | 386 } |
387 | |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
388 ////////////////////////////////////////////////////////////////////////////////////////// |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
389 //////////////////////////// D STRUCT UTILITIES //////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
390 ////////////////////////////////////////////////////////////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
391 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
392 LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs) |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
393 { |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
394 Type* t = lhs->getType()->toBasetype(); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
395 assert(t->ty == Tstruct); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
396 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
397 // set predicate |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
398 llvm::ICmpInst::Predicate cmpop; |
345
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
399 if (op == TOKequal || op == TOKidentity) |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
400 cmpop = llvm::ICmpInst::ICMP_EQ; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
401 else |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
402 cmpop = llvm::ICmpInst::ICMP_NE; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
403 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
404 // call memcmp |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
405 size_t sz = getABITypeSize(DtoType(t)); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
406 LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz)); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
407 return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp"); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
408 } |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
409 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
410 ////////////////////////////////////////////////////////////////////////////////////////// |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
411 //////////////////////////// D UNION HELPER CLASS //////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
412 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
413 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
414 DUnion::DUnion() |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
415 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
416 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
|
417 IrStruct* topstruct = gIR->topstruct(); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
418 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
|
419 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
|
420 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
421 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
|
422 IrStruct::Offset* so = &i->second; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
423 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
|
424 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
|
425 if (f == NULL) { // new field |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
426 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
427 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
428 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
429 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
430 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
431 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
432 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
433 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
434 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
|
435 if (sz > f->size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
436 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
437 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
438 unions = true; |
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 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
|
441 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
|
442 unions = true; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
443 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
444 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
445 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
446 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
447 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
448 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
449 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
450 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
451 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
452 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
453 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
454 |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
455 ispacked = topstruct->packed; |
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
456 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
457 /*{ |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
458 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
459 Logger::println("******** DUnion BEGIN"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
460 size_t n = fields.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
461 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
|
462 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
|
463 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
468 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
469 Logger::println("******** DUnion END"); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
470 }*/ |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
471 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
472 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
473 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
|
474 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
475 assert(nbytes > 0); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
476 std::vector<LLConstant*> i(nbytes, llvm::ConstantInt::get(LLType::Int8Ty, 0, false)); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
477 out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(LLType::Int8Ty, nbytes), i)); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
478 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
479 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
480 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
|
481 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
482 std::sort(in.begin(), in.end()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
483 std::vector<LLConstant*> out; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
484 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
485 size_t nin = in.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
486 size_t nfields = fields.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
487 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
488 size_t fi = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
489 size_t last = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
490 size_t ii = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
491 size_t os = 0; |
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 for(;;) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
494 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
495 if (fi == nfields) break; |
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 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
|
498 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
499 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
|
500 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
501 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
|
502 if (in[ii].idx == last) |
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 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
|
505 if (nos && nos-os) { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
506 assert(nos >= os); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
507 push_nulls(nos-os, out); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
508 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
509 os = nos + s; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
510 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
511 else |
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 os = s; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
514 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
515 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
|
516 ii++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
517 if (!nextSame) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
518 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
519 if (os < fields[fi].size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
520 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
|
521 os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
522 last = 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 continue; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
525 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
526 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
527 // default initialize if necessary |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
528 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
|
529 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
530 DUnionField& f = fields[fi]; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
531 out.push_back(f.init); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
532 if (f.initsize < f.size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
533 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
|
534 last = fi++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
535 os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
536 continue; |
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 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
539 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
540 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
|
541 size_t nout = out.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
542 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
|
543 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
|
544 |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
545 const llvm::StructType* st = llvm::StructType::get(tys, ispacked); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
546 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
|
547 } |
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 |
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
553 |
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
556 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
557 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
558 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
559 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
560 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
561 |
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
565 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
566 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
567 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
568 |