Mercurial > projects > ldc
annotate gen/arrays.c @ 58:2c3cd3596187 trunk
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
Added initial support for CatExp aka 'a ~ b'
Fixed global constant static arrays initialized with string literals
Fixed casting any dynamic array to void*
Fixed new expression with temporary storage
Fixed alias declarations in function scope
Fixed relational comparisons of pointers
author | lindquist |
---|---|
date | Thu, 25 Oct 2007 09:02:55 +0200 |
parents | 28e99b04a132 |
children | b688ad419f8c |
rev | line source |
---|---|
40 | 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" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
14 #include "gen/elem.h" |
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 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
6
diff
changeset
|
18 const llvm::StructType* LLVM_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); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
21 const llvm::Type* at = LLVM_DtoType(t->next); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
22 const llvm::Type* arrty; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
23 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
24 /*if (t->ty == Tsarray) { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
25 TypeSArray* tsa = (TypeSArray*)t; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
26 assert(tsa->dim->type->isintegral()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
27 arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
28 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
29 else { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
30 arrty = llvm::ArrayType::get(at,0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
31 }*/ |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
32 if (at == llvm::Type::VoidTy) { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
33 at = llvm::Type::Int8Ty; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
34 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
35 arrty = llvm::PointerType::get(at); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
36 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
37 std::vector<const llvm::Type*> members; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
38 if (global.params.is64bit) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
39 members.push_back(llvm::Type::Int64Ty); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
40 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
41 members.push_back(llvm::Type::Int32Ty); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
42 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
43 members.push_back(arrty); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
44 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
45 return llvm::StructType::get(members); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
46 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
47 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
48 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
49 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
6
diff
changeset
|
50 const llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
51 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
52 if (t->llvmType) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
53 return llvm::cast<llvm::ArrayType>(t->llvmType); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
54 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
55 assert(t->ty == Tsarray); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
56 assert(t->next); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
57 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
58 const llvm::Type* at = LLVM_DtoType(t->next); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
59 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
60 TypeSArray* tsa = (TypeSArray*)t; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
61 assert(tsa->dim->type->isintegral()); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
6
diff
changeset
|
62 const llvm::ArrayType* arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
63 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
64 tsa->llvmType = arrty; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
65 return arrty; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
66 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
67 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
68 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
69 |
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
|
70 void LLVM_DtoNullArray(llvm::Value* v) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
71 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
72 assert(gIR); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
73 |
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
|
74 llvm::Value* len = LLVM_DtoGEPi(v,0,0,"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
|
75 llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false); |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
76 new llvm::StoreInst(zerolen, len, gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
77 |
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
|
78 llvm::Value* ptr = LLVM_DtoGEPi(v,0,1,"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
|
79 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(ptr->getType()->getContainedType(0)); |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
80 llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty); |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
81 new llvm::StoreInst(nullptr, ptr, gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
82 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
83 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
84 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
85 |
34 | 86 void LLVM_DtoArrayAssign(llvm::Value* dst, llvm::Value* src) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
87 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
88 assert(gIR); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
89 if (dst->getType() == src->getType()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
90 { |
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 llvm::Value* ptr = LLVM_DtoGEPi(src,0,0,"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
|
92 llvm::Value* val = new llvm::LoadInst(ptr,"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
|
93 ptr = LLVM_DtoGEPi(dst,0,0,"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
|
94 new llvm::StoreInst(val, ptr, gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
95 |
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
|
96 ptr = LLVM_DtoGEPi(src,0,1,"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
|
97 val = new llvm::LoadInst(ptr,"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
|
98 ptr = LLVM_DtoGEPi(dst,0,1,"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
|
99 new llvm::StoreInst(val, ptr, gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
100 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
101 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
102 { |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
103 Logger::cout() << "array assignment type dont match: " << *dst->getType() << '\n' << *src->getType() << '\n'; |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
104 if (!llvm::isa<llvm::ArrayType>(src->getType()->getContainedType(0))) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
105 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
106 Logger::cout() << "invalid: " << *src << '\n'; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
107 assert(0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
108 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
109 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(src->getType()->getContainedType(0)); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
110 llvm::Type* dstty = llvm::PointerType::get(arrty->getElementType()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
111 |
34 | 112 llvm::Value* dstlen = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
113 llvm::Value* srclen = LLVM_DtoConstSize_t(arrty->getNumElements()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
114 new llvm::StoreInst(srclen, dstlen, gIR->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
115 |
34 | 116 llvm::Value* dstptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
117 llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
118 new llvm::StoreInst(srcptr, dstptr, gIR->scopebb()); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
119 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
120 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
121 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
122 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
123 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
124 void LLVM_DtoArrayInit(llvm::Value* l, llvm::Value* r) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
125 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
126 const llvm::PointerType* ptrty = llvm::cast<llvm::PointerType>(l->getType()); |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
127 const llvm::Type* t = ptrty->getContainedType(0); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
128 const llvm::ArrayType* arrty = llvm::cast_or_null<llvm::ArrayType>(t); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
129 if (arrty) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
130 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
131 llvm::Value* ptr = LLVM_DtoGEPi(l,0,0,"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
|
132 llvm::Value* dim = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
133 llvm::Value* val = r; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
134 LLVM_DtoArrayInit(ptr, dim, val); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
135 } |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
136 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
|
137 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
138 assert(0 && "Only static arrays support initialisers atm"); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
139 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
140 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
141 assert(0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
142 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
143 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
144 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
145 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
146 void LLVM_DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val) |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
147 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
148 const llvm::Type* t = ptr->getType()->getContainedType(0); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
149 |
43 | 150 std::vector<llvm::Value*> args; |
151 args.push_back(ptr); | |
152 args.push_back(dim); | |
153 args.push_back(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 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
155 const char* funcname = NULL; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
156 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
157 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
|
158 funcname = "_d_array_init_pointer"; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
159 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
160 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
|
161 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
|
162 args[0] = new llvm::BitCastInst(args[0],dstty,"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
|
163 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
168 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
|
169 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
|
170 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
171 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
|
172 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
|
173 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
174 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
|
175 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
|
176 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
177 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
|
178 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
|
179 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
180 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
|
181 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
|
182 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
183 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
|
184 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
|
185 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
186 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
|
187 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
|
188 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
189 else { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
190 assert(0); |
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 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
193 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
|
194 assert(fn); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
199 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
200 ////////////////////////////////////////////////////////////////////////////////////////// |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
201 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
202 void LLVM_DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
203 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
204 Logger::cout() << "LLVM_DtoSetArray(" << *arr << ", " << *dim << ", " << *ptr << ")\n"; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
205 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
|
206 //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
|
207 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
208 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
|
209 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
|
210 |
6 | 211 llvm::Value* arrdim = LLVM_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
|
212 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
|
213 |
6 | 214 llvm::Value* arrptr = LLVM_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
|
215 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
|
216 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
217 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
218 ////////////////////////////////////////////////////////////////////////////////////////// |
40 | 219 llvm::Constant* LLVM_DtoConstArrayInitializer(ArrayInitializer* arrinit) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
220 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
221 Logger::println("arr init begin"); |
40 | 222 Type* arrinittype = LLVM_DtoDType(arrinit->type); |
223 assert(arrinittype->ty == Tsarray); | |
224 TypeSArray* t = (TypeSArray*)arrinittype; | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
225 integer_t tdim = t->dim->toInteger(); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
226 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
227 std::vector<llvm::Constant*> inits(tdim, 0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
228 |
40 | 229 const llvm::Type* elemty = LLVM_DtoType(arrinittype->next); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
230 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
231 assert(arrinit->index.dim == arrinit->value.dim); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
232 for (int i=0,j=0; i < tdim; ++i) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
233 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
234 Initializer* init = 0; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
235 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
|
236 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
237 if (idx) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
238 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
239 integer_t k = idx->toInteger(); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
240 if (i == k) |
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 init = (Initializer*)arrinit->value.data[j]; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
243 assert(init); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
244 ++j; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
245 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
246 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
247 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
248 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
249 init = (Initializer*)arrinit->value.data[j]; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
250 ++j; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
251 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
252 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
253 llvm::Constant* v = 0; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
254 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
255 if (!init) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
256 { |
40 | 257 v = t->next->defaultInit()->toConstElem(gIR); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
258 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
259 else if (ExpInitializer* ex = init->isExpInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
260 { |
40 | 261 v = ex->exp->toConstElem(gIR); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
262 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
263 else if (StructInitializer* si = init->isStructInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
264 { |
40 | 265 v = LLVM_DtoConstStructInitializer(si); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
266 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
267 else if (ArrayInitializer* ai = init->isArrayInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
268 { |
40 | 269 v = LLVM_DtoConstArrayInitializer(ai); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
270 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
271 else if (init->isVoidInitializer()) |
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 v = llvm::UndefValue::get(elemty); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
274 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
275 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
276 assert(v); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
277 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
278 inits[i] = v; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
279 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
280 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
6
diff
changeset
|
281 const llvm::ArrayType* arrty = LLVM_DtoStaticArrayType(t); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
282 return llvm::ConstantArray::get(arrty, inits); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
283 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
284 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
285 ////////////////////////////////////////////////////////////////////////////////////////// |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
286 static llvm::Value* get_slice_ptr(elem* e, llvm::Value*& sz) |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
287 { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
288 assert(e->mem); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
289 const llvm::Type* t = e->mem->getType()->getContainedType(0); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
290 llvm::Value* ret = 0; |
22
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
291 if (e->arg != 0) { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
292 // this means it's a real slice |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
293 ret = e->mem; |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
294 |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
295 size_t elembsz = gTargetData->getTypeSize(ret->getType()); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
296 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
297 |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
298 if (llvm::isa<llvm::ConstantInt>(e->arg)) { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
299 sz = llvm::ConstantExpr::getMul(elemsz, llvm::cast<llvm::Constant>(e->arg)); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
300 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
301 else { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
302 sz = llvm::BinaryOperator::createMul(elemsz,e->arg,"tmp",gIR->scopebb()); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
303 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
304 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
305 else if (llvm::isa<llvm::ArrayType>(t)) { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
306 ret = LLVM_DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
307 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
308 size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0)); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
309 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
310 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
311 size_t numelements = llvm::cast<llvm::ArrayType>(t)->getNumElements(); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
312 llvm::ConstantInt* nelems = llvm::ConstantInt::get(LLVM_DtoSize_t(), numelements, false); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
313 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
314 sz = llvm::ConstantExpr::getMul(elemsz, nelems); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
315 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
316 else if (llvm::isa<llvm::StructType>(t)) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
317 ret = LLVM_DtoGEPi(e->mem, 0, 1, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
318 ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
319 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
320 size_t elembsz = gTargetData->getTypeSize(ret->getType()->getContainedType(0)); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
321 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(LLVM_DtoSize_t(), elembsz, false); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
322 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
323 llvm::Value* len = LLVM_DtoGEPi(e->mem, 0, 0, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
324 len = new llvm::LoadInst(len, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
325 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
|
326 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
327 else { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
328 assert(0); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
329 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
330 return ret; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
331 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
332 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
333 void LLVM_DtoArrayCopy(elem* dst, elem* src) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
334 { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
335 Logger::cout() << "Array copy ((((" << *src->mem << ")))) into ((((" << *dst->mem << "))))\n"; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
336 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
337 assert(dst->type == elem::SLICE); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
338 assert(src->type == elem::SLICE); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
339 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
340 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
|
341 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
342 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
|
343 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
|
344 |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
345 llvm::Value* sz2; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
346 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
|
347 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
348 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
|
349 std::vector<llvm::Value*> llargs; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
350 llargs.resize(4); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
351 llargs[0] = dstarr; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
352 llargs[1] = srcarr; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
353 llargs[2] = sz1; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
354 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
|
355 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
356 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
|
357 } |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
358 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
359 ////////////////////////////////////////////////////////////////////////////////////////// |
48 | 360 void LLVM_DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src) |
361 { | |
362 assert(dst->getType() == src->getType()); | |
363 size_t arrsz = gTargetData->getTypeSize(dst->getType()->getContainedType(0)); | |
364 llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrsz, false); | |
365 | |
366 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
367 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); | |
368 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); | |
369 | |
370 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); | |
371 std::vector<llvm::Value*> llargs; | |
372 llargs.resize(4); | |
373 llargs[0] = dstarr; | |
374 llargs[1] = srcarr; | |
375 llargs[2] = n; | |
376 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
377 | |
378 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
379 } | |
380 | |
381 ////////////////////////////////////////////////////////////////////////////////////////// | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
382 llvm::Constant* LLVM_DtoConstantSlice(llvm::Constant* dim, llvm::Constant* ptr) |
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 std::vector<const llvm::Type*> types; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
385 types.push_back(dim->getType()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
386 types.push_back(ptr->getType()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
387 const llvm::StructType* type = llvm::StructType::get(types); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
388 std::vector<llvm::Constant*> values; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
389 values.push_back(dim); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
390 values.push_back(ptr); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
391 return llvm::ConstantStruct::get(type,values); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
392 } |
34 | 393 |
394 ////////////////////////////////////////////////////////////////////////////////////////// | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
395 llvm::Value* LLVM_DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit) |
34 | 396 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
397 const llvm::Type* ty = LLVM_DtoType(dty); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
398 assert(ty != llvm::Type::VoidTy); |
34 | 399 size_t sz = gTargetData->getTypeSize(ty); |
400 llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), sz, false); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
401 llvm::Value* bytesize = (sz == 1) ? dim : llvm::BinaryOperator::createMul(n,dim,"tmp",gIR->scopebb()); |
34 | 402 |
403 llvm::Value* nullptr = llvm::ConstantPointerNull::get(llvm::PointerType::get(ty)); | |
404 | |
405 llvm::Value* newptr = LLVM_DtoRealloc(nullptr, bytesize); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
406 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
407 if (doinit) { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
408 elem* e = dty->defaultInit()->toElem(gIR); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
409 LLVM_DtoArrayInit(newptr,dim,e->getValue()); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
410 delete e; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
411 } |
34 | 412 |
413 llvm::Value* lenptr = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); | |
414 new llvm::StoreInst(dim,lenptr,gIR->scopebb()); | |
415 llvm::Value* ptrptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); | |
416 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
|
417 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
418 return newptr; |
34 | 419 } |
420 | |
421 ////////////////////////////////////////////////////////////////////////////////////////// | |
422 void LLVM_DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz) | |
423 { | |
424 llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb()); | |
425 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
|
426 |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
427 size_t isz = gTargetData->getTypeSize(ptrld->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
|
428 llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), isz, false); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
429 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
|
430 |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
431 llvm::Value* newptr = LLVM_DtoRealloc(ptrld, bytesz); |
34 | 432 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
|
433 |
34 | 434 llvm::Value* len = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb()); |
435 new llvm::StoreInst(sz,len,gIR->scopebb()); | |
436 } | |
437 | |
40 | 438 ////////////////////////////////////////////////////////////////////////////////////////// |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
439 void LLVM_DtoCatAssignElement(llvm::Value* arr, Expression* exp) |
40 | 440 { |
441 llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb()); | |
442 llvm::Value* idx = new llvm::LoadInst(ptr, "tmp", gIR->scopebb()); | |
443 llvm::Value* one = llvm::ConstantInt::get(idx->getType(),1,false); | |
444 llvm::Value* len = llvm::BinaryOperator::createAdd(idx, one, "tmp", gIR->scopebb()); | |
445 LLVM_DtoResizeDynArray(arr,len); | |
446 | |
447 ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb()); | |
448 ptr = new llvm::LoadInst(ptr, "tmp", gIR->scopebb()); | |
449 ptr = new llvm::GetElementPtrInst(ptr, idx, "tmp", gIR->scopebb()); | |
450 | |
451 elem* e = exp->toElem(gIR); | |
452 Type* et = LLVM_DtoDType(exp->type); | |
51
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
48
diff
changeset
|
453 LLVM_DtoAssign(et, ptr, e->getValue()); |
61bc1b4ad3c4
[svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents:
48
diff
changeset
|
454 delete e; |
40 | 455 } |
456 | |
457 ////////////////////////////////////////////////////////////////////////////////////////// | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
458 void LLVM_DtoCatArrays(llvm::Value* arr, Expression* exp1, Expression* exp2) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
459 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
460 Type* t1 = LLVM_DtoDType(exp1->type); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
461 Type* t2 = LLVM_DtoDType(exp2->type); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
462 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
463 assert(t1->ty == Tarray); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
464 assert(t1->ty == t2->ty); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
465 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
466 elem* e1 = exp1->toElem(gIR); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
467 llvm::Value* a = e1->getValue(); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
468 delete e1; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
469 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
470 elem* e2 = exp2->toElem(gIR); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
471 llvm::Value* b = e2->getValue(); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
472 delete e2; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
473 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
474 llvm::Value *len1, *len2, *src1, *src2, *res; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
475 len1 = gIR->ir->CreateLoad(LLVM_DtoGEPi(a,0,0,"tmp"),"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
476 len2 = gIR->ir->CreateLoad(LLVM_DtoGEPi(b,0,0,"tmp"),"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
477 res = gIR->ir->CreateAdd(len1,len2,"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
478 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
479 llvm::Value* mem = LLVM_DtoNewDynArray(arr, res, LLVM_DtoDType(t1->next), false); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
480 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
481 src1 = gIR->ir->CreateLoad(LLVM_DtoGEPi(a,0,1,"tmp"),"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
482 src2 = gIR->ir->CreateLoad(LLVM_DtoGEPi(b,0,1,"tmp"),"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
483 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
484 LLVM_DtoMemCpy(mem,src1,len1); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
485 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
486 LLVM_DtoMemCpy(mem,src2,len2); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
487 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
488 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
489 ////////////////////////////////////////////////////////////////////////////////////////// |
40 | 490 llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r) |
491 { | |
492 const char* fname; | |
493 if (op == TOKequal) | |
494 fname = "_d_static_array_eq"; | |
495 else if (op == TOKnotequal) | |
496 fname = "_d_static_array_neq"; | |
497 else | |
498 assert(0); | |
499 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); | |
500 assert(fn); | |
501 | |
502 assert(l->getType() == r->getType()); | |
503 assert(llvm::isa<llvm::PointerType>(l->getType())); | |
504 const llvm::Type* arrty = l->getType()->getContainedType(0); | |
505 assert(llvm::isa<llvm::ArrayType>(arrty)); | |
506 | |
507 llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
508 llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
509 llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(),gTargetData->getTypeSize(arrty),false); | |
510 | |
511 std::vector<llvm::Value*> args; | |
512 args.push_back(ll); | |
513 args.push_back(rr); | |
514 args.push_back(n); | |
515 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb()); | |
516 } | |
517 | |
518 ////////////////////////////////////////////////////////////////////////////////////////// | |
519 | |
52 | 520 llvm::Value* LLVM_DtoDynArrayCompare(TOK op, llvm::Value* l, llvm::Value* r) |
521 { | |
522 const char* fname; | |
523 if (op == TOKequal) | |
524 fname = "_d_dyn_array_eq"; | |
525 else if (op == TOKnotequal) | |
526 fname = "_d_dyn_array_neq"; | |
527 else | |
528 assert(0); | |
529 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); | |
530 assert(fn); | |
531 | |
532 Logger::cout() << "lhsType:" << *l->getType() << "\nrhsType:" << *r->getType() << '\n'; | |
533 assert(l->getType() == r->getType()); | |
534 assert(llvm::isa<llvm::PointerType>(l->getType())); | |
535 const llvm::Type* arrty = l->getType()->getContainedType(0); | |
536 assert(llvm::isa<llvm::StructType>(arrty)); | |
537 const llvm::StructType* structType = llvm::cast<llvm::StructType>(arrty); | |
538 const llvm::Type* elemType = structType->getElementType(1)->getContainedType(0); | |
539 | |
540 std::vector<const llvm::Type*> arrTypes; | |
541 arrTypes.push_back(LLVM_DtoSize_t()); | |
542 arrTypes.push_back(llvm::PointerType::get(llvm::Type::Int8Ty)); | |
543 const llvm::StructType* arrType = llvm::StructType::get(arrTypes); | |
544 | |
545 llvm::Value* llmem = l; | |
546 llvm::Value* rrmem = r; | |
547 | |
548 if (arrty != arrType) { | |
549 llmem= new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint()); | |
550 | |
551 llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp"); | |
552 ll = LLVM_DtoArrayCastLength(ll, elemType, llvm::Type::Int8Ty); | |
553 llvm::Value* lllen = LLVM_DtoGEPi(llmem, 0,0, "tmp"); | |
554 gIR->ir->CreateStore(ll,lllen); | |
555 | |
556 ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp"); | |
557 ll = new llvm::BitCastInst(ll, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
558 llvm::Value* llptr = LLVM_DtoGEPi(llmem, 0,1, "tmp"); | |
559 gIR->ir->CreateStore(ll,llptr); | |
560 | |
561 rrmem = new llvm::AllocaInst(arrType,"tmparr",gIR->topallocapoint()); | |
562 | |
563 llvm::Value* rr = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,0, "tmp"),"tmp"); | |
564 rr = LLVM_DtoArrayCastLength(rr, elemType, llvm::Type::Int8Ty); | |
565 llvm::Value* rrlen = LLVM_DtoGEPi(rrmem, 0,0, "tmp"); | |
566 gIR->ir->CreateStore(rr,rrlen); | |
567 | |
568 rr = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,1, "tmp"),"tmp"); | |
569 rr = new llvm::BitCastInst(rr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
570 llvm::Value* rrptr = LLVM_DtoGEPi(rrmem, 0,1, "tmp"); | |
571 gIR->ir->CreateStore(rr,rrptr); | |
572 } | |
573 | |
574 std::vector<llvm::Value*> args; | |
575 args.push_back(llmem); | |
576 args.push_back(rrmem); | |
577 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb()); | |
578 } | |
579 | |
580 ////////////////////////////////////////////////////////////////////////////////////////// | |
581 llvm::Value* LLVM_DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty) | |
582 { | |
583 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len"); | |
584 assert(fn); | |
585 std::vector<llvm::Value*> args; | |
586 args.push_back(len); | |
587 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(elemty), false)); | |
588 args.push_back(llvm::ConstantInt::get(LLVM_DtoSize_t(), gTargetData->getTypeSize(newelemty), false)); | |
589 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb()); | |
590 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
591 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
592 ////////////////////////////////////////////////////////////////////////////////////////// |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
593 llvm::Value* LLVM_DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r) |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
594 { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
595 assert(l->getType() == r->getType()); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
596 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
597 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
|
598 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
599 llvm::Value* ll = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,0, "tmp"),"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
600 llvm::Value* rl = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,0, "tmp"),"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
601 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
602 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
603 llvm::Value* lp = gIR->ir->CreateLoad(LLVM_DtoGEPi(l, 0,1, "tmp"),"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
604 llvm::Value* rp = gIR->ir->CreateLoad(LLVM_DtoGEPi(r, 0,1, "tmp"),"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
605 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
606 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
607 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp"); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
608 return b; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
609 } |