mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
Remove boilerplate code (unaryOp methods in Compiler)
This commit is contained in:
parent
07d0f1172f
commit
bd7b66a898
@ -131,12 +131,8 @@ class Compiler {
|
||||
virtual void exit(Operand* address) = 0;
|
||||
|
||||
virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0;
|
||||
virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0;
|
||||
|
||||
virtual Operand* neg(unsigned size, Operand* a) = 0;
|
||||
virtual Operand* fneg(unsigned size, Operand* a) = 0;
|
||||
virtual Operand* abs(unsigned size, Operand* a) = 0;
|
||||
virtual Operand* fabs(unsigned size, Operand* a) = 0;
|
||||
virtual Operand* fsqrt(unsigned size, Operand* a) = 0;
|
||||
virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) = 0;
|
||||
virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) = 0;
|
||||
virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) = 0;
|
||||
|
@ -99,7 +99,6 @@ const unsigned OperandTypeCount = MemoryOperand + 1;
|
||||
|
||||
const int NoRegister = -1;
|
||||
|
||||
|
||||
inline bool isBranch(lir::TernaryOperation op) {
|
||||
return op > FloatMin;
|
||||
}
|
||||
@ -120,6 +119,14 @@ inline bool isFloatBinaryOp(lir::TernaryOperation op) {
|
||||
return op >= FloatAdd && op <= FloatMin;
|
||||
}
|
||||
|
||||
inline bool isGeneralUnaryOp(lir::BinaryOperation op) {
|
||||
return op == Negate || op == Absolute;
|
||||
}
|
||||
|
||||
inline bool isFloatUnaryOp(lir::BinaryOperation op) {
|
||||
return op == FloatNegate || op == FloatSquareRoot || op == FloatAbsolute;
|
||||
}
|
||||
|
||||
class Operand { };
|
||||
|
||||
class Constant: public Operand {
|
||||
|
@ -2623,40 +2623,11 @@ class MyCompiler: public Compiler {
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual Operand* neg(unsigned size, Operand* a) {
|
||||
assert(&c, static_cast<Value*>(a)->type == lir::ValueGeneral);
|
||||
Value* result = value(&c, lir::ValueGeneral);
|
||||
appendTranslate(&c, lir::Negate, size, static_cast<Value*>(a), size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual Operand* fneg(unsigned size, Operand* a) {
|
||||
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
|
||||
Value* result = value(&c, lir::ValueFloat);
|
||||
appendTranslate(&c, lir::FloatNegate, size, static_cast<Value*>(a), size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual Operand* abs(unsigned size, Operand* a) {
|
||||
assert(&c, static_cast<Value*>(a)->type == lir::ValueGeneral);
|
||||
Value* result = value(&c, lir::ValueGeneral);
|
||||
appendTranslate(&c, lir::Absolute, size, static_cast<Value*>(a), size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual Operand* fabs(unsigned size, Operand* a) {
|
||||
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
|
||||
Value* result = value(&c, lir::ValueFloat);
|
||||
appendTranslate
|
||||
(&c, lir::FloatAbsolute, size, static_cast<Value*>(a), size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual Operand* fsqrt(unsigned size, Operand* a) {
|
||||
assert(&c, static_cast<Value*>(a)->type == lir::ValueFloat);
|
||||
Value* result = value(&c, lir::ValueFloat);
|
||||
appendTranslate
|
||||
(&c, lir::FloatSquareRoot, size, static_cast<Value*>(a), size, result);
|
||||
virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) {
|
||||
assert(&c, (isGeneralUnaryOp(type) and isGeneralValue(a))or(
|
||||
isFloatUnaryOp(type) and isFloatValue(a)));
|
||||
Value* result = value(&c, static_cast<Value*>(a)->type);
|
||||
appendTranslate(&c, type, size, static_cast<Value*>(a), size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3954,17 +3954,17 @@ intrinsic(MyThread* t, Frame* frame, object target)
|
||||
if (MATCH(methodName(t, target), "sqrt")
|
||||
and MATCH(methodSpec(t, target), "(D)D"))
|
||||
{
|
||||
frame->pushLong(c->fsqrt(8, frame->popLong()));
|
||||
frame->pushLong(c->unaryOp(lir::FloatSquareRoot, 8, frame->popLong()));
|
||||
return true;
|
||||
} else if (MATCH(methodName(t, target), "abs")) {
|
||||
if (MATCH(methodSpec(t, target), "(I)I")) {
|
||||
frame->pushInt(c->abs(4, frame->popInt()));
|
||||
frame->pushInt(c->unaryOp(lir::Absolute, 4, frame->popInt()));
|
||||
return true;
|
||||
} else if (MATCH(methodSpec(t, target), "(J)J")) {
|
||||
frame->pushLong(c->abs(8, frame->popLong()));
|
||||
frame->pushLong(c->unaryOp(lir::Absolute, 8, frame->popLong()));
|
||||
return true;
|
||||
} else if (MATCH(methodSpec(t, target), "(F)F")) {
|
||||
frame->pushInt(c->fabs(4, frame->popInt()));
|
||||
frame->pushInt(c->unaryOp(lir::FloatAbsolute, 4, frame->popInt()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -4649,7 +4649,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
||||
} break;
|
||||
|
||||
case dneg: {
|
||||
frame->pushLong(c->fneg(8, frame->popLong()));
|
||||
frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong()));
|
||||
} break;
|
||||
|
||||
case vm::drem: {
|
||||
@ -4766,7 +4766,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
||||
} break;
|
||||
|
||||
case fneg: {
|
||||
frame->pushInt(c->fneg(4, frame->popInt()));
|
||||
frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt()));
|
||||
} break;
|
||||
|
||||
case vm::frem: {
|
||||
@ -5238,7 +5238,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
||||
} break;
|
||||
|
||||
case ineg: {
|
||||
frame->pushInt(c->neg(4, frame->popInt()));
|
||||
frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt()));
|
||||
} break;
|
||||
|
||||
case instanceof: {
|
||||
@ -5740,7 +5740,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
||||
} break;
|
||||
|
||||
case lneg:
|
||||
frame->pushLong(c->neg(8, frame->popLong()));
|
||||
frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong()));
|
||||
break;
|
||||
|
||||
case lookupswitch: {
|
||||
|
Loading…
Reference in New Issue
Block a user