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

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

Issue 2594993002: [wasm] Rename wasm::LocalType to wasm::ValueType and kAst* to kWasm* (Closed)
Patch Set: Fix inspector tests Created 4 years 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
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (wasm.globals.length > 0) { 346 if (wasm.globals.length > 0) {
347 if (debug) print ("emitting globals @ " + binary.length); 347 if (debug) print ("emitting globals @ " + binary.length);
348 binary.emit_section(kGlobalSectionCode, section => { 348 binary.emit_section(kGlobalSectionCode, section => {
349 section.emit_u32v(wasm.globals.length); 349 section.emit_u32v(wasm.globals.length);
350 for (let global of wasm.globals) { 350 for (let global of wasm.globals) {
351 section.emit_u8(global.type); 351 section.emit_u8(global.type);
352 section.emit_u8(global.mutable); 352 section.emit_u8(global.mutable);
353 if ((typeof global.init_index) == "undefined") { 353 if ((typeof global.init_index) == "undefined") {
354 // Emit a constant initializer. 354 // Emit a constant initializer.
355 switch (global.type) { 355 switch (global.type) {
356 case kAstI32: 356 case kWasmI32:
357 section.emit_u8(kExprI32Const); 357 section.emit_u8(kExprI32Const);
358 section.emit_u32v(global.init); 358 section.emit_u32v(global.init);
359 break; 359 break;
360 case kAstI64: 360 case kWasmI64:
361 section.emit_u8(kExprI64Const); 361 section.emit_u8(kExprI64Const);
362 section.emit_u8(global.init); 362 section.emit_u8(global.init);
363 break; 363 break;
364 case kAstF32: 364 case kWasmF32:
365 section.emit_u8(kExprF32Const); 365 section.emit_u8(kExprF32Const);
366 f32_view[0] = global.init; 366 f32_view[0] = global.init;
367 section.emit_u8(byte_view[0]); 367 section.emit_u8(byte_view[0]);
368 section.emit_u8(byte_view[1]); 368 section.emit_u8(byte_view[1]);
369 section.emit_u8(byte_view[2]); 369 section.emit_u8(byte_view[2]);
370 section.emit_u8(byte_view[3]); 370 section.emit_u8(byte_view[3]);
371 break; 371 break;
372 case kAstF64: 372 case kWasmF64:
373 section.emit_u8(kExprF64Const); 373 section.emit_u8(kExprF64Const);
374 f64_view[0] = global.init; 374 f64_view[0] = global.init;
375 section.emit_u8(byte_view[0]); 375 section.emit_u8(byte_view[0]);
376 section.emit_u8(byte_view[1]); 376 section.emit_u8(byte_view[1]);
377 section.emit_u8(byte_view[2]); 377 section.emit_u8(byte_view[2]);
378 section.emit_u8(byte_view[3]); 378 section.emit_u8(byte_view[3]);
379 section.emit_u8(byte_view[4]); 379 section.emit_u8(byte_view[4]);
380 section.emit_u8(byte_view[5]); 380 section.emit_u8(byte_view[5]);
381 section.emit_u8(byte_view[6]); 381 section.emit_u8(byte_view[6]);
382 section.emit_u8(byte_view[7]); 382 section.emit_u8(byte_view[7]);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 if (debug) print("emitting code @ " + binary.length); 450 if (debug) print("emitting code @ " + binary.length);
451 binary.emit_section(kCodeSectionCode, section => { 451 binary.emit_section(kCodeSectionCode, section => {
452 section.emit_u32v(wasm.functions.length); 452 section.emit_u32v(wasm.functions.length);
453 for (let func of wasm.functions) { 453 for (let func of wasm.functions) {
454 // Function body length will be patched later. 454 // Function body length will be patched later.
455 let local_decls = []; 455 let local_decls = [];
456 let l = func.locals; 456 let l = func.locals;
457 if (l != undefined) { 457 if (l != undefined) {
458 let local_decls_count = 0; 458 let local_decls_count = 0;
459 if (l.i32_count > 0) { 459 if (l.i32_count > 0) {
460 local_decls.push({count: l.i32_count, type: kAstI32}); 460 local_decls.push({count: l.i32_count, type: kWasmI32});
461 } 461 }
462 if (l.i64_count > 0) { 462 if (l.i64_count > 0) {
463 local_decls.push({count: l.i64_count, type: kAstI64}); 463 local_decls.push({count: l.i64_count, type: kWasmI64});
464 } 464 }
465 if (l.f32_count > 0) { 465 if (l.f32_count > 0) {
466 local_decls.push({count: l.f32_count, type: kAstF32}); 466 local_decls.push({count: l.f32_count, type: kWasmF32});
467 } 467 }
468 if (l.f64_count > 0) { 468 if (l.f64_count > 0) {
469 local_decls.push({count: l.f64_count, type: kAstF64}); 469 local_decls.push({count: l.f64_count, type: kWasmF64});
470 } 470 }
471 } 471 }
472 472
473 let header = new Binary; 473 let header = new Binary;
474 header.emit_u32v(local_decls.length); 474 header.emit_u32v(local_decls.length);
475 for (let decl of local_decls) { 475 for (let decl of local_decls) {
476 header.emit_u32v(decl.count); 476 header.emit_u32v(decl.count);
477 header.emit_u8(decl.type); 477 header.emit_u8(decl.type);
478 } 478 }
479 479
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 546 }
547 return buffer; 547 return buffer;
548 } 548 }
549 549
550 instantiate(...args) { 550 instantiate(...args) {
551 let module = new WebAssembly.Module(this.toBuffer()); 551 let module = new WebAssembly.Module(this.toBuffer());
552 let instance = new WebAssembly.Instance(module, ...args); 552 let instance = new WebAssembly.Instance(module, ...args);
553 return instance; 553 return instance;
554 } 554 }
555 } 555 }
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/wasm-constants.js ('k') | test/unittests/wasm/function-body-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698