diff --git a/BUILD.gn b/BUILD.gn index af7b8cbeef..41e7327201 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -32,6 +32,12 @@ config("tint_common_config") { } 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_spv_writer") { } } +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 @@ source_set("libtint") { 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 @@ source_set("libtint") { } } -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 @@ executable("tint") { } group("tint_all") { - deps = [ ":tint" ] + deps = [ ":tint_exe" ] } diff --git a/samples/main.cc b/samples/main.cc index 2a24f41ac3..391380e1e9 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -343,7 +343,7 @@ int main(int argc, const char** argv) { #if TINT_BUILD_SPV_WRITER if (options.format == Format::kSpvAsm) { - auto w = static_cast(writer.get()); + auto* w = static_cast(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 db8a8619d1..e87aa780bc 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -224,7 +224,7 @@ void ParserImpl::global_decl() { return; } - auto ta = type_alias(); + auto* ta = type_alias(); if (has_error()) return; if (ta != nullptr) { @@ -612,7 +612,7 @@ std::pair ParserImpl::variable_ident_decl() { return {}; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return {}; if (type == nullptr) { @@ -672,7 +672,7 @@ ast::type::AliasType* ParserImpl::type_alias() { return nullptr; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -692,7 +692,7 @@ ast::type::AliasType* ParserImpl::type_alias() { return nullptr; } - auto alias = + auto* alias = ctx_.type_mgr().Get(std::make_unique(name, type)); register_alias(name, alias); @@ -724,7 +724,7 @@ ast::type::Type* ParserImpl::type_decl() { 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 @@ ast::type::Type* ParserImpl::type_decl_pointer(Token t) { return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -820,7 +820,7 @@ ast::type::Type* ParserImpl::type_decl_vector(Token t) { return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -847,7 +847,7 @@ ast::type::Type* ParserImpl::type_decl_array(Token t) { return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -901,7 +901,7 @@ ast::type::Type* ParserImpl::type_decl_matrix(Token t) { return nullptr; } - auto subtype = type_decl(); + auto* subtype = type_decl(); if (has_error()) return nullptr; if (subtype == nullptr) { @@ -1251,7 +1251,7 @@ std::unique_ptr ParserImpl::function_header() { return nullptr; } - auto type = function_type_decl(); + auto* type = function_type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -1585,7 +1585,7 @@ std::unique_ptr ParserImpl::statement() { } // break_stmt -//   : BREAK ({IF | UNLESS} paren_rhs_stmt)? +// : BREAK ({IF | UNLESS} paren_rhs_stmt)? std::unique_ptr ParserImpl::break_stmt() { auto t = peek(); if (!t.IsBreak()) @@ -1620,7 +1620,7 @@ std::unique_ptr ParserImpl::break_stmt() { } // continue_stmt -//   : CONTINUE ({IF | UNLESS} paren_rhs_stmt)? +// : CONTINUE ({IF | UNLESS} paren_rhs_stmt)? std::unique_ptr ParserImpl::continue_stmt() { auto t = peek(); if (!t.IsContinue()) @@ -2040,7 +2040,7 @@ std::unique_ptr ParserImpl::const_literal() { if (t.IsTrue()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique()); + auto* type = ctx_.type_mgr().Get(std::make_unique()); if (!type) { return nullptr; } @@ -2048,7 +2048,7 @@ std::unique_ptr ParserImpl::const_literal() { } if (t.IsFalse()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique()); + auto* type = ctx_.type_mgr().Get(std::make_unique()); if (!type) { return nullptr; } @@ -2056,7 +2056,7 @@ std::unique_ptr ParserImpl::const_literal() { } if (t.IsIntLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique()); + auto* type = ctx_.type_mgr().Get(std::make_unique()); if (!type) { return nullptr; } @@ -2064,7 +2064,7 @@ std::unique_ptr ParserImpl::const_literal() { } if (t.IsUintLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique()); + auto* type = ctx_.type_mgr().Get(std::make_unique()); if (!type) { return nullptr; } @@ -2072,7 +2072,7 @@ std::unique_ptr ParserImpl::const_literal() { } if (t.IsFloatLiteral()) { next(); // Consume the peek - auto type = ctx_.type_mgr().Get(std::make_unique()); + auto* type = ctx_.type_mgr().Get(std::make_unique()); if (!type) { return nullptr; } @@ -2088,7 +2088,7 @@ std::unique_ptr ParserImpl::const_expr() { 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 @@ std::unique_ptr ParserImpl::primary_expression() { return nullptr; } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type == nullptr) { @@ -2234,7 +2234,7 @@ std::unique_ptr ParserImpl::primary_expression() { std::move(ident)); } - auto type = type_decl(); + auto* type = type_decl(); if (has_error()) return nullptr; if (type != nullptr) { @@ -2673,7 +2673,7 @@ std::unique_ptr ParserImpl::shift_expr( 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 7fb33e5432..f302f38a7e 100644 --- a/tint_overrides_with_defaults.gni +++ b/tint_overrides_with_defaults.gni @@ -46,6 +46,11 @@ declare_args() { 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