Chromium Code Reviews| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/typing-asm.h" | 7 #include "src/typing-asm.h" |
| 8 | 8 |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 if (!valid_) return; \ | 34 if (!valid_) return; \ |
| 35 } while (false) | 35 } while (false) |
| 36 | 36 |
| 37 | 37 |
| 38 AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, | 38 AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, |
| 39 FunctionLiteral* root) | 39 FunctionLiteral* root) |
| 40 : zone_(zone), | 40 : zone_(zone), |
| 41 script_(script), | 41 script_(script), |
| 42 root_(root), | 42 root_(root), |
| 43 valid_(true), | 43 valid_(true), |
| 44 allow_simd_(false), | |
| 44 stdlib_types_(zone), | 45 stdlib_types_(zone), |
| 45 stdlib_heap_types_(zone), | 46 stdlib_heap_types_(zone), |
| 46 stdlib_math_types_(zone), | 47 stdlib_math_types_(zone), |
| 47 global_variable_type_(HashMap::PointersMatch, | 48 #define V(NAME, Name, name, lane_count, lane_type) \ |
| 48 ZoneHashMap::kDefaultHashMapCapacity, | 49 stdlib_simd_##name##_types_(zone), |
| 49 ZoneAllocationPolicy(zone)), | 50 SIMD128_TYPES(V) |
| 51 #undef V | |
| 52 global_variable_type_(HashMap::PointersMatch, | |
| 53 ZoneHashMap::kDefaultHashMapCapacity, | |
| 54 ZoneAllocationPolicy(zone)), | |
| 50 local_variable_type_(HashMap::PointersMatch, | 55 local_variable_type_(HashMap::PointersMatch, |
| 51 ZoneHashMap::kDefaultHashMapCapacity, | 56 ZoneHashMap::kDefaultHashMapCapacity, |
| 52 ZoneAllocationPolicy(zone)), | 57 ZoneAllocationPolicy(zone)), |
| 53 in_function_(false), | 58 in_function_(false), |
| 54 building_function_tables_(false), | 59 building_function_tables_(false), |
| 55 cache_(TypeCache::Get()) { | 60 cache_(TypeCache::Get()) { |
| 56 InitializeAstVisitor(isolate); | 61 InitializeAstVisitor(isolate); |
| 57 InitializeStdlib(); | 62 InitializeStdlib(); |
| 58 } | 63 } |
| 59 | 64 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 if (expected_shift < 0 || n != expected_shift) { | 686 if (expected_shift < 0 || n != expected_shift) { |
| 682 FAIL(right, "heap access shift must match element size"); | 687 FAIL(right, "heap access shift must match element size"); |
| 683 } | 688 } |
| 684 bin->set_bounds(Bounds(cache_.kAsmSigned)); | 689 bin->set_bounds(Bounds(cache_.kAsmSigned)); |
| 685 } | 690 } |
| 686 } | 691 } |
| 687 IntersectResult(expr, type); | 692 IntersectResult(expr, type); |
| 688 } | 693 } |
| 689 | 694 |
| 690 | 695 |
| 696 bool AsmTyper::IsStdlibObject(Expression* expr) { | |
| 697 VariableProxy* proxy = expr->AsVariableProxy(); | |
| 698 if (proxy == NULL) { | |
| 699 return false; | |
| 700 } | |
| 701 Variable* var = proxy->var(); | |
| 702 if (var->location() != VariableLocation::PARAMETER || var->index() != 0) { | |
| 703 return false; | |
| 704 } | |
| 705 return true; | |
| 706 } | |
| 707 | |
| 708 | |
| 709 bool AsmTyper::IsMathObject(Expression* expr) { | |
| 710 Property* property = expr->AsProperty(); | |
| 711 if (property == NULL) { | |
| 712 return false; | |
| 713 } | |
| 714 if (!IsStdlibObject(property->obj())) { | |
| 715 return false; | |
| 716 } | |
| 717 Literal* key = property->key()->AsLiteral(); | |
| 718 if (key == NULL || !key->IsPropertyName() || | |
|
titzer
2015/11/24 19:38:02
Maybe we can factor out the Literal+IsPropertyName
bradn
2015/11/25 04:05:40
Done.
| |
| 719 !key->AsPropertyName()->IsUtf8EqualTo(CStrVector("Math"))) { | |
| 720 return false; | |
| 721 } | |
| 722 return true; | |
| 723 } | |
| 724 | |
| 725 | |
| 726 bool AsmTyper::IsSIMDObject(Expression* expr) { | |
| 727 Property* property = expr->AsProperty(); | |
| 728 if (property == NULL) { | |
| 729 return false; | |
| 730 } | |
| 731 if (!IsStdlibObject(property->obj())) { | |
| 732 return false; | |
| 733 } | |
| 734 Literal* key = property->key()->AsLiteral(); | |
| 735 if (key == NULL || !key->IsPropertyName() || | |
| 736 !key->AsPropertyName()->IsUtf8EqualTo(CStrVector("SIMD"))) { | |
| 737 return false; | |
| 738 } | |
| 739 return true; | |
| 740 } | |
| 741 | |
| 742 | |
| 743 bool AsmTyper::IsSIMDTypeObject(Expression* expr, const char* name) { | |
| 744 Property* property = expr->AsProperty(); | |
| 745 if (property == NULL) { | |
| 746 return false; | |
| 747 } | |
| 748 if (!IsSIMDObject(property->obj())) { | |
| 749 return false; | |
| 750 } | |
| 751 Literal* key = property->key()->AsLiteral(); | |
| 752 if (key == NULL || !key->IsPropertyName() || | |
| 753 !key->AsPropertyName()->IsUtf8EqualTo(CStrVector(name))) { | |
| 754 return false; | |
| 755 } | |
| 756 return true; | |
| 757 } | |
| 758 | |
| 759 | |
| 691 void AsmTyper::VisitProperty(Property* expr) { | 760 void AsmTyper::VisitProperty(Property* expr) { |
| 692 // stdlib.Math.x | 761 if (IsMathObject(expr->obj())) { |
| 693 Property* inner_prop = expr->obj()->AsProperty(); | |
| 694 if (inner_prop != NULL) { | |
| 695 // Get property name. | |
| 696 Literal* key = expr->key()->AsLiteral(); | 762 Literal* key = expr->key()->AsLiteral(); |
| 697 if (key == NULL || !key->IsPropertyName()) | 763 if (key == NULL || !key->IsPropertyName()) |
| 698 FAIL(expr, "invalid type annotation on property 2"); | 764 FAIL(expr, "invalid key used on Math object"); |
| 699 Handle<String> name = key->AsPropertyName(); | 765 Handle<String> name = key->AsPropertyName(); |
| 700 | |
| 701 // Check that inner property name is "Math". | |
| 702 Literal* math_key = inner_prop->key()->AsLiteral(); | |
| 703 if (math_key == NULL || !math_key->IsPropertyName() || | |
| 704 !math_key->AsPropertyName()->IsUtf8EqualTo(CStrVector("Math"))) | |
| 705 FAIL(expr, "invalid type annotation on stdlib (a1)"); | |
| 706 | |
| 707 // Check that object is stdlib. | |
| 708 VariableProxy* proxy = inner_prop->obj()->AsVariableProxy(); | |
| 709 if (proxy == NULL) FAIL(expr, "invalid type annotation on stdlib (a2)"); | |
| 710 Variable* var = proxy->var(); | |
| 711 if (var->location() != VariableLocation::PARAMETER || var->index() != 0) | |
| 712 FAIL(expr, "invalid type annotation on stdlib (a3)"); | |
| 713 | |
| 714 // Look up library type. | |
| 715 Type* type = LibType(stdlib_math_types_, name); | 766 Type* type = LibType(stdlib_math_types_, name); |
| 716 if (type == NULL) FAIL(expr, "unknown standard function 3 "); | 767 if (type == NULL) FAIL(expr, "unknown Math function"); |
| 717 SetResult(expr, type); | 768 SetResult(expr, type); |
| 718 return; | 769 return; |
| 719 } | 770 } |
| 771 #define V(NAME, Name, name, lane_count, lane_type) \ | |
| 772 if (IsSIMDTypeObject(expr->obj(), #name)) { \ | |
| 773 Literal* key = expr->key()->AsLiteral(); \ | |
| 774 if (key == NULL || !key->IsPropertyName()) \ | |
| 775 FAIL(expr, "invalid key used on SIMD type object"); \ | |
| 776 Handle<String> kname = key->AsPropertyName(); \ | |
| 777 Type* type = LibType(stdlib_simd_##name##_types_, kname); \ | |
| 778 if (type == NULL) FAIL(expr, "unknown Math function"); \ | |
| 779 SetResult(expr, type); \ | |
| 780 return; \ | |
| 781 } | |
| 782 SIMD128_TYPES(V) | |
| 783 #undef V | |
| 720 | 784 |
| 721 // Only recurse at this point so that we avoid needing | 785 // Only recurse at this point so that we avoid needing |
| 722 // stdlib.Math to have a real type. | 786 // stdlib.Math to have a real type. |
| 723 RECURSE(VisitWithExpectation(expr->obj(), Type::Any(), | 787 RECURSE(VisitWithExpectation(expr->obj(), Type::Any(), |
| 724 "property holder expected to be object")); | 788 "property holder expected to be object")); |
| 725 | 789 |
| 726 // For heap view or function table access. | 790 // For heap view or function table access. |
| 727 if (computed_type_->IsArray()) { | 791 if (computed_type_->IsArray()) { |
| 728 VisitHeapAccess(expr); | 792 VisitHeapAccess(expr); |
| 729 return; | 793 return; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1206 computed_type_->Print(); | 1270 computed_type_->Print(); |
| 1207 PrintF("Expected type: "); | 1271 PrintF("Expected type: "); |
| 1208 expected_type_->Print(); | 1272 expected_type_->Print(); |
| 1209 #endif | 1273 #endif |
| 1210 FAIL(expr, msg); | 1274 FAIL(expr, msg); |
| 1211 } | 1275 } |
| 1212 expected_type_ = save; | 1276 expected_type_ = save; |
| 1213 } | 1277 } |
| 1214 } // namespace internal | 1278 } // namespace internal |
| 1215 } // namespace v8 | 1279 } // namespace v8 |
| OLD | NEW |