diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index 93b84fa7f6..cbabde2ebc 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -35,7 +35,8 @@ CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output) CommonFuzzer::~CommonFuzzer() = default; int CommonFuzzer::Run(const uint8_t* data, size_t size) { - std::unique_ptr parser; + Program program; + #if TINT_BUILD_WGSL_READER std::unique_ptr file; #endif // TINT_BUILD_WGSL_READER @@ -47,7 +48,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { std::string str(reinterpret_cast(data), size); file = std::make_unique("test.wgsl", str); - parser = std::make_unique(file.get()); + program = reader::wgsl::Parse(file.get()); } #endif // TINT_BUILD_WGSL_READER break; @@ -59,7 +60,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { std::vector input(u32Data, u32Data + sizeInU32); if (input.size() != 0) { - parser = std::make_unique(input); + program = reader::spirv::Parse(input); } } #endif // TINT_BUILD_WGSL_READER @@ -68,19 +69,10 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { break; } - if (!parser) { - return 0; - } - - if (!parser->Parse()) { - return 0; - } - if (output_ == OutputFormat::kNone) { return 0; } - auto program = parser->program(); if (!program.IsValid()) { return 0; } diff --git a/src/ast/module_clone_test.cc b/src/ast/module_clone_test.cc index 8afbf57b7d..7ed6be0e1b 100644 --- a/src/ast/module_clone_test.cc +++ b/src/ast/module_clone_test.cc @@ -120,9 +120,7 @@ const declaration_order_check_3 : i32 = 1; )"); // Parse the wgsl, create the src program - reader::wgsl::Parser parser(&file); - ASSERT_TRUE(parser.Parse()) << parser.error(); - auto src = parser.program(); + auto src = reader::wgsl::Parse(&file); ASSERT_TRUE(src.IsValid()) << diag::Formatter().format(src.Diagnostics()); diff --git a/src/reader/spirv/parser.cc b/src/reader/spirv/parser.cc index 75b6475073..d85402e536 100644 --- a/src/reader/spirv/parser.cc +++ b/src/reader/spirv/parser.cc @@ -22,27 +22,6 @@ namespace tint { namespace reader { namespace spirv { -Parser::Parser(const std::vector& spv_binary) - : Reader(), impl_(std::make_unique(spv_binary)) {} - -Parser::~Parser() = default; - -bool Parser::Parse() { - const auto result = impl_->Parse(); - auto err_msg = impl_->error(); - if (!err_msg.empty()) { - // TODO(bclayton): Migrate spirv::ParserImpl to using diagnostics. - diag::List diagnostics; - diagnostics.add_error(err_msg); - set_diagnostics(std::move(diagnostics)); - } - return result; -} - -Program Parser::program() { - return impl_->program(); -} - Program Parse(const std::vector& input) { ParserImpl parser(input); bool parsed = parser.Parse(); diff --git a/src/reader/spirv/parser.h b/src/reader/spirv/parser.h index cf9e53a1e2..d22ad30f25 100644 --- a/src/reader/spirv/parser.h +++ b/src/reader/spirv/parser.h @@ -15,40 +15,14 @@ #ifndef SRC_READER_SPIRV_PARSER_H_ #define SRC_READER_SPIRV_PARSER_H_ -#include -#include #include -#include "src/reader/reader.h" +#include "src/program.h" namespace tint { namespace reader { namespace spirv { -class ParserImpl; - -/// Parser for SPIR-V source data -/// [DEPRECATED] - Use Parse() -class Parser : public Reader { - public: - /// Creates a new parser - /// @param input the input data to parse - explicit Parser(const std::vector& input); - /// Destructor - ~Parser() override; - - /// Run the parser - /// @returns true if the parse was successful, false otherwise. - bool Parse() override; - - /// @returns the program. The program builder in the parser will be reset - /// after this. - Program program() override; - - private: - std::unique_ptr impl_; -}; - /// Parses the SPIR-V source data, returning the parsed program. /// If the source data fails to parse then the returned /// `program.Diagnostics.contains_errors()` will be true, and the diff --git a/src/reader/spirv/parser_test.cc b/src/reader/spirv/parser_test.cc index 8c4d7c1755..3da0fbcf97 100644 --- a/src/reader/spirv/parser_test.cc +++ b/src/reader/spirv/parser_test.cc @@ -26,13 +26,6 @@ namespace { using ParserTest = testing::Test; -TEST_F(ParserTest, Uint32VecEmptyOld) { - std::vector data; - Parser p(data); - EXPECT_FALSE(p.Parse()); - // TODO(dneto): What message? -} - TEST_F(ParserTest, DataEmpty) { std::vector data; auto program = Parse(data); diff --git a/src/reader/wgsl/parser.cc b/src/reader/wgsl/parser.cc index 4296e4d3ea..04728ed53f 100644 --- a/src/reader/wgsl/parser.cc +++ b/src/reader/wgsl/parser.cc @@ -22,23 +22,6 @@ namespace tint { namespace reader { namespace wgsl { -Parser::Parser(Source::File const* file) - : Reader(), impl_(std::make_unique(file)) {} - -Parser::~Parser() = default; - -bool Parser::Parse() { - bool ret = impl_->Parse(); - - set_diagnostics(std::move(impl_->diagnostics())); - - return ret; -} - -Program Parser::program() { - return impl_->program(); -} - Program Parse(Source::File const* file) { ParserImpl parser(file); parser.Parse(); diff --git a/src/reader/wgsl/parser.h b/src/reader/wgsl/parser.h index 1960396b51..4d83dcb8f1 100644 --- a/src/reader/wgsl/parser.h +++ b/src/reader/wgsl/parser.h @@ -15,39 +15,13 @@ #ifndef SRC_READER_WGSL_PARSER_H_ #define SRC_READER_WGSL_PARSER_H_ -#include -#include - -#include "src/reader/reader.h" +#include "src/program.h" #include "src/source.h" namespace tint { namespace reader { namespace wgsl { -class ParserImpl; - -/// Parser for WGSL source data -/// [DEPRECATED] - Use Parse() -class Parser : public Reader { - public: - /// Creates a new parser from the given file. - /// @param file the input source file to parse - explicit Parser(Source::File const* file); - ~Parser() override; - - /// Run the parser - /// @returns true if the parse was successful, false otherwise. - bool Parse() override; - - /// @returns the program. The program builder in the parser will be reset - /// after this. - Program program() override; - - private: - std::unique_ptr impl_; -}; - /// Parses the WGSL source, returning the parsed program. /// If the source fails to parse then the returned /// `program.Diagnostics.contains_errors()` will be true, and the diff --git a/src/reader/wgsl/parser_test.cc b/src/reader/wgsl/parser_test.cc index 030652e3f3..d75a74281f 100644 --- a/src/reader/wgsl/parser_test.cc +++ b/src/reader/wgsl/parser_test.cc @@ -25,41 +25,6 @@ namespace { using ParserTest = testing::Test; -TEST_F(ParserTest, EmptyOld) { - Source::File file("test.wgsl", ""); - Parser p(&file); - ASSERT_TRUE(p.Parse()) << p.error(); -} - -TEST_F(ParserTest, ParsesOld) { - Source::File file("test.wgsl", R"( -[[location(0)]] var gl_FragColor : vec4; - -[[stage(vertex)]] -fn main() -> void { - gl_FragColor = vec4(.4, .2, .3, 1); -} -)"); - Parser p(&file); - ASSERT_TRUE(p.Parse()) << p.error(); - - auto program = p.program(); - ASSERT_EQ(1u, program.AST().Functions().size()); - ASSERT_EQ(1u, program.AST().GlobalVariables().size()); -} - -TEST_F(ParserTest, HandlesErrorOld) { - Source::File file("test.wgsl", R"( -fn main() -> { // missing return type - return; -})"); - Parser p(&file); - - ASSERT_FALSE(p.Parse()); - ASSERT_TRUE(p.has_error()); - EXPECT_EQ(p.error(), "2:15: unable to determine function return type"); -} - TEST_F(ParserTest, Empty) { Source::File file("test.wgsl", ""); auto program = Parse(&file); @@ -76,7 +41,6 @@ fn main() -> void { gl_FragColor = vec4(.4, .2, .3, 1); } )"); - Parser p(&file); auto program = Parse(&file); auto errs = diag::Formatter().format(program.Diagnostics()); ASSERT_TRUE(program.IsValid()) << errs; diff --git a/src/transform/test_helper.h b/src/transform/test_helper.h index 78c84aca20..f52c5e741b 100644 --- a/src/transform/test_helper.h +++ b/src/transform/test_helper.h @@ -42,16 +42,12 @@ class TransformTest : public testing::Test { std::string Transform( std::string in, std::vector> transforms) { - Source::File file("test", in); - reader::wgsl::Parser parser(&file); - if (!parser.Parse()) { - return "WGSL reader failed:\n" + parser.error(); - } - diag::Formatter::Style style; style.print_newline_at_end = false; - auto program = parser.program(); + Source::File file("test", in); + auto program = reader::wgsl::Parse(&file); + if (!program.IsValid()) { return diag::Formatter(style).format(program.Diagnostics()); } diff --git a/src/type_determiner.cc b/src/type_determiner.cc index fc49224f0b..5bce843bbb 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -95,18 +95,6 @@ TypeDeterminer::TypeDeterminer(ProgramBuilder* builder) TypeDeterminer::~TypeDeterminer() = default; -diag::List TypeDeterminer::Run(Program* program) { - ProgramBuilder builder = program->CloneAsBuilder(); - TypeDeterminer td(&builder); - if (!td.Determine()) { - diag::List diagnostics; - diagnostics.add_error(td.error()); - return diagnostics; - } - *program = Program(std::move(builder)); - return {}; -} - void TypeDeterminer::set_referenced_from_function_if_needed(VariableInfo* var, bool local) { if (current_function_ == nullptr) { diff --git a/src/type_determiner.h b/src/type_determiner.h index 0a4fb3e743..8f0802ad08 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -59,14 +59,6 @@ class TypeDeterminer { /// Destructor ~TypeDeterminer(); - /// Run the type determiner on `program`, replacing the Program with a new - /// program containing type information. - /// [TEMPORARY] - Exists for making incremental changes. - /// @param program a pointer to the program variable that will be read from - /// and assigned to. - /// @returns a list of diagnostic messages - static diag::List Run(Program* program); - /// @returns error messages from the type determiner std::string error() const { return diagnostics_.str(); }