Ben Murdoch | 4a90d5f | 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_H_ |
| 6 | #define V8_WASM_MODULE_H_ |
| 7 | |
| 8 | #include "src/wasm/wasm-opcodes.h" |
| 9 | #include "src/wasm/wasm-result.h" |
| 10 | |
| 11 | #include "src/api.h" |
| 12 | #include "src/handles.h" |
| 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | namespace compiler { |
| 18 | class CallDescriptor; |
| 19 | } |
| 20 | |
| 21 | namespace wasm { |
| 22 | const size_t kMaxModuleSize = 1024 * 1024 * 1024; |
| 23 | const size_t kMaxFunctionSize = 128 * 1024; |
| 24 | const size_t kMaxStringSize = 256; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 25 | const uint32_t kWasmMagic = 0x6d736100; |
| 26 | const uint32_t kWasmVersion = 0x0a; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 28 | // WebAssembly sections are named as strings in the binary format, but |
| 29 | // internally V8 uses an enum to handle them. |
| 30 | // |
| 31 | // Entries have the form F(enumerator, string). |
| 32 | #define FOR_EACH_WASM_SECTION_TYPE(F) \ |
| 33 | F(Memory, "memory") \ |
| 34 | F(Signatures, "signatures") \ |
| 35 | F(Functions, "functions") \ |
| 36 | F(Globals, "globals") \ |
| 37 | F(DataSegments, "data_segments") \ |
| 38 | F(FunctionTable, "function_table") \ |
| 39 | F(End, "end") \ |
| 40 | F(StartFunction, "start_function") \ |
| 41 | F(ImportTable, "import_table") \ |
| 42 | F(ExportTable, "export_table") \ |
| 43 | F(FunctionSignatures, "function_signatures") \ |
| 44 | F(FunctionBodies, "function_bodies") \ |
| 45 | F(Names, "names") |
| 46 | |
| 47 | // Contants for the above section types: {LEB128 length, characters...}. |
| 48 | #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y' |
| 49 | #define WASM_SECTION_SIGNATURES \ |
| 50 | 10, 's', 'i', 'g', 'n', 'a', 't', 'u', 'r', 'e', 's' |
| 51 | #define WASM_SECTION_FUNCTIONS 9, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 's' |
| 52 | #define WASM_SECTION_GLOBALS 7, 'g', 'l', 'o', 'b', 'a', 'l', 's' |
| 53 | #define WASM_SECTION_DATA_SEGMENTS \ |
| 54 | 13, 'd', 'a', 't', 'a', '_', 's', 'e', 'g', 'm', 'e', 'n', 't', 's' |
| 55 | #define WASM_SECTION_FUNCTION_TABLE \ |
| 56 | 14, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 't', 'a', 'b', 'l', 'e' |
| 57 | #define WASM_SECTION_END 3, 'e', 'n', 'd' |
| 58 | #define WASM_SECTION_START_FUNCTION \ |
| 59 | 14, 's', 't', 'a', 'r', 't', '_', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n' |
| 60 | #define WASM_SECTION_IMPORT_TABLE \ |
| 61 | 12, 'i', 'm', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e' |
| 62 | #define WASM_SECTION_EXPORT_TABLE \ |
| 63 | 12, 'e', 'x', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e' |
| 64 | #define WASM_SECTION_FUNCTION_SIGNATURES \ |
| 65 | 19, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 's', 'i', 'g', 'n', 'a', \ |
| 66 | 't', 'u', 'r', 'e', 's' |
| 67 | #define WASM_SECTION_FUNCTION_BODIES \ |
| 68 | 15, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 'b', 'o', 'd', 'i', 'e', 's' |
| 69 | #define WASM_SECTION_NAMES 5, 'n', 'a', 'm', 'e', 's' |
| 70 | |
| 71 | // Constants for the above section headers' size (LEB128 + characters). |
| 72 | #define WASM_SECTION_MEMORY_SIZE ((size_t)7) |
| 73 | #define WASM_SECTION_SIGNATURES_SIZE ((size_t)11) |
| 74 | #define WASM_SECTION_FUNCTIONS_SIZE ((size_t)10) |
| 75 | #define WASM_SECTION_GLOBALS_SIZE ((size_t)8) |
| 76 | #define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)14) |
| 77 | #define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)15) |
| 78 | #define WASM_SECTION_END_SIZE ((size_t)4) |
| 79 | #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)15) |
| 80 | #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)13) |
| 81 | #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)13) |
| 82 | #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)20) |
| 83 | #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)16) |
| 84 | #define WASM_SECTION_NAMES_SIZE ((size_t)6) |
| 85 | |
| 86 | struct WasmSection { |
| 87 | enum class Code : uint32_t { |
| 88 | #define F(enumerator, string) enumerator, |
| 89 | FOR_EACH_WASM_SECTION_TYPE(F) |
| 90 | #undef F |
| 91 | Max |
| 92 | }; |
| 93 | static WasmSection::Code begin(); |
| 94 | static WasmSection::Code end(); |
| 95 | static WasmSection::Code next(WasmSection::Code code); |
| 96 | static const char* getName(Code code); |
| 97 | static size_t getNameLength(Code code); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 100 | enum WasmFunctionDeclBit { |
| 101 | kDeclFunctionName = 0x01, |
| 102 | kDeclFunctionImport = 0x02, |
| 103 | kDeclFunctionLocals = 0x04, |
| 104 | kDeclFunctionExport = 0x08 |
| 105 | }; |
| 106 | |
| 107 | // Constants for fixed-size elements within a module. |
| 108 | static const size_t kDeclMemorySize = 3; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 109 | static const size_t kDeclDataSegmentSize = 13; |
| 110 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 111 | // Static representation of a WASM function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | struct WasmFunction { |
| 113 | FunctionSig* sig; // signature of the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 114 | uint32_t func_index; // index into the function table. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 115 | uint32_t sig_index; // index into the signature table. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 116 | uint32_t name_offset; // offset in the module bytes of the name, if any. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 117 | uint32_t name_length; // length in bytes of the name. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 118 | uint32_t code_start_offset; // offset in the module bytes of code start. |
| 119 | uint32_t code_end_offset; // offset in the module bytes of code end. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 120 | uint16_t local_i32_count; // number of i32 local variables. |
| 121 | uint16_t local_i64_count; // number of i64 local variables. |
| 122 | uint16_t local_f32_count; // number of f32 local variables. |
| 123 | uint16_t local_f64_count; // number of f64 local variables. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 124 | bool exported; // true if this function is exported. |
| 125 | bool external; // true if this function is externally supplied. |
| 126 | }; |
| 127 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 128 | // Static representation of an imported WASM function. |
| 129 | struct WasmImport { |
| 130 | FunctionSig* sig; // signature of the function. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 131 | uint32_t sig_index; // index into the signature table. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 132 | uint32_t module_name_offset; // offset in module bytes of the module name. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 133 | uint32_t module_name_length; // length in bytes of the module name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 134 | uint32_t function_name_offset; // offset in module bytes of the import name. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 135 | uint32_t function_name_length; // length in bytes of the import name. |
| 136 | }; |
| 137 | |
| 138 | // Static representation of an exported WASM function. |
| 139 | struct WasmExport { |
| 140 | uint32_t func_index; // index into the function table. |
| 141 | uint32_t name_offset; // offset in module bytes of the name to export. |
| 142 | uint32_t name_length; // length in bytes of the exported name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 143 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 144 | |
| 145 | // Static representation of a wasm global variable. |
| 146 | struct WasmGlobal { |
| 147 | uint32_t name_offset; // offset in the module bytes of the name, if any. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 148 | uint32_t name_length; // length in bytes of the global name. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 149 | MachineType type; // type of the global. |
| 150 | uint32_t offset; // offset from beginning of globals area. |
| 151 | bool exported; // true if this global is exported. |
| 152 | }; |
| 153 | |
| 154 | // Static representation of a wasm data segment. |
| 155 | struct WasmDataSegment { |
| 156 | uint32_t dest_addr; // destination memory address of the data. |
| 157 | uint32_t source_offset; // start offset in the module bytes. |
| 158 | uint32_t source_size; // end offset in the module bytes. |
| 159 | bool init; // true if loaded upon instantiation. |
| 160 | }; |
| 161 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 162 | enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; |
| 163 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 164 | // Static representation of a module. |
| 165 | struct WasmModule { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 166 | static const uint32_t kPageSize = 0x10000; // Page size, 64kb. |
| 167 | static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb |
| 168 | static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | |
| 170 | Isolate* shared_isolate; // isolate for storing shared code. |
| 171 | const byte* module_start; // starting address for the module bytes. |
| 172 | const byte* module_end; // end address for the module bytes. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 173 | uint32_t min_mem_pages; // minimum size of the memory in 64k pages. |
| 174 | uint32_t max_mem_pages; // maximum size of the memory in 64k pages. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 175 | bool mem_export; // true if the memory is exported. |
| 176 | bool mem_external; // true if the memory is external. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 177 | int start_function_index; // start function, if any. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 178 | ModuleOrigin origin; // origin of the module |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 179 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 180 | std::vector<WasmGlobal> globals; // globals in this module. |
| 181 | std::vector<FunctionSig*> signatures; // signatures in this module. |
| 182 | std::vector<WasmFunction> functions; // functions in this module. |
| 183 | std::vector<WasmDataSegment> data_segments; // data segments in this module. |
| 184 | std::vector<uint16_t> function_table; // function table. |
| 185 | std::vector<WasmImport> import_table; // import table. |
| 186 | std::vector<WasmExport> export_table; // export table. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | |
| 188 | WasmModule(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 190 | // Get a string stored in the module bytes representing a name. |
| 191 | WasmName GetName(uint32_t offset, uint32_t length) const { |
| 192 | if (length == 0) return {"<?>", 3}; // no name. |
| 193 | CHECK(BoundsCheck(offset, offset + length)); |
| 194 | return {reinterpret_cast<const char*>(module_start + offset), length}; |
| 195 | } |
| 196 | |
| 197 | // Get a string stored in the module bytes representing a name. |
| 198 | WasmName GetNameOrNull(uint32_t offset, uint32_t length) const { |
| 199 | if (length == 0) return {NULL, 0}; // no name. |
| 200 | CHECK(BoundsCheck(offset, offset + length)); |
| 201 | return {reinterpret_cast<const char*>(module_start + offset), length}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | // Checks the given offset range is contained within the module bytes. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 205 | bool BoundsCheck(uint32_t start, uint32_t end) const { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 206 | size_t size = module_end - module_start; |
| 207 | return start < size && end < size; |
| 208 | } |
| 209 | |
| 210 | // Creates a new instantiation of the module in the given isolate. |
| 211 | MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi, |
| 212 | Handle<JSArrayBuffer> memory); |
| 213 | }; |
| 214 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 215 | // An instantiated WASM module, including memory, function table, etc. |
| 216 | struct WasmModuleInstance { |
| 217 | WasmModule* module; // static representation of the module. |
| 218 | // -- Heap allocated -------------------------------------------------------- |
| 219 | Handle<JSObject> js_object; // JavaScript module object. |
| 220 | Handle<Context> context; // JavaScript native context. |
| 221 | Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
| 222 | Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
| 223 | Handle<FixedArray> function_table; // indirect function table. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 224 | std::vector<Handle<Code>> function_code; // code objects for each function. |
| 225 | std::vector<Handle<Code>> import_code; // code objects for each import. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 226 | // -- raw memory ------------------------------------------------------------ |
| 227 | byte* mem_start; // start of linear memory. |
| 228 | size_t mem_size; // size of the linear memory. |
| 229 | // -- raw globals ----------------------------------------------------------- |
| 230 | byte* globals_start; // start of the globals area. |
| 231 | size_t globals_size; // size of the globals area. |
| 232 | |
| 233 | explicit WasmModuleInstance(WasmModule* m) |
| 234 | : module(m), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 235 | mem_start(nullptr), |
| 236 | mem_size(0), |
| 237 | globals_start(nullptr), |
| 238 | globals_size(0) {} |
| 239 | }; |
| 240 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 241 | // forward declaration. |
| 242 | class WasmLinker; |
| 243 | |
| 244 | // Interface provided to the decoder/graph builder which contains only |
| 245 | // minimal information about the globals, functions, and function tables. |
| 246 | struct ModuleEnv { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 247 | WasmModule* module; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 248 | WasmModuleInstance* instance; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 249 | WasmLinker* linker; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 250 | ModuleOrigin origin; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 251 | |
| 252 | bool IsValidGlobal(uint32_t index) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 253 | return module && index < module->globals.size(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 254 | } |
| 255 | bool IsValidFunction(uint32_t index) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 256 | return module && index < module->functions.size(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 257 | } |
| 258 | bool IsValidSignature(uint32_t index) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 259 | return module && index < module->signatures.size(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 261 | bool IsValidImport(uint32_t index) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 262 | return module && index < module->import_table.size(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 263 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 264 | MachineType GetGlobalType(uint32_t index) { |
| 265 | DCHECK(IsValidGlobal(index)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 266 | return module->globals[index].type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 267 | } |
| 268 | FunctionSig* GetFunctionSignature(uint32_t index) { |
| 269 | DCHECK(IsValidFunction(index)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 270 | return module->functions[index].sig; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 272 | FunctionSig* GetImportSignature(uint32_t index) { |
| 273 | DCHECK(IsValidImport(index)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 274 | return module->import_table[index].sig; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 275 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 276 | FunctionSig* GetSignature(uint32_t index) { |
| 277 | DCHECK(IsValidSignature(index)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 278 | return module->signatures[index]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 279 | } |
| 280 | size_t FunctionTableSize() { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 281 | return module ? module->function_table.size() : 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 284 | bool asm_js() { return origin == kAsmJsOrigin; } |
| 285 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 286 | Handle<Code> GetFunctionCode(uint32_t index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 287 | Handle<Code> GetImportCode(uint32_t index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 288 | Handle<FixedArray> GetFunctionTable(); |
| 289 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 290 | static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
| 291 | FunctionSig* sig); |
| 292 | static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
| 293 | Zone* zone, compiler::CallDescriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 294 | compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
| 295 | }; |
| 296 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 297 | // A helper for printing out the names of functions. |
| 298 | struct WasmFunctionName { |
| 299 | const WasmFunction* function_; |
| 300 | const WasmModule* module_; |
| 301 | WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv) |
| 302 | : function_(function), module_(menv ? menv->module : nullptr) {} |
| 303 | }; |
| 304 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 305 | std::ostream& operator<<(std::ostream& os, const WasmModule& module); |
| 306 | std::ostream& operator<<(std::ostream& os, const WasmFunction& function); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 307 | std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 308 | |
| 309 | typedef Result<WasmModule*> ModuleResult; |
| 310 | typedef Result<WasmFunction*> FunctionResult; |
| 311 | |
| 312 | // For testing. Decode, verify, and run the last exported function in the |
| 313 | // given encoded module. |
| 314 | int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
| 315 | const byte* module_end, bool asm_js = false); |
| 316 | |
| 317 | // For testing. Decode, verify, and run the last exported function in the |
| 318 | // given decoded module. |
| 319 | int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 320 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 321 | } // namespace wasm |
| 322 | } // namespace internal |
| 323 | } // namespace v8 |
| 324 | |
| 325 | #endif // V8_WASM_MODULE_H_ |