[svn r131] Fixed #11

All associative array properties now work as they should.

Fixed problems with some cases of array.length and array.ptr.

Fixed some problems with array properties.

Fixed 'in' contracts.
This commit is contained in:
Tomas Lindquist Olsen
2007-11-30 12:56:52 +01:00
parent 32ebd9617e
commit 0a226c956f
10 changed files with 169 additions and 61 deletions

View File

@@ -48,6 +48,20 @@ static llvm::Value* to_pkey(DValue* key)
return pkey;
}
// returns the keytype typeinfo
static llvm::Value* to_keyti(DValue* key)
{
// keyti param
Type* keytype = key->getType();
keytype->getTypeInfo(NULL);
TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration();
assert(tid);
DtoResolveDsymbol(Type::typeinfo);
DtoForceDeclareDsymbol(tid);
assert(tid->llvmValue);
return tid->llvmValue;
}
/////////////////////////////////////////////////////////////////////////////////////
DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
@@ -64,14 +78,7 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param
Type* keytype = key->getType();
keytype->getTypeInfo(NULL);
TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration();
assert(tid);
DtoResolveDsymbol(Type::typeinfo);
DtoForceDeclareDsymbol(tid);
assert(tid->llvmValue);
llvm::Value* keyti = tid->llvmValue;
llvm::Value* keyti = to_keyti(key);
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
// pkey param
@@ -89,7 +96,7 @@ DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key)
args.push_back(valsize);
// call runtime
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aaGet");
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index");
// cast return value
const llvm::Type* targettype = llvm::PointerType::get(DtoType(type));
@@ -119,14 +126,7 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key)
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param
Type* keytype = key->getType();
keytype->getTypeInfo(NULL);
TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration();
assert(tid);
DtoResolveDsymbol(Type::typeinfo);
DtoForceDeclareDsymbol(tid);
assert(tid->llvmValue);
llvm::Value* keyti = tid->llvmValue;
llvm::Value* keyti = to_keyti(key);
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
// pkey param
@@ -140,7 +140,7 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key)
args.push_back(pkey);
// call runtime
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aaIn");
llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in");
// cast return value
const llvm::Type* targettype = DtoType(type);
@@ -151,3 +151,38 @@ DValue* DtoAAIn(Type* type, DValue* aa, DValue* key)
}
/////////////////////////////////////////////////////////////////////////////////////
void DtoAARemove(DValue* aa, DValue* key)
{
// call:
// extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey)
// first get the runtime function
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel");
const llvm::FunctionType* funcTy = func->getFunctionType();
Logger::cout() << "_aaDel = " << *func << '\n';
// aa param
llvm::Value* aaval = aa->getRVal();
Logger::cout() << "aaval: " << *aaval << '\n';
Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n';
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param
llvm::Value* keyti = to_keyti(key);
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
// pkey param
llvm::Value* pkey = to_pkey(key);
pkey = DtoBitCast(pkey, funcTy->getParamType(2));
// build arg vector
std::vector<llvm::Value*> args;
args.push_back(aaval);
args.push_back(keyti);
args.push_back(pkey);
// call runtime
gIR->ir->CreateCall(func, args.begin(), args.end(),"");
}

View File

@@ -3,5 +3,6 @@
DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key);
DValue* DtoAAIn(Type* type, DValue* aa, DValue* key);
void DtoAARemove(DValue* aa, DValue* key);
#endif // LLVMDC_GEN_AA_H

View File

@@ -808,8 +808,10 @@ llvm::Value* DtoArrayLen(DValue* v)
return s->len;
}
const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0));
assert(arrTy);
return DtoConstSize_t(arrTy->getNumElements());
if (arrTy)
return DtoConstSize_t(arrTy->getNumElements());
else
return DtoLoad(DtoGEPi(s->ptr, 0,0, "tmp"));
}
return DtoLoad(DtoGEPi(v->getRVal(), 0,0, "tmp"));
}
@@ -831,9 +833,13 @@ llvm::Value* DtoArrayPtr(DValue* v)
if (t->ty == Tarray) {
if (DSliceValue* s = v->isSlice()) {
if (s->len) return s->ptr;
const llvm::Type* t = s->ptr->getType()->getContainedType(0);
Logger::cout() << "ptr of full slice: " << *s->ptr << '\n';
const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0));
assert(arrTy);
return DtoGEPi(s->ptr, 0,0, "tmp");
if (arrTy)
return DtoGEPi(s->ptr, 0,0, "tmp");
else
return DtoLoad(DtoGEPi(s->ptr, 0,1, "tmp"));
}
return DtoLoad(DtoGEPi(v->getRVal(), 0,1, "tmp"));
}

View File

@@ -256,6 +256,8 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
if (fdecl->llvmRunTimeHack) {
gIR->declareList.push_back(fdecl);
TypeFunction* tf = (TypeFunction*)fdecl->type;
tf->llvmRetInPtr = DtoIsPassedByRef(tf->next);
return;
}

View File

@@ -904,7 +904,7 @@ DValue* CallExp::toElem(IRState* p)
Logger::cout() << "what are we calling? : " << *funcval << '\n';
}
assert(llfnty);
//Logger::cout() << "Function LLVM type: " << *llfnty << '\n';
Logger::cout() << "Function LLVM type: " << *llfnty << '\n';
// argument handling
llvm::FunctionType::param_iterator argiter = llfnty->param_begin();
@@ -2572,6 +2572,19 @@ DValue* InExp::toElem(IRState* p)
return DtoAAIn(type, aa, key);
}
DValue* RemoveExp::toElem(IRState* p)
{
Logger::print("RemoveExp::toElem: %s\n", toChars());
LOG_SCOPE;
DValue* aa = e1->toElem(p);
DValue* key = e2->toElem(p);
DtoAARemove(aa, key);
return NULL; // does not produce anything useful
}
//////////////////////////////////////////////////////////////////////////////////////////
DValue* AssocArrayLiteralExp::toElem(IRState* p)
@@ -2583,6 +2596,20 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p)
assert(values);
assert(keys->dim == values->dim);
Type* aatype = DtoDType(type);
Type* vtype = aatype->next;
DValue* aa;
if (p->topexp() && p->topexp()->e2 == this)
{
aa = p->topexp()->v;
}
else
{
llvm::Value* tmp = new llvm::AllocaInst(DtoType(type),"aaliteral",p->topallocapoint());
aa = new DVarValue(type, tmp, true);
}
const size_t n = keys->dim;
for (size_t i=0; i<n; ++i)
{
@@ -2590,9 +2617,17 @@ DValue* AssocArrayLiteralExp::toElem(IRState* p)
Expression* eval = (Expression*)values->data[i];
Logger::println("(%u) aa[%s] = %s", i, ekey->toChars(), eval->toChars());
// index
DValue* key = ekey->toElem(p);
DValue* mem = DtoAAIndex(vtype, aa, key);
// store
DValue* val = eval->toElem(p);
DtoAssign(mem, val);
}
assert(0);
return aa;
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -2666,7 +2701,7 @@ STUB(BoolExp);
//STUB(CommaExp);
//STUB(ArrayLengthExp);
//STUB(HaltExp);
STUB(RemoveExp);
//STUB(RemoveExp);
//STUB(ArrayLiteralExp);
//STUB(AssocArrayLiteralExp);
//STUB(StructLiteralExp);