Skip to content

Commit

Permalink
Remove non explicitly typed IR::CONST() nodes.
Browse files Browse the repository at this point in the history
This change ensures that IR::CONST expressions
created by BasicBlock::BINOP(op,left,right) have
the correct types.

Change-Id: Iabac3f4ee1b897cc0d0bdf7e7385d7ae6dc513e4
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
  • Loading branch information
Roberto Raggi authored and Qt by Nokia committed Mar 9, 2012
1 parent 5c7b173 commit 7614325
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
49 changes: 23 additions & 26 deletions src/qml/qml/v4/qv4ir.cpp
Expand Up @@ -448,11 +448,6 @@ Temp *BasicBlock::TEMP(Type type)
return TEMP(type, function->tempCount++);
}

Expr *BasicBlock::CONST(double value)
{
return CONST(IR::RealType, value);
}

Expr *BasicBlock::CONST(Type type, double value)
{
Const *e = function->pool->New<Const>();
Expand Down Expand Up @@ -549,28 +544,30 @@ Expr *BasicBlock::BINOP(AluOp op, Expr *left, Expr *right)
if (left && right) {
if (Const *c1 = left->asConst()) {
if (Const *c2 = right->asConst()) {
const IR::Type ty = Binop::typeForOp(op, left, right);

switch (op) {
case OpAdd: return CONST(c1->value + c2->value);
case OpAnd: return CONST(c1->value ? c2->value : 0);
case OpBitAnd: return CONST(int(c1->value) & int(c2->value));
case OpBitOr: return CONST(int(c1->value) | int(c2->value));
case OpBitXor: return CONST(int(c1->value) ^ int(c2->value));
case OpDiv: return CONST(c1->value / c2->value);
case OpEqual: return CONST(c1->value == c2->value);
case OpGe: return CONST(c1->value >= c2->value);
case OpGt: return CONST(c1->value > c2->value);
case OpLe: return CONST(c1->value <= c2->value);
case OpLShift: return CONST(int(c1->value) << int(c2->value));
case OpLt: return CONST(c1->value < c2->value);
case OpMod: return CONST(::fmod(c1->value, c2->value));
case OpMul: return CONST(c1->value * c2->value);
case OpNotEqual: return CONST(c1->value != c2->value);
case OpOr: return CONST(c1->value ? c1->value : c2->value);
case OpRShift: return CONST(int(c1->value) >> int(c2->value));
case OpStrictEqual: return CONST(c1->value == c2->value);
case OpStrictNotEqual: return CONST(c1->value != c2->value);
case OpSub: return CONST(c1->value - c2->value);
case OpURShift: return CONST(unsigned(c1->value) >> int(c2->value));
case OpAdd: return CONST(ty, c1->value + c2->value);
case OpAnd: return CONST(ty, c1->value ? c2->value : 0);
case OpBitAnd: return CONST(ty, int(c1->value) & int(c2->value));
case OpBitOr: return CONST(ty, int(c1->value) | int(c2->value));
case OpBitXor: return CONST(ty, int(c1->value) ^ int(c2->value));
case OpDiv: return CONST(ty, c1->value / c2->value);
case OpEqual: return CONST(ty, c1->value == c2->value);
case OpGe: return CONST(ty, c1->value >= c2->value);
case OpGt: return CONST(ty, c1->value > c2->value);
case OpLe: return CONST(ty, c1->value <= c2->value);
case OpLShift: return CONST(ty, int(c1->value) << int(c2->value));
case OpLt: return CONST(ty, c1->value < c2->value);
case OpMod: return CONST(ty, ::fmod(c1->value, c2->value));
case OpMul: return CONST(ty, c1->value * c2->value);
case OpNotEqual: return CONST(ty, c1->value != c2->value);
case OpOr: return CONST(ty, c1->value ? c1->value : c2->value);
case OpRShift: return CONST(ty, int(c1->value) >> int(c2->value));
case OpStrictEqual: return CONST(ty, c1->value == c2->value);
case OpStrictNotEqual: return CONST(ty, c1->value != c2->value);
case OpSub: return CONST(ty, c1->value - c2->value);
case OpURShift: return CONST(ty, unsigned(c1->value) >> int(c2->value));

case OpIfTrue: // unary ops
case OpNot:
Expand Down
2 changes: 0 additions & 2 deletions src/qml/qml/v4/qv4ir_p.h
Expand Up @@ -339,7 +339,6 @@ struct Binop: Expr {

virtual void dump(QTextStream &out);

private:
static Type typeForOp(AluOp op, Expr *left, Expr *right);
};

Expand Down Expand Up @@ -525,7 +524,6 @@ struct BasicBlock {
Temp *TEMP(Type type, int index);
Temp *TEMP(Type type);

Expr *CONST(double value);
Expr *CONST(Type type, double value);
Expr *STRING(const QStringRef &value);

Expand Down
10 changes: 5 additions & 5 deletions src/qml/qml/v4/qv4irbuilder.cpp
Expand Up @@ -531,7 +531,7 @@ bool QV4IRBuilder::visit(AST::NumericLiteral *ast)
_expr.format = ExprResult::cx;
_block->JUMP(ast->value ? _expr.iftrue : _expr.iffalse);
} else {
_expr.code = _block->CONST(ast->value);
_expr.code = _block->CONST(IR::RealType, ast->value);
}
return false;
}
Expand Down Expand Up @@ -767,7 +767,7 @@ bool QV4IRBuilder::visit(AST::UnaryMinusExpression *ast)
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
_expr.code = _block->CONST(-c->value);
_expr.code = _block->CONST(expr->type, -c->value);
return false;
}

Expand All @@ -785,7 +785,7 @@ bool QV4IRBuilder::visit(AST::TildeExpression *ast)
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
_expr.code = _block->CONST(~int(c->value));
_expr.code = _block->CONST(expr->type, ~int(c->value));
return false;
}
IR::Expr *code = _block->UNOP(IR::OpCompl, expr);
Expand All @@ -803,7 +803,7 @@ bool QV4IRBuilder::visit(AST::NotExpression *ast)
if (expr.isNot(IR::InvalidType)) {
if (IR::Const *c = expr.code->asConst()) {
_expr = expr;
_expr.code = _block->CONST(!c->value);
_expr.code = _block->CONST(IR::BoolType, !c->value);
return false;
}

Expand Down Expand Up @@ -862,7 +862,7 @@ bool QV4IRBuilder::visit(AST::BinaryExpression *ast)
IR::Temp *r = _block->TEMP(IR::InvalidType);

_block = iffalse;
_block->MOVE(r, _block->CONST(0)); // ### use the right null value
_block->MOVE(r, _block->CONST(IR::BoolType, 0)); // ### use the right null value
_block->JUMP(endif);

_block = iftrue;
Expand Down

0 comments on commit 7614325

Please sign in to comment.