Mercurial > projects > ldc
comparison gen/binops.cpp @ 1503:cc5fee7836dc
Made is and !is use the same numeric comparison as == and !=, fixes #328
Factored out common code from EqualExp and IdentityExp into
DtoBinNumericEquals in binexp.cpp.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Tue, 16 Jun 2009 23:00:27 +0200 |
parents | ca2dfe98036c |
children |
comparison
equal
deleted
inserted
replaced
1502:2292878925f4 | 1503:cc5fee7836dc |
---|---|
3 #include "declaration.h" | 3 #include "declaration.h" |
4 | 4 |
5 #include "gen/irstate.h" | 5 #include "gen/irstate.h" |
6 #include "gen/tollvm.h" | 6 #include "gen/tollvm.h" |
7 #include "gen/dvalue.h" | 7 #include "gen/dvalue.h" |
8 #include "gen/logger.h" | |
9 #include "gen/complex.h" | |
8 | 10 |
9 ////////////////////////////////////////////////////////////////////////////// | 11 ////////////////////////////////////////////////////////////////////////////// |
10 | 12 |
11 DValue* DtoBinAdd(DValue* lhs, DValue* rhs) | 13 DValue* DtoBinAdd(DValue* lhs, DValue* rhs) |
12 { | 14 { |
63 res = gIR->ir->CreateSRem(l, r, "tmp"); | 65 res = gIR->ir->CreateSRem(l, r, "tmp"); |
64 else | 66 else |
65 res = gIR->ir->CreateURem(l, r, "tmp"); | 67 res = gIR->ir->CreateURem(l, r, "tmp"); |
66 return new DImValue( targettype, res ); | 68 return new DImValue( targettype, res ); |
67 } | 69 } |
70 | |
71 ////////////////////////////////////////////////////////////////////////////// | |
72 | |
73 LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op) | |
74 { | |
75 assert(op == TOKequal || op == TOKnotequal || | |
76 op == TOKidentity || op == TOKnotidentity); | |
77 Type* t = lhs->getType()->toBasetype(); | |
78 assert(t->isfloating()); | |
79 Logger::println("numeric equality"); | |
80 | |
81 LLValue* lv = lhs->getRVal(); | |
82 LLValue* rv = rhs->getRVal(); | |
83 LLValue* res = 0; | |
84 | |
85 if (t->iscomplex()) | |
86 { | |
87 Logger::println("complex"); | |
88 res = DtoComplexEquals(loc, op, lhs, rhs); | |
89 } | |
90 else if (t->isfloating()) | |
91 { | |
92 Logger::println("floating"); | |
93 res = (op == TOKidentity || op == TOKequal) | |
94 ? gIR->ir->CreateFCmpOEQ(lv,rv,"tmp") | |
95 : gIR->ir->CreateFCmpUNE(lv,rv,"tmp"); | |
96 } | |
97 | |
98 assert(res); | |
99 return res; | |
100 } |