[svn r365] Implemented raw struct equality comparison, uses C memcmp.

Renamed DtoDelegateCompare to DtoDelegateEquals, for consistency with the other equality helpers.
This commit is contained in:
Tomas Lindquist Olsen
2008-07-13 04:11:08 +02:00
parent 4b8d048d59
commit a4e4f34a34
6 changed files with 69 additions and 5 deletions

View File

@@ -186,9 +186,9 @@ const LLStructType* DtoDelegateType(Type* t)
//////////////////////////////////////////////////////////////////////////////////////////
LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs)
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
{
Logger::println("Doing delegate compare");
Logger::println("Doing delegate equality");
llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
llvm::Value *b1, *b2;
if (rhs == NULL)
@@ -444,6 +444,29 @@ void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes)
//////////////////////////////////////////////////////////////////////////////////////////
LLValue* DtoMemCmp(LLValue* lhs, LLValue* rhs, LLValue* nbytes)
{
// int memcmp ( const void * ptr1, const void * ptr2, size_t num );
LLFunction* fn = gIR->module->getFunction("memcmp");
if (!fn)
{
std::vector<const LLType*> params(3);
params[0] = getVoidPtrType();
params[1] = getVoidPtrType();
params[2] = DtoSize_t();
const LLFunctionType* fty = LLFunctionType::get(LLType::Int32Ty, params, false);
fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", gIR->module);
}
lhs = DtoBitCast(lhs,getVoidPtrType());
rhs = DtoBitCast(rhs,getVoidPtrType());
return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes, "tmp");
}
//////////////////////////////////////////////////////////////////////////////////////////
void DtoAggrZeroInit(LLValue* v)
{
uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0));