annotate gen/arrays.cpp @ 94:61615fa85940 trunk

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