annotate gen/aa.cpp @ 1579:819b4f961711

fix newline warning
author Moritz Warning <moritzwarning@web.de>
date Wed, 09 Sep 2009 02:03:24 +0200
parents 8d086d552909
children 8f121883bce8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
36 LLValue* tmp = DtoAlloca(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) {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
44 LLValue* tmp = DtoAlloca(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
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
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
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
54 {
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
55 // keyti param
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
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
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
58 }
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
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
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
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
67 // 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
68
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
69 // 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
70 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
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
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
81 // pkey param
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 315
diff changeset
82 LLValue* pkey = to_pkey(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
83 pkey = DtoBitCast(pkey, funcTy->getParamType(lvalue ? 3 : 2));
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
84
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
85 // 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
86 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
87 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
88 // 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
89 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
90
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
91 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
92 } 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
93 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
94 }
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
95
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
96 // cast return value
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
97 const LLType* targettype = getPtrToType(DtoType(type));
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
98 if (ret->getType() != targettype)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
99 ret = DtoBitCast(ret, targettype);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
100
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
101 // 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
102 // 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
103 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
104 llvm::BasicBlock* oldend = gIR->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
105 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
106 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
107
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1535
diff changeset
108 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
109 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
110 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
111
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 // 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
113
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 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
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 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
117
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 // 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
119 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
120 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
121
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 // 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
123 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
124 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
125
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 // 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
127 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
128 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
129
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 // 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
131 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
132
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
133 // 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
134 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
135 }
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
136 return new DVarValue(type, ret);
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
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
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 315
diff changeset
141 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
142 {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
143 // call:
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
144 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
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 // first get the runtime function
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
147 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn");
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
148 const llvm::FunctionType* funcTy = func->getFunctionType();
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
149
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 Logger::cout() << "_aaIn = " << *func << '\n';
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
152
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
153 // aa param
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
154 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
155 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
156 {
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 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
158 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
159 }
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
160 aaval = DtoBitCast(aaval, funcTy->getParamType(0));
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
161
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
162 // keyti param
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
163 LLValue* keyti = to_keyti(key);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
164 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
165
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
166 // pkey param
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 315
diff changeset
167 LLValue* pkey = to_pkey(loc, key);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
168 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
169
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
170 // call runtime
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 945
diff changeset
171 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
172
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
173 // cast return value
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
174 const LLType* targettype = DtoType(type);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
175 if (ret->getType() != targettype)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
176 ret = DtoBitCast(ret, targettype);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
177
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
178 return new DImValue(type, ret);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
179 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
180
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
diff changeset
181 /////////////////////////////////////////////////////////////////////////////////////
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
182
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 315
diff changeset
183 void DtoAARemove(Loc& loc, DValue* aa, DValue* key)
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
184 {
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
185 // call:
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
186 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey)
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
187
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
188 // first get the runtime function
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
189 llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel");
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
190 const llvm::FunctionType* funcTy = func->getFunctionType();
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
191
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 Logger::cout() << "_aaDel = " << *func << '\n';
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
194
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
195 // aa param
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
196 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
197 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
198 {
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
199 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
200 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
201 }
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
202 aaval = DtoBitCast(aaval, funcTy->getParamType(0));
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
203
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
204 // keyti param
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
205 LLValue* keyti = to_keyti(key);
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
206 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
207
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
208 // pkey param
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 315
diff changeset
209 LLValue* pkey = to_pkey(loc, key);
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
210 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
211
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
212 // build arg vector
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
213 LLSmallVector<LLValue*, 3> args;
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
214 args.push_back(aaval);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
215 args.push_back(keyti);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
216 args.push_back(pkey);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
217
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
218 // call runtime
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 275
diff changeset
219 gIR->CreateCallOrInvoke(func, args.begin(), args.end());
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 109
diff changeset
220 }
1512
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
221
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
222 /////////////////////////////////////////////////////////////////////////////////////
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
223
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
224 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
225 {
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
226 Type* t = l->getType()->toBasetype();
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
227 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
228
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
229 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
230 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
231
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
232 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
233 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
234 LLValue* aaTypeInfo = DtoTypeInfoOf(t);
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
235 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
236
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
237 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
238 if (op == TOKnotequal)
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1418
diff changeset
239 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
240 return res;
1579
819b4f961711 fix newline warning
Moritz Warning <moritzwarning@web.de>
parents: 1571
diff changeset
241 }