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>
This commit is contained in:
Ryan Harrison 2020-04-15 20:47:55 +00:00
parent 2b45a52cdf
commit 0caab67e6e
4 changed files with 72 additions and 24 deletions

View File

@ -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" ]
}

View File

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

View File

@ -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<std::string, ast::type::Type*> 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<ast::type::AliasType>(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<ast::Function> 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<ast::Statement> ParserImpl::statement() {
}
// 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 @@ std::unique_ptr<ast::BreakStatement> ParserImpl::break_stmt() {
}
// 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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
}
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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
}
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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
}
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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
}
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 @@ std::unique_ptr<ast::ConstructorExpression> 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<ast::Expression> 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<ast::Expression> 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<ast::Expression> 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

View File

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