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

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

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: Address review comments 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/import-memory.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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return this.addImportWithModule(name, undefined, type); 187 return this.addImportWithModule(name, undefined, type);
188 } 188 }
189 189
190 addImportedGlobal(module, name, type) { 190 addImportedGlobal(module, name, type) {
191 let o = {module: module, name: name, kind: kExternalGlobal, type: type, 191 let o = {module: module, name: name, kind: kExternalGlobal, type: type,
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) {
198 let o = {module: module, name: name, kind: kExternalMemory, initial: initial , maximum: maximum};
199 this.imports.push(o);
200 }
201
197 addDataSegment(addr, data, init) { 202 addDataSegment(addr, data, init) {
198 this.segments.push({addr: addr, data: data, init: init}); 203 this.segments.push({addr: addr, data: data, init: init});
199 return this.segments.length - 1; 204 return this.segments.length - 1;
200 } 205 }
201 206
207 exportMemoryAs(name) {
208 this.exports.push({name: name, kind: kExternalMemory, index: 0});
209 }
210
202 appendToTable(array) { 211 appendToTable(array) {
203 this.table.push(...array); 212 this.table.push(...array);
204 return this; 213 return this;
205 } 214 }
206 215
207 toArray(debug) { 216 toArray(debug) {
208 let binary = new Binary; 217 let binary = new Binary;
209 let wasm = this; 218 let wasm = this;
210 219
211 // Add header 220 // Add header
(...skipping 25 matching lines...) Expand all
237 section.emit_u32v(wasm.imports.length); 246 section.emit_u32v(wasm.imports.length);
238 for (let imp of wasm.imports) { 247 for (let imp of wasm.imports) {
239 section.emit_string(imp.module); 248 section.emit_string(imp.module);
240 section.emit_string(imp.name || ''); 249 section.emit_string(imp.name || '');
241 section.emit_u8(imp.kind); 250 section.emit_u8(imp.kind);
242 if (imp.kind == kExternalFunction) { 251 if (imp.kind == kExternalFunction) {
243 section.emit_u32v(imp.type); 252 section.emit_u32v(imp.type);
244 } else if (imp.kind == kExternalGlobal) { 253 } else if (imp.kind == kExternalGlobal) {
245 section.emit_u32v(imp.type); 254 section.emit_u32v(imp.type);
246 section.emit_u8(imp.mutable); 255 section.emit_u8(imp.mutable);
256 } else if (imp.kind == kExternalMemory) {
257 var has_max = (typeof imp.maximum) != "undefined";
258 section.emit_u8(has_max ? 1 : 0); // flags
259 section.emit_u32v(imp.initial); // initial
260 if (has_max) section.emit_u32v(imp.maximum); // maximum
247 } else { 261 } else {
248 throw new Error("unknown/unsupported import kind " + imp.kind); 262 throw new Error("unknown/unsupported import kind " + imp.kind);
249 } 263 }
250 } 264 }
251 }); 265 });
252 } 266 }
253 267
254 // Add functions declarations 268 // Add functions declarations
255 let has_names = false; 269 let has_names = false;
256 let names = false; 270 let names = false;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 487 }
474 return buffer; 488 return buffer;
475 } 489 }
476 490
477 instantiate(...args) { 491 instantiate(...args) {
478 let module = new WebAssembly.Module(this.toBuffer()); 492 let module = new WebAssembly.Module(this.toBuffer());
479 let instance = new WebAssembly.Instance(module, ...args); 493 let instance = new WebAssembly.Instance(module, ...args);
480 return instance; 494 return instance;
481 } 495 }
482 } 496 }
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/import-memory.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698