OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/asmjs/asm-typer.h" | 5 #include "src/asmjs/asm-typer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 return ValidateRelationalExpression(cmp); | 1506 return ValidateRelationalExpression(cmp); |
1507 case Token::EQ: | 1507 case Token::EQ: |
1508 case Token::NE: | 1508 case Token::NE: |
1509 return ValidateEqualityExpression(cmp); | 1509 return ValidateEqualityExpression(cmp); |
1510 } | 1510 } |
1511 | 1511 |
1512 UNREACHABLE(); | 1512 UNREACHABLE(); |
1513 } | 1513 } |
1514 | 1514 |
1515 namespace { | 1515 namespace { |
1516 bool IsNegate(BinaryOperation* binop) { | 1516 bool IsInvert(BinaryOperation* binop) { |
1517 if (binop->op() != Token::BIT_XOR) { | 1517 if (binop->op() != Token::BIT_XOR) { |
1518 return false; | 1518 return false; |
1519 } | 1519 } |
1520 | 1520 |
1521 auto* right_as_literal = binop->right()->AsLiteral(); | 1521 auto* right_as_literal = binop->right()->AsLiteral(); |
1522 if (right_as_literal == nullptr) { | 1522 if (right_as_literal == nullptr) { |
1523 return false; | 1523 return false; |
1524 } | 1524 } |
1525 | 1525 |
1526 return !right_as_literal->raw_value()->ContainsDot() && | 1526 return !right_as_literal->raw_value()->ContainsDot() && |
1527 right_as_literal->raw_value()->AsNumber() == -1.0; | 1527 right_as_literal->raw_value()->AsNumber() == -1.0; |
1528 } | 1528 } |
1529 | 1529 |
1530 bool IsUnaryMinus(BinaryOperation* binop) { | 1530 bool IsUnaryMinus(BinaryOperation* binop) { |
1531 // *VIOLATION* The parser replaces uses of +x with x*1.0. | 1531 // *VIOLATION* The parser replaces uses of -x with x*-1. |
1532 if (binop->op() != Token::MUL) { | 1532 if (binop->op() != Token::MUL) { |
1533 return false; | 1533 return false; |
1534 } | 1534 } |
1535 | 1535 |
1536 auto* right_as_literal = binop->right()->AsLiteral(); | 1536 auto* right_as_literal = binop->right()->AsLiteral(); |
1537 if (right_as_literal == nullptr) { | 1537 if (right_as_literal == nullptr) { |
1538 return false; | 1538 return false; |
1539 } | 1539 } |
1540 | 1540 |
1541 return !right_as_literal->raw_value()->ContainsDot() && | 1541 return !right_as_literal->raw_value()->ContainsDot() && |
(...skipping 25 matching lines...) Expand all Loading... |
1567 RECURSE(left_type = ValidateExpression(expr->left())); | 1567 RECURSE(left_type = ValidateExpression(expr->left())); |
1568 SetTypeOf(expr->right(), AsmType::Double()); | 1568 SetTypeOf(expr->right(), AsmType::Double()); |
1569 UNOP_OVERLOAD(Signed, Double); | 1569 UNOP_OVERLOAD(Signed, Double); |
1570 UNOP_OVERLOAD(Unsigned, Double); | 1570 UNOP_OVERLOAD(Unsigned, Double); |
1571 UNOP_OVERLOAD(DoubleQ, Double); | 1571 UNOP_OVERLOAD(DoubleQ, Double); |
1572 UNOP_OVERLOAD(FloatQ, Double); | 1572 UNOP_OVERLOAD(FloatQ, Double); |
1573 FAIL(expr, "Invalid type for conversion to double."); | 1573 FAIL(expr, "Invalid type for conversion to double."); |
1574 } | 1574 } |
1575 | 1575 |
1576 if (IsUnaryMinus(expr)) { | 1576 if (IsUnaryMinus(expr)) { |
1577 // *VIOLATION* the parser converts -x to x * -1.0. | 1577 // *VIOLATION* the parser converts -x to x * -1. |
1578 AsmType* left_type; | 1578 AsmType* left_type; |
1579 RECURSE(left_type = ValidateExpression(expr->left())); | 1579 RECURSE(left_type = ValidateExpression(expr->left())); |
1580 SetTypeOf(expr->right(), left_type); | 1580 SetTypeOf(expr->right(), left_type); |
1581 UNOP_OVERLOAD(Int, Intish); | 1581 UNOP_OVERLOAD(Int, Intish); |
1582 UNOP_OVERLOAD(DoubleQ, Double); | 1582 UNOP_OVERLOAD(DoubleQ, Double); |
1583 UNOP_OVERLOAD(FloatQ, Floatish); | 1583 UNOP_OVERLOAD(FloatQ, Floatish); |
1584 FAIL(expr, "Invalid type for unary -."); | 1584 FAIL(expr, "Invalid type for unary -."); |
1585 } | 1585 } |
1586 // FALTHROUGH | 1586 // FALTHROUGH |
1587 case Token::DIV: | 1587 case Token::DIV: |
1588 case Token::MOD: | 1588 case Token::MOD: |
1589 return ValidateMultiplicativeExpression(expr); | 1589 return ValidateMultiplicativeExpression(expr); |
1590 case Token::ADD: | 1590 case Token::ADD: |
1591 case Token::SUB: { | 1591 case Token::SUB: { |
1592 static const uint32_t kInitialIntishCount = 0; | 1592 static const uint32_t kInitialIntishCount = 0; |
1593 return ValidateAdditiveExpression(expr, kInitialIntishCount); | 1593 return ValidateAdditiveExpression(expr, kInitialIntishCount); |
1594 } | 1594 } |
1595 case Token::SAR: | 1595 case Token::SAR: |
1596 case Token::SHL: | 1596 case Token::SHL: |
1597 case Token::SHR: | 1597 case Token::SHR: |
1598 return ValidateShiftExpression(expr); | 1598 return ValidateShiftExpression(expr); |
1599 case Token::BIT_AND: | 1599 case Token::BIT_AND: |
1600 return ValidateBitwiseANDExpression(expr); | 1600 return ValidateBitwiseANDExpression(expr); |
1601 case Token::BIT_XOR: | 1601 case Token::BIT_XOR: |
1602 if (IsNegate(expr)) { | 1602 if (IsInvert(expr)) { |
1603 auto* left = expr->left(); | 1603 auto* left = expr->left(); |
1604 auto* left_as_binop = left->AsBinaryOperation(); | 1604 auto* left_as_binop = left->AsBinaryOperation(); |
1605 | 1605 |
1606 if (left_as_binop != nullptr && IsNegate(left_as_binop)) { | 1606 if (left_as_binop != nullptr && IsInvert(left_as_binop)) { |
1607 // This is the special ~~ operator. | 1607 // This is the special ~~ operator. |
1608 AsmType* left_type; | 1608 AsmType* left_type; |
1609 RECURSE(left_type = ValidateExpression(left_as_binop->left())); | 1609 RECURSE(left_type = ValidateExpression(left_as_binop->left())); |
1610 SetTypeOf(left_as_binop->right(), AsmType::FixNum()); | 1610 SetTypeOf(left_as_binop->right(), AsmType::FixNum()); |
1611 SetTypeOf(left_as_binop, AsmType::Signed()); | 1611 SetTypeOf(left_as_binop, AsmType::Signed()); |
1612 SetTypeOf(expr->right(), AsmType::FixNum()); | 1612 SetTypeOf(expr->right(), AsmType::FixNum()); |
1613 UNOP_OVERLOAD(Double, Signed); | 1613 UNOP_OVERLOAD(Double, Signed); |
1614 UNOP_OVERLOAD(FloatQ, Signed); | 1614 UNOP_OVERLOAD(FloatQ, Signed); |
1615 FAIL(left_as_binop, "Invalid type for conversion to signed."); | 1615 FAIL(left_as_binop, "Invalid type for conversion to signed."); |
1616 } | 1616 } |
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2785 return true; | 2785 return true; |
2786 } | 2786 } |
2787 | 2787 |
2788 *error_message = typer.error_message(); | 2788 *error_message = typer.error_message(); |
2789 return false; | 2789 return false; |
2790 } | 2790 } |
2791 | 2791 |
2792 } // namespace wasm | 2792 } // namespace wasm |
2793 } // namespace internal | 2793 } // namespace internal |
2794 } // namespace v8 | 2794 } // namespace v8 |
OLD | NEW |