ldc/gen/binops.cpp
Tomas Lindquist Olsen 8b83eda2a2 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
Did a lot of smaller cleans up here and there.
Replaced more llvm::Foo with LLFoo for common stuff.
Split up tollvm.cpp.
2008-06-09 09:37:08 +02:00

67 lines
1.8 KiB
C++

#include "gen/llvm.h"
#include "declaration.h"
#include "gen/irstate.h"
#include "gen/tollvm.h"
#include "gen/dvalue.h"
//////////////////////////////////////////////////////////////////////////////
DValue* DtoBinAdd(DValue* lhs, DValue* rhs)
{
LLValue* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp");
return new DImValue( lhs->getType(), v );
}
//////////////////////////////////////////////////////////////////////////////
DValue* DtoBinSub(DValue* lhs, DValue* rhs)
{
LLValue* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp");
return new DImValue( lhs->getType(), v );
}
//////////////////////////////////////////////////////////////////////////////
DValue* DtoBinMul(DValue* lhs, DValue* rhs)
{
LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp");
return new DImValue( lhs->getType(), v );
}
//////////////////////////////////////////////////////////////////////////////
DValue* DtoBinDiv(DValue* lhs, DValue* rhs)
{
Type* t = lhs->getType();
LLValue *l, *r;
l = lhs->getRVal();
r = rhs->getRVal();
LLValue* res;
if (t->isfloating())
res = gIR->ir->CreateFDiv(l, r, "tmp");
else if (!t->isunsigned())
res = gIR->ir->CreateSDiv(l, r, "tmp");
else
res = gIR->ir->CreateUDiv(l, r, "tmp");
return new DImValue( lhs->getType(), res );
}
//////////////////////////////////////////////////////////////////////////////
DValue* DtoBinRem(DValue* lhs, DValue* rhs)
{
Type* t = lhs->getType();
LLValue *l, *r;
l = lhs->getRVal();
r = rhs->getRVal();
LLValue* res;
if (t->isfloating())
res = gIR->ir->CreateFRem(l, r, "tmp");
else if (!t->isunsigned())
res = gIR->ir->CreateSRem(l, r, "tmp");
else
res = gIR->ir->CreateURem(l, r, "tmp");
return new DImValue( lhs->getType(), res );
}