Fixed AA Rvalue-only access (like indexing an AA return value immediately).

This commit is contained in:
Tomas Lindquist Olsen
2008-08-02 22:35:24 +02:00
parent 00072e5fd0
commit 1ee9104354
3 changed files with 9 additions and 7 deletions

View File

@@ -66,17 +66,19 @@ static LLValue* to_keyti(DValue* key)
/////////////////////////////////////////////////////////////////////////////////////
DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key)
DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
{
// call:
// extern(C) void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize)
// extern(C) void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey)
// or
// extern(C) void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey)
// first get the runtime function
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaGet");
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaGetRvalue");
const llvm::FunctionType* funcTy = func->getFunctionType();
// aa param
LLValue* aaval = aa->getLVal();
LLValue* aaval = lvalue ? aa->getLVal() : aa->getRVal();
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param

View File

@@ -1,7 +1,7 @@
#ifndef LLVMDC_GEN_AA_H
#define LLVMDC_GEN_AA_H
DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key);
DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue);
DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key);
void DtoAARemove(Loc& loc, DValue* aa, DValue* key);

View File

@@ -1034,7 +1034,7 @@ DValue* IndexExp::toElem(IRState* p)
arrptr = DtoGEP1(arrptr,r->getRVal());
}
else if (e1type->ty == Taarray) {
return DtoAAIndex(loc, type, l, r);
return DtoAAIndex(loc, type, l, r, modifiable);
}
else {
Logger::println("invalid index exp! e1type: %s", e1type->toChars());
@@ -2255,7 +2255,7 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p)
// index
DValue* key = ekey->toElem(p);
DValue* mem = DtoAAIndex(loc, vtype, aa, key);
DValue* mem = DtoAAIndex(loc, vtype, aa, key, true);
// store
DValue* val = eval->toElem(p);