Split Program into Program and ProgramBuilder

Program is now immutable*, and remains part of the public Tint
interface.

ProgramBuilder is the mutable builder for Programs, and is not part of
the public Tint interface. ast::Builder has been folded into
ProgramBuilder.

Immutable Programs can be cloned into a mutable ProgramBuilder with
Program::CloneAsBuilder().

Mutable ProgramBuilders can be moved into immutable Programs.

* - mostly immutable. It still has a move constructor and move
  assignment operator - required for practical usage - and the
  semantic information on AST nodes is still mutable.

Bug: tint:390
Change-Id: Ia856c50b1880c2f95c91467a9eef5024cbc380c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38240
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-01-26 16:57:10 +00:00
parent 1f7e18bbc0
commit a6b9a8eb2f
186 changed files with 3324 additions and 2645 deletions

View File

@@ -56,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
auto src = parser.program();
// Clone the src program to dst
auto dst = src.Clone();
tint::Program dst(src.Clone());
// Expect the demangled AST printed with to_str() to match
tint::Demangler d;

View File

@@ -19,6 +19,10 @@
#include <utility>
#include <vector>
#include "src/ast/module.h"
#include "src/program.h"
#include "src/program_builder.h"
namespace tint {
namespace fuzzers {
@@ -81,9 +85,13 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
return 0;
}
TypeDeterminer td(&program);
if (!td.Determine()) {
return 0;
{
ProgramBuilder builder = program.CloneAsBuilder();
TypeDeterminer td(&builder);
if (!td.Determine()) {
return 0;
}
program = Program(std::move(builder));
}
Validator v;