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