Mercurial > projects > ldc
annotate gen/arrays.c @ 48:4d171915a77b trunk
[svn r52] fixed static arrays in struct literals
author | lindquist |
---|---|
date | Fri, 19 Oct 2007 17:15:30 +0200 |
parents | eb7bf7b7972e |
children | 61bc1b4ad3c4 |
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 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
103 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
|
104 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
105 Logger::cout() << "invalid: " << *src << '\n'; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
106 assert(0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
107 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
108 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
|
109 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
|
110 |
34 | 111 llvm::Value* dstlen = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
112 llvm::Value* srclen = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
113 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
|
114 |
34 | 115 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
|
116 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
|
117 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
|
118 } |
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 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
|
124 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 if (arrty) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
129 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 LLVM_DtoArrayInit(ptr, dim, val); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
134 } |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
135 else if (llvm::isa<llvm::StructType>(t)) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
136 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
137 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
|
138 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
139 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
140 assert(0); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
141 } |
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 |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
145 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
|
146 { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
147 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
|
148 |
43 | 149 std::vector<llvm::Value*> args; |
150 args.push_back(ptr); | |
151 args.push_back(dim); | |
152 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
|
153 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
154 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
|
155 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
156 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
|
157 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
|
158 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
167 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
|
168 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
|
169 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
170 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
|
171 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
|
172 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
173 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
|
174 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
|
175 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
176 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
|
177 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
|
178 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
179 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
|
180 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
|
181 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
182 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
|
183 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
|
184 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
185 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
|
186 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
|
187 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
188 else { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
189 assert(0); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
190 } |
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 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
|
193 assert(fn); |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
194 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
|
195 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
|
196 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
199 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
200 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
|
201 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
202 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
|
203 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
|
204 //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
|
205 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
206 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
|
207 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
|
208 |
6 | 209 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
|
210 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
|
211 |
6 | 212 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
|
213 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
|
214 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
215 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
216 ////////////////////////////////////////////////////////////////////////////////////////// |
40 | 217 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
|
218 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
219 Logger::println("arr init begin"); |
40 | 220 Type* arrinittype = LLVM_DtoDType(arrinit->type); |
221 assert(arrinittype->ty == Tsarray); | |
222 TypeSArray* t = (TypeSArray*)arrinittype; | |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
223 integer_t tdim = t->dim->toInteger(); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
224 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
225 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
|
226 |
40 | 227 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
|
228 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
229 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
|
230 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
|
231 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
232 Initializer* init = 0; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
233 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
|
234 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
235 if (idx) |
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 integer_t k = idx->toInteger(); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
238 if (i == k) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
239 { |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
240 init = (Initializer*)arrinit->value.data[j]; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
241 assert(init); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
242 ++j; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
243 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
244 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
245 else |
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 init = (Initializer*)arrinit->value.data[j]; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
248 ++j; |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
249 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
250 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
251 llvm::Constant* v = 0; |
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 if (!init) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
254 { |
40 | 255 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
|
256 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
257 else if (ExpInitializer* ex = init->isExpInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
258 { |
40 | 259 v = ex->exp->toConstElem(gIR); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
260 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
261 else if (StructInitializer* si = init->isStructInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
262 { |
40 | 263 v = LLVM_DtoConstStructInitializer(si); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
264 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
265 else if (ArrayInitializer* ai = init->isArrayInitializer()) |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
266 { |
40 | 267 v = LLVM_DtoConstArrayInitializer(ai); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
268 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
269 else if (init->isVoidInitializer()) |
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 v = llvm::UndefValue::get(elemty); |
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 else |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
274 assert(v); |
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 inits[i] = 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 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
6
diff
changeset
|
279 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
|
280 return llvm::ConstantArray::get(arrty, inits); |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
281 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
282 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
283 ////////////////////////////////////////////////////////////////////////////////////////// |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
284 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
|
285 { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
286 assert(e->mem); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
287 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
|
288 llvm::Value* ret = 0; |
22
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
289 if (e->arg != 0) { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
290 // this means it's a real slice |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
291 ret = e->mem; |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
292 |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
293 size_t elembsz = gTargetData->getTypeSize(ret->getType()); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
294 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
|
295 |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
296 if (llvm::isa<llvm::ConstantInt>(e->arg)) { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
297 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
|
298 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
299 else { |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
300 sz = llvm::BinaryOperator::createMul(elemsz,e->arg,"tmp",gIR->scopebb()); |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
301 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
302 } |
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
303 else if (llvm::isa<llvm::ArrayType>(t)) { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
304 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
|
305 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
306 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
|
307 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
|
308 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
309 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
|
310 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
|
311 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
312 sz = llvm::ConstantExpr::getMul(elemsz, nelems); |
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 else if (llvm::isa<llvm::StructType>(t)) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
315 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
|
316 ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
317 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
318 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
|
319 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
|
320 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
321 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
|
322 len = new llvm::LoadInst(len, "tmp", gIR->scopebb()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
323 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
|
324 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
325 else { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
326 assert(0); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
327 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
328 return ret; |
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 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
331 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
|
332 { |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
333 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
|
334 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
335 assert(dst->type == elem::SLICE); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
336 assert(src->type == elem::SLICE); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
337 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
338 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
|
339 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
340 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
|
341 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
|
342 |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
343 llvm::Value* sz2; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
344 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
|
345 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
346 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
|
347 std::vector<llvm::Value*> llargs; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
348 llargs.resize(4); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
349 llargs[0] = dstarr; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
350 llargs[1] = srcarr; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
351 llargs[2] = sz1; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
352 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
|
353 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
354 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
|
355 } |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
356 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
357 ////////////////////////////////////////////////////////////////////////////////////////// |
48 | 358 void LLVM_DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src) |
359 { | |
360 assert(dst->getType() == src->getType()); | |
361 size_t arrsz = gTargetData->getTypeSize(dst->getType()->getContainedType(0)); | |
362 llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrsz, false); | |
363 | |
364 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
365 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); | |
366 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); | |
367 | |
368 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); | |
369 std::vector<llvm::Value*> llargs; | |
370 llargs.resize(4); | |
371 llargs[0] = dstarr; | |
372 llargs[1] = srcarr; | |
373 llargs[2] = n; | |
374 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
375 | |
376 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
377 } | |
378 | |
379 ////////////////////////////////////////////////////////////////////////////////////////// | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
380 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
|
381 { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
382 std::vector<const llvm::Type*> types; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
383 types.push_back(dim->getType()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
384 types.push_back(ptr->getType()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
385 const llvm::StructType* type = llvm::StructType::get(types); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
386 std::vector<llvm::Constant*> values; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
387 values.push_back(dim); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
388 values.push_back(ptr); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
389 return llvm::ConstantStruct::get(type,values); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
390 } |
34 | 391 |
392 ////////////////////////////////////////////////////////////////////////////////////////// | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
393 void LLVM_DtoNewDynArray(llvm::Value* dst, llvm::Value* dim, Type* dty, bool doinit) |
34 | 394 { |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
395 const llvm::Type* ty = LLVM_DtoType(dty); |
34 | 396 size_t sz = gTargetData->getTypeSize(ty); |
397 llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), sz, false); | |
398 llvm::Value* bytesize = llvm::BinaryOperator::createMul(n,dim,"tmp",gIR->scopebb()); | |
399 | |
400 llvm::Value* nullptr = llvm::ConstantPointerNull::get(llvm::PointerType::get(ty)); | |
401 | |
402 llvm::Value* newptr = LLVM_DtoRealloc(nullptr, bytesize); | |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
403 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
404 if (doinit) { |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
405 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
|
406 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
|
407 delete e; |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
408 } |
34 | 409 |
410 llvm::Value* lenptr = LLVM_DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); | |
411 new llvm::StoreInst(dim,lenptr,gIR->scopebb()); | |
412 llvm::Value* ptrptr = LLVM_DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); | |
413 new llvm::StoreInst(newptr,ptrptr,gIR->scopebb()); | |
414 } | |
415 | |
416 ////////////////////////////////////////////////////////////////////////////////////////// | |
417 void LLVM_DtoResizeDynArray(llvm::Value* arr, llvm::Value* sz) | |
418 { | |
419 llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb()); | |
420 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
|
421 |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
422 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
|
423 llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), isz, 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
|
424 llvm::Value* bytesz = llvm::BinaryOperator::createMul(n,sz,"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
|
425 |
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 llvm::Value* newptr = LLVM_DtoRealloc(ptrld, bytesz); |
34 | 427 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
|
428 |
34 | 429 llvm::Value* len = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb()); |
430 new llvm::StoreInst(sz,len,gIR->scopebb()); | |
431 } | |
432 | |
40 | 433 ////////////////////////////////////////////////////////////////////////////////////////// |
434 void LLVM_DtoCatArrayElement(llvm::Value* arr, Expression* exp) | |
435 { | |
436 llvm::Value* ptr = LLVM_DtoGEPi(arr, 0, 0, "tmp", gIR->scopebb()); | |
437 llvm::Value* idx = new llvm::LoadInst(ptr, "tmp", gIR->scopebb()); | |
438 llvm::Value* one = llvm::ConstantInt::get(idx->getType(),1,false); | |
439 llvm::Value* len = llvm::BinaryOperator::createAdd(idx, one, "tmp", gIR->scopebb()); | |
440 LLVM_DtoResizeDynArray(arr,len); | |
441 | |
442 ptr = LLVM_DtoGEPi(arr, 0, 1, "tmp", gIR->scopebb()); | |
443 ptr = new llvm::LoadInst(ptr, "tmp", gIR->scopebb()); | |
444 ptr = new llvm::GetElementPtrInst(ptr, idx, "tmp", gIR->scopebb()); | |
445 | |
446 elem* e = exp->toElem(gIR); | |
447 Type* et = LLVM_DtoDType(exp->type); | |
448 | |
449 if (et->ty == Tstruct) { | |
450 TypeStruct* ts = (TypeStruct*)et; | |
451 LLVM_DtoStructCopy(ts,ptr,e->getValue()); | |
452 } | |
453 else { | |
454 llvm::Value* val = e->getValue(); | |
455 Logger::cout() << "ptr = '" << *ptr << "' element = '" << *val << "'\n"; | |
456 new llvm::StoreInst(val, ptr, gIR->scopebb()); | |
457 } | |
458 } | |
459 | |
460 ////////////////////////////////////////////////////////////////////////////////////////// | |
461 llvm::Value* LLVM_DtoStaticArrayCompare(TOK op, llvm::Value* l, llvm::Value* r) | |
462 { | |
463 const char* fname; | |
464 if (op == TOKequal) | |
465 fname = "_d_static_array_eq"; | |
466 else if (op == TOKnotequal) | |
467 fname = "_d_static_array_neq"; | |
468 else | |
469 assert(0); | |
470 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); | |
471 assert(fn); | |
472 | |
473 assert(l->getType() == r->getType()); | |
474 assert(llvm::isa<llvm::PointerType>(l->getType())); | |
475 const llvm::Type* arrty = l->getType()->getContainedType(0); | |
476 assert(llvm::isa<llvm::ArrayType>(arrty)); | |
477 | |
478 llvm::Value* ll = new llvm::BitCastInst(l, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
479 llvm::Value* rr = new llvm::BitCastInst(r, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp", gIR->scopebb()); | |
480 llvm::Value* n = llvm::ConstantInt::get(LLVM_DtoSize_t(),gTargetData->getTypeSize(arrty),false); | |
481 | |
482 std::vector<llvm::Value*> args; | |
483 args.push_back(ll); | |
484 args.push_back(rr); | |
485 args.push_back(n); | |
486 return new llvm::CallInst(fn, args.begin(), args.end(), "tmp", gIR->scopebb()); | |
487 } | |
488 | |
489 ////////////////////////////////////////////////////////////////////////////////////////// | |
490 |