diff options
Diffstat (limited to 'src/qml/compiler')
| -rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 77 | ||||
| -rw-r--r-- | src/qml/compiler/qv4codegen_p.h | 6 | ||||
| -rw-r--r-- | src/qml/compiler/qv4instr_moth.cpp | 16 | ||||
| -rw-r--r-- | src/qml/compiler/qv4instr_moth_p.h | 26 | ||||
| -rw-r--r-- | src/qml/compiler/qv4isel_moth.cpp | 8 | ||||
| -rw-r--r-- | src/qml/compiler/qv4jsir.cpp | 6 | ||||
| -rw-r--r-- | src/qml/compiler/qv4jsir_p.h | 6 | ||||
| -rw-r--r-- | src/qml/compiler/qv4ssa.cpp | 12 |
8 files changed, 82 insertions, 75 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 6567b9a1ce..56d28d2147 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -924,10 +924,8 @@ Codegen::Reference Codegen::unop(UnaryOperation op, const Reference &expr) return expr; case Compl: return Reference::fromConst(this, Runtime::method_complement(v)); - case Increment: - return Reference::fromConst(this, Runtime::method_increment(v)); - case Decrement: - return Reference::fromConst(this, Runtime::method_decrement(v)); + default: + break; } } } @@ -960,17 +958,35 @@ Codegen::Reference Codegen::unop(UnaryOperation op, const Reference &expr) ucompl.result = dest.asLValue(); bytecodeGenerator->addInstruction(ucompl); } break; - case Increment: { - Instruction::Increment inc; + case PreIncrement: { + Instruction::PreIncrement inc; inc.source = expr.asRValue(); inc.result = dest.asLValue(); bytecodeGenerator->addInstruction(inc); + expr.store(dest); } break; - case Decrement: { - Instruction::Decrement dec; + case PreDecrement: { + Instruction::PreDecrement dec; dec.source = expr.asRValue(); dec.result = dest.asLValue(); bytecodeGenerator->addInstruction(dec); + expr.store(dest); + } break; + case PostIncrement: { + Instruction::PostIncrement inc; + inc.source = expr.asRValue(); + inc.result = dest.asLValue(); + bytecodeGenerator->addInstruction(inc); + expr.asLValue(); // mark expr as needsWriteBack + expr.writeBack(); + } break; + case PostDecrement: { + Instruction::PostDecrement dec; + dec.source = expr.asRValue(); + dec.result = dest.asLValue(); + bytecodeGenerator->addInstruction(dec); + expr.asLValue(); // mark expr as needsWriteBack + expr.writeBack(); } break; } @@ -2175,13 +2191,7 @@ bool Codegen::visit(PostDecrementExpression *ast) if (throwSyntaxErrorOnEvalOrArgumentsInStrictMode(expr, ast->decrementToken)) return false; - Reference oldValue = unop(UPlus, expr); - - TempScope scope(this); - Reference newValue = unop(Decrement, oldValue); - expr.store(newValue); - - _expr.result = oldValue; + _expr.result = unop(PostDecrement, expr); return false; } @@ -2201,14 +2211,7 @@ bool Codegen::visit(PostIncrementExpression *ast) if (throwSyntaxErrorOnEvalOrArgumentsInStrictMode(expr, ast->incrementToken)) return false; - Reference oldValue = unop(UPlus, expr); - - TempScope scope(this); - Reference newValue = unop(Increment, oldValue); - expr.store(newValue); - - _expr.result = oldValue; - + _expr.result = unop(PostIncrement, expr); return false; } @@ -2226,19 +2229,7 @@ bool Codegen::visit(PreDecrementExpression *ast) if (throwSyntaxErrorOnEvalOrArgumentsInStrictMode(expr, ast->decrementToken)) return false; - auto tmp = unop(Decrement, expr); - if (_expr.accept(nx)) { - bytecodeGenerator->setLocation(ast->decrementToken); - expr.store(tmp); - } else { - if (!tmp.isTempLocalArg()) { - auto tmp2 = Reference::fromTemp(this); - tmp2.store(tmp); - tmp = tmp2; - } - expr.store(tmp); - _expr.result = tmp; - } + _expr.result = unop(PreDecrement, expr); return false; } @@ -2257,19 +2248,7 @@ bool Codegen::visit(PreIncrementExpression *ast) if (throwSyntaxErrorOnEvalOrArgumentsInStrictMode(expr, ast->incrementToken)) return false; - auto tmp = unop(Increment, expr); - if (_expr.accept(nx)) { - bytecodeGenerator->setLocation(ast->incrementToken); - expr.store(tmp); - } else { - if (!tmp.isTempLocalArg()) { - auto tmp2 = Reference::fromTemp(this); - tmp2.store(tmp); - tmp = tmp2; - } - expr.store(tmp); - _expr.result = tmp; - } + _expr.result = unop(PreIncrement, expr); return false; } diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index 193681096e..db806f3f5e 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -463,8 +463,10 @@ protected: enum UnaryOperation { UPlus, UMinus, - Increment, - Decrement, + PreIncrement, + PreDecrement, + PostIncrement, + PostDecrement, Not, Compl }; diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp index 3f234f1394..07ffdfae03 100644 --- a/src/qml/compiler/qv4instr_moth.cpp +++ b/src/qml/compiler/qv4instr_moth.cpp @@ -412,13 +412,21 @@ void dumpBytecode(const char *code, int len) d << instr.result << ", " << instr.source; MOTH_END_INSTR(UComplInt) - MOTH_BEGIN_INSTR(Increment) + MOTH_BEGIN_INSTR(PreIncrement) d << instr.result << ", " << instr.source; - MOTH_END_INSTR(Increment) + MOTH_END_INSTR(PreIncrement) - MOTH_BEGIN_INSTR(Decrement) + MOTH_BEGIN_INSTR(PreDecrement) d << instr.result << ", " << instr.source; - MOTH_END_INSTR(Decrement) + MOTH_END_INSTR(PreDecrement) + + MOTH_BEGIN_INSTR(PostIncrement) + d << instr.result << ", " << instr.source; + MOTH_END_INSTR(PostIncrement) + + MOTH_BEGIN_INSTR(PostDecrement) + d << instr.result << ", " << instr.source; + MOTH_END_INSTR(PostDecrement) MOTH_BEGIN_INSTR(Binop) d << instr.alu << ", " << instr.result << ", " << instr.lhs << ", " << instr.rhs; diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h index 6625018443..ab22053e29 100644 --- a/src/qml/compiler/qv4instr_moth_p.h +++ b/src/qml/compiler/qv4instr_moth_p.h @@ -146,8 +146,10 @@ QT_BEGIN_NAMESPACE F(UMinus, uminus) \ F(UCompl, ucompl) \ F(UComplInt, ucomplInt) \ - F(Increment, increment) \ - F(Decrement, decrement) \ + F(PreIncrement, preIncrement) \ + F(PreDecrement, preDecrement) \ + F(PostIncrement, postIncrement) \ + F(PostDecrement, postDecrement) \ F(Binop, binop) \ F(Add, add) \ F(BitAnd, bitAnd) \ @@ -703,12 +705,22 @@ union Instr Param source; Param result; }; - struct instr_increment { + struct instr_preIncrement { MOTH_INSTR_HEADER Param source; Param result; }; - struct instr_decrement { + struct instr_preDecrement { + MOTH_INSTR_HEADER + Param source; + Param result; + }; + struct instr_postIncrement { + MOTH_INSTR_HEADER + Param source; + Param result; + }; + struct instr_postDecrement { MOTH_INSTR_HEADER Param source; Param result; @@ -901,8 +913,10 @@ union Instr instr_uminus uminus; instr_ucompl ucompl; instr_ucomplInt ucomplInt; - instr_increment increment; - instr_decrement decrement; + instr_preIncrement preIncrement; + instr_preDecrement preDecrement; + instr_postIncrement postIncrement; + instr_postDecrement postDecrement; instr_binop binop; instr_add add; instr_bitAnd bitAnd; diff --git a/src/qml/compiler/qv4isel_moth.cpp b/src/qml/compiler/qv4isel_moth.cpp index 24fbe3c680..986529f600 100644 --- a/src/qml/compiler/qv4isel_moth.cpp +++ b/src/qml/compiler/qv4isel_moth.cpp @@ -754,15 +754,15 @@ void InstructionSelection::unop(IR::AluOp oper, IR::Expr *source, IR::Expr *targ addInstruction(ucompl); return; } - case IR::OpIncrement: { - Instruction::Increment inc; + case IR::OpPreIncrement: { + Instruction::PreIncrement inc; inc.source = getParam(source); inc.result = getResultParam(target); addInstruction(inc); return; } - case IR::OpDecrement: { - Instruction::Decrement dec; + case IR::OpPreDecrement: { + Instruction::PreDecrement dec; dec.source = getParam(source); dec.result = getResultParam(target); addInstruction(dec); diff --git a/src/qml/compiler/qv4jsir.cpp b/src/qml/compiler/qv4jsir.cpp index 5a58380005..464eb008e7 100644 --- a/src/qml/compiler/qv4jsir.cpp +++ b/src/qml/compiler/qv4jsir.cpp @@ -90,8 +90,10 @@ const char *opname(AluOp op) case OpUMinus: return "neg"; case OpUPlus: return "plus"; case OpCompl: return "invert"; - case OpIncrement: return "incr"; - case OpDecrement: return "decr"; + case OpPreIncrement: return "pre-incr"; + case OpPreDecrement: return "pre-decr"; + case OpPostIncrement: return "post-incr"; + case OpPostDecrement: return "post-decr"; case OpBitAnd: return "bitand"; case OpBitOr: return "bitor"; diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h index 1b77dbf096..82632c391e 100644 --- a/src/qml/compiler/qv4jsir_p.h +++ b/src/qml/compiler/qv4jsir_p.h @@ -156,8 +156,10 @@ enum AluOp { OpUMinus, OpUPlus, OpCompl, - OpIncrement, - OpDecrement, + OpPreIncrement, + OpPreDecrement, + OpPostIncrement, + OpPostDecrement, OpBitAnd, OpBitOr, diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index 8cf5fac760..72a4a9e751 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -1993,8 +1993,8 @@ private: case OpUPlus: case OpUMinus: case OpNot: - case OpIncrement: - case OpDecrement: + case OpPreIncrement: + case OpPreDecrement: if (e->expr->type == VarType || e->expr->type == StringType || e->expr->type == QObjectType) markAsSideEffect(); break; @@ -2342,8 +2342,8 @@ private: case OpCompl: _ty.type = SInt32Type; return; case OpNot: _ty.type = BoolType; return; - case OpIncrement: - case OpDecrement: + case OpPreIncrement: + case OpPreDecrement: Q_ASSERT(!"Inplace operators should have been removed!"); Q_UNREACHABLE(); default: @@ -4178,11 +4178,11 @@ void optimizeSSA(StatementWorklist &W, DefUses &defUses, DominatorTree &df) constOperand->type = SInt32Type; doneSomething = true; break; - case OpIncrement: + case OpPreIncrement: constOperand->value = constOperand->value + 1; doneSomething = true; break; - case OpDecrement: + case OpPreDecrement: constOperand->value = constOperand->value - 1; doneSomething = true; break; |
