diff --git a/samples/main.cc b/samples/main.cc index 50e1f7a131..d1d0ec285a 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -623,7 +623,24 @@ bool GenerateWgsl(const tint::Program* program, const Options& options) { return false; } - return WriteFile(options.output_file, "w", result.wgsl); + if (!WriteFile(options.output_file, "w", result.wgsl)) { + return false; + } + + if (options.validate) { + // Attempt to re-parse the output program with Tint's WGSL reader. + auto source = std::make_unique(options.input_filename, + result.wgsl); + auto reparsed_program = tint::reader::wgsl::Parse(source.get()); + if (!reparsed_program.IsValid()) { + auto diag_printer = tint::diag::Printer::create(stderr, true); + tint::diag::Formatter diag_formatter; + diag_formatter.format(reparsed_program.Diagnostics(), diag_printer.get()); + return false; + } + } + + return true; #else (void)program; (void)options;