diff --git a/include/tint/tint.h b/include/tint/tint.h index 592a178a1c..e9e7c9d7a4 100644 --- a/include/tint/tint.h +++ b/include/tint/tint.h @@ -20,6 +20,7 @@ #include "src/ast/pipeline_stage.h" #include "src/ast/type_manager.h" +#include "src/demangler.h" #include "src/diagnostic/printer.h" #include "src/inspector/inspector.h" #include "src/namer.h" diff --git a/samples/main.cc b/samples/main.cc index 1c4f9c969e..21bf81199d 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -46,6 +46,7 @@ struct Options { bool parse_only = false; bool dump_ast = false; bool dawn_validation = false; + bool demangle = false; Format format = Format::kNone; @@ -80,6 +81,8 @@ const char kUsage[] = R"(Usage: tint [options] --dump-ast -- Dump the generated AST to stdout --dawn-validation -- SPIRV outputs are validated with the same flags as Dawn does. Has no effect on non-SPIRV outputs. + --demangle -- Preserve original source names. Demangle them. + Affects AST dumping, and text-based output languages. -h -- This help text)"; #pragma clang diagnostic push @@ -233,6 +236,8 @@ bool ParseArgs(const std::vector& args, Options* opts) { opts->dump_ast = true; } else if (arg == "--dawn-validation") { opts->dawn_validation = true; + } else if (arg == "--demangle") { + opts->demangle = true; } else if (!arg.empty()) { if (arg[0] == '-') { std::cerr << "Unrecognized option: " << arg << std::endl; @@ -496,7 +501,11 @@ int main(int argc, const char** argv) { } if (options.dump_ast) { - std::cout << std::endl << mod.to_str() << std::endl; + auto ast_str = mod.to_str(); + if (options.demangle) { + ast_str = tint::Demangler().Demangle(mod, ast_str); + } + std::cout << std::endl << ast_str << std::endl; } if (options.parse_only) { return 1; @@ -622,7 +631,11 @@ int main(int argc, const char** argv) { if (options.format != Format::kSpvAsm && options.format != Format::kSpirv) { auto* w = static_cast(writer.get()); - if (!WriteFile(options.output_file, "w", w->result())) { + auto output = w->result(); + if (options.demangle) { + output = tint::Demangler().Demangle(mod, output); + } + if (!WriteFile(options.output_file, "w", output)) { return 1; } }