Remove deprecated APIs

Remove the Parser classes from the wgsl and spirv namespaces.
These have been replaced with a Parse() method.

Remove the TypeDeterminer::Run() method, this was not called by tint and
the TypeDeterminer is now non-public API.

Change-Id: I5ddb82768da04398ab3958d1647be44f9fe30c21
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41840
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-17 20:15:25 +00:00 committed by Commit Bot service account
parent 6b4924fb0e
commit 7206e25798
11 changed files with 10 additions and 177 deletions

View File

@ -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<reader::Reader> parser;
Program program;
#if TINT_BUILD_WGSL_READER
std::unique_ptr<Source::File> 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<const char*>(data), size);
file = std::make_unique<Source::File>("test.wgsl", str);
parser = std::make_unique<reader::wgsl::Parser>(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<uint32_t> input(u32Data, u32Data + sizeInU32);
if (input.size() != 0) {
parser = std::make_unique<reader::spirv::Parser>(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;
}

View File

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

View File

@ -22,27 +22,6 @@ namespace tint {
namespace reader {
namespace spirv {
Parser::Parser(const std::vector<uint32_t>& spv_binary)
: Reader(), impl_(std::make_unique<ParserImpl>(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<uint32_t>& input) {
ParserImpl parser(input);
bool parsed = parser.Parse();

View File

@ -15,40 +15,14 @@
#ifndef SRC_READER_SPIRV_PARSER_H_
#define SRC_READER_SPIRV_PARSER_H_
#include <cstdint>
#include <memory>
#include <vector>
#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<uint32_t>& 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<ParserImpl> 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

View File

@ -26,13 +26,6 @@ namespace {
using ParserTest = testing::Test;
TEST_F(ParserTest, Uint32VecEmptyOld) {
std::vector<uint32_t> data;
Parser p(data);
EXPECT_FALSE(p.Parse());
// TODO(dneto): What message?
}
TEST_F(ParserTest, DataEmpty) {
std::vector<uint32_t> data;
auto program = Parse(data);

View File

@ -22,23 +22,6 @@ namespace tint {
namespace reader {
namespace wgsl {
Parser::Parser(Source::File const* file)
: Reader(), impl_(std::make_unique<ParserImpl>(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();

View File

@ -15,39 +15,13 @@
#ifndef SRC_READER_WGSL_PARSER_H_
#define SRC_READER_WGSL_PARSER_H_
#include <memory>
#include <string>
#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<ParserImpl> 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

View File

@ -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<out> gl_FragColor : vec4<f32>;
[[stage(vertex)]]
fn main() -> void {
gl_FragColor = vec4<f32>(.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<f32>(.4, .2, .3, 1);
}
)");
Parser p(&file);
auto program = Parse(&file);
auto errs = diag::Formatter().format(program.Diagnostics());
ASSERT_TRUE(program.IsValid()) << errs;

View File

@ -42,16 +42,12 @@ class TransformTest : public testing::Test {
std::string Transform(
std::string in,
std::vector<std::unique_ptr<transform::Transform>> 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());
}

View File

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

View File

@ -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(); }