Add support for WGSL writing to BUILD.gn
BUG=tint:49
Change-Id: I4473176d4177a719b7b2659f765b6b467ac43c84
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19682
Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 41e7327..a3b566b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -38,6 +38,12 @@
} 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_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 @@
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 391380e..e481030 100644
--- a/samples/main.cc
+++ b/samples/main.cc
@@ -356,7 +356,7 @@
#if TINT_BUILD_WGSL_WRITER
if (options.format == Format::kWgsl) {
- auto w = static_cast<tint::writer::wgsl::Generator*>(writer.get());
+ auto* w = static_cast<tint::writer::wgsl::Generator*>(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 88e54c6..1b99cb3 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -86,7 +86,7 @@
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::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 @@
} 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 @@
} 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 f302f38..5732e2d 100644
--- a/tint_overrides_with_defaults.gni
+++ b/tint_overrides_with_defaults.gni
@@ -51,7 +51,10 @@
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