Mercurial > projects > ldc
annotate gen/aa.cpp @ 1643:8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Mon, 08 Mar 2010 23:37:40 -0700 |
parents | 819b4f961711 |
children |
rev | line source |
---|---|
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
1 #include "gen/llvm.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
2 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
3 #include "mtype.h" |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
4 #include "module.h" |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
5 #include "declaration.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
6 #include "aggregate.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
7 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
8 #include "gen/aa.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
9 #include "gen/runtime.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
10 #include "gen/tollvm.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
11 #include "gen/llvmhelpers.h" |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
12 #include "gen/logger.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
13 #include "gen/irstate.h" |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
14 #include "gen/dvalue.h" |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
15 #include "ir/irmodule.h" |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
16 |
127 | 17 // returns the keytype typeinfo |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
18 static LLValue* to_keyti(DValue* key) |
127 | 19 { |
20 // keyti param | |
21 Type* keytype = key->getType(); | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
22 return DtoTypeInfoOf(keytype, false); |
127 | 23 } |
24 | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
25 ///////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
26 |
458
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
455
diff
changeset
|
27 DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue) |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
28 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
29 // call: |
458
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
455
diff
changeset
|
30 // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey) |
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
455
diff
changeset
|
31 // or |
1418
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
32 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
33 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
34 // first get the runtime function |
1418
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
35 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaIn"); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
36 const llvm::FunctionType* funcTy = func->getFunctionType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
37 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
38 // aa param |
458
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
455
diff
changeset
|
39 LLValue* aaval = lvalue ? aa->getLVal() : aa->getRVal(); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
40 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
41 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
42 // keyti param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
43 LLValue* keyti = to_keyti(key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
44 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
45 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
46 // pkey param |
1643
8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1579
diff
changeset
|
47 LLValue* pkey = makeLValue(loc, key); |
1418
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
48 pkey = DtoBitCast(pkey, funcTy->getParamType(lvalue ? 3 : 2)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
49 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
50 // call runtime |
1418
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
51 LLValue* ret; |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
52 if (lvalue) { |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
53 // valuesize param |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
54 LLValue* valsize = DtoConstSize_t(getTypePaddedSize(DtoType(type))); |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
55 |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
56 ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index").getInstruction(); |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
57 } else { |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
58 ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.index").getInstruction(); |
f5f8c21ce6ef
Make "`aa[key]`" use the same runtime call as "`key in aa`". The runtime calls
Frits van Bommel <fvbommel wxs.nl>
parents:
1350
diff
changeset
|
59 } |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
60 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
61 // cast return value |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
62 const LLType* targettype = getPtrToType(DtoType(type)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
63 if (ret->getType() != targettype) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
64 ret = DtoBitCast(ret, targettype); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
65 |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
66 // Only check bounds for rvalues ('aa[key]'). |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
67 // Lvalue use ('aa[key] = value') auto-adds an element. |
1116
d584cda84b00
Disable this for -release, -disable-boundscheck, etc.
Frits van Bommel <fvbommel wxs.nl>
parents:
1115
diff
changeset
|
68 if (!lvalue && global.params.useArrayBounds) { |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
69 llvm::BasicBlock* oldend = gIR->scopeend(); |
1571
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
70 llvm::BasicBlock* failbb = llvm::BasicBlock::Create(gIR->context(), "aaboundscheckfail", gIR->topfunc(), oldend); |
8d086d552909
IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents:
1560
diff
changeset
|
71 llvm::BasicBlock* okbb = llvm::BasicBlock::Create(gIR->context(), "aaboundsok", gIR->topfunc(), oldend); |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
72 |
1560
1d5c3354b3c2
getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents:
1535
diff
changeset
|
73 LLValue* nullaa = LLConstant::getNullValue(ret->getType()); |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
74 LLValue* cond = gIR->ir->CreateICmpNE(nullaa, ret, "aaboundscheck"); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
75 gIR->ir->CreateCondBr(cond, okbb, failbb); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
76 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
77 // set up failbb to call the array bounds error runtime function |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
78 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
79 gIR->scope() = IRScope(failbb, okbb); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
80 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
81 std::vector<LLValue*> args; |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
82 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
83 // file param |
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:
1116
diff
changeset
|
84 IrModule* irmod = getIrModule(NULL); |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1116
diff
changeset
|
85 args.push_back(DtoLoad(irmod->fileName)); |
1115
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
86 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
87 // line param |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
88 LLConstant* c = DtoConstUint(loc.linnum); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
89 args.push_back(c); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
90 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
91 // call |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
92 llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds"); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
93 gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end()); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
94 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
95 // the function does not return |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
96 gIR->ir->CreateUnreachable(); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
97 |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
98 // if ok, proceed in okbb |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
99 gIR->scope() = IRScope(okbb, oldend); |
af625ea2d3cf
Call _d_array_bounds when an associative array is indexed with a non-existent
Frits van Bommel <fvbommel wxs.nl>
parents:
1013
diff
changeset
|
100 } |
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:
479
diff
changeset
|
101 return new DVarValue(type, ret); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
102 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
103 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
104 ///////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
105 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
106 DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key) |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
107 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
108 // call: |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
109 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
110 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
111 // first get the runtime function |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
112 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn"); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
113 const llvm::FunctionType* funcTy = func->getFunctionType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
114 |
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:
585
diff
changeset
|
115 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:
585
diff
changeset
|
116 Logger::cout() << "_aaIn = " << *func << '\n'; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
117 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
118 // aa param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
119 LLValue* aaval = aa->getRVal(); |
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:
585
diff
changeset
|
120 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:
585
diff
changeset
|
121 { |
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:
585
diff
changeset
|
122 Logger::cout() << "aaval: " << *aaval << '\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:
585
diff
changeset
|
123 Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\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:
585
diff
changeset
|
124 } |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
125 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
126 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
127 // keyti param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
128 LLValue* keyti = to_keyti(key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
129 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
130 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
131 // pkey param |
1643
8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1579
diff
changeset
|
132 LLValue* pkey = makeLValue(loc, key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
133 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
134 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
135 // call runtime |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
136 LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction(); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
137 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
138 // cast return value |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
139 const LLType* targettype = DtoType(type); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
140 if (ret->getType() != targettype) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
141 ret = DtoBitCast(ret, targettype); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
142 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
143 return new DImValue(type, ret); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
144 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
145 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
146 ///////////////////////////////////////////////////////////////////////////////////// |
127 | 147 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
148 void DtoAARemove(Loc& loc, DValue* aa, DValue* key) |
127 | 149 { |
150 // call: | |
151 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) | |
152 | |
153 // first get the runtime function | |
154 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel"); | |
155 const llvm::FunctionType* funcTy = func->getFunctionType(); | |
156 | |
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:
585
diff
changeset
|
157 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:
585
diff
changeset
|
158 Logger::cout() << "_aaDel = " << *func << '\n'; |
127 | 159 |
160 // aa param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
161 LLValue* aaval = aa->getRVal(); |
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:
585
diff
changeset
|
162 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:
585
diff
changeset
|
163 { |
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:
585
diff
changeset
|
164 Logger::cout() << "aaval: " << *aaval << '\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:
585
diff
changeset
|
165 Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\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:
585
diff
changeset
|
166 } |
127 | 167 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
168 | |
169 // keyti param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
170 LLValue* keyti = to_keyti(key); |
127 | 171 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
172 | |
173 // pkey param | |
1643
8f121883bce8
Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1579
diff
changeset
|
174 LLValue* pkey = makeLValue(loc, key); |
127 | 175 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
176 | |
177 // build arg vector | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
178 LLSmallVector<LLValue*, 3> args; |
127 | 179 args.push_back(aaval); |
180 args.push_back(keyti); | |
181 args.push_back(pkey); | |
182 | |
183 // call runtime | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
275
diff
changeset
|
184 gIR->CreateCallOrInvoke(func, args.begin(), args.end()); |
127 | 185 } |
1512
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
186 |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
187 ///////////////////////////////////////////////////////////////////////////////////// |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
188 |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
189 LLValue* DtoAAEquals(Loc& loc, TOK op, DValue* l, DValue* r) |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
190 { |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
191 Type* t = l->getType()->toBasetype(); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
192 assert(t == r->getType()->toBasetype() && "aa equality is only defined for aas of same type"); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
193 |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
194 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaEq"); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
195 const llvm::FunctionType* funcTy = func->getFunctionType(); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
196 |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
197 LLValue* aaval = DtoBitCast(l->getRVal(), funcTy->getParamType(0)); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
198 LLValue* abval = DtoBitCast(r->getRVal(), funcTy->getParamType(1)); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
199 LLValue* aaTypeInfo = DtoTypeInfoOf(t); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
200 LLValue* res = gIR->CreateCallOrInvoke3(func, aaval, abval, aaTypeInfo, "aaEqRes").getInstruction(); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
201 |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
202 res = gIR->ir->CreateICmpNE(res, DtoConstInt(0), "tmp"); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
203 if (op == TOKnotequal) |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
204 res = gIR->ir->CreateNot(res, "tmp"); |
09734fb929c0
Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents:
1418
diff
changeset
|
205 return res; |
1579 | 206 } |