| 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 #ifndef V8_TYPING_ASM_H_ | 5 #ifndef V8_TYPING_ASM_H_ |
| 6 #define V8_TYPING_ASM_H_ | 6 #define V8_TYPING_ASM_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/effects.h" | 10 #include "src/effects.h" |
| 11 #include "src/type-info.h" | 11 #include "src/type-info.h" |
| 12 #include "src/types.h" | 12 #include "src/types.h" |
| 13 #include "src/zone.h" | 13 #include "src/zone.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 class TypeCache; | 18 class TypeCache; |
| 19 | 19 |
| 20 class AsmTyper : public AstVisitor { | 20 class AsmTyper : public AstVisitor { |
| 21 public: | 21 public: |
| 22 explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script, | 22 explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script, |
| 23 FunctionLiteral* root); | 23 FunctionLiteral* root); |
| 24 bool Validate(); | 24 bool Validate(); |
| 25 void set_allow_simd(bool simd); |
| 25 const char* error_message() { return error_message_; } | 26 const char* error_message() { return error_message_; } |
| 26 | 27 |
| 27 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 28 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 28 | 29 |
| 29 private: | 30 private: |
| 30 Zone* zone_; | 31 Zone* zone_; |
| 32 Isolate* isolate_; |
| 31 Script* script_; | 33 Script* script_; |
| 32 FunctionLiteral* root_; | 34 FunctionLiteral* root_; |
| 33 bool valid_; | 35 bool valid_; |
| 36 bool allow_simd_; |
| 37 |
| 38 struct VariableInfo : public ZoneObject { |
| 39 Type* type; |
| 40 bool is_stdlib_object; |
| 41 bool is_check_function; |
| 42 bool is_constructor_function; |
| 43 |
| 44 VariableInfo() |
| 45 : type(NULL), |
| 46 is_stdlib_object(false), |
| 47 is_check_function(false), |
| 48 is_constructor_function(false) {} |
| 49 explicit VariableInfo(Type* t) |
| 50 : type(t), is_check_function(false), is_constructor_function(false) {} |
| 51 }; |
| 34 | 52 |
| 35 // Information for bi-directional typing with a cap on nesting depth. | 53 // Information for bi-directional typing with a cap on nesting depth. |
| 36 Type* expected_type_; | 54 Type* expected_type_; |
| 37 Type* computed_type_; | 55 Type* computed_type_; |
| 56 VariableInfo* property_info_; |
| 38 int intish_; // How many ops we've gone without a x|0. | 57 int intish_; // How many ops we've gone without a x|0. |
| 39 | 58 |
| 40 Type* return_type_; // Return type of last function. | 59 Type* return_type_; // Return type of last function. |
| 41 size_t array_size_; // Array size of last ArrayLiteral. | 60 size_t array_size_; // Array size of last ArrayLiteral. |
| 42 | 61 |
| 43 typedef ZoneMap<std::string, Type*> ObjectTypeMap; | 62 typedef ZoneMap<std::string, VariableInfo*> ObjectTypeMap; |
| 44 ObjectTypeMap stdlib_types_; | 63 ObjectTypeMap stdlib_types_; |
| 45 ObjectTypeMap stdlib_heap_types_; | 64 ObjectTypeMap stdlib_heap_types_; |
| 46 ObjectTypeMap stdlib_math_types_; | 65 ObjectTypeMap stdlib_math_types_; |
| 66 #define V(NAME, Name, name, lane_count, lane_type) \ |
| 67 ObjectTypeMap stdlib_simd_##name##_types_; \ |
| 68 VariableInfo* stdlib_simd_##name##_constructor_type_; |
| 69 SIMD128_TYPES(V) |
| 70 #undef V |
| 47 | 71 |
| 48 // Map from Variable* to global/local variable Type*. | 72 // Map from Variable* to global/local variable Type*. |
| 49 ZoneHashMap global_variable_type_; | 73 ZoneHashMap global_variable_type_; |
| 50 ZoneHashMap local_variable_type_; | 74 ZoneHashMap local_variable_type_; |
| 51 | 75 |
| 52 bool in_function_; // In module function? | 76 bool in_function_; // In module function? |
| 53 bool building_function_tables_; | 77 bool building_function_tables_; |
| 54 | 78 |
| 55 TypeCache const& cache_; | 79 TypeCache const& cache_; |
| 56 | 80 |
| 57 static const int kErrorMessageLimit = 100; | 81 static const int kErrorMessageLimit = 100; |
| 58 char error_message_[kErrorMessageLimit]; | 82 char error_message_[kErrorMessageLimit]; |
| 59 | 83 |
| 60 static const int kMaxUncombinedAdditiveSteps = 1 << 20; | 84 static const int kMaxUncombinedAdditiveSteps = 1 << 20; |
| 61 static const int kMaxUncombinedMultiplicativeSteps = 1; | 85 static const int kMaxUncombinedMultiplicativeSteps = 1; |
| 62 | 86 |
| 63 void InitializeStdlib(); | 87 void InitializeStdlib(); |
| 88 void InitializeStdlibSIMD(); |
| 64 | 89 |
| 65 void VisitDeclarations(ZoneList<Declaration*>* d) override; | 90 void VisitDeclarations(ZoneList<Declaration*>* d) override; |
| 66 void VisitStatements(ZoneList<Statement*>* s) override; | 91 void VisitStatements(ZoneList<Statement*>* s) override; |
| 67 | 92 |
| 68 void VisitExpressionAnnotation(Expression* e, Variable* var, bool is_return); | 93 void VisitExpressionAnnotation(Expression* e, Variable* var, bool is_return); |
| 69 void VisitFunctionAnnotation(FunctionLiteral* f); | 94 void VisitFunctionAnnotation(FunctionLiteral* f); |
| 70 void VisitAsmModule(FunctionLiteral* f); | 95 void VisitAsmModule(FunctionLiteral* f); |
| 71 | 96 |
| 72 void VisitHeapAccess(Property* expr, bool assigning, Type* assignment_type); | 97 void VisitHeapAccess(Property* expr, bool assigning, Type* assignment_type); |
| 73 | 98 |
| 99 Expression* GetReceiverOfPropertyAccess(Expression* expr, const char* name); |
| 100 bool IsMathObject(Expression* expr); |
| 101 bool IsSIMDObject(Expression* expr); |
| 102 bool IsSIMDTypeObject(Expression* expr, const char* name); |
| 103 bool IsStdlibObject(Expression* expr); |
| 104 |
| 105 void VisitSIMDProperty(Property* expr); |
| 106 |
| 74 int ElementShiftSize(Type* type); | 107 int ElementShiftSize(Type* type); |
| 75 Type* StorageType(Type* type); | 108 Type* StorageType(Type* type); |
| 76 | 109 |
| 77 void SetType(Variable* variable, Type* type); | 110 void SetType(Variable* variable, Type* type); |
| 78 Type* GetType(Variable* variable); | 111 Type* GetType(Variable* variable); |
| 112 VariableInfo* GetVariableInfo(Variable* variable, bool setting); |
| 113 void SetVariableInfo(Variable* variable, const VariableInfo* info); |
| 79 | 114 |
| 80 Type* LibType(ObjectTypeMap map, Handle<String> name); | 115 VariableInfo* LibType(ObjectTypeMap* map, Handle<String> name); |
| 116 void VisitLibraryAccess(ObjectTypeMap* map, Property* expr); |
| 81 | 117 |
| 82 void SetResult(Expression* expr, Type* type); | 118 void SetResult(Expression* expr, Type* type); |
| 83 void IntersectResult(Expression* expr, Type* type); | 119 void IntersectResult(Expression* expr, Type* type); |
| 84 | 120 |
| 85 void VisitWithExpectation(Expression* expr, Type* expected_type, | 121 void VisitWithExpectation(Expression* expr, Type* expected_type, |
| 86 const char* msg); | 122 const char* msg); |
| 87 | 123 |
| 88 void VisitLiteral(Literal* expr, bool is_return); | 124 void VisitLiteral(Literal* expr, bool is_return); |
| 89 | 125 |
| 90 void VisitIntegerBitwiseOperator(BinaryOperation* expr, Type* left_expected, | 126 void VisitIntegerBitwiseOperator(BinaryOperation* expr, Type* left_expected, |
| 91 Type* right_expected, Type* result_type, | 127 Type* right_expected, Type* result_type, |
| 92 bool conversion); | 128 bool conversion); |
| 93 | 129 |
| 94 Zone* zone() const { return zone_; } | 130 Zone* zone() const { return zone_; } |
| 95 | 131 |
| 96 #define DECLARE_VISIT(type) void Visit##type(type* node) override; | 132 #define DECLARE_VISIT(type) void Visit##type(type* node) override; |
| 97 AST_NODE_LIST(DECLARE_VISIT) | 133 AST_NODE_LIST(DECLARE_VISIT) |
| 98 #undef DECLARE_VISIT | 134 #undef DECLARE_VISIT |
| 99 | 135 |
| 100 DISALLOW_COPY_AND_ASSIGN(AsmTyper); | 136 DISALLOW_COPY_AND_ASSIGN(AsmTyper); |
| 101 }; | 137 }; |
| 102 } // namespace internal | 138 } // namespace internal |
| 103 } // namespace v8 | 139 } // namespace v8 |
| 104 | 140 |
| 105 #endif // V8_TYPING_ASM_H_ | 141 #endif // V8_TYPING_ASM_H_ |
| OLD | NEW |