annotate gen/arrays.cpp @ 610:1b62222581fb

Change bool type to i8
author Christian Kamm <kamm incasoftware de>
date Sat, 20 Sep 2008 10:13:15 +0200
parents 48f079b4fe0f
children 83ca663ecc20
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"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
11 #include "gen/llvmhelpers.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
12 #include "gen/arrays.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
13 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
14 #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
15 #include "gen/dvalue.h"
4
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 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
18
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
19 const LLStructType* DtoArrayType(Type* arrayTy)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
20 {
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 217
diff changeset
21 assert(arrayTy->next);
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 217
diff changeset
22 const LLType* elemty = DtoType(arrayTy->next);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
23 if (elemty == LLType::VoidTy)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
24 elemty = LLType::Int8Ty;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
25 return LLStructType::get(DtoSize_t(), getPtrToType(elemty), 0);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
26 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
27
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
28 const LLStructType* DtoArrayType(const LLType* t)
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 217
diff changeset
29 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
30 return LLStructType::get(DtoSize_t(), getPtrToType(t), 0);
234
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 217
diff changeset
31 }
9760f54af0b7 [svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents: 217
diff changeset
32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
33 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
34
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
35 const LLArrayType* DtoStaticArrayType(Type* t)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
36 {
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
37 t = t->toBasetype();
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
38 assert(t->ty == Tsarray);
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
39 TypeSArray* tsa = (TypeSArray*)t;
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
40 Type* tnext = tsa->next;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
41
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
42 const LLType* elemty = DtoType(tnext);
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
43 if (elemty == LLType::VoidTy)
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
44 elemty = LLType::Int8Ty;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
45
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
46 return LLArrayType::get(elemty, tsa->dim->toUInteger());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
47 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
48
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
49 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
50
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
51 void DtoSetArrayToNull(LLValue* v)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
52 {
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
53 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
54 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
55
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
56 LLValue* len = DtoGEPi(v,0,0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
57 LLValue* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
58 DtoStore(zerolen, len);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
59
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
60 LLValue* ptr = DtoGEPi(v,0,1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
61 const LLPointerType* pty = isaPointer(ptr->getType()->getContainedType(0));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
62 LLValue* nullptr = llvm::ConstantPointerNull::get(pty);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
63 DtoStore(nullptr, ptr);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
64 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
65
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
66 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
67
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
68 void DtoArrayAssign(LLValue* dst, LLValue* src)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
69 {
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
70 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
71 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
72
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
73 assert(gIR);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
74 if (dst->getType() == src->getType())
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
75 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
76 LLValue* ptr = DtoGEPi(src,0,0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
77 LLValue* val = DtoLoad(ptr);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
78 ptr = DtoGEPi(dst,0,0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
79 DtoStore(val, ptr);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
80
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
81 ptr = DtoGEPi(src,0,1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
82 val = DtoLoad(ptr);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
83 ptr = DtoGEPi(dst,0,1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
84 DtoStore(val, ptr);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
85 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
86 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
87 {
118
d580b95cce2b [svn r122] Fixed temporary delegates can now alloca their own storage.
lindquist
parents: 116
diff changeset
88 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
89 const LLArrayType* arrty = isaArray(src->getType()->getContainedType(0));
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
90 if (!arrty)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
91 {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
92 std::cout << "invalid: " << *src << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
93 assert(0);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
94 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
95 const LLType* dstty = getPtrToType(arrty->getElementType());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
96
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
97 LLValue* dstlen = DtoGEPi(dst,0,0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
98 LLValue* srclen = DtoConstSize_t(arrty->getNumElements());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
99 DtoStore(srclen, dstlen);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
100
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
101 LLValue* dstptr = DtoGEPi(dst,0,1);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
102 LLValue* srcptr = DtoBitCast(src, dstty);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
103 DtoStore(srcptr, dstptr);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
104 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
105 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
106
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
107 //////////////////////////////////////////////////////////////////////////////////////////
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
108
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 398
diff changeset
109 void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
110 {
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
111 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
112 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
113
295
895e1b50cf2a [svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents: 293
diff changeset
114 LLValue* dim = DtoArrayLen(array);
895e1b50cf2a [svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents: 293
diff changeset
115 LLValue* ptr = DtoArrayPtr(array);
350
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
116 LLValue* val;
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
117
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
118 // give slices and complex values storage (and thus an address to pass)
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 507
diff changeset
119 if (value->isSlice())
350
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
120 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
121 val = DtoAlloca(DtoType(value->getType()), ".tmpparam");
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 507
diff changeset
122 DVarValue lval(value->getType(), val);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 398
diff changeset
123 DtoAssign(loc, &lval, value);
350
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
124 }
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
125 else
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
126 {
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
127 val = value->getRVal();
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
128 }
b85cf5faccfc [svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents: 340
diff changeset
129 assert(val);
295
895e1b50cf2a [svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents: 293
diff changeset
130
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
131 // prepare runtime call
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
132 LLSmallVector<LLValue*, 4> args;
43
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
133 args.push_back(ptr);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
134 args.push_back(dim);
eb7bf7b7972e [svn r47] fixed a problem with gdc 4.1
lindquist
parents: 40
diff changeset
135 args.push_back(val);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
136
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
137 // determine the right runtime function to call
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
138 const char* funcname = NULL;
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
139 Type* arrayelemty = array->getType()->nextOf()->toBasetype();
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
140 Type* valuety = value->getType()->toBasetype();
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
141
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
142 // lets first optimize all zero initializations down to a memset.
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
143 // this simplifies codegen later on as llvm null's have no address!
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
144 if (isaConstant(val) && isaConstant(val)->isNullValue())
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
145 {
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
146 size_t X = getABITypeSize(val->getType());
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
147 LLValue* nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(X), ".nbytes");
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
148 DtoMemSetZero(ptr, nbytes);
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
149 return;
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
150 }
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
151
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
152 // if not a zero initializer, call the appropriate runtime function!
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
153 switch (arrayelemty->ty)
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
154 {
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
155 case Tbool:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
156 case Tvoid:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
157 case Tchar:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
158 case Tint8:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
159 case Tuns8:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
160 funcname = "_d_array_init_i8";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
161 break;
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
162
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
163 case Twchar:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
164 case Tint16:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
165 case Tuns16:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
166 funcname = "_d_array_init_i16";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
167 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
168
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
169 case Tdchar:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
170 case Tint32:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
171 case Tuns32:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
172 funcname = "_d_array_init_i32";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
173 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
174
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
175 case Tint64:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
176 case Tuns64:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
177 funcname = "_d_array_init_i64";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
178 break;
338
0c90d816394f [svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents: 334
diff changeset
179
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
180 case Tfloat32:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
181 case Timaginary32:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
182 funcname = "_d_array_init_float";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
183 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
184
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
185 case Tfloat64:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
186 case Timaginary64:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
187 funcname = "_d_array_init_double";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
188 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
189
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
190 case Tfloat80:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
191 case Timaginary80:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
192 funcname = "_d_array_init_real";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
193 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
194
586
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
195 case Tcomplex32:
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
196 funcname = "_d_array_init_cfloat";
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
197 break;
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
198
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
199 case Tcomplex64:
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
200 funcname = "_d_array_init_cdouble";
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
201 break;
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
202
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
203 case Tcomplex80:
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
204 funcname = "_d_array_init_creal";
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
205 break;
192b82878b78 Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
206
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
207 case Tpointer:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
208 case Tclass:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
209 funcname = "_d_array_init_pointer";
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
210 args[0] = DtoBitCast(args[0], getPtrToType(getVoidPtrType()));
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
211 args[2] = DtoBitCast(args[2], getVoidPtrType());
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
212 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
213
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
214 // this currently acts as a kind of fallback for all the bastards...
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
215 // FIXME: this is probably too slow.
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
216 case Tstruct:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
217 case Tdelegate:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
218 case Tarray:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
219 case Tsarray:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
220 funcname = "_d_array_init_mem";
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
221 assert(arrayelemty == valuety && "ArrayInit doesn't work on elem-initialized static arrays");
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
222 args[0] = DtoBitCast(args[0], getVoidPtrType());
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
223 args[2] = DtoBitCast(args[2], getVoidPtrType());
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
224 args.push_back(DtoConstSize_t(getABITypeSize(DtoType(arrayelemty))));
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
225 break;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
226
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
227 default:
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
228 error("unhandled array init: %s = %s", array->getType()->toChars(), value->getType()->toChars());
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 338
diff changeset
229 assert(0 && "unhandled array init");
37
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
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
232 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, funcname);
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
233 assert(fn);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
234 Logger::cout() << "calling array init function: " << *fn <<'\n';
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
235 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
236 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
237 }
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
238
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
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
241 void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
242 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
243 Logger::println("SetArray");
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
244 assert(isaStruct(arr->getType()->getContainedType(0)));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
245 DtoStore(dim, DtoGEPi(arr,0,0));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
246 DtoStore(ptr, DtoGEPi(arr,0,1));
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
247 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
248
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
249 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
250 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
251 {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
252 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
253 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
254
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
255 Type* arrinittype = arrinit->type->toBasetype();
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
256
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
257 Type* t;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
258 integer_t tdim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
259 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
260 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
261 TypeSArray* tsa = (TypeSArray*)arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
262 tdim = tsa->dim->toInteger();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
263 t = tsa;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
264 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
265 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
266 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
267 t = arrinittype;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
268 tdim = arrinit->dim;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
269 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
270 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
271 assert(0);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
272
400
e6e972c5cc17 Should only error if array initializer is too long. Too short is ok.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
273 if(arrinit->dim > tdim)
e6e972c5cc17 Should only error if array initializer is too long. Too short is ok.
Christian Kamm <kamm incasoftware de>
parents: 399
diff changeset
274 error(arrinit->loc, "array initializer for %s is too long (%d)", arrinit->type->toChars(), arrinit->dim);
398
811f82dfddbd Add error if array initializer has incorrect length.
Christian Kamm <kamm incasoftware de>
parents: 365
diff changeset
275
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
276 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
277
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
278 std::vector<LLConstant*> inits(tdim, NULL);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
279
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
280 Type* arrnext = arrinittype->next;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
281 const LLType* elemty = DtoType(arrinittype->next);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
282
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
283 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
284 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
285 {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
286 Initializer* init = 0;
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
287 Expression* idx;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
288
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
289 if (j < arrinit->index.dim)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
290 idx = (Expression*)arrinit->index.data[j];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
291 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
292 idx = NULL;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
293
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
294 LLConstant* v = NULL;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
295
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
296 if (idx)
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
297 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
298 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
299 // 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
300 // 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
301 // 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
302 if (idx->type) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
303 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
304 //integer_t k = idx->toInteger();
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
305 //Logger::println("getting value for exp: %s | %s", idx->toChars(), arrnext->toChars());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
306 LLConstant* cc = idx->toConstElem(gIR);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
307 Logger::println("value gotten");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
308 assert(cc != NULL);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
309 LLConstantInt* ci = llvm::dyn_cast<LLConstantInt>(cc);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
310 assert(ci != NULL);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
311 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
312 if (i == k)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
313 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
314 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
315 assert(init);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
316 ++j;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
317 }
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
318 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
319 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
320 else
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
321 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
322 if (j < arrinit->value.dim) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
323 init = (Initializer*)arrinit->value.data[j];
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
324 ++j;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
325 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
326 else
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
327 v = arrnext->defaultInit()->toConstElem(gIR);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
328 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
329
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
330 if (!v)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
331 v = DtoConstInitializer(t->next, init);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
332 assert(v);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
333
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
334 inits[i] = v;
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 174
diff changeset
335 Logger::cout() << "llval: " << *v << '\n';
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
336 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
337
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 174
diff changeset
338 Logger::println("building constant array");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
339 const LLArrayType* arrty = LLArrayType::get(elemty,tdim);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
340 LLConstant* constarr = LLConstantArray::get(arrty, inits);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
341
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
342 if (arrinittype->ty == Tsarray)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
343 return constarr;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
344 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
345 assert(arrinittype->ty == Tarray);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
346
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 593
diff changeset
347 LLGlobalVariable* gvar = new LLGlobalVariable(arrty,true,LLGlobalValue::InternalLinkage,constarr,".constarray",gIR->module);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
348 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
349 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
350 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
351 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
352
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
353 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
354 static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
355 {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
356 assert(e->len != 0);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
357 const LLType* t = e->ptr->getType()->getContainedType(0);
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
358 sz = gIR->ir->CreateMul(DtoConstSize_t(getABITypeSize(t)), e->len, "tmp");
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
359 return e->ptr;
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
360 }
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
361
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
362 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
363 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
364 Logger::println("ArrayCopySlices");
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
365
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
366 LLValue *sz1,*sz2;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
367 LLValue* dstarr = get_slice_ptr(dst,sz1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
368 LLValue* srcarr = get_slice_ptr(src,sz2);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
369
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
370 DtoMemCpy(dstarr, srcarr, sz1);
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff changeset
371 }
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
372
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
373 void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
374 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
375 Logger::println("ArrayCopyToSlice");
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
376
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
377 LLValue* sz1;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
378 LLValue* dstarr = get_slice_ptr(dst,sz1);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
379 LLValue* srcarr = DtoArrayPtr(src);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
380
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
381 DtoMemCpy(dstarr, srcarr, sz1);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
382 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 102
diff changeset
383
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
384 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
385 void DtoStaticArrayCopy(LLValue* dst, LLValue* src)
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
386 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
387 Logger::println("StaticArrayCopy");
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
388
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
389 size_t n = getABITypeSize(dst->getType()->getContainedType(0));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
390 DtoMemCpy(dst, src, DtoConstSize_t(n));
48
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
391 }
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
392
4d171915a77b [svn r52] fixed static arrays in struct literals
lindquist
parents: 43
diff changeset
393 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
394 LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr)
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
395 {
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
396 LLConstant* values[2] = { dim, ptr };
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
397 return llvm::ConstantStruct::get(values, 2);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 11
diff changeset
398 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
399
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
400 //////////////////////////////////////////////////////////////////////////////////////////
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 586
diff changeset
401 DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool defaultInit)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
402 {
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
403 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
404 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
405
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
406 // typeinfo arg
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
407 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType);
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
408
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
409 // dim arg
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
410 assert(DtoType(dim->getType()) == DtoSize_t());
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
411 LLValue* arrayLen = dim->getRVal();
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
412
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
413 // get runtime function
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
414 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
415 const char* fnname = defaultInit ? (zeroInit ? "_d_newarrayT" : "_d_newarrayiT") : "_d_newarrayvT";
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
416 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
417
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
418 // call allocator
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
419 LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem")->get();
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
420
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
421 // cast to wanted type
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
422 const LLType* dstType = DtoType(arrayType)->getContainedType(1);
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
423 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
424 newptr = DtoBitCast(newptr, dstType, ".gc_mem");
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
425
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
426 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
427
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
428 return new DSliceValue(arrayType, arrayLen, newptr);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
429 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
430
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
431 //////////////////////////////////////////////////////////////////////////////////////////
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 586
diff changeset
432 DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims, bool defaultInit)
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
433 {
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
434 Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
435 LOG_SCOPE;
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
436
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
437 // typeinfo arg
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
438 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType);
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
439
293
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
440 // get value type
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
441 Type* vtype = arrayType->toBasetype();
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
442 for (size_t i=0; i<ndims; ++i)
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
443 vtype = vtype->nextOf();
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
444
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
445 // get runtime function
293
ebfa488f4abc [svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents: 291
diff changeset
446 bool zeroInit = vtype->isZeroInit();
593
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
447 const char* fnname = defaultInit ? (zeroInit ? "_d_newarraymT" : "_d_newarraymiT") : "_d_newarraymvT";
7042d912767e Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
448 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
449
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
450 // build dims
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
451 LLValue* dimsArg = DtoAlloca(DtoSize_t(), DtoConstUint(ndims), ".newdims");
287
00eb2c967c3a [svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents: 286
diff changeset
452 LLValue* firstDim = NULL;
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
453 for (size_t i=0; i<ndims; ++i)
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
454 {
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
455 LLValue* dim = dims[i]->getRVal();
287
00eb2c967c3a [svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents: 286
diff changeset
456 if (!firstDim) firstDim = dim;
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
457 DtoStore(dim, DtoGEPi1(dimsArg, i));
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
458 }
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
459
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
460 // call allocator
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
461 LLValue* newptr = gIR->CreateCallOrInvoke3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem")->get();
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
462
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
463 // cast to wanted type
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
464 const LLType* dstType = DtoType(arrayType)->getContainedType(1);
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
465 if (newptr->getType() != dstType)
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
466 newptr = DtoBitCast(newptr, dstType, ".gc_mem");
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
467
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
468 Logger::cout() << "final ptr = " << *newptr << '\n';
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
469
287
00eb2c967c3a [svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents: 286
diff changeset
470 assert(firstDim);
00eb2c967c3a [svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents: 286
diff changeset
471 return new DSliceValue(arrayType, firstDim, newptr);
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
472 }
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
473
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 280
diff changeset
474 //////////////////////////////////////////////////////////////////////////////////////////
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
475 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 22
diff changeset
476 {
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
477 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
478 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
479
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
480 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
481 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
482 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
483 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
484
211
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
485 // 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
486 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
487
f66219e0d530 [svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents: 205
diff changeset
488 // call runtime
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
489 LLFunction* 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
490
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
491 LLSmallVector<LLValue*,4> args;
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
492 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
493 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
494 args.push_back(DtoArrayLen(array));
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
495
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
496 LLValue* arrPtr = DtoArrayPtr(array);
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
497 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
498 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
499
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
500 LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem")->get();
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
501 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
502 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
503
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
504 return new DSliceValue(arrayType, newdim->getRVal(), newptr);
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
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
507 //////////////////////////////////////////////////////////////////////////////////////////
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
508 DSliceValue* DtoCatAssignElement(DValue* array, Expression* exp)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
509 {
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
510 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
511 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
512
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 assert(array);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
514
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
515 LLValue* idx = DtoArrayLen(array);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
516 LLValue* one = DtoConstSize_t(1);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
517 LLValue* len = gIR->ir->CreateAdd(idx,one,"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
518
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
519 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
520 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
521
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
522 LLValue* 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
523 ptr = llvm::GetElementPtrInst::Create(ptr, idx, "tmp", gIR->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
524
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 507
diff changeset
525 DValue* dptr = new DVarValue(exp->type, ptr);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
526
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
527 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
528
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
529 DtoAssign(exp->loc, 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
530
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
531 return slice;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
532 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
533
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
534 //////////////////////////////////////////////////////////////////////////////////////////
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
535 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
536 {
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
537 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
538 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
539
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
540 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
541
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
542 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
543
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
544 len1 = DtoArrayLen(arr);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
545 len2 = DtoArrayLen(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
546 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
547
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
548 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
549 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
550
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
551 src1 = slice->ptr;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
552 src2 = DtoArrayPtr(e);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
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 // 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
555 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
556
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 // memcpy
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
558 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0)));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
559 LLValue* bytelen = gIR->ir->CreateMul(len2, elemSize, "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
560 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
561
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 return slice;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
563 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
564
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
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 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
567 {
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
568 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
569 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
570
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
571 Type* t1 = exp1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
572 Type* t2 = exp2->type->toBasetype();
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
573
360
9c9544fd769d [svn r381] Allow concatenating with static arrays.
ChristianK
parents: 350
diff changeset
574 assert(t1->ty == Tarray || t1->ty == Tsarray);
9c9544fd769d [svn r381] Allow concatenating with static arrays.
ChristianK
parents: 350
diff changeset
575 assert(t2->ty == Tarray || t2->ty == Tsarray);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
576
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
577 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
578 DValue* e2 = exp2->toElem(gIR);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
579
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
580 llvm::Value *len1, *len2, *src1, *src2, *res;
174
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
581
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
582 len1 = DtoArrayLen(e1);
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
583 len2 = DtoArrayLen(e2);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
584 res = gIR->ir->CreateAdd(len1,len2,"tmp");
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
585
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
586 DValue* lenval = new DImValue(Type::tsize_t, res);
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 586
diff changeset
587 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
588 LLValue* mem = slice->ptr;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
589
174
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
590 src1 = DtoArrayPtr(e1);
16e676ae5ab4 [svn r190] Fixed array concatenation for some broken cases.
lindquist
parents: 173
diff changeset
591 src2 = DtoArrayPtr(e2);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
592
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
593 // first memcpy
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
594 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
595 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "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
596 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
597
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
598 // second memcpy
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
599 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
600 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
601 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
602
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 return slice;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
604 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
605
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 54
diff changeset
606 //////////////////////////////////////////////////////////////////////////////////////////
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
607 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
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 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
610 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
611
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
612 Type* t1 = exp1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
613 Type* t2 = exp2->type->toBasetype();
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
614
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
615 DValue* e1 = exp1->toElem(gIR);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
616 DValue* e2 = exp2->toElem(gIR);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
617
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
618 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
619
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
620 // handle prefix case, eg. int~int[]
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
621 if (t2->next && t1 == t2->next->toBasetype())
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
622 {
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 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
624 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
625
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 DValue* lenval = new DImValue(Type::tsize_t, res);
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 586
diff changeset
627 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
628 LLValue* mem = slice->ptr;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
629
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 507
diff changeset
630 DVarValue* memval = new DVarValue(e1->getType(), mem);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 398
diff changeset
631 DtoAssign(exp1->loc, memval, e1);
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
632
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 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
634
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 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
636
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
637 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
638 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "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
639 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
640
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
641
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
642 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
643 }
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
644 // 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
645 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
646 {
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
647 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
648 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp");
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
649
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
650 DValue* lenval = new DImValue(Type::tsize_t, res);
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 586
diff changeset
651 DSliceValue* slice = DtoNewDynArray(exp1->loc, type, lenval, false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
652 LLValue* mem = slice->ptr;
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
653
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
654 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
655
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
656 LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0)));
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
657 LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "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
658 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
659
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 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 507
diff changeset
661 DVarValue* memval = new DVarValue(e2->getType(), mem);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 398
diff changeset
662 DtoAssign(exp1->loc, memval, e2);
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
663
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
664 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
665 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
666 }
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
667
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 127
diff changeset
668 //////////////////////////////////////////////////////////////////////////////////////////
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
669 // helper for eq and cmp
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
670 static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue* r, bool useti)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
671 {
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
672 Logger::println("comparing arrays");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
673 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
674 assert(fn);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
675
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
676 LLValue* lmem;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
677 LLValue* rmem;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
678
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
679 // 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
680 Logger::println("casting to dynamic arrays");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
681 Type* l_ty = l->getType()->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
682 Type* r_ty = r->getType()->toBasetype();
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
683 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
684 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) {
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
685 Type* a_ty = l_ty->next->arrayOf();
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
686 if (l_ty->ty == Tsarray)
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
687 l = DtoCastArray(loc, l, a_ty);
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
688 if (r_ty->ty == Tsarray)
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
689 r = DtoCastArray(loc, r, a_ty);
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
690 }
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
691
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
692 Logger::println("giving storage");
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
693
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
694 // 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
695 if (l->isSlice()) {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
696 lmem = DtoAlloca(DtoType(l->getType()), "tmpparam");
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
697 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
698 }
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
699 // also null
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
700 else if (l->isNull())
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
701 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
702 lmem = DtoAlloca(DtoType(l->getType()), "tmpparam");
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
703 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
704 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
705 else
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
706 lmem = l->getRVal();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
707
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
708 // and for the rvalue ...
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
709 // 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
710 if (r->isSlice()) {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
711 rmem = DtoAlloca(DtoType(r->getType()), "tmpparam");
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
712 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
713 }
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
714 // also null
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
715 else if (r->isNull())
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
716 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
717 rmem = DtoAlloca(DtoType(r->getType()), "tmpparam");
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
718 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
719 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
720 else
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
721 rmem = r->getRVal();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
722
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
723 const LLType* pt = fn->getFunctionType()->getParamType(0);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
724
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
725 LLSmallVector<LLValue*, 3> args;
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
726 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
727 Logger::cout() << *lmem << '\n';
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 162
diff changeset
728 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
729 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
730 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
731
291
068cb3c60afb [svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents: 287
diff changeset
732 // pass array typeinfo ?
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
733 if (useti) {
291
068cb3c60afb [svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents: 287
diff changeset
734 Type* t = l->getType();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
735 LLValue* tival = DtoTypeInfoOf(t);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
736 // DtoTypeInfoOf only does declare, not enough in this case :/
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
737 DtoForceConstInitDsymbol(t->vtinfo);
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
738 Logger::cout() << "typeinfo decl: " << *tival << '\n';
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
739
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
740 pt = fn->getFunctionType()->getParamType(2);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
741 args.push_back(DtoBitCast(tival, pt));
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
742 }
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
743
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
744 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp");
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
745
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
746 // set param attrs
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
747 llvm::PAListPtr palist;
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
748 palist = palist.addAttr(1, llvm::ParamAttr::ByVal);
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
749 palist = palist.addAttr(2, llvm::ParamAttr::ByVal);
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
750 call->setParamAttrs(palist);
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 244
diff changeset
751
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
752 return call->get();
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
753 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
754
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
755 //////////////////////////////////////////////////////////////////////////////////////////
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
756 LLValue* DtoArrayEquals(Loc& loc, TOK op, DValue* l, DValue* r)
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
757 {
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
758 LLValue* res = DtoArrayEqCmp_impl(loc, "_adEq", l, r, true);
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
759 res = gIR->ir->CreateICmpNE(res, DtoConstInt(0), "tmp");
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
760 if (op == TOKnotequal)
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
761 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
762
297
5de180867c46 [svn r318] Moved the call to DtoBoolean before the not instruction.
ChristianK
parents: 296
diff changeset
763 return res;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
764 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
765
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
766 //////////////////////////////////////////////////////////////////////////////////////////
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
767 LLValue* DtoArrayCompare(Loc& loc, TOK op, DValue* l, DValue* r)
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
768 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
769 LLValue* res = 0;
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
770
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
771 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
772 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
773
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
774 switch(op)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
775 {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
776 case TOKlt:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
777 case TOKul:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
778 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
779 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
780 case TOKle:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
781 case TOKule:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
782 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
783 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
784 case TOKgt:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
785 case TOKug:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
786 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
787 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
788 case TOKge:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
789 case TOKuge:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
790 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
791 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
792 case TOKue:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
793 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
794 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
795 case TOKlg:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
796 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
797 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
798 case TOKleg:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
799 skip = true;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
800 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
801 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
802 case TOKunord:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
803 skip = true;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
804 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
805 break;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
806
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
807 default:
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
808 assert(0);
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 if (!skip)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
812 {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
813 Type* t = l->getType()->toBasetype()->next->toBasetype();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
814 if (t->ty == Tchar)
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
815 res = DtoArrayEqCmp_impl(loc, "_adCmpChar", l, r, false);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
816 else
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
817 res = DtoArrayEqCmp_impl(loc, "_adCmp", l, r, true);
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
818 res = gIR->ir->CreateICmp(cmpop, res, DtoConstInt(0), "tmp");
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
819 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
820
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
821 assert(res);
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
822 return res;
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
823 }
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
824
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
825 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
826 LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty)
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
827 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
828 Logger::println("DtoArrayCastLength");
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
829 LOG_SCOPE;
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
830
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
831 assert(len);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
832 assert(elemty);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
833 assert(newelemty);
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
834
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
835 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
836 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
837 if (esz == nsz)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
838 return len;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 88
diff changeset
839
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 213
diff changeset
840 LLSmallVector<LLValue*, 3> args;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
841 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
842 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
843 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
844
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
845 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 308
diff changeset
846 return gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp")->get();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
847 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
848
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
849 //////////////////////////////////////////////////////////////////////////////////////////
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
850 LLValue* DtoDynArrayIs(TOK op, DValue* l, DValue* r)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
851 {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
852 LLValue *len1, *ptr1, *len2, *ptr2;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
853
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
854 assert(l);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
855 assert(r);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
856
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
857 // compare lengths
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
858 len1 = DtoArrayLen(l);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
859 len2 = DtoArrayLen(r);
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
860 LLValue* b1 = gIR->ir->CreateICmpEQ(len1,len2,"tmp");
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
861
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
862 // compare pointers
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
863 ptr1 = DtoArrayPtr(l);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
864 ptr2 = DtoArrayPtr(r);
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
865 LLValue* b2 = gIR->ir->CreateICmpEQ(ptr1,ptr2,"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
866
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
867 // combine
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
868 LLValue* res = gIR->ir->CreateAnd(b1,b2,"tmp");
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 64
diff changeset
869
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
870 // return result
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
871 return (op == TOKnotidentity) ? gIR->ir->CreateNot(res) : res;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
872 }
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
873
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
874 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
875 LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c)
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
876 {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
877 const LLArrayType* at = isaArray(t);
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
878 assert(at);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
879
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
880 if (isaArray(at->getElementType()))
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
881 {
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
882 c = DtoConstStaticArray(at->getElementType(), c);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
883 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
884 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
885 assert(at->getElementType() == c->getType());
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
886 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
887 std::vector<LLConstant*> initvals;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
888 initvals.resize(at->getNumElements(), c);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
889 return llvm::ConstantArray::get(at, initvals);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 58
diff changeset
890 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
891
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
892 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
893 LLValue* DtoArrayLen(DValue* v)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
894 {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
895 Logger::println("DtoArrayLen");
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
896 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
897
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
898 Type* t = v->getType()->toBasetype();
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
899 if (t->ty == Tarray) {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
900 if (DSliceValue* s = v->isSlice())
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
901 return s->len;
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
902 else if (v->isNull())
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
903 return DtoConstSize_t(0);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
904 return DtoLoad(DtoGEPi(v->getRVal(), 0,0));
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
905 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
906 else if (t->ty == Tsarray) {
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 109
diff changeset
907 assert(!v->isSlice());
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
908 assert(!v->isNull());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
909 LLValue* rv = v->getRVal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
910 const LLArrayType* t = isaArray(rv->getType()->getContainedType(0));
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
911 assert(t);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
912 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
913 }
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
914 assert(0 && "unsupported array for len");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
915 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
916 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
917
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
918 //////////////////////////////////////////////////////////////////////////////////////////
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
919 LLValue* DtoArrayPtr(DValue* v)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
920 {
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
921 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
922 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
923
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
924 Type* t = v->getType()->toBasetype();
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
925 if (t->ty == Tarray) {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
926 if (DSliceValue* s = v->isSlice())
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
927 return s->ptr;
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
928 else if (v->isNull())
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
929 return getNullPtr(getPtrToType(DtoType(t->next)));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
930 return DtoLoad(DtoGEPi(v->getRVal(), 0,1));
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
931 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
932 else if (t->ty == Tsarray) {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
933 assert(!v->isSlice());
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 297
diff changeset
934 assert(!v->isNull());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
935 return DtoGEPi(v->getRVal(), 0,0);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
936 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
937 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
938 return 0;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
939 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 81
diff changeset
940
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
941 //////////////////////////////////////////////////////////////////////////////////////////
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
942 DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
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
943 {
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
944 Logger::println("DtoCastArray");
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
945 LOG_SCOPE;
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
946
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
947 const LLType* tolltype = DtoType(to);
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
948
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
949 Type* totype = to->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 479
diff changeset
950 Type* fromtype = u->getType()->toBasetype();
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
951 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
952
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
953 LLValue* rval;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
954 LLValue* rval2;
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
955 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
956
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
957 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
958 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
959 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
960 rval = DtoArrayPtr(u);
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 182
diff changeset
961 if (rval->getType() != tolltype)
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 182
diff changeset
962 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
963 }
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
964 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
965 Logger::cout() << "to array" << '\n';
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
966
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
967 const LLType* ptrty = DtoArrayType(totype)->getContainedType(1);
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
968 const LLType* ety = DtoTypeNotVoid(fromtype->next);
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
969
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
970 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
971 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
972 Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n';
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
973 rval = DtoBitCast(usl->ptr, 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
974 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
975 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
976 else
182
6526cf5bb2be [svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents: 176
diff changeset
977 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
978 }
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
979 else {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
980 LLValue* uval = u->getRVal();
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
981 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
982 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
983 assert(isaPointer(uval->getType()));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
984 const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
985
425
944d43f3779f Fix the static array cast size check.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
986 if(arrty->getNumElements()*fromtype->next->size() % totype->next->size() != 0)
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
987 {
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
988 error(loc, "invalid cast from '%s' to '%s', the element sizes don't line up", fromtype->toChars(), totype->toChars());
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
989 fatal();
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
990 }
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 400
diff changeset
991
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
992 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
993 rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
994 rval = DtoBitCast(uval, 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
995 }
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
996 else {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
997 LLValue* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
998 LLValue* one = llvm::ConstantInt::get(LLType::Int32Ty, 1, false);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
999 rval2 = DtoGEP(uval,zero,zero);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
1000 rval2 = DtoLoad(rval2);
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
1001 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
1002
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
1003 rval = DtoGEP(uval,zero,one);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 234
diff changeset
1004 rval = DtoLoad(rval);
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
1005 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n';
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 211
diff changeset
1006 rval = DtoBitCast(rval, 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
1007 }
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
1008 }
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
1009 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
1010 }
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
1011 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
1012 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
1013 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
1014 }
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
1015 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
1016 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
1017 }
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
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
1019 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
1020 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
1021 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
1022 }
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 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
1025 }
442
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1026
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1027
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1028 //////////////////////////////////////////////////////////////////////////////////////////
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1029 void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice)
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1030 {
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1031 Type* arrty = arr->getType()->toBasetype();
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1032 assert((arrty->ty == Tsarray || arrty->ty == Tarray) && "Can only array bounds check for static or dynamic arrays");
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1033
507
39dbe48d3fe2 Got rid of improper static array compile time index check.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
1034 // static arrays could get static checks for static indices
39dbe48d3fe2 Got rid of improper static array compile time index check.
Christian Kamm <kamm incasoftware de>
parents: 486
diff changeset
1035 // but shouldn't since it might be generic code that's never executed
442
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1036
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1037 // runtime check
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1038
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1039 llvm::BasicBlock* oldend = gIR->scopeend();
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1040 llvm::BasicBlock* failbb = llvm::BasicBlock::Create("arrayboundscheckfail", gIR->topfunc(), oldend);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1041 llvm::BasicBlock* okbb = llvm::BasicBlock::Create("arrayboundsok", gIR->topfunc(), oldend);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1042
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1043 llvm::ICmpInst::Predicate cmpop = isslice ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_ULT;
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1044 LLValue* cond = gIR->ir->CreateICmp(cmpop, index->getRVal(), DtoArrayLen(arr), "boundscheck");
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1045 gIR->ir->CreateCondBr(cond, okbb, failbb);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1046
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1047 // set up failbb to call the array bounds error runtime function
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1048
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1049 gIR->scope() = IRScope(failbb, okbb);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1050
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1051 std::vector<LLValue*> args;
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1052 llvm::PAListPtr palist;
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1053
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1054 // file param
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1055 // FIXME: every array bounds check creates a global for the filename !!!
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1056 LLConstant* c = DtoConstString(loc.filename);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1057
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1058 llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1059 if (!alloc)
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1060 {
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 442
diff changeset
1061 alloc = DtoAlloca(c->getType(), ".srcfile");
442
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1062 gIR->func()->srcfileArg = alloc;
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1063 }
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1064 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1065 DtoStore(c->getOperand(0), ptr);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1066 ptr = DtoGEPi(alloc, 0,1, "tmp");
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1067 DtoStore(c->getOperand(1), ptr);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1068
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1069 args.push_back(alloc);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1070 palist = palist.addAttr(1, llvm::ParamAttr::ByVal);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1071
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1072 // line param
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1073 c = DtoConstUint(loc.linnum);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1074 args.push_back(c);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1075
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1076 // call
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1077 llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds");
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1078 CallOrInvoke* call = gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1079 call->setParamAttrs(palist);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1080
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1081 // the function does not return
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1082 gIR->ir->CreateUnreachable();
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1083
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1084
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1085 // if ok, proceed in okbb
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1086 gIR->scope() = IRScope(okbb, oldend);
76078c8ab5b9 Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents: 425
diff changeset
1087 }