Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 2403823002: [wasm] Base address for data segments can also be the value of a global variable. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/test-wasm-module-builder.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, init) { 202 addDataSegment(addr, data, is_global = false) {
203 this.segments.push({addr: addr, data: data, init: init}); 203 this.segments.push({addr: addr, data: data, is_global: is_global});
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
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 section.emit_u8(kExprI32Const); 447 if (seg.is_global) {
448 section.emit_u32v(seg.addr); 448 // initializer is a global variable
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 }
449 section.emit_u8(kExprEnd); 456 section.emit_u8(kExprEnd);
450 section.emit_u32v(seg.data.length); 457 section.emit_u32v(seg.data.length);
451 section.emit_bytes(seg.data); 458 section.emit_bytes(seg.data);
452 } 459 }
453 }); 460 });
454 } 461 }
455 462
456 // Add any explicitly added sections 463 // Add any explicitly added sections
457 for (let exp of wasm.explicit) { 464 for (let exp of wasm.explicit) {
458 if (debug) print("emitting explicit @ " + binary.length); 465 if (debug) print("emitting explicit @ " + binary.length);
(...skipping 28 matching lines...) Expand all
487 } 494 }
488 return buffer; 495 return buffer;
489 } 496 }
490 497
491 instantiate(...args) { 498 instantiate(...args) {
492 let module = new WebAssembly.Module(this.toBuffer()); 499 let module = new WebAssembly.Module(this.toBuffer());
493 let instance = new WebAssembly.Instance(module, ...args); 500 let instance = new WebAssembly.Instance(module, ...args);
494 return instance; 501 return instance;
495 } 502 }
496 } 503 }
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/test-wasm-module-builder.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698