Mercurial > projects > ldc
annotate gen/arrays.cpp @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | 8f121883bce8 |
children |
rev | line source |
---|---|
40 | 1 #include "gen/llvm.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
2 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
3 #include "mtype.h" |
683
b411c41a9716
Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents:
655
diff
changeset
|
4 #include "module.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
5 #include "dsymbol.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
6 #include "aggregate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
7 #include "declaration.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
8 #include "init.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
9 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
10 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
11 #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
|
12 #include "gen/llvmhelpers.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
13 #include "gen/arrays.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
14 #include "gen/runtime.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
15 #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
|
16 #include "gen/dvalue.h" |
683
b411c41a9716
Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents:
655
diff
changeset
|
17 #include "ir/irmodule.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
18 |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
19 #include "gen/cl_options.h" |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
20 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
21 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
22 |
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 const LLStructType* DtoArrayType(Type* arrayTy) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
24 { |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
25 assert(arrayTy->nextOf()); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
26 const LLType* elemty = DtoType(arrayTy->nextOf()); |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
27 if (elemty == LLType::getVoidTy(gIR->context())) |
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
28 elemty = LLType::getInt8Ty(gIR->context()); |
1569
755abafbf25d
Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
29 return LLStructType::get(gIR->context(), DtoSize_t(), getPtrToType(elemty), NULL); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
30 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
31 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
32 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
|
33 { |
1569
755abafbf25d
Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
34 return LLStructType::get(gIR->context(), DtoSize_t(), getPtrToType(t), NULL); |
234
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
217
diff
changeset
|
35 } |
9760f54af0b7
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
lindquist
parents:
217
diff
changeset
|
36 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
37 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
38 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
39 const LLArrayType* DtoStaticArrayType(Type* t) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
40 { |
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
|
41 t = t->toBasetype(); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
42 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
|
43 TypeSArray* tsa = (TypeSArray*)t; |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
44 Type* tnext = tsa->nextOf(); |
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 const LLType* elemty = DtoType(tnext); |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
47 if (elemty == LLType::getVoidTy(gIR->context())) |
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
48 elemty = LLType::getInt8Ty(gIR->context()); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
49 |
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
|
50 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
|
51 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
52 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
53 ////////////////////////////////////////////////////////////////////////////////////////// |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
54 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
55 void DtoSetArrayToNull(LLValue* v) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
56 { |
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
|
57 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
|
58 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
|
59 |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
60 assert(isaPointer(v)); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
61 const LLType* t = v->getType()->getContainedType(0); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
62 |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1559
diff
changeset
|
63 DtoStore(LLConstant::getNullValue(t), v); |
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 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
398
diff
changeset
|
68 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
|
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("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
|
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 |
295
895e1b50cf2a
[svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents:
293
diff
changeset
|
73 LLValue* dim = DtoArrayLen(array); |
895e1b50cf2a
[svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents:
293
diff
changeset
|
74 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
|
75 LLValue* val; |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
76 |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
77 // 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
|
78 if (value->isSlice()) |
350
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
79 { |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1342
diff
changeset
|
80 val = DtoAlloca(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
|
81 DVarValue lval(value->getType(), val); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
398
diff
changeset
|
82 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
|
83 } |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
84 else |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
85 { |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
86 val = value->getRVal(); |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
87 } |
b85cf5faccfc
[svn r371] Fixed array init was still broken for immediate slices and complex values.
lindquist
parents:
340
diff
changeset
|
88 assert(val); |
295
895e1b50cf2a
[svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents:
293
diff
changeset
|
89 |
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
|
90 // prepare runtime call |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
91 LLSmallVector<LLValue*, 4> args; |
43 | 92 args.push_back(ptr); |
93 args.push_back(dim); | |
94 args.push_back(val); | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
58
diff
changeset
|
95 |
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
|
96 // 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
|
97 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
|
98 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
|
99 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
|
100 |
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
|
101 // 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
|
102 // 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
|
103 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
|
104 { |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
105 size_t X = getTypePaddedSize(val->getType()); |
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
|
106 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
|
107 DtoMemSetZero(ptr, nbytes); |
338
0c90d816394f
[svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents:
334
diff
changeset
|
108 return; |
0c90d816394f
[svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents:
334
diff
changeset
|
109 } |
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
|
110 |
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
|
111 // 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
|
112 switch (arrayelemty->ty) |
338
0c90d816394f
[svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents:
334
diff
changeset
|
113 { |
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
|
114 case Tbool: |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
115 val = gIR->ir->CreateZExt(val, LLType::getInt8Ty(gIR->context()), ".bool"); |
1480
b3ba2c6ff038
Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`.
Frits van Bommel <fvbommel wxs.nl>
parents:
1463
diff
changeset
|
116 // fall through |
611
83ca663ecc20
Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents:
610
diff
changeset
|
117 |
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
|
118 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
|
119 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
|
120 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
|
121 case Tuns8: |
1480
b3ba2c6ff038
Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`.
Frits van Bommel <fvbommel wxs.nl>
parents:
1463
diff
changeset
|
122 Logger::println("Using memset for array init"); |
b3ba2c6ff038
Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`.
Frits van Bommel <fvbommel wxs.nl>
parents:
1463
diff
changeset
|
123 DtoMemSet(ptr, val, dim); |
b3ba2c6ff038
Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`.
Frits van Bommel <fvbommel wxs.nl>
parents:
1463
diff
changeset
|
124 return; |
338
0c90d816394f
[svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents:
334
diff
changeset
|
125 |
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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 |
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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
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 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
|
139 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
|
140 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
|
141 break; |
338
0c90d816394f
[svn r359] Try to fix DtoArrayInit. Unfinished, breaks for arrays of primitive types.
ChristianK
parents:
334
diff
changeset
|
142 |
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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 |
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 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
|
149 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
|
150 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
|
151 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
|
152 |
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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 |
586
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
158 case Tcomplex32: |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
159 funcname = "_d_array_init_cfloat"; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
160 break; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
161 |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
162 case Tcomplex64: |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
163 funcname = "_d_array_init_cdouble"; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
164 break; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
165 |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
166 case Tcomplex80: |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
167 funcname = "_d_array_init_creal"; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
168 break; |
192b82878b78
Fixed most regressions from last commit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
169 |
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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 |
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 // 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
|
178 // 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 args[2] = DtoBitCast(args[2], getVoidPtrType()); |
1495
0c8d6d345001
The llvm element type of void arrays should be i8 and not void.
Christian Kamm <kamm incasoftware de>
parents:
1480
diff
changeset
|
187 args.push_back(DtoConstSize_t(getTypePaddedSize(DtoTypeNotVoid(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
|
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 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
|
191 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
|
192 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
|
193 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
194 |
825
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
195 if (Logger::enabled()) |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
196 { |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
197 Logger::cout() << "ptr = " << *args[0] << std::endl; |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
198 Logger::cout() << "dim = " << *args[1] << std::endl; |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
199 Logger::cout() << "val = " << *args[2] << std::endl; |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
200 } |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
201 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
202 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
|
203 assert(fn); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
204 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
205 Logger::cout() << "calling array init function: " << *fn <<'\n'; |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
206 LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); |
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
207 call.setCallingConv(llvm::CallingConv::C); |
37
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
208 } |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
209 |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
210 ////////////////////////////////////////////////////////////////////////////////////////// |
77cdca8c210f
[svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents:
36
diff
changeset
|
211 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
212 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
|
213 { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
219 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
220 ////////////////////////////////////////////////////////////////////////////////////////// |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
221 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
222 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
223 { |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
224 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
|
225 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
226 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
227 assert(arrinit->value.dim == arrinit->index.dim); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
228 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
229 // get base array type |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
230 Type* arrty = arrinit->type->toBasetype(); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
231 size_t arrlen = arrinit->dim; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
232 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
233 // for statis arrays, dmd does not include any trailing default |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
234 // initialized elements in the value/index lists |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
235 if (arrty->ty == Tsarray) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
236 { |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
237 TypeSArray* tsa = (TypeSArray*)arrty; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
238 arrlen = (size_t)tsa->dim->toInteger(); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
239 } |
398
811f82dfddbd
Add error if array initializer has incorrect length.
Christian Kamm <kamm incasoftware de>
parents:
365
diff
changeset
|
240 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
241 // make sure the number of initializers is sane |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
242 if (arrinit->index.dim > arrlen || arrinit->dim > arrlen) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
243 { |
1372
229e02867307
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
244 error(arrinit->loc, "too many initializers, %u, for array[%zu]", arrinit->index.dim, arrlen); |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
245 fatal(); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
246 } |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
247 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
248 // get elem type |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
249 Type* elemty = arrty->nextOf(); |
1495
0c8d6d345001
The llvm element type of void arrays should be i8 and not void.
Christian Kamm <kamm incasoftware de>
parents:
1480
diff
changeset
|
250 const LLType* llelemty = DtoTypeNotVoid(elemty); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
251 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
252 // true if array elements differ in type, can happen with array of unions |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
253 bool mismatch = false; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
254 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
255 // allocate room for initializers |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
256 std::vector<LLConstant*> initvals(arrlen, NULL); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
257 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
258 // go through each initializer, they're not sorted by index by the frontend |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
259 size_t j = 0; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
260 for (size_t i = 0; i < arrinit->index.dim; i++) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
261 { |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
262 // get index |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
263 Expression* idx = (Expression*)arrinit->index.data[i]; |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
109
diff
changeset
|
264 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
265 // idx can be null, then it's just the next element |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
266 if (idx) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
267 j = idx->toInteger(); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
268 assert(j < arrlen); |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
109
diff
changeset
|
269 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
270 // get value |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
271 Initializer* val = (Initializer*)arrinit->value.data[i]; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
272 assert(val); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
273 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
274 // error check from dmd |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
275 if (initvals[j] != NULL) |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
276 { |
1372
229e02867307
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
277 error(arrinit->loc, "duplicate initialization for index %zu", j); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
278 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
279 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
280 LLConstant* c = DtoConstInitializer(val->loc, elemty, val); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
281 assert(c); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
282 if (c->getType() != llelemty) |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
283 mismatch = true; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
284 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
285 initvals[j] = c; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
286 j++; |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
287 } |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
288 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
289 // die now if there was errors |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
290 if (global.errors) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
291 fatal(); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
292 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
293 // fill out any null entries still left with default values |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
294 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
295 // element default initializer |
932
5e3bb0c3ea8b
Fixed dstress/run/a/array_initialization_17_A.d regression. default initialized static array elements in a constant static array initializer was getting incorrect values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
914
diff
changeset
|
296 LLConstant* defelem = DtoConstExpInit(arrinit->loc, elemty, elemty->defaultInit(arrinit->loc)); |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
297 bool mismatch2 = (defelem->getType() != llelemty); |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
298 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
299 for (size_t i = 0; i < arrlen; i++) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
300 { |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
301 if (initvals[i] != NULL) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
302 continue; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
303 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
304 initvals[i] = defelem; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
305 |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
306 if (mismatch2) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
307 mismatch = true; |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
308 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
309 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
310 LLConstant* constarr; |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
311 if (mismatch) |
1650 | 312 constarr = LLConstantStruct::get(gIR->context(), initvals, false); // FIXME should this pack? |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
313 else |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
314 constarr = LLConstantArray::get(LLArrayType::get(llelemty, arrlen), initvals); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
315 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
316 // std::cout << "constarr: " << *constarr << std::endl; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
317 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
318 // if the type is a static array, we're done |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
319 if (arrty->ty == Tsarray) |
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
320 return constarr; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
321 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
322 // for dynamic array we need to make a global with the data, so we have a pointer for the dynamic array |
1292
ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents:
1271
diff
changeset
|
323 // Important: don't make the gvar constant, since this const initializer might |
ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents:
1271
diff
changeset
|
324 // be used as an initializer for a static T[] - where modifying contents is allowed. |
1529
ad7f2f1862d6
Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents:
1515
diff
changeset
|
325 LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, constarr->getType(), false, LLGlobalValue::InternalLinkage, constarr, ".constarray"); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
326 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
327 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
328 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
329 gep = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llelemty)); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
330 |
914
a65a6996922f
Fixed bug #191 by rewriting DtoConstArrayInitializer, patch unfortunately caused regressions, hopefully this doesn't :P
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
331 return DtoConstSlice(DtoConstSize_t(arrlen),gep); |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
332 } |
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 ////////////////////////////////////////////////////////////////////////////////////////// |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
335 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
|
336 { |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
337 assert(e->len != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
338 const LLType* t = e->ptr->getType()->getContainedType(0); |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
339 sz = gIR->ir->CreateMul(DtoConstSize_t(getTypePaddedSize(t)), e->len, "tmp"); |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
340 return DtoBitCast(e->ptr, getVoidPtrType()); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
341 } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
342 |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
343 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
|
344 { |
182
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
345 Logger::println("ArrayCopySlices"); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
346 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
347 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
|
348 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
|
349 LLValue* srcarr = get_slice_ptr(src,sz2); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
350 |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
351 if (global.params.useAssert || global.params.useArrayBounds) |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
352 { |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
353 LLValue* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_slice_copy"); |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
354 gIR->CreateCallOrInvoke4(fn, dstarr, sz1, srcarr, sz2); |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
355 } |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
356 else |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
357 { |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
358 DtoMemCpy(dstarr, srcarr, sz1); |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
359 } |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
diff
changeset
|
360 } |
21
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 DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
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("ArrayCopyToSlice"); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
365 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
366 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
|
367 LLValue* dstarr = get_slice_ptr(dst,sz1); |
1342
16d9afa22df4
Fix DtoArrayCopyToSlice by passing length*sizeof(element) instead of just length to _d_array_slice_copy.
Christian Kamm <kamm incasoftware de>
parents:
1328
diff
changeset
|
368 |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
369 LLValue* srcarr = DtoBitCast(DtoArrayPtr(src), getVoidPtrType()); |
1495
0c8d6d345001
The llvm element type of void arrays should be i8 and not void.
Christian Kamm <kamm incasoftware de>
parents:
1480
diff
changeset
|
370 const LLType* arrayelemty = DtoTypeNotVoid(src->getType()->nextOf()->toBasetype()); |
1342
16d9afa22df4
Fix DtoArrayCopyToSlice by passing length*sizeof(element) instead of just length to _d_array_slice_copy.
Christian Kamm <kamm incasoftware de>
parents:
1328
diff
changeset
|
371 LLValue* sz2 = gIR->ir->CreateMul(DtoConstSize_t(getTypePaddedSize(arrayelemty)), DtoArrayLen(src), "tmp"); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
102
diff
changeset
|
372 |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
373 if (global.params.useAssert || global.params.useArrayBounds) |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
374 { |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
375 LLValue* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_slice_copy"); |
1342
16d9afa22df4
Fix DtoArrayCopyToSlice by passing length*sizeof(element) instead of just length to _d_array_slice_copy.
Christian Kamm <kamm incasoftware de>
parents:
1328
diff
changeset
|
376 gIR->CreateCallOrInvoke4(fn, dstarr, sz1, srcarr, sz2); |
1328
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
377 } |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
378 else |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
379 { |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
380 DtoMemCpy(dstarr, srcarr, sz1); |
c78fd2d30da1
Changed array slice copying to call a runtime function when assertions or array bound checks are enabled instead of just doing a memcpy. This makes sure an exception is thrown if the copy is invalid (ie. different lengths or overlap). Fixes ticket #283 . Rebuilding the runtime is necessary.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
381 } |
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 | 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 | 388 |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
389 size_t n = getTypePaddedSize(dst->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
|
390 DtoMemCpy(dst, src, DtoConstSize_t(n)); |
48 | 391 } |
392 | |
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 }; |
1650 | 397 return LLConstantStruct::get(gIR->context(), values, 2, false); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
11
diff
changeset
|
398 } |
34 | 399 |
400 ////////////////////////////////////////////////////////////////////////////////////////// | |
1514
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
401 static bool isInitialized(Type* et) { |
1515
391fdb36f2aa
Be a little less overzealous with arrays of void-initialized typedefs;
Frits van Bommel <fvbommel wxs.nl>
parents:
1514
diff
changeset
|
402 // Strip static array types from element type |
1514
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
403 Type* bt = et->toBasetype(); |
1515
391fdb36f2aa
Be a little less overzealous with arrays of void-initialized typedefs;
Frits van Bommel <fvbommel wxs.nl>
parents:
1514
diff
changeset
|
404 while (bt->ty == Tsarray) { |
1514
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
405 et = bt->nextOf(); |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
406 bt = et->toBasetype(); |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
407 } |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
408 // If it's a typedef with "= void" initializer then don't initialize. |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
409 if (et->ty == Ttypedef) { |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
410 Logger::println("Typedef: %s", et->toChars()); |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
411 TypedefDeclaration* tdd = ((TypeTypedef*)et)->sym; |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
412 if (tdd && tdd->init && tdd->init->isVoidInitializer()) |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
413 return false; |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
414 } |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
415 // Otherwise, it's always initialized. |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
416 return true; |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
417 } |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
418 |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
419 ////////////////////////////////////////////////////////////////////////////////////////// |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
420 DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool defaultInit) |
34 | 421 { |
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
|
422 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
|
423 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
|
424 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
425 // typeinfo arg |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
426 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
427 |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
428 // dim arg |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
429 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
|
430 LLValue* arrayLen = dim->getRVal(); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
431 |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
432 // get runtime function |
1514
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
433 Type* eltType = arrayType->toBasetype()->nextOf(); |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
434 if (defaultInit && !isInitialized(eltType)) |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
435 defaultInit = false; |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
436 bool zeroInit = eltType->isZeroInit(); |
593
7042d912767e
Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
437 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
|
438 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname); |
34 | 439 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
440 // call allocator |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
441 LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem").getInstruction(); |
34 | 442 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
443 // cast to wanted type |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
444 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
|
445 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
|
446 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
447 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
448 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
449 Logger::cout() << "final ptr = " << *newptr << '\n'; |
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
|
450 |
593
7042d912767e
Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
451 return new DSliceValue(arrayType, arrayLen, newptr); |
34 | 452 } |
453 | |
454 ////////////////////////////////////////////////////////////////////////////////////////// | |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
586
diff
changeset
|
455 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
|
456 { |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
457 Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars()); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
458 LOG_SCOPE; |
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 // typeinfo arg |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
461 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
462 |
293
ebfa488f4abc
[svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents:
291
diff
changeset
|
463 // get value type |
ebfa488f4abc
[svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents:
291
diff
changeset
|
464 Type* vtype = arrayType->toBasetype(); |
ebfa488f4abc
[svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents:
291
diff
changeset
|
465 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
|
466 vtype = vtype->nextOf(); |
ebfa488f4abc
[svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents:
291
diff
changeset
|
467 |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
468 // get runtime function |
293
ebfa488f4abc
[svn r314] Get correct value type for newing of multidimensional dynamic arrays.
ChristianK
parents:
291
diff
changeset
|
469 bool zeroInit = vtype->isZeroInit(); |
1514
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
470 if (defaultInit && !isInitialized(vtype)) |
7a528017b4c6
Don't initialize arrays of (arrays of...) void-initialized typedefs.
Frits van Bommel <fvbommel wxs.nl>
parents:
1495
diff
changeset
|
471 defaultInit = false; |
593
7042d912767e
Undid some of the previous changes: DtoArrayInit has issues with arrays
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
472 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
|
473 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
474 |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
475 // build dims |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1342
diff
changeset
|
476 LLValue* dimsArg = DtoArrayAlloca(Type::tsize_t, ndims, ".newdims"); |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
477 LLValue* firstDim = NULL; |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
478 for (size_t i=0; i<ndims; ++i) |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
479 { |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
480 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
|
481 if (!firstDim) firstDim = dim; |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
482 DtoStore(dim, DtoGEPi1(dimsArg, i)); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
483 } |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
484 |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
485 // call allocator |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
486 LLValue* newptr = gIR->CreateCallOrInvoke3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem").getInstruction(); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
487 |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
488 // cast to wanted type |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
489 const LLType* dstType = DtoType(arrayType)->getContainedType(1); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
490 if (newptr->getType() != dstType) |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
491 newptr = DtoBitCast(newptr, dstType, ".gc_mem"); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
492 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
493 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
494 Logger::cout() << "final ptr = " << *newptr << '\n'; |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
495 |
287
00eb2c967c3a
[svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents:
286
diff
changeset
|
496 assert(firstDim); |
00eb2c967c3a
[svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
lindquist
parents:
286
diff
changeset
|
497 return new DSliceValue(arrayType, firstDim, newptr); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
498 } |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
499 |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
280
diff
changeset
|
500 ////////////////////////////////////////////////////////////////////////////////////////// |
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 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim) |
34 | 502 { |
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
|
503 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
|
504 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
|
505 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 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
|
510 |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
205
diff
changeset
|
511 // decide on what runtime function to call based on whether the type is zero initialized |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
512 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
205
diff
changeset
|
513 |
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
205
diff
changeset
|
514 // 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
|
515 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
|
516 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 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
|
521 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
522 LLValue* arrPtr = DtoArrayPtr(array); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
523 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
524 Logger::cout() << "arrPtr = " << *arrPtr << '\n'; |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
525 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
|
526 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
527 LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem").getInstruction(); |
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
|
528 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
|
529 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
|
530 |
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
|
531 return new DSliceValue(arrayType, newdim->getRVal(), newptr); |
34 | 532 } |
533 | |
40 | 534 ////////////////////////////////////////////////////////////////////////////////////////// |
1643
8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1638
diff
changeset
|
535 void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* exp) |
40 | 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("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
|
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 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
540 assert(array); |
40 | 541 |
1643
8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1638
diff
changeset
|
542 LLValue *valueToAppend = makeLValue(loc, exp->toElem(gIR)); |
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
|
543 |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
544 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_arrayappendcT"); |
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
545 LLSmallVector<LLValue*,3> args; |
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
546 args.push_back(DtoTypeInfoOf(arrayType)); |
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
547 args.push_back(DtoBitCast(array->getLVal(), getVoidPtrType())); |
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
548 args.push_back(DtoBitCast(valueToAppend, getVoidPtrType())); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
549 |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
550 gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
551 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
552 |
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 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
|
555 { |
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
|
556 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
|
557 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
|
558 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
559 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
|
560 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
561 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
|
562 |
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
|
563 len1 = DtoArrayLen(arr); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
564 len2 = DtoArrayLen(e); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
565 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
|
566 |
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
|
567 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
|
568 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
|
569 |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
570 src1 = slice->ptr; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
571 src2 = DtoArrayPtr(e); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
572 |
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
|
573 // 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
|
574 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
|
575 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
576 // memcpy |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
577 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src2->getType()->getContainedType(0))); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
578 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
|
579 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
|
580 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
581 return slice; |
40 | 582 } |
583 | |
584 ////////////////////////////////////////////////////////////////////////////////////////// | |
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
|
585 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
|
586 { |
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
|
587 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
|
588 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
|
589 |
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
|
590 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
|
591 Type* t2 = exp2->type->toBasetype(); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
592 |
360
9c9544fd769d
[svn r381] Allow concatenating with static arrays.
ChristianK
parents:
350
diff
changeset
|
593 assert(t1->ty == Tarray || t1->ty == Tsarray); |
9c9544fd769d
[svn r381] Allow concatenating with static arrays.
ChristianK
parents:
350
diff
changeset
|
594 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
|
595 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
596 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
|
597 DValue* e2 = exp2->toElem(gIR); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
598 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
599 llvm::Value *len1, *len2, *src1, *src2, *res; |
174
16e676ae5ab4
[svn r190] Fixed array concatenation for some broken cases.
lindquist
parents:
173
diff
changeset
|
600 |
16e676ae5ab4
[svn r190] Fixed array concatenation for some broken cases.
lindquist
parents:
173
diff
changeset
|
601 len1 = DtoArrayLen(e1); |
16e676ae5ab4
[svn r190] Fixed array concatenation for some broken cases.
lindquist
parents:
173
diff
changeset
|
602 len2 = DtoArrayLen(e2); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
603 res = gIR->ir->CreateAdd(len1,len2,"tmp"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
604 |
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
|
605 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
|
606 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
|
607 LLValue* mem = slice->ptr; |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
608 |
174
16e676ae5ab4
[svn r190] Fixed array concatenation for some broken cases.
lindquist
parents:
173
diff
changeset
|
609 src1 = DtoArrayPtr(e1); |
16e676ae5ab4
[svn r190] Fixed array concatenation for some broken cases.
lindquist
parents:
173
diff
changeset
|
610 src2 = DtoArrayPtr(e2); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
611 |
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
|
612 // first memcpy |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
613 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
614 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
|
615 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
|
616 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
617 // second memcpy |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
618 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
|
619 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
|
620 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
|
621 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
622 return slice; |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
623 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
624 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
54
diff
changeset
|
625 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
626 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) |
132 | 627 { |
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
|
628 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
|
629 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
|
630 |
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
|
631 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
|
632 Type* t2 = exp2->type->toBasetype(); |
132 | 633 |
634 DValue* e1 = exp1->toElem(gIR); | |
635 DValue* e2 = exp2->toElem(gIR); | |
636 | |
637 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
|
638 |
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 // handle prefix case, eg. int~int[] |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
640 if (t2->nextOf() && t1 == t2->nextOf()->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
|
641 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/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 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
|
643 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
|
644 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/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 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
|
646 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
|
647 LLValue* mem = slice->ptr; |
132 | 648 |
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
|
649 DVarValue* memval = new DVarValue(e1->getType(), mem); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
398
diff
changeset
|
650 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
|
651 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
652 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
|
653 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/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 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
|
655 |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
656 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
213
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 |
132 | 660 |
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
|
661 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
|
662 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
663 // 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
|
664 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
|
665 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
666 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
|
667 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); |
132 | 668 |
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
|
669 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
|
670 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
|
671 LLValue* mem = slice->ptr; |
132 | 672 |
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
|
673 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
|
674 |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
675 LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(src1->getType()->getContainedType(0))); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
676 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
|
677 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
|
678 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
679 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
|
680 DVarValue* memval = new DVarValue(e2->getType(), mem); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
398
diff
changeset
|
681 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
|
682 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
193
diff
changeset
|
683 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
|
684 } |
132 | 685 } |
686 | |
687 ////////////////////////////////////////////////////////////////////////////////////////// | |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
688 // 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
|
689 static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue* r, bool useti) |
40 | 690 { |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
162
diff
changeset
|
691 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
|
692 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, func); |
52 | 693 assert(fn); |
694 | |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
695 // find common dynamic array type |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
696 Type* commonType = l->getType()->toBasetype()->nextOf()->arrayOf(); |
52 | 697 |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
698 // 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
|
699 Logger::println("casting to dynamic arrays"); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
700 l = DtoCastArray(loc, l, commonType); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
701 r = DtoCastArray(loc, r, commonType); |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
162
diff
changeset
|
702 |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
703 LLValue* lmem; |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
704 LLValue* rmem; |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
705 LLSmallVector<LLValue*, 3> args; |
52 | 706 |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
707 // get values, reinterpret cast to void[] |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
708 lmem = DtoAggrPaint(l->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context()))); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
709 args.push_back(lmem); |
52 | 710 |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
711 rmem = DtoAggrPaint(r->getRVal(), DtoArrayType(LLType::getInt8Ty(gIR->context()))); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
712 args.push_back(rmem); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
713 |
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
|
714 // pass array typeinfo ? |
100 | 715 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
|
716 Type* t = l->getType(); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
717 LLValue* tival = DtoTypeInfoOf(t); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
718 // DtoTypeInfoOf only does declare, not enough in this case :/ |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1013
diff
changeset
|
719 t->vtinfo->codegen(Type::sir); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
720 |
1463 | 721 #if 0 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
722 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
723 Logger::cout() << "typeinfo decl: " << *tival << '\n'; |
1463 | 724 #endif |
100 | 725 |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
726 args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2))); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
727 } |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
728 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
729 LLCallSite 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
|
730 |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
731 return call.getInstruction(); |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
732 } |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
733 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
734 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
735 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
|
736 { |
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
|
737 LLValue* res = DtoArrayEqCmp_impl(loc, "_adEq", l, r, true); |
365 | 738 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
|
739 if (op == TOKnotequal) |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
740 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
|
741 |
297
5de180867c46
[svn r318] Moved the call to DtoBoolean before the not instruction.
ChristianK
parents:
296
diff
changeset
|
742 return res; |
52 | 743 } |
744 | |
745 ////////////////////////////////////////////////////////////////////////////////////////// | |
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
|
746 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
|
747 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
748 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
|
749 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
750 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
|
751 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
|
752 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
753 switch(op) |
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 case TOKlt: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
756 case TOKul: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
757 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
|
758 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
759 case TOKle: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
760 case TOKule: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
761 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
|
762 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
763 case TOKgt: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
764 case TOKug: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
765 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
|
766 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
767 case TOKge: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
768 case TOKuge: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
769 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
|
770 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
771 case TOKue: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
772 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
|
773 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
774 case TOKlg: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
775 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
|
776 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
777 case TOKleg: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
778 skip = true; |
1559
06d5cc873350
getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
779 res = LLConstantInt::getTrue(gIR->context()); |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
780 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
781 case TOKunord: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
782 skip = true; |
1559
06d5cc873350
getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents:
1554
diff
changeset
|
783 res = LLConstantInt::getFalse(gIR->context()); |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
784 break; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
785 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
786 default: |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
787 assert(0); |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
788 } |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
789 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
790 if (!skip) |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
791 { |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
792 Type* t = l->getType()->toBasetype()->nextOf()->toBasetype(); |
100 | 793 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
|
794 res = DtoArrayEqCmp_impl(loc, "_adCmpChar", l, r, false); |
100 | 795 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
|
796 res = DtoArrayEqCmp_impl(loc, "_adCmp", l, r, true); |
365 | 797 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
|
798 } |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
799 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
800 assert(res); |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
801 return res; |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
802 } |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
803 |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
804 ////////////////////////////////////////////////////////////////////////////////////////// |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
805 LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty) |
52 | 806 { |
182
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
807 Logger::println("DtoArrayCastLength"); |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
808 LOG_SCOPE; |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
809 |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
810 assert(len); |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
811 assert(elemty); |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
812 assert(newelemty); |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
813 |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
814 size_t esz = getTypePaddedSize(elemty); |
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
932
diff
changeset
|
815 size_t nsz = getTypePaddedSize(newelemty); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
88
diff
changeset
|
816 if (esz == nsz) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
88
diff
changeset
|
817 return len; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
88
diff
changeset
|
818 |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
213
diff
changeset
|
819 LLSmallVector<LLValue*, 3> args; |
52 | 820 args.push_back(len); |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1548
diff
changeset
|
821 args.push_back(LLConstantInt::get(DtoSize_t(), esz, false)); |
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1548
diff
changeset
|
822 args.push_back(LLConstantInt::get(DtoSize_t(), nsz, false)); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
88
diff
changeset
|
823 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
234
diff
changeset
|
824 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len"); |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
825 return gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp").getInstruction(); |
52 | 826 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
827 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
828 ////////////////////////////////////////////////////////////////////////////////////////// |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
829 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
|
830 { |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
831 LLValue *len1, *ptr1, *len2, *ptr2; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
832 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
833 assert(l); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
834 assert(r); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
835 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
836 // compare lengths |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
837 len1 = DtoArrayLen(l); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
838 len2 = DtoArrayLen(r); |
365 | 839 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
|
840 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
841 // compare pointers |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
842 ptr1 = DtoArrayPtr(l); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
843 ptr2 = DtoArrayPtr(r); |
365 | 844 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
|
845 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
846 // combine |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
847 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
|
848 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
849 // return result |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
850 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
|
851 } |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
58
diff
changeset
|
852 |
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
58
diff
changeset
|
853 ////////////////////////////////////////////////////////////////////////////////////////// |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
854 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
|
855 { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
109
diff
changeset
|
856 Logger::println("DtoArrayLen"); |
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
109
diff
changeset
|
857 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
|
858 |
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
|
859 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
|
860 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
|
861 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
|
862 return s->len; |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
863 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
|
864 return DtoConstSize_t(0); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
865 else if (v->isLVal()) |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
866 return DtoLoad(DtoGEPi(v->getLVal(), 0,0), ".len"); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
867 return gIR->ir->CreateExtractValue(v->getRVal(), 0, ".len"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
868 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
869 else if (t->ty == Tsarray) { |
116
fd7ad91fd713
[svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents:
109
diff
changeset
|
870 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
|
871 assert(!v->isNull()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
872 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
|
873 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
|
874 assert(t); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
875 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
|
876 } |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
877 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
|
878 return 0; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
879 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
880 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
881 ////////////////////////////////////////////////////////////////////////////////////////// |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
882 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
|
883 { |
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
|
884 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
|
885 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
|
886 |
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
|
887 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
|
888 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
|
889 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
|
890 return s->ptr; |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
891 else if (v->isNull()) |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
892 return getNullPtr(getPtrToType(DtoType(t->nextOf()))); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
893 else if (v->isLVal()) |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
894 return DtoLoad(DtoGEPi(v->getLVal(), 0,1), ".ptr"); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
683
diff
changeset
|
895 return gIR->ir->CreateExtractValue(v->getRVal(), 1, ".ptr"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
896 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
897 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
|
898 assert(!v->isSlice()); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
297
diff
changeset
|
899 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
|
900 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
|
901 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
902 assert(0); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
903 return 0; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
904 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
81
diff
changeset
|
905 |
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
|
906 ////////////////////////////////////////////////////////////////////////////////////////// |
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
|
907 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
|
908 { |
182
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
909 Logger::println("DtoCastArray"); |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
910 LOG_SCOPE; |
6526cf5bb2be
[svn r198] Fixed: doing a length-changing cast of a full slice segfaulted. eg:
lindquist
parents:
176
diff
changeset
|
911 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
912 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
|
913 |
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
|
914 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
|
915 Type* fromtype = u->getType()->toBasetype(); |
1441
a3af393d1936
Error on invalid array cast. See DMD3041.
Christian Kamm <kamm incasoftware de>
parents:
1381
diff
changeset
|
916 if (fromtype->ty != Tarray && fromtype->ty != Tsarray) { |
a3af393d1936
Error on invalid array cast. See DMD3041.
Christian Kamm <kamm incasoftware de>
parents:
1381
diff
changeset
|
917 error(loc, "can't cast %s to %s", u->getType()->toChars(), to->toChars()); |
a3af393d1936
Error on invalid array cast. See DMD3041.
Christian Kamm <kamm incasoftware de>
parents:
1381
diff
changeset
|
918 fatal(); |
a3af393d1936
Error on invalid array cast. See DMD3041.
Christian Kamm <kamm incasoftware de>
parents:
1381
diff
changeset
|
919 } |
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
|
920 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
921 LLValue* rval; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
211
diff
changeset
|
922 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
|
923 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
|
924 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
925 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
926 Logger::cout() << "from array or sarray" << '\n'; |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
927 |
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
|
928 if (totype->ty == Tpointer) { |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
929 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
930 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
|
931 rval = DtoArrayPtr(u); |
193
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
182
diff
changeset
|
932 if (rval->getType() != tolltype) |
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
182
diff
changeset
|
933 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
|
934 } |
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
|
935 else if (totype->ty == Tarray) { |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
936 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
611
diff
changeset
|
937 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
|
938 |
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
|
939 const LLType* ptrty = DtoArrayType(totype)->getContainedType(1); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
940 const LLType* ety = DtoTypeNotVoid(fromtype->nextOf()); |
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 |
1203
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
942 if (fromtype->ty == Tsarray) { |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
943 LLValue* uval = u->getRVal(); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
944 |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
945 if (Logger::enabled()) |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
946 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
947 |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
948 assert(isaPointer(uval->getType())); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
949 const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
950 |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
951 if(arrty->getNumElements()*fromtype->nextOf()->size() % totype->nextOf()->size() != 0) |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
952 { |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
953 error(loc, "invalid cast from '%s' to '%s', the element sizes don't line up", fromtype->toChars(), totype->toChars()); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
954 fatal(); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
955 } |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
956 |
1554
d6e8d5db259f
LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents:
1548
diff
changeset
|
957 rval2 = LLConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); |
1205
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
958 if (fromtype->nextOf()->size() != totype->nextOf()->size()) |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
959 rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0)); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
960 rval = DtoBitCast(uval, ptrty); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
961 } |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
962 else { |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
963 rval2 = DtoArrayLen(u); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
964 if (fromtype->nextOf()->size() != totype->nextOf()->size()) |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
965 rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0)); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
966 |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
967 rval = DtoArrayPtr(u); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
968 rval = DtoBitCast(rval, ptrty); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
969 } |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
970 isslice = true; |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
971 } |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
972 else if (totype->ty == Tsarray) { |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
973 if (Logger::enabled()) |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
974 Logger::cout() << "to sarray" << '\n'; |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
975 |
1205
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
976 size_t tosize = ((TypeSArray*)totype)->dim->toInteger(); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
977 |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
978 if (fromtype->ty == Tsarray) { |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
979 LLValue* uval = u->getRVal(); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
980 |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
981 if (Logger::enabled()) |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
982 Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
983 |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
984 assert(isaPointer(uval->getType())); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
985 const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
986 |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
987 /*if(arrty->getNumElements()*fromtype->nextOf()->size() != tosize*totype->nextOf()->size()) |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
988 { |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
989 error(loc, "invalid cast from '%s' to '%s', the sizes are not the same", fromtype->toChars(), totype->toChars()); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
990 fatal(); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
991 }*/ |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
992 |
1203
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
993 rval = DtoBitCast(uval, getPtrToType(tolltype)); |
d51b5fa41657
Implement static array -> static array cast. Fixes #223.
Christian Kamm <kamm incasoftware de>
parents:
1148
diff
changeset
|
994 } |
1205
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
995 else { |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
996 size_t i = (tosize * totype->nextOf()->size() - 1) / fromtype->nextOf()->size(); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
997 DConstValue index(Type::tsize_t, DtoConstSize_t(i)); |
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
998 DtoArrayBoundsCheck(loc, u, &index, false); |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
999 |
1205
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
1000 rval = DtoArrayPtr(u); |
1633
5c0cebff9be8
Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents:
1571
diff
changeset
|
1001 rval = DtoBitCast(rval, getPtrToType(tolltype)); |
1205
e45984519be7
Simplify array casts and implement dyn array -> static array.
Christian Kamm <kamm incasoftware de>
parents:
1203
diff
changeset
|
1002 } |
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
|
1003 } |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1004 else if (totype->ty == Tbool) { |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1005 // return (arr.ptr !is null) |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1006 LLValue* ptr = DtoArrayPtr(u); |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1007 LLConstant* nul = getNullPtr(ptr->getType()); |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1008 rval = gIR->ir->CreateICmpNE(ptr, nul, "tmp"); |
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
758
diff
changeset
|
1009 } |
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
|
1010 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
|
1011 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
|
1012 } |
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 |
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 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
|
1015 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
|
1016 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
|
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 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
|
1020 } |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1021 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1022 ////////////////////////////////////////////////////////////////////////////////////////// |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1023 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
|
1024 { |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1025 Type* arrty = arr->getType()->toBasetype(); |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1205
diff
changeset
|
1026 assert((arrty->ty == Tsarray || arrty->ty == Tarray) && |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1205
diff
changeset
|
1027 "Can only array bounds check for static or dynamic arrays"); |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1028 |
507
39dbe48d3fe2
Got rid of improper static array compile time index check.
Christian Kamm <kamm incasoftware de>
parents:
486
diff
changeset
|
1029 // 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
|
1030 // 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
|
1031 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1032 // runtime check |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1033 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1034 llvm::BasicBlock* oldend = gIR->scopeend(); |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
1035 llvm::BasicBlock* failbb = llvm::BasicBlock::Create(gIR->context(), "arrayboundscheckfail", gIR->topfunc(), oldend); |
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1569
diff
changeset
|
1036 llvm::BasicBlock* okbb = llvm::BasicBlock::Create(gIR->context(), "arrayboundsok", gIR->topfunc(), oldend); |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1037 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1038 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
|
1039 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
|
1040 gIR->ir->CreateCondBr(cond, okbb, failbb); |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1041 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1042 // 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
|
1043 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1044 gIR->scope() = IRScope(failbb, okbb); |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1045 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1046 std::vector<LLValue*> args; |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1047 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1048 // file param |
1381
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1049 // we might be generating for an imported template function |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1205
diff
changeset
|
1050 Module* funcmodule = gIR->func()->decl->getModule(); |
1381
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1051 const char* cur_file = funcmodule->srcfile->name->toChars(); |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1052 if (loc.filename && strcmp(loc.filename, cur_file) != 0) |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1053 { |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1054 args.push_back(DtoConstString(loc.filename)); |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1055 } |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1056 else |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1057 { |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1058 IrModule* irmod = getIrModule(funcmodule); |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1059 args.push_back(DtoLoad(irmod->fileName)); |
44c8eef6e6ee
Fixed filename in array bounds check for mixed in imported template function. Fixes ticket #295 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1372
diff
changeset
|
1060 } |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1061 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1062 // line param |
683
b411c41a9716
Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents:
655
diff
changeset
|
1063 LLConstant* c = DtoConstUint(loc.linnum); |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1064 args.push_back(c); |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1065 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1066 // call |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1067 llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds"); |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
1068 gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end()); |
442
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1069 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1070 // the function does not return |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1071 gIR->ir->CreateUnreachable(); |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1072 |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1073 // if ok, proceed in okbb |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1074 gIR->scope() = IRScope(okbb, oldend); |
76078c8ab5b9
Move DtoArrayBoundsCheck from llvmhelpers to arrays.
Christian Kamm <kamm incasoftware de>
parents:
425
diff
changeset
|
1075 } |