F(Mul, mul) \
F(Sub, sub) \
F(BinopContext, binopContext) \
- F(AddNumberParams, addNumberParams) \
- F(MulNumberParams, mulNumberParams) \
- F(SubNumberParams, subNumberParams) \
F(LoadThis, loadThis) \
F(LoadQmlIdArray, loadQmlIdArray) \
F(LoadQmlImportedScripts, loadQmlImportedScripts) \
Param rhs;
Param result;
};
- struct instr_addNumberParams {
- MOTH_INSTR_HEADER
- Param lhs;
- Param rhs;
- Param result;
- };
- struct instr_mulNumberParams {
- MOTH_INSTR_HEADER
- Param lhs;
- Param rhs;
- Param result;
- };
- struct instr_subNumberParams {
- MOTH_INSTR_HEADER
- Param lhs;
- Param rhs;
- Param result;
- };
struct instr_loadThis {
MOTH_INSTR_HEADER
Param result;
instr_mul mul;
instr_sub sub;
instr_binopContext binopContext;
- instr_addNumberParams addNumberParams;
- instr_mulNumberParams mulNumberParams;
- instr_subNumberParams subNumberParams;
instr_loadThis loadThis;
instr_loadQmlIdArray loadQmlIdArray;
instr_loadQmlImportedScripts loadQmlImportedScripts;
Param InstructionSelection::binopHelper(V4IR::AluOp oper, V4IR::Expr *leftSource, V4IR::Expr *rightSource, V4IR::Temp *target)
{
- if (isNumberType(leftSource) && isNumberType(rightSource)) {
- switch (oper) {
- case V4IR::OpAdd: {
- Instruction::AddNumberParams instr;
- instr.lhs = getParam(leftSource);
- instr.rhs = getParam(rightSource);
- instr.result = getResultParam(target);
- addInstruction(instr);
- return instr.result;
- }
- case V4IR::OpMul: {
- Instruction::MulNumberParams instr;
- instr.lhs = getParam(leftSource);
- instr.rhs = getParam(rightSource);
- instr.result = getResultParam(target);
- addInstruction(instr);
- return instr.result;
- }
- case V4IR::OpSub: {
- Instruction::SubNumberParams instr;
- instr.lhs = getParam(leftSource);
- instr.rhs = getParam(rightSource);
- instr.result = getResultParam(target);
- addInstruction(instr);
- return instr.result;
- }
- default:
- break;
- }
- }
-
if (oper == V4IR::OpAdd) {
Instruction::Add add;
add.lhs = getParam(leftSource);
STOREVALUE(instr.result, instr.alu(context, VALUEPTR(instr.lhs), VALUEPTR(instr.rhs)));
MOTH_END_INSTR(BinopContext)
- MOTH_BEGIN_INSTR(AddNumberParams)
- double lhs = VALUE(instr.lhs).asDouble();
- double rhs = VALUE(instr.rhs).asDouble();
- VALUEPTR(instr.result)->setDouble(lhs + rhs);
- MOTH_END_INSTR(AddNumberParams)
-
- MOTH_BEGIN_INSTR(MulNumberParams)
- double lhs = VALUE(instr.lhs).asDouble();
- double rhs = VALUE(instr.rhs).asDouble();
- VALUEPTR(instr.result)->setDouble(lhs * rhs);
- MOTH_END_INSTR(MulNumberParams)
-
- MOTH_BEGIN_INSTR(SubNumberParams)
- double lhs = VALUE(instr.lhs).asDouble();
- double rhs = VALUE(instr.rhs).asDouble();
- VALUEPTR(instr.result)->setDouble(lhs - rhs);
- MOTH_END_INSTR(SubNumberParams)
-
MOTH_BEGIN_INSTR(Ret)
context->engine->stackPop(stackSize);
// TRACE(Ret, "returning value %s", result.toString(context)->toQString().toUtf8().constData());