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:
parent
0caab67e6e
commit
460345d993
26
BUILD.gn
26
BUILD.gn
|
@ -38,6 +38,12 @@ config("tint_common_config") {
|
||||||
} else {
|
} else {
|
||||||
defines += [ "TINT_BUILD_WGSL_READER=0" ]
|
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
|
# 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") {
|
source_set("libtint") {
|
||||||
deps = [ ":libtint_core" ]
|
deps = [ ":libtint_core" ]
|
||||||
|
|
||||||
|
@ -317,6 +339,10 @@ source_set("libtint") {
|
||||||
deps += [ ":libtint_wgsl_reader" ]
|
deps += [ ":libtint_wgsl_reader" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tint_build_wgsl_writer) {
|
||||||
|
deps += [ ":libtint_wgsl_writer" ]
|
||||||
|
}
|
||||||
|
|
||||||
configs += [ ":tint_common_config" ]
|
configs += [ ":tint_common_config" ]
|
||||||
|
|
||||||
if (build_with_chromium) {
|
if (build_with_chromium) {
|
||||||
|
|
|
@ -356,7 +356,7 @@ int main(int argc, const char** argv) {
|
||||||
|
|
||||||
#if TINT_BUILD_WGSL_WRITER
|
#if TINT_BUILD_WGSL_WRITER
|
||||||
if (options.format == Format::kWgsl) {
|
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;
|
std::cout << w->result() << std::endl;
|
||||||
}
|
}
|
||||||
#endif // TINT_BUILD_WGSL_WRITER
|
#endif // TINT_BUILD_WGSL_WRITER
|
||||||
|
|
|
@ -86,7 +86,7 @@ bool GeneratorImpl::Generate(const ast::Module& module) {
|
||||||
if (!module.entry_points().empty())
|
if (!module.entry_points().empty())
|
||||||
out_ << std::endl;
|
out_ << std::endl;
|
||||||
|
|
||||||
for (const auto& alias : module.alias_types()) {
|
for (auto* const alias : module.alias_types()) {
|
||||||
if (!EmitAliasType(alias)) {
|
if (!EmitAliasType(alias)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -367,10 +367,10 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
|
||||||
|
|
||||||
bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
||||||
if (type->IsAlias()) {
|
if (type->IsAlias()) {
|
||||||
auto alias = type->AsAlias();
|
auto* alias = type->AsAlias();
|
||||||
out_ << alias->name();
|
out_ << alias->name();
|
||||||
} else if (type->IsArray()) {
|
} else if (type->IsArray()) {
|
||||||
auto ary = type->AsArray();
|
auto* ary = type->AsArray();
|
||||||
out_ << "array<";
|
out_ << "array<";
|
||||||
if (!EmitType(ary->type())) {
|
if (!EmitType(ary->type())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -387,21 +387,21 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
||||||
} else if (type->IsI32()) {
|
} else if (type->IsI32()) {
|
||||||
out_ << "i32";
|
out_ << "i32";
|
||||||
} else if (type->IsMatrix()) {
|
} else if (type->IsMatrix()) {
|
||||||
auto mat = type->AsMatrix();
|
auto* mat = type->AsMatrix();
|
||||||
out_ << "mat" << mat->columns() << "x" << mat->rows() << "<";
|
out_ << "mat" << mat->columns() << "x" << mat->rows() << "<";
|
||||||
if (!EmitType(mat->type())) {
|
if (!EmitType(mat->type())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << ">";
|
out_ << ">";
|
||||||
} else if (type->IsPointer()) {
|
} else if (type->IsPointer()) {
|
||||||
auto ptr = type->AsPointer();
|
auto* ptr = type->AsPointer();
|
||||||
out_ << "ptr<" << ptr->storage_class() << ", ";
|
out_ << "ptr<" << ptr->storage_class() << ", ";
|
||||||
if (!EmitType(ptr->type())) {
|
if (!EmitType(ptr->type())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << ">";
|
out_ << ">";
|
||||||
} else if (type->IsStruct()) {
|
} else if (type->IsStruct()) {
|
||||||
auto str = type->AsStruct()->impl();
|
auto* str = type->AsStruct()->impl();
|
||||||
if (str->decoration() != ast::StructDecoration::kNone) {
|
if (str->decoration() != ast::StructDecoration::kNone) {
|
||||||
out_ << "[[" << str->decoration() << "]] ";
|
out_ << "[[" << str->decoration() << "]] ";
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
|
||||||
} else if (type->IsU32()) {
|
} else if (type->IsU32()) {
|
||||||
out_ << "u32";
|
out_ << "u32";
|
||||||
} else if (type->IsVector()) {
|
} else if (type->IsVector()) {
|
||||||
auto vec = type->AsVector();
|
auto* vec = type->AsVector();
|
||||||
out_ << "vec" << vec->size() << "<";
|
out_ << "vec" << vec->size() << "<";
|
||||||
if (!EmitType(vec->type())) {
|
if (!EmitType(vec->type())) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -51,7 +51,10 @@ declare_args() {
|
||||||
tint_build_wgsl_reader = false
|
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
|
# Generate fuzzers
|
||||||
# TODO(rharrison): Implement fuzzer support
|
# TODO(rharrison): Implement fuzzer support
|
||||||
|
|
Loading…
Reference in New Issue