Move the ast node ownership from Context to Module
Fixes: tint:335
Change-Id: I128e229daa56d43e7227ecab72269be33b3ee012
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33240
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/writer/hlsl/test_helper.h b/src/writer/hlsl/test_helper.h
index b55f542..aea3938 100644
--- a/src/writer/hlsl/test_helper.h
+++ b/src/writer/hlsl/test_helper.h
@@ -43,13 +43,13 @@
/// @returns the pre result string
std::string pre_result() const { return pre.str(); }
- /// Creates a new `ast::Node` owned by the Context. When the Context is
+ /// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer template <typename T, typename... ARGS>
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
- return ctx.create<T>(std::forward<ARGS>(args)...);
+ return mod.create<T>(std::forward<ARGS>(args)...);
}
/// The context
diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h
index 149ba43..b336a47 100644
--- a/src/writer/msl/test_helper.h
+++ b/src/writer/msl/test_helper.h
@@ -35,13 +35,13 @@
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
~TestHelperBase() = default;
- /// Creates a new `ast::Node` owned by the Context. When the Context is
+ /// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
- return ctx.create<T>(std::forward<ARGS>(args)...);
+ return mod.create<T>(std::forward<ARGS>(args)...);
}
/// The context
diff --git a/src/writer/spirv/builder_function_decoration_test.cc b/src/writer/spirv/builder_function_decoration_test.cc
index 8b59b2e..161966c 100644
--- a/src/writer/spirv/builder_function_decoration_test.cc
+++ b/src/writer/spirv/builder_function_decoration_test.cc
@@ -105,9 +105,9 @@
EXPECT_TRUE(b.GenerateGlobalVariable(v_out)) << b.error();
EXPECT_TRUE(b.GenerateGlobalVariable(v_wg)) << b.error();
- mod.AddGlobalVariable(v_in);
- mod.AddGlobalVariable(v_out);
- mod.AddGlobalVariable(v_wg);
+ mod->AddGlobalVariable(v_in);
+ mod->AddGlobalVariable(v_out);
+ mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e"
@@ -168,9 +168,9 @@
EXPECT_TRUE(b.GenerateGlobalVariable(v_out)) << b.error();
EXPECT_TRUE(b.GenerateGlobalVariable(v_wg)) << b.error();
- mod.AddGlobalVariable(v_in);
- mod.AddGlobalVariable(v_out);
- mod.AddGlobalVariable(v_wg);
+ mod->AddGlobalVariable(v_in);
+ mod->AddGlobalVariable(v_out);
+ mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e"
diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc
index 1a6de92..20cbf8a 100644
--- a/src/writer/spirv/builder_function_test.cc
+++ b/src/writer/spirv/builder_function_test.cc
@@ -252,10 +252,10 @@
decos.push_back(create<ast::SetDecoration>(0, Source{}));
data_var->set_decorations(decos);
- mod.AddConstructedType(&s);
+ mod->AddConstructedType(&s);
td.RegisterVariableForTesting(data_var);
- mod.AddGlobalVariable(data_var);
+ mod->AddGlobalVariable(data_var);
{
ast::VariableList params;
@@ -272,7 +272,7 @@
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
- mod.AddFunction(func);
+ mod->AddFunction(func);
}
{
@@ -290,7 +290,7 @@
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
- mod.AddFunction(func);
+ mod->AddFunction(func);
}
ASSERT_TRUE(td.Determine()) << td.error();
diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc
index c877885..3b05637 100644
--- a/src/writer/spirv/builder_intrinsic_test.cc
+++ b/src/writer/spirv/builder_intrinsic_test.cc
@@ -51,16 +51,15 @@
namespace spirv {
namespace {
-class IntrinsicBuilderTest : public ast::BuilderWithContext,
+class IntrinsicBuilderTest : public ast::BuilderWithContextAndModule,
public testing::Test {
protected:
void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var);
}
- ast::Module mod;
- TypeDeterminer td{ctx, &mod};
- spirv::Builder b{ctx, &mod};
+ TypeDeterminer td{ctx, mod};
+ spirv::Builder b{ctx, mod};
};
template <typename T>
diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h
index 98637ba..c8194b4 100644
--- a/src/writer/spirv/test_helper.h
+++ b/src/writer/spirv/test_helper.h
@@ -31,13 +31,11 @@
/// Helper class for testing
template <typename BASE>
-class TestHelperBase : public ast::BuilderWithContext, public BASE {
+class TestHelperBase : public ast::BuilderWithContextAndModule, public BASE {
public:
- TestHelperBase() : td(ctx, &mod), b(ctx, &mod) {}
+ TestHelperBase() : td(ctx, mod), b(ctx, mod) {}
~TestHelperBase() override = default;
- /// The module
- ast::Module mod;
/// The type determiner
TypeDeterminer td;
/// The generator
diff --git a/src/writer/wgsl/test_helper.h b/src/writer/wgsl/test_helper.h
index 76e434f..57b14ce 100644
--- a/src/writer/wgsl/test_helper.h
+++ b/src/writer/wgsl/test_helper.h
@@ -36,13 +36,13 @@
~TestHelperBase() = default;
- /// Creates a new `ast::Node` owned by the Context. When the Context is
+ /// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
- return ctx.create<T>(std::forward<ARGS>(args)...);
+ return mod.create<T>(std::forward<ARGS>(args)...);
}
/// The context