[tint][ir][tint_ir_roundtrip_fuzzer] Emit WGSL output on error

Helps you actually see what's gone wrong when the emitted program
doesn't validate.

Change-Id: I928cc8b0df48e7e79868646937c34cf19488ec1c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/139645
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc b/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
index 18670d7..0ec7710 100644
--- a/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
+++ b/src/tint/fuzzers/tint_ir_roundtrip_fuzzer.cc
@@ -19,6 +19,7 @@
 #include "src/tint/ir/from_program.h"
 #include "src/tint/ir/to_program.h"
 #include "src/tint/reader/wgsl/parser_impl.h"
+#include "src/tint/writer/wgsl/generator.h"
 
 [[noreturn]] void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
     auto printer = tint::diag::Printer::create(stderr, true);
@@ -52,6 +53,12 @@
 
     auto dst = tint::ir::ToProgram(ir.Get());
     if (!dst.IsValid()) {
+#if TINT_BUILD_WGSL_WRITER
+        if (auto result = tint::writer::wgsl::Generate(&dst, {}); result.success) {
+            std::cerr << result.wgsl << std::endl << std::endl;
+        }
+#endif
+
         std::cerr << dst.Diagnostics() << std::endl;
         __builtin_trap();
     }