Add support for WGSL reading to BUILD.gn BUG=tint:47 Change-Id: Ic50421f4dc712c614cf5783027ba273b53b2bd83 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19681 Reviewed-by: dan sinclair <dsinclair@google.com>
diff --git a/BUILD.gn b/BUILD.gn index af7b8cb..41e7327 100644 --- a/BUILD.gn +++ b/BUILD.gn
@@ -32,6 +32,12 @@ } else { defines += [ "TINT_BUILD_SPV_WRITER=0" ] } + + if (tint_build_wgsl_reader) { + defines += [ "TINT_BUILD_WGSL_READER=1" ] + } else { + defines += [ "TINT_BUILD_WGSL_READER=0" ] + } } # libtint source sets are divided into a non-optional core in :libtint_core and @@ -276,8 +282,29 @@ } } +source_set("libtint_wgsl_reader") { + sources = [ + "src/reader/wgsl/lexer.cc", + "src/reader/wgsl/lexer.h", + "src/reader/wgsl/parser.cc", + "src/reader/wgsl/parser.h", + "src/reader/wgsl/parser_impl.cc", + "src/reader/wgsl/parser_impl.h", + "src/reader/wgsl/token.cc", + "src/reader/wgsl/token.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" ] + if (tint_build_spv_reader) { deps += [ ":libtint_spv_reader" ] } @@ -286,6 +313,10 @@ deps += [ ":libtint_spv_writer" ] } + if (tint_build_wgsl_reader) { + deps += [ ":libtint_wgsl_reader" ] + } + configs += [ ":tint_common_config" ] if (build_with_chromium) { @@ -294,11 +325,23 @@ } } -executable("tint") { +config("tint_exe_config") { + include_dirs = [] + if (tint_build_spv_reader || tint_build_spv_writer) { + include_dirs = [ "${tint_spirv_tools_dir}/include/" ] + } +} + +executable("tint_exe") { sources = [ "samples/main.cc" ] deps = [ ":libtint" ] + if (tint_build_spv_reader || tint_build_spv_writer) { + deps += ["${tint_spirv_headers_dir}/:spv_headers" ] + } + configs += [ ":tint_common_config" ] + configs += [ ":tint_exe_config" ] if (build_with_chromium) { configs -= [ "//build/config/compiler:chromium_code" ] @@ -307,5 +350,5 @@ } group("tint_all") { - deps = [ ":tint" ] + deps = [ ":tint_exe" ] }
diff --git a/samples/main.cc b/samples/main.cc index 2a24f41..391380e 100644 --- a/samples/main.cc +++ b/samples/main.cc
@@ -343,7 +343,7 @@ #if TINT_BUILD_SPV_WRITER if (options.format == Format::kSpvAsm) { - auto w = static_cast<tint::writer::spirv::Generator*>(writer.get()); + auto* w = static_cast<tint::writer::spirv::Generator*>(writer.get()); auto str = Disassemble(w->result()); // TODO(dsinclair): Write to file if output_file given std::cout << str << std::endl;
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index db8a861..e87aa78 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc
@@ -224,7 +224,7 @@ return; } - auto ta = type_alias(); + auto* ta = type_alias(); if (has_error()) return; if (ta != nullptr) { @@ -612,7 +612,7 @@ return {}; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return {}; if (type == nullptr) { @@ -672,7 +672,7 @@ return nullptr; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -692,7 +692,7 @@ return nullptr; } - auto alias = + auto* alias = ctx_.type_mgr().Get(std::make_unique<ast::type::AliasType>(name, type)); register_alias(name, alias); @@ -724,7 +724,7 @@ auto t = peek(); if (t.IsIdentifier()) { next(); // Consume the peek - auto alias = get_alias(t.to_str()); + auto* alias = get_alias(t.to_str()); if (alias == nullptr) { set_error(t, "unknown type alias '" + t.to_str() + "'"); return nullptr; @@ -787,7 +787,7 @@ return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -820,7 +820,7 @@ return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -847,7 +847,7 @@ return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -901,7 +901,7 @@ return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -1251,7 +1251,7 @@ return nullptr; } - auto type = function_type_decl(); + auto* type = function_type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -1585,7 +1585,7 @@ } // break_stmt -// : BREAK ({IF | UNLESS} paren_rhs_stmt)? +// : BREAK ({IF | UNLESS} paren_rhs_stmt)? std::unique_ptr<ast::BreakStatement> ParserImpl::break_stmt() { auto t = peek(); if (!t.IsBreak()) @@ -1620,7 +1620,7 @@ } // continue_stmt -// : CONTINUE ({IF | UNLESS} paren_rhs_stmt)? +// : CONTINUE ({IF | UNLESS} paren_rhs_stmt)? std::unique_ptr<ast::ContinueStatement> ParserImpl::continue_stmt() { auto t = peek(); if (!t.IsContinue()) @@ -2040,7 +2040,7 @@ if (t.IsTrue()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>()); + auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>()); if (!type) { return nullptr; } @@ -2048,7 +2048,7 @@ } if (t.IsFalse()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>()); + auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>()); if (!type) { return nullptr; } @@ -2056,7 +2056,7 @@ } if (t.IsIntLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>()); + auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>()); if (!type) { return nullptr; } @@ -2064,7 +2064,7 @@ } if (t.IsUintLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>()); + auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>()); if (!type) { return nullptr; } @@ -2072,7 +2072,7 @@ } if (t.IsFloatLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()); + auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()); if (!type) { return nullptr; } @@ -2088,7 +2088,7 @@ auto t = peek(); auto source = t.source(); - auto type = type_decl(); + auto* type = type_decl(); if (type != nullptr) { t = next(); if (!t.IsParenLeft()) { @@ -2181,7 +2181,7 @@ return nullptr; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -2234,7 +2234,7 @@ std::move(ident)); } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type != nullptr) { @@ -2673,7 +2673,7 @@ auto t2 = peek(1); auto t3 = peek(2); - auto name = ""; + auto* name = ""; ast::BinaryOp op = ast::BinaryOp::kNone; if (t.IsLessThan() && t2.IsLessThan()) { next(); // Consume the t peek
diff --git a/tint_overrides_with_defaults.gni b/tint_overrides_with_defaults.gni index 7fb33e5..f302f38 100644 --- a/tint_overrides_with_defaults.gni +++ b/tint_overrides_with_defaults.gni
@@ -46,6 +46,11 @@ tint_build_spv_writer = false } + # Build the WGSL input reader + if (!defined(tint_build_wgsl_reader)) { + tint_build_wgsl_reader = false + } + # TODO(rharrison): Implement support for the reset of the reader/writers # Generate fuzzers