| 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_map> | 10 #include <unordered_map> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 | 12 |
| 13 #include "src/allocation.h" | 13 #include "src/allocation.h" |
| 14 #include "src/asmjs/asm-types.h" | 14 #include "src/asmjs/asm-types.h" |
| 15 #include "src/ast/ast-type-bounds.h" | 15 #include "src/ast/ast-type-bounds.h" |
| 16 #include "src/ast/ast-types.h" | 16 #include "src/ast/ast-types.h" |
| 17 #include "src/ast/ast.h" | 17 #include "src/ast/ast.h" |
| 18 #include "src/effects.h" | 18 #include "src/effects.h" |
| 19 #include "src/messages.h" |
| 19 #include "src/type-info.h" | 20 #include "src/type-info.h" |
| 20 #include "src/zone/zone-containers.h" | 21 #include "src/zone/zone-containers.h" |
| 21 #include "src/zone/zone.h" | 22 #include "src/zone/zone.h" |
| 22 | 23 |
| 23 namespace v8 { | 24 namespace v8 { |
| 24 namespace internal { | 25 namespace internal { |
| 25 namespace wasm { | 26 namespace wasm { |
| 26 | 27 |
| 27 class AsmType; | 28 class AsmType; |
| 28 class AsmTyperHarnessBuilder; | 29 class AsmTyperHarnessBuilder; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 AsmTyper(Isolate* isolate, Zone* zone, Handle<Script> script, | 72 AsmTyper(Isolate* isolate, Zone* zone, Handle<Script> script, |
| 72 FunctionLiteral* root); | 73 FunctionLiteral* root); |
| 73 | 74 |
| 74 bool Validate(); | 75 bool Validate(); |
| 75 // Do asm.js validation in phases (to interleave with conversion to wasm). | 76 // Do asm.js validation in phases (to interleave with conversion to wasm). |
| 76 bool ValidateBeforeFunctionsPhase(); | 77 bool ValidateBeforeFunctionsPhase(); |
| 77 bool ValidateInnerFunction(FunctionDeclaration* decl); | 78 bool ValidateInnerFunction(FunctionDeclaration* decl); |
| 78 bool ValidateAfterFunctionsPhase(); | 79 bool ValidateAfterFunctionsPhase(); |
| 79 void ClearFunctionNodeTypes(); | 80 void ClearFunctionNodeTypes(); |
| 80 | 81 |
| 81 const char* error_message() const { return error_message_; } | 82 Handle<JSMessageObject> error_message() const { return error_message_; } |
| 83 const MessageLocation* message_location() const { return &message_location_; } |
| 82 | 84 |
| 83 AsmType* TypeOf(AstNode* node) const; | 85 AsmType* TypeOf(AstNode* node) const; |
| 84 AsmType* TypeOf(Variable* v) const; | 86 AsmType* TypeOf(Variable* v) const; |
| 85 StandardMember VariableAsStandardMember(Variable* var); | 87 StandardMember VariableAsStandardMember(Variable* var); |
| 86 | 88 |
| 87 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; | 89 typedef std::unordered_set<StandardMember, std::hash<int> > StdlibSet; |
| 88 | 90 |
| 89 StdlibSet StdlibUses() const { return stdlib_uses_; } | 91 StdlibSet StdlibUses() const { return stdlib_uses_; } |
| 90 | 92 |
| 91 // Each FFI import has a usage-site signature associated with it. | 93 // Each FFI import has a usage-site signature associated with it. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 bool IsGlobal() const { | 133 bool IsGlobal() const { |
| 132 return mutability_ == kImmutableGlobal || mutability_ == kConstGlobal || | 134 return mutability_ == kImmutableGlobal || mutability_ == kConstGlobal || |
| 133 mutability_ == kMutableGlobal; | 135 mutability_ == kMutableGlobal; |
| 134 } | 136 } |
| 135 | 137 |
| 136 bool IsStdlib() const { return standard_member_ == kStdlib; } | 138 bool IsStdlib() const { return standard_member_ == kStdlib; } |
| 137 bool IsFFI() const { return standard_member_ == kFFI; } | 139 bool IsFFI() const { return standard_member_ == kFFI; } |
| 138 bool IsHeap() const { return standard_member_ == kHeap; } | 140 bool IsHeap() const { return standard_member_ == kHeap; } |
| 139 | 141 |
| 140 void MarkDefined() { missing_definition_ = false; } | 142 void MarkDefined() { missing_definition_ = false; } |
| 141 void SetFirstForwardUse(int source_location); | 143 void SetFirstForwardUse(const MessageLocation& source_location); |
| 142 | 144 |
| 143 StandardMember standard_member() const { return standard_member_; } | 145 StandardMember standard_member() const { return standard_member_; } |
| 144 void set_standard_member(StandardMember standard_member) { | 146 void set_standard_member(StandardMember standard_member) { |
| 145 standard_member_ = standard_member; | 147 standard_member_ = standard_member; |
| 146 } | 148 } |
| 147 | 149 |
| 148 AsmType* type() const { return type_; } | 150 AsmType* type() const { return type_; } |
| 149 void set_type(AsmType* type) { type_ = type; } | 151 void set_type(AsmType* type) { type_ = type; } |
| 150 | 152 |
| 151 Mutability mutability() const { return mutability_; } | 153 Mutability mutability() const { return mutability_; } |
| 152 void set_mutability(Mutability mutability) { mutability_ = mutability; } | 154 void set_mutability(Mutability mutability) { mutability_ = mutability; } |
| 153 | 155 |
| 154 bool missing_definition() const { return missing_definition_; } | 156 bool missing_definition() const { return missing_definition_; } |
| 155 | 157 |
| 156 int source_location() const { return source_location_; } | 158 const MessageLocation* source_location() { return &source_location_; } |
| 157 | 159 |
| 158 static VariableInfo* ForSpecialSymbol(Zone* zone, | 160 static VariableInfo* ForSpecialSymbol(Zone* zone, |
| 159 StandardMember standard_member); | 161 StandardMember standard_member); |
| 160 | 162 |
| 161 private: | 163 private: |
| 162 AsmType* type_; | 164 AsmType* type_; |
| 163 StandardMember standard_member_ = kNone; | 165 StandardMember standard_member_ = kNone; |
| 164 Mutability mutability_ = kInvalidMutability; | 166 Mutability mutability_ = kInvalidMutability; |
| 165 // missing_definition_ is set to true for forward definition - i.e., use | 167 // missing_definition_ is set to true for forward definition - i.e., use |
| 166 // before definition. | 168 // before definition. |
| 167 bool missing_definition_ = false; | 169 bool missing_definition_ = false; |
| 168 // source_location_ holds the line number that first referenced this | 170 // Used for error messages. |
| 169 // VariableInfo. Used for error messages. | 171 MessageLocation source_location_; |
| 170 // TODO(bradnelson): When merged with console change, this should | |
| 171 // become a source location. | |
| 172 int source_location_ = -1; | |
| 173 }; | 172 }; |
| 174 | 173 |
| 175 // RAII-style manager for the in_function_ member variable. | 174 // RAII-style manager for the in_function_ member variable. |
| 176 struct FunctionScope { | 175 struct FunctionScope { |
| 177 explicit FunctionScope(AsmTyper* typer) : typer_(typer) { | 176 explicit FunctionScope(AsmTyper* typer) : typer_(typer) { |
| 178 DCHECK(!typer_->in_function_); | 177 DCHECK(!typer_->in_function_); |
| 179 typer_->in_function_ = true; | 178 typer_->in_function_ = true; |
| 180 typer_->local_scope_.Clear(); | 179 typer_->local_scope_.Clear(); |
| 181 typer_->return_type_ = AsmType::None(); | 180 typer_->return_type_ = AsmType::None(); |
| 182 } | 181 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ZoneHashMap global_scope_; // 3.1 Global environment | 389 ZoneHashMap global_scope_; // 3.1 Global environment |
| 391 ZoneHashMap local_scope_; // 3.2 Variable environment | 390 ZoneHashMap local_scope_; // 3.2 Variable environment |
| 392 | 391 |
| 393 std::uintptr_t stack_limit_; | 392 std::uintptr_t stack_limit_; |
| 394 bool stack_overflow_ = false; | 393 bool stack_overflow_ = false; |
| 395 std::unordered_map<AstNode*, AsmType*> module_node_types_; | 394 std::unordered_map<AstNode*, AsmType*> module_node_types_; |
| 396 std::unordered_map<AstNode*, AsmType*> function_node_types_; | 395 std::unordered_map<AstNode*, AsmType*> function_node_types_; |
| 397 static const int kErrorMessageLimit = 128; | 396 static const int kErrorMessageLimit = 128; |
| 398 AsmType* fround_type_; | 397 AsmType* fround_type_; |
| 399 AsmType* ffi_type_; | 398 AsmType* ffi_type_; |
| 400 char error_message_[kErrorMessageLimit]; | 399 Handle<JSMessageObject> error_message_; |
| 400 MessageLocation message_location_; |
| 401 StdlibSet stdlib_uses_; | 401 StdlibSet stdlib_uses_; |
| 402 | 402 |
| 403 SourceLayoutTracker source_layout_; | 403 SourceLayoutTracker source_layout_; |
| 404 ReturnStatement* module_return_; | 404 ReturnStatement* module_return_; |
| 405 ZoneVector<Assignment*> function_pointer_tables_; | 405 ZoneVector<Assignment*> function_pointer_tables_; |
| 406 | 406 |
| 407 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); | 407 DISALLOW_IMPLICIT_CONSTRUCTORS(AsmTyper); |
| 408 }; | 408 }; |
| 409 | 409 |
| 410 } // namespace wasm | 410 } // namespace wasm |
| 411 } // namespace internal | 411 } // namespace internal |
| 412 } // namespace v8 | 412 } // namespace v8 |
| 413 | 413 |
| 414 #endif // SRC_ASMJS_ASM_TYPER_H_ | 414 #endif // SRC_ASMJS_ASM_TYPER_H_ |
| OLD | NEW |