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 // Used for encoding f32 and double constants to bits. | 5 // Used for encoding f32 and double constants to bits. |
6 let __buffer = new ArrayBuffer(8); | 6 let __buffer = new ArrayBuffer(8); |
7 let byte_view = new Int8Array(__buffer); | 7 let byte_view = new Int8Array(__buffer); |
8 let f32_view = new Float32Array(__buffer); | 8 let f32_view = new Float32Array(__buffer); |
9 let f64_view = new Float64Array(__buffer); | 9 let f64_view = new Float64Array(__buffer); |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 mutable: false} | 192 mutable: false} |
193 this.imports.push(o); | 193 this.imports.push(o); |
194 return this.num_imported_globals++; | 194 return this.num_imported_globals++; |
195 } | 195 } |
196 | 196 |
197 addImportedMemory(module, name, initial = 0, maximum) { | 197 addImportedMemory(module, name, initial = 0, maximum) { |
198 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; | 198 let o = {module: module, name: name, kind: kExternalMemory, initial: initial
, maximum: maximum}; |
199 this.imports.push(o); | 199 this.imports.push(o); |
200 } | 200 } |
201 | 201 |
202 addDataSegment(addr, data, is_global = false) { | 202 addDataSegment(addr, data, init) { |
203 this.segments.push({addr: addr, data: data, is_global: is_global}); | 203 this.segments.push({addr: addr, data: data, init: init}); |
204 return this.segments.length - 1; | 204 return this.segments.length - 1; |
205 } | 205 } |
206 | 206 |
207 exportMemoryAs(name) { | 207 exportMemoryAs(name) { |
208 this.exports.push({name: name, kind: kExternalMemory, index: 0}); | 208 this.exports.push({name: name, kind: kExternalMemory, index: 0}); |
209 } | 209 } |
210 | 210 |
211 appendToTable(array) { | 211 appendToTable(array) { |
212 this.table.push(...array); | 212 this.table.push(...array); |
213 return this; | 213 return this; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 }); | 437 }); |
438 } | 438 } |
439 | 439 |
440 // Add data segments. | 440 // Add data segments. |
441 if (wasm.segments.length > 0) { | 441 if (wasm.segments.length > 0) { |
442 if (debug) print("emitting data segments @ " + binary.length); | 442 if (debug) print("emitting data segments @ " + binary.length); |
443 binary.emit_section(kDataSectionCode, section => { | 443 binary.emit_section(kDataSectionCode, section => { |
444 section.emit_u32v(wasm.segments.length); | 444 section.emit_u32v(wasm.segments.length); |
445 for (let seg of wasm.segments) { | 445 for (let seg of wasm.segments) { |
446 section.emit_u8(0); // linear memory index 0 | 446 section.emit_u8(0); // linear memory index 0 |
447 if (seg.is_global) { | 447 section.emit_u8(kExprI32Const); |
448 // initializer is a global variable | 448 section.emit_u32v(seg.addr); |
449 section.emit_u8(kExprGetGlobal); | |
450 section.emit_u32v(seg.addr); | |
451 } else { | |
452 // initializer is a constant | |
453 section.emit_u8(kExprI32Const); | |
454 section.emit_u32v(seg.addr); | |
455 } | |
456 section.emit_u8(kExprEnd); | 449 section.emit_u8(kExprEnd); |
457 section.emit_u32v(seg.data.length); | 450 section.emit_u32v(seg.data.length); |
458 section.emit_bytes(seg.data); | 451 section.emit_bytes(seg.data); |
459 } | 452 } |
460 }); | 453 }); |
461 } | 454 } |
462 | 455 |
463 // Add any explicitly added sections | 456 // Add any explicitly added sections |
464 for (let exp of wasm.explicit) { | 457 for (let exp of wasm.explicit) { |
465 if (debug) print("emitting explicit @ " + binary.length); | 458 if (debug) print("emitting explicit @ " + binary.length); |
(...skipping 28 matching lines...) Expand all Loading... |
494 } | 487 } |
495 return buffer; | 488 return buffer; |
496 } | 489 } |
497 | 490 |
498 instantiate(...args) { | 491 instantiate(...args) { |
499 let module = new WebAssembly.Module(this.toBuffer()); | 492 let module = new WebAssembly.Module(this.toBuffer()); |
500 let instance = new WebAssembly.Instance(module, ...args); | 493 let instance = new WebAssembly.Instance(module, ...args); |
501 return instance; | 494 return instance; |
502 } | 495 } |
503 } | 496 } |
OLD | NEW |