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:
parent
836027e327
commit
0f49753f35
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue