typing-asm.h revision 1b268ca467c924004286c97bac133db489cf43d0
1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2015 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_TYPING_ASM_H_ 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_TYPING_ASM_H_ 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/allocation.h" 9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/ast/ast.h" 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/effects.h" 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/type-info.h" 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/types.h" 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/zone.h" 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace v8 { 16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace internal { 17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass TypeCache; 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass AsmTyper : public AstVisitor { 21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch public: 22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script, 23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch FunctionLiteral* root); 24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool Validate(); 25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void set_allow_simd(bool simd) { allow_simd_ = simd; } 26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch const char* error_message() { return error_message_; } 27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch enum StandardMember { 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kNone = 0, 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kStdlib, 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kInfinity, 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kNaN, 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathAcos, 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathAsin, 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathAtan, 36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathCos, 37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathSin, 38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathTan, 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathExp, 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathLog, 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathCeil, 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathFloor, 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathSqrt, 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathAbs, 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathMin, 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathMax, 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathAtan2, 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathPow, 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathImul, 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathFround, 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathE, 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathLN10, 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathLN2, 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathLOG2E, 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathLOG10E, 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathPI, 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathSQRT1_2, 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch kMathSQRT2, 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch }; 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch StandardMember VariableAsStandardMember(Variable* variable); 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch private: 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Zone* zone_; 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Isolate* isolate_; 68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Script* script_; 69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch FunctionLiteral* root_; 70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool valid_; 71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool allow_simd_; 72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch struct VariableInfo : public ZoneObject { 74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* type; 75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool is_check_function; 76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool is_constructor_function; 77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch StandardMember standard_member; 78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch VariableInfo() 80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch : type(NULL), 81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch is_check_function(false), 82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch is_constructor_function(false), 83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch standard_member(kNone) {} 84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch explicit VariableInfo(Type* t) 85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch : type(t), 86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch is_check_function(false), 87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch is_constructor_function(false), 88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch standard_member(kNone) {} 89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch }; 90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch // Information for bi-directional typing with a cap on nesting depth. 92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* expected_type_; 93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* computed_type_; 94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch VariableInfo* property_info_; 95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch int32_t intish_; // How many ops we've gone without a x|0. 96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* return_type_; // Return type of last function. 98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch size_t array_size_; // Array size of last ArrayLiteral. 99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch typedef ZoneMap<std::string, VariableInfo*> ObjectTypeMap; 101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ObjectTypeMap stdlib_types_; 102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ObjectTypeMap stdlib_heap_types_; 103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ObjectTypeMap stdlib_math_types_; 104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V(NAME, Name, name, lane_count, lane_type) \ 105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ObjectTypeMap stdlib_simd_##name##_types_; \ 106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch VariableInfo* stdlib_simd_##name##_constructor_type_; 107b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch SIMD128_TYPES(V) 108b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#undef V 109b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 110b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch // Map from Variable* to global/local variable Type*. 111b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ZoneHashMap global_variable_type_; 112b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ZoneHashMap local_variable_type_; 113b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 114b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool in_function_; // In module function? 115b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool building_function_tables_; 116b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool visiting_exports_; 117b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 118b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch TypeCache const& cache_; 119b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 120b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch static const int kErrorMessageLimit = 100; 121b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch char error_message_[kErrorMessageLimit]; 122b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 123b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch static const int kMaxUncombinedAdditiveSteps = 1 << 20; 124b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch static const int kMaxUncombinedMultiplicativeSteps = 1; 125b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 126b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void InitializeStdlib(); 127b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void InitializeStdlibSIMD(); 128b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 129b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitDeclarations(ZoneList<Declaration*>* d) override; 130b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitStatements(ZoneList<Statement*>* s) override; 131b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 132b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitExpressionAnnotation(Expression* e, Variable* var, bool is_return); 133b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitFunctionAnnotation(FunctionLiteral* f); 134b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitAsmModule(FunctionLiteral* f); 135b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 136b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitHeapAccess(Property* expr, bool assigning, Type* assignment_type); 137b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 138b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void CheckPolymorphicStdlibArguments(enum StandardMember standard_member, 139b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ZoneList<Expression*>* args); 140b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 141b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Expression* GetReceiverOfPropertyAccess(Expression* expr, const char* name); 142b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool IsMathObject(Expression* expr); 143b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool IsSIMDObject(Expression* expr); 144b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool IsSIMDTypeObject(Expression* expr, const char* name); 145b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool IsStdlibObject(Expression* expr); 146b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 147b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitSIMDProperty(Property* expr); 148b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 149b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch int ElementShiftSize(Type* type); 150b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* StorageType(Type* type); 151b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 152b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void SetType(Variable* variable, Type* type); 153b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* GetType(Variable* variable); 154b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch VariableInfo* GetVariableInfo(Variable* variable, bool setting); 155b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void SetVariableInfo(Variable* variable, const VariableInfo* info); 156b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 157b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch VariableInfo* LibType(ObjectTypeMap* map, Handle<String> name); 158b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitLibraryAccess(ObjectTypeMap* map, Property* expr); 159b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 160b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void SetResult(Expression* expr, Type* type); 161b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void IntersectResult(Expression* expr, Type* type); 162b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 163b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitWithExpectation(Expression* expr, Type* expected_type, 164b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch const char* msg); 165b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 166b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitLiteral(Literal* expr, bool is_return); 167b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 168b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitVariableProxy(VariableProxy* expr, bool assignment); 169b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 170b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch void VisitIntegerBitwiseOperator(BinaryOperation* expr, Type* left_expected, 171b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Type* right_expected, Type* result_type, 172b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch bool conversion); 173b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 174b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch Zone* zone() const { return zone_; } 175b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 176b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define DECLARE_VISIT(type) void Visit##type(type* node) override; 177b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch AST_NODE_LIST(DECLARE_VISIT) 178b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#undef DECLARE_VISIT 179b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 180b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch DISALLOW_COPY_AND_ASSIGN(AsmTyper); 181b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}; 182b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} // namespace internal 183b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} // namespace v8 184b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 185b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif // V8_TYPING_ASM_H_ 186b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch