Store bools as i8.

I really hope we can refactor this to use a less leaky
abstraction later – it should at least be possible to merge
voidToI8 and i1ToI8.
This commit is contained in:
David Nadlinger
2013-06-06 21:14:46 +02:00
parent 7e92984ebe
commit 848dee32d4
16 changed files with 105 additions and 60 deletions

View File

@@ -18,18 +18,36 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
static bool checkVarValueType(LLType* t, bool extraDeref)
{
if (extraDeref)
{
llvm::PointerType* pt = llvm::dyn_cast<llvm::PointerType>(t);
if (!pt) return false;
t = pt->getElementType();
}
llvm::PointerType* pt = llvm::dyn_cast<llvm::PointerType>(t);
if (!pt) return false;
// bools should not be stored as i1 any longer.
if (pt->getElementType() == llvm::Type::getInt1Ty(gIR->context()))
return false;
return true;
}
DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue)
: DValue(t), var(vd), val(llvmValue)
{
assert(isaPointer(llvmValue));
assert(!isSpecialRefVar(vd) ||
isaPointer(isaPointer(llvmValue)->getElementType()));
assert(checkVarValueType(llvmValue->getType(), isSpecialRefVar(vd)));
}
DVarValue::DVarValue(Type* t, LLValue* llvmValue)
: DValue(t), var(0), val(llvmValue)
{
assert(isaPointer(llvmValue));
assert(checkVarValueType(llvmValue->getType(), false));
}
LLValue* DVarValue::getLVal()
@@ -50,7 +68,17 @@ LLValue* DVarValue::getRVal()
if (DtoIsPassedByRef(type->toBasetype()))
return storage;
return DtoLoad(storage);
llvm::Value* rawValue = DtoLoad(storage);
if (type->toBasetype()->ty == Tbool)
{
assert(rawValue->getType() == llvm::Type::getInt8Ty(gIR->context()));
return gIR->ir->CreateTrunc(rawValue,
llvm::Type::getInt1Ty(gIR->context()));
}
return rawValue;
}
LLValue* DVarValue::getRefStorage()