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(); | |
72 | 77 |
73 const char* error_message() const { return error_message_; } | 78 const char* error_message() const { return error_message_; } |
74 | 79 |
75 AsmType* TypeOf(AstNode* node) const; | 80 AsmType* TypeOf(AstNode* node) const; |
76 AsmType* TypeOf(Variable* v) const; | 81 AsmType* TypeOf(Variable* v) const; |
77 StandardMember VariableAsStandardMember(Variable* var); | 82 StandardMember VariableAsStandardMember(Variable* var); |
78 | 83 |
79 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; | 84 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; |
80 | 85 |
81 StdlibSet StdlibUses() const { return stdlib_uses_; } | 86 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) {} | 197 explicit Context(ZoneList<Statement*>* s) : statements_(s) {} |
193 ZoneList<Statement*>* statements_; | 198 ZoneList<Statement*>* statements_; |
194 int next_index_ = 0; | 199 int next_index_ = 0; |
195 }; | 200 }; |
196 | 201 |
197 ZoneVector<Context> context_stack_; | 202 ZoneVector<Context> context_stack_; |
198 | 203 |
199 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); | 204 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); |
200 }; | 205 }; |
201 | 206 |
207 class SourceLayoutTracker { | |
208 public: | |
209 SourceLayoutTracker() = default; | |
210 bool IsValid() const; | |
211 void AddUseAsm(const AstNode& node) { use_asm_.AddNewElement(node); } | |
212 void AddGlobal(const AstNode& node) { globals_.AddNewElement(node); } | |
213 void AddFunction(const AstNode& node) { functions_.AddNewElement(node); } | |
214 void AddTable(const AstNode& node) { tables_.AddNewElement(node); } | |
215 void AddExport(const AstNode& node) { exports_.AddNewElement(node); } | |
216 | |
217 private: | |
218 class Section { | |
219 public: | |
220 Section() = default; | |
221 Section(const Section&) = default; | |
222 Section& operator=(const Section&) = default; | |
223 | |
224 void AddNewElement(const AstNode& node); | |
225 bool OverlapsWith(const Section& other) const; | |
226 | |
227 private: | |
228 int start_ = kNoSourcePosition; | |
229 int end_ = kNoSourcePosition; | |
230 }; | |
231 | |
232 Section use_asm_; | |
233 Section globals_; | |
234 Section functions_; | |
235 Section tables_; | |
236 Section exports_; | |
237 | |
238 DISALLOW_COPY_AND_ASSIGN(SourceLayoutTracker); | |
239 }; | |
240 | |
202 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; | 241 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; |
203 void InitializeStdlib(); | 242 void InitializeStdlib(); |
204 void SetTypeOf(AstNode* node, AsmType* type); | 243 void SetTypeOf(AstNode* node, AsmType* type); |
205 | 244 |
206 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); | 245 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); |
207 bool AddGlobal(Variable* global, VariableInfo* info); | 246 bool AddGlobal(Variable* global, VariableInfo* info); |
208 bool AddLocal(Variable* global, VariableInfo* info); | 247 bool AddLocal(Variable* global, VariableInfo* info); |
209 // Used for 5.5 GlobalVariableTypeAnnotations | 248 // Used for 5.5 GlobalVariableTypeAnnotations |
210 VariableInfo* ImportLookup(Property* expr); | 249 VariableInfo* ImportLookup(Property* expr); |
211 // 3.3 Environment Lookup | 250 // 3.3 Environment Lookup |
212 // NOTE: In the spec, the lookup function's prototype is | 251 // NOTE: In the spec, the lookup function's prototype is |
213 // | 252 // |
214 // Lookup(Delta, Gamma, x) | 253 // Lookup(Delta, Gamma, x) |
215 // | 254 // |
216 // Delta is the global_scope_ member, and Gamma, local_scope_. | 255 // Delta is the global_scope_ member, and Gamma, local_scope_. |
217 VariableInfo* Lookup(Variable* variable) const; | 256 VariableInfo* Lookup(Variable* variable) const; |
218 | 257 |
219 // All of the ValidateXXX methods below return AsmType::None() in case of | 258 // All of the ValidateXXX methods below return AsmType::None() in case of |
220 // validation failure. | 259 // validation failure. |
221 | 260 |
222 // 6.1 ValidateModule | 261 // 6.1 ValidateModule |
223 AsmType* ValidateModule(FunctionLiteral* fun); | 262 AsmType* ValidateModuleBeforeFunctionsPhase(FunctionLiteral* fun); |
titzer
2016/11/28 10:40:11
Seems a little weird to use AsmType* as the return
bradn
2016/11/29 06:30:34
Used so the FAIL macro can be shared throughout.
N
| |
263 AsmType* ValidateModuleFunction(FunctionDeclaration* fun_decl); | |
264 AsmType* ValidateModuleFunctions(FunctionLiteral* fun); | |
265 AsmType* ValidateModuleAfterFunctionsPhase(FunctionLiteral* fun); | |
224 AsmType* ValidateGlobalDeclaration(Assignment* assign); | 266 AsmType* ValidateGlobalDeclaration(Assignment* assign); |
225 // 6.2 ValidateExport | 267 // 6.2 ValidateExport |
226 AsmType* ExportType(VariableProxy* fun_export); | 268 AsmType* ExportType(VariableProxy* fun_export); |
227 AsmType* ValidateExport(ReturnStatement* exports); | 269 AsmType* ValidateExport(ReturnStatement* exports); |
228 // 6.3 ValidateFunctionTable | 270 // 6.3 ValidateFunctionTable |
229 AsmType* ValidateFunctionTable(Assignment* assign); | 271 AsmType* ValidateFunctionTable(Assignment* assign); |
230 // 6.4 ValidateFunction | 272 // 6.4 ValidateFunction |
231 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); | 273 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); |
232 // 6.5 ValidateStatement | 274 // 6.5 ValidateStatement |
233 AsmType* ValidateStatement(Statement* statement); | 275 AsmType* ValidateStatement(Statement* statement); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 | 387 |
346 std::uintptr_t stack_limit_; | 388 std::uintptr_t stack_limit_; |
347 bool stack_overflow_ = false; | 389 bool stack_overflow_ = false; |
348 ZoneMap<AstNode*, AsmType*> node_types_; | 390 ZoneMap<AstNode*, AsmType*> node_types_; |
349 static const int kErrorMessageLimit = 128; | 391 static const int kErrorMessageLimit = 128; |
350 AsmType* fround_type_; | 392 AsmType* fround_type_; |
351 AsmType* ffi_type_; | 393 AsmType* ffi_type_; |
352 char error_message_[kErrorMessageLimit]; | 394 char error_message_[kErrorMessageLimit]; |
353 StdlibSet stdlib_uses_; | 395 StdlibSet stdlib_uses_; |
354 | 396 |
397 SourceLayoutTracker source_layout_; | |
398 ReturnStatement* module_return_; | |
399 ZoneVector<Assignment*> function_pointer_tables_; | |
400 | |
355 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); | 401 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); |
356 }; | 402 }; |
357 | 403 |
358 } // namespace wasm | 404 } // namespace wasm |
359 } // namespace internal | 405 } // namespace internal |
360 } // namespace v8 | 406 } // namespace v8 |
361 | 407 |
362 #endif // SRC_ASMJS_ASM_TYPER_H_ | 408 #endif // SRC_ASMJS_ASM_TYPER_H_ |
OLD | NEW |