Commit 1d0719c7 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm][fuzzer] Integrate wasm-module-builder.js changes

Recent changes in wasm-module-builder.js were not translated to the
fuzzer JS output. After this CL, the fuzzer should generate .js files
that output back the fuzzed module.

Change-Id: I8bc33ab7f4f838a519c7aa47e425d8ac65b88d45
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2904217
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74659}
parent fc912616
......@@ -4074,7 +4074,6 @@ v8_source_set("v8_base_without_compiler") {
"src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-features.cc",
"src/wasm/wasm-import-wrapper-cache.cc",
"src/wasm/wasm-init-expr.cc",
"src/wasm/wasm-js.cc",
"src/wasm/wasm-module-builder.cc",
"src/wasm/wasm-module-sourcemap.cc",
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/wasm/wasm-init-expr.h"
namespace v8 {
namespace internal {
namespace wasm {
std::ostream& operator<<(std::ostream& os, const WasmInitExpr& expr) {
os << "(";
switch (expr.kind()) {
case WasmInitExpr::kNone:
UNREACHABLE();
case WasmInitExpr::kGlobalGet:
os << "global.get " << expr.immediate().index;
break;
case WasmInitExpr::kI32Const:
os << "i32.const " << expr.immediate().i32_const;
break;
case WasmInitExpr::kI64Const:
os << "i64.const " << expr.immediate().i64_const;
break;
case WasmInitExpr::kF32Const:
os << "f32.const " << expr.immediate().f32_const;
break;
case WasmInitExpr::kF64Const:
os << "f64.const " << expr.immediate().f64_const;
break;
case WasmInitExpr::kS128Const:
os << "s128.const 0x" << std::hex;
for (uint8_t b : expr.immediate().s128_const) {
os << b;
}
os << std::dec;
break;
case WasmInitExpr::kRefNullConst:
os << "ref.null " << expr.immediate().heap_type;
break;
case WasmInitExpr::kRefFuncConst:
os << "ref.func " << expr.immediate().index;
break;
case WasmInitExpr::kRttCanon:
os << "rtt.canon " << expr.immediate().heap_type;
break;
case WasmInitExpr::kRttSub:
os << "rtt.sub " << *expr.operand();
break;
}
os << ")";
return os;
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -140,9 +140,6 @@ class WasmInitExpr {
std::unique_ptr<WasmInitExpr> operand_ = nullptr;
};
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const WasmInitExpr& expr);
} // namespace wasm
} // namespace internal
} // namespace v8
......
......@@ -158,6 +158,39 @@ struct PrintName {
std::ostream& operator<<(std::ostream& os, const PrintName& name) {
return os.write(name.name.begin(), name.name.size());
}
std::ostream& operator<<(std::ostream& os, const WasmInitExpr& expr) {
os << "WasmInitExpr.";
switch (expr.kind()) {
case WasmInitExpr::kNone:
UNREACHABLE();
case WasmInitExpr::kS128Const:
case WasmInitExpr::kRttCanon:
case WasmInitExpr::kRttSub:
case WasmInitExpr::kRefNullConst:
// TODO(manoskouk): Implement these.
UNIMPLEMENTED();
case WasmInitExpr::kGlobalGet:
os << "GlobalGet(" << expr.immediate().index;
break;
case WasmInitExpr::kI32Const:
os << "I32Const(" << expr.immediate().i32_const;
break;
case WasmInitExpr::kI64Const:
os << "I64Const(" << expr.immediate().i64_const;
break;
case WasmInitExpr::kF32Const:
os << "F32Const(" << expr.immediate().f32_const;
break;
case WasmInitExpr::kF64Const:
os << "F64Const(" << expr.immediate().f64_const;
break;
case WasmInitExpr::kRefFuncConst:
os << "RefFunc(" << expr.immediate().index;
break;
}
return os << ")";
}
} // namespace
void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
......@@ -213,7 +246,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
for (WasmGlobal& glob : module->globals) {
os << "builder.addGlobal(" << ValueTypeToConstantName(glob.type) << ", "
<< glob.mutability << ");\n";
<< glob.mutability << ", " << glob.init << ");\n";
}
// TODO(7748): Support array/struct types.
......@@ -231,6 +264,8 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
Zone tmp_zone(isolate->allocator(), ZONE_NAME);
// There currently cannot be more than one table.
// TODO(manoskouk): Add support for more tables.
// TODO(9495): Add support for talbes with explicit initializers.
DCHECK_GE(1, module->tables.size());
for (const WasmTable& table : module->tables) {
os << "builder.setTableBounds(" << table.initial_size << ", ";
......@@ -241,19 +276,22 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
}
}
for (const WasmElemSegment& elem_segment : module->elem_segments) {
os << "builder.addElementSegment(";
os << elem_segment.table_index << ", ";
switch (elem_segment.offset.kind()) {
case WasmInitExpr::kGlobalGet:
os << elem_segment.offset.immediate().index << ", true";
break;
case WasmInitExpr::kI32Const:
os << elem_segment.offset.immediate().i32_const << ", false";
break;
default:
UNREACHABLE();
const char* status_str =
elem_segment.status == WasmElemSegment::kStatusActive
? "Active"
: elem_segment.status == WasmElemSegment::kStatusPassive
? "Passive"
: "Declarative";
os << "builder.add" << status_str << "ElementSegment(";
if (elem_segment.status == WasmElemSegment::kStatusActive) {
os << elem_segment.table_index << ", " << elem_segment.offset << ", ";
}
os << "[";
for (uint32_t i = 0; i < elem_segment.entries.size(); i++) {
os << elem_segment.entries[i];
if (i < elem_segment.entries.size() - 1) os << ", ";
}
os << ", " << PrintCollection(elem_segment.entries) << ");\n";
os << "], " << ValueTypeToConstantName(elem_segment.type) << ");\n";
}
for (const WasmFunction& func : module->functions) {
......
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