| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 function StringRef(string) { | 5 function StringRef(string) { |
| 6 this.pos = -1; | 6 this.pos = -1; |
| 7 this.string = string; | 7 this.string = string; |
| 8 } | 8 } |
| 9 | 9 |
| 10 function DataRef(data) { | 10 function DataRef(data) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 WasmModuleBuilder.prototype.addFunction = function(name, sig) { | 73 WasmModuleBuilder.prototype.addFunction = function(name, sig) { |
| 74 var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); | 74 var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); |
| 75 var func = new WasmFunctionBuilder(name, sig_index); | 75 var func = new WasmFunctionBuilder(name, sig_index); |
| 76 func.index = this.functions.length; | 76 func.index = this.functions.length; |
| 77 this.functions.push(func); | 77 this.functions.push(func); |
| 78 return func; | 78 return func; |
| 79 } | 79 } |
| 80 | 80 |
| 81 WasmModuleBuilder.prototype.addImportWithModule = function(module, name, sig) { |
| 82 var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); |
| 83 this.imports.push({module: module, name: name, sig_index: sig_index}); |
| 84 return this.imports.length - 1; |
| 85 } |
| 86 |
| 81 WasmModuleBuilder.prototype.addImport = function(name, sig) { | 87 WasmModuleBuilder.prototype.addImport = function(name, sig) { |
| 82 var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); | 88 var sig_index = (typeof sig) == "number" ? sig : this.addSignature(sig); |
| 83 this.imports.push({name: name, sig_index: sig_index}); | 89 this.imports.push({module: name, name: undefined, sig_index: sig_index}); |
| 84 return this.imports.length - 1; | 90 return this.imports.length - 1; |
| 85 } | 91 } |
| 86 | 92 |
| 87 WasmModuleBuilder.prototype.addDataSegment = function(addr, data, init) { | 93 WasmModuleBuilder.prototype.addDataSegment = function(addr, data, init) { |
| 88 this.data_segments.push({addr: addr, data: data, init: init}); | 94 this.data_segments.push({addr: addr, data: data, init: init}); |
| 89 return this.data_segments.length - 1; | 95 return this.data_segments.length - 1; |
| 90 } | 96 } |
| 91 | 97 |
| 92 WasmModuleBuilder.prototype.appendToFunctionTable = function(array) { | 98 WasmModuleBuilder.prototype.appendToFunctionTable = function(array) { |
| 93 this.function_table = this.function_table.concat(array); | 99 this.function_table = this.function_table.concat(array); |
| 94 return this; | 100 return this; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 171 } |
| 166 } | 172 } |
| 167 | 173 |
| 168 // Add imports section | 174 // Add imports section |
| 169 if (this.imports.length > 0) { | 175 if (this.imports.length > 0) { |
| 170 if (debug) print("emitting imports @ " + bytes.length); | 176 if (debug) print("emitting imports @ " + bytes.length); |
| 171 emit_u8(bytes, kDeclImportTable); | 177 emit_u8(bytes, kDeclImportTable); |
| 172 emit_varint(bytes, this.imports.length); | 178 emit_varint(bytes, this.imports.length); |
| 173 for (imp of this.imports) { | 179 for (imp of this.imports) { |
| 174 emit_u16(bytes, imp.sig_index); | 180 emit_u16(bytes, imp.sig_index); |
| 175 emit_string(bytes, ""); | 181 emit_string(bytes, imp.module); |
| 176 emit_string(bytes, imp.name); | 182 if (imp.name == undefined) { |
| 183 emit_u32(bytes, 0); |
| 184 } else { |
| 185 emit_string(bytes, imp.name); |
| 186 } |
| 177 } | 187 } |
| 178 } | 188 } |
| 179 | 189 |
| 180 // Add functions section | 190 // Add functions section |
| 181 var names = false; | 191 var names = false; |
| 182 var exports = 0; | 192 var exports = 0; |
| 183 if (this.functions.length > 0) { | 193 if (this.functions.length > 0) { |
| 184 if (debug) print("emitting functions @ " + bytes.length); | 194 if (debug) print("emitting functions @ " + bytes.length); |
| 185 emit_u8(bytes, kDeclFunctions); | 195 emit_u8(bytes, kDeclFunctions); |
| 186 emit_varint(bytes, this.functions.length); | 196 emit_varint(bytes, this.functions.length); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 367 } |
| 358 | 368 |
| 359 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { | 369 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { |
| 360 var buffer = this.toBuffer(); | 370 var buffer = this.toBuffer(); |
| 361 if (memory != undefined) { | 371 if (memory != undefined) { |
| 362 return Wasm.instantiateModule(buffer, ffi, memory); | 372 return Wasm.instantiateModule(buffer, ffi, memory); |
| 363 } else { | 373 } else { |
| 364 return Wasm.instantiateModule(buffer, ffi); | 374 return Wasm.instantiateModule(buffer, ffi); |
| 365 } | 375 } |
| 366 } | 376 } |
| OLD | NEW |