Commit 091e100c authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove IIFE around generated test code

This is mostly used for regression tests which don't need that function.
If we want to wrap it for inclusion in an existing test file, we can
easily add a function around it, and name it properly.

R=ahaas@chromium.org

Bug: v8:10177
Change-Id: I2aedcdfad09fe1fe07af9f0caa2b8bd45da902f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2036077Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66102}
parent 7a20b6b9
......@@ -151,11 +151,10 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
"\n"
"load('test/mjsunit/wasm/wasm-module-builder.js');\n"
"\n"
"(function() {\n"
" const builder = new WasmModuleBuilder();\n";
"const builder = new WasmModuleBuilder();\n";
if (module->has_memory) {
os << " builder.addMemory(" << module->initial_pages;
os << "builder.addMemory(" << module->initial_pages;
if (module->has_maximum_pages) {
os << ", " << module->maximum_pages;
} else {
......@@ -169,12 +168,12 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
}
for (WasmGlobal& glob : module->globals) {
os << " builder.addGlobal(" << ValueTypeToConstantName(glob.type) << ", "
os << "builder.addGlobal(" << ValueTypeToConstantName(glob.type) << ", "
<< glob.mutability << ");\n";
}
for (const FunctionSig* sig : module->signatures) {
os << " builder.addType(makeSig(" << PrintParameters(sig) << ", "
os << "builder.addType(makeSig(" << PrintParameters(sig) << ", "
<< PrintReturns(sig) << "));\n";
}
......@@ -183,7 +182,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
// There currently cannot be more than one table.
DCHECK_GE(1, module->tables.size());
for (const WasmTable& table : module->tables) {
os << " builder.setTableBounds(" << table.initial_size << ", ";
os << "builder.setTableBounds(" << table.initial_size << ", ";
if (table.has_maximum_size) {
os << table.maximum_size << ");\n";
} else {
......@@ -191,7 +190,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
}
}
for (const WasmElemSegment& elem_segment : module->elem_segments) {
os << " builder.addElementSegment(";
os << "builder.addElementSegment(";
switch (elem_segment.offset.kind) {
case WasmInitExpr::kGlobalIndex:
os << elem_segment.offset.val.global_index << ", true";
......@@ -207,11 +206,11 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
for (const WasmFunction& func : module->functions) {
Vector<const uint8_t> func_code = wire_bytes.GetFunctionBytes(&func);
os << " // Generate function " << (func.func_index + 1) << " (out of "
os << "// Generate function " << (func.func_index + 1) << " (out of "
<< module->functions.size() << ").\n";
// Add function.
os << " builder.addFunction(undefined, " << func.sig_index
os << "builder.addFunction(undefined, " << func.sig_index
<< " /* sig */)\n";
// Add locals.
......@@ -219,7 +218,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
DecodeLocalDecls(enabled_features, &decls, func_code.begin(),
func_code.end());
if (!decls.type_list.empty()) {
os << " ";
os << " ";
for (size_t pos = 0, count = 1, locals = decls.type_list.size();
pos < locals; pos += count, count = 1) {
ValueType type = decls.type_list[pos];
......@@ -232,28 +231,28 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
}
// Add body.
os << " .addBodyWithEnd([\n";
os << " .addBodyWithEnd([\n";
FunctionBody func_body(func.sig, func.code.offset(), func_code.begin(),
func_code.end());
PrintRawWasmCode(isolate->allocator(), func_body, module, kOmitLocals);
os << " ]);\n";
os << "]);\n";
}
for (WasmExport& exp : module->export_table) {
if (exp.kind != kExternalFunction) continue;
os << " builder.addExport('" << PrintName(wire_bytes, exp.name) << "', "
os << "builder.addExport('" << PrintName(wire_bytes, exp.name) << "', "
<< exp.index << ");\n";
}
if (compiles) {
os << " const instance = builder.instantiate();\n"
" print(instance.exports.main(1, 2, 3));\n";
os << "const instance = builder.instantiate();\n"
"print(instance.exports.main(1, 2, 3));\n";
} else {
os << " assertThrows(function() { builder.instantiate(); }, "
os << "assertThrows(function() { builder.instantiate(); }, "
"WebAssembly.CompileError);\n";
}
os << "})();\n";
os << "\n";
}
void WasmExecutionFuzzer::FuzzWasmModule(Vector<const uint8_t> data,
......
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