Commit 0e89afaa authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][test] Get rid of the imported parameter in addElementSegments

This parameter was just for convenience but did not end up in the
generated bytes.

R=clemensh@chromium.org

Bug: v8:9183
Change-Id: Id4faf5b9ad20a357c069c3189db6ed14945dea8c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1621929
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61681}
parent 84841783
......@@ -192,11 +192,8 @@ function getMemoryFill(mem) {
const tableIndex = 0;
const isGlobal = false;
const isImport = true;
builder.addElementSegment(
tableIndex, 2, isGlobal, [f.index, f.index], isImport);
builder.addElementSegment(
tableIndex, 0, isGlobal, [f.index, f.index], isImport);
builder.addElementSegment(tableIndex, 2, isGlobal, [f.index, f.index]);
builder.addElementSegment(tableIndex, 0, isGlobal, [f.index, f.index]);
assertEquals(null, table.get(0));
assertEquals(null, table.get(1));
......@@ -223,9 +220,7 @@ function getMemoryFill(mem) {
const tableIndex = 0;
const isGlobal = false;
const isImport = true;
builder.addElementSegment(
tableIndex, 0, isGlobal, [f.index, f.index], isImport);
builder.addElementSegment(tableIndex, 0, isGlobal, [f.index, f.index]);
builder.addDataSegment(0, [42]);
// Instantiation fails, but still modifies the table. The memory is not
......
......@@ -239,7 +239,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
.exportAs("main");
builder.addImportedTable("z", "table", kTableSize, kTableSize);
builder.addElementSegment(0, 1, false, [f2.index], true);
builder.addElementSegment(0, 1, false, [f2.index]);
var m2_bytes = builder.toBuffer();
var m2 = new WebAssembly.Module(m2_bytes);
......
......@@ -41,8 +41,8 @@ let kTableSize = 50;
let f17 = addConstFunc(builder, 17);
builder.addExport("f15", f15);
builder.addExport("f17", f17);
builder.addElementSegment(0, 15, false, [f15], true);
builder.addElementSegment(0, 1, false, [call.index], true);
builder.addElementSegment(0, 15, false, [f15]);
builder.addElementSegment(0, 1, false, [call.index]);
var mod1 = builder.toModule();
}
......@@ -62,10 +62,10 @@ let kTableSize = 50;
])
.exportAs("call");
let f26 = addConstFunc(builder, 26);
builder.addElementSegment(0, 17, false, [f17], true);
builder.addElementSegment(0, 21, false, [f21], true);
builder.addElementSegment(0, 26, false, [f26], true);
builder.addElementSegment(0, 5, false, [call.index], true);
builder.addElementSegment(0, 17, false, [f17]);
builder.addElementSegment(0, 21, false, [f21]);
builder.addElementSegment(0, 26, false, [f26]);
builder.addElementSegment(0, 5, false, [call.index]);
var mod2 = builder.toModule();
}
......@@ -113,8 +113,8 @@ function addConstFuncUsingGlobal(builder, val) {
let f18 = addConstFuncUsingGlobal(builder, 18);
builder.addExport("f14", f14);
builder.addExport("f18", f18);
builder.addElementSegment(0, 14, false, [f14], true);
builder.addElementSegment(0, 1, false, [call.index], true);
builder.addElementSegment(0, 14, false, [f14]);
builder.addElementSegment(0, 1, false, [call.index]);
var mod1 = builder.toModule();
}
......@@ -134,10 +134,10 @@ function addConstFuncUsingGlobal(builder, val) {
])
.exportAs("call");
let f28 = addConstFuncUsingGlobal(builder, 28);
builder.addElementSegment(0, 18, false, [f18], true);
builder.addElementSegment(0, 22, false, [f22], true);
builder.addElementSegment(0, 28, false, [f28], true);
builder.addElementSegment(0, 5, false, [call.index], true);
builder.addElementSegment(0, 18, false, [f18]);
builder.addElementSegment(0, 22, false, [f22]);
builder.addElementSegment(0, 28, false, [f28]);
builder.addElementSegment(0, 5, false, [call.index]);
var mod2 = builder.toModule();
}
......@@ -193,8 +193,8 @@ function addConstFuncUsingMemory(builder, val) {
let f19 = addConstFuncUsingMemory(builder, 19);
builder.addExport("f13", f13);
builder.addExport("f19", f19);
builder.addElementSegment(0, 13, false, [f13], true);
builder.addElementSegment(0, 1, false, [call.index], true);
builder.addElementSegment(0, 13, false, [f13]);
builder.addElementSegment(0, 1, false, [call.index]);
var mod1 = builder.toModule();
}
......@@ -216,10 +216,10 @@ function addConstFuncUsingMemory(builder, val) {
])
.exportAs("call");
let f29 = addConstFuncUsingMemory(builder, 29);
builder.addElementSegment(0, 19, false, [f19], true);
builder.addElementSegment(0, 23, false, [f23], true);
builder.addElementSegment(0, 29, false, [f29], true);
builder.addElementSegment(0, 5, false, [call.index], true);
builder.addElementSegment(0, 19, false, [f19]);
builder.addElementSegment(0, 23, false, [f23]);
builder.addElementSegment(0, 29, false, [f29]);
builder.addElementSegment(0, 5, false, [call.index]);
var mod2 = builder.toModule();
}
......
......@@ -68,11 +68,11 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
// We want to crash if we call through the table with index 0.
builder.addElementSegment(placeholder, 0, false,
[f_unreachable, f_unreachable, f_unreachable], false);
builder.addElementSegment(table1, 0, false, [f1, f2, f3], false);
[f_unreachable, f_unreachable, f_unreachable]);
builder.addElementSegment(table1, 0, false, [f1, f2, f3]);
// Keep one slot in table2 uninitialized. We should trap if we call it.
builder.addElementSegment(table2, 1, false,
[f_unreachable, f_unreachable, f4, f5], false);
[f_unreachable, f_unreachable, f4, f5]);
const instance = builder.instantiate();
......@@ -126,7 +126,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
kExprCallIndirect, sig_index, t1])
.exportAs('call');
builder.addElementSegment(t1, g, true, [f1.index], true);
builder.addElementSegment(t1, g, true, [f1.index]);
const base1 = 3;
const base2 = 5;
......
......@@ -316,7 +316,7 @@ function js_div(a, b) { return (a / b) | 0; }
.exportAs("main");
builder.addImportedTable("z", "table", kTableSize, kTableSize);
builder.addElementSegment(0, 1, false, [f2.index], true);
builder.addElementSegment(0, 1, false, [f2.index]);
var m2 = new WebAssembly.Module(builder.toBuffer());
......@@ -586,7 +586,7 @@ function js_div(a, b) { return (a / b) | 0; }
builder1.setName('module_1');
builder1.addFunction('f', kSig_i_i).addBody([kExprGetLocal, 0]);
builder1.addImportedTable('z', 'table');
builder1.addElementSegment(0, 0, false, [0], true);
builder1.addElementSegment(0, 0, false, [0]);
let module1 = new WebAssembly.Module(builder1.toBuffer());
let instance1 =
new WebAssembly.Instance(module1, {z: {table: instance0.exports.table}});
......@@ -624,7 +624,7 @@ function js_div(a, b) { return (a / b) | 0; }
builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_v).addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0]);
builder.addImportedTable('', 'table');
builder.addElementSegment(0, 0, false, [0], true);
builder.addElementSegment(0, 0, false, [0]);
builder.addImportedMemory('', 'memory', 1);
......
......@@ -537,7 +537,7 @@ function checkStack(stack, expected_lines) {
const builder1 = new WasmModuleBuilder();
builder1.addFunction('main', kSig_i_v).addBody([kExprUnreachable]);
builder1.addImportedTable('z', 'table');
builder1.addElementSegment(0, 0, false, [0], true);
builder1.addElementSegment(0, 0, false, [0]);
const module1 = new WebAssembly.Module(builder1.toBuffer());
const instance1 =
new WebAssembly.Instance(module1, {z: {table: instance0.exports.table}});
......
......@@ -29,7 +29,7 @@ const instance_for_import = (function() {
const f2 = builder_for_import.addFunction('f2', kSig_i_v)
.addBody([kExprI32Const, value2]).index;
builder_for_import.addElementSegment(t1, offset1, false, [f1, f2], false);
builder_for_import.addElementSegment(t1, offset1, false, [f1, f2]);
const instance_for_import = builder_for_import.instantiate();
const table1 = instance_for_import.exports.table;
assertEquals(value1, table1.get(offset1)());
......@@ -52,11 +52,11 @@ const f5 = builder.addFunction('f5', kSig_i_v)
.addBody([kExprI32Const, value5]).index;
builder.addElementSegment(t2, offset2, false, [f3, f4], false);
builder.addElementSegment(t3, offset3, false, [f5, f4], false);
builder.addElementSegment(t4, offset4, false, [f3, f5], false);
builder.addElementSegment(t2, offset2, false, [f3, f4]);
builder.addElementSegment(t3, offset3, false, [f5, f4]);
builder.addElementSegment(t4, offset4, false, [f3, f5]);
// Add one more overlapping offset
builder.addElementSegment(t4, offset4 + 1, false, [f4, f3], false);
builder.addElementSegment(t4, offset4 + 1, false, [f4, f3]);
const instance = builder.instantiate(instance_for_import);
// table2 == table1
......
......@@ -117,8 +117,8 @@ const dummy_func = exports.set_table_func1;
const offset1 = 3;
const offset2 = 9;
builder.addElementSegment(t1, offset1, false, [f1.index, f2.index], false);
builder.addElementSegment(t2, offset2, false, [f3.index, f1.index], false);
builder.addElementSegment(t1, offset1, false, [f1.index, f2.index]);
builder.addElementSegment(t2, offset2, false, [f3.index, f1.index]);
const instance = builder.instantiate();
......
......@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f2.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f2.index]);
const instance = builder.instantiate();
......@@ -27,7 +27,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22])
.exportAs("f2");
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f2.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f2.index]);
const instance = builder.instantiate();
......@@ -42,8 +42,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f2.index], false);
builder.addElementSegment(0, offset + 1, false, [f1.index, f2.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f2.index]);
builder.addElementSegment(0, offset + 1, false, [f1.index, f2.index]);
const instance = builder.instantiate();
......@@ -58,7 +58,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]).exportAs("f1");
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index]);
const instance = builder.instantiate();
......@@ -78,7 +78,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index]);
const instance = builder.instantiate();
......@@ -97,7 +97,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index]);
const instance = builder.instantiate();
assertEquals(null, instance.exports.table.get(offset - 1));
......@@ -111,7 +111,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const f2 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 22]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index], false);
builder.addElementSegment(0, offset, false, [f1.index, f1.index, f1.index]);
const instance = builder.instantiate();
assertThrows(() => instance.exports.table.get(size + 3), RangeError);
......@@ -125,7 +125,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const import1 = builder.addImport("q", "fun", kSig_i_ii);
const f1 = builder.addFunction('f', kSig_i_v).addBody([kExprI32Const, 11]);
const offset = 3;
builder.addElementSegment(0, offset, false, [f1.index, import1], false);
builder.addElementSegment(0, offset, false, [f1.index, import1]);
const instance = builder.instantiate({q: {fun: () => 33}});
assertEquals(33, instance.exports.table.get(offset + 1)());
......
......@@ -179,8 +179,6 @@ let id = (() => { // identity exported function
let t = builder.addImport("q", "exp_ten", sig_i_v);
builder.setTableBounds(7, 35);
// builder.addElementSegment(0, g1, true,
// [funcs.mul.index, funcs.add.index, funcs.sub.index]);
builder.addElementSegment(0, g1, true, [a, i, t]);
builder.addExportOfKind("table", kExternalTable, 0);
......@@ -266,7 +264,7 @@ let id = (() => { // identity exported function
kExprGetLocal, 0,
kExprCallIndirect, index_i_ii, kTableZero])
.exportAs("main");
builder.addElementSegment(0, 0, false, [0], true);
builder.addElementSegment(0, 0, false, [0]);
return new WebAssembly.Module(builder.toBuffer());
}
......
......@@ -897,7 +897,7 @@ class WasmModuleBuilder {
this.exports.push({name: name, kind: kExternalMemory, index: 0});
}
addElementSegment(table, base, is_global, array, is_import = false) {
addElementSegment(table, base, is_global, array) {
if (this.tables.length + this.num_imported_tables == 0) {
this.addTable(kWasmAnyFunc, 0);
}
......@@ -909,7 +909,7 @@ class WasmModuleBuilder {
// know how long the table actually is. If |is_global| is true, then the
// base is a global index, instead of an integer offset, so we can't update
// the table then either.
if (!(is_import || is_global)) {
if (!(is_global || table < this.num_imported_tables)) {
var length = base + array.length;
if (length > this.tables[0].initial_size) {
this.tables[0].initial_size = length;
......
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