mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-18 13:53:14 +01:00
[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:
@@ -13,6 +13,7 @@
|
||||
#include "gen/arrays.h"
|
||||
#include "gen/logger.h"
|
||||
#include "gen/structs.h"
|
||||
#include "gen/dvalue.h"
|
||||
|
||||
#include "ir/irstruct.h"
|
||||
|
||||
@@ -377,6 +378,28 @@ void DtoDefineStruct(StructDeclaration* sd)
|
||||
sd->ir.DModule = gIR->dmodule;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////// D STRUCT UTILITIES ////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
|
||||
{
|
||||
Type* t = lhs->getType()->toBasetype();
|
||||
assert(t->ty == Tstruct);
|
||||
|
||||
// set predicate
|
||||
llvm::ICmpInst::Predicate cmpop;
|
||||
if (op == TOKequal)
|
||||
cmpop = llvm::ICmpInst::ICMP_EQ;
|
||||
else
|
||||
cmpop = llvm::ICmpInst::ICMP_NE;
|
||||
|
||||
// call memcmp
|
||||
size_t sz = getABITypeSize(DtoType(t));
|
||||
LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz));
|
||||
return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////// D UNION HELPER CLASS ////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user