Mercurial > projects > ldc
annotate gen/aa.cpp @ 1302:a26b99b7e293
Translate fsub/fdiv correctly. See #256.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 06 May 2009 18:08:44 +0200 |
parents | 0686701178d3 |
children | 15e9762bb620 |
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 |
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
|
114 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
|
115 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
|
116 |
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 // 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
|
118 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
|
119 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
|
120 |
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 // 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
|
122 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
|
123 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
|
124 |
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 // 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
|
126 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
|
127 |
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 // 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
|
129 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
|
130 } |
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
|
131 return new DVarValue(type, ret); |
109
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 ///////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
135 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
136 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
|
137 { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
138 // call: |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
139 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
140 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
141 // first get the runtime function |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
142 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn"); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
143 const llvm::FunctionType* funcTy = func->getFunctionType(); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
144 |
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
|
145 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
|
146 Logger::cout() << "_aaIn = " << *func << '\n'; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
147 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
148 // aa param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
149 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
|
150 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
|
151 { |
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() << "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
|
153 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
|
154 } |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
155 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
156 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
157 // keyti param |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
158 LLValue* keyti = to_keyti(key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
159 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
160 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
161 // pkey param |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
162 LLValue* pkey = to_pkey(loc, key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
163 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
164 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
165 // call runtime |
1013
8c73ff5f69e0
Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents:
945
diff
changeset
|
166 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
|
167 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
168 // cast return value |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
169 const LLType* targettype = DtoType(type); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
170 if (ret->getType() != targettype) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
171 ret = DtoBitCast(ret, targettype); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
172 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
173 return new DImValue(type, ret); |
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 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff
changeset
|
176 ///////////////////////////////////////////////////////////////////////////////////// |
127 | 177 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
178 void DtoAARemove(Loc& loc, DValue* aa, DValue* key) |
127 | 179 { |
180 // call: | |
181 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) | |
182 | |
183 // first get the runtime function | |
184 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel"); | |
185 const llvm::FunctionType* funcTy = func->getFunctionType(); | |
186 | |
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
|
187 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
|
188 Logger::cout() << "_aaDel = " << *func << '\n'; |
127 | 189 |
190 // aa param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
191 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
|
192 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
|
193 { |
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() << "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
|
195 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
|
196 } |
127 | 197 aaval = DtoBitCast(aaval, funcTy->getParamType(0)); |
198 | |
199 // keyti param | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
200 LLValue* keyti = to_keyti(key); |
127 | 201 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); |
202 | |
203 // pkey param | |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
315
diff
changeset
|
204 LLValue* pkey = to_pkey(loc, key); |
127 | 205 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); |
206 | |
207 // build arg vector | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
208 LLSmallVector<LLValue*, 3> args; |
127 | 209 args.push_back(aaval); |
210 args.push_back(keyti); | |
211 args.push_back(pkey); | |
212 | |
213 // call runtime | |
315
a9697749e898
[svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents:
275
diff
changeset
|
214 gIR->CreateCallOrInvoke(func, args.begin(), args.end()); |
127 | 215 } |