Add reset method to the generators.

This CL allows the backend generators to be reset so they can be re-run
again.

Bug: tint:211
Change-Id: I67b0c650d0ab4615130777becc513099247339c9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28043
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-09-03 01:02:06 +00:00 committed by Commit Bot service account
parent 836027e327
commit 0f49753f35
10 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,12 @@ Generator::Generator(ast::Module module)
Generator::~Generator() = default;
void Generator::Reset() {
set_error("");
out_ = std::ostringstream();
impl_ = std::make_unique<GeneratorImpl>(&module_);
}
bool Generator::Generate() {
auto ret = impl_->Generate(out_);
if (!ret) {

View File

@ -34,6 +34,9 @@ class Generator : public Text {
explicit Generator(ast::Module module);
~Generator() override;
/// Resets the generator
void Reset() override;
/// Generates the result data
/// @returns true on successful generation; false otherwise
bool Generate() override;

View File

@ -52,6 +52,9 @@ class GeneratorImpl {
/// @returns the error
std::string error() const { return error_; }
/// Resets the generator
void Reset();
/// @param out the output stream
/// @returns true on successful generation; false otherwise
bool Generate(std::ostream& out);

View File

@ -26,6 +26,11 @@ Generator::Generator(ast::Module module)
Generator::~Generator() = default;
void Generator::Reset() {
set_error("");
impl_ = std::make_unique<GeneratorImpl>(&module_);
}
bool Generator::Generate() {
auto ret = impl_->Generate();
if (!ret) {

View File

@ -33,6 +33,9 @@ class Generator : public Text {
explicit Generator(ast::Module module);
~Generator() override;
/// Resets the generator
void Reset() override;
/// Generates the result data
/// @returns true on successful generation; false otherwise
bool Generate() override;

View File

@ -27,6 +27,11 @@ Generator::Generator(ast::Module module)
Generator::~Generator() = default;
void Generator::Reset() {
builder_ = std::make_unique<Builder>(&module_);
writer_ = std::make_unique<BinaryWriter>();
}
bool Generator::Generate() {
if (!builder_->Build()) {
set_error(builder_->error());

View File

@ -35,6 +35,9 @@ class Generator : public writer::Writer {
explicit Generator(ast::Module module);
~Generator() override;
/// Resets the generator
void Reset() override;
/// Generates the result data
/// @returns true on successful generation; false otherwise
bool Generate() override;

View File

@ -25,6 +25,11 @@ Generator::Generator(ast::Module module)
Generator::~Generator() = default;
void Generator::Reset() {
set_error("");
impl_ = std::make_unique<GeneratorImpl>();
}
bool Generator::Generate() {
auto ret = impl_->Generate(module_);
if (!ret) {

View File

@ -33,6 +33,9 @@ class Generator : public Text {
explicit Generator(ast::Module module);
~Generator() override;
/// Resets the generator
void Reset() override;
/// Generates the result data
/// @returns true on successful generation; false otherwise
bool Generate() override;

View File

@ -30,6 +30,9 @@ class Writer {
/// @returns the writer error string
const std::string& error() const { return error_; }
/// Resets the generator
virtual void Reset() = 0;
/// Converts the module into the desired format
/// @returns true on success; false on failure
virtual bool Generate() = 0;