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