mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
Migrate from using ast::Module to Program
Enforce all places where Dawn passes in or returns a ast::Module, now takes a `const Program* ` or returns a `Program`. As the end goal of all this is to have immutable Programs, all Program inputs take a pointer instead of moving the actual object. As consumers of a Program are now all const, we have to const_cast to work around all the places we've been incorrectly mutating a ast::Module. These const_casts are temporary, and will be fixed in the next set of changes. Depends on https://dawn-review.googlesource.com/c/dawn/+/38522 Bug: tint:390 Change-Id: Ie05b112b16134937d1b601e9b713ea4ec4e1c677 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38541 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -496,22 +496,22 @@ int main(int argc, const char** argv) {
|
||||
diag_formatter.format(reader->diagnostics(), diag_printer.get());
|
||||
return 1;
|
||||
}
|
||||
auto mod = reader->module();
|
||||
if (!mod.IsValid()) {
|
||||
std::cerr << "Invalid module generated..." << std::endl;
|
||||
auto program = reader->program();
|
||||
if (!program.IsValid()) {
|
||||
std::cerr << "Invalid program generated..." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
tint::TypeDeterminer td(&mod);
|
||||
tint::TypeDeterminer td(&program);
|
||||
if (!td.Determine()) {
|
||||
std::cerr << "Type Determination: " << td.error() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (options.dump_ast) {
|
||||
auto ast_str = mod.to_str();
|
||||
auto ast_str = program.to_str();
|
||||
if (options.demangle) {
|
||||
ast_str = tint::Demangler().Demangle(mod, ast_str);
|
||||
ast_str = tint::Demangler().Demangle(program, ast_str);
|
||||
}
|
||||
std::cout << std::endl << ast_str << std::endl;
|
||||
}
|
||||
@@ -520,7 +520,7 @@ int main(int argc, const char** argv) {
|
||||
}
|
||||
|
||||
tint::Validator v;
|
||||
if (!v.Validate(&mod)) {
|
||||
if (!v.Validate(&program)) {
|
||||
diag_formatter.format(v.diagnostics(), diag_printer.get());
|
||||
return 1;
|
||||
}
|
||||
@@ -546,37 +546,40 @@ int main(int argc, const char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
auto out = transform_manager.Run(&mod);
|
||||
auto out = transform_manager.Run(&program);
|
||||
if (out.diagnostics.contains_errors()) {
|
||||
diag_formatter.format(out.diagnostics, diag_printer.get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
mod = std::move(out.module);
|
||||
program = std::move(out.program);
|
||||
|
||||
std::unique_ptr<tint::writer::Writer> writer;
|
||||
|
||||
#if TINT_BUILD_SPV_WRITER
|
||||
if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) {
|
||||
writer = std::make_unique<tint::writer::spirv::Generator>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::spirv::Generator>(&program);
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_WRITER
|
||||
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
if (options.format == Format::kWgsl) {
|
||||
writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::wgsl::Generator>(&program);
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
if (options.format == Format::kMsl) {
|
||||
writer = std::make_unique<tint::writer::msl::Generator>(std::move(mod));
|
||||
writer = std::make_unique<tint::writer::msl::Generator>(&program);
|
||||
}
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
|
||||
#if TINT_BUILD_HLSL_WRITER
|
||||
if (options.format == Format::kHlsl) {
|
||||
writer = std::make_unique<tint::writer::hlsl::Generator>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::hlsl::Generator>(&program);
|
||||
}
|
||||
#endif // TINT_BUILD_HLSL_WRITER
|
||||
|
||||
@@ -641,7 +644,7 @@ int main(int argc, const char** argv) {
|
||||
auto* w = static_cast<tint::writer::Text*>(writer.get());
|
||||
auto output = w->result();
|
||||
if (options.demangle) {
|
||||
output = tint::Demangler().Demangle(mod, output);
|
||||
output = tint::Demangler().Demangle(program, output);
|
||||
}
|
||||
if (!WriteFile(options.output_file, "w", output)) {
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user