Mercurial > projects > ldc
annotate gen/aa.cpp @ 1138:4c8bb03e4fbc
Update DtoConstFP() to be correct after LLVM r67562, which changed the way the
APFloat constructor expects its i80 APInts to be formatted. (They're now
actually consistent with the x87 format)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Tue, 24 Mar 2009 15:24:59 +0100 |
parents | d584cda84b00 |
children | 0686701178d3 |
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 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
17 // makes sure the key value lives in memory so it can be passed to the runtime functions without problems |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
18 // returns the pointer |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
19 static LLValue* to_pkey(Loc& loc, DValue* key) |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
20 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
21 Type* keytype = key->getType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
22 bool needmem = !DtoIsPassedByRef(keytype); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
23 LLValue* pkey; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
24 if (key->isIm()) { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
25 pkey = key->getRVal(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
26 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
27 else if (DVarValue* var = key->isVar()) { |
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
|
28 pkey = key->getLVal(); |
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
|
29 needmem = false; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
30 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
31 else if (key->isConst()) { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
32 needmem = true; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
33 pkey = key->getRVal(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
34 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
35 else { |
479
672eb4893b55
Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents:
468
diff
changeset
|
36 LLValue* tmp = DtoAlloca(DtoType(keytype), "aatmpkeystorage"); |
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
|
37 DVarValue var(keytype, tmp); |
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
|
38 DtoAssign(loc, &var, key); |
168
08cfde5f70d3
[svn r184] fixed an AA helper for giving keys storage, which the runtime needs. tango.text.UnicodeData now compiles.
lindquist
parents:
163
diff
changeset
|
39 return tmp; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
40 } |
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 // give memory |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
43 if (needmem) { |
479
672eb4893b55
Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents:
468
diff
changeset
|
44 LLValue* tmp = DtoAlloca(DtoType(keytype), "aatmpkeystorage"); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
45 DtoStore(pkey, tmp); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
46 pkey = tmp; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
47 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
48 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
49 return pkey; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
50 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
51 |
127 | 52 // returns the keytype typeinfo |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
53 static LLValue* to_keyti(DValue* key) |
127 | 54 { |
55 // keyti param | |
56 Type* keytype = key->getType(); | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
57 return DtoTypeInfoOf(keytype, false); |
127 | 58 } |
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 |
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
|
62 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
|
63 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
64 // 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
|
65 // 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
|
66 // or |
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
|
67 // extern(C) void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey) |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
68 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
69 // first get the runtime function |
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
|
70 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaGetRvalue"); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
71 const llvm::FunctionType* funcTy = func->getFunctionType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
72 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
73 // 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
|
74 LLValue* aaval = lvalue ? aa->getLVal() : aa->getRVal(); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
75 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
76 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
77 // keyti param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
78 LLValue* keyti = to_keyti(key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
79 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
80 |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
156
diff
changeset
|
81 // valuesize param |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
622
diff
changeset
|
82 LLValue* valsize = DtoConstSize_t(getTypePaddedSize(DtoType(type))); |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
156
diff
changeset
|
83 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
84 // pkey param |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
85 LLValue* pkey = to_pkey(loc, key); |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
156
diff
changeset
|
86 pkey = DtoBitCast(pkey, funcTy->getParamType(3)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
87 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
88 // call runtime |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
89 LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index").getInstruction(); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
90 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
91 // cast return value |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
92 const LLType* targettype = getPtrToType(DtoType(type)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
93 if (ret->getType() != targettype) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
94 ret = DtoBitCast(ret, targettype); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
95 |
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
|
96 // 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
|
97 // 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
|
98 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
|
99 llvm::BasicBlock* oldend = gIR->scopeend(); |
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 llvm::BasicBlock* failbb = llvm::BasicBlock::Create("aaboundscheckfail", gIR->topfunc(), 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
|
101 llvm::BasicBlock* okbb = llvm::BasicBlock::Create("aaboundsok", gIR->topfunc(), 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
|
102 |
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
|
103 LLValue* nullaa = LLConstant::getNullValue(ret->getType()); |
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
|
104 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
|
105 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
|
106 |
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
|
107 // 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
|
108 |
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
|
109 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
|
110 |
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
|
111 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
|
112 |
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
|
113 // file 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
|
114 args.push_back(DtoLoad(gIR->dmodule->ir.irModule->fileName)); |
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
|
115 |
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
|
116 // 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
|
117 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
|
118 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
|
119 |
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
|
120 // 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
|
121 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
|
122 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
|
123 |
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
|
124 // 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
|
125 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
|
126 |
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
|
127 // 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
|
128 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
|
129 } |
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
|
130 return new DVarValue(type, ret); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
131 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
132 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
133 ///////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
134 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
135 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
|
136 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
137 // call: |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
138 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
139 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
140 // first get the runtime function |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
141 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn"); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
142 const llvm::FunctionType* funcTy = func->getFunctionType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
143 |
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
|
144 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
|
145 Logger::cout() << "_aaIn = " << *func << '\n'; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
146 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
147 // aa param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
148 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
|
149 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
|
150 { |
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
|
151 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
|
152 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
|
153 } |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
154 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
155 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
156 // keyti param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
157 LLValue* keyti = to_keyti(key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
158 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
159 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
160 // pkey param |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
161 LLValue* pkey = to_pkey(loc, key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
162 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
163 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
164 // call runtime |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
165 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
|
166 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
167 // cast return value |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
168 const LLType* targettype = DtoType(type); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
169 if (ret->getType() != targettype) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
170 ret = DtoBitCast(ret, targettype); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
171 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
172 return new DImValue(type, ret); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
173 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
174 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
175 ///////////////////////////////////////////////////////////////////////////////////// |
127 | 176 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
177 void DtoAARemove(Loc& loc, DValue* aa, DValue* key) |
127 | 178 { |
179 // call: | |
180 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) | |
181 | |
182 // first get the runtime function | |
183 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel"); | |
184 const llvm::FunctionType* funcTy = func->getFunctionType(); | |
185 | |
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
|
186 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
|
187 Logger::cout() << "_aaDel = " << *func << '\n'; |
127 | 188 |
189 // aa param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
190 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
|
191 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
|
192 { |
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
|
193 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
|
194 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
|
195 } |
127 | 196 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
197 | |
198 // keyti param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
199 LLValue* keyti = to_keyti(key); |
127 | 200 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
201 | |
202 // pkey param | |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
203 LLValue* pkey = to_pkey(loc, key); |
127 | 204 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
205 | |
206 // build arg vector | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
207 LLSmallVector<LLValue*, 3> args; |
127 | 208 args.push_back(aaval); |
209 args.push_back(keyti); | |
210 args.push_back(pkey); | |
211 | |
212 // call runtime | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
275
diff
changeset
|
213 gIR->CreateCallOrInvoke(func, args.begin(), args.end()); |
127 | 214 } |