Files
ldc/gen/binops.cpp
Tomas Lindquist Olsen b4bb3aaec4 [svn r229] Updated the object.d implementation to the latest Tango.
Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array.
Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 .
Cleaned up some type code.
Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant.
Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
2008-05-30 19:32:04 +02:00

68 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();
llvm::Value *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();
llvm::Value *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 );
}