Chromium Code Reviews| 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 ValidatePhase1of2(); | |
| 75 bool ValidateInnerFunction(FunctionDeclaration* decl); | |
| 76 bool ValidatePhase2of2(); | |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 explicit Context(ZoneList<Statement*>* s) : statements_(s) {} | 189 explicit Context(ZoneList<Statement*>* s) : statements_(s) {} |
| 185 ZoneList<Statement*>* statements_; | 190 ZoneList<Statement*>* statements_; |
| 186 int next_index_ = 0; | 191 int next_index_ = 0; |
| 187 }; | 192 }; |
| 188 | 193 |
| 189 ZoneVector<Context> context_stack_; | 194 ZoneVector<Context> context_stack_; |
| 190 | 195 |
| 191 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); | 196 DISALLOW_IMPLICIT_CONSTRUCTORS(FlattenedStatements); |
| 192 }; | 197 }; |
| 193 | 198 |
| 199 class SourceLayoutTracker { | |
| 200 public: | |
| 201 SourceLayoutTracker() = default; | |
| 202 bool IsValid() const; | |
| 203 void AddUseAsm(const AstNode& node) { use_asm_.AddNewElement(node); } | |
| 204 void AddGlobal(const AstNode& node) { globals_.AddNewElement(node); } | |
| 205 void AddFunction(const AstNode& node) { functions_.AddNewElement(node); } | |
| 206 void AddTable(const AstNode& node) { tables_.AddNewElement(node); } | |
| 207 void AddExport(const AstNode& node) { exports_.AddNewElement(node); } | |
| 208 | |
| 209 private: | |
| 210 class Section { | |
| 211 public: | |
| 212 Section() = default; | |
| 213 Section(const Section&) = default; | |
| 214 Section& operator=(const Section&) = default; | |
| 215 | |
| 216 void AddNewElement(const AstNode& node); | |
| 217 bool OverlapsWith(const Section& other) const; | |
| 218 | |
| 219 private: | |
| 220 int start_ = kNoSourcePosition; | |
| 221 int end_ = kNoSourcePosition; | |
| 222 }; | |
| 223 | |
| 224 Section use_asm_; | |
| 225 Section globals_; | |
| 226 Section functions_; | |
| 227 Section tables_; | |
| 228 Section exports_; | |
| 229 | |
| 230 DISALLOW_COPY_AND_ASSIGN(SourceLayoutTracker); | |
| 231 }; | |
| 232 | |
| 194 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; | 233 using ObjectTypeMap = ZoneMap<std::string, VariableInfo*>; |
| 195 void InitializeStdlib(); | 234 void InitializeStdlib(); |
| 196 void SetTypeOf(AstNode* node, AsmType* type); | 235 void SetTypeOf(AstNode* node, AsmType* type); |
| 197 | 236 |
| 198 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); | 237 void AddForwardReference(VariableProxy* proxy, VariableInfo* info); |
| 199 bool AddGlobal(Variable* global, VariableInfo* info); | 238 bool AddGlobal(Variable* global, VariableInfo* info); |
| 200 bool AddLocal(Variable* global, VariableInfo* info); | 239 bool AddLocal(Variable* global, VariableInfo* info); |
| 201 // Used for 5.5 GlobalVariableTypeAnnotations | 240 // Used for 5.5 GlobalVariableTypeAnnotations |
| 202 VariableInfo* ImportLookup(Property* expr); | 241 VariableInfo* ImportLookup(Property* expr); |
| 203 // 3.3 Environment Lookup | 242 // 3.3 Environment Lookup |
| 204 // NOTE: In the spec, the lookup function's prototype is | 243 // NOTE: In the spec, the lookup function's prototype is |
| 205 // | 244 // |
| 206 // Lookup(Delta, Gamma, x) | 245 // Lookup(Delta, Gamma, x) |
| 207 // | 246 // |
| 208 // Delta is the global_scope_ member, and Gamma, local_scope_. | 247 // Delta is the global_scope_ member, and Gamma, local_scope_. |
| 209 VariableInfo* Lookup(Variable* variable) const; | 248 VariableInfo* Lookup(Variable* variable) const; |
| 210 | 249 |
| 211 // All of the ValidateXXX methods below return AsmType::None() in case of | 250 // All of the ValidateXXX methods below return AsmType::None() in case of |
| 212 // validation failure. | 251 // validation failure. |
| 213 | 252 |
| 214 // 6.1 ValidateModule | 253 // 6.1 ValidateModule |
| 215 AsmType* ValidateModule(FunctionLiteral* fun); | 254 AsmType* ValidateModulePhase1of2(FunctionLiteral* fun); |
|
titzer
2016/10/07 12:56:59
Can we get some more descriptive names for these p
bradn
2016/11/25 09:19:36
Done.
| |
| 255 AsmType* ValidateModuleFunction(FunctionDeclaration* fun_decl); | |
| 256 AsmType* ValidateModuleFunctions(FunctionLiteral* fun); | |
| 257 AsmType* ValidateModulePhase2of2(FunctionLiteral* fun); | |
| 216 AsmType* ValidateGlobalDeclaration(Assignment* assign); | 258 AsmType* ValidateGlobalDeclaration(Assignment* assign); |
| 217 // 6.2 ValidateExport | 259 // 6.2 ValidateExport |
| 218 AsmType* ExportType(VariableProxy* fun_export); | 260 AsmType* ExportType(VariableProxy* fun_export); |
| 219 AsmType* ValidateExport(ReturnStatement* exports); | 261 AsmType* ValidateExport(ReturnStatement* exports); |
| 220 // 6.3 ValidateFunctionTable | 262 // 6.3 ValidateFunctionTable |
| 221 AsmType* ValidateFunctionTable(Assignment* assign); | 263 AsmType* ValidateFunctionTable(Assignment* assign); |
| 222 // 6.4 ValidateFunction | 264 // 6.4 ValidateFunction |
| 223 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); | 265 AsmType* ValidateFunction(FunctionDeclaration* fun_decl); |
| 224 // 6.5 ValidateStatement | 266 // 6.5 ValidateStatement |
| 225 AsmType* ValidateStatement(Statement* statement); | 267 AsmType* ValidateStatement(Statement* statement); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 377 |
| 336 std::uintptr_t stack_limit_; | 378 std::uintptr_t stack_limit_; |
| 337 bool stack_overflow_ = false; | 379 bool stack_overflow_ = false; |
| 338 ZoneMap<AstNode*, AsmType*> node_types_; | 380 ZoneMap<AstNode*, AsmType*> node_types_; |
| 339 static const int kErrorMessageLimit = 100; | 381 static const int kErrorMessageLimit = 100; |
| 340 AsmType* fround_type_; | 382 AsmType* fround_type_; |
| 341 AsmType* ffi_type_; | 383 AsmType* ffi_type_; |
| 342 char error_message_[kErrorMessageLimit]; | 384 char error_message_[kErrorMessageLimit]; |
| 343 StdlibSet stdlib_uses_; | 385 StdlibSet stdlib_uses_; |
| 344 | 386 |
| 387 SourceLayoutTracker source_layout_; | |
| 388 ReturnStatement* module_return_; | |
| 389 ZoneVector<Assignment*> function_pointer_tables_; | |
| 390 | |
| 345 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); | 391 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); |
| 346 }; | 392 }; |
| 347 | 393 |
| 348 } // namespace wasm | 394 } // namespace wasm |
| 349 } // namespace internal | 395 } // namespace internal |
| 350 } // namespace v8 | 396 } // namespace v8 |
| 351 | 397 |
| 352 #endif // SRC_ASMJS_ASM_TYPER_H_ | 398 #endif // SRC_ASMJS_ASM_TYPER_H_ |
| OLD | NEW |