blob: 7cf5cfe3c107a8e4a7b1fd9ed9a80cd135c2393f [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// 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 Murdochc8c1d9e2017-03-08 14:04:23 +00008#include "src/globals.h"
Ben Murdoch014dc512016-03-22 12:00:34 +00009#include "src/wasm/ast-decoder.h"
10#include "src/wasm/wasm-module.h"
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000011#include "src/wasm/wasm-result.h"
Ben Murdoch014dc512016-03-22 12:00:34 +000012
13namespace v8 {
14namespace internal {
15namespace wasm {
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000016
17typedef Result<const WasmModule*> ModuleResult;
18typedef Result<WasmFunction*> FunctionResult;
19typedef std::vector<std::pair<int, int>> FunctionOffsets;
20typedef Result<FunctionOffsets> FunctionOffsetsResult;
21typedef std::vector<std::vector<std::pair<int, int>>> AsmJsOffsets;
22typedef Result<AsmJsOffsets> AsmJsOffsetsResult;
23
Ben Murdoch014dc512016-03-22 12:00:34 +000024// Decodes the bytes of a WASM module between {module_start} and {module_end}.
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000025V8_EXPORT_PRIVATE ModuleResult DecodeWasmModule(Isolate* isolate,
Ben Murdochf3b273f2017-01-17 12:11:28 +000026 const byte* module_start,
27 const byte* module_end,
28 bool verify_functions,
29 ModuleOrigin origin);
Ben Murdoch014dc512016-03-22 12:00:34 +000030
31// Exposed for testing. Decodes a single function signature, allocating it
32// in the given zone. Returns {nullptr} upon failure.
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000033V8_EXPORT_PRIVATE FunctionSig* DecodeWasmSignatureForTesting(Zone* zone,
34 const byte* start,
35 const byte* end);
Ben Murdoch014dc512016-03-22 12:00:34 +000036
37// Decodes the bytes of a WASM function between
38// {function_start} and {function_end}.
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000039V8_EXPORT_PRIVATE FunctionResult DecodeWasmFunction(Isolate* isolate,
40 Zone* zone, ModuleEnv* env,
41 const byte* function_start,
42 const byte* function_end);
Ben Murdoch13e2dad2016-09-16 13:49:30 +010043
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 Murdochc8c1d9e2017-03-08 14:04:23 +000047FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start,
48 const byte* module_end);
Ben Murdochf3b273f2017-01-17 12:11:28 +000049
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000050V8_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.
58AsmJsOffsetsResult DecodeAsmJsOffsets(const byte* module_start,
59 const byte* module_end);
Ben Murdoch13e2dad2016-09-16 13:49:30 +010060
Ben Murdoch014dc512016-03-22 12:00:34 +000061} // namespace wasm
62} // namespace internal
63} // namespace v8
64
65#endif // V8_WASM_MODULE_DECODER_H_