OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/typing-asm.h" | 5 #include "src/typing-asm.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 RECURSE(VisitWithExpectation( | 683 RECURSE(VisitWithExpectation( |
684 expr->value(), type, "assignment value expected to match surrounding")); | 684 expr->value(), type, "assignment value expected to match surrounding")); |
685 Type* target_type = StorageType(computed_type_); | 685 Type* target_type = StorageType(computed_type_); |
686 if (expr->target()->IsVariableProxy()) { | 686 if (expr->target()->IsVariableProxy()) { |
687 if (intish_ != 0) { | 687 if (intish_ != 0) { |
688 FAIL(expr, "intish or floatish assignment"); | 688 FAIL(expr, "intish or floatish assignment"); |
689 } | 689 } |
690 expected_type_ = target_type; | 690 expected_type_ = target_type; |
691 VisitVariableProxy(expr->target()->AsVariableProxy(), true); | 691 VisitVariableProxy(expr->target()->AsVariableProxy(), true); |
692 } else if (expr->target()->IsProperty()) { | 692 } else if (expr->target()->IsProperty()) { |
693 int value_intish = intish_; | 693 int32_t value_intish = intish_; |
694 Property* property = expr->target()->AsProperty(); | 694 Property* property = expr->target()->AsProperty(); |
695 RECURSE(VisitWithExpectation(property->obj(), Type::Any(), | 695 RECURSE(VisitWithExpectation(property->obj(), Type::Any(), |
696 "bad propety object")); | 696 "bad propety object")); |
697 if (!computed_type_->IsArray()) { | 697 if (!computed_type_->IsArray()) { |
698 FAIL(property->obj(), "array expected"); | 698 FAIL(property->obj(), "array expected"); |
699 } | 699 } |
700 if (value_intish != 0 && computed_type_->Is(cache_.kFloat64Array)) { | 700 if (value_intish != 0 && computed_type_->Is(cache_.kFloat64Array)) { |
701 FAIL(expr, "floatish assignment to double array"); | 701 FAIL(expr, "floatish assignment to double array"); |
702 } | 702 } |
703 VisitHeapAccess(property, true, target_type); | 703 VisitHeapAccess(property, true, target_type); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 FAIL(expr, "increment or decrement operator encountered"); | 1076 FAIL(expr, "increment or decrement operator encountered"); |
1077 } | 1077 } |
1078 | 1078 |
1079 | 1079 |
1080 void AsmTyper::VisitIntegerBitwiseOperator(BinaryOperation* expr, | 1080 void AsmTyper::VisitIntegerBitwiseOperator(BinaryOperation* expr, |
1081 Type* left_expected, | 1081 Type* left_expected, |
1082 Type* right_expected, | 1082 Type* right_expected, |
1083 Type* result_type, bool conversion) { | 1083 Type* result_type, bool conversion) { |
1084 RECURSE(VisitWithExpectation(expr->left(), Type::Number(), | 1084 RECURSE(VisitWithExpectation(expr->left(), Type::Number(), |
1085 "left bitwise operand expected to be a number")); | 1085 "left bitwise operand expected to be a number")); |
1086 int left_intish = intish_; | 1086 int32_t left_intish = intish_; |
1087 Type* left_type = computed_type_; | 1087 Type* left_type = computed_type_; |
1088 if (!left_type->Is(left_expected)) { | 1088 if (!left_type->Is(left_expected)) { |
1089 FAIL(expr->left(), "left bitwise operand expected to be an integer"); | 1089 FAIL(expr->left(), "left bitwise operand expected to be an integer"); |
1090 } | 1090 } |
1091 if (left_intish > kMaxUncombinedAdditiveSteps) { | 1091 if (left_intish > kMaxUncombinedAdditiveSteps) { |
1092 FAIL(expr->left(), "too many consecutive additive ops"); | 1092 FAIL(expr->left(), "too many consecutive additive ops"); |
1093 } | 1093 } |
1094 | 1094 |
1095 RECURSE( | 1095 RECURSE( |
1096 VisitWithExpectation(expr->right(), Type::Number(), | 1096 VisitWithExpectation(expr->right(), Type::Number(), |
1097 "right bitwise operand expected to be a number")); | 1097 "right bitwise operand expected to be a number")); |
1098 int right_intish = intish_; | 1098 int32_t right_intish = intish_; |
1099 Type* right_type = computed_type_; | 1099 Type* right_type = computed_type_; |
1100 if (!right_type->Is(right_expected)) { | 1100 if (!right_type->Is(right_expected)) { |
1101 FAIL(expr->right(), "right bitwise operand expected to be an integer"); | 1101 FAIL(expr->right(), "right bitwise operand expected to be an integer"); |
1102 } | 1102 } |
1103 if (right_intish > kMaxUncombinedAdditiveSteps) { | 1103 if (right_intish > kMaxUncombinedAdditiveSteps) { |
1104 FAIL(expr->right(), "too many consecutive additive ops"); | 1104 FAIL(expr->right(), "too many consecutive additive ops"); |
1105 } | 1105 } |
1106 | 1106 |
1107 intish_ = 0; | 1107 intish_ = 0; |
1108 | 1108 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 } | 1197 } |
1198 case Token::ADD: | 1198 case Token::ADD: |
1199 case Token::SUB: | 1199 case Token::SUB: |
1200 case Token::MUL: | 1200 case Token::MUL: |
1201 case Token::DIV: | 1201 case Token::DIV: |
1202 case Token::MOD: { | 1202 case Token::MOD: { |
1203 RECURSE(VisitWithExpectation( | 1203 RECURSE(VisitWithExpectation( |
1204 expr->left(), Type::Number(), | 1204 expr->left(), Type::Number(), |
1205 "left arithmetic operand expected to be number")); | 1205 "left arithmetic operand expected to be number")); |
1206 Type* left_type = computed_type_; | 1206 Type* left_type = computed_type_; |
1207 int left_intish = intish_; | 1207 int32_t left_intish = intish_; |
1208 RECURSE(VisitWithExpectation( | 1208 RECURSE(VisitWithExpectation( |
1209 expr->right(), Type::Number(), | 1209 expr->right(), Type::Number(), |
1210 "right arithmetic operand expected to be number")); | 1210 "right arithmetic operand expected to be number")); |
1211 Type* right_type = computed_type_; | 1211 Type* right_type = computed_type_; |
1212 int right_intish = intish_; | 1212 int32_t right_intish = intish_; |
1213 Type* type = Type::Union(left_type, right_type, zone()); | 1213 Type* type = Type::Union(left_type, right_type, zone()); |
1214 if (type->Is(cache_.kAsmInt)) { | 1214 if (type->Is(cache_.kAsmInt)) { |
1215 if (expr->op() == Token::MUL) { | 1215 if (expr->op() == Token::MUL) { |
| 1216 int32_t i; |
| 1217 Literal* left = expr->left()->AsLiteral(); |
1216 Literal* right = expr->right()->AsLiteral(); | 1218 Literal* right = expr->right()->AsLiteral(); |
1217 if (!right) { | 1219 if (left != nullptr && left->value()->IsNumber() && |
1218 FAIL(expr, "direct integer multiply forbidden"); | 1220 left->value()->ToInt32(&i)) { |
1219 } | 1221 if (right_intish != 0) { |
1220 if (!right->value()->IsNumber()) { | 1222 FAIL(expr, "intish not allowed in multiply"); |
1221 FAIL(expr, "multiply must be by an integer"); | 1223 } |
1222 } | 1224 } else if (right != nullptr && right->value()->IsNumber() && |
1223 int32_t i; | 1225 right->value()->ToInt32(&i)) { |
1224 if (!right->value()->ToInt32(&i)) { | 1226 if (left_intish != 0) { |
1225 FAIL(expr, "multiply must be a signed integer"); | 1227 FAIL(expr, "intish not allowed in multiply"); |
| 1228 } |
| 1229 } else { |
| 1230 FAIL(expr, "multiply must be by an integer literal"); |
1226 } | 1231 } |
1227 i = abs(i); | 1232 i = abs(i); |
1228 if (i >= 1 << 20) { | 1233 if (i >= (1 << 20)) { |
1229 FAIL(expr, "multiply must be by value in -2^20 < n < 2^20"); | 1234 FAIL(expr, "multiply must be by value in -2^20 < n < 2^20"); |
1230 } | 1235 } |
1231 intish_ = i; | 1236 intish_ = i; |
1232 IntersectResult(expr, cache_.kAsmInt); | 1237 IntersectResult(expr, cache_.kAsmInt); |
1233 return; | 1238 return; |
1234 } else { | 1239 } else { |
1235 intish_ = left_intish + right_intish + 1; | 1240 intish_ = left_intish + right_intish + 1; |
1236 if (expr->op() == Token::ADD || expr->op() == Token::SUB) { | 1241 if (expr->op() == Token::ADD || expr->op() == Token::SUB) { |
1237 if (intish_ > kMaxUncombinedAdditiveSteps) { | 1242 if (intish_ > kMaxUncombinedAdditiveSteps) { |
1238 FAIL(expr, "too many consecutive additive ops"); | 1243 FAIL(expr, "too many consecutive additive ops"); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 } | 1560 } |
1556 | 1561 |
1557 | 1562 |
1558 void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) { | 1563 void AsmTyper::VisitRewritableExpression(RewritableExpression* expr) { |
1559 RECURSE(Visit(expr->expression())); | 1564 RECURSE(Visit(expr->expression())); |
1560 } | 1565 } |
1561 | 1566 |
1562 | 1567 |
1563 } // namespace internal | 1568 } // namespace internal |
1564 } // namespace v8 | 1569 } // namespace v8 |
OLD | NEW |