Commit 79a14688 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][wasm-gc][test] Improve and extend Javascript testing API

Changes:
- Add possibility to define and emit all reference types.
- Simplify function locals definition.
- Change 'type' to 'type_index' where appropiate.

Bug: v8:7748
Change-Id: Ie35a6204369e678298ee2ff2ec7c7793c5315c3e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2390144
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69814}
parent ff0c5cfa
......@@ -12,7 +12,7 @@ var builder = new WasmModuleBuilder();
// clang-format off
var func_idx = builder.addFunction('helper', kSig_v_v)
.addLocals({ i32_count: 1 })
.addLocals(kWasmI32, 1 )
.addBody([
kExprNop,
kExprI32Const, 12,
......
......@@ -80,10 +80,9 @@ async function instantiateWasm() {
])
.exportAs('main');
builder.addFunction('B (liftoff)', kSig_v_i)
.addLocals(
{i32_count: 1, f32_count: 4},
['i32_arg', 'i32_local', 'f32_local', '0', '0'])
builder.addFunction('B (liftoff)', kSig_v_i, ['i32_arg'])
.addLocals(kWasmI32, 1, ['i32_local'])
.addLocals(kWasmF32, 4, ['f32_local', '0', '0'])
.addBody([
// Load a parameter and a constant onto the operand stack.
kExprLocalGet, 0, kExprI32Const, 3,
......@@ -96,8 +95,8 @@ async function instantiateWasm() {
]);
// A third function which will be stepped through.
let func = builder.addFunction('C (interpreted)', kSig_v_i)
.addLocals({i32_count: 1}, ['i32_arg', 'i32_local'])
let func = builder.addFunction('C (interpreted)', kSig_v_i, ['i32_arg'])
.addLocals(kWasmI32, 1, ['i32_local'])
.addBody([
// Set global 0 to param 0.
kExprLocalGet, 0, kExprGlobalSet, 0,
......
......@@ -74,36 +74,37 @@ async function instantiateWasm() {
// Add a function without breakpoint, to check that locals are shown
// correctly in compiled code.
const main = builder.addFunction('call_func', kSig_v_i).addLocals({f32_count: 1}).addBody([
// Set local 1 to 7.2.
...wasmF32Const(7.2), kExprLocalSet, 1,
// Call function 'func', forwarding param 0.
kExprLocalGet, 0, kExprCallFunction, 1
]).exportAs('main');
const main = builder.addFunction('call_func', kSig_v_i).addLocals(kWasmF32, 1)
.addBody([
// Set local 1 to 7.2.
...wasmF32Const(7.2), kExprLocalSet, 1,
// Call function 'func', forwarding param 0.
kExprLocalGet, 0, kExprCallFunction, 1
]).exportAs('main');
// A second function which will be stepped through.
const func = builder.addFunction('func', kSig_v_i)
.addLocals(
{i32_count: 1, i64_count: 1, f64_count: 3},
['i32Arg', undefined, 'i64_local', 'unicode☼f64', '0', '0'])
.addBody([
// Set param 0 to 11.
kExprI32Const, 11, kExprLocalSet, 0,
// Set local 1 to 47.
kExprI32Const, 47, kExprLocalSet, 1,
// Set local 2 to 0x7FFFFFFFFFFFFFFF (max i64).
kExprI64Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
kExprLocalSet, 2,
// Set local 2 to 0x8000000000000000 (min i64).
kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f,
kExprLocalSet, 2,
// Set local 3 to 1/7.
kExprI32Const, 1, kExprF64UConvertI32, kExprI32Const, 7,
kExprF64UConvertI32, kExprF64Div, kExprLocalSet, 3,
// Set global 0 to 15
kExprI32Const, 15, kExprGlobalSet, 0,
]);
const func = builder.addFunction('func', kSig_v_i, ['i32Arg'])
.addLocals(kWasmI32, 1)
.addLocals(kWasmI64, 1, ['i64_local'])
.addLocals(kWasmF64, 3, ['unicode☼f64', '0', '0'])
.addBody([
// Set param 0 to 11.
kExprI32Const, 11, kExprLocalSet, 0,
// Set local 1 to 47.
kExprI32Const, 47, kExprLocalSet, 1,
// Set local 2 to 0x7FFFFFFFFFFFFFFF (max i64).
kExprI64Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
kExprLocalSet, 2,
// Set local 2 to 0x8000000000000000 (min i64).
kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f,
kExprLocalSet, 2,
// Set local 3 to 1/7.
kExprI32Const, 1, kExprF64UConvertI32, kExprI32Const, 7,
kExprF64UConvertI32, kExprF64Div, kExprLocalSet, 3,
// Set global 0 to 15
kExprI32Const, 15, kExprGlobalSet, 0,
]);
// Append function to table to test function table output.
builder.appendToTable([main.index]);
......@@ -114,8 +115,10 @@ async function instantiateWasm() {
function addWasmJSToTable() {
// Create WasmJS functions to test the function tables output.
const js_func = function js_func() { return 7; };
const wasmjs_func = new WebAssembly.Function({parameters:[], results:['i32']}, js_func);
const wasmjs_anonymous_func = new WebAssembly.Function({parameters:[], results:['i32']}, _ => 7);
const wasmjs_func = new WebAssembly.Function(
{parameters:[], results:['i32']}, js_func);
const wasmjs_anonymous_func = new WebAssembly.Function(
{parameters:[], results:['i32']}, _ => 7);
instance.exports.exported_table.set(0, wasmjs_func);
instance.exports.exported_table.set(1, wasmjs_anonymous_func);
......@@ -123,7 +126,8 @@ async function instantiateWasm() {
InspectorTest.log('Calling instantiate function.');
await WasmInspectorTest.instantiate(moduleBytes);
await WasmInspectorTest.evalWithUrl(`(${addWasmJSToTable})()`, 'populateTable');
await WasmInspectorTest.evalWithUrl(`(${addWasmJSToTable})()`,
'populateTable');
}
function printIfFailure(message) {
......
......@@ -11,7 +11,7 @@ var builder = new WasmModuleBuilder();
// clang-format off
var func_idx = builder.addFunction('helper', kSig_v_v)
.addLocals({ i32_count: 1 })
.addLocals(kWasmI32, 1)
.addBody([
kExprNop,
kExprI32Const, 12,
......
......@@ -11,9 +11,8 @@ session.setupScriptMap();
const builder = new WasmModuleBuilder();
// Create a function which computes the div of the first two arguments.
builder.addFunction('div', kSig_i_iii)
.addLocals(
{i32_count: 2}, ['a', 'b', 'unused', 'local_zero', 'local_const_11'])
builder.addFunction('div', kSig_i_iii, ['a', 'b', 'unused'])
.addLocals(kWasmI32, 2, ['local_zero', 'local_const_11'])
.addBody([
kExprI32Const, 11, // const 11
kExprLocalSet, 4, // set local #4 ('local_const_11')
......
......@@ -34,7 +34,7 @@ var func_b = builder.addFunction('wasm_B', kSig_v_i)
.exportAs('main');
let fact = builder.addFunction('fact', kSig_i_i)
.addLocals({i32_count: 1})
.addLocals(kWasmI32, 1)
.addBody([
// clang-format off
kExprLocalGet, 0,
......
......@@ -15,7 +15,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprI32Add,
]).exportFunc();
builder.addFunction("main", kSig_i_i)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprTry, kWasmStmt,
kExprLocalGet, 0,
......
......@@ -6,9 +6,9 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_iii)
.addLocals({f32_count: 4})
.addLocals({i64_count: 1})
.addLocals({f32_count: 2})
.addLocals(kWasmF32, 4)
.addLocals(kWasmI64, 1)
.addLocals(kWasmF32, 2)
.addBodyWithEnd([
kExprI64Const, 0,
kExprLocalGet, 3,
......
......@@ -19,7 +19,7 @@ kExprEnd, // @5
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addLocals({f32_count: 1}).addLocals({i32_count: 13})
.addLocals(kWasmF32, 1).addLocals(kWasmI32, 13)
.addBodyWithEnd([
// signature: v_v
// body:
......
......@@ -18,7 +18,7 @@ kExprEnd, // @3
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addLocals({f64_count: 8})
.addLocals(kWasmF64, 8)
.addBodyWithEnd([
// signature: d_v
// body:
......
......@@ -10,7 +10,7 @@ const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addLocals({i32_count: 2}).addLocals({f32_count: 2})
.addLocals(kWasmI32, 2).addLocals(kWasmF32, 2)
.addBodyWithEnd([
// signature: i_iii
// body:
......
......@@ -12,7 +12,7 @@ builder.addGlobal(kWasmI32, 1);
const sig = builder.addType(makeSig([kWasmI32, kWasmI64, kWasmI64, kWasmI64], [kWasmF32]));
// Generate function 1 (out of 3).
builder.addFunction(undefined, sig)
.addLocals({i32_count: 57}).addLocals({i64_count: 11})
.addLocals(kWasmI32, 57).addLocals(kWasmI64, 11)
.addBodyWithEnd([
// signature: f_illl
// body:
......
......@@ -11,7 +11,7 @@ builder.addMemory(1, 1, false, true);
const sig = builder.addType(makeSig([], [kWasmI32]));
builder.addFunction(undefined, sig)
.addLocals({i32_count: 1002}).addLocals({i64_count: 3})
.addLocals(kWasmI32, 1002).addLocals(kWasmI64, 3)
.addBodyWithEnd([
// signature: i_v
// body:
......
......@@ -16,10 +16,10 @@ const sig = builder.addType(makeSig(
[kWasmI64]));
// Generate function 2 (out of 3).
builder.addFunction(undefined, sig)
.addLocals({f32_count: 10})
.addLocals({i32_count: 4})
.addLocals({f64_count: 1})
.addLocals({i32_count: 15})
.addLocals(kWasmF32, 10)
.addLocals(kWasmI32, 4)
.addLocals(kWasmF64, 1)
.addLocals(kWasmI32, 15)
.addBodyWithEnd([
// signature: v_liliiiiiilll
// body:
......
......@@ -5,7 +5,7 @@
load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_v_v).addLocals({i64_count: 1}).addBody([
builder.addFunction(undefined, kSig_v_v).addLocals(kWasmI64, 1).addBody([
kExprI64Const, 0xeb, 0xd7, 0xaf, 0xdf,
0xbe, 0xfd, 0xfa, 0xf5, 0x6b, // i64.const
kExprI32Const, 0, // i32.const
......
......@@ -6,7 +6,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
sig0 = makeSig([], [kWasmI32]);
builder.addFunction(undefined, sig0).addLocals({i64_count: 1}).addBody([
builder.addFunction(undefined, sig0).addLocals(kWasmI64, 1).addBody([
kExprLoop, kWasmI32, // loop i32
kExprF32Const, 0x00, 0x00, 0x00, 0x00, // f32.const 0 --> f32:0
kExprLocalGet, 0x00, // get_local 0 --> i64:0
......
......@@ -49,7 +49,7 @@ assertEquals(1, instance.exports.main());
const builder2 = new WasmModuleBuilder();
sig0 = makeSig([], [kWasmI32]);
builder2.addFunction(undefined, sig0).addLocals({i64_count: 1}).addBody([
builder2.addFunction(undefined, sig0).addLocals(kWasmI64, 1).addBody([
kExprLoop, kWasmI32, // loop i32
kExprLocalGet, 0, // get_local 3
kExprF32SConvertI64, // f32.sconvert/i64
......
......@@ -9,6 +9,6 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_i)
.addBody([kExprLocalGet, 0])
.addLocals({s128_count: 1});
.addLocals(kWasmS128, 1)
assertFalse(WebAssembly.validate(builder.toBuffer()));
......@@ -41,7 +41,7 @@ builder.addImport('mod', 'get', kSig_i_v);
builder.addImport('mod', 'call', kSig_v_i);
builder.
addFunction('main', kSig_v_v).
addLocals({i32_count: kNumLocals}).
addLocals(kWasmI32, kNumLocals).
addBody(body).
exportAs('main');
let m1_bytes = builder.toBuffer();
......
......@@ -6,6 +6,6 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_i_i)
.addLocals({i32_count: 0xffffffff})
.addLocals(kWasmI32, 0xffffffff)
.addBody([]);
assertThrows(() => builder.instantiate(), WebAssembly.CompileError);
......@@ -6,7 +6,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, makeSig([kWasmI32, kWasmF32], []))
.addLocals({i32_count: 7})
.addLocals(kWasmI32, 7)
.addBody([
kExprLocalGet, 0, // get_local
kExprI32Const, 0, // i32.const 0
......
......@@ -32,7 +32,7 @@ const gen_i32_code = [
kExprI32Const, 1, // i32.const 1
kExprI32Add // i32.add --> 2nd param
];
builder.addFunction(undefined, kSig_v_v).addLocals({i32_count: 1}).addBody([
builder.addFunction(undefined, kSig_v_v).addLocals(kWasmI32, 1).addBody([
// Generate six values on the stack, then six more to force the other six on
// the stack.
...wasmI32Const(0), // i32.const 0
......
......@@ -16,7 +16,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var func_idx = builder.addFunction('helper', kSig_i_v)
.addLocals({i32_count: 1})
.addLocals(kWasmI32, 1)
.addBody([
kExprI32Const, 0x01,
]).index;
......
......@@ -13,7 +13,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
kExprEnd, // @1
]);
builder.addFunction(undefined, 1 /* sig */)
.addLocals({i32_count: 65})
.addLocals(kWasmI32, 65)
.addBodyWithEnd([
kExprLoop, kWasmStmt, // @3
kSimdPrefix,
......
......@@ -9,7 +9,7 @@ builder.addGlobal(kWasmI32, 1);
builder.addGlobal(kWasmF32, 1);
builder.addType(makeSig([kWasmI32, kWasmF32, kWasmF32, kWasmF64], [kWasmI32]));
builder.addFunction(undefined, 0 /* sig */)
.addLocals({i32_count: 504})
.addLocals(kWasmI32, 504)
.addBody([
kExprGlobalGet, 0x00,
kExprLocalSet, 0x04,
......
......@@ -7,7 +7,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const sig = builder.addType(makeSig([], [kWasmF64]));
builder.addFunction(undefined, sig)
.addLocals({f32_count: 5}).addLocals({f64_count: 3})
.addLocals(kWasmF32, 5).addLocals(kWasmF64, 3)
.addBody([
kExprBlock, kWasmF64,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
......
......@@ -6,7 +6,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_i_i)
.addLocals({i32_count: 7})
.addLocals(kWasmI32, 7)
.addBody([
kExprI32Const, 0,
kExprIf, kWasmI32, // @11 i32
......
......@@ -6,7 +6,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_v_v)
.addLocals({i32_count: 1}).addLocals({f32_count: 1}).addLocals({f64_count: 1})
.addLocals(kWasmI32, 1).addLocals(kWasmF32, 1).addLocals(kWasmF64, 1)
.addBody([
kExprLocalGet, 1,
kExprLocalGet, 2,
......
......@@ -6,7 +6,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_i_i)
.addLocals({i32_count: 5})
.addLocals(kWasmI32, 5)
.addBody([
kExprLocalGet, 0, // --> 1
kExprIf, kWasmI32,
......
......@@ -9,7 +9,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestTruncatedBrOnExnInLoop() {
let builder = new WasmModuleBuilder();
let fun = builder.addFunction(undefined, kSig_v_v)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprLoop, kWasmStmt,
kExprLocalGet, 0,
......
......@@ -7,7 +7,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const sig = builder.addType(makeSig([kWasmI32], []));
builder.addFunction(undefined, sig)
.addLocals({i64_count: 1})
.addLocals(kWasmI64, 1)
.addBody([
kExprLoop, kWasmI32,
kExprLocalGet, 1,
......
......@@ -7,7 +7,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const sig = builder.addType(makeSig([kWasmI64], [kWasmI64]));
builder.addFunction(undefined, sig)
.addLocals({i32_count: 14}).addLocals({i64_count: 17}).addLocals({f32_count: 14})
.addLocals(kWasmI32, 14).addLocals(kWasmI64, 17).addLocals(kWasmF32, 14)
.addBody([
kExprBlock, kWasmStmt,
kExprBr, 0x00,
......
......@@ -48,7 +48,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const gc_index = builder.addImport('q', 'gc', void_sig);
// First call the gc, then check if the object still exists.
builder.addFunction('main', ref_sig)
.addLocals({anyfunc_count: 10})
.addLocals(kWasmAnyFunc, 10)
.addBody([
kExprLocalGet, 0,
kExprLocalSet, 1, // Set local
......@@ -139,7 +139,7 @@ load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const sig_index = builder.addType(kSig_a_v);
builder.addFunction('main', sig_index)
.addLocals({anyfunc_count: 1})
.addLocals(kWasmAnyFunc, 1)
.addBody([kExprLocalGet, 0])
.exportFunc();
......
......@@ -437,7 +437,7 @@ function CmpExchgLoop(opcode, alignment) {
let builder = new WasmModuleBuilder();
builder.addImportedMemory("m", "imported_mem", 0, 2, "shared");
builder.addFunction("main", makeSig([kWasmI32], []))
.addLocals({i64_count: 2})
.addLocals(kWasmI64, 2)
.addBody([
kExprLoop, kWasmStmt,
kExprLocalGet, 0,
......
......@@ -126,9 +126,7 @@ function makeWorkerCodeForOpcode(compareExchangeOpcode, size, functionName,
builder.addFunction(functionName, makeSig([kWasmI32, kWasmI32, kWasmI32,
kWasmI32, kWasmI32
], []))
.addLocals({
i32_count: 3
})
.addLocals(kWasmI32, 3)
.addBody(body)
.exportAs(functionName);
}
......@@ -147,8 +145,8 @@ function spawnWorker(module, memory, address, sequence) {
`onmessage = function(msg) {
this.instance = new WebAssembly.Instance(msg.module,
{m: {imported_mem: msg.memory}});
instance.exports.worker(msg.address, msg.sequence, msg.sequenceLength, msg.workerId,
msg.bitMask);
instance.exports.worker(msg.address, msg.sequence,
msg.sequenceLength, msg.workerId, msg.bitMask);
postMessage({workerId: msg.workerId});
}`,
{type: 'string'}
......
......@@ -131,9 +131,7 @@ function makeWorkerCodeForOpcode(compareExchangeOpcode, size, functionName,
builder.addFunction(functionName, makeSig([kWasmI32, kWasmI32, kWasmI32,
kWasmI32, kWasmI32
], []))
.addLocals({
i32_count: 1, i64_count: 2
})
.addLocals(kWasmI32, 1).addLocals(kWasmI64, 2)
.addBody(body)
.exportAs(functionName);
}
......
......@@ -105,7 +105,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_a);
builder.addFunction("throw_catch_local", kSig_a_v)
.addLocals({anyfunc_count: 1})
.addLocals(kWasmAnyFunc, 1)
.addBody([
kExprTry, kWasmAnyFunc,
kExprLocalGet, 0,
......
......@@ -21,7 +21,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
kExprEnd,
]).exportFunc();
builder.addFunction("rethrow1", kSig_i_i)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprTry, kWasmI32,
kExprThrow, except,
......@@ -51,7 +51,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
let except1 = builder.addException(kSig_v_v);
let except2 = builder.addException(kSig_v_v);
builder.addFunction("rethrow_nested", kSig_i_i)
.addLocals({except_count: 2})
.addLocals(kWasmExnRef, 2)
.addBody([
kExprTry, kWasmI32,
kExprThrow, except2,
......@@ -93,7 +93,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_v);
builder.addFunction("rethrow_recatch", kSig_i_i)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprTry, kWasmI32,
kExprThrow, except,
......
......@@ -13,7 +13,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
var kSig_v_s = makeSig([kWasmS128], []);
var except = builder.addException(kSig_v_s);
builder.addFunction("throw_simd", kSig_v_v)
.addLocals({s128_count: 1})
.addLocals(kWasmS128, 1)
.addBody([
kExprLocalGet, 0,
kExprThrow, 0,
......@@ -31,7 +31,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
var kSig_v_s = makeSig([kWasmS128], []);
var except = builder.addException(kSig_v_s);
builder.addFunction("throw_catch_simd", kSig_i_v)
.addLocals({s128_count: 1})
.addLocals(kWasmS128, 1)
.addBody([
kExprTry, kWasmS128,
kExprLocalGet, 0,
......
......@@ -12,7 +12,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("push_and_drop_exnref", kSig_v_v)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprLocalGet, 0,
kExprDrop,
......@@ -343,7 +343,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_v);
builder.addFunction("catch_complex", kSig_i_i)
.addLocals({except_count: 1})
.addLocals(kWasmExnRef, 1)
.addBody([
kExprBlock, kWasmI32,
kExprTry, kWasmStmt,
......@@ -467,7 +467,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
let builder = new WasmModuleBuilder();
let except = builder.addException(kSig_v_l);
builder.addFunction("throw_catch_param", kSig_i_i)
.addLocals({i64_count: 1})
.addLocals(kWasmI64, 1)
.addBody([
kExprLocalGet, 0,
kExprI64UConvertI32,
......@@ -661,7 +661,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
.exportFunc();
builder.addFunction("same_scope_multiple", kSig_i_i)
.addLocals({i32_count: 1, except_count: 1})
.addLocals(kWasmI32, 1).addLocals(kWasmExnRef, 1)
// path = 0;
//
// try {
......
......@@ -53,7 +53,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const gc_index = builder.addImport("q", "gc", void_sig);
// First call the gc, then check if the object still exists.
builder.addFunction('main', ref_sig)
.addLocals({externref_count: 10})
.addLocals(kWasmExternRef, 10)
.addBody([
kExprLocalGet, 0, kExprLocalSet, 1, // Set local
kExprLocalGet, 0, kExprLocalSet, 2, // Set local
......@@ -209,7 +209,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_r_v)
.addBody([kExprLocalGet, 0])
.addLocals({externref_count: 1})
.addLocals(kWasmExternRef, 1)
.exportFunc();
const instance = builder.instantiate();
......
......@@ -54,7 +54,7 @@ function WasmI64AtomicWait(memory, offset, index, val_low,
// I64 for the instruction parameter.
builder.addFunction("main",
makeSig([kWasmI32, kWasmI32, kWasmI32, kWasmF64], [kWasmI32]))
.addLocals({i64_count: 1}) // local that is passed as value param to wait
.addLocals(kWasmI64, 1) // local that is passed as value param to wait
.addBody([
kExprLocalGet, 1,
kExprI64UConvertI32,
......
......@@ -17,7 +17,7 @@ builder.addImportedMemory('m', 'imported_mem', 1, 2);
builder.addType(makeSig(new Array(18).fill(kWasmS128), []));
builder.addFunction(undefined, makeSig([], []))
.addLocals({s128_count: 9})
.addLocals(kWasmS128, 9)
.addBodyWithEnd([
// These will all be args to the callee.
// Load first arg from memory, this was written with values from JS.
......
......@@ -33,7 +33,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
// For each v128 on the stack, we return the first and last lane. This help
// catch bugs with reading/writing the wrong stack slots.
builder.addFunction("main", sig_iiiiiiiiii_v)
.addLocals({"i32_count": 10, "s128_count": 1})
.addLocals(kWasmI32, 10).addLocals(kWasmS128, 1)
.addBody([
kExprCallFunction, callee.index,
......
......@@ -43,7 +43,7 @@ function instantiate(buffer, ffi) {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_i_i)
.addLocals({i32_count: 1})
.addLocals(kWasmI32, 1)
.addBody([kExprLocalGet, 0, kExprLocalSet, 1, kExprLocalGet, 1])
.exportAs('main');
......@@ -57,16 +57,15 @@ function instantiate(buffer, ffi) {
print(arguments.callee.name);
// TODO(titzer): i64 only works on 64-bit platforms.
var types = [
{locals: {i32_count: 1}, type: kWasmI32},
// {locals: {i64_count: 1}, type: kWasmI64},
{locals: {f32_count: 1}, type: kWasmF32},
{locals: {f64_count: 1}, type: kWasmF64},
{count: 1, type: kWasmI32},
{count: 1, type: kWasmF32},
{count: 1, type: kWasmF64},
];
for (p of types) {
let builder = new WasmModuleBuilder();
builder.addFunction(undefined, makeSig_r_x(p.type, p.type))
.addLocals(p.locals)
.addLocals(p.type, p.count)
.addBody([kExprLocalGet, 0, kExprLocalSet, 1, kExprLocalGet, 1])
.exportAs('main');
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment