| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_WASM_MODULE_DECODER_H_ |
| 6 | #define V8_WASM_MODULE_DECODER_H_ |
| 7 | |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 8 | #include "src/globals.h" |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/wasm/ast-decoder.h" |
| 10 | #include "src/wasm/wasm-module.h" |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 11 | #include "src/wasm/wasm-result.h" |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | namespace wasm { |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 16 | |
| 17 | typedef Result<const WasmModule*> ModuleResult; |
| 18 | typedef Result<WasmFunction*> FunctionResult; |
| 19 | typedef std::vector<std::pair<int, int>> FunctionOffsets; |
| 20 | typedef Result<FunctionOffsets> FunctionOffsetsResult; |
| 21 | typedef std::vector<std::vector<std::pair<int, int>>> AsmJsOffsets; |
| 22 | typedef Result<AsmJsOffsets> AsmJsOffsetsResult; |
| 23 | |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | // Decodes the bytes of a WASM module between {module_start} and {module_end}. |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 25 | V8_EXPORT_PRIVATE ModuleResult DecodeWasmModule(Isolate* isolate, |
| Ben Murdoch | f3b273f | 2017-01-17 12:11:28 +0000 | [diff] [blame] | 26 | const byte* module_start, |
| 27 | const byte* module_end, |
| 28 | bool verify_functions, |
| 29 | ModuleOrigin origin); |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | |
| 31 | // Exposed for testing. Decodes a single function signature, allocating it |
| 32 | // in the given zone. Returns {nullptr} upon failure. |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 33 | V8_EXPORT_PRIVATE FunctionSig* DecodeWasmSignatureForTesting(Zone* zone, |
| 34 | const byte* start, |
| 35 | const byte* end); |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | |
| 37 | // Decodes the bytes of a WASM function between |
| 38 | // {function_start} and {function_end}. |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 39 | V8_EXPORT_PRIVATE FunctionResult DecodeWasmFunction(Isolate* isolate, |
| 40 | Zone* zone, ModuleEnv* env, |
| 41 | const byte* function_start, |
| 42 | const byte* function_end); |
| Ben Murdoch | 13e2dad | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 43 | |
| 44 | // Extracts the function offset table from the wasm module bytes. |
| 45 | // Returns a vector with <offset, length> entries, or failure if the wasm bytes |
| 46 | // are detected as invalid. Note that this validation is not complete. |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 47 | FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start, |
| 48 | const byte* module_end); |
| Ben Murdoch | f3b273f | 2017-01-17 12:11:28 +0000 | [diff] [blame] | 49 | |
| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 50 | V8_EXPORT_PRIVATE WasmInitExpr DecodeWasmInitExprForTesting(const byte* start, |
| 51 | const byte* end); |
| 52 | |
| 53 | // Extracts the mapping from wasm byte offset to asm.js source position per |
| 54 | // function. |
| 55 | // Returns a vector of vectors with <byte_offset, source_position> entries, or |
| 56 | // failure if the wasm bytes are detected as invalid. Note that this validation |
| 57 | // is not complete. |
| 58 | AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* module_start, |
| 59 | const byte* module_end); |
| Ben Murdoch | 13e2dad | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 60 | |
| Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 61 | } // namespace wasm |
| 62 | } // namespace internal |
| 63 | } // namespace v8 |
| 64 | |
| 65 | #endif // V8_WASM_MODULE_DECODER_H_ |