| 1 |
#include "gen/llvm.h" |
|---|
| 2 |
|
|---|
| 3 |
#include "declaration.h" |
|---|
| 4 |
|
|---|
| 5 |
#include "gen/irstate.h" |
|---|
| 6 |
#include "gen/tollvm.h" |
|---|
| 7 |
#include "gen/dvalue.h" |
|---|
| 8 |
#include "gen/logger.h" |
|---|
| 9 |
#include "gen/complex.h" |
|---|
| 10 |
|
|---|
| 11 |
////////////////////////////////////////////////////////////////////////////// |
|---|
| 12 |
|
|---|
| 13 |
DValue* DtoBinAdd(DValue* lhs, DValue* rhs) |
|---|
| 14 |
{ |
|---|
| 15 |
LLValue* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp"); |
|---|
| 16 |
return new DImValue( lhs->getType(), v ); |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
////////////////////////////////////////////////////////////////////////////// |
|---|
| 20 |
|
|---|
| 21 |
DValue* DtoBinSub(DValue* lhs, DValue* rhs) |
|---|
| 22 |
{ |
|---|
| 23 |
LLValue* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp"); |
|---|
| 24 |
return new DImValue( lhs->getType(), v ); |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
////////////////////////////////////////////////////////////////////////////// |
|---|
| 28 |
|
|---|
| 29 |
DValue* DtoBinMul(Type* targettype, DValue* lhs, DValue* rhs) |
|---|
| 30 |
{ |
|---|
| 31 |
LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp"); |
|---|
| 32 |
return new DImValue( targettype, v ); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
////////////////////////////////////////////////////////////////////////////// |
|---|
| 36 |
|
|---|
| 37 |
DValue* DtoBinDiv(Type* targettype, DValue* lhs, DValue* rhs) |
|---|
| 38 |
{ |
|---|
| 39 |
Type* t = lhs->getType(); |
|---|
| 40 |
LLValue *l, *r; |
|---|
| 41 |
l = lhs->getRVal(); |
|---|
| 42 |
r = rhs->getRVal(); |
|---|
| 43 |
LLValue* res; |
|---|
| 44 |
if (t->isfloating()) |
|---|
| 45 |
res = gIR->ir->CreateFDiv(l, r, "tmp"); |
|---|
| 46 |
else if (!t->isunsigned()) |
|---|
| 47 |
res = gIR->ir->CreateSDiv(l, r, "tmp"); |
|---|
| 48 |
else |
|---|
| 49 |
res = gIR->ir->CreateUDiv(l, r, "tmp"); |
|---|
| 50 |
return new DImValue( targettype, res ); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
////////////////////////////////////////////////////////////////////////////// |
|---|
| 54 |
|
|---|
| 55 |
DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs) |
|---|
| 56 |
{ |
|---|
| 57 |
Type* t = lhs->getType(); |
|---|
| 58 |
LLValue *l, *r; |
|---|
| 59 |
l = lhs->getRVal(); |
|---|
| 60 |
r = rhs->getRVal(); |
|---|
| 61 |
LLValue* res; |
|---|
| 62 |
if (t->isfloating()) |
|---|
| 63 |
res = gIR->ir->CreateFRem(l, r, "tmp"); |
|---|
| 64 |
else if (!t->isunsigned()) |
|---|
| 65 |
res = gIR->ir->CreateSRem(l, r, "tmp"); |
|---|
| 66 |
else |
|---|
| 67 |
res = gIR->ir->CreateURem(l, r, "tmp"); |
|---|
| 68 |
return new DImValue( targettype, res ); |
|---|
| 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 |
} |
|---|