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>
This commit is contained in:
Ryan Harrison 2020-04-15 20:54:10 +00:00 committed by dan sinclair
parent 0caab67e6e
commit 460345d993
4 changed files with 38 additions and 9 deletions

View File

@ -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) {

View File

@ -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<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

View File

@ -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;

View File

@ -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