annotate gen/arrays.cpp @ 88:058d3925950e trunk

[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
author lindquist
date Tue, 06 Nov 2007 10:03:14 +0100
parents fd32135dca3e
children 61615fa85940
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1 #include "gen/llvm.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
2
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
3 #include "mtype.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
4 #include "dsymbol.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
5 #include "aggregate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
6 #include "declaration.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
7 #include "init.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
8
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
9 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
10 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
11 #include "gen/arrays.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
12 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
14 #include "gen/dvalue.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
15
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
16 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
17
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
18 const llvm::StructType* DtoArrayType(Type* t)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
19 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
20 assert(t->next);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
21 const llvm::Type* at = DtoType(t->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
22 const llvm::Type* arrty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
23
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
24 /*if (t->ty == Tsarray) {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
25 TypeSArray* tsa = (TypeSArray*)t;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
26 assert(tsa->dim->type->isintegral());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
27 arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
28 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
29 else {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
30 arrty = llvm::ArrayType::get(at,0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
31 }*/
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
32 if (at == llvm::Type::VoidTy) {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
33 at = llvm::Type::Int8Ty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
34 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
35 arrty = llvm::PointerType::get(at);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
36
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
37 std::vector<const llvm::Type*> members;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
38 if (global.params.is64bit)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
39 members.push_back(llvm::Type::Int64Ty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
40 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
41 members.push_back(llvm::Type::Int32Ty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
42
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
43 members.push_back(arrty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
44
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
45 return llvm::StructType::get(members);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
46 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
47
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
48 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
49
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
50 const llvm::ArrayType* DtoStaticArrayType(Type* t)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
51 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
52 if (t->llvmType)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
53 return llvm::cast<llvm::ArrayType>(t->llvmType);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
54
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
55 assert(t->ty == Tsarray);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
56 assert(t->next);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
57
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
58 const llvm::Type* at = DtoType(t->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
59
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
60 TypeSArray* tsa = (TypeSArray*)t;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
61 assert(tsa->dim->type->isintegral());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 6
diff changeset
62 const llvm::ArrayType* arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
63
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
64 tsa->llvmType = arrty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
65 return arrty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
66 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
67
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
68 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
69
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
70 void DtoNullArray(llvm::Value* v)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
71 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
72 assert(gIR);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
73
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
74 llvm::Value* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
75 llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false);
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
76 new llvm::StoreInst(zerolen, len, gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
77
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
78 llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
79 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(ptr->getType()->getContainedType(0));
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
80 llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty);
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
81 new llvm::StoreInst(nullptr, ptr, gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
82 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
83
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
84 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
85
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
86 void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
87 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
88 assert(gIR);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
89 if (dst->getType() == src->getType())
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
90 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
91 llvm::Value* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
92 llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
93 ptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
94 new llvm::StoreInst(val, ptr, gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
95
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
96 ptr = DtoGEPi(src,0,1,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
97 val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
98 ptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
99 new llvm::StoreInst(val, ptr, gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
100 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
101 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
102 {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
103 Logger::cout() << "array assignment type dont match: " << *dst->getType() << '\n' << *src->getType() << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
104 if (!llvm::isa<llvm::ArrayType>(src->getType()->getContainedType(0)))
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
105 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
106 Logger::cout() << "invalid: " << *src << '\n';
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
107 assert(0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
108 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
109 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0));
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
110 llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
111
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
112 llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
113 llvm::Value* srclen = DtoConstSize_t(arrty->getNumElements());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
114 new llvm::StoreInst(srclen, dstlen, gIR->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
115
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
116 llvm::Value* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
117 llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
118 new llvm::StoreInst(srcptr, dstptr, gIR->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
119 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
120 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
121
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
122 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
123
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
124 void DtoArrayInit(llvm::Value* l, llvm::Value* r)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
125 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
126 const llvm::PointerType* ptrty = llvm::cast<llvm::PointerType>(l->getType());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
127 const llvm::Type* t = ptrty->getContainedType(0);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
128 const llvm::ArrayType* arrty = llvm::dyn_cast<llvm::ArrayType>(t);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
129 if (arrty)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
130 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
131 llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
132 llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
133 DtoArrayInit(ptr, dim, r);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
134 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
135 else if (llvm::isa<llvm::StructType>(t))
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
136 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
137 llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
138 llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
139 DtoArrayInit(ptr, dim, r);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
140 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
141 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
142 assert(0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
143 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
144
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
145 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
146
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
147 typedef const llvm::Type* constLLVMTypeP;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
148
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
149 static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
150 {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
151 if (llvm::isa<llvm::ArrayType>(pt)) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
152 size_t n = checkRectArrayInit(pt->getContainedType(0), finalty);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
153 size_t ne = llvm::cast<llvm::ArrayType>(pt)->getNumElements();
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
154 if (n) return n * ne;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
155 return ne;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
156 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
157 finalty = pt;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
158 return 0;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
159 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
160
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
161 void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
162 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
163 Logger::println("HELLO");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
164 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
165 const llvm::Type* pt = ptr->getType()->getContainedType(0);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
166 const llvm::Type* t = val->getType();
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
167 const llvm::Type* finalTy;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
168 if (size_t arrsz = checkRectArrayInit(pt, finalTy)) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
169 assert(finalTy == t);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
170 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(dim);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
171 assert(c);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
172 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
173 ptr = gIR->ir->CreateBitCast(ptr, llvm::PointerType::get(finalTy), "tmp");
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
174 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
175 else if (llvm::isa<llvm::StructType>(t)) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
176 assert(0);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
177 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
178 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
179 assert(t == pt);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
180 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
181
43
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
182 std::vector<llvm::Value*> args;
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
183 args.push_back(ptr);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
184 args.push_back(dim);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
185 args.push_back(val);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
186
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
187 const char* funcname = NULL;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
188
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
189 if (llvm::isa<llvm::PointerType>(t)) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
190 funcname = "_d_array_init_pointer";
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
191
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
192 const llvm::Type* dstty = llvm::PointerType::get(llvm::PointerType::get(llvm::Type::Int8Ty));
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
193 if (args[0]->getType() != dstty)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
194 args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb());
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
195
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
196 const llvm::Type* valty = llvm::PointerType::get(llvm::Type::Int8Ty);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
197 if (args[2]->getType() != valty)
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
198 args[2] = new llvm::BitCastInst(args[2],valty,"tmp",gIR->scopebb());
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
199 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
200 else if (t == llvm::Type::Int1Ty) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
201 funcname = "_d_array_init_i1";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
202 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
203 else if (t == llvm::Type::Int8Ty) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
204 funcname = "_d_array_init_i8";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
205 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
206 else if (t == llvm::Type::Int16Ty) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
207 funcname = "_d_array_init_i16";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
208 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
209 else if (t == llvm::Type::Int32Ty) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
210 funcname = "_d_array_init_i32";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
211 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
212 else if (t == llvm::Type::Int64Ty) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
213 funcname = "_d_array_init_i64";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
214 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
215 else if (t == llvm::Type::FloatTy) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
216 funcname = "_d_array_init_float";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
217 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
218 else if (t == llvm::Type::DoubleTy) {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
219 funcname = "_d_array_init_double";
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
220 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
221 else {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
222 Logger::cout() << *ptr->getType() << " = " << *val->getType() << '\n';
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
223 assert(0);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
224 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
225
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
226 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, funcname);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
227 assert(fn);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
228 Logger::cout() << "calling array init function: " << *fn <<'\n';
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
229 llvm::CallInst* call = new llvm::CallInst(fn, args.begin(), args.end(), "", gIR->scopebb());
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
230 call->setCallingConv(llvm::CallingConv::C);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
231 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
232
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
233 //////////////////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
234
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
235 void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
236 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
237 Logger::cout() << "DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n";
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
238 const llvm::StructType* st = llvm::cast<llvm::StructType>(arr->getType()->getContainedType(0));
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
239 //const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(r->getType());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
240
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
241 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
242 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
243
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
244 llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
245 new llvm::StoreInst(dim, arrdim, gIR->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
246
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
247 llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
248 new llvm::StoreInst(ptr, arrptr, gIR->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
249 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
250
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
251 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
252 llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
253 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
254 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
255 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
256
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
257 Type* arrinittype = DtoDType(arrinit->type);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
258
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
259 Type* t;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
260 integer_t tdim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
261 if (arrinittype->ty == Tsarray) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
262 Logger::println("static array");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
263 TypeSArray* tsa = (TypeSArray*)arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
264 tdim = tsa->dim->toInteger();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
265 t = tsa;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
266 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
267 else if (arrinittype->ty == Tarray) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
268 Logger::println("dynamic array");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
269 t = arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
270 tdim = arrinit->dim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
271 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
272 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
273 assert(0);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
274
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
275 Logger::println("dim = %u", tdim);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
276
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
277 std::vector<llvm::Constant*> inits(tdim, NULL);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
278
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
279 const llvm::Type* elemty = DtoType(arrinittype->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
280
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
281 assert(arrinit->index.dim == arrinit->value.dim);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
282 for (unsigned i=0,j=0; i < tdim; ++i)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
283 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
284 Initializer* init = 0;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
285 Expression* idx = (Expression*)arrinit->index.data[j];
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
286
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
287 if (idx)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
288 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
289 // this is pretty weird :/ idx->type turned out NULL for the initializer:
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
290 // const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
291 // in std.c.linux.socket
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
292 if (idx->type) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
293 //integer_t k = idx->toInteger();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
294 Logger::println("getting value for exp: %s | %s", idx->toChars(), idx->type->toChars());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
295 llvm::Constant* cc = idx->toConstElem(gIR);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
296 Logger::println("value gotten");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
297 assert(cc != NULL);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
298 llvm::ConstantInt* ci = llvm::dyn_cast<llvm::ConstantInt>(cc);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
299 assert(ci != NULL);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
300 uint64_t k = ci->getZExtValue();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
301 if (i == k)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
302 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
303 init = (Initializer*)arrinit->value.data[j];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
304 assert(init);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
305 ++j;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
306 }
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
307 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
308 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
309 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
310 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
311 init = (Initializer*)arrinit->value.data[j];
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
312 ++j;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
313 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
314
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
315 llvm::Constant* v = DtoConstInitializer(t->next, init);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
316 assert(v);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
317
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
318 inits[i] = v;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
319 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
320
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
321 const llvm::ArrayType* arrty = llvm::ArrayType::get(elemty,tdim);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
322 llvm::Constant* constarr = llvm::ConstantArray::get(arrty, inits);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
323
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
324 if (arrinittype->ty == Tsarray)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
325 return constarr;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
326 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
327 assert(arrinittype->ty == Tarray);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
328
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
329 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrty,true,llvm::GlobalValue::InternalLinkage,constarr,"constarray",gIR->module);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
330 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
331 llvm::Constant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
332 return DtoConstSlice(DtoConstSize_t(tdim),gep);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
333 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
334
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
335 //////////////////////////////////////////////////////////////////////////////////////////
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
336 static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
337 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
338 const llvm::Type* t = e->ptr->getType()->getContainedType(0);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
339 llvm::Value* ret = 0;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
340 if (e->len != 0) {
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
341 // this means it's a real slice
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
342 ret = e->ptr;
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
343
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
344 size_t elembsz = gTargetData->getTypeSize(ret->getType());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
345 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
346
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
347 if (llvm::isa<llvm::ConstantInt>(e->len)) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
348 sz = llvm::ConstantExpr::getMul(elemsz, llvm::cast<llvm::Constant>(e->len));
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
349 }
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
350 else {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
351 sz = llvm::BinaryOperator::createMul(elemsz,e->len,"tmp",gIR->scopebb());
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
352 }
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
353 }
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
354 else if (llvm::isa<llvm::ArrayType>(t)) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
355 ret = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
356
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
357 size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
358 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
359
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
360 size_t numelements = llvm::cast<llvm::ArrayType>(t)->getNumElements();
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
361 llvm::ConstantInt* nelems = llvm::ConstantInt::get(DtoSize_t(), numelements, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
362
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
363 sz = llvm::ConstantExpr::getMul(elemsz, nelems);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
364 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
365 else if (llvm::isa<llvm::StructType>(t)) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
366 ret = DtoGEPi(e->ptr, 0, 1, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
367 ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
368
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
369 size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
370 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
371
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
372 llvm::Value* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
373 len = new llvm::LoadInst(len, "tmp", gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
374 sz = llvm::BinaryOperator::createMul(len,elemsz,"tmp",gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
375 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
376 else {
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
377 assert(0);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
378 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
379 return ret;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
380 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
381
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
382 void DtoArrayCopy(DSliceValue* dst, DSliceValue* src)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
383 {
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
384 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
385
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
386 llvm::Value* sz1;
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
387 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb());
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
388
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
389 llvm::Value* sz2;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
390 llvm::Value* srcarr = new llvm::BitCastInst(get_slice_ptr(src,sz2),arrty,"tmp",gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
391
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
392 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
393 std::vector<llvm::Value*> llargs;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
394 llargs.resize(4);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
395 llargs[0] = dstarr;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
396 llargs[1] = srcarr;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
397 llargs[2] = sz1;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
398 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
399
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
400 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
401 }
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
402
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
403 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
404 void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
405 {
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
406 assert(dst->getType() == src->getType());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
407 size_t arrsz = gTargetData->getTypeSize(dst->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
408 llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false);
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
409
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
410 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
411 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
412 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
413
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
414 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
415 std::vector<llvm::Value*> llargs;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
416 llargs.resize(4);
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
417 llargs[0] = dstarr;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
418 llargs[1] = srcarr;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
419 llargs[2] = n;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
420 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
421
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
422 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
423 }
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
424
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
425 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
426 llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
427 {
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
428 std::vector<const llvm::Type*> types;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
429 types.push_back(dim->getType());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
430 types.push_back(ptr->getType());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
431 const llvm::StructType* type = llvm::StructType::get(types);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
432 std::vector<llvm::Constant*> values;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
433 values.push_back(dim);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
434 values.push_back(ptr);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
435 return llvm::ConstantStruct::get(type,values);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
436 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
437
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
438 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
439 llvm::Value* DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
440 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
441 const llvm::Type* ty = DtoType(dty);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
442 assert(ty != llvm::Type::VoidTy);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
443 size_t sz = gTargetData->getTypeSize(ty);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
444 llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
445 llvm::Value* bytesize = (sz == 1) ? dim : llvm::BinaryOperator::createMul(n,dim,"tmp",gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
446
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
447 llvm::Value* nullptr = llvm::ConstantPointerNull::get(llvm::PointerType::get(ty));
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
448
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
449 llvm::Value* newptr = DtoRealloc(nullptr, bytesize);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
450
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
451 if (doinit) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
452 DValue* e = dty->defaultInit()->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
453 DtoArrayInit(newptr,dim,e->getRVal());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
454 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
455
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
456 llvm::Value* lenptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
457 new llvm::StoreInst(dim,lenptr,gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
458 llvm::Value* ptrptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
459 new llvm::StoreInst(newptr,ptrptr,gIR->scopebb());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
460
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
461 return newptr;
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
462 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
463
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
464 //////////////////////////////////////////////////////////////////////////////////////////
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
465 llvm::Value* DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
466 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
467 llvm::Value* ptr = DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
468 llvm::Value* ptrld = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
469
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
470 size_t isz = gTargetData->getTypeSize(ptrld->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
471 llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), isz, false);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
472 llvm::Value* bytesz = (isz == 1) ? sz : llvm::BinaryOperator::createMul(n,sz,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
473
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
474 llvm::Value* newptr = DtoRealloc(ptrld, bytesz);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
475 new llvm::StoreInst(newptr,ptr,gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
476
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
477 llvm::Value* len = DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
478 new llvm::StoreInst(sz,len,gIR->scopebb());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
479
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
480 return newptr;
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
481 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
482
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
483 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
484 void DtoCatAssignElement(llvm::Value* arr, Expression* exp)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
485 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
486 llvm::Value* ptr = DtoGEPi(arr, 0, 0, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
487 llvm::Value* idx = DtoLoad(ptr);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
488 llvm::Value* one = llvm::ConstantInt::get(idx->getType(),1,false);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
489 llvm::Value* len = llvm::BinaryOperator::createAdd(idx, one, "tmp", gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
490 DtoResizeDynArray(arr,len);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
491
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
492 ptr = DtoLoad(DtoGEPi(arr, 0, 1, "tmp"));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
493 ptr = new llvm::GetElementPtrInst(ptr, idx, "tmp", gIR->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
494
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
495 DValue* dptr = new DVarValue(exp->type, ptr, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
496
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
497 gIR->exps.push_back(IRExp(0,exp,dptr));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
498 DValue* e = exp->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
499 gIR->exps.pop_back();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
500
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
501 if (!e->inPlace())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
502 DtoAssign(dptr, e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
503 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
504
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
505 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
506 void DtoCatAssignArray(llvm::Value* arr, Expression* exp)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
507 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
508 DValue* e = exp->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
509
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
510 llvm::Value *len1, *len2, *src1, *src2, *res;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
511
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
512 DValue* darr = new DVarValue(exp->type, arr, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
513
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
514 len1 = DtoArrayLen(darr);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
515 len2 = DtoArrayLen(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
516 res = gIR->ir->CreateAdd(len1,len2,"tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
517
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
518 llvm::Value* mem = DtoResizeDynArray(arr,res);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
519
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
520 src1 = DtoArrayPtr(darr);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
521 src2 = DtoArrayPtr(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
522
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
523 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
524 DtoMemCpy(mem,src2,len2);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
525 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
526
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
527 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
528 void DtoCatArrays(llvm::Value* arr, Expression* exp1, Expression* exp2)
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
529 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
530 Type* t1 = DtoDType(exp1->type);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
531 Type* t2 = DtoDType(exp2->type);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
532
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
533 assert(t1->ty == Tarray);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
534 assert(t1->ty == t2->ty);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
535
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
536 DValue* e1 = exp1->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
537 llvm::Value* a = e1->getRVal();
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
538
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
539 DValue* e2 = exp2->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
540 llvm::Value* b = e2->getRVal();
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
541
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
542 llvm::Value *len1, *len2, *src1, *src2, *res;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
543 len1 = gIR->ir->CreateLoad(DtoGEPi(a,0,0,"tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
544 len2 = gIR->ir->CreateLoad(DtoGEPi(b,0,0,"tmp"),"tmp");
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
545 res = gIR->ir->CreateAdd(len1,len2,"tmp");
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
546
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
547 llvm::Value* mem = DtoNewDynArray(arr, res, DtoDType(t1->next), false);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
548
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
549 src1 = gIR->ir->CreateLoad(DtoGEPi(a,0,1,"tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
550 src2 = gIR->ir->CreateLoad(DtoGEPi(b,0,1,"tmp"),"tmp");
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
551
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
552 DtoMemCpy(mem,src1,len1);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
553 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
554 DtoMemCpy(mem,src2,len2);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
555 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
556
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
557 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
558 llvm::Value* DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
559 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
560 const char* fname;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
561 if (op == TOKequal)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
562 fname = "_d_static_array_eq";
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
563 else if (op == TOKnotequal)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
564 fname = "_d_static_array_neq";
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
565 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
566 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
567 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
568 assert(fn);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
569
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
570 assert(l->getType() == r->getType());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
571 assert(llvm::isa<llvm::PointerType>(l->getType()));
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
572 const llvm::Type* arrty = l->getType()->getContainedType(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
573 assert(llvm::isa<llvm::ArrayType>(arrty));
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
574
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
575 llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
576 llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
577 llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(),gTargetData->getTypeSize(arrty),false);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
578
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
579 std::vector<llvm::Value*> args;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
580 args.push_back(ll);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
581 args.push_back(rr);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
582 args.push_back(n);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
583 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
584 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
585
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
586 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
587
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
588 llvm::Value* DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r)
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
589 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
590 const char* fname;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
591 if (op == TOKequal)
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
592 fname = "_d_dyn_array_eq";
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
593 else if (op == TOKnotequal)
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
594 fname = "_d_dyn_array_neq";
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
595 else
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
596 assert(0);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
597 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
598 assert(fn);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
599
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
600 Logger::cout() << "lhsType:" << *l->getType() << "\nrhsType:" << *r->getType() << '\n';
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
601 assert(l->getType() == r->getType());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
602 assert(llvm::isa<llvm::PointerType>(l->getType()));
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
603 const llvm::Type* arrty = l->getType()->getContainedType(0);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
604 assert(llvm::isa<llvm::StructType>(arrty));
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
605 const llvm::StructType* structType = llvm::cast<llvm::StructType>(arrty);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
606 const llvm::Type* elemType = structType->getElementType(1)->getContainedType(0);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
607
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
608 std::vector<const llvm::Type*> arrTypes;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
609 arrTypes.push_back(DtoSize_t());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
610 arrTypes.push_back(llvm::PointerType::get(llvm::Type::Int8Ty));
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
611 const llvm::StructType* arrType = llvm::StructType::get(arrTypes);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
612
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
613 llvm::Value* llmem = l;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
614 llvm::Value* rrmem = r;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
615
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
616 if (arrty != arrType) {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
617 llmem= new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
618
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
619 llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
620 ll = DtoArrayCastLength(ll, elemType, llvm::Type::Int8Ty);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
621 llvm::Value* lllen = DtoGEPi(llmem, 0,0, "tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
622 gIR->ir->CreateStore(ll,lllen);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
623
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
624 ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
625 ll = new llvm::BitCastInst(ll, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
626 llvm::Value* llptr = DtoGEPi(llmem, 0,1, "tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
627 gIR->ir->CreateStore(ll,llptr);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
628
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
629 rrmem = new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
630
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
631 llvm::Value* rr = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
632 rr = DtoArrayCastLength(rr, elemType, llvm::Type::Int8Ty);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
633 llvm::Value* rrlen = DtoGEPi(rrmem, 0,0, "tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
634 gIR->ir->CreateStore(rr,rrlen);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
635
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
636 rr = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
637 rr = new llvm::BitCastInst(rr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
638 llvm::Value* rrptr = DtoGEPi(rrmem, 0,1, "tmp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
639 gIR->ir->CreateStore(rr,rrptr);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
640 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
641
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
642 std::vector<llvm::Value*> args;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
643 args.push_back(llmem);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
644 args.push_back(rrmem);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
645 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
646 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
647
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
648 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
649 llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty)
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
650 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
651 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
652 assert(fn);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
653 std::vector<llvm::Value*> args;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
654 args.push_back(len);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
655 args.push_back(llvm::ConstantInt::get(DtoSize_t(), gTargetData->getTypeSize(elemty), false));
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
656 args.push_back(llvm::ConstantInt::get(DtoSize_t(), gTargetData->getTypeSize(newelemty), false));
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
657 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
658 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
659
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
660 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
661 llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
662 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
663 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
664
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
665 if (r == NULL) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
666 llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
667 llvm::Value* rl = DtoConstSize_t(0);
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
668 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
669
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
670 llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
671 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(lp->getType());
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
672 llvm::Value* rp = llvm::ConstantPointerNull::get(pty);
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
673 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
674
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
675 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
676 return b;
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
677 }
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
678 else {
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
679 assert(l->getType() == r->getType());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
680
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
681 llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
682 llvm::Value* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
683 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
684
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
685 llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
686 llvm::Value* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
687 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
688
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
689 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
690 return b;
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
691 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
692 }
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
693
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
694 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
695 llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
696 {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
697 assert(llvm::isa<llvm::ArrayType>(t));
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
698 const llvm::ArrayType* at = llvm::cast<llvm::ArrayType>(t);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
699
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
700 if (llvm::isa<llvm::ArrayType>(at->getElementType()))
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
701 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
702 c = DtoConstStaticArray(at->getElementType(), c);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
703 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
704 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
705 assert(at->getElementType() == c->getType());
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
706 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
707 std::vector<llvm::Constant*> initvals;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
708 initvals.resize(at->getNumElements(), c);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
709 return llvm::ConstantArray::get(at, initvals);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
710 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
711
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
712 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
713 llvm::Value* DtoArrayLen(DValue* v)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
714 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
715 Type* t = DtoDType(v->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
716 if (t->ty == Tarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
717 if (DSliceValue* s = v->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
718 if (s->len) return s->len;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
719 DValue* next = new DVarValue(t,s->ptr,true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
720 return DtoArrayLen(next);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
721 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
722 return DtoLoad(DtoGEPi(v->getRVal(), 0,0, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
723 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
724 else if (t->ty == Tsarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
725 const llvm::ArrayType* t = llvm::cast<llvm::ArrayType>(v->getLVal()->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
726 return DtoConstSize_t(t->getNumElements());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
727 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
728 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
729 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
730 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
731
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
732 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
733 llvm::Value* DtoArrayPtr(DValue* v)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
734 {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
735 Type* t = DtoDType(v->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
736 if (t->ty == Tarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
737 if (DSliceValue* s = v->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
738 if (s->len) return s->ptr;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
739 DValue* next = new DVarValue(t,s->ptr,true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
740 return DtoArrayPtr(next);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
741 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
742 return DtoLoad(DtoGEPi(v->getRVal(), 0,1, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
743 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
744 else if (t->ty == Tsarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
745 return DtoGEPi(v->getRVal(), 0,0, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
746 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
747 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
748 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
749 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
750