Program: Remove deprecated global variable methods

Fixup all usages

Bug: tint:390
Change-Id: I2e239dfc77872acb9f0b2ee5494350605dd780a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38545
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-26 16:57:10 +00:00
parent a07396a13c
commit a86f4effe4
31 changed files with 252 additions and 256 deletions

View File

@ -106,7 +106,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
std::map<uint32_t, Scalar> Inspector::GetConstantIDs() { std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
std::map<uint32_t, Scalar> result; std::map<uint32_t, Scalar> result;
for (auto* var : program_.global_variables()) { for (auto* var : program_.AST().GlobalVariables()) {
if (!var->HasConstantIdDecoration()) { if (!var->HasConstantIdDecoration()) {
continue; continue;
} }

View File

@ -114,11 +114,11 @@ class InspectorHelper : public ast::BuilderWithProgram {
std::string in, out; std::string in, out;
std::tie(in, out) = inout; std::tie(in, out) = inout;
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var(in, ast::StorageClass::kInput, ty.u32, nullptr, Var(in, ast::StorageClass::kInput, ty.u32, nullptr,
ast::VariableDecorationList{ ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)})); create<ast::LocationDecoration>(location++)}));
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var(out, ast::StorageClass::kOutput, ty.u32, nullptr, Var(out, ast::StorageClass::kOutput, ty.u32, nullptr,
ast::VariableDecorationList{ ast::VariableDecorationList{
create<ast::LocationDecoration>(location++)})); create<ast::LocationDecoration>(location++)}));
@ -187,7 +187,7 @@ class InspectorHelper : public ast::BuilderWithProgram {
ast::VariableDecorationList{ ast::VariableDecorationList{
create<ast::ConstantIdDecoration>(id), create<ast::ConstantIdDecoration>(id),
}); });
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
} }
/// @param type AST type of the literal, must resolve to BoolLiteral /// @param type AST type of the literal, must resolve to BoolLiteral
@ -334,7 +334,7 @@ class InspectorHelper : public ast::BuilderWithProgram {
create<ast::GroupDecoration>(group), create<ast::GroupDecoration>(group),
}); });
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
} }
/// Adds an uniform buffer variable to the program /// Adds an uniform buffer variable to the program
@ -469,7 +469,7 @@ class InspectorHelper : public ast::BuilderWithProgram {
} }
void AddGlobalVariable(const std::string& name, type::Type* type) { void AddGlobalVariable(const std::string& name, type::Type* type) {
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type)); Var(name, ast::StorageClass::kUniformConstant, type));
} }
@ -477,7 +477,7 @@ class InspectorHelper : public ast::BuilderWithProgram {
/// @param name the name of the variable /// @param name the name of the variable
/// @param type the type to use /// @param type the type to use
void AddDepthTexture(const std::string& name, type::Type* type) { void AddDepthTexture(const std::string& name, type::Type* type) {
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var(name, ast::StorageClass::kUniformConstant, type)); Var(name, ast::StorageClass::kUniformConstant, type));
} }
@ -1114,11 +1114,11 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
} }
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var("in_var", ast::StorageClass::kInput, ty.u32, nullptr, Var("in_var", ast::StorageClass::kInput, ty.u32, nullptr,
ast::VariableDecorationList{ ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)})); create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}));
mod->AddGlobalVariable( mod->AST().AddGlobalVariable(
Var("out_var", ast::StorageClass::kOutput, ty.u32, nullptr, Var("out_var", ast::StorageClass::kOutput, ty.u32, nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)})); ast::VariableDecorationList{create<ast::LocationDecoration>(0)}));
auto* func = auto* func =

View File

@ -118,21 +118,6 @@ class Program {
return types_.Get<T>(std::forward<ARGS>(args)...); return types_.Get<T>(std::forward<ARGS>(args)...);
} }
/// Add a global variable to the program
/// [DEPRECATED]: Use AST().AddGlobalVariable(var)
/// @param var the variable to add
void AddGlobalVariable(ast::Variable* var) { AST().AddGlobalVariable(var); }
/// [DEPRECATED]: Use AST().GlobalVariables()
/// @returns the global variables for the program
const ast::VariableList& global_variables() const {
return AST().GlobalVariables();
}
/// [DEPRECATED]: Use AST().GlobalVariables()
/// @returns the global variables for the program
ast::VariableList& global_variables() { return AST().GlobalVariables(); }
/// Adds a constructed type to the program. /// Adds a constructed type to the program.
/// The type must be an alias or a struct. /// The type must be an alias or a struct.
/// [DEPRECATED]: Use AST().AddConstructedType(type) /// [DEPRECATED]: Use AST().AddConstructedType(type)

View File

@ -46,18 +46,18 @@ TEST_F(ProgramTest, IsValid_Empty) {
TEST_F(ProgramTest, IsValid_GlobalVariable) { TEST_F(ProgramTest, IsValid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, ty.f32); auto* var = Var("var", ast::StorageClass::kInput, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(mod->IsValid()); EXPECT_TRUE(mod->IsValid());
} }
TEST_F(ProgramTest, IsValid_Null_GlobalVariable) { TEST_F(ProgramTest, IsValid_Null_GlobalVariable) {
mod->AddGlobalVariable(nullptr); mod->AST().AddGlobalVariable(nullptr);
EXPECT_FALSE(mod->IsValid()); EXPECT_FALSE(mod->IsValid());
} }
TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) { TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) {
auto* var = Var("var", ast::StorageClass::kInput, nullptr); auto* var = Var("var", ast::StorageClass::kInput, nullptr);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_FALSE(mod->IsValid()); EXPECT_FALSE(mod->IsValid());
} }

View File

@ -1091,7 +1091,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
MakeVariable(inst.result_id(), ast::StorageClass::kNone, ast_type, MakeVariable(inst.result_id(), ast::StorageClass::kNone, ast_type,
true, ast_expr, std::move(spec_id_decos)); true, ast_expr, std::move(spec_id_decos));
if (ast_var) { if (ast_var) {
program_.AddGlobalVariable(ast_var); program_.AST().AddGlobalVariable(ast_var);
scalar_spec_constants_.insert(inst.result_id()); scalar_spec_constants_.insert(inst.result_id());
} }
} }
@ -1209,7 +1209,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
ast_constructor, ast::VariableDecorationList{}); ast_constructor, ast::VariableDecorationList{});
// TODO(dneto): initializers (a.k.a. constructor expression) // TODO(dneto): initializers (a.k.a. constructor expression)
if (ast_var) { if (ast_var) {
program_.AddGlobalVariable(ast_var); program_.AST().AddGlobalVariable(ast_var);
} }
} }
@ -1226,7 +1226,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition), create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition),
}); });
program_.AddGlobalVariable(var); program_.AST().AddGlobalVariable(var);
} }
return success_; return success_;
} }

View File

@ -323,7 +323,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("variable declaration", Token::Type::kSemicolon)) if (!expect("variable declaration", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
program_.AddGlobalVariable(gv.value); program_.AST().AddGlobalVariable(gv.value);
return true; return true;
} }
@ -335,7 +335,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("constant declaration", Token::Type::kSemicolon)) if (!expect("constant declaration", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
program_.AddGlobalVariable(gc.value); program_.AST().AddGlobalVariable(gc.value);
return true; return true;
} }

View File

@ -35,9 +35,9 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(m.global_variables().size(), 1u); ASSERT_EQ(m.AST().GlobalVariables().size(), 1u);
auto* v = m.global_variables()[0]; auto* v = m.AST().GlobalVariables()[0];
EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a"));
} }
@ -61,9 +61,9 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConstant) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(m.global_variables().size(), 1u); ASSERT_EQ(m.AST().GlobalVariables().size(), 1u);
auto* v = m.global_variables()[0]; auto* v = m.AST().GlobalVariables()[0];
EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a"));
} }

View File

@ -41,7 +41,7 @@ fn main() -> void {
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(1u, m.Functions().size()); ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size()); ASSERT_EQ(1u, m.AST().GlobalVariables().size());
} }
TEST_F(ParserImplTest, HandlesError) { TEST_F(ParserImplTest, HandlesError) {

View File

@ -43,7 +43,7 @@ fn main() -> void {
auto m = p.program(); auto m = p.program();
ASSERT_EQ(1u, m.Functions().size()); ASSERT_EQ(1u, m.Functions().size());
ASSERT_EQ(1u, m.global_variables().size()); ASSERT_EQ(1u, m.AST().GlobalVariables().size());
} }
TEST_F(ParserTest, HandlesError) { TEST_F(ParserTest, HandlesError) {

View File

@ -62,7 +62,7 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
out.program.create<ast::BuiltinDecoration>(Source{}, out.program.create<ast::BuiltinDecoration>(Source{},
ast::Builtin::kPointSize), ast::Builtin::kPointSize),
}); });
out.program.AddGlobalVariable(pointsize_var); out.program.AST().AddGlobalVariable(pointsize_var);
// Build the AST expression & statement for assigning pointsize one. // Build the AST expression & statement for assigning pointsize one.
auto* one = out.program.create<ast::ScalarConstructorExpression>( auto* one = out.program.create<ast::ScalarConstructorExpression>(

View File

@ -83,7 +83,7 @@ FirstIndexOffset::~FirstIndexOffset() = default;
Transform::Output FirstIndexOffset::Run(const Program* in) { Transform::Output FirstIndexOffset::Run(const Program* in) {
// First do a quick check to see if the transform has already been applied. // First do a quick check to see if the transform has already been applied.
for (ast::Variable* var : in->global_variables()) { for (ast::Variable* var : in->AST().GlobalVariables()) {
if (auto* dec_var = var->As<ast::Variable>()) { if (auto* dec_var = var->As<ast::Variable>()) {
if (dec_var->symbol() == in->GetSymbol(kBufferName)) { if (dec_var->symbol() == in->GetSymbol(kBufferName)) {
diag::Diagnostic err; diag::Diagnostic err;
@ -240,7 +240,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) {
dst->create<ast::GroupDecoration>(Source{}, group_), dst->create<ast::GroupDecoration>(Source{}, group_),
}); // decorations }); // decorations
dst->AddGlobalVariable(idx_var); dst->AST().AddGlobalVariable(idx_var);
dst->AddConstructedType(struct_type); dst->AddConstructedType(struct_type);

View File

@ -150,7 +150,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
} }
// Look for an existing vertex index builtin // Look for an existing vertex index builtin
for (auto* v : in->global_variables()) { for (auto* v : in->AST().GlobalVariables()) {
if (v->storage_class() != ast::StorageClass::kInput) { if (v->storage_class() != ast::StorageClass::kInput) {
continue; continue;
} }
@ -181,7 +181,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
ast::Builtin::kVertexIndex), ast::Builtin::kVertexIndex),
}); });
out->AddGlobalVariable(var); out->AST().AddGlobalVariable(var);
} }
void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() { void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
@ -197,7 +197,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
} }
// Look for an existing instance index builtin // Look for an existing instance index builtin
for (auto* v : in->global_variables()) { for (auto* v : in->AST().GlobalVariables()) {
if (v->storage_class() != ast::StorageClass::kInput) { if (v->storage_class() != ast::StorageClass::kInput) {
continue; continue;
} }
@ -227,12 +227,12 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
out->create<ast::BuiltinDecoration>(Source{}, out->create<ast::BuiltinDecoration>(Source{},
ast::Builtin::kInstanceIndex), ast::Builtin::kInstanceIndex),
}); });
out->AddGlobalVariable(var); out->AST().AddGlobalVariable(var);
} }
void VertexPulling::State::ConvertVertexInputVariablesToPrivate() { void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
// TODO(https://crbug.com/tint/390): Remove this const_cast hack! // TODO(https://crbug.com/tint/390): Remove this const_cast hack!
for (auto*& v : const_cast<Program*>(in)->global_variables()) { for (auto*& v : const_cast<Program*>(in)->AST().GlobalVariables()) {
if (v->storage_class() != ast::StorageClass::kInput) { if (v->storage_class() != ast::StorageClass::kInput) {
continue; continue;
} }
@ -299,7 +299,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
out->create<ast::BindingDecoration>(Source{}, i), out->create<ast::BindingDecoration>(Source{}, i),
out->create<ast::GroupDecoration>(Source{}, cfg.pulling_group), out->create<ast::GroupDecoration>(Source{}, cfg.pulling_group),
}); });
out->AddGlobalVariable(var); out->AST().AddGlobalVariable(var);
} }
out->AddConstructedType(struct_type); out->AddConstructedType(struct_type);
} }

View File

@ -116,7 +116,7 @@ bool TypeDeterminer::Determine() {
} }
} }
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
variable_stack_.set_global(var->symbol(), var); variable_stack_.set_global(var->symbol(), var);
if (var->has_constructor()) { if (var->has_constructor()) {

View File

@ -350,7 +350,7 @@ TEST_F(TypeDeterminerTest, Stmt_VariableDecl_ModuleScope) {
ast::VariableDecorationList{}); ast::VariableDecorationList{});
auto* init = var->constructor(); auto* init = var->constructor();
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
ASSERT_NE(init->result_type(), nullptr); ASSERT_NE(init->result_type(), nullptr);
@ -367,7 +367,7 @@ TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
auto* idx = Expr(2); auto* idx = Expr(2);
auto* var = Var("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>()); auto* var = Var("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -383,7 +383,8 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
auto* aary = ty.alias("myarrty", ty.array<f32, 3>()); auto* aary = ty.alias("myarrty", ty.array<f32, 3>());
mod->AddGlobalVariable(Var("my_var", ast::StorageClass::kFunction, aary)); mod->AST().AddGlobalVariable(
Var("my_var", ast::StorageClass::kFunction, aary));
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -398,7 +399,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
auto* var = Const("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>()); auto* var = Const("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -411,7 +412,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -427,7 +428,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -443,7 +444,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) { TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -540,7 +541,7 @@ TEST_F(TypeDeterminerTest, Expr_Constructor_Type) {
TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) { TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32); auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -553,7 +554,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) {
} }
TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) { TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalConstant) {
mod->AddGlobalVariable(Const("my_var", ast::StorageClass::kNone, ty.f32)); mod->AST().AddGlobalVariable(
Const("my_var", ast::StorageClass::kNone, ty.f32));
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -647,11 +649,11 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
auto* wg_var = Var("wg_var", ast::StorageClass::kWorkgroup, ty.f32); auto* wg_var = Var("wg_var", ast::StorageClass::kWorkgroup, ty.f32);
auto* priv_var = Var("priv_var", ast::StorageClass::kPrivate, ty.f32); auto* priv_var = Var("priv_var", ast::StorageClass::kPrivate, ty.f32);
mod->AddGlobalVariable(in_var); mod->AST().AddGlobalVariable(in_var);
mod->AddGlobalVariable(out_var); mod->AST().AddGlobalVariable(out_var);
mod->AddGlobalVariable(sb_var); mod->AST().AddGlobalVariable(sb_var);
mod->AddGlobalVariable(wg_var); mod->AST().AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var); mod->AST().AddGlobalVariable(priv_var);
auto* func = Func( auto* func = Func(
"my_func", ast::VariableList{}, ty.f32, "my_func", ast::VariableList{}, ty.f32,
@ -684,11 +686,11 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
auto* wg_var = Var("wg_var", ast::StorageClass::kWorkgroup, ty.f32); auto* wg_var = Var("wg_var", ast::StorageClass::kWorkgroup, ty.f32);
auto* priv_var = Var("priv_var", ast::StorageClass::kPrivate, ty.f32); auto* priv_var = Var("priv_var", ast::StorageClass::kPrivate, ty.f32);
mod->AddGlobalVariable(in_var); mod->AST().AddGlobalVariable(in_var);
mod->AddGlobalVariable(out_var); mod->AST().AddGlobalVariable(out_var);
mod->AddGlobalVariable(sb_var); mod->AST().AddGlobalVariable(sb_var);
mod->AddGlobalVariable(wg_var); mod->AST().AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var); mod->AST().AddGlobalVariable(priv_var);
auto* func = Func( auto* func = Func(
"my_func", ast::VariableList{}, ty.f32, "my_func", ast::VariableList{}, ty.f32,
@ -754,7 +756,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) {
auto* st = ty.struct_("S", strct); auto* st = ty.struct_("S", strct);
auto* var = Var("my_struct", ast::StorageClass::kNone, st); auto* var = Var("my_struct", ast::StorageClass::kNone, st);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -777,7 +779,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) {
auto* alias = ty.alias("alias", st); auto* alias = ty.alias("alias", st);
auto* var = Var("my_struct", ast::StorageClass::kNone, alias); auto* var = Var("my_struct", ast::StorageClass::kNone, alias);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -792,7 +794,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct_Alias) {
TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) { TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) {
auto* var = Var("my_vec", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("my_vec", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -806,7 +808,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) {
TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) { TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
auto* var = Var("my_vec", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("my_vec", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -856,7 +858,7 @@ TEST_F(TypeDeterminerTest, Expr_Accessor_MultiLevel) {
auto* stA = ty.struct_("A", strctA); auto* stA = ty.struct_("A", strctA);
auto* var = Var("c", ast::StorageClass::kNone, stA); auto* var = Var("c", ast::StorageClass::kNone, stA);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
auto* mem = MemberAccessor( auto* mem = MemberAccessor(
@ -876,7 +878,7 @@ TEST_P(Expr_Binary_BitwiseTest, Scalar) {
auto* var = Var("val", ast::StorageClass::kNone, ty.i32); auto* var = Var("val", ast::StorageClass::kNone, ty.i32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -892,7 +894,7 @@ TEST_P(Expr_Binary_BitwiseTest, Vector) {
auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<i32>()); auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<i32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -922,7 +924,7 @@ TEST_P(Expr_Binary_LogicalTest, Scalar) {
auto* var = Var("val", ast::StorageClass::kNone, ty.bool_); auto* var = Var("val", ast::StorageClass::kNone, ty.bool_);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -938,7 +940,7 @@ TEST_P(Expr_Binary_LogicalTest, Vector) {
auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<bool>()); auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<bool>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -962,7 +964,7 @@ TEST_P(Expr_Binary_CompareTest, Scalar) {
auto* var = Var("val", ast::StorageClass::kNone, ty.i32); auto* var = Var("val", ast::StorageClass::kNone, ty.i32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -978,7 +980,7 @@ TEST_P(Expr_Binary_CompareTest, Vector) {
auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<i32>()); auto* var = Var("val", ast::StorageClass::kNone, ty.vec3<i32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1003,7 +1005,7 @@ INSTANTIATE_TEST_SUITE_P(TypeDeterminerTest,
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) {
auto* var = Var("val", ast::StorageClass::kNone, ty.i32); auto* var = Var("val", ast::StorageClass::kNone, ty.i32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1017,8 +1019,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) {
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32); auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>()); auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(scalar); mod->AST().AddGlobalVariable(scalar);
mod->AddGlobalVariable(vector); mod->AST().AddGlobalVariable(vector);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1034,8 +1036,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) {
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32); auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>()); auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(scalar); mod->AST().AddGlobalVariable(scalar);
mod->AddGlobalVariable(vector); mod->AST().AddGlobalVariable(vector);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1050,7 +1052,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) {
auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>()); auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(vector); mod->AST().AddGlobalVariable(vector);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1066,8 +1068,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32); auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(scalar); mod->AST().AddGlobalVariable(scalar);
mod->AddGlobalVariable(matrix); mod->AST().AddGlobalVariable(matrix);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1086,8 +1088,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32); auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(scalar); mod->AST().AddGlobalVariable(scalar);
mod->AddGlobalVariable(matrix); mod->AST().AddGlobalVariable(matrix);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1106,8 +1108,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) {
auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>()); auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>());
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(vector); mod->AST().AddGlobalVariable(vector);
mod->AddGlobalVariable(matrix); mod->AST().AddGlobalVariable(matrix);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1123,8 +1125,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) {
auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>()); auto* vector = Var("vector", ast::StorageClass::kNone, ty.vec3<f32>());
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>()); auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
mod->AddGlobalVariable(vector); mod->AST().AddGlobalVariable(vector);
mod->AddGlobalVariable(matrix); mod->AST().AddGlobalVariable(matrix);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1140,8 +1142,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) {
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) { TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) {
auto* matrix1 = Var("mat3x4", ast::StorageClass::kNone, ty.mat3x4<f32>()); auto* matrix1 = Var("mat3x4", ast::StorageClass::kNone, ty.mat3x4<f32>());
auto* matrix2 = Var("mat4x3", ast::StorageClass::kNone, ty.mat4x3<f32>()); auto* matrix2 = Var("mat4x3", ast::StorageClass::kNone, ty.mat4x3<f32>());
mod->AddGlobalVariable(matrix1); mod->AST().AddGlobalVariable(matrix1);
mod->AddGlobalVariable(matrix2); mod->AST().AddGlobalVariable(matrix2);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -1163,7 +1165,7 @@ TEST_P(IntrinsicDerivativeTest, Scalar) {
auto* var = Var("ident", ast::StorageClass::kNone, ty.f32); auto* var = Var("ident", ast::StorageClass::kNone, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -1179,7 +1181,7 @@ TEST_P(IntrinsicDerivativeTest, Vector) {
auto* var = Var("ident", ast::StorageClass::kNone, ty.vec4<f32>()); auto* var = Var("ident", ast::StorageClass::kNone, ty.vec4<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -1207,8 +1209,8 @@ TEST_P(IntrinsicDerivativeTest, ToomManyParams) {
auto* var1 = Var("ident1", ast::StorageClass::kNone, ty.vec4<f32>()); auto* var1 = Var("ident1", ast::StorageClass::kNone, ty.vec4<f32>());
auto* var2 = Var("ident2", ast::StorageClass::kNone, ty.vec4<f32>()); auto* var2 = Var("ident2", ast::StorageClass::kNone, ty.vec4<f32>());
mod->AddGlobalVariable(var1); mod->AST().AddGlobalVariable(var1);
mod->AddGlobalVariable(var2); mod->AST().AddGlobalVariable(var2);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -1234,7 +1236,7 @@ TEST_P(Intrinsic, Test) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<bool>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<bool>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call(name, "my_var"); auto* expr = Call(name, "my_var");
@ -1255,7 +1257,7 @@ TEST_P(Intrinsic_FloatMethod, Vector) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call(name, "my_var"); auto* expr = Call(name, "my_var");
@ -1275,7 +1277,7 @@ TEST_P(Intrinsic_FloatMethod, Scalar) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32); auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call(name, "my_var"); auto* expr = Call(name, "my_var");
@ -1291,7 +1293,7 @@ TEST_P(Intrinsic_FloatMethod, MissingParam) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32); auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call(name); auto* expr = Call(name);
@ -1306,7 +1308,7 @@ TEST_P(Intrinsic_FloatMethod, TooManyParams) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32); auto* var = Var("my_var", ast::StorageClass::kNone, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call(name, "my_var", "my_var"); auto* expr = Call(name, "my_var", "my_var");
@ -1368,7 +1370,7 @@ class Intrinsic_TextureOperation
type::Type* type, type::Type* type,
ast::ExpressionList* call_params) { ast::ExpressionList* call_params) {
auto* var = Var(name, ast::StorageClass::kNone, type); auto* var = Var(name, ast::StorageClass::kNone, type);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
call_params->push_back(Expr(name)); call_params->push_back(Expr(name));
} }
@ -1500,7 +1502,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_F(TypeDeterminerTest, Intrinsic_Dot) { TEST_F(TypeDeterminerTest, Intrinsic_Dot) {
auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("my_var", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call("dot", "my_var", "my_var"); auto* expr = Call("dot", "my_var", "my_var");
@ -1516,8 +1518,8 @@ TEST_F(TypeDeterminerTest, Intrinsic_Select) {
auto* bool_var = Var( // source auto* bool_var = Var( // source
"bool_var", ast::StorageClass::kNone, ty.vec3<bool>()); "bool_var", ast::StorageClass::kNone, ty.vec3<bool>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
mod->AddGlobalVariable(bool_var); mod->AST().AddGlobalVariable(bool_var);
auto* expr = Call("select", "my_var", "my_var", "bool_var"); auto* expr = Call("select", "my_var", "my_var", "bool_var");
@ -1533,7 +1535,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_Select) {
TEST_F(TypeDeterminerTest, Intrinsic_Select_TooFewParams) { TEST_F(TypeDeterminerTest, Intrinsic_Select_TooFewParams) {
auto* var = Var("v", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("v", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call("select", "v"); auto* expr = Call("select", "v");
@ -1547,7 +1549,7 @@ TEST_F(TypeDeterminerTest, Intrinsic_Select_TooFewParams) {
TEST_F(TypeDeterminerTest, Intrinsic_Select_TooManyParams) { TEST_F(TypeDeterminerTest, Intrinsic_Select_TooManyParams) {
auto* var = Var("v", ast::StorageClass::kNone, ty.vec3<f32>()); auto* var = Var("v", ast::StorageClass::kNone, ty.vec3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call("select", "v", "v", "v", "v"); auto* expr = Call("select", "v", "v", "v", "v");
@ -1564,7 +1566,7 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
auto* var = Var("ident", ast::StorageClass::kNone, ty.vec4<f32>()); auto* var = Var("ident", ast::StorageClass::kNone, ty.vec4<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
EXPECT_TRUE(td()->Determine()); EXPECT_TRUE(td()->Determine());
@ -2650,7 +2652,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant) { TEST_F(TypeDeterminerTest, ImportData_GLSL_Determinant) {
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>()); auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2669,7 +2671,7 @@ TEST_P(ImportData_Matrix_OneParam_Test, Error_Float) {
auto param = GetParam(); auto param = GetParam();
auto* var = Var("var", ast::StorageClass::kFunction, ty.f32); auto* var = Var("var", ast::StorageClass::kFunction, ty.f32);
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2694,7 +2696,7 @@ TEST_P(ImportData_Matrix_OneParam_Test, TooManyParams) {
auto param = GetParam(); auto param = GetParam();
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>()); auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
@ -2764,11 +2766,16 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
mod->Functions().Add(ep_1); mod->Functions().Add(ep_1);
mod->Functions().Add(ep_2); mod->Functions().Add(ep_2);
mod->AddGlobalVariable(Var("first", ast::StorageClass::kPrivate, ty.f32)); mod->AST().AddGlobalVariable(
mod->AddGlobalVariable(Var("second", ast::StorageClass::kPrivate, ty.f32)); Var("first", ast::StorageClass::kPrivate, ty.f32));
mod->AddGlobalVariable(Var("call_a", ast::StorageClass::kPrivate, ty.f32)); mod->AST().AddGlobalVariable(
mod->AddGlobalVariable(Var("call_b", ast::StorageClass::kPrivate, ty.f32)); Var("second", ast::StorageClass::kPrivate, ty.f32));
mod->AddGlobalVariable(Var("call_c", ast::StorageClass::kPrivate, ty.f32)); mod->AST().AddGlobalVariable(
Var("call_a", ast::StorageClass::kPrivate, ty.f32));
mod->AST().AddGlobalVariable(
Var("call_b", ast::StorageClass::kPrivate, ty.f32));
mod->AST().AddGlobalVariable(
Var("call_c", ast::StorageClass::kPrivate, ty.f32));
// Register the functions and calculate the callers // Register the functions and calculate the callers
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();

View File

@ -65,7 +65,7 @@ void ValidatorImpl::add_error(const Source& src, const std::string& msg) {
bool ValidatorImpl::Validate() { bool ValidatorImpl::Validate() {
function_stack_.push_scope(); function_stack_.push_scope();
if (!ValidateGlobalVariables(program_->global_variables())) { if (!ValidateGlobalVariables(program_->AST().GlobalVariables())) {
return false; return false;
} }
if (!ValidateConstructedTypes(program_->constructed_types())) { if (!ValidateConstructedTypes(program_->constructed_types())) {

View File

@ -324,20 +324,21 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) { TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
// var<in> gloabl_var: f32; // var<in> gloabl_var: f32;
mod->AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var", mod->AST().AddGlobalVariable(Var(
ast::StorageClass::kInput, ty.f32, nullptr, Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
ast::VariableDecorationList{})); ty.f32, nullptr, ast::VariableDecorationList{}));
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
EXPECT_TRUE(v.ValidateGlobalVariables(mod->global_variables())) << v.error(); EXPECT_TRUE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()))
<< v.error();
} }
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) { TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
// var gloabl_var: f32; // var gloabl_var: f32;
mod->AddGlobalVariable(Var(Source{Source::Location{12, 34}}, "global_var", mod->AST().AddGlobalVariable(Var(
ast::StorageClass::kNone, ty.f32, nullptr, Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
ast::VariableDecorationList{})); ty.f32, nullptr, ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -349,9 +350,9 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) { TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
// const<in> gloabl_var: f32; // const<in> gloabl_var: f32;
mod->AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var", mod->AST().AddGlobalVariable(Const(
ast::StorageClass::kInput, ty.f32, nullptr, Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kInput,
ast::VariableDecorationList{})); ty.f32, nullptr, ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -364,9 +365,9 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) { TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
// const gloabl_var: f32; // const gloabl_var: f32;
mod->AddGlobalVariable(Const(Source{Source::Location{12, 34}}, "global_var", mod->AST().AddGlobalVariable(Const(
ast::StorageClass::kNone, ty.f32, nullptr, Source{Source::Location{12, 34}}, "global_var", ast::StorageClass::kNone,
ast::VariableDecorationList{})); ty.f32, nullptr, ast::VariableDecorationList{}));
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
@ -379,8 +380,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
// fn my_func() -> f32 { // fn my_func() -> f32 {
// not_global_var = 3.14f; // not_global_var = 3.14f;
// } // }
mod->AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate, ty.f32, mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
Expr(2.1f), ast::VariableDecorationList{})); ty.f32, Expr(2.1f),
ast::VariableDecorationList{}));
SetSource(Source{Source::Location{12, 34}}); SetSource(Source{Source::Location{12, 34}});
auto* lhs = Expr("not_global_var"); auto* lhs = Expr("not_global_var");
@ -407,8 +409,9 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
// return; // return;
// } // }
mod->AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate, ty.f32, mod->AST().AddGlobalVariable(Var("global_var", ast::StorageClass::kPrivate,
Expr(2.1f), ast::VariableDecorationList{})); ty.f32, Expr(2.1f),
ast::VariableDecorationList{}));
auto* func = Func( auto* func = Func(
"my_func", ast::VariableList{}, ty.void_, "my_func", ast::VariableList{}, ty.void_,
@ -499,16 +502,17 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
// var global_var1 : i32 = 0; // var global_var1 : i32 = 0;
auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32, auto* var0 = Var("global_var0", ast::StorageClass::kPrivate, ty.f32,
Expr(0.1f), ast::VariableDecorationList{}); Expr(0.1f), ast::VariableDecorationList{});
mod->AddGlobalVariable(var0); mod->AST().AddGlobalVariable(var0);
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1", auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var1",
ast::StorageClass::kPrivate, ty.f32, Expr(0), ast::StorageClass::kPrivate, ty.f32, Expr(0),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
mod->AddGlobalVariable(var1); mod->AST().AddGlobalVariable(var1);
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
EXPECT_TRUE(v.ValidateGlobalVariables(mod->global_variables())) << v.error(); EXPECT_TRUE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()))
<< v.error();
} }
TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) { TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
@ -516,16 +520,16 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
// var global_var : i32 = 0; // var global_var : i32 = 0;
auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32, auto* var0 = Var("global_var", ast::StorageClass::kPrivate, ty.f32,
Expr(0.1f), ast::VariableDecorationList{}); Expr(0.1f), ast::VariableDecorationList{});
mod->AddGlobalVariable(var0); mod->AST().AddGlobalVariable(var0);
auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var", auto* var1 = Var(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kPrivate, ty.i32, Expr(0), ast::StorageClass::kPrivate, ty.i32, Expr(0),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
mod->AddGlobalVariable(var1); mod->AST().AddGlobalVariable(var1);
ValidatorImpl& v = Build(); ValidatorImpl& v = Build();
EXPECT_FALSE(v.ValidateGlobalVariables(mod->global_variables())); EXPECT_FALSE(v.ValidateGlobalVariables(mod->AST().GlobalVariables()));
EXPECT_EQ(v.error(), EXPECT_EQ(v.error(),
"12:34 v-0011: redeclared global identifier 'global_var'"); "12:34 v-0011: redeclared global identifier 'global_var'");
} }
@ -566,7 +570,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32, Expr(2.1f), auto* global_var = Var("a", ast::StorageClass::kPrivate, ty.f32, Expr(2.1f),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
mod->AddGlobalVariable(global_var); mod->AST().AddGlobalVariable(global_var);
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f), auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
ast::VariableDecorationList{}); ast::VariableDecorationList{});

View File

@ -136,7 +136,7 @@ void GeneratorImpl::make_indent(std::ostream& out) {
} }
bool GeneratorImpl::Generate(std::ostream& out) { bool GeneratorImpl::Generate(std::ostream& out) {
for (auto* global : program_->global_variables()) { for (auto* global : program_->AST().GlobalVariables()) {
register_global(global); register_global(global);
} }
@ -149,7 +149,7 @@ bool GeneratorImpl::Generate(std::ostream& out) {
out << std::endl; out << std::endl;
} }
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
if (!var->is_const()) { if (!var->is_const()) {
continue; continue;
} }

View File

@ -57,8 +57,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32, Func("vtx_main", ast::VariableList{}, ty.f32,
@ -110,8 +110,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32, Func("vtx_main", ast::VariableList{}, ty.f32,
@ -163,8 +163,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.f32, Func("main", ast::VariableList{}, ty.f32,
@ -216,8 +216,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.f32, Func("main", ast::VariableList{}, ty.f32,
@ -266,8 +266,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.f32, Func("main", ast::VariableList{}, ty.f32,
@ -311,8 +311,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.f32, Func("main", ast::VariableList{}, ty.f32,
@ -364,8 +364,8 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.void_, Func("main", ast::VariableList{}, ty.void_,

View File

@ -157,8 +157,8 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.void_, Func("main", ast::VariableList{}, ty.void_,
@ -208,8 +208,8 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("frag_main", ast::VariableList{}, ty.void_, Func("frag_main", ast::VariableList{}, ty.void_,
@ -262,8 +262,8 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto* func = auto* func =
Func("frag_main", ast::VariableList{}, ty.void_, Func("frag_main", ast::VariableList{}, ty.void_,
@ -310,7 +310,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "x"), ast::VariableDecorationList{}); MemberAccessor("coord", "x"), ast::VariableDecorationList{});
@ -361,7 +361,7 @@ TEST_F(HlslGeneratorImplTest_Function,
mod->AddConstructedType(s); mod->AddConstructedType(s);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
@ -416,7 +416,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "b"), ast::VariableDecorationList{}); MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -466,7 +466,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "b"), ast::VariableDecorationList{}); MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -515,7 +515,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* func = auto* func =
Func("frag_main", ast::VariableList{}, ty.void_, Func("frag_main", ast::VariableList{}, ty.void_,
@ -567,9 +567,9 @@ TEST_F(
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var); td.RegisterVariableForTesting(val_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
mod->AddGlobalVariable(val_var); mod->AST().AddGlobalVariable(val_var);
auto* sub_func = Func( auto* sub_func = Func(
"sub_func", "sub_func",
@ -635,7 +635,7 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto* sub_func = Func( auto* sub_func = Func(
"sub_func", "sub_func",
@ -701,8 +701,8 @@ TEST_F(
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto* sub_func = Func( auto* sub_func = Func(
"sub_func", "sub_func",
@ -768,7 +768,7 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* sub_func = Func( auto* sub_func = Func(
"sub_func", "sub_func",
@ -828,7 +828,7 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* sub_func = Func( auto* sub_func = Func(
"sub_func", "sub_func",
@ -883,7 +883,7 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* list = create<ast::BlockStatement>(ast::StatementList{ auto* list = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
@ -1055,7 +1055,7 @@ TEST_F(HlslGeneratorImplTest_Function,
mod->AddConstructedType(s); mod->AddConstructedType(s);
td.RegisterVariableForTesting(data_var); td.RegisterVariableForTesting(data_var);
mod->AddGlobalVariable(data_var); mod->AST().AddGlobalVariable(data_var);
{ {
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,

View File

@ -213,7 +213,7 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
auto* expr = Call("determinant", "var"); auto* expr = Call("determinant", "var");
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
// Register the global // Register the global
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -46,7 +46,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
auto* s = ty.struct_("Str", strct); auto* s = ty.struct_("Str", strct);
auto* str_var = Var("str", ast::StorageClass::kPrivate, s); auto* str_var = Var("str", ast::StorageClass::kPrivate, s);
mod->AddGlobalVariable(str_var); mod->AST().AddGlobalVariable(str_var);
auto* expr = MemberAccessor("str", "mem"); auto* expr = MemberAccessor("str", "mem");
@ -79,7 +79,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "b"); auto* expr = MemberAccessor("data", "b");
@ -112,7 +112,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{}); ast::StructDecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "a"); auto* expr = MemberAccessor("data", "a");
@ -149,9 +149,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* b_var = Var("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>()); auto* b_var = Var("b", ast::StorageClass::kPrivate, ty.mat2x3<f32>());
mod->AddGlobalVariable(b_var); mod->AST().AddGlobalVariable(b_var);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* lhs = MemberAccessor("data", "a"); auto* lhs = MemberAccessor("data", "a");
auto* rhs = Expr("b"); auto* rhs = Expr("b");
@ -197,7 +197,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = MemberAccessor("data", "a"); auto* lhs = MemberAccessor("data", "a");
@ -240,7 +240,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "a"); auto* expr = MemberAccessor("data", "a");
@ -282,7 +282,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "a"); auto* expr = MemberAccessor("data", "a");
@ -317,7 +317,7 @@ TEST_F(
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "a"); auto* expr = MemberAccessor("data", "a");
@ -353,7 +353,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = IndexAccessor( auto* expr = IndexAccessor(
@ -389,7 +389,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{}); ast::StructDecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2)); auto* expr = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
@ -424,7 +424,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::StructDecorationList{}); ast::StructDecorationList{});
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = IndexAccessor(MemberAccessor("data", "a"), auto* expr = IndexAccessor(MemberAccessor("data", "a"),
@ -459,7 +459,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = MemberAccessor("data", "b"); auto* lhs = MemberAccessor("data", "b");
@ -499,7 +499,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2)); auto* lhs = IndexAccessor(MemberAccessor("data", "a"), Expr(2));
@ -536,7 +536,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = MemberAccessor("data", "a"); auto* lhs = MemberAccessor("data", "a");
@ -573,7 +573,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor("data", "b"); auto* expr = MemberAccessor("data", "b");
@ -607,7 +607,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* s = ty.struct_("Data", str); auto* s = ty.struct_("Data", str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, s); auto* coord_var = Var("data", ast::StorageClass::kStorage, s);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = MemberAccessor("data", "b"); auto* lhs = MemberAccessor("data", "b");
@ -662,7 +662,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = auto* expr =
@ -711,7 +711,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
@ -765,7 +765,7 @@ TEST_F(
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = MemberAccessor( auto* expr = MemberAccessor(
@ -817,7 +817,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* expr = IndexAccessor( auto* expr = IndexAccessor(
@ -869,7 +869,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = auto* lhs =
@ -925,7 +925,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* pre_struct = ty.struct_("Pre", pre_str); auto* pre_struct = ty.struct_("Pre", pre_str);
auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct); auto* coord_var = Var("data", ast::StorageClass::kStorage, pre_struct);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
auto* lhs = MemberAccessor( auto* lhs = MemberAccessor(

View File

@ -115,7 +115,7 @@ std::string GeneratorImpl::generate_name(const std::string& prefix) {
bool GeneratorImpl::Generate() { bool GeneratorImpl::Generate() {
out_ << "#include <metal_stdlib>" << std::endl << std::endl; out_ << "#include <metal_stdlib>" << std::endl << std::endl;
for (auto* global : program_->global_variables()) { for (auto* global : program_->AST().GlobalVariables()) {
global_variables_.set(global->symbol(), global); global_variables_.set(global->symbol(), global);
} }
@ -128,7 +128,7 @@ bool GeneratorImpl::Generate() {
out_ << std::endl; out_ << std::endl;
} }
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
if (!var->is_const()) { if (!var->is_const()) {
continue; continue;
} }

View File

@ -58,8 +58,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -106,8 +106,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -154,8 +154,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -202,8 +202,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -247,8 +247,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -287,8 +287,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -334,8 +334,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto body = ast::StatementList{create<ast::AssignmentStatement>( auto body = ast::StatementList{create<ast::AssignmentStatement>(
Expr("depth"), MemberAccessor("coord", "x"))}; Expr("depth"), MemberAccessor("coord", "x"))};

View File

@ -163,8 +163,8 @@ TEST_F(MslGeneratorImplTest,
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.void_, Func("main", ast::VariableList{}, ty.void_,
@ -212,8 +212,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
@ -264,8 +264,8 @@ TEST_F(MslGeneratorImplTest,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), create<ast::AssignmentStatement>(Expr("depth"),
@ -308,7 +308,7 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "x"), ast::VariableDecorationList{}); MemberAccessor("coord", "x"), ast::VariableDecorationList{});
@ -359,7 +359,7 @@ TEST_F(MslGeneratorImplTest,
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "b"), ast::VariableDecorationList{}); MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -413,7 +413,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("coord", "b"), ast::VariableDecorationList{}); MemberAccessor("coord", "b"), ast::VariableDecorationList{});
@ -469,9 +469,9 @@ TEST_F(
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
td.RegisterVariableForTesting(val_var); td.RegisterVariableForTesting(val_var);
mod->AddGlobalVariable(foo_var); mod->AST().AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
mod->AddGlobalVariable(val_var); mod->AST().AddGlobalVariable(val_var);
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
@ -536,7 +536,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
@ -602,8 +602,8 @@ TEST_F(
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var); mod->AST().AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
@ -663,7 +663,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
ast::VariableList params; ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32));
@ -730,7 +730,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
ast::VariableList params; ast::VariableList params;
params.push_back( params.push_back(
@ -799,7 +799,7 @@ TEST_F(MslGeneratorImplTest,
create<ast::GroupDecoration>(1)}); create<ast::GroupDecoration>(1)});
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var); mod->AST().AddGlobalVariable(coord_var);
ast::VariableList params; ast::VariableList params;
params.push_back( params.push_back(
@ -861,7 +861,7 @@ TEST_F(MslGeneratorImplTest,
ast::VariableDecorationList{create<ast::LocationDecoration>(1)}); ast::VariableDecorationList{create<ast::LocationDecoration>(1)});
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(bar_var); mod->AST().AddGlobalVariable(bar_var);
auto* list = create<ast::BlockStatement>(ast::StatementList{ auto* list = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(), create<ast::ReturnStatement>(),
@ -988,7 +988,7 @@ TEST_F(MslGeneratorImplTest,
mod->AddConstructedType(s); mod->AddConstructedType(s);
td.RegisterVariableForTesting(data_var); td.RegisterVariableForTesting(data_var);
mod->AddGlobalVariable(data_var); mod->AST().AddGlobalVariable(data_var);
{ {
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,

View File

@ -198,7 +198,7 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
TEST_F(MslGeneratorImplTest, MslImportData_Determinant) { TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>()); auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
mod->AddGlobalVariable(var); mod->AST().AddGlobalVariable(var);
auto* expr = Call("determinant", "var"); auto* expr = Call("determinant", "var");

View File

@ -297,7 +297,7 @@ bool Builder::Build() {
{Operand::Int(SpvAddressingModelLogical), {Operand::Int(SpvAddressingModelLogical),
Operand::Int(SpvMemoryModelGLSL450)}); Operand::Int(SpvMemoryModelGLSL450)});
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
if (!GenerateGlobalVariable(var)) { if (!GenerateGlobalVariable(var)) {
return false; return false;
} }

View File

@ -100,9 +100,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32); auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32);
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32); auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32);
mod->AddGlobalVariable(v_in); mod->AST().AddGlobalVariable(v_in);
mod->AddGlobalVariable(v_out); mod->AST().AddGlobalVariable(v_out);
mod->AddGlobalVariable(v_wg); mod->AST().AddGlobalVariable(v_wg);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -149,9 +149,9 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32); auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32);
auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32); auto* v_wg = Var("my_wg", ast::StorageClass::kWorkgroup, ty.f32);
mod->AddGlobalVariable(v_in); mod->AST().AddGlobalVariable(v_in);
mod->AddGlobalVariable(v_out); mod->AST().AddGlobalVariable(v_out);
mod->AddGlobalVariable(v_wg); mod->AST().AddGlobalVariable(v_wg);
td.RegisterVariableForTesting(v_in); td.RegisterVariableForTesting(v_in);
td.RegisterVariableForTesting(v_out); td.RegisterVariableForTesting(v_out);
@ -276,7 +276,7 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) {
ast::VariableDecorationList{ ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
}); });
mod->AddGlobalVariable(fragdepth); mod->AST().AddGlobalVariable(fragdepth);
auto* func = auto* func =
Func("main", ast::VariableList{}, ty.void_, Func("main", ast::VariableList{}, ty.void_,

View File

@ -245,7 +245,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
mod->AddConstructedType(s); mod->AddConstructedType(s);
td.RegisterVariableForTesting(data_var); td.RegisterVariableForTesting(data_var);
mod->AddGlobalVariable(data_var); mod->AST().AddGlobalVariable(data_var);
{ {
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,

View File

@ -4150,8 +4150,8 @@ TEST_P(IntrinsicTextureTest, Call) {
TEST_P(IntrinsicTextureTest, ValidateSPIRV) { TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
auto param = GetParam(); auto param = GetParam();
mod->AddGlobalVariable(param.buildTextureVariable(this)); mod->AST().AddGlobalVariable(param.buildTextureVariable(this));
mod->AddGlobalVariable(param.buildSamplerVariable(this)); mod->AST().AddGlobalVariable(param.buildSamplerVariable(this));
auto* call = auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this)); create<ast::CallExpression>(Expr(param.function), param.args(this));

View File

@ -92,12 +92,12 @@ bool GeneratorImpl::Generate() {
if (!program_->constructed_types().empty()) if (!program_->constructed_types().empty())
out_ << std::endl; out_ << std::endl;
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
if (!EmitVariable(var)) { if (!EmitVariable(var)) {
return false; return false;
} }
} }
if (!program_->global_variables().empty()) { if (!program_->AST().GlobalVariables().empty()) {
out_ << std::endl; out_ << std::endl;
} }
@ -132,7 +132,7 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
// TODO(dsinclair): This should be smarter and only emit needed const // TODO(dsinclair): This should be smarter and only emit needed const
// variables // variables
for (auto* var : program_->global_variables()) { for (auto* var : program_->AST().GlobalVariables()) {
if (!var->is_const()) { if (!var->is_const()) {
continue; continue;
} }

View File

@ -194,7 +194,7 @@ TEST_F(WgslGeneratorImplTest,
mod->AddConstructedType(s); mod->AddConstructedType(s);
td.RegisterVariableForTesting(data_var); td.RegisterVariableForTesting(data_var);
mod->AddGlobalVariable(data_var); mod->AST().AddGlobalVariable(data_var);
{ {
auto* var = auto* var =