OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 SRC_ASMJS_ASM_TYPER_H_ | 5 #ifndef SRC_ASMJS_ASM_TYPER_H_ |
6 #define SRC_ASMJS_ASM_TYPER_H_ | 6 #define SRC_ASMJS_ASM_TYPER_H_ |
7 | 7 |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 | 11 |
12 #include "src/allocation.h" | 12 #include "src/allocation.h" |
13 #include "src/asmjs/asm-types.h" | 13 #include "src/asmjs/asm-types.h" |
14 #include "src/ast/ast-type-bounds.h" | 14 #include "src/ast/ast-type-bounds.h" |
15 #include "src/ast/ast-types.h" | 15 #include "src/ast/ast-types.h" |
16 #include "src/ast/ast.h" | 16 #include "src/ast/ast.h" |
17 #include "src/effects.h" | 17 #include "src/effects.h" |
18 #include "src/type-info.h" | 18 #include "src/type-info.h" |
19 #include "src/zone/zone-containers.h" | 19 #include "src/zone/zone-containers.h" |
20 #include "src/zone/zone.h" | 20 #include "src/zone/zone.h" |
21 | 21 |
22 namespace v8 { | 22 namespace v8 { |
23 namespace internal { | 23 namespace internal { |
24 namespace wasm { | 24 namespace wasm { |
25 | 25 |
26 class AsmType; | 26 class AsmType; |
27 class AsmTyperHarnessBuilder; | 27 class AsmTyperHarnessBuilder; |
| 28 class SourceLayoutTracker; |
28 | 29 |
29 class AsmTyper final { | 30 class AsmTyper final { |
30 public: | 31 public: |
31 enum StandardMember { | 32 enum StandardMember { |
32 kHeap = -4, | 33 kHeap = -4, |
33 kFFI = -3, | 34 kFFI = -3, |
34 kStdlib = -2, | 35 kStdlib = -2, |
35 kModule = -1, | 36 kModule = -1, |
36 kNone = 0, | 37 kNone = 0, |
37 kInfinity, | 38 kInfinity, |
(...skipping 24 matching lines...) Expand all Loading... |
62 kMathLOG10E, | 63 kMathLOG10E, |
63 kMathPI, | 64 kMathPI, |
64 kMathSQRT1_2, | 65 kMathSQRT1_2, |
65 kMathSQRT2, | 66 kMathSQRT2, |
66 }; | 67 }; |
67 | 68 |
68 ~AsmTyper() = default; | 69 ~AsmTyper() = default; |
69 AsmTyper(Isolate* isolate, Zone* zone, Script* script, FunctionLiteral* root); | 70 AsmTyper(Isolate* isolate, Zone* zone, Script* script, FunctionLiteral* root); |
70 | 71 |
71 bool Validate(); | 72 bool Validate(); |
| 73 // Do asm.js validation in phases (to interleave with conversion to wasm). |
| 74 bool ValidateBeforeFunctionsPhase(); |
| 75 bool ValidateInnerFunction(FunctionDeclaration* decl); |
| 76 bool ValidateAfterFunctionsPhase(); |
| 77 void ClearFunctionNodeTypes(); |
72 | 78 |
73 const char* error_message() const { return error_message_; } | 79 const char* error_message() const { return error_message_; } |
74 | 80 |
75 AsmType* TypeOf(AstNode* node) const; | 81 AsmType* TypeOf(AstNode* node) const; |
76 AsmType* TypeOf(Variable* v) const; | 82 AsmType* TypeOf(Variable* v) const; |
77 StandardMember VariableAsStandardMember(Variable* var); | 83 StandardMember VariableAsStandardMember(Variable* var); |
78 | 84 |
79 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; | 85 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; |
80 | 86 |
81 StdlibSet StdlibUses() const { return stdlib_uses_; } | 87 StdlibSet StdlibUses() const { return stdlib_uses_; } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 explicit Context(ZoneList<Statement*>* s) : statements_(s) {} | 198 explicit Context(ZoneList<Statement*>* s) : statements_(s) {} |
193 ZoneList<Statement*>* statements_; | 199 ZoneList<Statement*>* statements_; |
194 int next_index_ = 0; | 200 int next_index_ = 0; |
195 }; | 201 }; |
196 | 202 |
197 ZoneVector<Context> context_stack_; | 203 ZoneVector<Context> context_stack_; |
198 | 204 |
199 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); | 205 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); |
200 }; | 206 }; |
201 | 207 |
| 208 class SourceLayoutTracker { |
| 209 public: |
| 210 SourceLayoutTracker() = default; |
| 211 bool IsValid() const; |
| 212 void AddUseAsm(const AstNode& node) { use_asm_.AddNewElement(node); } |
| 213 void AddGlobal(const AstNode& node) { globals_.AddNewElement(node); } |
| 214 void AddFunction(const AstNode& node) { functions_.AddNewElement(node); } |
| 215 void AddTable(const AstNode& node) { tables_.AddNewElement(node); } |
| 216 void AddExport(const AstNode& node) { exports_.AddNewElement(node); } |
| 217 |
| 218 private: |
| 219 class Section { |
| 220 public: |
| 221 Section() = default; |
| 222 Section(const Section&) = default; |
| 223 Section& operator=(const Section&) = default; |
| 224 |
| 225 void AddNewElement(const AstNode& node); |
| 226 bool OverlapsWith(const Section& other) const; |
| 227 |
| 228 private: |
| 229 int start_ = kNoSourcePosition; |
| 230 int end_ = kNoSourcePosition; |
| 231 }; |
| 232 |
| 233 Section use_asm_; |
| 234 Section globals_; |
| 235 Section functions_; |
| 236 Section tables_; |
| 237 Section exports_; |
| 238 |
| 239 DISALLOW_COPY_AND_ASSIGN(SourceLayoutTracker); |
| 240 }; |
| 241 |
202 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; | 242 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; |
203 void InitializeStdlib(); | 243 void InitializeStdlib(); |
204 void SetTypeOf(AstNode* node, AsmType* type); | 244 void SetTypeOf(AstNode* node, AsmType* type); |
205 | 245 |
206 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); | 246 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); |
207 bool AddGlobal(Variable* global, VariableInfo* info); | 247 bool AddGlobal(Variable* global, VariableInfo* info); |
208 bool AddLocal(Variable* global, VariableInfo* info); | 248 bool AddLocal(Variable* global, VariableInfo* info); |
209 // Used for 5.5 GlobalVariableTypeAnnotations | 249 // Used for 5.5 GlobalVariableTypeAnnotations |
210 VariableInfo* ImportLookup(Property* expr); | 250 VariableInfo* ImportLookup(Property* expr); |
211 // 3.3 Environment Lookup | 251 // 3.3 Environment Lookup |
212 // NOTE: In the spec, the lookup function's prototype is | 252 // NOTE: In the spec, the lookup function's prototype is |
213 // | 253 // |
214 // Lookup(Delta, Gamma, x) | 254 // Lookup(Delta, Gamma, x) |
215 // | 255 // |
216 // Delta is the global_scope_ member, and Gamma, local_scope_. | 256 // Delta is the global_scope_ member, and Gamma, local_scope_. |
217 VariableInfo* Lookup(Variable* variable) const; | 257 VariableInfo* Lookup(Variable* variable) const; |
218 | 258 |
219 // All of the ValidateXXX methods below return AsmType::None() in case of | 259 // All of the ValidateXXX methods below return AsmType::None() in case of |
220 // validation failure. | 260 // validation failure. |
221 | 261 |
222 // 6.1 ValidateModule | 262 // 6.1 ValidateModule |
223 AsmType* ValidateModule(FunctionLiteral* fun); | 263 AsmType* ValidateModuleBeforeFunctionsPhase(FunctionLiteral* fun); |
| 264 AsmType* ValidateModuleFunction(FunctionDeclaration* fun_decl); |
| 265 AsmType* ValidateModuleFunctions(FunctionLiteral* fun); |
| 266 AsmType* ValidateModuleAfterFunctionsPhase(FunctionLiteral* fun); |
224 AsmType* ValidateGlobalDeclaration(Assignment* assign); | 267 AsmType* ValidateGlobalDeclaration(Assignment* assign); |
225 // 6.2 ValidateExport | 268 // 6.2 ValidateExport |
226 AsmType* ExportType(VariableProxy* fun_export); | 269 AsmType* ExportType(VariableProxy* fun_export); |
227 AsmType* ValidateExport(ReturnStatement* exports); | 270 AsmType* ValidateExport(ReturnStatement* exports); |
228 // 6.3 ValidateFunctionTable | 271 // 6.3 ValidateFunctionTable |
229 AsmType* ValidateFunctionTable(Assignment* assign); | 272 AsmType* ValidateFunctionTable(Assignment* assign); |
230 // 6.4 ValidateFunction | 273 // 6.4 ValidateFunction |
231 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); | 274 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); |
232 // 6.5 ValidateStatement | 275 // 6.5 ValidateStatement |
233 AsmType* ValidateStatement(Statement* statement); | 276 AsmType* ValidateStatement(Statement* statement); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // the module name. | 381 // the module name. |
339 VariableInfo* module_info_; | 382 VariableInfo* module_info_; |
340 Handle<String> module_name_; | 383 Handle<String> module_name_; |
341 | 384 |
342 // 3 Environments | 385 // 3 Environments |
343 ZoneHashMap global_scope_; // 3.1 Global environment | 386 ZoneHashMap global_scope_; // 3.1 Global environment |
344 ZoneHashMap local_scope_; // 3.2 Variable environment | 387 ZoneHashMap local_scope_; // 3.2 Variable environment |
345 | 388 |
346 std::uintptr_t stack_limit_; | 389 std::uintptr_t stack_limit_; |
347 bool stack_overflow_ = false; | 390 bool stack_overflow_ = false; |
348 ZoneMap<AstNode*, AsmType*> node_types_; | 391 ZoneMap<AstNode*, AsmType*> module_node_types_; |
| 392 ZoneMap<AstNode*, AsmType*> function_node_types_; |
349 static const int kErrorMessageLimit = 128; | 393 static const int kErrorMessageLimit = 128; |
350 AsmType* fround_type_; | 394 AsmType* fround_type_; |
351 AsmType* ffi_type_; | 395 AsmType* ffi_type_; |
352 char error_message_[kErrorMessageLimit]; | 396 char error_message_[kErrorMessageLimit]; |
353 StdlibSet stdlib_uses_; | 397 StdlibSet stdlib_uses_; |
354 | 398 |
| 399 SourceLayoutTracker source_layout_; |
| 400 ReturnStatement* module_return_; |
| 401 ZoneVector<Assignment*> function_pointer_tables_; |
| 402 |
355 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); | 403 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); |
356 }; | 404 }; |
357 | 405 |
358 } // namespace wasm | 406 } // namespace wasm |
359 } // namespace internal | 407 } // namespace internal |
360 } // namespace v8 | 408 } // namespace v8 |
361 | 409 |
362 #endif // SRC_ASMJS_ASM_TYPER_H_ | 410 #endif // SRC_ASMJS_ASM_TYPER_H_ |
OLD | NEW |