Mercurial > projects > ldc
annotate gen/structs.cpp @ 627:79cbe5034fec
Tango patch: xml document fixes and symbol visibility in gc
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 01 Oct 2008 19:19:26 +0200 |
parents | 26fce59fe80a |
children | a15ccbf7451d |
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()); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
32 |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
33 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
34 Logger::cout() << "llvm struct type: " << *structtype << '\n'; |
88
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 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
|
37 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
38 std::vector<DUnionIdx> inits; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
39 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
|
40 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
41 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
|
42 assert(ini); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
43 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
|
44 assert(vd); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
45 LLConstant* v = DtoConstInitializer(vd->type, ini); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
46 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
|
47 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
48 |
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
|
49 DtoConstInitStruct((StructDeclaration*)si->ad); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
50 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
|
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 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
54 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
55 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
|
56 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
57 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
|
58 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
59 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
60 if (idxs.empty()) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
61 idxs.push_back(0); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
62 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
63 const LLType* llt = getPtrToType(DtoType(t)); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
64 const LLType* st = getPtrToType(DtoType(sd->type)); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
65 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
66 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
67 { |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
68 Logger::cout() << "ptr = " << *ptr << '\n'; |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
69 Logger::cout() << "st = " << *st << '\n'; |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
70 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
71 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
72 if (ptr->getType() != st) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
73 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
|
74 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
|
75 } |
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 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
|
78 VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i]; |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
449
diff
changeset
|
79 Type* vdtype = vd->type->toBasetype(); |
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
|
80 //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
|
81 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
|
82 if (os == vd->offset && vdtype == t) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
83 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
|
84 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
|
85 if (ptr->getType() != llt) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
86 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
87 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
|
88 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
|
89 return ptr; |
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 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
|
92 TypeStruct* ts = (TypeStruct*)vdtype; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
93 StructDeclaration* ssd = ts->sym; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
94 idxs.push_back(vd->ir.irField->index); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 DStructIndexVector tmp; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
102 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
|
103 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
104 else { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
105 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
|
106 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
|
107 ptr = DtoBitCast(ptr, sty); |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
108 DStructIndexVector tmp; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
109 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
|
110 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
111 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
112 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
|
113 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
114 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
115 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
116 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
117 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 } |
100 | 123 |
124 ////////////////////////////////////////////////////////////////////////////////////////// | |
125 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
126 void DtoResolveStruct(StructDeclaration* sd) |
100 | 127 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
128 if (sd->ir.resolved) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
129 sd->ir.resolved = true; |
100 | 130 |
132 | 131 Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 132 LOG_SCOPE; |
133 | |
171
95f07e3f8bb9
[svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents:
169
diff
changeset
|
134 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
|
135 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
|
136 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
449
diff
changeset
|
137 TypeStruct* ts = (TypeStruct*)sd->type->toBasetype(); |
100 | 138 |
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
|
139 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
|
140 |
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
|
141 IrStruct* irstruct = new IrStruct(ts); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
142 sd->ir.irStruct = irstruct; |
100 | 143 gIR->structs.push_back(irstruct); |
144 | |
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
|
145 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
|
146 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
147 // fields |
132 | 148 Array* arr = &sd->fields; |
149 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
|
150 VarDeclaration* v = (VarDeclaration*)arr->data[k]; |
336 | 151 v->toObjFile(0); // TODO: multiobj |
132 | 152 } |
153 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
154 bool thisModule = false; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
155 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
|
156 thisModule = true; |
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 // methods |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
159 arr = sd->members; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 if (thisModule || (fd->prot() != PROTprivate)) { |
336 | 164 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
|
165 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
166 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
167 else if (s->isAttribDeclaration()) { |
336 | 168 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
|
169 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
170 else { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
171 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
|
172 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
173 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
174 |
132 | 175 /*for (int k=0; k < sd->members->dim; k++) { |
100 | 176 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]); |
177 dsym->toObjFile(); | |
132 | 178 }*/ |
100 | 179 |
180 Logger::println("doing struct fields"); | |
181 | |
182 const llvm::StructType* structtype = 0; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
183 std::vector<const LLType*> fieldtypes; |
100 | 184 |
185 if (irstruct->offsets.empty()) | |
186 { | |
187 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
|
188 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
|
189 structtype = llvm::StructType::get(fieldtypes, ispacked); |
100 | 190 } |
191 else | |
192 { | |
193 Logger::println("has fields"); | |
194 unsigned prevsize = (unsigned)-1; | |
195 unsigned lastoffset = (unsigned)-1; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
196 const LLType* fieldtype = NULL; |
100 | 197 VarDeclaration* fieldinit = NULL; |
198 size_t fieldpad = 0; | |
199 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
|
200 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { |
100 | 201 // first iteration |
202 if (lastoffset == (unsigned)-1) { | |
203 lastoffset = i->first; | |
204 assert(lastoffset == 0); | |
205 fieldtype = i->second.type; | |
206 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
|
207 prevsize = fieldinit->type->size(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
208 i->second.var->ir.irField->index = idx; |
100 | 209 } |
210 // colliding offset? | |
211 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
|
212 size_t s = i->second.var->type->size(); |
100 | 213 if (s > prevsize) { |
214 fieldpad += s - prevsize; | |
215 prevsize = s; | |
216 } | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
217 sd->ir.irStruct->hasUnions = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
218 i->second.var->ir.irField->index = idx; |
100 | 219 } |
220 // intersecting offset? | |
221 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
|
222 size_t s = i->second.var->type->size(); |
100 | 223 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
|
224 sd->ir.irStruct->hasUnions = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
225 i->second.var->ir.irField->index = idx; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
226 i->second.var->ir.irField->indexOffset = (i->first - lastoffset) / s; |
100 | 227 } |
228 // fresh offset | |
229 else { | |
230 // commit the field | |
231 fieldtypes.push_back(fieldtype); | |
232 irstruct->defaultFields.push_back(fieldinit); | |
233 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
|
234 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
100 | 235 irstruct->defaultFields.push_back(NULL); |
236 idx++; | |
237 } | |
238 | |
239 idx++; | |
240 | |
241 // start new | |
242 lastoffset = i->first; | |
243 fieldtype = i->second.type; | |
244 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
|
245 prevsize = fieldinit->type->size(); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
246 i->second.var->ir.irField->index = idx; |
100 | 247 fieldpad = 0; |
248 } | |
249 } | |
250 fieldtypes.push_back(fieldtype); | |
251 irstruct->defaultFields.push_back(fieldinit); | |
252 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
|
253 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
100 | 254 irstruct->defaultFields.push_back(NULL); |
255 } | |
256 | |
257 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
|
258 structtype = llvm::StructType::get(fieldtypes, ispacked); |
100 | 259 } |
260 | |
261 // refine abstract types for stuff like: struct S{S* next;} | |
262 if (irstruct->recty != 0) | |
263 { | |
264 llvm::PATypeHolder& pa = irstruct->recty; | |
265 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
266 structtype = isaStruct(pa.get()); | |
267 } | |
268 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
269 assert(ts->ir.type == 0); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
270 ts->ir.type = new llvm::PATypeHolder(structtype); |
100 | 271 |
272 if (sd->parent->isModule()) { | |
273 gIR->module->addTypeName(sd->mangle(),structtype); | |
274 } | |
275 | |
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
|
276 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
|
277 |
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 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
|
279 } |
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 |
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 |
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 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
|
284 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
285 if (sd->ir.declared) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
286 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
|
287 |
132 | 288 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
|
289 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
|
290 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
449
diff
changeset
|
291 TypeStruct* ts = (TypeStruct*)sd->type->toBasetype(); |
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 |
100 | 293 std::string initname("_D"); |
294 initname.append(sd->mangle()); | |
295 initname.append("6__initZ"); | |
296 | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
137
diff
changeset
|
297 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
298 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
|
299 sd->ir.irStruct->init = initvar; |
100 | 300 |
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
|
301 gIR->constInitList.push_back(sd); |
171
95f07e3f8bb9
[svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents:
169
diff
changeset
|
302 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
|
303 gIR->defineList.push_back(sd); |
100 | 304 } |
305 | |
306 ////////////////////////////////////////////////////////////////////////////////////////// | |
307 | |
308 void DtoConstInitStruct(StructDeclaration* sd) | |
309 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
310 if (sd->ir.initialized) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
311 sd->ir.initialized = true; |
100 | 312 |
132 | 313 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 314 LOG_SCOPE; |
315 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
316 IrStruct* irstruct = sd->ir.irStruct; |
100 | 317 gIR->structs.push_back(irstruct); |
318 | |
319 // 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
|
320 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) |
100 | 321 { |
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
|
322 IrStruct::Offset* so = &i->second; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
323 LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); |
100 | 324 so->init = finit; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
325 so->var->ir.irField->constInit = finit; |
100 | 326 } |
327 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
328 const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get()); |
100 | 329 |
330 // 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
|
331 std::vector<LLConstant*> fieldinits_ll; |
100 | 332 size_t nfi = irstruct->defaultFields.size(); |
333 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
|
334 LLConstant* c; |
100 | 335 if (irstruct->defaultFields[i] != NULL) { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
336 c = irstruct->defaultFields[i]->ir.irField->constInit; |
100 | 337 assert(c); |
338 } | |
339 else { | |
340 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
|
341 std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(LLType::Int8Ty, 0, false)); |
100 | 342 c = llvm::ConstantArray::get(arrty, vals); |
343 } | |
344 fieldinits_ll.push_back(c); | |
345 } | |
346 | |
347 // 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
|
348 sd->ir.irStruct->dunion = new DUnion(); // uses gIR->topstruct() |
100 | 349 |
350 // always generate the constant initalizer | |
351 if (!sd->zeroInit) { | |
352 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
|
353 #if 0 |
100 | 354 //assert(tk == gIR->gIR->topstruct()().size()); |
355 #ifndef LLVMD_NO_LOGGER | |
356 Logger::cout() << "struct type: " << *structtype << '\n'; | |
357 for (size_t k=0; k<fieldinits_ll.size(); ++k) { | |
358 Logger::cout() << "Type:" << '\n'; | |
359 Logger::cout() << *fieldinits_ll[k]->getType() << '\n'; | |
360 Logger::cout() << "Value:" << '\n'; | |
361 Logger::cout() << *fieldinits_ll[k] << '\n'; | |
362 } | |
363 Logger::cout() << "Initializer printed" << '\n'; | |
364 #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
|
365 #endif |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
366 sd->ir.irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll); |
100 | 367 } |
368 else { | |
369 Logger::println("Zero initialized"); | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
370 sd->ir.irStruct->constInit = llvm::ConstantAggregateZero::get(structtype); |
100 | 371 } |
372 | |
373 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
|
374 |
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
|
375 // 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
|
376 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
|
377 DtoTypeInfoOf(sd->type, false); |
100 | 378 } |
379 | |
380 ////////////////////////////////////////////////////////////////////////////////////////// | |
381 | |
382 void DtoDefineStruct(StructDeclaration* sd) | |
383 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
384 if (sd->ir.defined) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
385 sd->ir.defined = true; |
100 | 386 |
132 | 387 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 388 LOG_SCOPE; |
389 | |
390 assert(sd->type->ty == Tstruct); | |
391 TypeStruct* ts = (TypeStruct*)sd->type; | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
392 sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit); |
100 | 393 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
394 sd->ir.DModule = gIR->dmodule; |
100 | 395 } |
396 | |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
397 ////////////////////////////////////////////////////////////////////////////////////////// |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
398 //////////////////////////// D STRUCT UTILITIES //////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
399 ////////////////////////////////////////////////////////////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
400 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
401 LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs) |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
402 { |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
403 Type* t = lhs->getType()->toBasetype(); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
404 assert(t->ty == Tstruct); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
405 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
406 // set predicate |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
407 llvm::ICmpInst::Predicate cmpop; |
345
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
408 if (op == TOKequal || op == TOKidentity) |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
409 cmpop = llvm::ICmpInst::ICMP_EQ; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
410 else |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
411 cmpop = llvm::ICmpInst::ICMP_NE; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
412 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
413 // call memcmp |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
414 size_t sz = getABITypeSize(DtoType(t)); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
415 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
|
416 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
|
417 } |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
418 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
419 ////////////////////////////////////////////////////////////////////////////////////////// |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
420 //////////////////////////// D UNION HELPER CLASS //////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
421 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
422 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
423 DUnion::DUnion() |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
424 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
425 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
|
426 IrStruct* topstruct = gIR->topstruct(); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
427 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
|
428 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
|
429 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
430 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
|
431 IrStruct::Offset* so = &i->second; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
432 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
|
433 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
|
434 if (f == NULL) { // new field |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
435 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
436 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
437 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
438 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
439 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
440 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
441 f->types.push_back(ft); |
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 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
|
444 if (sz > f->size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
445 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
446 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
447 unions = true; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
448 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
449 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
|
450 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
|
451 unions = true; |
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 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
454 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
455 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
456 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
457 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
458 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
459 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
460 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
461 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
462 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
463 |
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
|
464 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
|
465 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
466 /*{ |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
467 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
468 Logger::println("******** DUnion BEGIN"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
469 size_t n = fields.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
470 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
|
471 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
|
472 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
473 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
|
474 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
|
475 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
|
476 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
477 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
478 Logger::println("******** DUnion END"); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
479 }*/ |
88
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 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
482 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
|
483 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
488 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
489 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
|
490 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
491 std::sort(in.begin(), in.end()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
492 std::vector<LLConstant*> out; |
88
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 size_t nin = in.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
495 size_t nfields = fields.size(); |
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 size_t fi = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
498 size_t last = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
499 size_t ii = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
500 size_t os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
501 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
502 for(;;) |
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 if (fi == nfields) break; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
505 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
506 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
|
507 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
508 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
|
509 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
510 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
|
511 if (in[ii].idx == last) |
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 nos = in[ii].idxos * s; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
514 if (nos && nos-os) { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
515 assert(nos >= os); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
516 push_nulls(nos-os, out); |
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 os = nos + s; |
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 else |
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 os = s; |
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 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
|
525 ii++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
526 if (!nextSame) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
527 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
528 if (os < fields[fi].size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
529 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
|
530 os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
531 last = fi++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
532 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
533 continue; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
534 } |
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 // default initialize if necessary |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
537 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
|
538 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
539 DUnionField& f = fields[fi]; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
540 out.push_back(f.init); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
541 if (f.initsize < f.size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
542 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
|
543 last = fi++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
544 os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
545 continue; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
546 } |
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 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
549 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
|
550 size_t nout = out.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
551 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
|
552 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
|
553 |
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
|
554 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
|
555 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
|
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 |
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
571 |
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 |