fuzzers: Hook up the Program::printer
When TINT_BUILD_WGSL_WRITER is enabled.
This allows printing of the AST for debugging purposes.
Change-Id: I92b5911c16cb1e5fd22e81def00de33e9257f575
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/78541
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc
index 12fa3c4..fe5f10c 100644
--- a/fuzzers/tint_common_fuzzer.cc
+++ b/fuzzers/tint_common_fuzzer.cc
@@ -114,6 +114,16 @@
int CommonFuzzer::Run(const uint8_t* data, size_t size) {
tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
+#if TINT_BUILD_WGSL_WRITER
+ tint::Program::printer = [](const tint::Program* program) {
+ auto result = tint::writer::wgsl::Generate(program, {});
+ if (!result.error.empty()) {
+ return "error: " + result.error;
+ }
+ return result.wgsl;
+ };
+#endif // TINT_BUILD_WGSL_WRITER
+
Program program;
#if TINT_BUILD_SPV_READER