| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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 V8_COMPILER_WASM_COMPILER_H_ | 5 #ifndef V8_COMPILER_WASM_COMPILER_H_ |
| 6 #define V8_COMPILER_WASM_COMPILER_H_ | 6 #define V8_COMPILER_WASM_COMPILER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 // Clients of this interface shouldn't depend on lots of compiler internals. | 10 // Clients of this interface shouldn't depend on lots of compiler internals. |
| 11 // Do not include anything from src/compiler here! | 11 // Do not include anything from src/compiler here! |
| 12 #include "src/compilation-info.h" | 12 #include "src/compilation-info.h" |
| 13 #include "src/compiler.h" | 13 #include "src/compiler.h" |
| 14 #include "src/trap-handler/trap-handler.h" | 14 #include "src/trap-handler/trap-handler.h" |
| 15 #include "src/wasm/function-body-decoder.h" |
| 15 #include "src/wasm/wasm-module.h" | 16 #include "src/wasm/wasm-module.h" |
| 16 #include "src/wasm/wasm-opcodes.h" | 17 #include "src/wasm/wasm-opcodes.h" |
| 17 #include "src/wasm/wasm-result.h" | 18 #include "src/wasm/wasm-result.h" |
| 18 #include "src/zone/zone.h" | 19 #include "src/zone/zone.h" |
| 19 | 20 |
| 20 namespace v8 { | 21 namespace v8 { |
| 21 namespace internal { | 22 namespace internal { |
| 22 | 23 |
| 23 namespace compiler { | 24 namespace compiler { |
| 24 // Forward declarations for some compiler data structures. | 25 // Forward declarations for some compiler data structures. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 struct DecodeStruct; | 40 struct DecodeStruct; |
| 40 | 41 |
| 41 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}. | 42 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}. |
| 42 typedef compiler::Node TFNode; | 43 typedef compiler::Node TFNode; |
| 43 typedef compiler::JSGraph TFGraph; | 44 typedef compiler::JSGraph TFGraph; |
| 44 } // namespace wasm | 45 } // namespace wasm |
| 45 | 46 |
| 46 namespace compiler { | 47 namespace compiler { |
| 47 class WasmCompilationUnit final { | 48 class WasmCompilationUnit final { |
| 48 public: | 49 public: |
| 49 WasmCompilationUnit(wasm::ErrorThrower* thrower, Isolate* isolate, | 50 WasmCompilationUnit(Isolate* isolate, wasm::ModuleBytesEnv* module_env, |
| 50 wasm::ModuleBytesEnv* module_env, | 51 const wasm::WasmFunction* function); |
| 51 const wasm::WasmFunction* function, uint32_t index); | 52 WasmCompilationUnit(Isolate* isolate, wasm::ModuleEnv* module_env, |
| 53 wasm::FunctionBody body, wasm::WasmName name, int index); |
| 52 | 54 |
| 53 Zone* graph_zone() { return graph_zone_.get(); } | 55 Zone* graph_zone() { return graph_zone_.get(); } |
| 54 int index() const { return index_; } | 56 int func_index() const { return func_index_; } |
| 55 | 57 |
| 56 void ExecuteCompilation(); | 58 void ExecuteCompilation(); |
| 57 Handle<Code> FinishCompilation(); | 59 Handle<Code> FinishCompilation(wasm::ErrorThrower* thrower); |
| 58 | 60 |
| 59 static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, | 61 static Handle<Code> CompileWasmFunction(wasm::ErrorThrower* thrower, |
| 60 Isolate* isolate, | 62 Isolate* isolate, |
| 61 wasm::ModuleBytesEnv* module_env, | 63 wasm::ModuleBytesEnv* module_env, |
| 62 const wasm::WasmFunction* function) { | 64 const wasm::WasmFunction* function); |
| 63 WasmCompilationUnit unit(thrower, isolate, module_env, function, | |
| 64 function->func_index); | |
| 65 unit.ExecuteCompilation(); | |
| 66 return unit.FinishCompilation(); | |
| 67 } | |
| 68 | 65 |
| 69 private: | 66 private: |
| 70 SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms); | 67 SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms); |
| 71 char* GetTaggedFunctionName(const wasm::WasmFunction* function); | |
| 72 | 68 |
| 73 wasm::ErrorThrower* thrower_; | |
| 74 Isolate* isolate_; | 69 Isolate* isolate_; |
| 75 wasm::ModuleBytesEnv* module_env_; | 70 wasm::ModuleEnv* module_env_; |
| 76 const wasm::WasmFunction* function_; | 71 wasm::FunctionBody func_body_; |
| 77 // Function name is tagged with uint32 func_index - wasm#<func_index> | 72 wasm::WasmName func_name_; |
| 78 char function_name_[16]; | |
| 79 // The graph zone is deallocated at the end of ExecuteCompilation. | 73 // The graph zone is deallocated at the end of ExecuteCompilation. |
| 80 std::unique_ptr<Zone> graph_zone_; | 74 std::unique_ptr<Zone> graph_zone_; |
| 81 JSGraph* jsgraph_; | 75 JSGraph* jsgraph_; |
| 82 Zone compilation_zone_; | 76 Zone compilation_zone_; |
| 83 CompilationInfo info_; | 77 CompilationInfo info_; |
| 84 std::unique_ptr<CompilationJob> job_; | 78 std::unique_ptr<CompilationJob> job_; |
| 85 uint32_t index_; | 79 int func_index_; |
| 86 wasm::Result<wasm::DecodeStruct*> graph_construction_result_; | 80 wasm::Result<wasm::DecodeStruct*> graph_construction_result_; |
| 87 bool ok_; | 81 bool ok_ = true; |
| 88 ZoneVector<trap_handler::ProtectedInstructionData> | 82 ZoneVector<trap_handler::ProtectedInstructionData> |
| 89 protected_instructions_; // Instructions that are protected by the signal | 83 protected_instructions_; // Instructions that are protected by the signal |
| 90 // handler. | 84 // handler. |
| 91 | 85 |
| 92 DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit); | 86 DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit); |
| 93 }; | 87 }; |
| 94 | 88 |
| 95 // Wraps a JS function, producing a code object that can be called from WASM. | 89 // Wraps a JS function, producing a code object that can be called from WASM. |
| 96 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, | 90 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, |
| 97 wasm::FunctionSig* sig, uint32_t index, | 91 wasm::FunctionSig* sig, uint32_t index, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 385 } |
| 392 | 386 |
| 393 int AddParameterNodes(Node** args, int pos, int param_count, | 387 int AddParameterNodes(Node** args, int pos, int param_count, |
| 394 wasm::FunctionSig* sig); | 388 wasm::FunctionSig* sig); |
| 395 }; | 389 }; |
| 396 } // namespace compiler | 390 } // namespace compiler |
| 397 } // namespace internal | 391 } // namespace internal |
| 398 } // namespace v8 | 392 } // namespace v8 |
| 399 | 393 |
| 400 #endif // V8_COMPILER_WASM_COMPILER_H_ | 394 #endif // V8_COMPILER_WASM_COMPILER_H_ |
| OLD | NEW |