fuzzers: Switch AST fuzzers to new generator API
Change-Id: If9f843a318be6e9bbb44bc852814811a5e42baf0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57980
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/fuzzers/tint_ast_fuzzer/fuzzer.cc b/fuzzers/tint_ast_fuzzer/fuzzer.cc
index 59dc075..ae39e6c 100644
--- a/fuzzers/tint_ast_fuzzer/fuzzer.cc
+++ b/fuzzers/tint_ast_fuzzer/fuzzer.cc
@@ -82,14 +82,15 @@
if (!cli_params.record_mutations) {
// If mutations are not being recorded, then the mutated `program` must be
// stored into the `mutator_state`.
- writer::wgsl::Generator generator(&program);
- if (!generator.Generate()) {
+ writer::wgsl::Options options;
+ auto result = writer::wgsl::Generate(&program, options);
+ if (!result.success) {
std::cout << "Can't generate WGSL for valid tint::Program:" << std::endl
<< " seed: " << seed << std::endl
- << generator.error() << std::endl;
+ << result.error << std::endl;
return 0;
}
- *mutator_state.mutable_program() = generator.result();
+ *mutator_state.mutable_program() = result.wgsl;
}
if (mutator_state.ByteSizeLong() > max_size) {
@@ -120,10 +121,11 @@
Replay(reader::wgsl::Parse(&file), mutator_state.mutation_sequence());
assert(program.IsValid() && "Replayed program is invalid");
- writer::wgsl::Generator generator(&program);
- success = generator.Generate();
- assert(success && "Can't generate a shader for the valid tint::Program");
- program_text = generator.result();
+ writer::wgsl::Options options;
+ auto result = writer::wgsl::Generate(&program, options);
+ assert(result.success &&
+ "Can't generate a shader for the valid tint::Program");
+ program_text = result.wgsl;
} else {
program_text.assign(data, data + size);
}
diff --git a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc
index 84e47b5..3af0059 100644
--- a/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc
+++ b/fuzzers/tint_ast_fuzzer/mutations/replace_identifier_test.cc
@@ -540,8 +540,9 @@
&program, &node_id_map, nullptr));
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
- writer::wgsl::Generator generator(&program);
- ASSERT_TRUE(generator.Generate()) << generator.error();
+ writer::wgsl::Options options;
+ auto result = writer::wgsl::Generate(&program, options);
+ ASSERT_TRUE(result.success) << result.error;
std::string expected_shader = R"(fn f() {
var b : vec2<u32>;
@@ -549,7 +550,7 @@
(*(&(b)))[1] = 3u;
}
)";
- ASSERT_EQ(expected_shader, generator.result());
+ ASSERT_EQ(expected_shader, result.wgsl);
}
TEST(ReplaceIdentifierTest, Applicable2) {
@@ -588,8 +589,9 @@
&program, &node_id_map, nullptr));
ASSERT_TRUE(program.IsValid()) << program.Diagnostics().str();
- writer::wgsl::Generator generator(&program);
- ASSERT_TRUE(generator.Generate()) << generator.error();
+ writer::wgsl::Options options;
+ auto result = writer::wgsl::Generate(&program, options);
+ ASSERT_TRUE(result.success) << result.error;
std::string expected_shader = R"(fn f(b : ptr<function, vec2<u32>>) {
var a = vec2<u32>(34u, 45u);
@@ -597,7 +599,7 @@
(*(b))[1] = 3u;
}
)";
- ASSERT_EQ(expected_shader, generator.result());
+ ASSERT_EQ(expected_shader, result.wgsl);
}
TEST(ReplaceIdentifierTest, NotApplicable12) {