diff gen/structs.cpp @ 344:e20ce6d8d374 trunk

[svn r365] Implemented raw struct equality comparison, uses C memcmp. Renamed DtoDelegateCompare to DtoDelegateEquals, for consistency with the other equality helpers.
author lindquist
date Sun, 13 Jul 2008 04:11:08 +0200
parents aaade6ded589
children 5320fe65a65d
line wrap: on
line diff
--- a/gen/structs.cpp	Sun Jul 13 03:02:15 2008 +0200
+++ b/gen/structs.cpp	Sun Jul 13 04:11:08 2008 +0200
@@ -13,6 +13,7 @@
 #include "gen/arrays.h"
 #include "gen/logger.h"
 #include "gen/structs.h"
+#include "gen/dvalue.h"
 
 #include "ir/irstruct.h"
 
@@ -378,6 +379,28 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////   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   ////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////