diff --git a/BUILD.gn b/BUILD.gn index 41e7327201..a3b566b2a6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -38,6 +38,12 @@ config("tint_common_config") { } else { defines += [ "TINT_BUILD_WGSL_READER=0" ] } + + if (tint_build_wgsl_writer) { + defines += [ "TINT_BUILD_WGSL_WRITER=1" ] + } else { + defines += [ "TINT_BUILD_WGSL_WRITER=0" ] + } } # libtint source sets are divided into a non-optional core in :libtint_core and @@ -302,6 +308,22 @@ source_set("libtint_wgsl_reader") { } } +source_set("libtint_wgsl_writer") { + sources = [ + "src/writer/wgsl/generator.cc", + "src/writer/wgsl/generator.h", + "src/writer/wgsl/generator_impl.cc", + "src/writer/wgsl/generator_impl.h", + ] + + configs += [ ":tint_common_config" ] + + if (build_with_chromium) { + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ "//build/config/compiler:no_chromium_code" ] + } +} + source_set("libtint") { deps = [ ":libtint_core" ] @@ -317,6 +339,10 @@ source_set("libtint") { deps += [ ":libtint_wgsl_reader" ] } + if (tint_build_wgsl_writer) { + deps += [ ":libtint_wgsl_writer" ] + } + configs += [ ":tint_common_config" ] if (build_with_chromium) { diff --git a/samples/main.cc b/samples/main.cc index 391380e1e9..e481030c07 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -356,7 +356,7 @@ int main(int argc, const char** argv) { #if TINT_BUILD_WGSL_WRITER if (options.format == Format::kWgsl) { - auto w = static_cast(writer.get()); + auto* w = static_cast(writer.get()); std::cout << w->result() << std::endl; } #endif // TINT_BUILD_WGSL_WRITER diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 88e54c6006..1b99cb3e6b 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -86,7 +86,7 @@ bool GeneratorImpl::Generate(const ast::Module& module) { if (!module.entry_points().empty()) out_ << std::endl; - for (const auto& alias : module.alias_types()) { + for (auto* const alias : module.alias_types()) { if (!EmitAliasType(alias)) { return false; } @@ -367,10 +367,10 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { bool GeneratorImpl::EmitType(ast::type::Type* type) { if (type->IsAlias()) { - auto alias = type->AsAlias(); + auto* alias = type->AsAlias(); out_ << alias->name(); } else if (type->IsArray()) { - auto ary = type->AsArray(); + auto* ary = type->AsArray(); out_ << "array<"; if (!EmitType(ary->type())) { return false; @@ -387,21 +387,21 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { } else if (type->IsI32()) { out_ << "i32"; } else if (type->IsMatrix()) { - auto mat = type->AsMatrix(); + auto* mat = type->AsMatrix(); out_ << "mat" << mat->columns() << "x" << mat->rows() << "<"; if (!EmitType(mat->type())) { return false; } out_ << ">"; } else if (type->IsPointer()) { - auto ptr = type->AsPointer(); + auto* ptr = type->AsPointer(); out_ << "ptr<" << ptr->storage_class() << ", "; if (!EmitType(ptr->type())) { return false; } out_ << ">"; } else if (type->IsStruct()) { - auto str = type->AsStruct()->impl(); + auto* str = type->AsStruct()->impl(); if (str->decoration() != ast::StructDecoration::kNone) { out_ << "[[" << str->decoration() << "]] "; } @@ -440,7 +440,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) { } else if (type->IsU32()) { out_ << "u32"; } else if (type->IsVector()) { - auto vec = type->AsVector(); + auto* vec = type->AsVector(); out_ << "vec" << vec->size() << "<"; if (!EmitType(vec->type())) { return false; diff --git a/tint_overrides_with_defaults.gni b/tint_overrides_with_defaults.gni index f302f38a7e..5732e2dc86 100644 --- a/tint_overrides_with_defaults.gni +++ b/tint_overrides_with_defaults.gni @@ -51,7 +51,10 @@ declare_args() { tint_build_wgsl_reader = false } - # TODO(rharrison): Implement support for the reset of the reader/writers + # Build the WGSL output writer + if (!defined(tint_build_wgsl_writer)) { + tint_build_wgsl_writer = false + } # Generate fuzzers # TODO(rharrison): Implement fuzzer support