From 625f28814d4e331d4d989c090d6eebc2a2cc916d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 15 Jul 2008 14:53:16 +0200 Subject: [PATCH] [svn r393] Started implementation for DtoNullValue. --- gen/llvmhelpers.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++-- gen/llvmhelpers.h | 3 +++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 4e0337d1..316b683c 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -628,6 +628,49 @@ void DtoAssign(DValue* lhs, DValue* rhs) } } +/****************************************************************************************/ +/*//////////////////////////////////////////////////////////////////////////////////////// +// NULL VALUE HELPER +////////////////////////////////////////////////////////////////////////////////////////*/ + +DValue* DtoNullValue(Type* type) +{ + Type* basetype = type->toBasetype(); + TY basety = basetype->ty; + const LLType* lltype = DtoType(basetype); + + // complex, needs to be first since complex are also floating + if (basetype->iscomplex()) + { + const LLType* basefp = DtoComplexBaseType(basetype); + return new DComplexValue(type, LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp)); + } + // integer, floating, pointer and class have no special representation + else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass) + { + return new DConstValue(type, LLConstant::getNullValue(lltype)); + } + // dynamic array + else if (basety == Tarray) + { + //TODO: What types do the constants here need to have? + return new DSliceValue(type, NULL, NULL); + } + // delegate + else if (basety == Tdelegate) + { + //TODO: Is this correct? + return new DNullValue(type, LLConstant::getNullValue(lltype)); + } + + // unknown + std::cout << "unsupported: null value for " << type->toChars() << '\n'; + assert(0); + return 0; + +} + + /****************************************************************************************/ /*//////////////////////////////////////////////////////////////////////////////////////// // CASTING HELPERS @@ -1335,8 +1378,7 @@ LLValue* DtoBoolean(DValue* dval) // complex else if (dtype->iscomplex()) { - // huh? - return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0)))); + return DtoComplexEquals(TOKnotequal, dval, DtoNullValue(dtype)); } // floating point else if (dtype->isfloating()) diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index e8244fc0..989d0bff 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -41,6 +41,9 @@ LLValue* DtoNestedVariable(VarDeclaration* vd); // basic operations void DtoAssign(DValue* lhs, DValue* rhs); +// create a null dvalue +DValue* DtoNullValue(Type* t); + // casts DValue* DtoCastInt(DValue* val, Type* to); DValue* DtoCastPtr(DValue* val, Type* to);