Mercurial > projects > ldc
annotate gen/structs.cpp @ 151:d11848349f97 trunk
[svn r157] Fixed the nasty type==NULL bug :D
author | lindquist |
---|---|
date | Mon, 24 Mar 2008 20:48:40 +0100 |
parents | 4c577c2b7229 |
children | ccd07d9f2ce9 |
rev | line source |
---|---|
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
1 #include <algorithm> |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
2 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
3 #include "gen/llvm.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
4 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
5 #include "mtype.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
6 #include "aggregate.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
7 #include "init.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
8 #include "declaration.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
9 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
10 #include "gen/irstate.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
11 #include "gen/tollvm.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
12 #include "gen/arrays.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
13 #include "gen/logger.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
14 #include "gen/structs.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
15 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
16 #include "ir/irstruct.h" |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
17 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
18 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
19 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
20 const llvm::Type* DtoStructType(Type* t) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
21 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
22 assert(0); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
23 std::vector<const llvm::Type*> types; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
24 return llvm::StructType::get(types); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
25 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
26 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
27 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
28 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
29 llvm::Value* DtoStructZeroInit(llvm::Value* v) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
30 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
31 assert(gIR); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
32 uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0)); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
33 //llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
34 const llvm::Type* sarrty = getPtrToType(llvm::Type::Int8Ty); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
35 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
36 llvm::Value* sarr = DtoBitCast(v, sarrty); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
37 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
38 llvm::Function* fn = LLVM_DeclareMemSet32(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
39 std::vector<llvm::Value*> llargs; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
40 llargs.resize(4); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
41 llargs[0] = sarr; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
42 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
43 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
44 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
45 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
46 llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
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 return ret; |
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
53 llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src) |
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::cout() << "dst = " << *dst << " src = " << *src << '\n'; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
56 assert(dst->getType() == src->getType()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
57 assert(gIR); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
58 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
59 uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0)); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
60 //llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
61 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
62 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
63 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
64 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
65 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
66 llvm::Function* fn = LLVM_DeclareMemCpy32(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
67 std::vector<llvm::Value*> llargs; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
68 llargs.resize(4); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
69 llargs[0] = dstarr; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
70 llargs[1] = srcarr; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
71 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
72 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
73 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
74 return new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
78 llvm::Constant* DtoConstStructInitializer(StructInitializer* si) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
79 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
80 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
|
81 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
82 |
100 | 83 TypeStruct* ts = (TypeStruct*)si->ad->type; |
84 | |
85 const llvm::StructType* structtype = isaStruct(ts->llvmType->get()); | |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
86 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
|
87 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
88 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
|
89 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
90 std::vector<DUnionIdx> inits; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
91 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
|
92 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
93 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
|
94 assert(ini); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
95 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
|
96 assert(vd); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
97 llvm::Constant* v = DtoConstInitializer(vd->type, ini); |
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
|
98 inits.push_back(DUnionIdx(vd->irField->index, vd->irField->indexOffset, v)); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
99 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
100 |
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
|
101 DtoConstInitStruct((StructDeclaration*)si->ad); |
137 | 102 return si->ad->irStruct->dunion->getConst(inits); |
88
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 |
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 llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
108 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
109 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
|
110 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
111 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
112 if (idxs.empty()) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
113 idxs.push_back(0); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
114 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
115 const llvm::Type* llt = getPtrToType(DtoType(t)); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
116 const llvm::Type* 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
|
117 if (ptr->getType() != st) { |
137 | 118 assert(sd->irStruct->hasUnions); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
119 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
|
120 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
121 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
122 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
|
123 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
|
124 Type* vdtype = DtoDType(vd->type); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
125 Logger::println("found %u type %s", vd->offset, vdtype->toChars()); |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
126 assert(vd->irField->index >= 0); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
127 if (os == vd->offset && vdtype == t) { |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
128 idxs.push_back(vd->irField->index); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
129 ptr = DtoGEP(ptr, idxs, "tmp"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
130 if (ptr->getType() != llt) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
131 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
132 if (vd->irField->indexOffset) |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
133 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->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
|
134 return ptr; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
135 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
136 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
|
137 TypeStruct* ts = (TypeStruct*)vdtype; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
138 StructDeclaration* ssd = ts->sym; |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
139 idxs.push_back(vd->irField->index); |
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
|
140 if (vd->irField->indexOffset) { |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
141 Logger::println("has union field offset"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
142 ptr = DtoGEP(ptr, idxs, "tmp"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
143 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
|
144 ptr = DtoBitCast(ptr, llt); |
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
|
145 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->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
|
146 std::vector<unsigned> tmp; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
147 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
|
148 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
149 else { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
150 const llvm::Type* 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
|
151 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
|
152 ptr = DtoBitCast(ptr, sty); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
153 std::vector<unsigned> tmp; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
154 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
|
155 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
156 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
157 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
|
158 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
159 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
160 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
161 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
162 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
163 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
|
164 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
|
165 ptr = DtoBitCast(ptr, llt); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
166 return new llvm::GetElementPtrInst(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
167 } |
100 | 168 |
169 ////////////////////////////////////////////////////////////////////////////////////////// | |
170 | |
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
|
171 void DtoResolveStruct(StructDeclaration* sd) |
100 | 172 { |
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
|
173 if (sd->llvmResolved) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
174 sd->llvmResolved = true; |
100 | 175 |
132 | 176 Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 177 LOG_SCOPE; |
178 | |
179 TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); | |
180 | |
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
|
181 IrStruct* irstruct = new IrStruct(ts); |
137 | 182 sd->irStruct = irstruct; |
100 | 183 gIR->structs.push_back(irstruct); |
184 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
185 // fields |
132 | 186 Array* arr = &sd->fields; |
187 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
|
188 VarDeclaration* v = (VarDeclaration*)arr->data[k]; |
132 | 189 v->toObjFile(); |
190 } | |
191 | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
192 bool thisModule = false; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
193 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
|
194 thisModule = true; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
195 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
196 // methods |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
197 arr = sd->members; |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 if (thisModule || (fd->prot() != PROTprivate)) { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
202 fd->toObjFile(); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
203 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
204 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
205 else if (s->isAttribDeclaration()) { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
206 s->toObjFile(); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
207 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
208 else { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
209 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
|
210 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
211 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
212 |
132 | 213 /*for (int k=0; k < sd->members->dim; k++) { |
100 | 214 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]); |
215 dsym->toObjFile(); | |
132 | 216 }*/ |
100 | 217 |
218 Logger::println("doing struct fields"); | |
219 | |
220 const llvm::StructType* structtype = 0; | |
221 std::vector<const llvm::Type*> fieldtypes; | |
222 | |
223 if (irstruct->offsets.empty()) | |
224 { | |
225 Logger::println("has no fields"); | |
226 fieldtypes.push_back(llvm::Type::Int8Ty); | |
227 structtype = llvm::StructType::get(fieldtypes); | |
228 } | |
229 else | |
230 { | |
231 Logger::println("has fields"); | |
232 unsigned prevsize = (unsigned)-1; | |
233 unsigned lastoffset = (unsigned)-1; | |
234 const llvm::Type* fieldtype = NULL; | |
235 VarDeclaration* fieldinit = NULL; | |
236 size_t fieldpad = 0; | |
237 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
|
238 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { |
100 | 239 // first iteration |
240 if (lastoffset == (unsigned)-1) { | |
241 lastoffset = i->first; | |
242 assert(lastoffset == 0); | |
243 fieldtype = i->second.type; | |
244 fieldinit = i->second.var; | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
245 prevsize = getABITypeSize(fieldtype); |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
246 i->second.var->irField->index = idx; |
100 | 247 } |
248 // colliding offset? | |
249 else if (lastoffset == i->first) { | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
250 size_t s = getABITypeSize(i->second.type); |
100 | 251 if (s > prevsize) { |
252 fieldpad += s - prevsize; | |
253 prevsize = s; | |
254 } | |
137 | 255 sd->irStruct->hasUnions = true; |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
256 i->second.var->irField->index = idx; |
100 | 257 } |
258 // intersecting offset? | |
259 else if (i->first < (lastoffset + prevsize)) { | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
260 size_t s = getABITypeSize(i->second.type); |
100 | 261 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size |
137 | 262 sd->irStruct->hasUnions = true; |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
263 i->second.var->irField->index = idx; |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
264 i->second.var->irField->indexOffset = (i->first - lastoffset) / s; |
100 | 265 } |
266 // fresh offset | |
267 else { | |
268 // commit the field | |
269 fieldtypes.push_back(fieldtype); | |
270 irstruct->defaultFields.push_back(fieldinit); | |
271 if (fieldpad) { | |
272 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad)); | |
273 irstruct->defaultFields.push_back(NULL); | |
274 idx++; | |
275 } | |
276 | |
277 idx++; | |
278 | |
279 // start new | |
280 lastoffset = i->first; | |
281 fieldtype = i->second.type; | |
282 fieldinit = i->second.var; | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
283 prevsize = getABITypeSize(fieldtype); |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
284 i->second.var->irField->index = idx; |
100 | 285 fieldpad = 0; |
286 } | |
287 } | |
288 fieldtypes.push_back(fieldtype); | |
289 irstruct->defaultFields.push_back(fieldinit); | |
290 if (fieldpad) { | |
291 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad)); | |
292 irstruct->defaultFields.push_back(NULL); | |
293 } | |
294 | |
295 Logger::println("creating struct type"); | |
296 structtype = llvm::StructType::get(fieldtypes); | |
297 } | |
298 | |
299 // refine abstract types for stuff like: struct S{S* next;} | |
300 if (irstruct->recty != 0) | |
301 { | |
302 llvm::PATypeHolder& pa = irstruct->recty; | |
303 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
304 structtype = isaStruct(pa.get()); | |
305 } | |
306 | |
307 assert(ts->llvmType == 0); | |
308 ts->llvmType = new llvm::PATypeHolder(structtype); | |
309 | |
310 if (sd->parent->isModule()) { | |
311 gIR->module->addTypeName(sd->mangle(),structtype); | |
312 } | |
313 | |
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
|
314 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
|
315 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
316 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
|
317 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
318 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
319 ////////////////////////////////////////////////////////////////////////////////////////// |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
320 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
321 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
|
322 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
323 if (sd->llvmDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
324 sd->llvmDeclared = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
325 |
132 | 326 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
|
327 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
|
328 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
329 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
|
330 |
100 | 331 std::string initname("_D"); |
332 initname.append(sd->mangle()); | |
333 initname.append("6__initZ"); | |
334 | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
137
diff
changeset
|
335 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); |
100 | 336 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module); |
137 | 337 sd->irStruct->init = initvar; |
100 | 338 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
339 gIR->constInitList.push_back(sd); |
100 | 340 if (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
|
341 gIR->defineList.push_back(sd); |
100 | 342 } |
343 | |
344 ////////////////////////////////////////////////////////////////////////////////////////// | |
345 | |
346 void DtoConstInitStruct(StructDeclaration* sd) | |
347 { | |
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
|
348 if (sd->llvmInitialized) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
349 sd->llvmInitialized = true; |
100 | 350 |
132 | 351 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 352 LOG_SCOPE; |
353 | |
137 | 354 IrStruct* irstruct = sd->irStruct; |
100 | 355 gIR->structs.push_back(irstruct); |
356 | |
357 // 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
|
358 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) |
100 | 359 { |
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
|
360 IrStruct::Offset* so = &i->second; |
100 | 361 llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); |
362 so->init = finit; | |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
363 so->var->irField->constInit = finit; |
100 | 364 } |
365 | |
366 const llvm::StructType* structtype = isaStruct(sd->type->llvmType->get()); | |
367 | |
368 // go through the field inits and build the default initializer | |
369 std::vector<llvm::Constant*> fieldinits_ll; | |
370 size_t nfi = irstruct->defaultFields.size(); | |
371 for (size_t i=0; i<nfi; ++i) { | |
372 llvm::Constant* c; | |
373 if (irstruct->defaultFields[i] != 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
|
374 c = irstruct->defaultFields[i]->irField->constInit; |
100 | 375 assert(c); |
376 } | |
377 else { | |
378 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i)); | |
379 std::vector<llvm::Constant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
380 c = llvm::ConstantArray::get(arrty, vals); | |
381 } | |
382 fieldinits_ll.push_back(c); | |
383 } | |
384 | |
385 // generate the union mapper | |
137 | 386 sd->irStruct->dunion = new DUnion; // uses gIR->topstruct() |
100 | 387 |
388 // always generate the constant initalizer | |
389 if (!sd->zeroInit) { | |
390 Logger::println("Not zero initialized"); | |
391 //assert(tk == gIR->gIR->topstruct()().size()); | |
392 #ifndef LLVMD_NO_LOGGER | |
393 Logger::cout() << "struct type: " << *structtype << '\n'; | |
394 for (size_t k=0; k<fieldinits_ll.size(); ++k) { | |
395 Logger::cout() << "Type:" << '\n'; | |
396 Logger::cout() << *fieldinits_ll[k]->getType() << '\n'; | |
397 Logger::cout() << "Value:" << '\n'; | |
398 Logger::cout() << *fieldinits_ll[k] << '\n'; | |
399 } | |
400 Logger::cout() << "Initializer printed" << '\n'; | |
401 #endif | |
137 | 402 sd->irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll); |
100 | 403 } |
404 else { | |
405 Logger::println("Zero initialized"); | |
137 | 406 sd->irStruct->constInit = llvm::ConstantAggregateZero::get(structtype); |
100 | 407 } |
408 | |
409 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
|
410 |
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
|
411 // emit typeinfo |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
412 if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
413 sd->type->getTypeInfo(NULL); |
100 | 414 } |
415 | |
416 ////////////////////////////////////////////////////////////////////////////////////////// | |
417 | |
418 void DtoDefineStruct(StructDeclaration* sd) | |
419 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
420 if (sd->llvmDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
421 sd->llvmDefined = true; |
100 | 422 |
132 | 423 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 424 LOG_SCOPE; |
425 | |
426 assert(sd->type->ty == Tstruct); | |
427 TypeStruct* ts = (TypeStruct*)sd->type; | |
137 | 428 sd->irStruct->init->setInitializer(sd->irStruct->constInit); |
100 | 429 |
430 sd->llvmDModule = gIR->dmodule; | |
431 } | |
432 | |
88
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 //////////////////////////// D UNION HELPER CLASS //////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
435 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
436 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
437 DUnion::DUnion() |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
438 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
439 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
|
440 IrStruct* topstruct = gIR->topstruct(); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
441 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
|
442 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
|
443 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
444 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
|
445 IrStruct::Offset* so = &i->second; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
446 const llvm::Type* 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
|
447 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
|
448 if (f == NULL) { // new field |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
449 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
450 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
451 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
452 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
453 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
454 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
455 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
456 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
457 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
|
458 if (sz > f->size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
459 f->size = 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 unions = true; |
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 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
|
464 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
|
465 unions = true; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
466 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
467 else { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
468 fields.push_back(DUnionField()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
469 f = &fields.back(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
470 f->size = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
471 f->offset = o; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
472 f->init = so->init; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
473 f->initsize = sz; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
474 f->types.push_back(ft); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
475 } |
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 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
478 /*{ |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
479 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
480 Logger::println("******** DUnion BEGIN"); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
481 size_t n = fields.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
482 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
|
483 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
|
484 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
485 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
|
486 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
|
487 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
|
488 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
489 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
490 Logger::println("******** DUnion END"); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
102
diff
changeset
|
491 }*/ |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
492 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
493 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
494 static void push_nulls(size_t nbytes, std::vector<llvm::Constant*>& out) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
495 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
496 assert(nbytes > 0); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
497 std::vector<llvm::Constant*> i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
498 out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, nbytes), i)); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
499 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
500 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
501 llvm::Constant* DUnion::getConst(std::vector<DUnionIdx>& in) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
502 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
503 std::sort(in.begin(), in.end()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
504 std::vector<llvm::Constant*> out; |
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 size_t nin = in.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
507 size_t nfields = fields.size(); |
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 size_t fi = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
510 size_t last = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
511 size_t ii = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
512 size_t os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
513 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
514 for(;;) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
515 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
516 if (fi == nfields) break; |
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 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
|
519 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
520 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
|
521 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
522 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
|
523 if (in[ii].idx == last) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
524 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
525 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
|
526 if (nos && nos-os) { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
527 assert(nos >= os); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
528 push_nulls(nos-os, out); |
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 os = nos + s; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
531 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
532 else |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
533 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
534 os = s; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
535 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
536 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
|
537 ii++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
538 if (!nextSame) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
539 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
540 if (os < fields[fi].size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
541 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
|
542 os = 0; |
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 } |
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 // default initialize if necessary |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
549 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
|
550 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
551 DUnionField& f = fields[fi]; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
552 out.push_back(f.init); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
553 if (f.initsize < f.size) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
554 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
|
555 last = fi++; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
556 os = 0; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
557 continue; |
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 std::vector<const llvm::Type*> tys; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
562 size_t nout = out.size(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
563 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
|
564 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
|
565 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
566 const llvm::StructType* st = llvm::StructType::get(tys); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
567 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
|
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 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
578 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
579 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
580 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
581 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
582 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
583 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
584 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
585 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
586 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
587 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
588 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
589 |