blob: 019dc56af6478d6826172c11af2a7f3d5c6dc3ec [file] [log] [blame]
Ben Murdoch4a90d5f2016-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_H_
6#define V8_WASM_MODULE_H_
7
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/api.h"
9#include "src/handles.h"
Ben Murdoch61f157c2016-09-16 13:49:30 +010010#include "src/wasm/wasm-opcodes.h"
11#include "src/wasm/wasm-result.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000012
13namespace v8 {
14namespace internal {
15
16namespace compiler {
17class CallDescriptor;
Ben Murdochc5610432016-08-08 18:44:38 +010018class WasmCompilationUnit;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019}
20
21namespace wasm {
22const size_t kMaxModuleSize = 1024 * 1024 * 1024;
23const size_t kMaxFunctionSize = 128 * 1024;
24const size_t kMaxStringSize = 256;
Ben Murdochda12d292016-06-02 14:46:10 +010025const uint32_t kWasmMagic = 0x6d736100;
Ben Murdochc5610432016-08-08 18:44:38 +010026const uint32_t kWasmVersion = 0x0b;
27const uint8_t kWasmFunctionTypeForm = 0x40;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028
Ben Murdochda12d292016-06-02 14:46:10 +010029// WebAssembly sections are named as strings in the binary format, but
30// internally V8 uses an enum to handle them.
31//
32// Entries have the form F(enumerator, string).
Ben Murdochc5610432016-08-08 18:44:38 +010033#define FOR_EACH_WASM_SECTION_TYPE(F) \
34 F(Signatures, 1, "type") \
35 F(ImportTable, 2, "import") \
36 F(FunctionSignatures, 3, "function") \
37 F(FunctionTable, 4, "table") \
38 F(Memory, 5, "memory") \
39 F(ExportTable, 6, "export") \
40 F(StartFunction, 7, "start") \
41 F(FunctionBodies, 8, "code") \
42 F(DataSegments, 9, "data") \
43 F(Names, 10, "name") \
Ben Murdoch61f157c2016-09-16 13:49:30 +010044 F(FunctionTablePad, 11, "table_pad") \
Ben Murdochc5610432016-08-08 18:44:38 +010045 F(Globals, 0, "global") \
46 F(End, 0, "end")
Ben Murdochda12d292016-06-02 14:46:10 +010047
48// Contants for the above section types: {LEB128 length, characters...}.
49#define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y'
Ben Murdochc5610432016-08-08 18:44:38 +010050#define WASM_SECTION_SIGNATURES 4, 't', 'y', 'p', 'e'
Ben Murdochc5610432016-08-08 18:44:38 +010051#define WASM_SECTION_GLOBALS 6, 'g', 'l', 'o', 'b', 'a', 'l'
52#define WASM_SECTION_DATA_SEGMENTS 4, 'd', 'a', 't', 'a'
53#define WASM_SECTION_FUNCTION_TABLE 5, 't', 'a', 'b', 'l', 'e'
Ben Murdochda12d292016-06-02 14:46:10 +010054#define WASM_SECTION_END 3, 'e', 'n', 'd'
Ben Murdochc5610432016-08-08 18:44:38 +010055#define WASM_SECTION_START_FUNCTION 5, 's', 't', 'a', 'r', 't'
56#define WASM_SECTION_IMPORT_TABLE 6, 'i', 'm', 'p', 'o', 'r', 't'
57#define WASM_SECTION_EXPORT_TABLE 6, 'e', 'x', 'p', 'o', 'r', 't'
58#define WASM_SECTION_FUNCTION_SIGNATURES \
59 8, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n'
60#define WASM_SECTION_FUNCTION_BODIES 4, 'c', 'o', 'd', 'e'
61#define WASM_SECTION_NAMES 4, 'n', 'a', 'm', 'e'
Ben Murdoch61f157c2016-09-16 13:49:30 +010062#define WASM_SECTION_FUNCTION_TABLE_PAD \
63 9, 't', 'a', 'b', 'l', 'e', '_', 'p', 'a', 'd'
Ben Murdochda12d292016-06-02 14:46:10 +010064
65// Constants for the above section headers' size (LEB128 + characters).
66#define WASM_SECTION_MEMORY_SIZE ((size_t)7)
Ben Murdochc5610432016-08-08 18:44:38 +010067#define WASM_SECTION_SIGNATURES_SIZE ((size_t)5)
Ben Murdochc5610432016-08-08 18:44:38 +010068#define WASM_SECTION_GLOBALS_SIZE ((size_t)7)
69#define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)5)
70#define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)6)
Ben Murdochda12d292016-06-02 14:46:10 +010071#define WASM_SECTION_END_SIZE ((size_t)4)
Ben Murdochc5610432016-08-08 18:44:38 +010072#define WASM_SECTION_START_FUNCTION_SIZE ((size_t)6)
73#define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)7)
74#define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)7)
75#define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)9)
76#define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5)
77#define WASM_SECTION_NAMES_SIZE ((size_t)5)
Ben Murdoch61f157c2016-09-16 13:49:30 +010078#define WASM_SECTION_FUNCTION_TABLE_PAD_SIZE ((size_t)10)
79
80class WasmDebugInfo;
Ben Murdochda12d292016-06-02 14:46:10 +010081
82struct WasmSection {
83 enum class Code : uint32_t {
Ben Murdochc5610432016-08-08 18:44:38 +010084#define F(enumerator, order, string) enumerator,
Ben Murdochda12d292016-06-02 14:46:10 +010085 FOR_EACH_WASM_SECTION_TYPE(F)
86#undef F
87 Max
88 };
89 static WasmSection::Code begin();
90 static WasmSection::Code end();
91 static WasmSection::Code next(WasmSection::Code code);
92 static const char* getName(Code code);
Ben Murdochc5610432016-08-08 18:44:38 +010093 static int getOrder(Code code);
Ben Murdochda12d292016-06-02 14:46:10 +010094 static size_t getNameLength(Code code);
Ben Murdochc5610432016-08-08 18:44:38 +010095 static WasmSection::Code lookup(const byte* string, uint32_t length);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000096};
97
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098enum WasmFunctionDeclBit {
99 kDeclFunctionName = 0x01,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000100 kDeclFunctionExport = 0x08
101};
102
103// Constants for fixed-size elements within a module.
104static const size_t kDeclMemorySize = 3;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000105static const size_t kDeclDataSegmentSize = 13;
106
Ben Murdochc5610432016-08-08 18:44:38 +0100107static const uint32_t kMaxReturnCount = 1;
108
Ben Murdoch097c5b22016-05-18 11:27:45 +0100109// Static representation of a WASM function.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110struct WasmFunction {
111 FunctionSig* sig; // signature of the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100112 uint32_t func_index; // index into the function table.
Ben Murdochda12d292016-06-02 14:46:10 +0100113 uint32_t sig_index; // index into the signature table.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000114 uint32_t name_offset; // offset in the module bytes of the name, if any.
Ben Murdochda12d292016-06-02 14:46:10 +0100115 uint32_t name_length; // length in bytes of the name.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 uint32_t code_start_offset; // offset in the module bytes of code start.
117 uint32_t code_end_offset; // offset in the module bytes of code end.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118};
119
Ben Murdoch097c5b22016-05-18 11:27:45 +0100120// Static representation of an imported WASM function.
121struct WasmImport {
122 FunctionSig* sig; // signature of the function.
Ben Murdochda12d292016-06-02 14:46:10 +0100123 uint32_t sig_index; // index into the signature table.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100124 uint32_t module_name_offset; // offset in module bytes of the module name.
Ben Murdochda12d292016-06-02 14:46:10 +0100125 uint32_t module_name_length; // length in bytes of the module name.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100126 uint32_t function_name_offset; // offset in module bytes of the import name.
Ben Murdochda12d292016-06-02 14:46:10 +0100127 uint32_t function_name_length; // length in bytes of the import name.
128};
129
130// Static representation of an exported WASM function.
131struct WasmExport {
132 uint32_t func_index; // index into the function table.
133 uint32_t name_offset; // offset in module bytes of the name to export.
134 uint32_t name_length; // length in bytes of the exported name.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100135};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000136
137// Static representation of a wasm global variable.
138struct WasmGlobal {
139 uint32_t name_offset; // offset in the module bytes of the name, if any.
Ben Murdochda12d292016-06-02 14:46:10 +0100140 uint32_t name_length; // length in bytes of the global name.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 MachineType type; // type of the global.
142 uint32_t offset; // offset from beginning of globals area.
143 bool exported; // true if this global is exported.
144};
145
146// Static representation of a wasm data segment.
147struct WasmDataSegment {
148 uint32_t dest_addr; // destination memory address of the data.
149 uint32_t source_offset; // start offset in the module bytes.
150 uint32_t source_size; // end offset in the module bytes.
151 bool init; // true if loaded upon instantiation.
152};
153
Ben Murdochda12d292016-06-02 14:46:10 +0100154enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin };
155
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000156// Static representation of a module.
157struct WasmModule {
Ben Murdochda12d292016-06-02 14:46:10 +0100158 static const uint32_t kPageSize = 0x10000; // Page size, 64kb.
159 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
160 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000162 const byte* module_start; // starting address for the module bytes.
163 const byte* module_end; // end address for the module bytes.
Ben Murdochda12d292016-06-02 14:46:10 +0100164 uint32_t min_mem_pages; // minimum size of the memory in 64k pages.
165 uint32_t max_mem_pages; // maximum size of the memory in 64k pages.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000166 bool mem_export; // true if the memory is exported.
167 bool mem_external; // true if the memory is external.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100168 int start_function_index; // start function, if any.
Ben Murdochda12d292016-06-02 14:46:10 +0100169 ModuleOrigin origin; // origin of the module
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170
Ben Murdochda12d292016-06-02 14:46:10 +0100171 std::vector<WasmGlobal> globals; // globals in this module.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100172 uint32_t globals_size; // size of globals table.
173 uint32_t indirect_table_size; // size of indirect function
174 // table (includes padding).
Ben Murdochda12d292016-06-02 14:46:10 +0100175 std::vector<FunctionSig*> signatures; // signatures in this module.
176 std::vector<WasmFunction> functions; // functions in this module.
177 std::vector<WasmDataSegment> data_segments; // data segments in this module.
178 std::vector<uint16_t> function_table; // function table.
179 std::vector<WasmImport> import_table; // import table.
180 std::vector<WasmExport> export_table; // export table.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100181 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we
182 // use on the try bots, semaphore::Wait() can return while some compilation
183 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned
184 // up right after semaphore::Wait() returns, then this can cause an
185 // invalid-semaphore error in the compilation tasks.
186 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots
187 // switch to libc-2.21 or higher.
188 base::SmartPointer<base::Semaphore> pending_tasks;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000189
190 WasmModule();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000191
Ben Murdochda12d292016-06-02 14:46:10 +0100192 // Get a string stored in the module bytes representing a name.
193 WasmName GetName(uint32_t offset, uint32_t length) const {
194 if (length == 0) return {"<?>", 3}; // no name.
195 CHECK(BoundsCheck(offset, offset + length));
Ben Murdochc5610432016-08-08 18:44:38 +0100196 DCHECK_GE(static_cast<int>(length), 0);
197 return {reinterpret_cast<const char*>(module_start + offset),
198 static_cast<int>(length)};
199 }
200
201 // Get a string stored in the module bytes representing a function name.
202 WasmName GetName(WasmFunction* function) const {
203 return GetName(function->name_offset, function->name_length);
Ben Murdochda12d292016-06-02 14:46:10 +0100204 }
205
206 // Get a string stored in the module bytes representing a name.
207 WasmName GetNameOrNull(uint32_t offset, uint32_t length) const {
Ben Murdoch61f157c2016-09-16 13:49:30 +0100208 if (offset == 0 && length == 0) return {NULL, 0}; // no name.
Ben Murdochda12d292016-06-02 14:46:10 +0100209 CHECK(BoundsCheck(offset, offset + length));
Ben Murdochc5610432016-08-08 18:44:38 +0100210 DCHECK_GE(static_cast<int>(length), 0);
211 return {reinterpret_cast<const char*>(module_start + offset),
212 static_cast<int>(length)};
213 }
214
215 // Get a string stored in the module bytes representing a function name.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100216 WasmName GetNameOrNull(const WasmFunction* function) const {
Ben Murdochc5610432016-08-08 18:44:38 +0100217 return GetNameOrNull(function->name_offset, function->name_length);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000218 }
219
220 // Checks the given offset range is contained within the module bytes.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100221 bool BoundsCheck(uint32_t start, uint32_t end) const {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000222 size_t size = module_end - module_start;
Ben Murdochc5610432016-08-08 18:44:38 +0100223 return start <= size && end <= size;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000224 }
225
226 // Creates a new instantiation of the module in the given isolate.
Ben Murdochc5610432016-08-08 18:44:38 +0100227 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSReceiver> ffi,
Ben Murdoch61f157c2016-09-16 13:49:30 +0100228 Handle<JSArrayBuffer> memory) const;
229
230 Handle<FixedArray> CompileFunctions(Isolate* isolate) const;
231
232 uint32_t FunctionTableSize() const {
233 if (indirect_table_size > 0) {
234 return indirect_table_size;
235 }
236 DCHECK_LE(function_table.size(), UINT32_MAX);
237 return static_cast<uint32_t>(function_table.size());
238 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239};
240
Ben Murdoch097c5b22016-05-18 11:27:45 +0100241// An instantiated WASM module, including memory, function table, etc.
242struct WasmModuleInstance {
Ben Murdoch61f157c2016-09-16 13:49:30 +0100243 const WasmModule* module; // static representation of the module.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100244 // -- Heap allocated --------------------------------------------------------
245 Handle<JSObject> js_object; // JavaScript module object.
246 Handle<Context> context; // JavaScript native context.
247 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory.
248 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals.
249 Handle<FixedArray> function_table; // indirect function table.
Ben Murdochda12d292016-06-02 14:46:10 +0100250 std::vector<Handle<Code>> function_code; // code objects for each function.
251 std::vector<Handle<Code>> import_code; // code objects for each import.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100252 // -- raw memory ------------------------------------------------------------
253 byte* mem_start; // start of linear memory.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100254 uint32_t mem_size; // size of the linear memory.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100255 // -- raw globals -----------------------------------------------------------
256 byte* globals_start; // start of the globals area.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100257
Ben Murdoch61f157c2016-09-16 13:49:30 +0100258 explicit WasmModuleInstance(const WasmModule* m)
Ben Murdoch097c5b22016-05-18 11:27:45 +0100259 : module(m),
Ben Murdoch61f157c2016-09-16 13:49:30 +0100260 function_code(m->functions.size()),
261 import_code(m->import_table.size()),
Ben Murdoch097c5b22016-05-18 11:27:45 +0100262 mem_start(nullptr),
263 mem_size(0),
Ben Murdoch61f157c2016-09-16 13:49:30 +0100264 globals_start(nullptr) {}
Ben Murdoch097c5b22016-05-18 11:27:45 +0100265};
266
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000267// Interface provided to the decoder/graph builder which contains only
268// minimal information about the globals, functions, and function tables.
269struct ModuleEnv {
Ben Murdoch61f157c2016-09-16 13:49:30 +0100270 const WasmModule* module;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100271 WasmModuleInstance* instance;
Ben Murdochda12d292016-06-02 14:46:10 +0100272 ModuleOrigin origin;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100273 // TODO(mtrofin): remove this once we introduce WASM_DIRECT_CALL
274 // reloc infos.
275 std::vector<Handle<Code>> placeholders;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276
277 bool IsValidGlobal(uint32_t index) {
Ben Murdochda12d292016-06-02 14:46:10 +0100278 return module && index < module->globals.size();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000279 }
Ben Murdoch61f157c2016-09-16 13:49:30 +0100280 bool IsValidFunction(uint32_t index) const {
Ben Murdochda12d292016-06-02 14:46:10 +0100281 return module && index < module->functions.size();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000282 }
283 bool IsValidSignature(uint32_t index) {
Ben Murdochda12d292016-06-02 14:46:10 +0100284 return module && index < module->signatures.size();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100286 bool IsValidImport(uint32_t index) {
Ben Murdochda12d292016-06-02 14:46:10 +0100287 return module && index < module->import_table.size();
Ben Murdoch097c5b22016-05-18 11:27:45 +0100288 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289 MachineType GetGlobalType(uint32_t index) {
290 DCHECK(IsValidGlobal(index));
Ben Murdochda12d292016-06-02 14:46:10 +0100291 return module->globals[index].type;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000292 }
293 FunctionSig* GetFunctionSignature(uint32_t index) {
294 DCHECK(IsValidFunction(index));
Ben Murdochda12d292016-06-02 14:46:10 +0100295 return module->functions[index].sig;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000296 }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100297 FunctionSig* GetImportSignature(uint32_t index) {
298 DCHECK(IsValidImport(index));
Ben Murdochda12d292016-06-02 14:46:10 +0100299 return module->import_table[index].sig;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100300 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000301 FunctionSig* GetSignature(uint32_t index) {
302 DCHECK(IsValidSignature(index));
Ben Murdochda12d292016-06-02 14:46:10 +0100303 return module->signatures[index];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000304 }
Ben Murdoch61f157c2016-09-16 13:49:30 +0100305 uint32_t FunctionTableSize() const {
306 return module->FunctionTableSize();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000307 }
308
Ben Murdochda12d292016-06-02 14:46:10 +0100309 bool asm_js() { return origin == kAsmJsOrigin; }
310
Ben Murdoch61f157c2016-09-16 13:49:30 +0100311 Handle<Code> GetCodeOrPlaceholder(uint32_t index) const;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100312 Handle<Code> GetImportCode(uint32_t index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000313
Ben Murdoch097c5b22016-05-18 11:27:45 +0100314 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone,
315 FunctionSig* sig);
316 static compiler::CallDescriptor* GetI32WasmCallDescriptor(
317 Zone* zone, compiler::CallDescriptor* descriptor);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000318 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index);
319};
320
Ben Murdoch097c5b22016-05-18 11:27:45 +0100321// A helper for printing out the names of functions.
322struct WasmFunctionName {
323 const WasmFunction* function_;
324 const WasmModule* module_;
325 WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv)
326 : function_(function), module_(menv ? menv->module : nullptr) {}
327};
328
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000329std::ostream& operator<<(std::ostream& os, const WasmModule& module);
330std::ostream& operator<<(std::ostream& os, const WasmFunction& function);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100331std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000332
Ben Murdoch61f157c2016-09-16 13:49:30 +0100333typedef Result<const WasmModule*> ModuleResult;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000334typedef Result<WasmFunction*> FunctionResult;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100335typedef std::vector<std::pair<int, int>> FunctionOffsets;
336typedef Result<FunctionOffsets> FunctionOffsetsResult;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000337
Ben Murdoch61f157c2016-09-16 13:49:30 +0100338// Extract a function name from the given wasm object.
339// Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a
340// valid UTF-8 string.
341Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm,
342 uint32_t func_index);
343
344// Extract a function name from the given wasm object.
345// Returns a null handle if the function is unnamed or the name is not a valid
346// UTF-8 string.
347Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm,
348 uint32_t func_index);
349
350// Return the binary source bytes of a wasm module.
351SeqOneByteString* GetWasmBytes(JSObject* wasm);
352
353// Get the debug info associated with the given wasm object.
354// If no debug info exists yet, it is created automatically.
355WasmDebugInfo* GetDebugInfo(JSObject* wasm);
356
357// Check whether the given object is a wasm object.
358// This checks the number and type of internal fields, so it's not 100 percent
359// secure. If it turns out that we need more complete checks, we could add a
360// special marker as internal field, which will definitely never occur anywhere
361// else.
362bool IsWasmObject(Object* object);
363
364namespace testing {
365
366// Decode, verify, and run the function labeled "main" in the
367// given encoded module. The module should have no imports.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000368int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
369 const byte* module_end, bool asm_js = false);
370
Ben Murdoch61f157c2016-09-16 13:49:30 +0100371} // namespace testing
Ben Murdochc5610432016-08-08 18:44:38 +0100372
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000373} // namespace wasm
374} // namespace internal
375} // namespace v8
376
377#endif // V8_WASM_MODULE_H_