annotate gen/arrays.cpp @ 211:f66219e0d530 trunk

[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
author lindquist
date Tue, 27 May 2008 19:53:29 +0200
parents 9d44ec83acd1
children 7816aafeea3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1 #include "gen/llvm.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
2
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
3 #include "mtype.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
4 #include "dsymbol.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
5 #include "aggregate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
6 #include "declaration.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
7 #include "init.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
8
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
9 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
10 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
11 #include "gen/arrays.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
12 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
13 #include "gen/logger.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
14 #include "gen/dvalue.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
15
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
16 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
17
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
18 const llvm::StructType* DtoArrayType(Type* t)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
19 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
20 assert(t->next);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
21 const llvm::Type* at = DtoType(t->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
22 const llvm::Type* arrty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
23
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
24 if (at == llvm::Type::VoidTy) {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
25 at = llvm::Type::Int8Ty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
26 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
27 arrty = getPtrToType(at);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
28
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
29 std::vector<const llvm::Type*> members;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
30 if (global.params.is64bit)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
31 members.push_back(llvm::Type::Int64Ty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
32 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
33 members.push_back(llvm::Type::Int32Ty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
34
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
35 members.push_back(arrty);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
36
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
37 return llvm::StructType::get(members);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
38 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
39
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
40 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
41
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
42 const llvm::ArrayType* DtoStaticArrayType(Type* t)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
43 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
44 if (t->ir.type)
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
45 return isaArray(t->ir.type->get());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
46
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
47 assert(t->ty == Tsarray);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
48 assert(t->next);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
49
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
50 const llvm::Type* at = DtoType(t->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
51
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
52 TypeSArray* tsa = (TypeSArray*)t;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
53 assert(tsa->dim->type->isintegral());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 6
diff changeset
54 const llvm::ArrayType* arrty = llvm::ArrayType::get(at,tsa->dim->toUInteger());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
55
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
56 assert(!tsa->ir.type);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
57 tsa->ir.type = new llvm::PATypeHolder(arrty);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
58 return arrty;
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
59 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
60
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
61 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
62
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
63 void DtoSetArrayToNull(llvm::Value* v)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
64 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
65 Logger::println("DtoSetArrayToNull");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
66 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
67
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
68 llvm::Value* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
69 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
70 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
71
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
72 llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb());
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
73 const llvm::PointerType* pty = isaPointer(ptr->getType()->getContainedType(0));
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* 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
75 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
76 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
77
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
78 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
79
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
80 void DtoArrayAssign(llvm::Value* dst, llvm::Value* src)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
81 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
82 Logger::println("DtoArrayAssign");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
83 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
84
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
85 assert(gIR);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
86 if (dst->getType() == src->getType())
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
87 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
88 llvm::Value* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
89 llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
90 ptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
91 new llvm::StoreInst(val, ptr, gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
92
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
93 ptr = DtoGEPi(src,0,1,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
94 val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
95 ptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
96 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
97 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
98 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
99 {
118
d580b95cce2b [svn r122] Fixed temporary delegates can now alloca their own storage.
lindquist
parents: 116
diff changeset
100 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n';
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
101 const llvm::ArrayType* arrty = isaArray(src->getType()->getContainedType(0));
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
102 if (!arrty)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
103 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
104 Logger::cout() << "invalid: " << *src << '\n';
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
105 assert(0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
106 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
107 const llvm::Type* dstty = getPtrToType(arrty->getElementType());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
108
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
109 llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb());
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
110 llvm::Value* srclen = DtoConstSize_t(arrty->getNumElements());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
111 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
112
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
113 llvm::Value* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
114 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
115 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
116 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
117 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
118
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
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
121 void DtoArrayInit(llvm::Value* l, llvm::Value* r)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
122 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
123 Logger::println("DtoArrayInit");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
124 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
125
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
126 const llvm::PointerType* ptrty = isaPointer(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);
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
128 const llvm::ArrayType* arrty = isaArray(t);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
129 if (arrty)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
130 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
131 llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb());
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
132 llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
133 DtoArrayInit(ptr, dim, r);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
134 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
135 else if (isaStruct(t))
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
136 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
137 llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
138 llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
139 DtoArrayInit(ptr, dim, r);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
140 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
141 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
142 assert(0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
143 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
144
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
145 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
146
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
147 typedef const llvm::Type* constLLVMTypeP;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
148
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
149 static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty)
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
150 {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
151 if (const llvm::ArrayType* arrty = isaArray(pt)) {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
152 size_t n = checkRectArrayInit(arrty->getElementType(), finalty);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
153 size_t ne = arrty->getNumElements();
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
154 if (n) return n * ne;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
155 return ne;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
156 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
157 finalty = pt;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
158 return 0;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
159 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
160
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
161 void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val)
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
162 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
163 Logger::println("DtoArrayInit");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
164 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
165
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
166 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
167 const llvm::Type* pt = ptr->getType()->getContainedType(0);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
168 const llvm::Type* t = val->getType();
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
169 const llvm::Type* finalTy;
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
170 size_t aggrsz = 0;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
171 if (size_t arrsz = checkRectArrayInit(pt, finalTy)) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
172 assert(finalTy == t);
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
173 llvm::Constant* c = isaConstant(dim);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
174 assert(c);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
175 dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
176 ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(finalTy), "tmp");
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
177 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
178 else if (isaStruct(t)) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
179 aggrsz = getABITypeSize(t);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
180 llvm::Constant* c = isaConstant(val);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
181 if (c && c->isNullValue()) {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
182 llvm::Value* nbytes;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
183 if (aggrsz == 1)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
184 nbytes = dim;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
185 else
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
186 nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(aggrsz), "tmp");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
187 DtoMemSetZero(ptr,nbytes);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
188 return;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
189 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
190 else {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
191 ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(llvm::Type::Int8Ty), "tmp");
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
192 }
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
193 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
194 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
195 assert(t == pt);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
196 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
197
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
198 Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n';
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
199
43
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
200 std::vector<llvm::Value*> args;
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
201 args.push_back(ptr);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
202 args.push_back(dim);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
203 args.push_back(val);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
204
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
205 const char* funcname = NULL;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
206
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
207 if (aggrsz) {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
208 funcname = "_d_array_init_mem";
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
209 args.push_back(DtoConstSize_t(aggrsz));
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
210 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
211 else if (isaPointer(t)) {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
212 funcname = "_d_array_init_pointer";
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
213
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
214 const llvm::Type* dstty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
215 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
216 args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb());
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
217
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
218 const llvm::Type* valty = getPtrToType(llvm::Type::Int8Ty);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
219 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
220 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
221 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
222 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
223 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
224 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
225 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
226 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
227 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
228 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
229 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
230 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
231 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
232 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
233 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
234 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
235 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
236 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
237 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
238 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
239 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
240 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
241 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
242 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
243 else {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
244 Logger::cout() << *ptr->getType() << " = " << *val->getType() << '\n';
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
245 assert(0);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
246 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
247
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
248 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
249 assert(fn);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
250 Logger::cout() << "calling array init function: " << *fn <<'\n';
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
251 llvm::CallInst* call = llvm::CallInst::Create(fn, args.begin(), args.end(), "", gIR->scopebb());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
252 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
253 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
254
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
255 //////////////////////////////////////////////////////////////////////////////////////////
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
256
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
257 void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
258 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
259 Logger::println("DtoSetArray");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
260 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
261
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
262 Logger::cout() << "arr = " << *arr << '\n';
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
263 Logger::cout() << "dim = " << *dim << '\n';
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
264 Logger::cout() << "ptr = " << *ptr << '\n';
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
265
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
266 const llvm::StructType* st = isaStruct(arr->getType()->getContainedType(0));
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
267
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
268 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
269 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
270
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
271 llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb());
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
272 Logger::cout() << "arrdim = " << *arrdim << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
273 new llvm::StoreInst(dim, arrdim, gIR->scopebb());
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
274
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
275 llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb());
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
276 Logger::cout() << "arrptr = " << *arrptr << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
277 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
278 }
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 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
281 llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
282 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
283 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
284 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
285
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
286 Type* arrinittype = DtoDType(arrinit->type);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
287
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
288 Type* t;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
289 integer_t tdim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
290 if (arrinittype->ty == Tsarray) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
291 Logger::println("static array");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
292 TypeSArray* tsa = (TypeSArray*)arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
293 tdim = tsa->dim->toInteger();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
294 t = tsa;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
295 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
296 else if (arrinittype->ty == Tarray) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
297 Logger::println("dynamic array");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
298 t = arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
299 tdim = arrinit->dim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
300 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
301 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
302 assert(0);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
303
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
304 Logger::println("dim = %u", tdim);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
305
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
306 std::vector<llvm::Constant*> inits(tdim, NULL);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
307
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
308 Type* arrnext = arrinittype->next;
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
309 const llvm::Type* elemty = DtoType(arrinittype->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
310
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
311 assert(arrinit->index.dim == arrinit->value.dim);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
312 for (unsigned i=0,j=0; i < tdim; ++i)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
313 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
314 Initializer* init = 0;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
315 Expression* idx;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
316
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
317 if (j < arrinit->index.dim)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
318 idx = (Expression*)arrinit->index.data[j];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
319 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
320 idx = NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
321
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
322 llvm::Constant* v = NULL;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
323
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
324 if (idx)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
325 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
326 Logger::println("%d has idx", i);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
327 // this is pretty weird :/ idx->type turned out NULL for the initializer:
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
328 // const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
329 // in std.c.linux.socket
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
330 if (idx->type) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
331 Logger::println("has idx->type", i);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
332 //integer_t k = idx->toInteger();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
333 //Logger::println("getting value for exp: %s | %s", idx->toChars(), arrnext->toChars());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
334 llvm::Constant* cc = idx->toConstElem(gIR);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
335 Logger::println("value gotten");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
336 assert(cc != NULL);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
337 llvm::ConstantInt* ci = llvm::dyn_cast<llvm::ConstantInt>(cc);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
338 assert(ci != NULL);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
339 uint64_t k = ci->getZExtValue();
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
340 if (i == k)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
341 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
342 init = (Initializer*)arrinit->value.data[j];
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
343 assert(init);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
344 ++j;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
345 }
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
346 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
347 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
348 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
349 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
350 if (j < arrinit->value.dim) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
351 init = (Initializer*)arrinit->value.data[j];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
352 ++j;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
353 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
354 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
355 v = arrnext->defaultInit()->toConstElem(gIR);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
356 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
357
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
358 if (!v)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
359 v = DtoConstInitializer(t->next, init);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
360 assert(v);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
361
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
362 inits[i] = v;
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 174
diff changeset
363 Logger::cout() << "llval: " << *v << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
364 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
365
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 174
diff changeset
366 Logger::println("building constant array");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
367 const llvm::ArrayType* arrty = llvm::ArrayType::get(elemty,tdim);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
368 llvm::Constant* constarr = llvm::ConstantArray::get(arrty, inits);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
369
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
370 if (arrinittype->ty == Tsarray)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
371 return constarr;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
372 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
373 assert(arrinittype->ty == Tarray);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
374
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
375 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrty,true,llvm::GlobalValue::InternalLinkage,constarr,"constarray",gIR->module);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
376 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
377 llvm::Constant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
378 return DtoConstSlice(DtoConstSize_t(tdim),gep);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
379 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
380
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
381 //////////////////////////////////////////////////////////////////////////////////////////
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
382 static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
383 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
384 const llvm::Type* t = e->ptr->getType()->getContainedType(0);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
385 llvm::Value* ret = 0;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
386 if (e->len != 0) {
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
387 // this means it's a real slice
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
388 ret = e->ptr;
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
389
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
390 size_t elembsz = getABITypeSize(ret->getType());
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
391 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
392
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
393 if (isaConstantInt(e->len)) {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
394 sz = llvm::ConstantExpr::getMul(elemsz, isaConstant(e->len));
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
395 }
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
396 else {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
397 sz = llvm::BinaryOperator::createMul(elemsz,e->len,"tmp",gIR->scopebb());
22
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
398 }
a6360e68134a [svn r26] * Fixed templates defining a constant value
lindquist
parents: 21
diff changeset
399 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
400 else if (isaArray(t)) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
401 ret = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
402
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
403 size_t elembsz = getABITypeSize(ret->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
404 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
405
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
406 size_t numelements = isaArray(t)->getNumElements();
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
407 llvm::ConstantInt* nelems = llvm::ConstantInt::get(DtoSize_t(), numelements, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
408
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
409 sz = llvm::ConstantExpr::getMul(elemsz, nelems);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
410 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
411 else if (isaStruct(t)) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
412 ret = DtoGEPi(e->ptr, 0, 1, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
413 ret = new llvm::LoadInst(ret, "tmp", gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
414
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
415 size_t elembsz = getABITypeSize(ret->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
416 llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
417
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
418 llvm::Value* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb());
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
419 len = new llvm::LoadInst(len, "tmp", gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
420 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
421 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
422 else {
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
423 assert(0);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
424 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
425 return ret;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
426 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
427
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
428 void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
429 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
430 Logger::println("ArrayCopySlices");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
431 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
432
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
433 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
434 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
435
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
436 llvm::Value* sz2;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
437 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
438
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
439 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
440 std::vector<llvm::Value*> llargs;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
441 llargs.resize(4);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
442 llargs[0] = dstarr;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
443 llargs[1] = srcarr;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
444 llargs[2] = sz1;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
445 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
446
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
447 llvm::CallInst::Create(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
448 }
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
449
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
450 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
451 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
452 Logger::println("ArrayCopyToSlice");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
453 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
454
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
455 llvm::Value* sz1;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
456 llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
457 llvm::Value* srcarr = new llvm::BitCastInst(DtoArrayPtr(src),arrty,"tmp",gIR->scopebb());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
458
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
459 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
460 std::vector<llvm::Value*> llargs;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
461 llargs.resize(4);
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
462 llargs[0] = dstarr;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
463 llargs[1] = srcarr;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
464 llargs[2] = sz1;
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
465 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
466
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
467 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
468 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
469
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
470 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
471 void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src)
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
472 {
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 136
diff changeset
473 Logger::cout() << "static array copy: " << *dst << " from " << *src << '\n';
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
474 assert(dst->getType() == src->getType());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
475 size_t arrsz = getABITypeSize(dst->getType()->getContainedType(0));
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
476 llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false);
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
477
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
478 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
479 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
480 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
481
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
482 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
483 std::vector<llvm::Value*> llargs;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
484 llargs.resize(4);
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
485 llargs[0] = dstarr;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
486 llargs[1] = srcarr;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
487 llargs[2] = n;
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
488 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
489
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
490 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
491 }
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
492
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
493 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
494 llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
495 {
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
496 std::vector<const llvm::Type*> types;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
497 types.push_back(dim->getType());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
498 types.push_back(ptr->getType());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
499 const llvm::StructType* type = llvm::StructType::get(types);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
500 std::vector<llvm::Constant*> values;
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
501 values.push_back(dim);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
502 values.push_back(ptr);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
503 return llvm::ConstantStruct::get(type,values);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
504 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
505
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
506 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
507 DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
508 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
509 Logger::println("DtoNewDynArray : %s", arrayType->toChars());
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
510 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
511
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
512 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
513 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" );
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
514
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
515 llvm::SmallVector<llvm::Value*,2> args;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
516 args.push_back(DtoTypeInfoOf(arrayType));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
517 assert(DtoType(dim->getType()) == DtoSize_t());
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
518 args.push_back(dim->getRVal());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
519
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
520 llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
521 const llvm::Type* dstType = DtoType(arrayType)->getContainedType(1);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
522 if (newptr->getType() != dstType)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
523 newptr = DtoBitCast(newptr, dstType, ".gc_mem");
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
524
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
525 Logger::cout() << "final ptr = " << *newptr << '\n';
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
526
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
527 #if 0
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
528 if (defaultInit) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
529 DValue* e = dty->defaultInit()->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
530 DtoArrayInit(newptr,dim,e->getRVal());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
531 }
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
532 #endif
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
533
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
534 return new DSliceValue(arrayType, args[1], newptr);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
535 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
536
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
537 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
538 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
539 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
540 Logger::println("DtoResizeDynArray : %s", arrayType->toChars());
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
541 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
542
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
543 assert(array);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
544 assert(newdim);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
545 assert(arrayType);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
546 assert(arrayType->toBasetype()->ty == Tarray);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
547
211
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
548 // decide on what runtime function to call based on whether the type is zero initialized
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
549 bool zeroInit = arrayType->toBasetype()->next->isZeroInit();
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
550
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
551 // call runtime
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
552 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_arraysetlengthT" : "_d_arraysetlengthiT" );
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
553
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
554 llvm::SmallVector<llvm::Value*,4> args;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
555 args.push_back(DtoTypeInfoOf(arrayType));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
556 args.push_back(newdim->getRVal());
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
557 args.push_back(DtoArrayLen(array));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
558 llvm::Value* arrPtr = DtoArrayPtr(array);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
559 Logger::cout() << "arrPtr = " << *arrPtr << '\n';
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
560 args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp"));
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
561
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
562 llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
563 if (newptr->getType() != arrPtr->getType())
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
564 newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem");
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
565
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
566 return new DSliceValue(arrayType, newdim->getRVal(), newptr);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
567 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
568
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
569 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
570 DSliceValue* DtoCatAssignElement(DValue* array, Expression* exp)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
571 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
572 Logger::println("DtoCatAssignElement");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
573 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
574
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
575 assert(array);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
576
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
577 llvm::Value* idx = DtoArrayLen(array);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
578 llvm::Value* one = DtoConstSize_t(1);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
579 llvm::Value* len = gIR->ir->CreateAdd(idx,one,"tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
580
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
581 DValue* newdim = new DImValue(Type::tsize_t, len);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
582 DSliceValue* slice = DtoResizeDynArray(array->getType(), array, newdim);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
583
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
584 llvm::Value* ptr = slice->ptr;
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
585 ptr = llvm::GetElementPtrInst::Create(ptr, idx, "tmp", gIR->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
586
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
587 DValue* dptr = new DVarValue(exp->type, ptr, true);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
588
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
589 gIR->exps.push_back(IRExp(0,exp,dptr));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
590 DValue* e = exp->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
591 gIR->exps.pop_back();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
592
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
593 if (!e->inPlace())
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
594 DtoAssign(dptr, e);
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
595
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
596 return slice;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
597 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
598
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
599 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
600 DSliceValue* DtoCatAssignArray(DValue* arr, Expression* exp)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
601 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
602 Logger::println("DtoCatAssignArray");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
603 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
604
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
605 DValue* e = exp->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
606
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
607 llvm::Value *len1, *len2, *src1, *src2, *res;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
608
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
609 len1 = DtoArrayLen(arr);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
610 len2 = DtoArrayLen(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
611 res = gIR->ir->CreateAdd(len1,len2,"tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
612
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
613 DValue* newdim = new DImValue(Type::tsize_t, res);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
614 DSliceValue* slice = DtoResizeDynArray(arr->getType(), arr, newdim);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
615
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
616 src1 = slice->ptr;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
617 src2 = DtoArrayPtr(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
618
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
619 // advance ptr
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
620 src1 = gIR->ir->CreateGEP(src1,len1,"tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
621
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
622 // memcpy
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
623 llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0)));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
624 llvm::Value* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
625 DtoMemCpy(src1,src2,bytelen);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
626
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
627 return slice;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
628 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
629
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
630 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
631 DSliceValue* DtoCatArrays(Type* type, Expression* exp1, Expression* exp2)
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
632 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
633 Logger::println("DtoCatArrays");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
634 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
635
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
636 Type* t1 = DtoDType(exp1->type);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
637 Type* t2 = DtoDType(exp2->type);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
638
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
639 assert(t1->ty == Tarray);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
640 assert(t1->ty == t2->ty);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
641
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
642 DValue* e1 = exp1->toElem(gIR);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
643 DValue* e2 = exp2->toElem(gIR);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
644
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
645 llvm::Value *len1, *len2, *src1, *src2, *res;
174
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
646
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
647 len1 = DtoArrayLen(e1);
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
648 len2 = DtoArrayLen(e2);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
649 res = gIR->ir->CreateAdd(len1,len2,"tmp");
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
650
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
651 DValue* lenval = new DImValue(Type::tsize_t, res);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
652 DSliceValue* slice = DtoNewDynArray(type, lenval, false);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
653 llvm::Value* mem = slice->ptr;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
654
174
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
655 src1 = DtoArrayPtr(e1);
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
656 src2 = DtoArrayPtr(e2);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
657
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
658 // first memcpy
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
659 llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
660 llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
661 DtoMemCpy(mem,src1,bytelen);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
662
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
663 // second memcpy
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
664 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
665 bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
666 DtoMemCpy(mem,src2,bytelen);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
667
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
668 return slice;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
669 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
670
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
671 //////////////////////////////////////////////////////////////////////////////////////////
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
672 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
673 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
674 Logger::println("DtoCatArrayElement");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
675 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
676
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
677 Type* t1 = DtoDType(exp1->type);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
678 Type* t2 = DtoDType(exp2->type);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
679
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
680 DValue* e1 = exp1->toElem(gIR);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
681 DValue* e2 = exp2->toElem(gIR);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
682
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
683 llvm::Value *len1, *src1, *res;
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
684
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
685 // handle prefix case, eg. int~int[]
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
686 if (t2->next && t1 == DtoDType(t2->next))
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
687 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
688 len1 = DtoArrayLen(e2);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
689 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
690
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
691 DValue* lenval = new DImValue(Type::tsize_t, res);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
692 DSliceValue* slice = DtoNewDynArray(type, lenval, false);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
693 llvm::Value* mem = slice->ptr;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
694
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
695 DVarValue* memval = new DVarValue(e1->getType(), mem, true);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
696 DtoAssign(memval, e1);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
697
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
698 src1 = DtoArrayPtr(e2);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
699
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
700 mem = gIR->ir->CreateGEP(mem,DtoConstSize_t(1),"tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
701
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
702 llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
703 llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
704 DtoMemCpy(mem,src1,bytelen);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
705
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
706
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
707 return slice;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
708 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
709 // handle suffix case, eg. int[]~int
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
710 else
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
711 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
712 len1 = DtoArrayLen(e1);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
713 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp");
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
714
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
715 DValue* lenval = new DImValue(Type::tsize_t, res);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
716 DSliceValue* slice = DtoNewDynArray(type, lenval, false);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
717 llvm::Value* mem = slice->ptr;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
718
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
719 src1 = DtoArrayPtr(e1);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
720
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
721 llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
722 llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
723 DtoMemCpy(mem,src1,bytelen);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
724
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
725 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
726 DVarValue* memval = new DVarValue(e2->getType(), mem, true);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
727 DtoAssign(memval, e2);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
728
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
729 return slice;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
730 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
731 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
732
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
733 //////////////////////////////////////////////////////////////////////////////////////////
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
734 // helper for eq and cmp
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
735 static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
736 {
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
737 Logger::println("comparing arrays");
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
738 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
739 assert(fn);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
740
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
741 llvm::Value* lmem;
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
742 llvm::Value* rmem;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
743
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
744 // cast static arrays to dynamic ones, this turns them into DSliceValues
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
745 Logger::println("casting to dynamic arrays");
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
746 Type* l_ty = DtoDType(l->getType());
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
747 Type* r_ty = DtoDType(r->getType());
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
748 assert(l_ty->next == r_ty->next);
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
749 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
750 Type* a_ty = new Type(Tarray, l_ty->next);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
751 if (l_ty->ty == Tsarray)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
752 l = DtoCastArray(l, a_ty);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
753 if (r_ty->ty == Tsarray)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
754 r = DtoCastArray(r, a_ty);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
755 }
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
756
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
757 Logger::println("giving storage");
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
758
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
759 // we need to give slices storage
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
760 if (l->isSlice()) {
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
761 lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
762 DtoSetArray(lmem, DtoArrayLen(l), DtoArrayPtr(l));
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
763 }
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
764 // also null
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
765 else if (l->isNull())
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
766 {
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
767 lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
768 DtoSetArray(lmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(l->getType()->next->pointerTo())));
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
769 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
770 else
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
771 lmem = l->getRVal();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
772
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
773 // and for the rvalue ...
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
774 // we need to give slices storage
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
775 if (r->isSlice()) {
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
776 rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
777 DtoSetArray(rmem, DtoArrayLen(r), DtoArrayPtr(r));
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
778 }
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
779 // also null
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
780 else if (r->isNull())
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
781 {
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
782 rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
783 DtoSetArray(rmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(r->getType()->next->pointerTo())));
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
784 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
785 else
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
786 rmem = r->getRVal();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
787
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
788 const llvm::Type* pt = fn->getFunctionType()->getParamType(0);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
789
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
790 std::vector<llvm::Value*> args;
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
791 Logger::cout() << "bitcasting to " << *pt << '\n';
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
792 Logger::cout() << *lmem << '\n';
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
793 Logger::cout() << *rmem << '\n';
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
794 args.push_back(DtoBitCast(lmem,pt));
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
795 args.push_back(DtoBitCast(rmem,pt));
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
796
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
797 // pass element typeinfo ?
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
798 if (useti) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
799 TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration();
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
800 DtoForceConstInitDsymbol(ti);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
801 Logger::cout() << "typeinfo decl: " << *ti->ir.getIrValue() << '\n';
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
802
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
803 pt = fn->getFunctionType()->getParamType(2);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
804 args.push_back(DtoBitCast(ti->ir.getIrValue(), pt));
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
805 }
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
806
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
807 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
808 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
809
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
810 //////////////////////////////////////////////////////////////////////////////////////////
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
811 llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
812 {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
813 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq");
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
814 assert(fn);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
815
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
816 llvm::Value* res = DtoArrayEqCmp_impl("_adEq", l, r, true);
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
817 if (op == TOKnotequal)
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
818 res = gIR->ir->CreateNot(res, "tmp");
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
819
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
820 return res;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
821 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
822
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
823 //////////////////////////////////////////////////////////////////////////////////////////
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
824 llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
825 {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
826 llvm::Value* res = 0;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
827
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
828 llvm::ICmpInst::Predicate cmpop;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
829 bool skip = false;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
830
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
831 switch(op)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
832 {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
833 case TOKlt:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
834 case TOKul:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
835 cmpop = llvm::ICmpInst::ICMP_SLT;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
836 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
837 case TOKle:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
838 case TOKule:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
839 cmpop = llvm::ICmpInst::ICMP_SLE;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
840 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
841 case TOKgt:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
842 case TOKug:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
843 cmpop = llvm::ICmpInst::ICMP_SGT;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
844 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
845 case TOKge:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
846 case TOKuge:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
847 cmpop = llvm::ICmpInst::ICMP_SGE;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
848 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
849 case TOKue:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
850 cmpop = llvm::ICmpInst::ICMP_EQ;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
851 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
852 case TOKlg:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
853 cmpop = llvm::ICmpInst::ICMP_NE;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
854 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
855 case TOKleg:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
856 skip = true;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
857 res = llvm::ConstantInt::getTrue();
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
858 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
859 case TOKunord:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
860 skip = true;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
861 res = llvm::ConstantInt::getFalse();
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
862 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
863
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
864 default:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
865 assert(0);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
866 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
867
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
868 if (!skip)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
869 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
870 Type* t = DtoDType(DtoDType(l->getType())->next);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
871 if (t->ty == Tchar)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
872 res = DtoArrayEqCmp_impl("_adCmpChar", l, r, false);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
873 else
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
874 res = DtoArrayEqCmp_impl("_adCmp", l, r, true);
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
875 res = new llvm::ICmpInst(cmpop, res, DtoConstInt(0), "tmp", gIR->scopebb());
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
876 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
877
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
878 assert(res);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
879 return res;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
880 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
881
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
882 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
883 llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty)
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
884 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
885 Logger::println("DtoArrayCastLength");
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
886 LOG_SCOPE;
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
887
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
888 assert(len);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
889 assert(elemty);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
890 assert(newelemty);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
891
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
892 size_t esz = getABITypeSize(elemty);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
893 size_t nsz = getABITypeSize(newelemty);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
894 if (esz == nsz)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
895 return len;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
896
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
897 std::vector<llvm::Value*> args;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
898 args.push_back(len);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
899 args.push_back(llvm::ConstantInt::get(DtoSize_t(), esz, false));
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
900 args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false));
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
901
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
902 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
903 return llvm::CallInst::Create(fn, args.begin(), args.end(), "tmp", gIR->scopebb());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
904 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
905
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
906 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
907 llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
908 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
909 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
910
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
911 if (r == NULL) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
912 llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 157
diff changeset
913 llvm::Value* rl = llvm::Constant::getNullValue(ll->getType());//DtoConstSize_t(0);
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
914 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
915
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
916 llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
917 const llvm::PointerType* pty = isaPointer(lp->getType());
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
918 llvm::Value* rp = llvm::ConstantPointerNull::get(pty);
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
919 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
920
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
921 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
922 return b;
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
923 }
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
924 else {
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
925 assert(l->getType() == r->getType());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
926
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
927 llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
928 llvm::Value* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
929 llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
930
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
931 llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp");
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
932 llvm::Value* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
933 llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
934
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
935 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
936 return b;
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
937 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
938 }
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
939
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
940 //////////////////////////////////////////////////////////////////////////////////////////
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
941 llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c)
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
942 {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
943 const llvm::ArrayType* at = isaArray(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
944 assert(at);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
945
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
946 if (isaArray(at->getElementType()))
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
947 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 69
diff changeset
948 c = DtoConstStaticArray(at->getElementType(), c);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
949 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
950 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
951 assert(at->getElementType() == c->getType());
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
952 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
953 std::vector<llvm::Constant*> initvals;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
954 initvals.resize(at->getNumElements(), c);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
955 return llvm::ConstantArray::get(at, initvals);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
956 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
957
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
958 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
959 llvm::Value* DtoArrayLen(DValue* v)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
960 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
961 Logger::println("DtoArrayLen");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
962 LOG_SCOPE;
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
963
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
964 Type* t = DtoDType(v->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
965 if (t->ty == Tarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
966 if (DSliceValue* s = v->isSlice()) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
967 if (s->len) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
968 return s->len;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
969 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
970 const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0));
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
971 if (arrTy)
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
972 return DtoConstSize_t(arrTy->getNumElements());
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
973 else
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
974 return DtoLoad(DtoGEPi(s->ptr, 0,0, "tmp"));
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
975 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
976 return DtoLoad(DtoGEPi(v->getRVal(), 0,0, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
977 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
978 else if (t->ty == Tsarray) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
979 assert(!v->isSlice());
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
980 llvm::Value* rv = v->getRVal();
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
981 Logger::cout() << "casting: " << *rv << '\n';
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
982 const llvm::ArrayType* t = isaArray(rv->getType()->getContainedType(0));
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
983 return DtoConstSize_t(t->getNumElements());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
984 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
985 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
986 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
987 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
988
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
989 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
990 llvm::Value* DtoArrayPtr(DValue* v)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
991 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
992 Logger::println("DtoArrayPtr");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
993 LOG_SCOPE;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 193
diff changeset
994
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
995 Type* t = DtoDType(v->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
996 if (t->ty == Tarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
997 if (DSliceValue* s = v->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
998 if (s->len) return s->ptr;
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
999 const llvm::Type* t = s->ptr->getType()->getContainedType(0);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
1000 Logger::cout() << "ptr of full slice: " << *s->ptr << '\n';
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
1001 const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0));
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
1002 if (arrTy)
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
1003 return DtoGEPi(s->ptr, 0,0, "tmp");
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
1004 else
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 118
diff changeset
1005 return DtoLoad(DtoGEPi(s->ptr, 0,1, "tmp"));
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1006 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1007 return DtoLoad(DtoGEPi(v->getRVal(), 0,1, "tmp"));
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1008 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1009 else if (t->ty == Tsarray) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1010 return DtoGEPi(v->getRVal(), 0,0, "tmp");
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1011 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1012 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1013 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1014 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
1015
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1016 //////////////////////////////////////////////////////////////////////////////////////////
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1017 DValue* DtoCastArray(DValue* u, Type* to)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1018 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
1019 Logger::println("DtoCastArray");
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
1020 LOG_SCOPE;
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
1021
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1022 const llvm::Type* tolltype = DtoType(to);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1023
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1024 Type* totype = DtoDType(to);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1025 Type* fromtype = DtoDType(u->getType());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1026 assert(fromtype->ty == Tarray || fromtype->ty == Tsarray);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1027
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1028 llvm::Value* rval;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1029 llvm::Value* rval2;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1030 bool isslice = false;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1031
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1032 Logger::cout() << "from array or sarray" << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1033 if (totype->ty == Tpointer) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1034 Logger::cout() << "to pointer" << '\n';
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
1035 rval = DtoArrayPtr(u);
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 182
diff changeset
1036 if (rval->getType() != tolltype)
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 182
diff changeset
1037 rval = gIR->ir->CreateBitCast(rval, tolltype, "tmp");
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1038 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1039 else if (totype->ty == Tarray) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1040 Logger::cout() << "to array" << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1041 const llvm::Type* ptrty = DtoType(totype->next);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1042 if (ptrty == llvm::Type::VoidTy)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1043 ptrty = llvm::Type::Int8Ty;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1044 ptrty = getPtrToType(ptrty);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1045
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1046 const llvm::Type* ety = DtoType(fromtype->next);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1047 if (ety == llvm::Type::VoidTy)
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1048 ety = llvm::Type::Int8Ty;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1049
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1050 if (DSliceValue* usl = u->isSlice()) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1051 Logger::println("from slice");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1052 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1053 rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1054 if (fromtype->next->size() == totype->next->size())
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
1055 rval2 = DtoArrayLen(usl);
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1056 else
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
1057 rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0));
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1058 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1059 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1060 llvm::Value* uval = u->getRVal();
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1061 if (fromtype->ty == Tsarray) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1062 Logger::cout() << "uvalTy = " << *uval->getType() << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1063 assert(isaPointer(uval->getType()));
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1064 const llvm::ArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1065 rval2 = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1066 rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1067 rval = new llvm::BitCastInst(uval, ptrty, "tmp", gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1068 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1069 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1070 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1071 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1072 rval2 = DtoGEP(uval,zero,zero,"tmp",gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1073 rval2 = new llvm::LoadInst(rval2, "tmp", gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1074 rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1075
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1076 rval = DtoGEP(uval,zero,one,"tmp",gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1077 rval = new llvm::LoadInst(rval, "tmp", gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1078 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1079 rval = new llvm::BitCastInst(rval, ptrty, "tmp", gIR->scopebb());
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1080 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1081 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1082 isslice = true;
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1083 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1084 else if (totype->ty == Tsarray) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1085 Logger::cout() << "to sarray" << '\n';
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1086 assert(0);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1087 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1088 else {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1089 assert(0);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1090 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1091
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1092 if (isslice) {
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1093 Logger::println("isslice");
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1094 return new DSliceValue(to, rval2, rval);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1095 }
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1096
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1097 return new DImValue(to, rval);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1098 }