ast: Move Module function methods to FunctionList

Module will be split into Module (immutable) and ModuleBuilder (mutable).
By moving these methods to the FunctionList, we can deduplicate a bunch of common logic.

Bug: tint:390
Change-Id: I3fd85200aae4e8dc3d5afce8c9aaa6512809a3a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38363
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-21 18:45:50 +00:00 committed by Commit Bot service account
parent 281b602f59
commit 6761160dc1
38 changed files with 354 additions and 305 deletions

View File

@ -360,5 +360,32 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
return ret; return ret;
} }
Function* FunctionList::Find(Symbol sym) const {
for (auto* func : *this) {
if (func->symbol() == sym) {
return func;
}
}
return nullptr;
}
Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
for (auto* func : *this) {
if (func->symbol() == sym && func->pipeline_stage() == stage) {
return func;
}
}
return nullptr;
}
bool FunctionList::HasStage(ast::PipelineStage stage) const {
for (auto* func : *this) {
if (func->pipeline_stage() == stage) {
return true;
}
}
return false;
}
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -210,7 +210,28 @@ class Function : public Castable<Function, Node> {
}; };
/// A list of functions /// A list of functions
using FunctionList = std::vector<Function*>; class FunctionList : public std::vector<Function*> {
public:
/// Appends f to the end of the list
/// @param f the function to append to this list
void Add(Function* f) { this->emplace_back(f); }
/// Returns the function with the given name
/// @param sym the function symbol to search for
/// @returns the associated function or nullptr if none exists
Function* Find(Symbol sym) const;
/// Returns the function with the given name
/// @param sym the function symbol to search for
/// @param stage the pipeline stage
/// @returns the associated function or nullptr if none exists
Function* Find(Symbol sym, PipelineStage stage) const;
/// @param stage the pipeline stage
/// @returns true if the Builder contains an entrypoint function with
/// the given stage
bool HasStage(PipelineStage stage) const;
};
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -18,6 +18,7 @@
#include "src/ast/discard_statement.h" #include "src/ast/discard_statement.h"
#include "src/ast/location_decoration.h" #include "src/ast/location_decoration.h"
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
#include "src/ast/stage_decoration.h"
#include "src/ast/test_helper.h" #include "src/ast/test_helper.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/ast/workgroup_decoration.h" #include "src/ast/workgroup_decoration.h"
@ -356,6 +357,58 @@ TEST_F(FunctionTest, WorkgroupSize) {
EXPECT_EQ(z, 6u); EXPECT_EQ(z, 6u);
} }
using FunctionListTest = TestHelper;
TEST_F(FunctionListTest, FindSymbol) {
auto* func = Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{});
FunctionList list;
list.Add(func);
EXPECT_EQ(func, list.Find(mod->RegisterSymbol("main")));
}
TEST_F(FunctionListTest, FindSymbolMissing) {
FunctionList list;
EXPECT_EQ(nullptr, list.Find(mod->RegisterSymbol("Missing")));
}
TEST_F(FunctionListTest, FindSymbolStage) {
auto* fs = Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
});
auto* vs = Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(PipelineStage::kVertex),
});
FunctionList list;
list.Add(fs);
list.Add(vs);
EXPECT_EQ(fs,
list.Find(mod->RegisterSymbol("main"), PipelineStage::kFragment));
EXPECT_EQ(vs, list.Find(mod->RegisterSymbol("main"), PipelineStage::kVertex));
}
TEST_F(FunctionListTest, FindSymbolStageMissing) {
FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
}));
EXPECT_EQ(nullptr,
list.Find(mod->RegisterSymbol("main"), PipelineStage::kVertex));
}
TEST_F(FunctionListTest, HasStage) {
FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment),
}));
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));
EXPECT_FALSE(list.HasStage(PipelineStage::kVertex));
}
} // namespace } // namespace
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint

View File

@ -48,34 +48,6 @@ void Module::Clone(CloneContext* ctx) const {
} }
} }
Function* Module::FindFunctionBySymbol(Symbol sym) const {
for (auto* func : functions_) {
if (func->symbol() == sym) {
return func;
}
}
return nullptr;
}
Function* Module::FindFunctionBySymbolAndStage(Symbol sym,
PipelineStage stage) const {
for (auto* func : functions_) {
if (func->symbol() == sym && func->pipeline_stage() == stage) {
return func;
}
}
return nullptr;
}
bool Module::HasStage(ast::PipelineStage stage) const {
for (auto* func : functions_) {
if (func->pipeline_stage() == stage) {
return true;
}
}
return false;
}
Symbol Module::RegisterSymbol(const std::string& name) { Symbol Module::RegisterSymbol(const std::string& name) {
return symbol_table_.Register(name); return symbol_table_.Register(name);
} }

View File

@ -82,24 +82,11 @@ class Module {
return constructed_types_; return constructed_types_;
} }
/// Adds a function to the module /// @returns the functions declared in the translation unit
/// @param func the function const FunctionList& Functions() const { return functions_; }
void AddFunction(Function* func) { functions_.push_back(func); }
/// @returns the modules functions /// @returns the functions declared in the translation unit
const FunctionList& functions() const { return functions_; } FunctionList& Functions() { return functions_; }
/// Returns the function with the given name
/// @param sym the function symbol to search for
/// @returns the associated function or nullptr if none exists
Function* FindFunctionBySymbol(Symbol sym) const;
/// Returns the function with the given name
/// @param sym the function symbol to search for
/// @param stage the pipeline stage
/// @returns the associated function or nullptr if none exists
Function* FindFunctionBySymbolAndStage(Symbol sym, PipelineStage stage) const;
/// @param stage the pipeline stage
/// @returns true if the module contains an entrypoint function with the given
/// stage
bool HasStage(PipelineStage stage) const;
/// @returns true if all required fields in the AST are present. /// @returns true if all required fields in the AST are present.
bool IsValid() const; bool IsValid() const;

View File

@ -32,7 +32,7 @@ namespace {
using ModuleTest = TestHelper; using ModuleTest = TestHelper;
TEST_F(ModuleTest, Creation) { TEST_F(ModuleTest, Creation) {
EXPECT_EQ(mod->functions().size(), 0u); EXPECT_EQ(mod->Functions().size(), 0u);
} }
TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) { TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
@ -41,17 +41,6 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
EXPECT_EQ(str, expected); EXPECT_EQ(str, expected);
} }
TEST_F(ModuleTest, LookupFunction) {
auto* func = Func("main", VariableList{}, ty.f32, StatementList{},
ast::FunctionDecorationList{});
mod->AddFunction(func);
EXPECT_EQ(func, mod->FindFunctionBySymbol(mod->RegisterSymbol("main")));
}
TEST_F(ModuleTest, LookupFunctionMissing) {
EXPECT_EQ(nullptr, mod->FindFunctionBySymbol(mod->RegisterSymbol("Missing")));
}
TEST_F(ModuleTest, IsValid_Empty) { TEST_F(ModuleTest, IsValid_Empty) {
EXPECT_TRUE(mod->IsValid()); EXPECT_TRUE(mod->IsValid());
} }
@ -102,12 +91,12 @@ TEST_F(ModuleTest, IsValid_Function) {
auto* func = Func("main", VariableList(), ty.f32, StatementList{}, auto* func = Func("main", VariableList(), ty.f32, StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(mod->IsValid()); EXPECT_TRUE(mod->IsValid());
} }
TEST_F(ModuleTest, IsValid_Null_Function) { TEST_F(ModuleTest, IsValid_Null_Function) {
mod->AddFunction(nullptr); mod->Functions().Add(nullptr);
EXPECT_FALSE(mod->IsValid()); EXPECT_FALSE(mod->IsValid());
} }
@ -115,7 +104,7 @@ TEST_F(ModuleTest, IsValid_Invalid_Function) {
auto* func = Func("main", VariableList{}, nullptr, StatementList{}, auto* func = Func("main", VariableList{}, nullptr, StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_FALSE(mod->IsValid()); EXPECT_FALSE(mod->IsValid());
} }

View File

@ -50,7 +50,7 @@ Inspector::~Inspector() = default;
std::vector<EntryPoint> Inspector::GetEntryPoints() { std::vector<EntryPoint> Inspector::GetEntryPoints() {
std::vector<EntryPoint> result; std::vector<EntryPoint> result;
for (auto* func : module_.functions()) { for (auto* func : module_.Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -278,7 +278,7 @@ std::vector<ResourceBinding> Inspector::GetMultisampledTextureResourceBindings(
} }
ast::Function* Inspector::FindEntryPointByName(const std::string& name) { ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
auto* func = module_.FindFunctionBySymbol(module_.GetSymbol(name)); auto* func = module_.Functions().Find(module_.GetSymbol(name));
if (!func) { if (!func) {
error_ += name + " was not found!"; error_ += name + " was not found!";
return nullptr; return nullptr;

View File

@ -701,7 +701,7 @@ TEST_F(InspectorGetEntryPointTest, NoFunctions) {
} }
TEST_F(InspectorGetEntryPointTest, NoEntryPoints) { TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {
mod->AddFunction(MakeEmptyBodyFunction("foo", {})); mod->Functions().Add(MakeEmptyBodyFunction("foo", {}));
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -714,7 +714,7 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available. // TODO(dsinclair): Update to run the namer transform when available.
@ -732,13 +732,13 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto* bar = MakeEmptyBodyFunction( auto* bar = MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{ "bar", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(bar); mod->Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when available. // TODO(dsinclair): Update to run the namer transform when available.
@ -756,21 +756,21 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
auto* func = MakeEmptyBodyFunction("func", {}); auto* func = MakeEmptyBodyFunction("func", {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeCallerBodyFunction( auto* foo = MakeCallerBodyFunction(
"foo", "func", "foo", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto* bar = MakeCallerBodyFunction( auto* bar = MakeCallerBodyFunction(
"bar", "func", "bar", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(bar); mod->Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when available. // TODO(dsinclair): Update to run the namer transform when available.
@ -792,7 +792,7 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -811,7 +811,7 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
create<ast::WorkgroupDecoration>(8u, 2u, 1u), create<ast::WorkgroupDecoration>(8u, 2u, 1u),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -826,14 +826,14 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
TEST_F(InspectorGetEntryPointTest, NoInOutVariables) { TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
auto* func = MakeEmptyBodyFunction("func", {}); auto* func = MakeEmptyBodyFunction("func", {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeCallerBodyFunction( auto* foo = MakeCallerBodyFunction(
"foo", "func", "foo", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -851,7 +851,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -875,14 +875,14 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
auto* func = auto* func =
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeCallerBodyFunction( auto* foo = MakeCallerBodyFunction(
"foo", "func", "foo", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -906,14 +906,14 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
auto* func = auto* func =
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeInOutVariableCallerBodyFunction( auto* foo = MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}}, "foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -940,7 +940,7 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -970,14 +970,14 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
auto* func = MakeInOutVariableBodyFunction( auto* func = MakeInOutVariableBodyFunction(
"func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, {}); "func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeCallerBodyFunction( auto* foo = MakeCallerBodyFunction(
"foo", "func", "foo", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1011,14 +1011,14 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto* bar = MakeInOutVariableBodyFunction( auto* bar = MakeInOutVariableBodyFunction(
"bar", {{"in2_var", "out_var"}}, "bar", {{"in2_var", "out_var"}},
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(bar); mod->Functions().Add(bar);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1057,21 +1057,21 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
auto* func = auto* func =
MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {}); MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {});
mod->AddFunction(func); mod->Functions().Add(func);
auto* foo = MakeInOutVariableCallerBodyFunction( auto* foo = MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}}, "foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto* bar = MakeCallerBodyFunction( auto* bar = MakeCallerBodyFunction(
"bar", "func", "bar", "func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(bar); mod->Functions().Add(bar);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1125,7 +1125,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) {
// TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
// through // through
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) { TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) {
mod->AddFunction(MakeEmptyBodyFunction("foo", {})); mod->Functions().Add(MakeEmptyBodyFunction("foo", {}));
auto result = inspector()->GetRemappedNameForEntryPoint("foo"); auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_TRUE(inspector()->has_error()); ASSERT_TRUE(inspector()->has_error());
@ -1140,7 +1140,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available. // TODO(dsinclair): Update to run the namer transform when available.
@ -1158,7 +1158,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available. // TODO(dsinclair): Update to run the namer transform when available.
@ -1166,7 +1166,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
"bar", ast::FunctionDecorationList{ "bar", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(bar); mod->Functions().Add(bar);
{ {
auto result = inspector()->GetRemappedNameForEntryPoint("foo"); auto result = inspector()->GetRemappedNameForEntryPoint("foo");
@ -1284,14 +1284,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "ub_func", "ep_func", "ub_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1312,14 +1312,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "ub_func", "ep_func", "ub_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1337,14 +1337,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "ub_func", "ep_func", "ub_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1366,14 +1366,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
auto* ub_func = MakeStructVariableReferenceBodyFunction( auto* ub_func = MakeStructVariableReferenceBodyFunction(
"ub_func", "foo_ub", {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}}); "ub_func", "foo_ub", {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "ub_func", "ep_func", "ub_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1399,7 +1399,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
const std::string& var_name) { const std::string& var_name) {
auto* ub_func = MakeStructVariableReferenceBodyFunction( auto* ub_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}}); func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
}; };
AddReferenceFunc("ub_foo_func", "ub_foo"); AddReferenceFunc("ub_foo_func", "ub_foo");
AddReferenceFunc("ub_bar_func", "ub_bar"); AddReferenceFunc("ub_bar_func", "ub_bar");
@ -1417,7 +1417,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1447,14 +1447,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(ub_func); mod->Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "ub_func", "ep_func", "ub_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1476,14 +1476,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1505,14 +1505,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
auto* sb_func = MakeStructVariableReferenceBodyFunction( auto* sb_func = MakeStructVariableReferenceBodyFunction(
"sb_func", "foo_sb", {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}}); "sb_func", "foo_sb", {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1538,7 +1538,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
const std::string& var_name) { const std::string& var_name) {
auto* sb_func = MakeStructVariableReferenceBodyFunction( auto* sb_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}}); func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
}; };
AddReferenceFunc("sb_foo_func", "sb_foo"); AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1559,7 +1559,7 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1589,14 +1589,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1618,14 +1618,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1647,14 +1647,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1672,14 +1672,14 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1707,7 +1707,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
const std::string& var_name) { const std::string& var_name) {
auto* sb_func = MakeStructVariableReferenceBodyFunction( auto* sb_func = MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}}); func_name, var_name, {{0, ty.i32}, {1, ty.u32}, {2, ty.f32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
}; };
AddReferenceFunc("sb_foo_func", "sb_foo"); AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1728,7 +1728,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1759,14 +1759,14 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1790,14 +1790,14 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1820,14 +1820,14 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32}}); {{0, ty.i32}});
mod->AddFunction(sb_func); mod->Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "sb_func", "ep_func", "sb_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1849,7 +1849,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1866,7 +1866,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {
"ep_func", ast::FunctionDecorationList{ "ep_func", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1885,14 +1885,14 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {
auto* foo_func = MakeSamplerReferenceBodyFunction( auto* foo_func = MakeSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32, {}); "foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32, {});
mod->AddFunction(foo_func); mod->Functions().Add(foo_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "foo_func", "ep_func", "foo_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1916,7 +1916,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1936,7 +1936,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1958,7 +1958,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1975,7 +1975,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {
"ep_func", ast::FunctionDecorationList{ "ep_func", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1995,14 +1995,14 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {
auto* foo_func = MakeComparisonSamplerReferenceBodyFunction( auto* foo_func = MakeComparisonSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", "foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth",
ty.f32, {}); ty.f32, {});
mod->AddFunction(foo_func); mod->Functions().Add(foo_func);
auto* ep_func = MakeCallerBodyFunction( auto* ep_func = MakeCallerBodyFunction(
"ep_func", "foo_func", "ep_func", "foo_func",
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(ep_func); mod->Functions().Add(ep_func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2026,7 +2026,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2046,7 +2046,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2061,7 +2061,7 @@ TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo"); auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -2084,7 +2084,7 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2175,7 +2175,7 @@ TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2246,7 +2246,7 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2301,7 +2301,7 @@ TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) {
"foo", ast::FunctionDecorationList{ "foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(foo); mod->Functions().Add(foo);
auto result = inspector()->GetSampledTextureResourceBindings("foo"); auto result = inspector()->GetSampledTextureResourceBindings("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
@ -2326,7 +2326,7 @@ TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();

View File

@ -859,7 +859,7 @@ bool FunctionEmitter::Emit() {
auto& statements = statements_stack_[0].GetStatements(); auto& statements = statements_stack_[0].GetStatements();
auto* body = create<ast::BlockStatement>(Source{}, statements); auto* body = create<ast::BlockStatement>(Source{}, statements);
ast_module_.AddFunction( ast_module_.Functions().Add(
create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name), create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name),
std::move(decl.params), decl.return_type, body, std::move(decl.params), decl.return_type, body,
std::move(decl.decorations))); std::move(decl.decorations)));

View File

@ -378,7 +378,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (func.errored) if (func.errored)
errored = true; errored = true;
if (func.matched) { if (func.matched) {
module_.AddFunction(func.value); module_.Functions().Add(func.value);
return true; return true;
} }

View File

@ -135,8 +135,8 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_module(); auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u); ASSERT_EQ(m.Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main"); EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) { TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
@ -145,8 +145,8 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_module(); auto& m = p->get_module();
ASSERT_EQ(m.functions().size(), 1u); ASSERT_EQ(m.Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.functions()[0]->symbol()), "main"); EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) { TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) {

View File

@ -15,8 +15,8 @@
#include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/type/i32_type.h"
#include "src/reader/wgsl/parser_impl_test_helper.h" #include "src/reader/wgsl/parser_impl_test_helper.h"
#include "src/type/i32_type.h"
namespace tint { namespace tint {
namespace reader { namespace reader {
@ -40,7 +40,7 @@ fn main() -> void {
ASSERT_TRUE(p->Parse()) << p->error(); ASSERT_TRUE(p->Parse()) << p->error();
auto& m = p->get_module(); auto& m = p->get_module();
ASSERT_EQ(1u, m.functions().size()); ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size()); ASSERT_EQ(1u, m.global_variables().size());
} }

View File

@ -42,7 +42,7 @@ fn main() -> void {
ASSERT_TRUE(p.Parse()) << p.error(); ASSERT_TRUE(p.Parse()) << p.error();
auto m = p.module(); auto m = p.module();
ASSERT_EQ(1u, m.functions().size()); ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size()); ASSERT_EQ(1u, m.global_variables().size());
} }

View File

@ -41,7 +41,7 @@ EmitVertexPointSize::~EmitVertexPointSize() = default;
Transform::Output EmitVertexPointSize::Run(ast::Module* in) { Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
Output out; Output out;
if (!in->HasStage(ast::PipelineStage::kVertex)) { if (!in->Functions().HasStage(ast::PipelineStage::kVertex)) {
// If the module doesn't have any vertex stages, then there's nothing to do. // If the module doesn't have any vertex stages, then there's nothing to do.
out.module = in->Clone(); out.module = in->Clone();
return out; return out;

View File

@ -85,8 +85,8 @@ Transform::Output VertexPulling::Run(ast::Module* in) {
} }
// Find entry point // Find entry point
auto* func = in->FindFunctionBySymbolAndStage( auto* func = in->Functions().Find(in->GetSymbol(cfg.entry_point_name),
in->GetSymbol(cfg.entry_point_name), ast::PipelineStage::kVertex); ast::PipelineStage::kVertex);
if (func == nullptr) { if (func == nullptr) {
diag::Diagnostic err; diag::Diagnostic err;
err.severity = diag::Severity::Error; err.severity = diag::Severity::Error;

View File

@ -115,13 +115,13 @@ bool TypeDeterminer::Determine() {
} }
} }
if (!DetermineFunctions(mod_->functions())) { if (!DetermineFunctions(mod_->Functions())) {
return false; return false;
} }
// Walk over the caller to callee information and update functions with which // Walk over the caller to callee information and update functions with which
// entry points call those functions. // entry points call those functions.
for (auto* func : mod_->functions()) { for (auto* func : mod_->Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -393,7 +393,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
caller_to_callee_[current_function_->symbol()].push_back( caller_to_callee_[current_function_->symbol()].push_back(
ident->symbol()); ident->symbol());
auto* callee_func = mod_->FindFunctionBySymbol(ident->symbol()); auto* callee_func = mod_->Functions().Find(ident->symbol());
if (callee_func == nullptr) { if (callee_func == nullptr) {
set_error(expr->source(), "unable to find called function: " + set_error(expr->source(), "unable to find called function: " +
mod_->SymbolToName(ident->symbol())); mod_->SymbolToName(ident->symbol()));

View File

@ -292,7 +292,7 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::VariableList params; ast::VariableList params;
auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -319,14 +319,14 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func_main); mod->Functions().Add(func_main);
auto* func = Func("func", params0, ty.f32, auto* func = Func("func", params0, ty.f32,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_FALSE(td()->Determine()) << td()->error(); EXPECT_FALSE(td()->Determine()) << td()->error();
EXPECT_EQ(td()->error(), EXPECT_EQ(td()->error(),
@ -471,7 +471,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
ast::VariableList params; ast::VariableList params;
auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -486,7 +486,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::VariableList params; ast::VariableList params;
auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -624,7 +624,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
auto* func = Func("my_func", ast::VariableList{}, ty.f32, auto* func = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -663,7 +663,7 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -700,7 +700,7 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
auto* func2 = Func( auto* func2 = Func(
"func", ast::VariableList{}, ty.f32, "func", ast::VariableList{}, ty.f32,
@ -709,7 +709,7 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func2); mod->Functions().Add(func2);
// Register the function // Register the function
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -734,7 +734,7 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
auto* v = Var("var", ast::StorageClass::kFunction, ty.f32); auto* v = Var("var", ast::StorageClass::kFunction, ty.f32);
td()->RegisterVariableForTesting(v); td()->RegisterVariableForTesting(v);
@ -1587,7 +1587,7 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
auto* func = Func("func", ast::VariableList{}, ty.i32, auto* func = Func("func", ast::VariableList{}, ty.i32,
ast::StatementList{stmt}, ast::FunctionDecorationList{}); ast::StatementList{stmt}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var->storage_class(), ast::StorageClass::kFunction); EXPECT_EQ(var->storage_class(), ast::StorageClass::kFunction);
@ -1599,7 +1599,7 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
auto* func = Func("func", ast::VariableList{}, ty.i32, auto* func = Func("func", ast::VariableList{}, ty.i32,
ast::StatementList{stmt}, ast::FunctionDecorationList{}); ast::StatementList{stmt}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var->storage_class(), ast::StorageClass::kNone); EXPECT_EQ(var->storage_class(), ast::StorageClass::kNone);
@ -1612,7 +1612,7 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
auto* func = Func("func", ast::VariableList{}, ty.i32, auto* func = Func("func", ast::VariableList{}, ty.i32,
ast::StatementList{stmt}, ast::FunctionDecorationList{}); ast::StatementList{stmt}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_FALSE(td()->Determine()); EXPECT_FALSE(td()->Determine());
EXPECT_EQ(td()->error(), EXPECT_EQ(td()->error(),
@ -2758,11 +2758,11 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func_b); mod->Functions().Add(func_b);
mod->AddFunction(func_c); mod->Functions().Add(func_c);
mod->AddFunction(func_a); mod->Functions().Add(func_a);
mod->AddFunction(ep_1); mod->Functions().Add(ep_1);
mod->AddFunction(ep_2); mod->Functions().Add(ep_2);
mod->AddGlobalVariable(Var("first", ast::StorageClass::kPrivate, ty.f32)); mod->AddGlobalVariable(Var("first", ast::StorageClass::kPrivate, ty.f32));
mod->AddGlobalVariable(Var("second", ast::StorageClass::kPrivate, ty.f32)); mod->AddGlobalVariable(Var("second", ast::StorageClass::kPrivate, ty.f32));

View File

@ -49,7 +49,7 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -68,7 +68,7 @@ TEST_F(ValidateFunctionTest,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -89,7 +89,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
create<ast::VariableDeclStatement>(var), create<ast::VariableDeclStatement>(var),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -105,7 +105,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
auto* func = auto* func =
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.i32, ast::StatementList{}, ast::FunctionDecorationList{}); ty.i32, ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -127,13 +127,13 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->DetermineFunctions(mod->functions())) << td()->error(); EXPECT_TRUE(td()->DetermineFunctions(mod->Functions())) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
EXPECT_TRUE(v.ValidateFunctions(mod->functions())) << v.error(); EXPECT_TRUE(v.ValidateFunctions(mod->Functions())) << v.error();
} }
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
@ -144,7 +144,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
Source{Source::Location{12, 34}}, Expr(2)), Source{Source::Location{12, 34}}, Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -165,7 +165,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
Source{Source::Location{12, 34}}, Expr(2)), Source{Source::Location{12, 34}}, Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -194,8 +194,8 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
mod->AddFunction(func_copy); mod->Functions().Add(func_copy);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -217,7 +217,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func0); mod->Functions().Add(func0);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -241,7 +241,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
create<ast::ReturnStatement>(Expr(2)), create<ast::ReturnStatement>(Expr(2)),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func0); mod->Functions().Add(func0);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -263,7 +263,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -288,7 +288,7 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -313,7 +313,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -335,7 +335,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -351,7 +351,7 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -71,10 +71,10 @@ bool ValidatorImpl::Validate() {
if (!ValidateConstructedTypes(module_.constructed_types())) { if (!ValidateConstructedTypes(module_.constructed_types())) {
return false; return false;
} }
if (!ValidateFunctions(module_.functions())) { if (!ValidateFunctions(module_.Functions())) {
return false; return false;
} }
if (!ValidateEntryPoint(module_.functions())) { if (!ValidateEntryPoint(module_.Functions())) {
return false; return false;
} }
function_stack_.pop_scope(); function_stack_.pop_scope();

View File

@ -392,7 +392,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
Source{Source::Location{12, 34}}, lhs, rhs), Source{Source::Location{12, 34}}, lhs, rhs),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -420,7 +420,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -578,7 +578,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error(); EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
@ -608,7 +608,7 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error(); EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
@ -707,8 +707,8 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func0); mod->Functions().Add(func0);
mod->AddFunction(func1); mod->Functions().Add(func1);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -172,7 +172,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
@ -197,7 +197,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
auto* main = auto* main =
Func("main", ast::VariableList{}, ty.void_, Func("main", ast::VariableList{}, ty.void_,
@ -207,7 +207,7 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(main); mod->Functions().Add(main);
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -160,7 +160,7 @@ bool GeneratorImpl::Generate(std::ostream& out) {
std::unordered_set<Symbol> emitted_globals; std::unordered_set<Symbol> emitted_globals;
// Make sure all entry point data is emitted before the entry point functions // Make sure all entry point data is emitted before the entry point functions
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -170,13 +170,13 @@ bool GeneratorImpl::Generate(std::ostream& out) {
} }
} }
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!EmitFunction(out, func)) { if (!EmitFunction(out, func)) {
return false; return false;
} }
} }
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -631,7 +631,7 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
name = it->second; name = it->second;
} }
auto* func = module_->FindFunctionBySymbol(ident->symbol()); auto* func = module_->Functions().Find(ident->symbol());
if (func == nullptr) { if (func == nullptr) {
error_ = error_ =
"Unable to find function: " + module_->SymbolToName(ident->symbol()); "Unable to find function: " + module_->SymbolToName(ident->symbol());

View File

@ -507,7 +507,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
auto* func = Func("foo", ast::VariableList{}, ty.void_, ast::StatementList{}, auto* func = Func("foo", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, params.push_back(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,

View File

@ -34,7 +34,7 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -60,7 +60,7 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -70,7 +70,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -123,7 +123,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -176,7 +176,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -229,7 +229,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -279,7 +279,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -324,7 +324,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -377,7 +377,7 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;

View File

@ -59,7 +59,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -80,7 +80,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -105,7 +105,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -128,7 +128,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -169,7 +169,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -221,7 +221,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -276,7 +276,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -325,7 +325,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -378,7 +378,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -431,7 +431,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -481,7 +481,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -528,7 +528,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -582,7 +582,7 @@ TEST_F(
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* func_1 = Func( auto* func_1 = Func(
"ep_1", ast::VariableList{}, ty.void_, "ep_1", ast::VariableList{}, ty.void_,
@ -594,7 +594,7 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -646,7 +646,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* func_1 = auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_, Func("ep_1", ast::VariableList{}, ty.void_,
@ -659,7 +659,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -715,7 +715,7 @@ TEST_F(
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* func_1 = auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_, Func("ep_1", ast::VariableList{}, ty.void_,
@ -728,7 +728,7 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -779,7 +779,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
Call("sub_func", 1.0f), ast::VariableDecorationList{}); Call("sub_func", 1.0f), ast::VariableDecorationList{});
@ -794,7 +794,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -839,7 +839,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
Call("sub_func", 1.0f), ast::VariableDecorationList{}); Call("sub_func", 1.0f), ast::VariableDecorationList{});
@ -854,7 +854,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -902,7 +902,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -933,7 +933,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -956,7 +956,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -983,7 +983,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::WorkgroupDecoration>(2u, 4u, 6u), create<ast::WorkgroupDecoration>(2u, 4u, 6u),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -1008,7 +1008,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -1071,7 +1071,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
{ {
@ -1088,7 +1088,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -30,7 +30,7 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) { TEST_F(HlslGeneratorImplTest, Generate) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -138,7 +138,7 @@ bool GeneratorImpl::Generate() {
} }
// Make sure all entry point data is emitted before the entry point functions // Make sure all entry point data is emitted before the entry point functions
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -148,13 +148,13 @@ bool GeneratorImpl::Generate() {
} }
} }
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!EmitFunction(func)) { if (!EmitFunction(func)) {
return false; return false;
} }
} }
for (auto* func : module_->functions()) { for (auto* func : module_->Functions()) {
if (!func->IsEntryPoint()) { if (!func->IsEntryPoint()) {
continue; continue;
} }
@ -525,7 +525,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
name = it->second; name = it->second;
} }
auto* func = module_->FindFunctionBySymbol(ident->symbol()); auto* func = module_->Functions().Find(ident->symbol());
if (func == nullptr) { if (func == nullptr) {
error_ = error_ =
"Unable to find function: " + module_->SymbolToName(ident->symbol()); "Unable to find function: " + module_->SymbolToName(ident->symbol());

View File

@ -35,7 +35,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
auto* call = Call("my_func"); auto* call = Call("my_func");
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -47,7 +47,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
auto* call = Call("my_func", "param1", "param2"); auto* call = Call("my_func", "param1", "param2");
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -59,7 +59,7 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
auto* call = Call("my_func", "param1", "param2"); auto* call = Call("my_func", "param1", "param2");
auto* func = Func("my_func", ast::VariableList{}, ty.void_, auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{}); ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
auto* expr = create<ast::CallStatement>(call); auto* expr = create<ast::CallStatement>(call);

View File

@ -71,7 +71,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -119,7 +119,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -167,7 +167,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -215,7 +215,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -260,7 +260,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -300,7 +300,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -345,7 +345,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -62,7 +62,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -85,7 +85,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -112,7 +112,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -134,7 +134,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_NoReturn_Void) {
ast::FunctionDecorationList{create<ast::StageDecoration>( ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kFragment)}); ast::PipelineStage::kFragment)});
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -174,7 +174,7 @@ TEST_F(MslGeneratorImplTest,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -223,7 +223,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
ast::FunctionDecorationList{create<ast::StageDecoration>( ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kFragment)}); ast::PipelineStage::kFragment)});
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -278,7 +278,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -323,7 +323,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -374,7 +374,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -428,7 +428,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -483,7 +483,7 @@ TEST_F(
auto* sub_func = auto* sub_func =
Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
@ -495,7 +495,7 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -547,7 +547,7 @@ TEST_F(MslGeneratorImplTest,
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
@ -560,7 +560,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -616,7 +616,7 @@ TEST_F(
auto* sub_func = auto* sub_func =
Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
@ -628,7 +628,7 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -674,7 +674,7 @@ TEST_F(MslGeneratorImplTest,
auto* sub_func = auto* sub_func =
Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
ast::ExpressionList expr; ast::ExpressionList expr;
expr.push_back(Expr(1.0f)); expr.push_back(Expr(1.0f));
@ -692,7 +692,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -741,7 +741,7 @@ TEST_F(MslGeneratorImplTest,
auto* sub_func = auto* sub_func =
Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
Call("sub_func", 1.0f), ast::VariableDecorationList{}); Call("sub_func", 1.0f), ast::VariableDecorationList{});
@ -756,7 +756,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -810,7 +810,7 @@ TEST_F(MslGeneratorImplTest,
auto* sub_func = auto* sub_func =
Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func); mod->Functions().Add(sub_func);
ast::ExpressionList expr; ast::ExpressionList expr;
expr.push_back(Expr(1.0f)); expr.push_back(Expr(1.0f));
@ -828,7 +828,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -881,7 +881,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(func_1); mod->Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
@ -914,7 +914,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -938,7 +938,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
}, },
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -1004,7 +1004,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
{ {
@ -1018,7 +1018,7 @@ TEST_F(MslGeneratorImplTest,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute)}); create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
mod->AddFunction(func); mod->Functions().Add(func);
} }
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -53,7 +53,7 @@ TEST_F(MslGeneratorImplTest, Generate) {
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -302,7 +302,7 @@ bool Builder::Build() {
} }
} }
for (auto* func : mod_->functions()) { for (auto* func : mod_->Functions()) {
if (!GenerateFunction(func)) { if (!GenerateFunction(func)) {
return false; return false;
} }

View File

@ -261,7 +261,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
{ {
@ -278,7 +278,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -4165,7 +4165,7 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod->AddFunction(main); mod->Functions().Add(main);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -101,7 +101,7 @@ bool GeneratorImpl::Generate() {
out_ << std::endl; out_ << std::endl;
} }
for (auto* func : module_.functions()) { for (auto* func : module_.Functions()) {
if (!EmitFunction(func)) { if (!EmitFunction(func)) {
return false; return false;
} }
@ -113,8 +113,7 @@ bool GeneratorImpl::Generate() {
bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
const std::string& name) { const std::string& name) {
auto* func = auto* func = module_.Functions().Find(module_.GetSymbol(name), stage);
module_.FindFunctionBySymbolAndStage(module_.GetSymbol(name), stage);
if (func == nullptr) { if (func == nullptr) {
error_ = "Unable to find requested entry point: " + name; error_ = "Unable to find requested entry point: " + name;
return false; return false;
@ -153,7 +152,7 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
out_ << std::endl; out_ << std::endl;
} }
for (auto* f : module_.functions()) { for (auto* f : module_.Functions()) {
if (!f->HasAncestorEntryPoint(module_.GetSymbol(name))) { if (!f->HasAncestorEntryPoint(module_.GetSymbol(name))) {
continue; continue;
} }

View File

@ -212,7 +212,7 @@ TEST_F(WgslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
{ {
@ -231,7 +231,7 @@ TEST_F(WgslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod->AddFunction(func); mod->Functions().Add(func);
} }
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -30,8 +30,9 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Generate) { TEST_F(WgslGeneratorImplTest, Generate) {
mod->AddFunction(Func("my_func", ast::VariableList{}, ty.void_, mod->Functions().Add(Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{}, ast::FunctionDecorationList{})); ast::StatementList{},
ast::FunctionDecorationList{}));
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();