diff --git a/BUILD.gn b/BUILD.gn index 156cb69ae5..20d18baae7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -373,6 +373,7 @@ source_set("libtint_core_src") { "src/inspector/scalar.h", "src/namer.cc", "src/namer.h", + "src/program.cc", "src/program.h", "src/reader/reader.cc", "src/reader/reader.h", @@ -791,7 +792,6 @@ source_set("tint_unittests_core_src") { "src/ast/loop_statement_test.cc", "src/ast/member_accessor_expression_test.cc", "src/ast/module_clone_test.cc", - "src/ast/module_test.cc", "src/ast/null_literal_test.cc", "src/ast/return_statement_test.cc", "src/ast/scalar_constructor_expression_test.cc", @@ -817,6 +817,7 @@ source_set("tint_unittests_core_src") { "src/diagnostic/printer_test.cc", "src/inspector/inspector_test.cc", "src/namer_test.cc", + "src/program_test.cc", "src/scope_stack_test.cc", "src/symbol_table_test.cc", "src/symbol_test.cc", diff --git a/fuzzers/tint_ast_clone_fuzzer.cc b/fuzzers/tint_ast_clone_fuzzer.cc index 6a898f1a3c..6c339e982a 100644 --- a/fuzzers/tint_ast_clone_fuzzer.cc +++ b/fuzzers/tint_ast_clone_fuzzer.cc @@ -47,15 +47,15 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { tint::Source::File file("test.wgsl", str); - // Parse the wgsl, create the src module + // Parse the wgsl, create the src program tint::reader::wgsl::ParserImpl parser(&file); parser.set_max_errors(1); if (!parser.Parse()) { return 0; } - auto src = parser.module(); + auto src = parser.program(); - // Clone the src module to dst + // Clone the src program to dst auto dst = src.Clone(); // Expect the demangled AST printed with to_str() to match @@ -78,24 +78,25 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ASSERT_EQ(src_types.count(dst_type.second), 0u); } - // Regenerate the wgsl for the src module. We use this instead of the original - // source so that reformatting doesn't impact the final wgsl comparision. - // Note that the src module is moved into the generator and this generator has - // a limited scope, so that the src module is released before we attempt to - // print the dst module. - // This guarantee that all the source module nodes and types are destructed - // and freed. - // ASAN should error if there's any remaining references in dst when we try to - // reconstruct the WGSL. + // Regenerate the wgsl for the src program. We use this instead of the + // original source so that reformatting doesn't impact the final wgsl + // comparison. std::string src_wgsl; { - tint::writer::wgsl::Generator src_gen(std::move(src)); + tint::writer::wgsl::Generator src_gen(&src); ASSERT_TRUE(src_gen.Generate()); src_wgsl = src_gen.result(); + + // Move the src program to a temporary that'll be dropped, so that the src + // program is released before we attempt to print the dst program. This + // guarantee that all the source program nodes and types are destructed and + // freed. ASAN should error if there's any remaining references in dst when + // we try to reconstruct the WGSL. + auto tmp = std::move(src); } - // Print the dst module, check it matches the original source - tint::writer::wgsl::Generator dst_gen(std::move(dst)); + // Print the dst program, check it matches the original source + tint::writer::wgsl::Generator dst_gen(&dst); ASSERT_TRUE(dst_gen.Generate()); auto dst_wgsl = dst_gen.result(); ASSERT_EQ(src_wgsl, dst_wgsl); diff --git a/fuzzers/tint_common_fuzzer.cc b/fuzzers/tint_common_fuzzer.cc index 66826a79cd..4c83b6ad37 100644 --- a/fuzzers/tint_common_fuzzer.cc +++ b/fuzzers/tint_common_fuzzer.cc @@ -76,23 +76,23 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { return 0; } - auto mod = parser->module(); - if (!mod.IsValid()) { + auto program = parser->program(); + if (!program.IsValid()) { return 0; } - TypeDeterminer td(&mod); + TypeDeterminer td(&program); if (!td.Determine()) { return 0; } Validator v; - if (!v.Validate(&mod)) { + if (!v.Validate(&program)) { return 0; } if (inspector_enabled_) { - inspector::Inspector inspector(mod); + inspector::Inspector inspector(&program); auto entry_points = inspector.GetEntryPoints(); if (inspector.has_error()) { @@ -154,12 +154,12 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { } if (transform_manager_) { - auto out = transform_manager_->Run(&mod); + auto out = transform_manager_->Run(&program); if (out.diagnostics.contains_errors()) { return 0; } - mod = std::move(out.module); + program = std::move(out.program); } std::unique_ptr writer; @@ -167,22 +167,22 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) { switch (output_) { case OutputFormat::kWGSL: #if TINT_BUILD_WGSL_WRITER - writer = std::make_unique(std::move(mod)); + writer = std::make_unique(&program); #endif // TINT_BUILD_WGSL_WRITER break; case OutputFormat::kSpv: #if TINT_BUILD_SPV_WRITER - writer = std::make_unique(std::move(mod)); + writer = std::make_unique(&program); #endif // TINT_BUILD_SPV_WRITER break; case OutputFormat::kHLSL: #if TINT_BUILD_HLSL_WRITER - writer = std::make_unique(std::move(mod)); + writer = std::make_unique(&program); #endif // TINT_BUILD_HLSL_WRITER break; case OutputFormat::kMSL: #if TINT_BUILD_MSL_WRITER - writer = std::make_unique(std::move(mod)); + writer = std::make_unique(&program); #endif // TINT_BUILD_MSL_WRITER break; case OutputFormat::kNone: diff --git a/samples/main.cc b/samples/main.cc index 678d3d338c..b429369b08 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -496,22 +496,22 @@ int main(int argc, const char** argv) { diag_formatter.format(reader->diagnostics(), diag_printer.get()); return 1; } - auto mod = reader->module(); - if (!mod.IsValid()) { - std::cerr << "Invalid module generated..." << std::endl; + auto program = reader->program(); + if (!program.IsValid()) { + std::cerr << "Invalid program generated..." << std::endl; return 1; } - tint::TypeDeterminer td(&mod); + tint::TypeDeterminer td(&program); if (!td.Determine()) { std::cerr << "Type Determination: " << td.error() << std::endl; return 1; } if (options.dump_ast) { - auto ast_str = mod.to_str(); + auto ast_str = program.to_str(); if (options.demangle) { - ast_str = tint::Demangler().Demangle(mod, ast_str); + ast_str = tint::Demangler().Demangle(program, ast_str); } std::cout << std::endl << ast_str << std::endl; } @@ -520,7 +520,7 @@ int main(int argc, const char** argv) { } tint::Validator v; - if (!v.Validate(&mod)) { + if (!v.Validate(&program)) { diag_formatter.format(v.diagnostics(), diag_printer.get()); return 1; } @@ -546,37 +546,40 @@ int main(int argc, const char** argv) { } } - auto out = transform_manager.Run(&mod); + auto out = transform_manager.Run(&program); if (out.diagnostics.contains_errors()) { diag_formatter.format(out.diagnostics, diag_printer.get()); return 1; } - mod = std::move(out.module); + program = std::move(out.program); std::unique_ptr writer; #if TINT_BUILD_SPV_WRITER if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) { - writer = std::make_unique(std::move(mod)); + writer = + std::make_unique(&program); } #endif // TINT_BUILD_SPV_WRITER #if TINT_BUILD_WGSL_WRITER if (options.format == Format::kWgsl) { - writer = std::make_unique(std::move(mod)); + writer = + std::make_unique(&program); } #endif // TINT_BUILD_WGSL_WRITER #if TINT_BUILD_MSL_WRITER if (options.format == Format::kMsl) { - writer = std::make_unique(std::move(mod)); + writer = std::make_unique(&program); } #endif // TINT_BUILD_MSL_WRITER #if TINT_BUILD_HLSL_WRITER if (options.format == Format::kHlsl) { - writer = std::make_unique(std::move(mod)); + writer = + std::make_unique(&program); } #endif // TINT_BUILD_HLSL_WRITER @@ -641,7 +644,7 @@ int main(int argc, const char** argv) { auto* w = static_cast(writer.get()); auto output = w->result(); if (options.demangle) { - output = tint::Demangler().Demangle(mod, output); + output = tint::Demangler().Demangle(program, output); } if (!WriteFile(options.output_file, "w", output)) { return 1; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb0edaf6d4..638f26a18d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,6 +187,7 @@ set(TINT_LIB_SRCS inspector/scalar.h namer.cc namer.h + program.cc program.h reader/reader.cc reader/reader.h @@ -421,7 +422,6 @@ if(${TINT_BUILD_TESTS}) ast/loop_statement_test.cc ast/member_accessor_expression_test.cc ast/module_clone_test.cc - ast/module_test.cc ast/null_literal_test.cc ast/return_statement_test.cc ast/scalar_constructor_expression_test.cc @@ -447,6 +447,7 @@ if(${TINT_BUILD_TESTS}) diagnostic/printer_test.cc inspector/inspector_test.cc namer_test.cc + program_test.cc scope_stack_test.cc symbol_table_test.cc symbol_test.cc diff --git a/src/ast/access_decoration.cc b/src/ast/access_decoration.cc index 51e2b73413..996c3c76c8 100644 --- a/src/ast/access_decoration.cc +++ b/src/ast/access_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/access_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::AccessDecoration); diff --git a/src/ast/array_accessor_expression.cc b/src/ast/array_accessor_expression.cc index ad5b1eea9f..6a9e6befbf 100644 --- a/src/ast/array_accessor_expression.cc +++ b/src/ast/array_accessor_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/array_accessor_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ArrayAccessorExpression); diff --git a/src/ast/assignment_statement.cc b/src/ast/assignment_statement.cc index 02b7c2bc3e..a0b1a2b0ba 100644 --- a/src/ast/assignment_statement.cc +++ b/src/ast/assignment_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/assignment_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::AssignmentStatement); diff --git a/src/ast/binary_expression.cc b/src/ast/binary_expression.cc index e9970f815e..de5065d71a 100644 --- a/src/ast/binary_expression.cc +++ b/src/ast/binary_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/binary_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BinaryExpression); diff --git a/src/ast/binding_decoration.cc b/src/ast/binding_decoration.cc index 9f686a2efd..05a0d86257 100644 --- a/src/ast/binding_decoration.cc +++ b/src/ast/binding_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/binding_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BindingDecoration); diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc index 39fc72ffe8..85c42a55dc 100644 --- a/src/ast/bitcast_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/bitcast_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BitcastExpression); diff --git a/src/ast/block_statement.cc b/src/ast/block_statement.cc index dfbf12f69f..2ce6b34be6 100644 --- a/src/ast/block_statement.cc +++ b/src/ast/block_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/block_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement); diff --git a/src/ast/bool_literal.cc b/src/ast/bool_literal.cc index d7c53467bf..a8004e66ec 100644 --- a/src/ast/bool_literal.cc +++ b/src/ast/bool_literal.cc @@ -14,8 +14,8 @@ #include "src/ast/bool_literal.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BoolLiteral); diff --git a/src/ast/break_statement.cc b/src/ast/break_statement.cc index 4115174d26..1a7cc9d3eb 100644 --- a/src/ast/break_statement.cc +++ b/src/ast/break_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/break_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BreakStatement); diff --git a/src/ast/builder.cc b/src/ast/builder.cc index b46ee0e8ec..d929a02b47 100644 --- a/src/ast/builder.cc +++ b/src/ast/builder.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -TypesBuilder::TypesBuilder(Module* mod) - : bool_(mod->create()), - f32(mod->create()), - i32(mod->create()), - u32(mod->create()), - void_(mod->create()), - mod_(mod) {} +TypesBuilder::TypesBuilder(Program* p) + : bool_(p->create()), + f32(p->create()), + i32(p->create()), + u32(p->create()), + void_(p->create()), + program_(p) {} -Builder::Builder(Module* m) : mod(m), ty(m) {} +Builder::Builder(Program* p) : program(p), ty(p), mod(p) {} Builder::~Builder() = default; @@ -40,8 +40,8 @@ Variable* Builder::Var(const std::string& name, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(mod->RegisterSymbol(name), storage, type, false, - constructor, decorations); + auto* var = create(program->RegisterSymbol(name), storage, type, + false, constructor, decorations); OnVariableBuilt(var); return var; } @@ -52,8 +52,8 @@ Variable* Builder::Var(const Source& source, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(source, mod->RegisterSymbol(name), storage, type, - false, constructor, decorations); + auto* var = create(source, program->RegisterSymbol(name), storage, + type, false, constructor, decorations); OnVariableBuilt(var); return var; } @@ -69,8 +69,8 @@ Variable* Builder::Const(const std::string& name, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(mod->RegisterSymbol(name), storage, type, true, - constructor, decorations); + auto* var = create(program->RegisterSymbol(name), storage, type, + true, constructor, decorations); OnVariableBuilt(var); return var; } @@ -81,16 +81,16 @@ Variable* Builder::Const(const Source& source, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(source, mod->RegisterSymbol(name), storage, type, - true, constructor, decorations); + auto* var = create(source, program->RegisterSymbol(name), storage, + type, true, constructor, decorations); OnVariableBuilt(var); return var; } -BuilderWithModule::BuilderWithModule() : Builder(new Module()) {} +BuilderWithProgram::BuilderWithProgram() : Builder(new Program()) {} -BuilderWithModule::~BuilderWithModule() { - delete mod; +BuilderWithProgram::~BuilderWithProgram() { + delete program; } } // namespace ast diff --git a/src/ast/builder.h b/src/ast/builder.h index 35a49e1bcc..62462ace5d 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -27,7 +27,6 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/struct.h" @@ -36,6 +35,7 @@ #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/alias_type.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" @@ -56,8 +56,8 @@ namespace ast { class TypesBuilder { public: /// Constructor - /// @param mod the module - explicit TypesBuilder(Module* mod); + /// @param program the program + explicit TypesBuilder(Program* program); /// A boolean type type::Bool* const bool_; @@ -79,80 +79,80 @@ class TypesBuilder { /// @return the tint AST type for a 2-element vector of the C type `T`. template type::Vector* vec2() const { - return mod_->create(Of(), 2); + return program_->create(Of(), 2); } /// @return the tint AST type for a 3-element vector of the C type `T`. template type::Vector* vec3() const { - return mod_->create(Of(), 3); + return program_->create(Of(), 3); } /// @return the tint AST type for a 4-element vector of the C type `T`. template type::Type* vec4() const { - return mod_->create(Of(), 4); + return program_->create(Of(), 4); } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template type::Matrix* mat2x2() const { - return mod_->create(Of(), 2, 2); + return program_->create(Of(), 2, 2); } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template type::Matrix* mat2x3() const { - return mod_->create(Of(), 3, 2); + return program_->create(Of(), 3, 2); } /// @return the tint AST type for a 2x4 matrix of the C type `T`. template type::Matrix* mat2x4() const { - return mod_->create(Of(), 4, 2); + return program_->create(Of(), 4, 2); } /// @return the tint AST type for a 3x2 matrix of the C type `T`. template type::Matrix* mat3x2() const { - return mod_->create(Of(), 2, 3); + return program_->create(Of(), 2, 3); } /// @return the tint AST type for a 3x3 matrix of the C type `T`. template type::Matrix* mat3x3() const { - return mod_->create(Of(), 3, 3); + return program_->create(Of(), 3, 3); } /// @return the tint AST type for a 3x4 matrix of the C type `T`. template type::Matrix* mat3x4() const { - return mod_->create(Of(), 4, 3); + return program_->create(Of(), 4, 3); } /// @return the tint AST type for a 4x2 matrix of the C type `T`. template type::Matrix* mat4x2() const { - return mod_->create(Of(), 2, 4); + return program_->create(Of(), 2, 4); } /// @return the tint AST type for a 4x3 matrix of the C type `T`. template type::Matrix* mat4x3() const { - return mod_->create(Of(), 3, 4); + return program_->create(Of(), 3, 4); } /// @return the tint AST type for a 4x4 matrix of the C type `T`. template type::Matrix* mat4x4() const { - return mod_->create(Of(), 4, 4); + return program_->create(Of(), 4, 4); } /// @param subtype the array element type /// @param n the array size. 0 represents a runtime-array. /// @return the tint AST type for a array of size `n` of type `T` type::Array* array(type::Type* subtype, uint32_t n) const { - return mod_->create(subtype, n, ArrayDecorationList{}); + return program_->create(subtype, n, ArrayDecorationList{}); } /// @return the tint AST type for an array of size `N` of type `T` @@ -166,21 +166,21 @@ class TypesBuilder { /// @param type the alias type /// @returns the alias pointer type::Alias* alias(const std::string& name, type::Type* type) const { - return mod_->create(mod_->RegisterSymbol(name), type); + return program_->create(program_->RegisterSymbol(name), type); } /// @return the tint AST pointer to type `T` with the given StorageClass. /// @param storage_class the storage class of the pointer template type::Pointer* pointer(StorageClass storage_class) const { - return mod_->create(Of(), storage_class); + return program_->create(Of(), storage_class); } /// @param name the struct name /// @param impl the struct implementation /// @returns a struct pointer type::Struct* struct_(const std::string& name, ast::Struct* impl) const { - return mod_->create(mod_->RegisterSymbol(name), impl); + return program_->create(program_->RegisterSymbol(name), impl); } private: @@ -192,7 +192,7 @@ class TypesBuilder { template struct CToAST {}; - Module* const mod_; + Program* const program_; }; /// Helper for building common AST constructs. @@ -216,8 +216,8 @@ class Builder { using f32 = float; /// Constructor - /// @param mod the module to use in the builder - explicit Builder(Module* mod); + /// @param program the program to build + explicit Builder(Program* program); virtual ~Builder(); /// @param expr the expression @@ -227,20 +227,20 @@ class Builder { /// @param name the identifier name /// @return an IdentifierExpression with the given name IdentifierExpression* Expr(const std::string& name) { - return create(mod->RegisterSymbol(name)); + return create(program->RegisterSymbol(name)); } /// @param source the source information /// @param name the identifier name /// @return an IdentifierExpression with the given name IdentifierExpression* Expr(const Source& source, const std::string& name) { - return create(source, mod->RegisterSymbol(name)); + return create(source, program->RegisterSymbol(name)); } /// @param name the identifier name /// @return an IdentifierExpression with the given name IdentifierExpression* Expr(const char* name) { - return create(mod->RegisterSymbol(name)); + return create(program->RegisterSymbol(name)); } /// @param value the boolean value @@ -602,7 +602,7 @@ class Builder { /// @param val the offset value /// @returns the offset decoration pointer StructMemberOffsetDecoration* MemberOffset(uint32_t val) { - return mod->create(source_, val); + return program->create(source_, val); } /// Creates a Function @@ -619,9 +619,9 @@ class Builder { type::Type* type, ast::StatementList body, ast::FunctionDecorationList decorations) { - return mod->create(source, mod->RegisterSymbol(name), params, - type, create(body), - decorations); + return program->create( + source, program->RegisterSymbol(name), params, type, + create(body), decorations); } /// Creates a Function @@ -636,7 +636,7 @@ class Builder { type::Type* type, ast::StatementList body, ast::FunctionDecorationList decorations) { - return create(mod->RegisterSymbol(name), params, type, + return create(program->RegisterSymbol(name), params, type, create(body), decorations); } @@ -649,8 +649,8 @@ class Builder { StructMember* Member(const Source& source, const std::string& name, type::Type* type) { - return mod->create(source, mod->RegisterSymbol(name), type, - StructMemberDecorationList{}); + return program->create(source, program->RegisterSymbol(name), + type, StructMemberDecorationList{}); } /// Creates a StructMember @@ -658,8 +658,8 @@ class Builder { /// @param type the struct member type /// @returns the struct member pointer StructMember* Member(const std::string& name, type::Type* type) { - return mod->create(source_, mod->RegisterSymbol(name), type, - StructMemberDecorationList{}); + return program->create(source_, program->RegisterSymbol(name), + type, StructMemberDecorationList{}); } /// Creates a StructMember @@ -670,8 +670,8 @@ class Builder { StructMember* Member(const std::string& name, type::Type* type, StructMemberDecorationList decos) { - return mod->create(source_, mod->RegisterSymbol(name), type, - decos); + return program->create(source_, program->RegisterSymbol(name), + type, decos); } /// Creates a new Node owned by the Module, with the explicit Source. @@ -682,7 +682,7 @@ class Builder { template traits::EnableIfIsType* create(const Source& source, ARGS&&... args) { - return mod->create(source, std::forward(args)...); + return program->create(source, std::forward(args)...); } /// Creates a new Node owned by the Module, with the explicit Source. @@ -692,7 +692,7 @@ class Builder { /// @returns the node pointer template traits::EnableIfIsType* create(Source&& source, ARGS&&... args) { - return mod->create(std::move(source), std::forward(args)...); + return program->create(std::move(source), std::forward(args)...); } /// Creates a new type::Type owned by the Module, using the Builder's @@ -702,7 +702,7 @@ class Builder { /// @returns the node pointer template traits::EnableIfIsType* create(ARGS&&... args) { - return mod->create(source_, std::forward(args)...); + return program->create(source_, std::forward(args)...); } /// Creates a new type::Type owned by the Module. @@ -720,7 +720,7 @@ class Builder { traits::EnableIfIsType* create(ARGS&&... args) { static_assert(std::is_base_of::value, "T does not derive from type::Type"); - return mod->create(std::forward(args)...); + return program->create(std::forward(args)...); } /// Sets the current builder source to `src` @@ -731,11 +731,14 @@ class Builder { /// @param loc the Source used for future create() calls void SetSource(const Source::Location& loc) { source_ = Source(loc); } - /// The builder module - Module* const mod; + /// The builder program + Program* const program; /// The builder types const TypesBuilder ty; + /// [DEPRECATED] Temporary alias to #program + Program* const mod; + protected: /// Called whenever a new variable is built with `Var()`. virtual void OnVariableBuilt(Variable*) {} @@ -744,11 +747,11 @@ class Builder { Source source_; }; -/// BuilderWithModule is a `Builder` that constructs and owns its `Module`. -class BuilderWithModule : public Builder { +/// BuilderWithProgram is a `Builder` that constructs and owns its `Program`. +class BuilderWithProgram : public Builder { public: - BuilderWithModule(); - ~BuilderWithModule() override; + BuilderWithProgram(); + ~BuilderWithProgram() override; }; //! @cond Doxygen_Suppress diff --git a/src/ast/builtin_decoration.cc b/src/ast/builtin_decoration.cc index 0cfd81125e..d0db918110 100644 --- a/src/ast/builtin_decoration.cc +++ b/src/ast/builtin_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/builtin_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::BuiltinDecoration); diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index 6144b4dc5d..61e5316f2f 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/call_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::CallExpression); diff --git a/src/ast/call_statement.cc b/src/ast/call_statement.cc index f70f36bcca..82eedc821b 100644 --- a/src/ast/call_statement.cc +++ b/src/ast/call_statement.cc @@ -15,8 +15,8 @@ #include "src/ast/call_statement.h" #include "src/ast/call_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::CallStatement); diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc index 62cae3f4e2..84e6b2197d 100644 --- a/src/ast/case_statement.cc +++ b/src/ast/case_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/case_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::CaseStatement); diff --git a/src/ast/constant_id_decoration.cc b/src/ast/constant_id_decoration.cc index c97c84d04e..c2bb255c27 100644 --- a/src/ast/constant_id_decoration.cc +++ b/src/ast/constant_id_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/constant_id_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ConstantIdDecoration); diff --git a/src/ast/continue_statement.cc b/src/ast/continue_statement.cc index d380a8346e..98557bc6b4 100644 --- a/src/ast/continue_statement.cc +++ b/src/ast/continue_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/continue_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ContinueStatement); diff --git a/src/ast/discard_statement.cc b/src/ast/discard_statement.cc index a8f0d3cd18..1a522ccf1c 100644 --- a/src/ast/discard_statement.cc +++ b/src/ast/discard_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/discard_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::DiscardStatement); diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc index a9d5cf1c8c..67c52f2dd4 100644 --- a/src/ast/else_statement.cc +++ b/src/ast/else_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/else_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ElseStatement); diff --git a/src/ast/fallthrough_statement.cc b/src/ast/fallthrough_statement.cc index 378c5fc971..f18ea60d63 100644 --- a/src/ast/fallthrough_statement.cc +++ b/src/ast/fallthrough_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/fallthrough_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::FallthroughStatement); diff --git a/src/ast/float_literal.cc b/src/ast/float_literal.cc index 8795e0f0ae..734706f8db 100644 --- a/src/ast/float_literal.cc +++ b/src/ast/float_literal.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::FloatLiteral); diff --git a/src/ast/function.cc b/src/ast/function.cc index 96fd6d2f13..9123896720 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -16,11 +16,11 @@ #include -#include "src/ast/module.h" #include "src/ast/stage_decoration.h" #include "src/ast/variable.h" #include "src/ast/workgroup_decoration.h" #include "src/clone_context.h" +#include "src/program.h" #include "src/type/multisampled_texture_type.h" #include "src/type/sampled_texture_type.h" #include "src/type/texture_type.h" diff --git a/src/ast/group_decoration.cc b/src/ast/group_decoration.cc index 599493e9a4..738882c41a 100644 --- a/src/ast/group_decoration.cc +++ b/src/ast/group_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/group_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::GroupDecoration); diff --git a/src/ast/identifier_expression.cc b/src/ast/identifier_expression.cc index 05c771f0fd..e10c664e67 100644 --- a/src/ast/identifier_expression.cc +++ b/src/ast/identifier_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression); diff --git a/src/ast/if_statement.cc b/src/ast/if_statement.cc index 80171b1a06..e7e06090c1 100644 --- a/src/ast/if_statement.cc +++ b/src/ast/if_statement.cc @@ -15,8 +15,8 @@ #include "src/ast/if_statement.h" #include "src/ast/else_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::IfStatement); diff --git a/src/ast/location_decoration.cc b/src/ast/location_decoration.cc index 8202dfe058..7b23c2a30d 100644 --- a/src/ast/location_decoration.cc +++ b/src/ast/location_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/location_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::LocationDecoration); diff --git a/src/ast/loop_statement.cc b/src/ast/loop_statement.cc index 14fb504bcd..cee9f23c7d 100644 --- a/src/ast/loop_statement.cc +++ b/src/ast/loop_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/loop_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::LoopStatement); diff --git a/src/ast/member_accessor_expression.cc b/src/ast/member_accessor_expression.cc index 4cbb2db0da..d25c6e868d 100644 --- a/src/ast/member_accessor_expression.cc +++ b/src/ast/member_accessor_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::MemberAccessorExpression); diff --git a/src/ast/module.cc b/src/ast/module.cc index 39bd5e453f..0de64bbd81 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -14,117 +14,10 @@ #include "src/ast/module.h" -#include - -#include "src/clone_context.h" -#include "src/type/struct_type.h" - namespace tint { namespace ast { -Module::Module() = default; - -Module::Module(Module&&) = default; - -Module& Module::operator=(Module&& rhs) = default; - -Module::~Module() = default; - -Module Module::Clone() const { - Module out; - CloneContext(&out, this).Clone(); - return out; -} - -void Module::Clone(CloneContext* ctx) const { - for (auto* ty : constructed_types_) { - ctx->dst->constructed_types_.emplace_back(ctx->Clone(ty)); - } - for (auto* var : global_variables_) { - ctx->dst->global_variables_.emplace_back(ctx->Clone(var)); - } - for (auto* func : functions_) { - ctx->dst->functions_.emplace_back(ctx->Clone(func)); - } -} - -Symbol Module::RegisterSymbol(const std::string& name) { - return symbol_table_.Register(name); -} - -Symbol Module::GetSymbol(const std::string& name) const { - return symbol_table_.GetSymbol(name); -} - -std::string Module::SymbolToName(const Symbol sym) const { - return symbol_table_.NameFor(sym); -} - -bool Module::IsValid() const { - for (auto* var : global_variables_) { - if (var == nullptr || !var->IsValid()) { - return false; - } - } - for (auto* const ty : constructed_types_) { - if (ty == nullptr) { - return false; - } - if (auto* alias = ty->As()) { - if (alias->type() == nullptr) { - return false; - } - if (auto* str = alias->type()->As()) { - if (!str->symbol().IsValid()) { - return false; - } - } - } else if (auto* str = ty->As()) { - if (!str->symbol().IsValid()) { - return false; - } - } else { - return false; - } - } - for (auto* func : functions_) { - if (func == nullptr || !func->IsValid()) { - return false; - } - } - return true; -} - -std::string Module::to_str() const { - std::ostringstream out; - - out << "Module{" << std::endl; - const auto indent = 2; - for (auto* const ty : constructed_types_) { - for (size_t i = 0; i < indent; ++i) { - out << " "; - } - if (auto* alias = ty->As()) { - out << alias->symbol().to_str() << " -> " << alias->type()->type_name() - << std::endl; - if (auto* str = alias->type()->As()) { - str->impl()->to_str(out, indent); - } - } else if (auto* str = ty->As()) { - out << str->symbol().to_str() << " "; - str->impl()->to_str(out, indent); - } - } - for (auto* var : global_variables_) { - var->to_str(out, indent); - } - for (auto* func : functions_) { - func->to_str(out, indent); - } - out << "}" << std::endl; - - return out.str(); -} +// Placeholder } // namespace ast } // namespace tint diff --git a/src/ast/module.h b/src/ast/module.h index 393f3db029..3e2beebfd8 100644 --- a/src/ast/module.h +++ b/src/ast/module.h @@ -15,149 +15,10 @@ #ifndef SRC_AST_MODULE_H_ #define SRC_AST_MODULE_H_ -#include -#include -#include -#include -#include -#include -#include - -#include "src/ast/function.h" -#include "src/ast/variable.h" -#include "src/block_allocator.h" -#include "src/symbol_table.h" -#include "src/traits.h" -#include "src/type/alias_type.h" -#include "src/type/type_manager.h" - namespace tint { namespace ast { -/// Represents all the source in a given program. -class Module { - public: - /// Constructor - Module(); - - /// Move constructor - Module(Module&&); - - /// Move assignment operator - /// @param rhs the Module to move - /// @return this Module - Module& operator=(Module&& rhs); - - /// Destructor - ~Module(); - - /// @return a deep copy of this module - Module Clone() const; - - /// Clone this module into `ctx->mod` using the provided CloneContext - /// The module will be cloned in this order: - /// * Constructed types - /// * Global variables - /// * Functions - /// @param ctx the clone context - void Clone(CloneContext* ctx) const; - - /// Add a global variable to the module - /// @param var the variable to add - void AddGlobalVariable(Variable* var) { global_variables_.push_back(var); } - /// @returns the global variables for the module - const VariableList& global_variables() const { return global_variables_; } - - /// @returns the global variables for the module - VariableList& global_variables() { return global_variables_; } - - /// Adds a constructed type to the module. - /// The type must be an alias or a struct. - /// @param type the constructed type to add - void AddConstructedType(type::Type* type) { - constructed_types_.push_back(type); - } - /// @returns the constructed types in the module - const std::vector& constructed_types() const { - return constructed_types_; - } - - /// @returns the functions declared in the translation unit - const FunctionList& Functions() const { return functions_; } - - /// @returns the functions declared in the translation unit - FunctionList& Functions() { return functions_; } - - /// @returns true if all required fields in the AST are present. - bool IsValid() const; - - /// @returns a string representation of the module - std::string to_str() const; - - /// Creates a new Node owned by the Module. When the Module is - /// destructed, the Node will also be destructed. - /// @param args the arguments to pass to the type constructor - /// @returns the node pointer - template - traits::EnableIfIsType* create(ARGS&&... args) { - return ast_nodes_.Create(std::forward(args)...); - } - - /// Creates a new type::Type owned by the Module. - /// When the Module is destructed, owned Module and the returned - /// `Type` will also be destructed. - /// Types are unique (de-aliased), and so calling create() for the same `T` - /// and arguments will return the same pointer. - /// @warning Use this method to acquire a type only if all of its type - /// information is provided in the constructor arguments `args`.
- /// If the type requires additional configuration after construction that - /// affect its fundamental type, build the type with `std::make_unique`, make - /// any necessary alterations and then call unique_type() instead. - /// @param args the arguments to pass to the type constructor - /// @returns the de-aliased type pointer - template - traits::EnableIfIsType* create(ARGS&&... args) { - static_assert(std::is_base_of::value, - "T does not derive from type::Type"); - return type_mgr_.Get(std::forward(args)...); - } - - /// Returns all the declared types in the module - /// @returns the mapping from name string to type. - const std::unordered_map& types() { - return type_mgr_.types(); - } - - /// @returns all the declared nodes in the module - BlockAllocator::View nodes() { return ast_nodes_.Objects(); } - - /// Registers `name` as a symbol - /// @param name the name to register - /// @returns the symbol for the `name`. If `name` is already registered the - /// previously generated symbol will be returned. - Symbol RegisterSymbol(const std::string& name); - - /// Returns the symbol for `name` - /// @param name the name to lookup - /// @returns the symbol for name or symbol::kInvalid - Symbol GetSymbol(const std::string& name) const; - - /// Returns the `name` for `sym` - /// @param sym the symbol to retrieve the name for - /// @returns the use provided `name` for the symbol or "" if not found - std::string SymbolToName(const Symbol sym) const; - - private: - Module(const Module&) = delete; - - SymbolTable symbol_table_; - VariableList global_variables_; - // The constructed types are owned by the type manager - std::vector constructed_types_; - FunctionList functions_; - BlockAllocator ast_nodes_; - type::Manager type_mgr_; -}; +// Placeholder } // namespace ast } // namespace tint diff --git a/src/ast/module_clone_test.cc b/src/ast/module_clone_test.cc index f855fcb2eb..b32c577eef 100644 --- a/src/ast/module_clone_test.cc +++ b/src/ast/module_clone_test.cc @@ -108,12 +108,12 @@ fn main() -> void { )"); - // Parse the wgsl, create the src module + // Parse the wgsl, create the src program reader::wgsl::Parser parser(&file); ASSERT_TRUE(parser.Parse()) << parser.error(); - auto src = parser.module(); + auto src = parser.program(); - // Clone the src module to dst + // Clone the src program to dst auto dst = src.Clone(); // Expect the AST printed with to_str() to match @@ -138,24 +138,25 @@ fn main() -> void { << dst_type.second->type_name(); } - // Regenerate the wgsl for the src module. We use this instead of the original - // source so that reformatting doesn't impact the final wgsl comparision. - // Note that the src module is moved into the generator and this generator has - // a limited scope, so that the src module is released before we attempt to - // print the dst module. - // This guarantee that all the source module nodes and types are destructed - // and freed. - // ASAN should error if there's any remaining references in dst when we try to - // reconstruct the WGSL. + // Regenerate the wgsl for the src program. We use this instead of the + // original source so that reformatting doesn't impact the final wgsl + // comparison. std::string src_wgsl; { - writer::wgsl::Generator src_gen(std::move(src)); - ASSERT_TRUE(src_gen.Generate()) << src_gen.error(); + tint::writer::wgsl::Generator src_gen(&src); + ASSERT_TRUE(src_gen.Generate()); src_wgsl = src_gen.result(); + + // Move the src program to a temporary that'll be dropped, so that the src + // program is released before we attempt to print the dst program. This + // guarantee that all the source program nodes and types are destructed and + // freed. ASAN should error if there's any remaining references in dst when + // we try to reconstruct the WGSL. + auto tmp = std::move(src); } - // Print the dst module, check it matches the original source - writer::wgsl::Generator dst_gen(std::move(dst)); + // Print the dst program, check it matches the original source + tint::writer::wgsl::Generator dst_gen(&dst); ASSERT_TRUE(dst_gen.Generate()); auto dst_wgsl = dst_gen.result(); ASSERT_EQ(src_wgsl, dst_wgsl); diff --git a/src/ast/node.h b/src/ast/node.h index 924ffd13ad..1c215e40a8 100644 --- a/src/ast/node.h +++ b/src/ast/node.h @@ -32,8 +32,6 @@ class Type; namespace ast { -class Module; - /// AST base class node class Node : public Castable { public: diff --git a/src/ast/null_literal.cc b/src/ast/null_literal.cc index 1bb8cc15b9..7a52a7f307 100644 --- a/src/ast/null_literal.cc +++ b/src/ast/null_literal.cc @@ -14,8 +14,8 @@ #include "src/ast/null_literal.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::NullLiteral); diff --git a/src/ast/return_statement.cc b/src/ast/return_statement.cc index 105e7e55b9..86024605bb 100644 --- a/src/ast/return_statement.cc +++ b/src/ast/return_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/return_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement); diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc index 4658081e8f..dfa4ae3b8e 100644 --- a/src/ast/scalar_constructor_expression.cc +++ b/src/ast/scalar_constructor_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/scalar_constructor_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression); diff --git a/src/ast/sint_literal.cc b/src/ast/sint_literal.cc index e5a22100b2..4957286a3f 100644 --- a/src/ast/sint_literal.cc +++ b/src/ast/sint_literal.cc @@ -14,8 +14,8 @@ #include "src/ast/sint_literal.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::SintLiteral); diff --git a/src/ast/stage_decoration.cc b/src/ast/stage_decoration.cc index 4867d7ba0b..e359ac4f89 100644 --- a/src/ast/stage_decoration.cc +++ b/src/ast/stage_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/stage_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::StageDecoration); diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc index 16d7a14cce..1473d02a35 100644 --- a/src/ast/stride_decoration.cc +++ b/src/ast/stride_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/stride_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::StrideDecoration); diff --git a/src/ast/struct.cc b/src/ast/struct.cc index 1302d8d996..92e01f76f8 100644 --- a/src/ast/struct.cc +++ b/src/ast/struct.cc @@ -14,9 +14,9 @@ #include "src/ast/struct.h" -#include "src/ast/module.h" #include "src/ast/struct_block_decoration.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::Struct); diff --git a/src/ast/struct_block_decoration.cc b/src/ast/struct_block_decoration.cc index c12902c774..55af859ea6 100644 --- a/src/ast/struct_block_decoration.cc +++ b/src/ast/struct_block_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/struct_block_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::StructBlockDecoration); diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 28fbd3ac2a..4ecd79d9a0 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -14,9 +14,9 @@ #include "src/ast/struct_member.h" -#include "src/ast/module.h" #include "src/ast/struct_member_offset_decoration.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMember); diff --git a/src/ast/struct_member_offset_decoration.cc b/src/ast/struct_member_offset_decoration.cc index 380d480d76..71fbfc9a6c 100644 --- a/src/ast/struct_member_offset_decoration.cc +++ b/src/ast/struct_member_offset_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/struct_member_offset_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::StructMemberOffsetDecoration); diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc index cbd2018dec..3e536cde2a 100644 --- a/src/ast/switch_statement.cc +++ b/src/ast/switch_statement.cc @@ -15,8 +15,8 @@ #include "src/ast/switch_statement.h" #include "src/ast/case_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::SwitchStatement); diff --git a/src/ast/test_helper.h b/src/ast/test_helper.h index 7cb44f8aa5..ab6d46894e 100644 --- a/src/ast/test_helper.h +++ b/src/ast/test_helper.h @@ -21,15 +21,15 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" -#include "src/ast/module.h" #include "src/demangler.h" +#include "src/program.h" namespace tint { namespace ast { /// Helper class for testing template -class TestHelperBase : public BASE, public BuilderWithModule { +class TestHelperBase : public BASE, public BuilderWithProgram { public: /// Demangles the given string /// @param s the string to demangle diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index e8dbcc47d6..b5807b48d6 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/type_constructor_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::TypeConstructorExpression); diff --git a/src/ast/uint_literal.cc b/src/ast/uint_literal.cc index be00e75ae0..00d414bb69 100644 --- a/src/ast/uint_literal.cc +++ b/src/ast/uint_literal.cc @@ -14,8 +14,8 @@ #include "src/ast/uint_literal.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::UintLiteral); diff --git a/src/ast/unary_op_expression.cc b/src/ast/unary_op_expression.cc index 100a3760ea..21c6a05153 100644 --- a/src/ast/unary_op_expression.cc +++ b/src/ast/unary_op_expression.cc @@ -14,8 +14,8 @@ #include "src/ast/unary_op_expression.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::UnaryOpExpression); diff --git a/src/ast/variable.cc b/src/ast/variable.cc index 1e579e132b..0e4c336085 100644 --- a/src/ast/variable.cc +++ b/src/ast/variable.cc @@ -17,8 +17,8 @@ #include #include "src/ast/constant_id_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::Variable); diff --git a/src/ast/variable_decl_statement.cc b/src/ast/variable_decl_statement.cc index d915dd084c..91a56d1a0e 100644 --- a/src/ast/variable_decl_statement.cc +++ b/src/ast/variable_decl_statement.cc @@ -14,8 +14,8 @@ #include "src/ast/variable_decl_statement.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::VariableDeclStatement); diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc index b6e6702400..57ea5e4c69 100644 --- a/src/ast/workgroup_decoration.cc +++ b/src/ast/workgroup_decoration.cc @@ -14,8 +14,8 @@ #include "src/ast/workgroup_decoration.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::ast::WorkgroupDecoration); diff --git a/src/clone_context.cc b/src/clone_context.cc index 1eb88337d7..5eb1a86cf7 100644 --- a/src/clone_context.cc +++ b/src/clone_context.cc @@ -14,11 +14,11 @@ #include "src/clone_context.h" -#include "src/ast/module.h" +#include "src/program.h" namespace tint { -CloneContext::CloneContext(ast::Module* to, ast::Module const* from) +CloneContext::CloneContext(Program* to, Program const* from) : dst(to), src(from) {} CloneContext::~CloneContext() = default; diff --git a/src/clone_context.h b/src/clone_context.h index 9a0cd55306..1f742b931b 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -27,29 +27,27 @@ namespace tint { // Forward declarations -namespace ast { -class Module; -} // namespace ast +class Program; /// CloneContext holds the state used while cloning AST nodes and types. class CloneContext { public: /// Constructor - /// @param to the target module to clone into - /// @param from the source module to clone from - CloneContext(ast::Module* to, ast::Module const* from); + /// @param to the target program to clone into + /// @param from the source program to clone from + CloneContext(Program* to, Program const* from); /// Destructor ~CloneContext(); - /// Clones the Node or type::Type `a` into the module #dst if `a` is not + /// Clones the Node or type::Type `a` into the program #dst if `a` is not /// null. If `a` is null, then Clone() returns null. If `a` has been cloned /// already by this CloneContext then the same cloned pointer is returned. /// /// Clone() may use a function registered with ReplaceAll() to create a /// transformed version of the object. See ReplaceAll() for more information. /// - /// The Node or type::Type `a` must be owned by the module #src. + /// The Node or type::Type `a` must be owned by the program #src. /// /// @note Semantic information such as resolved expression type and intrinsic /// information is not cloned. @@ -78,7 +76,7 @@ class CloneContext { /// Clones the Source `s` into `dst` /// TODO(bclayton) - Currently this 'clone' is a shallow copy. If/when - /// `Source.File`s are owned by the `Module` this should make a copy of the + /// `Source.File`s are owned by the Program this should make a copy of the /// file. /// @param s the `Source` to clone /// @return the cloned source @@ -86,15 +84,15 @@ class CloneContext { /// Clones the Symbol `s` into `dst` /// - /// The Symbol `s` must be owned by the module #src. + /// The Symbol `s` must be owned by the program #src. /// /// @param s the Symbol to clone /// @return the cloned source Symbol Clone(const Symbol& s) const; - /// Clones each of the elements of the vector `v` into the module #dst-> + /// Clones each of the elements of the vector `v` into the program #dst. /// - /// All the elements of the vector `v` must be owned by the module #src. + /// All the elements of the vector `v` must be owned by the program #src. /// /// @param v the vector to clone /// @return the cloned vector @@ -147,14 +145,14 @@ class CloneContext { return *this; } - /// Clone performs the clone of the entire module #src to #dst. + /// Clone performs the clone of the entire program #src to #dst. void Clone(); - /// The target module to clone into. - ast::Module* const dst; + /// The target program to clone into. + Program* const dst; - /// The source module to clone from. - ast::Module const* const src; + /// The source program to clone from. + Program const* const src; private: using Transform = std::function; diff --git a/src/clone_context_test.cc b/src/clone_context_test.cc index a0f378f5b4..5762cf3247 100644 --- a/src/clone_context_test.cc +++ b/src/clone_context_test.cc @@ -16,7 +16,7 @@ #include "gtest/gtest.h" -#include "src/ast/module.h" +#include "src/program.h" namespace tint { namespace { @@ -44,7 +44,7 @@ struct Replaceable : public Castable {}; struct Replacement : public Castable {}; TEST(CloneContext, Clone) { - ast::Module original; + Program original; auto* original_root = original.create(); original_root->a = original.create(); original_root->a->b = original.create(); @@ -63,7 +63,7 @@ TEST(CloneContext, Clone) { // // C: Clonable - ast::Module cloned; + Program cloned; auto* cloned_root = CloneContext(&cloned, &original).Clone(original_root); EXPECT_NE(cloned_root->a, nullptr); @@ -88,7 +88,7 @@ TEST(CloneContext, Clone) { } TEST(CloneContext, CloneWithReplacements) { - ast::Module original; + Program original; auto* original_root = original.create(); original_root->a = original.create(); original_root->a->b = original.create(); @@ -107,7 +107,7 @@ TEST(CloneContext, CloneWithReplacements) { // C: Clonable // R: Replaceable - ast::Module cloned; + Program cloned; auto* cloned_root = CloneContext(&cloned, &original) .ReplaceAll([&](CloneContext* ctx, Replaceable* in) { auto* out = cloned.create(); diff --git a/src/demangler.cc b/src/demangler.cc index c874d26829..9296d11302 100644 --- a/src/demangler.cc +++ b/src/demangler.cc @@ -26,7 +26,7 @@ Demangler::Demangler() = default; Demangler::~Demangler() = default; -std::string Demangler::Demangle(const ast::Module& mod, +std::string Demangler::Demangle(const Program& program, const std::string& str) const { auto ret = str; @@ -46,7 +46,7 @@ std::string Demangler::Demangle(const ast::Module& mod, auto id = ret.substr(start_idx, len); Symbol sym(std::stoi(id)); - auto name = mod.SymbolToName(sym); + auto name = program.SymbolToName(sym); ret.replace(idx, end_idx - idx, name); pos = idx + name.length(); diff --git a/src/demangler.h b/src/demangler.h index 23f9a2ea75..9496d6ccd1 100644 --- a/src/demangler.h +++ b/src/demangler.h @@ -17,7 +17,7 @@ #include -#include "src/ast/module.h" +#include "src/program.h" namespace tint { @@ -30,10 +30,10 @@ class Demangler { ~Demangler(); /// Transforms given string and replaces any symbols with original names - /// @param mod the module where the symbols are registered + /// @param program the program where the symbols are registered /// @param str the string to replace /// @returns the string with any symbol replacements performed. - std::string Demangle(const ast::Module& mod, const std::string& str) const; + std::string Demangle(const Program& program, const std::string& str) const; }; } // namespace tint diff --git a/src/demangler_test.cc b/src/demangler_test.cc index cc0477c531..9e83fb443f 100644 --- a/src/demangler_test.cc +++ b/src/demangler_test.cc @@ -15,6 +15,7 @@ #include "src/demangler.h" #include "gtest/gtest.h" +#include "src/program.h" namespace tint { namespace { @@ -22,7 +23,7 @@ namespace { using DemanglerTest = testing::Test; TEST_F(DemanglerTest, NoSymbols) { - ast::Module m; + Program m; m.RegisterSymbol("sym1"); Demangler d; @@ -30,7 +31,7 @@ TEST_F(DemanglerTest, NoSymbols) { } TEST_F(DemanglerTest, Symbol) { - ast::Module m; + Program m; m.RegisterSymbol("sym1"); Demangler d; @@ -38,7 +39,7 @@ TEST_F(DemanglerTest, Symbol) { } TEST_F(DemanglerTest, MultipleSymbols) { - ast::Module m; + Program m; m.RegisterSymbol("sym1"); m.RegisterSymbol("sym2"); diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index ab60122e76..97c02cce8b 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -43,29 +43,27 @@ namespace tint { namespace inspector { -Inspector::Inspector(const ast::Module& module) : module_(module) {} - -Inspector::Inspector(const Program* program) : Inspector(program->module) {} +Inspector::Inspector(const Program* program) : program_(*program) {} Inspector::~Inspector() = default; std::vector Inspector::GetEntryPoints() { std::vector result; - for (auto* func : module_.Functions()) { + for (auto* func : program_.Functions()) { if (!func->IsEntryPoint()) { continue; } EntryPoint entry_point; - entry_point.name = module_.SymbolToName(func->symbol()); - entry_point.remapped_name = module_.SymbolToName(func->symbol()); + entry_point.name = program_.SymbolToName(func->symbol()); + entry_point.remapped_name = program_.SymbolToName(func->symbol()); entry_point.stage = func->pipeline_stage(); std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y, entry_point.workgroup_size_z) = func->workgroup_size(); for (auto* var : func->referenced_module_variables()) { - auto name = module_.SymbolToName(var->symbol()); + auto name = program_.SymbolToName(var->symbol()); if (var->HasBuiltinDecoration()) { continue; } @@ -108,7 +106,7 @@ std::string Inspector::GetRemappedNameForEntryPoint( std::map Inspector::GetConstantIDs() { std::map result; - for (auto* var : module_.global_variables()) { + for (auto* var : program_.global_variables()) { if (!var->HasConstantIdDecoration()) { continue; } @@ -285,7 +283,7 @@ std::vector Inspector::GetMultisampledTextureResourceBindings( } ast::Function* Inspector::FindEntryPointByName(const std::string& name) { - auto* func = module_.Functions().Find(module_.GetSymbol(name)); + auto* func = program_.Functions().Find(program_.GetSymbol(name)); if (!func) { error_ += name + " was not found!"; return nullptr; diff --git a/src/inspector/inspector.h b/src/inspector/inspector.h index 662726cf54..5ba70befd5 100644 --- a/src/inspector/inspector.h +++ b/src/inspector/inspector.h @@ -21,7 +21,6 @@ #include #include -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/inspector/entry_point.h" #include "src/inspector/scalar.h" @@ -68,13 +67,9 @@ struct ResourceBinding { SampledKind sampled_kind; }; -/// Extracts information from a module +/// Extracts information from a program class Inspector { public: - /// Constructor - /// @param module Shader module to extract information from. - explicit Inspector(const ast::Module& module); - /// Constructor /// @param program Shader program to extract information from. explicit Inspector(const Program* program); @@ -134,7 +129,7 @@ class Inspector { const std::string& entry_point); private: - const ast::Module& module_; + const Program& program_; std::string error_; /// @param name name of the entry point to find diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 9067461db9..b214dc9e76 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -67,11 +67,11 @@ namespace tint { namespace inspector { namespace { -class InspectorHelper : public ast::BuilderWithModule { +class InspectorHelper : public ast::BuilderWithProgram { public: InspectorHelper() : td_(std::make_unique(mod)), - inspector_(std::make_unique(*mod)), + inspector_(std::make_unique(mod)), sampler_type_(type::SamplerKind::kSampler), comparison_sampler_type_(type::SamplerKind::kComparisonSampler) {} @@ -317,7 +317,7 @@ class InspectorHelper : public ast::BuilderWithModule { return {struct_type, std::move(access_type)}; } - /// Adds a binding variable with a struct type to the module + /// Adds a binding variable with a struct type to the program /// @param name the name of the variable /// @param type the type to use /// @param storage_class the storage class to use @@ -337,7 +337,7 @@ class InspectorHelper : public ast::BuilderWithModule { mod->AddGlobalVariable(var); } - /// Adds an uniform buffer variable to the module + /// Adds an uniform buffer variable to the program /// @param name the name of the variable /// @param type the type to use /// @param group the binding/group/ to use for the uniform buffer @@ -349,7 +349,7 @@ class InspectorHelper : public ast::BuilderWithModule { AddBinding(name, type, ast::StorageClass::kUniform, group, binding); } - /// Adds a storage buffer variable to the module + /// Adds a storage buffer variable to the program /// @param name the name of the variable /// @param type the type to use /// @param group the binding/group to use for the storage buffer @@ -398,7 +398,7 @@ class InspectorHelper : public ast::BuilderWithModule { ast::FunctionDecorationList{}); } - /// Adds a regular sampler variable to the module + /// Adds a regular sampler variable to the program /// @param name the name of the variable /// @param group the binding/group to use for the storage buffer /// @param binding the binding number to use for the storage buffer @@ -407,7 +407,7 @@ class InspectorHelper : public ast::BuilderWithModule { binding); } - /// Adds a comparison sampler variable to the module + /// Adds a comparison sampler variable to the program /// @param name the name of the variable /// @param group the binding/group to use for the storage buffer /// @param binding the binding number to use for the storage buffer @@ -444,7 +444,7 @@ class InspectorHelper : public ast::BuilderWithModule { return create(dim, type); } - /// Adds a sampled texture variable to the module + /// Adds a sampled texture variable to the program /// @param name the name of the variable /// @param type the type to use /// @param group the binding/group to use for the sampled texture @@ -456,7 +456,7 @@ class InspectorHelper : public ast::BuilderWithModule { AddBinding(name, type, ast::StorageClass::kUniformConstant, group, binding); } - /// Adds a multi-sampled texture variable to the module + /// Adds a multi-sampled texture variable to the program /// @param name the name of the variable /// @param type the type to use /// @param group the binding/group to use for the multi-sampled texture @@ -473,7 +473,7 @@ class InspectorHelper : public ast::BuilderWithModule { Var(name, ast::StorageClass::kUniformConstant, type)); } - /// Adds a depth texture variable to the module + /// Adds a depth texture variable to the program /// @param name the name of the variable /// @param type the type to use void AddDepthTexture(const std::string& name, type::Type* type) { diff --git a/src/namer.cc b/src/namer.cc index f5f56004ca..405a56aea1 100644 --- a/src/namer.cc +++ b/src/namer.cc @@ -22,7 +22,7 @@ namespace tint { -Namer::Namer(ast::Module* mod) : module_(mod) {} +Namer::Namer(Program* program) : program_(program) {} Namer::~Namer() = default; @@ -42,7 +42,7 @@ std::string Namer::GenerateName(const std::string& prefix) { return name; } -MangleNamer::MangleNamer(ast::Module* mod) : Namer(mod) {} +MangleNamer::MangleNamer(Program* program) : Namer(program) {} MangleNamer::~MangleNamer() = default; @@ -50,12 +50,12 @@ std::string MangleNamer::NameFor(const Symbol& sym) { return sym.to_str(); } -UnsafeNamer::UnsafeNamer(ast::Module* mod) : Namer(mod) {} +UnsafeNamer::UnsafeNamer(Program* program) : Namer(program) {} UnsafeNamer::~UnsafeNamer() = default; std::string UnsafeNamer::NameFor(const Symbol& sym) { - return module_->SymbolToName(sym); + return program_->SymbolToName(sym); } } // namespace tint diff --git a/src/namer.h b/src/namer.h index 8d05eb2f34..c818c3f3c5 100644 --- a/src/namer.h +++ b/src/namer.h @@ -19,7 +19,7 @@ #include #include -#include "src/ast/module.h" +#include "src/program.h" namespace tint { @@ -27,8 +27,8 @@ namespace tint { class Namer { public: /// Constructor - /// @param mod the module this namer works with - explicit Namer(ast::Module* mod); + /// @param program the program this namer works with + explicit Namer(Program* program); /// Destructor virtual ~Namer(); @@ -48,8 +48,8 @@ class Namer { /// @returns true if `name` has already been used bool IsUsed(const std::string& name); - /// The module storing the symbol table - ast::Module* module_ = nullptr; + /// The program storing the symbol table + Program* program_ = nullptr; private: // The list of names taken by the remapper @@ -60,8 +60,8 @@ class Namer { class MangleNamer : public Namer { public: /// Constructor - /// @param mod the module to retrieve names from - explicit MangleNamer(ast::Module* mod); + /// @param program the program to retrieve names from + explicit MangleNamer(Program* program); /// Destructor ~MangleNamer() override; @@ -77,8 +77,8 @@ class MangleNamer : public Namer { class UnsafeNamer : public Namer { public: /// Constructor - /// @param mod the module to retrieve names from - explicit UnsafeNamer(ast::Module* mod); + /// @param program the program to retrieve names from + explicit UnsafeNamer(Program* program); /// Destructor ~UnsafeNamer() override; diff --git a/src/namer_test.cc b/src/namer_test.cc index 5a318f7df0..552a959de1 100644 --- a/src/namer_test.cc +++ b/src/namer_test.cc @@ -15,7 +15,7 @@ #include "src/namer.h" #include "gtest/gtest.h" -#include "src/ast/module.h" +#include "src/program.h" namespace tint { namespace { @@ -23,7 +23,7 @@ namespace { using NamerTest = testing::Test; TEST_F(NamerTest, GenerateName) { - ast::Module m; + Program m; MangleNamer n(&m); EXPECT_EQ("name", n.GenerateName("name")); EXPECT_EQ("name_0", n.GenerateName("name")); @@ -33,7 +33,7 @@ TEST_F(NamerTest, GenerateName) { using MangleNamerTest = testing::Test; TEST_F(MangleNamerTest, ReturnsName) { - ast::Module m; + Program m; auto s = m.RegisterSymbol("my_sym"); MangleNamer n(&m); @@ -41,7 +41,7 @@ TEST_F(MangleNamerTest, ReturnsName) { } TEST_F(MangleNamerTest, ReturnsSameValueForSameName) { - ast::Module m; + Program m; auto s1 = m.RegisterSymbol("my_sym"); auto s2 = m.RegisterSymbol("my_sym2"); @@ -53,7 +53,7 @@ TEST_F(MangleNamerTest, ReturnsSameValueForSameName) { using UnsafeNamerTest = testing::Test; TEST_F(UnsafeNamerTest, ReturnsName) { - ast::Module m; + Program m; auto s = m.RegisterSymbol("my_sym"); UnsafeNamer n(&m); diff --git a/src/program.cc b/src/program.cc new file mode 100644 index 0000000000..b2abaa4d2c --- /dev/null +++ b/src/program.cc @@ -0,0 +1,128 @@ +// Copyright 2021 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/program.h" + +#include + +#include "src/clone_context.h" +#include "src/type/struct_type.h" + +namespace tint { + +Program::Program() = default; + +Program::Program(Program&&) = default; + +Program& Program::operator=(Program&& rhs) = default; + +Program::~Program() = default; + +Program Program::Clone() const { + Program out; + CloneContext(&out, this).Clone(); + return out; +} + +void Program::Clone(CloneContext* ctx) const { + for (auto* ty : constructed_types_) { + ctx->dst->constructed_types_.emplace_back(ctx->Clone(ty)); + } + for (auto* var : global_variables_) { + ctx->dst->global_variables_.emplace_back(ctx->Clone(var)); + } + for (auto* func : functions_) { + ctx->dst->functions_.emplace_back(ctx->Clone(func)); + } +} + +Symbol Program::RegisterSymbol(const std::string& name) { + return symbol_table_.Register(name); +} + +Symbol Program::GetSymbol(const std::string& name) const { + return symbol_table_.GetSymbol(name); +} + +std::string Program::SymbolToName(const Symbol sym) const { + return symbol_table_.NameFor(sym); +} + +bool Program::IsValid() const { + for (auto* var : global_variables_) { + if (var == nullptr || !var->IsValid()) { + return false; + } + } + for (auto* const ty : constructed_types_) { + if (ty == nullptr) { + return false; + } + if (auto* alias = ty->As()) { + if (alias->type() == nullptr) { + return false; + } + if (auto* str = alias->type()->As()) { + if (!str->symbol().IsValid()) { + return false; + } + } + } else if (auto* str = ty->As()) { + if (!str->symbol().IsValid()) { + return false; + } + } else { + return false; + } + } + for (auto* func : functions_) { + if (func == nullptr || !func->IsValid()) { + return false; + } + } + return true; +} + +std::string Program::to_str() const { + std::ostringstream out; + + out << "Module{" << std::endl; + const auto indent = 2; + for (auto* const ty : constructed_types_) { + for (size_t i = 0; i < indent; ++i) { + out << " "; + } + if (auto* alias = ty->As()) { + out << alias->symbol().to_str() << " -> " << alias->type()->type_name() + << std::endl; + if (auto* str = alias->type()->As()) { + str->impl()->to_str(out, indent); + } + } else if (auto* str = ty->As()) { + out << str->symbol().to_str() << " "; + str->impl()->to_str(out, indent); + } + } + for (auto* var : global_variables_) { + var->to_str(out, indent); + } + for (auto* func : functions_) { + func->to_str(out, indent); + } + out << "}" << std::endl; + + return out.str(); +} + +} // namespace tint diff --git a/src/program.h b/src/program.h index 31c7f0328b..e232c3b11d 100644 --- a/src/program.h +++ b/src/program.h @@ -15,25 +15,151 @@ #ifndef SRC_PROGRAM_H_ #define SRC_PROGRAM_H_ +#include +#include #include +#include +#include +#include +#include -#include "src/ast/module.h" +#include "src/ast/function.h" +#include "src/ast/variable.h" +#include "src/block_allocator.h" +#include "src/symbol_table.h" +#include "src/traits.h" +#include "src/type/alias_type.h" +#include "src/type/type_manager.h" namespace tint { -/// Program is (currently) a simple wrapper of to ast::Module. -/// This wrapper is used as a stepping stone to having Dawn use tint::Program -/// instead of tint::ast::Module. +/// Represents all the source in a given program. class Program { public: - /// The wrapped module - ast::Module module; + /// Constructor + Program(); - /// @returns true if all required fields in the module are present. - bool IsValid() const { return module.IsValid(); } + /// Move constructor + Program(Program&&); + + /// Move assignment operator + /// @param rhs the Program to move + /// @return this Program + Program& operator=(Program&& rhs); + + /// Destructor + ~Program(); /// @return a deep copy of this program - Program Clone() const { return Program{module.Clone()}; } + Program Clone() const; + + /// Clone this program into `ctx->mod` using the provided CloneContext + /// The program will be cloned in this order: + /// * Constructed types + /// * Global variables + /// * Functions + /// @param ctx the clone context + void Clone(CloneContext* ctx) const; + + /// Add a global variable to the program + /// @param var the variable to add + void AddGlobalVariable(ast::Variable* var) { + global_variables_.push_back(var); + } + /// @returns the global variables for the program + const ast::VariableList& global_variables() const { + return global_variables_; + } + + /// @returns the global variables for the program + ast::VariableList& global_variables() { return global_variables_; } + + /// Adds a constructed type to the program. + /// The type must be an alias or a struct. + /// @param type the constructed type to add + void AddConstructedType(type::Type* type) { + constructed_types_.push_back(type); + } + /// @returns the constructed types in the program + const std::vector& constructed_types() const { + return constructed_types_; + } + + /// @returns the functions declared in the translation unit + const ast::FunctionList& Functions() const { return functions_; } + + /// @returns the functions declared in the translation unit + ast::FunctionList& Functions() { return functions_; } + + /// @returns true if all required fields in the AST are present. + bool IsValid() const; + + /// @returns a string representation of the program + std::string to_str() const; + + /// Creates a new Node owned by the Program. When the Program is + /// destructed, the Node will also be destructed. + /// @param args the arguments to pass to the type constructor + /// @returns the node pointer + template + traits::EnableIfIsType* create(ARGS&&... args) { + return ast_nodes_.Create(std::forward(args)...); + } + + /// Creates a new type::Type owned by the Program. + /// When the Program is destructed, owned Program and the returned + /// `Type` will also be destructed. + /// Types are unique (de-aliased), and so calling create() for the same `T` + /// and arguments will return the same pointer. + /// @warning Use this method to acquire a type only if all of its type + /// information is provided in the constructor arguments `args`.
+ /// If the type requires additional configuration after construction that + /// affect its fundamental type, build the type with `std::make_unique`, make + /// any necessary alterations and then call unique_type() instead. + /// @param args the arguments to pass to the type constructor + /// @returns the de-aliased type pointer + template + traits::EnableIfIsType* create(ARGS&&... args) { + static_assert(std::is_base_of::value, + "T does not derive from type::Type"); + return type_mgr_.Get(std::forward(args)...); + } + + /// Returns all the declared types in the program + /// @returns the mapping from name string to type. + const std::unordered_map& types() { + return type_mgr_.types(); + } + + /// @returns all the declared nodes in the program + BlockAllocator::View nodes() { return ast_nodes_.Objects(); } + + /// Registers `name` as a symbol + /// @param name the name to register + /// @returns the symbol for the `name`. If `name` is already registered the + /// previously generated symbol will be returned. + Symbol RegisterSymbol(const std::string& name); + + /// Returns the symbol for `name` + /// @param name the name to lookup + /// @returns the symbol for name or symbol::kInvalid + Symbol GetSymbol(const std::string& name) const; + + /// Returns the `name` for `sym` + /// @param sym the symbol to retrieve the name for + /// @returns the use provided `name` for the symbol or "" if not found + std::string SymbolToName(const Symbol sym) const; + + private: + Program(const Program&) = delete; + + SymbolTable symbol_table_; + ast::VariableList global_variables_; + // The constructed types are owned by the type manager + std::vector constructed_types_; + ast::FunctionList functions_; + BlockAllocator ast_nodes_; + type::Manager type_mgr_; }; } // namespace tint diff --git a/src/ast/module_test.cc b/src/program_test.cc similarity index 69% rename from src/ast/module_test.cc rename to src/program_test.cc index 399a442a07..8cc57173d6 100644 --- a/src/ast/module_test.cc +++ b/src/program_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/module.h" +#include "src/program.h" #include #include @@ -26,82 +26,81 @@ #include "src/type/struct_type.h" namespace tint { -namespace ast { namespace { -using ModuleTest = TestHelper; +using ProgramTest = ast::TestHelper; -TEST_F(ModuleTest, Creation) { +TEST_F(ProgramTest, Creation) { EXPECT_EQ(mod->Functions().size(), 0u); } -TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) { +TEST_F(ProgramTest, ToStrEmitsPreambleAndPostamble) { const auto str = mod->to_str(); auto* const expected = "Module{\n}\n"; EXPECT_EQ(str, expected); } -TEST_F(ModuleTest, IsValid_Empty) { +TEST_F(ProgramTest, IsValid_Empty) { EXPECT_TRUE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_GlobalVariable) { - auto* var = Var("var", StorageClass::kInput, ty.f32); +TEST_F(ProgramTest, IsValid_GlobalVariable) { + auto* var = Var("var", ast::StorageClass::kInput, ty.f32); mod->AddGlobalVariable(var); EXPECT_TRUE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Null_GlobalVariable) { +TEST_F(ProgramTest, IsValid_Null_GlobalVariable) { mod->AddGlobalVariable(nullptr); EXPECT_FALSE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) { - auto* var = Var("var", StorageClass::kInput, nullptr); +TEST_F(ProgramTest, IsValid_Invalid_GlobalVariable) { + auto* var = Var("var", ast::StorageClass::kInput, nullptr); mod->AddGlobalVariable(var); EXPECT_FALSE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Alias) { +TEST_F(ProgramTest, IsValid_Alias) { auto* alias = ty.alias("alias", ty.f32); mod->AddConstructedType(alias); EXPECT_TRUE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Null_Alias) { +TEST_F(ProgramTest, IsValid_Null_Alias) { mod->AddConstructedType(nullptr); EXPECT_FALSE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Struct) { +TEST_F(ProgramTest, IsValid_Struct) { auto* st = ty.struct_("name", {}); auto* alias = ty.alias("name", st); mod->AddConstructedType(alias); EXPECT_TRUE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Struct_EmptyName) { +TEST_F(ProgramTest, IsValid_Struct_EmptyName) { auto* st = ty.struct_("", {}); auto* alias = ty.alias("name", st); mod->AddConstructedType(alias); EXPECT_FALSE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Function) { - auto* func = Func("main", VariableList(), ty.f32, StatementList{}, +TEST_F(ProgramTest, IsValid_Function) { + auto* func = Func("main", ast::VariableList(), ty.f32, ast::StatementList{}, ast::FunctionDecorationList{}); mod->Functions().Add(func); EXPECT_TRUE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Null_Function) { +TEST_F(ProgramTest, IsValid_Null_Function) { mod->Functions().Add(nullptr); EXPECT_FALSE(mod->IsValid()); } -TEST_F(ModuleTest, IsValid_Invalid_Function) { - auto* func = Func("main", VariableList{}, nullptr, StatementList{}, +TEST_F(ProgramTest, IsValid_Invalid_Function) { + auto* func = Func("main", ast::VariableList{}, nullptr, ast::StatementList{}, ast::FunctionDecorationList{}); mod->Functions().Add(func); @@ -109,5 +108,4 @@ TEST_F(ModuleTest, IsValid_Invalid_Function) { } } // namespace -} // namespace ast } // namespace tint diff --git a/src/reader/reader.h b/src/reader/reader.h index a852dd047c..008d780af0 100644 --- a/src/reader/reader.h +++ b/src/reader/reader.h @@ -18,7 +18,6 @@ #include #include -#include "src/ast/module.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" #include "src/program.h" @@ -47,11 +46,8 @@ class Reader { /// @returns the full list of diagnostic messages. const diag::List& diagnostics() const { return diags_; } - /// @returns the module. The module in the parser will be reset after this. - virtual ast::Module module() = 0; - - /// @returns the program. The module in the parser will be reset after this. - Program program() { return Program{module()}; } + /// @returns the program. The program in the parser will be reset after this. + virtual Program program() = 0; protected: /// Constructor diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 41fb4bfc75..251a9ec605 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -632,16 +632,16 @@ struct SwitchStatementBuilder /// @param cond the switch statement condition explicit SwitchStatementBuilder(ast::Expression* cond) : condition(cond) {} - /// @param mod the ast Module to build into + /// @param program the program to build into /// @returns the built ast::SwitchStatement - ast::SwitchStatement* Build(ast::Module* mod) const override { + ast::SwitchStatement* Build(Program* program) const override { // We've listed cases in reverse order in the switch statement. // Reorder them to match the presentation order in WGSL. auto reversed_cases = cases; std::reverse(reversed_cases.begin(), reversed_cases.end()); - return mod->create(Source{}, condition, - reversed_cases); + return program->create(Source{}, condition, + reversed_cases); } /// Switch statement condition @@ -658,10 +658,10 @@ struct IfStatementBuilder /// @param c the if-statement condition explicit IfStatementBuilder(ast::Expression* c) : cond(c) {} - /// @param mod the ast Module to build into + /// @param program the program to build into /// @returns the built ast::IfStatement - ast::IfStatement* Build(ast::Module* mod) const override { - return mod->create(Source{}, cond, body, else_stmts); + ast::IfStatement* Build(Program* program) const override { + return program->create(Source{}, cond, body, else_stmts); } /// If-statement condition @@ -676,10 +676,10 @@ struct IfStatementBuilder /// @see StatementBuilder struct LoopStatementBuilder : public Castable { - /// @param mod the ast Module to build into + /// @param program the program to build into /// @returns the built ast::LoopStatement - ast::LoopStatement* Build(ast::Module* mod) const override { - return mod->create(Source{}, body, continuing); + ast::LoopStatement* Build(Program* program) const override { + return program->create(Source{}, body, continuing); } /// Loop-statement block body @@ -717,7 +717,7 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi, const spvtools::opt::Function& function, const EntryPointInfo* ep_info) : parser_impl_(*pi), - ast_module_(pi->get_module()), + program_(pi->get_program()), ir_context_(*(pi->ir_context())), def_use_mgr_(ir_context_.get_def_use_mgr()), constant_mgr_(ir_context_.get_constant_mgr()), @@ -725,7 +725,7 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi, fail_stream_(pi->fail_stream()), namer_(pi->namer()), function_(function), - i32_(ast_module_.create()), + i32_(program_.create()), ep_info_(ep_info) { PushNewStatementBlock(nullptr, 0, nullptr); } @@ -749,12 +749,12 @@ FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) = FunctionEmitter::StatementBlock::~StatementBlock() = default; -void FunctionEmitter::StatementBlock::Finalize(ast::Module* mod) { +void FunctionEmitter::StatementBlock::Finalize(Program* program) { assert(!finalized_ /* Finalize() must only be called once */); for (size_t i = 0; i < statements_.size(); i++) { if (auto* builder = statements_[i]->As()) { - statements_[i] = builder->Build(mod); + statements_[i] = builder->Build(program); } } @@ -786,7 +786,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name, const auto& top = statements_stack_.back(); auto* cond = create( - Source{}, ast_module_.RegisterSymbol(guard_name)); + Source{}, program_.RegisterSymbol(guard_name)); auto* builder = AddStatementBuilder(cond); PushNewStatementBlock( @@ -811,7 +811,7 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) { const ast::StatementList FunctionEmitter::ast_body() { assert(!statements_stack_.empty()); auto& entry = statements_stack_[0]; - entry.Finalize(&ast_module_); + entry.Finalize(&program_); return entry.GetStatements(); } @@ -855,14 +855,13 @@ bool FunctionEmitter::Emit() { << statements_stack_.size(); } - statements_stack_[0].Finalize(&ast_module_); + statements_stack_[0].Finalize(&program_); auto& statements = statements_stack_[0].GetStatements(); auto* body = create(Source{}, statements); - ast_module_.Functions().Add( - create(decl.source, ast_module_.RegisterSymbol(decl.name), - std::move(decl.params), decl.return_type, body, - std::move(decl.decorations))); + program_.Functions().Add(create( + decl.source, program_.RegisterSymbol(decl.name), std::move(decl.params), + decl.return_type, body, std::move(decl.decorations))); // Maintain the invariant by repopulating the one and only element. statements_stack_.clear(); @@ -2013,7 +2012,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) { return TypedExpression{ parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()), create(Source{}, - ast_module_.RegisterSymbol(name))}; + program_.RegisterSymbol(name))}; } if (singly_used_values_.count(id)) { auto expr = std::move(singly_used_values_[id]); @@ -2035,7 +2034,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) { auto name = namer_.Name(inst->result_id()); return TypedExpression{parser_impl_.ConvertType(inst->type_id()), create( - Source{}, ast_module_.RegisterSymbol(name))}; + Source{}, program_.RegisterSymbol(name))}; } default: break; @@ -2079,7 +2078,7 @@ bool FunctionEmitter::EmitBasicBlock(const BlockInfo& block_info) { // Close off previous constructs. while (!statements_stack_.empty() && (statements_stack_.back().GetEndId() == block_info.id)) { - statements_stack_.back().Finalize(&ast_module_); + statements_stack_.back().Finalize(&program_); statements_stack_.pop_back(); } if (statements_stack_.empty()) { @@ -2265,8 +2264,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) { if (!guard_name.empty()) { // Declare the guard variable just before the "if", initialized to true. auto* guard_var = - create(Source{}, // source - ast_module_.RegisterSymbol(guard_name), // symbol + create(Source{}, // source + program_.RegisterSymbol(guard_name), // symbol ast::StorageClass::kFunction, // storage_class parser_impl_.Bool(), // type false, // is_const @@ -2673,7 +2672,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed( return create( Source{}, create( - Source{}, ast_module_.RegisterSymbol(flow_guard)), + Source{}, program_.RegisterSymbol(flow_guard)), MakeFalse(Source{})); } @@ -2794,7 +2793,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info, assert(!phi_var_name.empty()); auto* var = create( Source{}, // source - ast_module_.RegisterSymbol(phi_var_name), // symbol + program_.RegisterSymbol(phi_var_name), // symbol ast::StorageClass::kFunction, // storage_class parser_impl_.ConvertType(def_inst->type_id()), // type false, // is_const @@ -2832,8 +2831,8 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info, auto expr = MakeExpression(assignment.value); AddStatement(create( Source{}, - create( - Source{}, ast_module_.RegisterSymbol(var_name)), + create(Source{}, + program_.RegisterSymbol(var_name)), expr.expr)); } } @@ -2871,7 +2870,7 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar( AddStatement(create( Source{}, create(Source{}, - ast_module_.RegisterSymbol(name)), + program_.RegisterSymbol(name)), ast_expr.expr)); return true; } @@ -3010,7 +3009,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) { TypedExpression expr{ parser_impl_.ConvertType(inst.type_id()), create( - Source{}, ast_module_.RegisterSymbol(def_info->phi_var))}; + Source{}, program_.RegisterSymbol(def_info->phi_var))}; return EmitConstDefOrWriteToHoistedVar(inst, expr); } @@ -3073,7 +3072,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( create( Source{}, create( - Source{}, ast_module_.RegisterSymbol(unary_builtin_name)), + Source{}, program_.RegisterSymbol(unary_builtin_name)), std::move(params))}; } @@ -3178,8 +3177,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst( return {}; } - auto* func = create( - Source{}, ast_module_.RegisterSymbol(name)); + auto* func = create(Source{}, + program_.RegisterSymbol(name)); ast::ExpressionList operands; type::Type* first_operand_type = nullptr; // All parameters to GLSL.std.450 extended instructions are IDs. @@ -3205,20 +3204,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) { } const char* names[] = {"x", "y", "z", "w"}; return create( - Source{}, ast_module_.RegisterSymbol(names[i & 3])); + Source{}, program_.RegisterSymbol(names[i & 3])); } ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) { switch (n) { case 1: return create(Source{}, - ast_module_.RegisterSymbol("x")); + program_.RegisterSymbol("x")); case 2: - return create( - Source{}, ast_module_.RegisterSymbol("xy")); + return create(Source{}, + program_.RegisterSymbol("xy")); case 3: - return create( - Source{}, ast_module_.RegisterSymbol("xyz")); + return create(Source{}, + program_.RegisterSymbol("xyz")); default: break; } @@ -3313,7 +3312,7 @@ TypedExpression FunctionEmitter::MakeAccessChain( auto name = namer_.Name(base_id); current_expr.expr = create( - Source{}, ast_module_.RegisterSymbol(name)); + Source{}, program_.RegisterSymbol(name)); current_expr.type = parser_impl_.ConvertType(ptr_ty_id); } } @@ -3406,7 +3405,7 @@ TypedExpression FunctionEmitter::MakeAccessChain( auto name = namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val)); auto* member_access = create( - Source{}, ast_module_.RegisterSymbol(name)); + Source{}, program_.RegisterSymbol(name)); next_expr = create( Source{}, current_expr.expr, member_access); @@ -3527,7 +3526,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract( } auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val)); auto* member_access = create( - Source{}, ast_module_.RegisterSymbol(name)); + Source{}, program_.RegisterSymbol(name)); next_expr = create( Source{}, current_expr.expr, member_access); @@ -3700,7 +3699,7 @@ type::Type* FunctionEmitter::RemapStorageClass(type::Type* type, // buffer pointer. const auto sc = GetStorageClassForPointerValue(result_id); if (ast_ptr_type->storage_class() != sc) { - return parser_impl_.get_module().create( + return parser_impl_.get_program().create( ast_ptr_type->type(), sc); } } @@ -3932,7 +3931,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) { // We ignore function attributes such as Inline, DontInline, Pure, Const. auto name = namer_.Name(inst.GetSingleWordInOperand(0)); auto* function = create( - Source{}, ast_module_.RegisterSymbol(name)); + Source{}, program_.RegisterSymbol(name)); ast::ExpressionList params; for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) { @@ -3961,7 +3960,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall( ss << intrinsic; auto name = ss.str(); auto* ident = create( - Source{}, ast_module_.RegisterSymbol(name)); + Source{}, program_.RegisterSymbol(name)); ident->set_intrinsic(intrinsic); ast::ExpressionList params; @@ -4004,12 +4003,11 @@ TypedExpression FunctionEmitter::MakeSimpleSelect( params.push_back(operand2.expr); // The condition goes last. params.push_back(condition.expr); - return {operand1.type, - create( - Source{}, - create( - Source{}, ast_module_.RegisterSymbol("select")), - std::move(params))}; + return {operand1.type, create( + Source{}, + create( + Source{}, program_.RegisterSymbol("select")), + std::move(params))}; } return {}; } @@ -4058,7 +4056,7 @@ ast::Expression* FunctionEmitter::GetImageExpression( } auto name = namer_.Name(image->result_id()); return create(GetSourceForInst(inst), - ast_module_.RegisterSymbol(name)); + program_.RegisterSymbol(name)); } ast::Expression* FunctionEmitter::GetSamplerExpression( @@ -4074,7 +4072,7 @@ ast::Expression* FunctionEmitter::GetSamplerExpression( } auto name = namer_.Name(image->result_id()); return create(GetSourceForInst(inst), - ast_module_.RegisterSymbol(name)); + program_.RegisterSymbol(name)); } bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { @@ -4261,7 +4259,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { } auto* ident = create( - Source{}, ast_module_.RegisterSymbol(builtin_name)); + Source{}, program_.RegisterSymbol(builtin_name)); auto* call_expr = create(Source{}, ident, std::move(params)); @@ -4569,14 +4567,14 @@ TypedExpression FunctionEmitter::MakeArrayLength( } auto* member_ident = create( - Source{}, ast_module_.RegisterSymbol(field_name)); + Source{}, program_.RegisterSymbol(field_name)); auto* member_access = create( Source{}, MakeExpression(struct_ptr_id).expr, member_ident); // Generate the intrinsic function call. std::string call_ident_str = "arrayLength"; auto* call_ident = create( - Source{}, ast_module_.RegisterSymbol(call_ident_str)); + Source{}, program_.RegisterSymbol(call_ident_str)); call_ident->set_intrinsic(ast::Intrinsic::kArrayLength); ast::ExpressionList params{member_access}; diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index 66500599f7..a7a0ddd7cf 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -33,9 +33,9 @@ #include "src/ast/case_statement.h" #include "src/ast/expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/statement.h" #include "src/ast/storage_class.h" +#include "src/program.h" #include "src/reader/spirv/construct.h" #include "src/reader/spirv/entry_point_info.h" #include "src/reader/spirv/fail_stream.h" @@ -345,9 +345,9 @@ class StatementBuilder : public Castable { /// Constructor StatementBuilder() : Base(Source{}) {} - /// @param mod the ast Module to build into - /// @returns the build AST node - virtual ast::Statement* Build(ast::Module* mod) const = 0; + /// @param program the program to build into + /// @returns the built AST node + virtual ast::Statement* Build(Program* program) const = 0; private: bool IsValid() const override; @@ -355,15 +355,15 @@ class StatementBuilder : public Castable { void to_str(std::ostream& out, size_t indent) const override; }; -/// A FunctionEmitter emits a SPIR-V function onto a Tint AST module. +/// A FunctionEmitter emits a SPIR-V function onto a Tint program. class FunctionEmitter { public: - /// Creates a FunctionEmitter, and prepares to write to the AST module + /// Creates a FunctionEmitter, and prepares to write to the program /// in `pi` /// @param pi a ParserImpl which has already executed BuildInternalModule /// @param function the function to emit FunctionEmitter(ParserImpl* pi, const spvtools::opt::Function& function); - /// Creates a FunctionEmitter, and prepares to write to the AST module + /// Creates a FunctionEmitter, and prepares to write to the program /// in `pi` /// @param pi a ParserImpl which has already executed BuildInternalModule /// @param function the function to emit @@ -374,7 +374,7 @@ class FunctionEmitter { /// Destructor ~FunctionEmitter(); - /// Emits the function to AST module. + /// Emits the function to program. /// @return whether emission succeeded bool Emit(); @@ -964,8 +964,8 @@ class FunctionEmitter { /// Replaces any StatementBuilders with the built result, and calls the /// completion callback (if set). Must only be called once, after all /// statements have been added with Add(). - /// @param mod the module - void Finalize(ast::Module* mod); + /// @param program the program + void Finalize(Program* program); /// Add() adds `statement` to the block. /// Add() must not be called after calling Finalize(). @@ -1049,13 +1049,13 @@ class FunctionEmitter { /// @returns the node pointer template T* create(ARGS&&... args) const { - return ast_module_.create(std::forward(args)...); + return program_.create(std::forward(args)...); } using StatementsStack = std::vector; ParserImpl& parser_impl_; - ast::Module& ast_module_; + Program& program_; spvtools::opt::IRContext& ir_context_; spvtools::opt::analysis::DefUseManager* def_use_mgr_; spvtools::opt::analysis::ConstantManager* constant_mgr_; diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc index b5c5f20e8c..e034ed07c4 100644 --- a/src/reader/spirv/function_arithmetic_test.cc +++ b/src/reader/spirv/function_arithmetic_test.cc @@ -139,7 +139,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -151,7 +151,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { @@ -166,7 +166,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -180,7 +180,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { @@ -195,7 +195,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -209,7 +209,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { @@ -224,7 +224,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -240,7 +240,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { @@ -255,7 +255,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -271,7 +271,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { @@ -286,7 +286,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -304,7 +304,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { @@ -319,7 +319,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -337,7 +337,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { @@ -352,7 +352,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -372,7 +372,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, FNegate_Scalar) { @@ -387,7 +387,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -399,7 +399,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryArithTest, FNegate_Vector) { @@ -414,7 +414,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -430,7 +430,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } struct BinaryData { @@ -478,7 +478,7 @@ TEST_P(SpvBinaryArithTest, EmitExpression) { << GetParam().ast_type << "\n {\n Binary[not set]{" << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_rhs; - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str())) + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str())) << assembly; } @@ -701,7 +701,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) { << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -736,7 +736,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) { << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -759,7 +759,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } INSTANTIATE_TEST_SUITE_P( @@ -847,7 +847,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) { << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -882,7 +882,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -905,7 +905,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } INSTANTIATE_TEST_SUITE_P( @@ -935,7 +935,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -948,7 +948,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { @@ -965,7 +965,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -978,7 +978,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { @@ -995,7 +995,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -1008,7 +1008,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { @@ -1025,7 +1025,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -1038,7 +1038,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { @@ -1055,7 +1055,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -1068,7 +1068,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, Dot) { @@ -1085,7 +1085,7 @@ TEST_F(SpvBinaryArithTestBasic, Dot) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_3 none @@ -1100,7 +1100,7 @@ TEST_F(SpvBinaryArithTestBasic, Dot) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvBinaryArithTestBasic, OuterProduct) { @@ -1119,7 +1119,7 @@ TEST_F(SpvBinaryArithTestBasic, OuterProduct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(got, HasSubstr(R"(VariableConst{ x_3 none diff --git a/src/reader/spirv/function_bit_test.cc b/src/reader/spirv/function_bit_test.cc index 3565456607..b54067d044 100644 --- a/src/reader/spirv/function_bit_test.cc +++ b/src/reader/spirv/function_bit_test.cc @@ -163,7 +163,7 @@ TEST_P(SpvBinaryBitTest, EmitExpression) { << GetParam().ast_type << "\n {\n Binary[not set]{" << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_rhs; - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str())) + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str())) << assembly; } @@ -401,7 +401,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -413,7 +413,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_Int_Uint) { @@ -428,7 +428,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -442,7 +442,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_Uint_Int) { @@ -457,7 +457,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -471,7 +471,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { @@ -486,7 +486,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -498,7 +498,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { @@ -513,7 +513,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -529,7 +529,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { @@ -544,7 +544,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -562,7 +562,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { @@ -577,7 +577,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -595,7 +595,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { const auto assembly = CommonTypes() + R"( @@ -609,7 +609,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -625,7 +625,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } std::string BitTestPreamble() { @@ -664,7 +664,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -692,7 +692,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -722,7 +722,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -752,7 +752,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -780,7 +780,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -808,7 +808,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -838,7 +838,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -868,7 +868,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -896,7 +896,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -924,7 +924,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -954,7 +954,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Uint) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -984,7 +984,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Int) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1012,7 +1012,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1040,7 +1040,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1070,7 +1070,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_UintVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1100,7 +1100,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_IntVector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body = ToString(p->get_module(), fe.ast_body()); + const auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 diff --git a/src/reader/spirv/function_call_test.cc b/src/reader/spirv/function_call_test.cc index 251bafca09..d830d7caf4 100644 --- a/src/reader/spirv/function_call_test.cc +++ b/src/reader/spirv/function_call_test.cc @@ -46,8 +46,8 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) { OpFunctionEnd )")); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); - const auto module_ast_str = p->get_module().to_str(); - EXPECT_THAT(module_ast_str, Eq(R"(Module{ + const auto program_ast_str = p->get_program().to_str(); + EXPECT_THAT(program_ast_str, Eq(R"(Module{ Function tint_symbol_1 -> __void () { @@ -64,7 +64,7 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) { Return{} } } -)")) << module_ast_str; +)")) << program_ast_str; } TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) { @@ -90,7 +90,7 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) { { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -106,17 +106,17 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) { } } Return{})")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Return{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(Return{ { ScalarConstructor[not set]{42} } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } } @@ -147,7 +147,7 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) { { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_10 @@ -178,16 +178,16 @@ Assignment{ Identifier[not set]{x_1} } Return{})")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Return{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(Return{ { ScalarConstructor[not set]{42} } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } } @@ -216,9 +216,9 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) { )")); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); - const auto module_ast_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{ + const auto program_ast_str = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program_ast_str, HasSubstr(R"(Module{ Function x_50 -> __u32 ( VariableConst{ @@ -264,7 +264,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) { } Return{} } -})")) << module_ast_str; +})")) << program_ast_str; } } // namespace diff --git a/src/reader/spirv/function_cfg_test.cc b/src/reader/spirv/function_cfg_test.cc index cc5bdf977a..693dbe6dd1 100644 --- a/src/reader/spirv/function_cfg_test.cc +++ b/src/reader/spirv/function_cfg_test.cc @@ -7361,7 +7361,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromThen_ForwardWithinThen) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -7473,7 +7473,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromElse_ForwardWithinElse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -7600,7 +7600,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly; - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -7791,7 +7791,7 @@ TEST_F(SpvParserTest, EmitBody_If_Empty) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -7827,7 +7827,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_NoElse) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -7875,7 +7875,7 @@ TEST_F(SpvParserTest, EmitBody_If_NoThen_Else) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -7931,7 +7931,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -7998,7 +7998,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else_Premerge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8070,7 +8070,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Premerge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8134,7 +8134,7 @@ TEST_F(SpvParserTest, EmitBody_If_Else_Premerge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8219,7 +8219,7 @@ TEST_F(SpvParserTest, EmitBody_If_Nest_If) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8309,7 +8309,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_TrueBackedge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8364,7 +8364,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_FalseBackedge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8415,7 +8415,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_BothBackedge) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8458,7 +8458,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_UnconditionalBackege) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8509,7 +8509,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_SingleBlockContinue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8574,7 +8574,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_MultiBlockContinue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8648,7 +8648,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_ContinueNestIf) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8720,7 +8720,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_MultiBlockContinueIsEntireLoop) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -8778,7 +8778,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Never) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -8838,7 +8838,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_TrueToBody_FalseBreaks) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -8905,7 +8905,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_FalseToBody_TrueBreaks) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -8979,7 +8979,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_NestedIfContinue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ If{ ( @@ -9037,7 +9037,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyAlwaysBreaks) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -9086,7 +9086,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -9142,7 +9142,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -9204,7 +9204,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue_Early) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -9266,7 +9266,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse_Early) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -9319,7 +9319,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_NoCases) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9364,7 +9364,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_OneCase) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9418,7 +9418,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_TwoCases) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9478,7 +9478,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_CasesWithDup) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9544,7 +9544,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_NoDupCases) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9615,7 +9615,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_WithDupCase) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9687,7 +9687,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_SintValue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9757,7 +9757,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_UintValue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -9809,7 +9809,7 @@ TEST_F(SpvParserTest, EmitBody_Return_TopLevel) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Return{} )"; ASSERT_EQ(expect, got); @@ -9835,7 +9835,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideIf) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -9875,7 +9875,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideLoop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Return{} } @@ -9905,7 +9905,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_TopLevel) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Return{ { ScalarConstructor[not set]{2} @@ -9944,7 +9944,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_InsideIf) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -10001,7 +10001,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_Loop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Return{ { @@ -10031,7 +10031,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_TopLevel) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Discard{} )"; ASSERT_EQ(expect, got); @@ -10057,7 +10057,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideIf) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -10097,7 +10097,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideLoop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Discard{} } @@ -10119,7 +10119,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_TopLevel) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Return{} )"; ASSERT_EQ(expect, got); @@ -10145,7 +10145,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideIf) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -10185,7 +10185,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideLoop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Return{} } @@ -10215,7 +10215,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InNonVoidFunction) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Return{ { ScalarConstructor[not set]{0} @@ -10249,7 +10249,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_MultiBlockLoop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ continuing { Assignment{ @@ -10284,7 +10284,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_SingleBlockLoop) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -10321,7 +10321,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_LastInCase) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -10381,7 +10381,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_NotLastInCase) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -10452,7 +10452,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopBreak_MultiBlockLoop_FromBody) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -10534,7 +10534,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ continuing { Assignment{ @@ -10576,7 +10576,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_LastInLoopConstruct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ Assignment{ Identifier[not set]{var_1} @@ -10630,7 +10630,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_BeforeLast) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ If{ ( @@ -10699,7 +10699,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_FromSwitch) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -10769,7 +10769,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromThen) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -10812,7 +10812,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromElse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{false} @@ -10864,7 +10864,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Fallthrough) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -10915,7 +10915,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Forward) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11019,7 +11019,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Back_SingleBlock_Back) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11062,7 +11062,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11113,7 +11113,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11171,7 +11171,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11227,7 +11227,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11287,7 +11287,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11348,7 +11348,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11431,7 +11431,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnTrue) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11526,7 +11526,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnFalse) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11611,7 +11611,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11680,7 +11680,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11747,7 +11747,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11821,7 +11821,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -11890,7 +11890,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -11948,7 +11948,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12021,7 +12021,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12117,7 +12117,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12256,7 +12256,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12337,7 +12337,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12405,7 +12405,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Continue_FromHeader) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12462,7 +12462,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12534,7 +12534,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12622,7 +12622,7 @@ TEST_F( ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12701,7 +12701,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopContinue_FromSwitch) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -12789,7 +12789,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12886,7 +12886,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -12982,7 +12982,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -13091,7 +13091,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -13188,7 +13188,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnTrue) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -13269,7 +13269,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnFalse) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -13333,7 +13333,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_IfBreak_IfBreak_Same) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{0} @@ -13418,7 +13418,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Fallthrough_Fallthrough_Same) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -13509,7 +13509,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Forward_Forward_Same) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{var_1} ScalarConstructor[not set]{1} @@ -13578,7 +13578,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = "unhandled case"; ASSERT_EQ(expect, got); } @@ -13613,7 +13613,7 @@ TEST_F(SpvParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = "unhandled case"; ASSERT_EQ(expect, got); } diff --git a/src/reader/spirv/function_composite_test.cc b/src/reader/spirv/function_composite_test.cc index b8f004b680..d292742fda 100644 --- a/src/reader/spirv/function_composite_test.cc +++ b/src/reader/spirv/function_composite_test.cc @@ -86,7 +86,7 @@ TEST_F(SpvParserTest_Composite_Construct, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -128,7 +128,7 @@ VariableDeclStatement{ } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_Composite_Construct, Matrix) { @@ -143,7 +143,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -169,7 +169,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_Composite_Construct, Array) { @@ -184,7 +184,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -200,7 +200,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_Composite_Construct, Struct) { @@ -215,7 +215,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -233,7 +233,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } using SpvParserTest_CompositeExtract = SpvParserTest; @@ -250,7 +250,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -266,7 +266,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CompositeExtract, Vector_IndexTooBigError) { @@ -301,7 +301,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -313,7 +313,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CompositeExtract, Matrix_IndexTooBigError) { @@ -352,7 +352,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -367,7 +367,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CompositeExtract, Array) { @@ -386,7 +386,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -398,7 +398,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CompositeExtract, RuntimeArray_IsError) { @@ -437,7 +437,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -449,7 +449,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { @@ -480,7 +480,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); auto got = fe.ast_body(); - EXPECT_THAT(ToString(p->get_module(), got), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), got), HasSubstr(R"( VariableConst{ x_2 none @@ -492,8 +492,8 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { } } })")) - << ToString(p->get_module(), got); - EXPECT_THAT(ToString(p->get_module(), got), HasSubstr(R"( + << ToString(p->get_program(), got); + EXPECT_THAT(ToString(p->get_program(), got), HasSubstr(R"( VariableConst{ x_4 none @@ -505,7 +505,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { } } })")) - << ToString(p->get_module(), got); + << ToString(p->get_program(), got); } TEST_F(SpvParserTest_CompositeExtract, Struct_IndexTooBigError) { @@ -546,7 +546,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -567,7 +567,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } using SpvParserTest_CopyObject = SpvParserTest; @@ -585,7 +585,7 @@ TEST_F(SpvParserTest_CopyObject, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -605,7 +605,7 @@ VariableDeclStatement{ Identifier[not set]{x_1} } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_CopyObject, Pointer) { @@ -624,7 +624,7 @@ TEST_F(SpvParserTest_CopyObject, Pointer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -644,7 +644,7 @@ VariableDeclStatement{ Identifier[not set]{x_1} } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } using SpvParserTest_VectorShuffle = SpvParserTest; @@ -665,7 +665,7 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -692,7 +692,7 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { @@ -708,7 +708,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -751,7 +751,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { @@ -768,7 +768,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_10 none @@ -784,7 +784,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest_VectorShuffle, IndexTooBig_IsError) { diff --git a/src/reader/spirv/function_conversion_test.cc b/src/reader/spirv/function_conversion_test.cc index 5499451096..1e352a254a 100644 --- a/src/reader/spirv/function_conversion_test.cc +++ b/src/reader/spirv/function_conversion_test.cc @@ -82,7 +82,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -93,7 +93,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { @@ -108,7 +108,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -123,7 +123,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) { @@ -238,7 +238,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -250,7 +250,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { @@ -266,7 +266,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -280,7 +280,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { @@ -296,7 +296,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -308,7 +308,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { @@ -324,7 +324,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -338,7 +338,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) { @@ -387,7 +387,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -401,7 +401,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { @@ -417,7 +417,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -429,7 +429,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { @@ -445,7 +445,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -459,7 +459,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { @@ -475,7 +475,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -487,7 +487,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) { @@ -537,7 +537,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -549,7 +549,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { @@ -565,7 +565,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -579,7 +579,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { @@ -595,7 +595,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -607,7 +607,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { @@ -623,7 +623,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -637,7 +637,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) { @@ -687,7 +687,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -701,7 +701,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) { @@ -717,7 +717,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -729,7 +729,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) { @@ -745,7 +745,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -759,7 +759,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) { @@ -775,7 +775,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableConst{ x_1 none @@ -787,7 +787,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } // TODO(dneto): OpSConvert // only if multiple widths diff --git a/src/reader/spirv/function_decl_test.cc b/src/reader/spirv/function_decl_test.cc index 164ab13b09..6d83356356 100644 --- a/src/reader/spirv/function_decl_test.cc +++ b/src/reader/spirv/function_decl_test.cc @@ -59,7 +59,7 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.Emit()); - auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str()); + auto got = Demangler().Demangle(p->get_program(), p->get_program().to_str()); std::string expect = R"(Module{ Function x_100 -> __void () @@ -83,7 +83,7 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.Emit()); - auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str()); + auto got = Demangler().Demangle(p->get_program(), p->get_program().to_str()); std::string expect = R"(Module{ Function x_100 -> __f32 () @@ -115,7 +115,7 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.Emit()); - auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str()); + auto got = Demangler().Demangle(p->get_program(), p->get_program().to_str()); std::string expect = R"(Module{ Function x_100 -> __void ( @@ -159,7 +159,7 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.Emit()); - auto got = Demangler().Demangle(p->get_module(), p->get_module().to_str()); + auto got = Demangler().Demangle(p->get_program(), p->get_program().to_str()); std::string expect = R"(Module{ Function x_100 -> __void ( diff --git a/src/reader/spirv/function_glsl_std_450_test.cc b/src/reader/spirv/function_glsl_std_450_test.cc index 78f7932cc6..0706ec652a 100644 --- a/src/reader/spirv/function_glsl_std_450_test.cc +++ b/src/reader/spirv/function_glsl_std_450_test.cc @@ -183,7 +183,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -191,14 +191,14 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) { @@ -212,7 +212,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -220,14 +220,14 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { @@ -241,7 +241,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -249,7 +249,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} Identifier[not set]{f2} @@ -257,7 +257,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { @@ -271,7 +271,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -279,7 +279,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} Identifier[not set]{v2f2} @@ -287,7 +287,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) { @@ -301,7 +301,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -309,14 +309,14 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) { @@ -330,7 +330,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -338,14 +338,14 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { @@ -359,7 +359,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -367,7 +367,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} Identifier[not set]{f2} @@ -375,7 +375,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { @@ -389,7 +389,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -397,7 +397,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} Identifier[not set]{v2f2} @@ -405,7 +405,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { @@ -419,7 +419,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -427,7 +427,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} Identifier[not set]{f2} @@ -436,7 +436,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { @@ -451,7 +451,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -459,7 +459,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} Identifier[not set]{v2f2} @@ -468,7 +468,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) { @@ -482,7 +482,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -490,7 +490,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} Identifier[not set]{u1} @@ -498,7 +498,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) { @@ -513,7 +513,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -521,7 +521,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} Identifier[not set]{v2u1} @@ -529,7 +529,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { @@ -543,7 +543,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -551,7 +551,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{f1} Identifier[not set]{i1} @@ -559,7 +559,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { @@ -574,7 +574,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -582,7 +582,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2f1} Identifier[not set]{v2i1} @@ -590,7 +590,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { @@ -605,7 +605,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -613,7 +613,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v3f1} Identifier[not set]{v3f2} @@ -621,7 +621,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } INSTANTIATE_TEST_SUITE_P(Samples, @@ -709,7 +709,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -717,14 +717,14 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{i1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { @@ -739,7 +739,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -747,14 +747,14 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2i1} ) } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { @@ -769,7 +769,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -777,7 +777,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{i1} Identifier[not set]{i2} @@ -785,7 +785,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { @@ -800,7 +800,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -808,7 +808,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2i1} Identifier[not set]{v2i2} @@ -816,7 +816,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { @@ -831,7 +831,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -839,7 +839,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{i1} Identifier[not set]{i2} @@ -848,7 +848,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { @@ -863,7 +863,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -871,7 +871,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2i1} Identifier[not set]{v2i2} @@ -880,7 +880,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } INSTANTIATE_TEST_SUITE_P(Samples, @@ -907,7 +907,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -915,7 +915,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{u1} Identifier[not set]{u2} @@ -923,7 +923,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { @@ -938,7 +938,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -946,7 +946,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2u1} Identifier[not set]{v2u2} @@ -954,7 +954,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { @@ -968,7 +968,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -976,7 +976,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{u1} Identifier[not set]{u2} @@ -985,7 +985,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { @@ -1000,7 +1000,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -1008,7 +1008,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { { Call[not set]{ Identifier[not set]{)" + GetParam().wgsl_func + - R"(} + R"(} ( Identifier[not set]{v2u1} Identifier[not set]{v2u2} @@ -1017,7 +1017,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } INSTANTIATE_TEST_SUITE_P(Samples, @@ -1043,7 +1043,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SAbs) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1095,7 +1095,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMax) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1153,7 +1153,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMin) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1211,7 +1211,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SClamp) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1271,7 +1271,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMax) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1329,7 +1329,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMin) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 @@ -1387,7 +1387,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UClamp) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto body = ToString(p->get_module(), fe.ast_body()); + auto body = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body, HasSubstr(R"( VariableConst{ x_1 diff --git a/src/reader/spirv/function_logical_test.cc b/src/reader/spirv/function_logical_test.cc index e5171cf818..6cb1f14c39 100644 --- a/src/reader/spirv/function_logical_test.cc +++ b/src/reader/spirv/function_logical_test.cc @@ -206,7 +206,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -218,7 +218,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { @@ -233,7 +233,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -249,7 +249,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } struct BinaryData { @@ -296,7 +296,7 @@ TEST_P(SpvBinaryLogicalTest, EmitExpression) { << GetParam().ast_type << "\n {\n Binary[not set]{" << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_rhs; - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str())) + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(ss.str())) << assembly; } @@ -702,7 +702,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -718,7 +718,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordEqual_Vector) { @@ -733,7 +733,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -757,7 +757,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { @@ -772,7 +772,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -788,7 +788,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { @@ -803,7 +803,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -827,7 +827,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { @@ -842,7 +842,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -858,7 +858,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { @@ -873,7 +873,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -897,7 +897,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { @@ -912,7 +912,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -928,7 +928,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { @@ -943,7 +943,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -967,7 +967,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { @@ -982,7 +982,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -998,7 +998,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { @@ -1013,7 +1013,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -1037,7 +1037,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { @@ -1052,7 +1052,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -1068,7 +1068,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { @@ -1083,7 +1083,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -1107,7 +1107,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) { @@ -1122,7 +1122,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1139,7 +1139,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) { @@ -1154,7 +1154,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1171,7 +1171,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) { @@ -1186,7 +1186,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1203,7 +1203,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) { @@ -1218,7 +1218,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1243,7 +1243,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) { @@ -1258,7 +1258,7 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1287,7 +1287,7 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } using SpvLogicalTest = SpvParserTestBase<::testing::Test>; @@ -1304,7 +1304,7 @@ TEST_F(SpvLogicalTest, Any) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1323,7 +1323,7 @@ TEST_F(SpvLogicalTest, Any) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvLogicalTest, All) { @@ -1338,7 +1338,7 @@ TEST_F(SpvLogicalTest, All) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1357,7 +1357,7 @@ TEST_F(SpvLogicalTest, All) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvLogicalTest, IsNan_Scalar) { @@ -1372,7 +1372,7 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1387,7 +1387,7 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvLogicalTest, IsNan_Vector) { @@ -1402,7 +1402,7 @@ TEST_F(SpvLogicalTest, IsNan_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1421,7 +1421,7 @@ TEST_F(SpvLogicalTest, IsNan_Vector) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvLogicalTest, IsInf_Scalar) { @@ -1436,7 +1436,7 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1451,7 +1451,7 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvLogicalTest, IsInf_Vector) { @@ -1466,7 +1466,7 @@ TEST_F(SpvLogicalTest, IsInf_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1485,7 +1485,7 @@ TEST_F(SpvLogicalTest, IsInf_Vector) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } // TODO(dneto): Kernel-guarded instructions. diff --git a/src/reader/spirv/function_memory_test.cc b/src/reader/spirv/function_memory_test.cc index 29023df553..bc9e7f9a7b 100644 --- a/src/reader/spirv/function_memory_test.cc +++ b/src/reader/spirv/function_memory_test.cc @@ -51,7 +51,8 @@ TEST_F(SpvParserTest, EmitStatement_StoreBoolConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{true} } @@ -83,7 +84,8 @@ TEST_F(SpvParserTest, EmitStatement_StoreUintConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{42} } @@ -111,7 +113,8 @@ TEST_F(SpvParserTest, EmitStatement_StoreIntConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{42} } @@ -139,7 +142,8 @@ TEST_F(SpvParserTest, EmitStatement_StoreFloatConst) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{42.000000} } @@ -168,7 +172,7 @@ TEST_F(SpvParserTest, EmitStatement_LoadBool) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_2 none @@ -197,7 +201,7 @@ TEST_F(SpvParserTest, EmitStatement_LoadScalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_2 @@ -239,7 +243,7 @@ TEST_F(SpvParserTest, EmitStatement_UseLoadedScalarTwice) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_2 @@ -277,7 +281,8 @@ TEST_F(SpvParserTest, EmitStatement_StoreToModuleScopeVar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{42} })")); @@ -344,13 +349,14 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorSwizzle) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ MemberAccessor[not set]{ Identifier[not set]{myvar} Identifier[not set]{z} } ScalarConstructor[not set]{42} -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorConstOutOfBounds) { @@ -407,7 +413,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorNonConstIndex) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ ArrayAccessor[not set]{ Identifier[not set]{myvar} Identifier[not set]{x_11} @@ -444,7 +451,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Matrix) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ ArrayAccessor[not set]{ Identifier[not set]{myvar} ScalarConstructor[not set]{2} @@ -487,7 +495,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Array) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ ArrayAccessor[not set]{ Identifier[not set]{myvar} ScalarConstructor[not set]{2} @@ -529,7 +538,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ MemberAccessor[not set]{ Identifier[not set]{myvar} Identifier[not set]{age} @@ -577,7 +587,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_DifferOnlyMemberName) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ MemberAccessor[not set]{ Identifier[not set]{myvar} Identifier[not set]{age} @@ -590,7 +601,7 @@ Assignment{ Identifier[not set]{ancientness} } ScalarConstructor[not set]{420.000000} -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitStatement_AccessChain_StructNonConstIndex) { @@ -687,7 +698,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_RuntimeArray) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ ArrayAccessor[not set]{ MemberAccessor[not set]{ Identifier[not set]{myvar} @@ -727,7 +739,8 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Compound_Matrix_Vector) { << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ MemberAccessor[not set]{ ArrayAccessor[not set]{ Identifier[not set]{myvar} @@ -801,7 +814,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly << p->error(); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( RTArr -> __array__u32_stride_4 S Struct{ @@ -836,7 +849,8 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ MemberAccessor[not set]{ Identifier[not set]{myvar} Identifier[not set]{field0} @@ -852,7 +866,7 @@ Assignment{ ScalarConstructor[not set]{1} } ScalarConstructor[not set]{0} -})")) << ToString(p->get_module(), fe.ast_body()) +})")) << ToString(p->get_program(), fe.ast_body()) << p->error(); } @@ -875,7 +889,8 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{ + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), + HasSubstr(R"(Assignment{ ArrayAccessor[not set]{ MemberAccessor[not set]{ Identifier[not set]{myvar} @@ -884,7 +899,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) { ScalarConstructor[not set]{1} } ScalarConstructor[not set]{0} -})")) << ToString(p->get_module(), fe.ast_body()) +})")) << ToString(p->get_program(), fe.ast_body()) << p->error(); } @@ -908,7 +923,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_2 @@ -928,7 +943,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) { Assignment{ Identifier[not set]{x_2} ScalarConstructor[not set]{0} -})")) << ToString(p->get_module(), fe.ast_body()) +})")) << ToString(p->get_program(), fe.ast_body()) << p->error(); } @@ -964,7 +979,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithHoisting) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), Eq(R"(VariableDeclStatement{ Variable{ x_2 @@ -999,7 +1014,7 @@ Assignment{ ScalarConstructor[not set]{0} } Return{} -)")) << ToString(p->get_module(), fe.ast_body()) +)")) << ToString(p->get_program(), fe.ast_body()) << p->error(); } @@ -1052,7 +1067,7 @@ TEST_F(SpvParserTest, ArrayLength) { ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - const auto body_str = ToString(p->get_module(), fe.ast_body()); + const auto body_str = ToString(p->get_program(), fe.ast_body()); EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_1 diff --git a/src/reader/spirv/function_misc_test.cc b/src/reader/spirv/function_misc_test.cc index 2558e49b57..978b1b61bd 100644 --- a/src/reader/spirv/function_misc_test.cc +++ b/src/reader/spirv/function_misc_test.cc @@ -68,7 +68,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_11 @@ -108,7 +108,7 @@ VariableDeclStatement{ ScalarConstructor[not set]{0.000000} } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { @@ -129,7 +129,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_11 @@ -171,7 +171,7 @@ VariableDeclStatement{ } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { @@ -190,7 +190,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_11 @@ -212,7 +212,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { @@ -232,7 +232,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_11 @@ -246,7 +246,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { @@ -265,7 +265,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ VariableConst{ x_11 @@ -281,7 +281,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { } } } -})")) << ToString(p->get_module(), fe.ast_body()); +})")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTestMiscInstruction, OpNop) { @@ -297,8 +297,8 @@ TEST_F(SpvParserTestMiscInstruction, OpNop) { << p->error() << assembly; FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(Return{} -)")) << ToString(p->get_module(), fe.ast_body()); + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), Eq(R"(Return{} +)")) << ToString(p->get_program(), fe.ast_body()); } // Test swizzle generation. @@ -329,7 +329,7 @@ TEST_P(SpvParserSwizzleTest, Sample) { ASSERT_NE(result, nullptr); std::ostringstream ss; result->to_str(ss, 0); - auto str = Demangler().Demangle(p->get_module(), ss.str()); + auto str = Demangler().Demangle(p->get_program(), ss.str()); EXPECT_THAT(str, Eq(GetParam().expected_expr)); } else { EXPECT_EQ(result, nullptr); diff --git a/src/reader/spirv/function_var_test.cc b/src/reader/spirv/function_var_test.cc index 96fab3731b..9707955cdc 100644 --- a/src/reader/spirv/function_var_test.cc +++ b/src/reader/spirv/function_var_test.cc @@ -91,7 +91,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_AnonymousVars) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_1 @@ -130,7 +130,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_NamedVars) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ a @@ -169,7 +169,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MixedTypes) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ a @@ -211,7 +211,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarInitializers) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ a @@ -285,7 +285,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarNullInitializers) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ a @@ -345,7 +345,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -360,7 +360,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) { @@ -384,7 +384,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -431,7 +431,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -446,7 +446,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) { @@ -466,7 +466,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -481,7 +481,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) { @@ -500,7 +500,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -515,7 +515,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) { @@ -535,7 +535,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -550,7 +550,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) { @@ -570,7 +570,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -590,7 +590,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) { @@ -610,7 +610,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitFunctionVariables()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ Variable{ x_200 @@ -630,7 +630,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) { } } } -)")) << ToString(p->get_module(), fe.ast_body()); +)")) << ToString(p->get_program(), fe.ast_body()); } TEST_F(SpvParserTest, @@ -655,7 +655,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ Variable{ @@ -703,7 +703,7 @@ TEST_F(SpvParserTest, EmitStatement_CombinatorialValue_Immediate_UsedTwice) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ Variable{ x_25 @@ -775,7 +775,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ Variable{ x_25 @@ -874,7 +874,7 @@ TEST_F( FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Assignment{ Identifier[not set]{x_1} ScalarConstructor[not set]{0} @@ -992,7 +992,7 @@ TEST_F( // We don't hoist x_1 into its own mutable variable. It is emitted as // a const definition. - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1077,7 +1077,7 @@ TEST_F(SpvParserTest, FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{true} @@ -1164,7 +1164,7 @@ TEST_F( FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(If{ ( ScalarConstructor[not set]{true} @@ -1247,7 +1247,7 @@ TEST_F(SpvParserTest, // We don't hoist x_1 into its own mutable variable. It is emitted as // a const definition. - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ VariableConst{ x_1 @@ -1321,7 +1321,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ VariableDeclStatement{ Variable{ @@ -1465,7 +1465,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(Loop{ VariableDeclStatement{ Variable{ @@ -1623,7 +1623,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_ValueFromLoopBodyAndContinuing) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ VariableConst{ x_101 @@ -1792,7 +1792,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromElseAndThen) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ VariableConst{ x_101 @@ -1914,7 +1914,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromHeaderAndThen) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ VariableConst{ x_101 @@ -2022,7 +2022,7 @@ TEST_F(SpvParserTest, EmitStatement_UseInPhiCountsAsUse) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); - auto got = ToString(p->get_module(), fe.ast_body()); + auto got = ToString(p->get_program(), fe.ast_body()); auto* expect = R"(VariableDeclStatement{ Variable{ x_101_phi diff --git a/src/reader/spirv/parser.cc b/src/reader/spirv/parser.cc index de8078a82c..3fc771042e 100644 --- a/src/reader/spirv/parser.cc +++ b/src/reader/spirv/parser.cc @@ -38,8 +38,8 @@ bool Parser::Parse() { return result; } -ast::Module Parser::module() { - return impl_->module(); +Program Parser::program() { + return impl_->program(); } } // namespace spirv diff --git a/src/reader/spirv/parser.h b/src/reader/spirv/parser.h index 0ace60c83d..842ccbc87a 100644 --- a/src/reader/spirv/parser.h +++ b/src/reader/spirv/parser.h @@ -40,8 +40,8 @@ class Parser : public Reader { /// @returns true if the parse was successful, false otherwise. bool Parse() override; - /// @returns the module. The module in the parser will be reset after this. - ast::Module module() override; + /// @returns the program. The program in the parser will be reset after this. + Program program() override; private: std::unique_ptr impl_; diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 5a3a1d9820..1e9992644a 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -255,7 +255,7 @@ ParserImpl::ParserImpl(const std::vector& spv_binary) : Reader(), spv_binary_(spv_binary), fail_stream_(&success_, &errors_), - bool_type_(ast_module_.create()), + bool_type_(program_.create()), namer_(fail_stream_), enum_converter_(fail_stream_), tools_context_(kInputEnv) { @@ -307,10 +307,10 @@ bool ParserImpl::Parse() { return success_; } -ast::Module ParserImpl::module() { +Program ParserImpl::program() { // TODO(dneto): Should we clear out spv_binary_ here, to reduce // memory usage? - return std::move(ast_module_); + return std::move(program_); } type::Type* ParserImpl::ConvertType(uint32_t type_id) { @@ -344,7 +344,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) { switch (spirv_type->kind()) { case spvtools::opt::analysis::Type::kVoid: - return save(ast_module_.create()); + return save(program_.create()); case spvtools::opt::analysis::Type::kBool: return save(bool_type_); case spvtools::opt::analysis::Type::kInteger: @@ -374,7 +374,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) { case spvtools::opt::analysis::Type::kImage: // Fake it for sampler and texture types. These are handled in an // entirely different way. - return save(ast_module_.create()); + return save(program_.create()); default: break; } @@ -713,8 +713,8 @@ bool ParserImpl::RegisterEntryPoints() { type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Integer* int_ty) { if (int_ty->width() == 32) { - type::Type* signed_ty = ast_module_.create(); - type::Type* unsigned_ty = ast_module_.create(); + type::Type* signed_ty = program_.create(); + type::Type* unsigned_ty = program_.create(); signed_type_for_[unsigned_ty] = signed_ty; unsigned_type_for_[signed_ty] = unsigned_ty; return int_ty->IsSigned() ? signed_ty : unsigned_ty; @@ -726,7 +726,7 @@ type::Type* ParserImpl::ConvertType( type::Type* ParserImpl::ConvertType( const spvtools::opt::analysis::Float* float_ty) { if (float_ty->width() == 32) { - return ast_module_.create(); + return program_.create(); } Fail() << "unhandled float width: " << float_ty->width(); return nullptr; @@ -739,16 +739,16 @@ type::Type* ParserImpl::ConvertType( if (ast_elem_ty == nullptr) { return nullptr; } - auto* this_ty = ast_module_.create(ast_elem_ty, num_elem); + auto* this_ty = program_.create(ast_elem_ty, num_elem); // Generate the opposite-signedness vector type, if this type is integral. if (unsigned_type_for_.count(ast_elem_ty)) { - auto* other_ty = ast_module_.create( + auto* other_ty = program_.create( unsigned_type_for_[ast_elem_ty], num_elem); signed_type_for_[other_ty] = this_ty; unsigned_type_for_[this_ty] = other_ty; } else if (signed_type_for_.count(ast_elem_ty)) { - auto* other_ty = ast_module_.create( - signed_type_for_[ast_elem_ty], num_elem); + auto* other_ty = + program_.create(signed_type_for_[ast_elem_ty], num_elem); unsigned_type_for_[other_ty] = this_ty; signed_type_for_[this_ty] = other_ty; } @@ -765,7 +765,7 @@ type::Type* ParserImpl::ConvertType( if (ast_scalar_ty == nullptr) { return nullptr; } - return ast_module_.create(ast_scalar_ty, num_rows, num_columns); + return program_.create(ast_scalar_ty, num_rows, num_columns); } type::Type* ParserImpl::ConvertType( @@ -947,7 +947,7 @@ type::Type* ParserImpl::ConvertType( } const auto member_name = namer_.GetMemberName(type_id, member_index); auto* ast_struct_member = create( - Source{}, ast_module_.RegisterSymbol(member_name), ast_member_ty, + Source{}, program_.RegisterSymbol(member_name), ast_member_ty, std::move(ast_member_decorations)); ast_members.push_back(ast_struct_member); } @@ -963,13 +963,13 @@ type::Type* ParserImpl::ConvertType( namer_.SuggestSanitizedName(type_id, "S"); auto name = namer_.GetName(type_id); - auto* result = ast_module_.create( - ast_module_.RegisterSymbol(name), ast_struct); + auto* result = + program_.create(program_.RegisterSymbol(name), ast_struct); id_to_type_[type_id] = result; if (num_non_writable_members == members.size()) { read_only_struct_types_.insert(result); } - ast_module_.AddConstructedType(result); + program_.AddConstructedType(result); return result; } @@ -1003,7 +1003,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id, ast_storage_class = ast::StorageClass::kStorage; remap_buffer_block_type_.insert(type_id); } - return ast_module_.create(ast_elem_ty, ast_storage_class); + return program_.create(ast_elem_ty, ast_storage_class); } bool ParserImpl::RegisterTypes() { @@ -1091,7 +1091,7 @@ bool ParserImpl::EmitScalarSpecConstants() { MakeVariable(inst.result_id(), ast::StorageClass::kNone, ast_type, true, ast_expr, std::move(spec_id_decos)); if (ast_var) { - ast_module_.AddGlobalVariable(ast_var); + program_.AddGlobalVariable(ast_var); scalar_spec_constants_.insert(inst.result_id()); } } @@ -1129,11 +1129,11 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id, return; } const auto name = namer_.GetName(type_id); - auto* ast_alias_type = ast_module_.create( - ast_module_.RegisterSymbol(name), ast_underlying_type); + auto* ast_alias_type = program_.create( + program_.RegisterSymbol(name), ast_underlying_type); // Record this new alias as the AST type for this SPIR-V ID. id_to_type_[type_id] = ast_alias_type; - ast_module_.AddConstructedType(ast_alias_type); + program_.AddConstructedType(ast_alias_type); } bool ParserImpl::EmitModuleScopeVariables() { @@ -1209,7 +1209,7 @@ bool ParserImpl::EmitModuleScopeVariables() { ast_constructor, ast::VariableDecorationList{}); // TODO(dneto): initializers (a.k.a. constructor expression) if (ast_var) { - ast_module_.AddGlobalVariable(ast_var); + program_.AddGlobalVariable(ast_var); } } @@ -1226,7 +1226,7 @@ bool ParserImpl::EmitModuleScopeVariables() { create(Source{}, ast::Builtin::kPosition), }); - ast_module_.AddGlobalVariable(var); + program_.AddGlobalVariable(var); } return success_; } @@ -1248,7 +1248,7 @@ ast::Variable* ParserImpl::MakeVariable( auto access = read_only_struct_types_.count(type) ? ast::AccessControl::kReadOnly : ast::AccessControl::kReadWrite; - type = ast_module_.create(access, type); + type = program_.create(access, type); } for (auto& deco : GetDecorationsFor(id)) { @@ -1306,13 +1306,13 @@ ast::Variable* ParserImpl::MakeVariable( } std::string name = namer_.Name(id); - return create(Source{}, // source - ast_module_.RegisterSymbol(name), // symbol - sc, // storage_class - type, // type - is_const, // is_const - constructor, // constructor - decorations); // decorations + return create(Source{}, // source + program_.RegisterSymbol(name), // symbol + sc, // storage_class + type, // type + is_const, // is_const + constructor, // constructor + decorations); // decorations } TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { @@ -1451,7 +1451,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) { if (const auto* mat_ty = type->As()) { // Matrix components are columns auto* column_ty = - ast_module_.create(mat_ty->type(), mat_ty->rows()); + program_.create(mat_ty->type(), mat_ty->rows()); ast::ExpressionList ast_components; for (size_t i = 0; i < mat_ty->columns(); ++i) { ast_components.emplace_back(MakeNullValue(column_ty)); @@ -1546,14 +1546,14 @@ type::Type* ParserImpl::GetSignedIntMatchingShape(type::Type* other) { if (other == nullptr) { Fail() << "no type provided"; } - auto* i32 = ast_module_.create(); + auto* i32 = program_.create(); if (other->Is() || other->Is() || other->Is()) { return i32; } auto* vec_ty = other->As(); if (vec_ty) { - return ast_module_.create(i32, vec_ty->size()); + return program_.create(i32, vec_ty->size()); } Fail() << "required numeric scalar or vector, but got " << other->type_name(); return nullptr; @@ -1564,14 +1564,14 @@ type::Type* ParserImpl::GetUnsignedIntMatchingShape(type::Type* other) { Fail() << "no type provided"; return nullptr; } - auto* u32 = ast_module_.create(); + auto* u32 = program_.create(); if (other->Is() || other->Is() || other->Is()) { return u32; } auto* vec_ty = other->As(); if (vec_ty) { - return ast_module_.create(u32, vec_ty->size()); + return program_.create(u32, vec_ty->size()); } Fail() << "required numeric scalar or vector, but got " << other->type_name(); return nullptr; @@ -1845,7 +1845,7 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( // Construct the Tint handle type. type::Type* ast_store_type = nullptr; if (usage.IsSampler()) { - ast_store_type = ast_module_.create( + ast_store_type = program_.create( usage.IsComparisonSampler() ? type::SamplerKind::kComparisonSampler : type::SamplerKind::kSampler); } else if (usage.IsTexture()) { @@ -1876,13 +1876,13 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( // OpImage variable with an OpImage*Dref* instruction. In WGSL we must // treat that as a depth texture. if (image_type->depth() || usage.IsDepthTexture()) { - ast_store_type = ast_module_.create(dim); + ast_store_type = program_.create(dim); } else if (image_type->is_multisampled()) { // Multisampled textures are never depth textures. - ast_store_type = ast_module_.create( + ast_store_type = program_.create( dim, ast_sampled_component_type); } else { - ast_store_type = ast_module_.create( + ast_store_type = program_.create( dim, ast_sampled_component_type); } } else { @@ -1893,8 +1893,8 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( if (format == type::ImageFormat::kNone) { return nullptr; } - ast_store_type = ast_module_.create( - access, ast_module_.create(dim, format)); + ast_store_type = program_.create( + access, program_.create(dim, format)); } } else { Fail() << "unsupported: UniformConstant variable is not a recognized " @@ -1904,7 +1904,7 @@ type::Pointer* ParserImpl::GetTypeForHandleVar( } // Form the pointer type. - auto* result = ast_module_.create( + auto* result = program_.create( ast_store_type, ast::StorageClass::kUniformConstant); // Remember it for later. handle_type_[&var] = result; @@ -1922,7 +1922,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) { case type::ImageFormat::kRg32Uint: case type::ImageFormat::kRgba16Uint: case type::ImageFormat::kRgba32Uint: - return ast_module_.create(); + return program_.create(); case type::ImageFormat::kR8Sint: case type::ImageFormat::kR16Sint: @@ -1933,7 +1933,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) { case type::ImageFormat::kRg32Sint: case type::ImageFormat::kRgba16Sint: case type::ImageFormat::kRgba32Sint: - return ast_module_.create(); + return program_.create(); case type::ImageFormat::kR8Unorm: case type::ImageFormat::kRg8Unorm: @@ -1952,7 +1952,7 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) { case type::ImageFormat::kRg32Float: case type::ImageFormat::kRgba16Float: case type::ImageFormat::kRgba32Float: - return ast_module_.create(); + return program_.create(); default: break; } @@ -1992,7 +1992,7 @@ type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) { case type::ImageFormat::kRg8Uint: case type::ImageFormat::kRg8Unorm: // Two channels - return ast_module_.create(component_type, 2); + return program_.create(component_type, 2); case type::ImageFormat::kBgra8Unorm: case type::ImageFormat::kBgra8UnormSrgb: @@ -2009,7 +2009,7 @@ type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) { case type::ImageFormat::kRgba8Unorm: case type::ImageFormat::kRgba8UnormSrgb: // Four channels - return ast_module_.create(component_type, 4); + return program_.create(component_type, 4); default: break; diff --git a/src/reader/spirv/parser_impl.h b/src/reader/spirv/parser_impl.h index bc858626b4..c3cee04be9 100644 --- a/src/reader/spirv/parser_impl.h +++ b/src/reader/spirv/parser_impl.h @@ -32,8 +32,8 @@ #include "source/opt/types.h" #include "spirv-tools/libspirv.hpp" #include "src/ast/expression.h" -#include "src/ast/module.h" #include "src/ast/struct_member_decoration.h" +#include "src/program.h" #include "src/reader/reader.h" #include "src/reader/spirv/entry_point_info.h" #include "src/reader/spirv/enum_converter.h" @@ -95,12 +95,12 @@ class ParserImpl : Reader { /// @returns true if the parse was successful, false otherwise. bool Parse() override; - /// @returns the module. The module in the parser will be reset after this. - ast::Module module() override; + /// @returns the program. The program in the parser will be reset after this. + Program program() override; - /// Returns a pointer to the module, without resetting it. - /// @returns the module - ast::Module& get_module() { return ast_module_; } + /// Returns a reference to the program, without resetting it. + /// @returns the program + Program& get_program() { return program_; } /// Logs failure, ands return a failure stream to accumulate diagnostic /// messages. By convention, a failure should only be logged along with @@ -118,14 +118,14 @@ class ParserImpl : Reader { const std::string error() { return errors_.str(); } /// Builds an internal representation of the SPIR-V binary, - /// and parses it into a Tint AST module. Diagnostics are emitted + /// and parses it into a Tint program. Diagnostics are emitted /// to the error stream. /// @returns true if it was successful. bool BuildAndParseInternalModule() { return BuildInternalModule() && ParseInternalModule(); } /// Builds an internal representation of the SPIR-V binary, - /// and parses the module, except functions, into a Tint AST module. + /// and parses the module, except functions, into a Tint program. /// Diagnostics are emitted to the error stream. /// @returns true if it was successful. bool BuildAndParseInternalModuleExceptFunctions() { @@ -524,20 +524,20 @@ class ParserImpl : Reader { bool ParseArrayDecorations(const spvtools::opt::analysis::Type* spv_type, ast::ArrayDecorationList* decorations); - /// Creates a new `ast::Node` owned by the Module. When the Module is + /// Creates a new `ast::Node` owned by the Program. When the Program is /// destructed, the `ast::Node` will also be destructed. /// @param args the arguments to pass to the type constructor /// @returns the node pointer template T* create(ARGS&&... args) { - return ast_module_.create(std::forward(args)...); + return program_.create(std::forward(args)...); } // The SPIR-V binary we're parsing std::vector spv_binary_; // The resulting module in Tint AST form. - ast::Module ast_module_; + Program program_; // Is the parse successful? bool success_ = true; diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index cc871c05ed..f76b004226 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -566,7 +566,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { EXPECT_TRUE(type->Is()); std::stringstream ss; type->As()->impl()->to_str(ss, 0); - EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ + EXPECT_THAT(Demangler().Demangle(p->get_program(), ss.str()), Eq(R"(Struct{ StructMember{field0: __u32} StructMember{field1: __f32} } @@ -587,7 +587,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { EXPECT_TRUE(type->Is()); std::stringstream ss; type->As()->impl()->to_str(ss, 0); - EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ + EXPECT_THAT(Demangler().Demangle(p->get_program(), ss.str()), Eq(R"(Struct{ [[block]] StructMember{field0: __u32} } @@ -612,7 +612,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { EXPECT_TRUE(type->Is()); std::stringstream ss; type->As()->impl()->to_str(ss, 0); - EXPECT_THAT(Demangler().Demangle(p->get_module(), ss.str()), Eq(R"(Struct{ + EXPECT_THAT(Demangler().Demangle(p->get_program(), ss.str()), Eq(R"(Struct{ StructMember{[[ offset 0 ]] field0: __f32} StructMember{[[ offset 8 ]] field1: __vec_2__f32} StructMember{[[ offset 16 ]] field2: __mat_2_2__f32} diff --git a/src/reader/spirv/parser_impl_function_decl_test.cc b/src/reader/spirv/parser_impl_function_decl_test.cc index ef85635fef..5c6f1d5a03 100644 --- a/src/reader/spirv/parser_impl_function_decl_test.cc +++ b/src/reader/spirv/parser_impl_function_decl_test.cc @@ -53,8 +53,8 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) { auto p = parser(test::Assemble(CommonTypes())); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, Not(HasSubstr("Function{"))); + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, Not(HasSubstr("Function{"))); } TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) { @@ -64,8 +64,8 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, Not(HasSubstr("Function{"))); + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, Not(HasSubstr("Function{"))); } TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_Vertex) { @@ -79,10 +79,10 @@ OpFunctionEnd)"; auto p = parser(test::Assemble(input)); ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("main").to_str() + - R"( -> __void + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("main").to_str() + + R"( -> __void StageDecoration{vertex} () {)")); @@ -99,10 +99,10 @@ OpFunctionEnd)"; auto p = parser(test::Assemble(input)); ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("main").to_str() + - R"( -> __void + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("main").to_str() + + R"( -> __void StageDecoration{fragment} () {)")); @@ -119,10 +119,10 @@ OpFunctionEnd)"; auto p = parser(test::Assemble(input)); ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("main").to_str() + - R"( -> __void + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("main").to_str() + + R"( -> __void StageDecoration{compute} () {)")); @@ -141,16 +141,16 @@ OpFunctionEnd)"; auto p = parser(test::Assemble(input)); ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->error().empty()) << p->error(); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("frag_main").to_str() + - R"( -> __void + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("frag_main").to_str() + + R"( -> __void StageDecoration{fragment} () {)")); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("comp_main").to_str() + - R"( -> __void + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("comp_main").to_str() + + R"( -> __void StageDecoration{compute} () {)")); @@ -165,10 +165,10 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->get_module().to_str(); - EXPECT_THAT(module_ast, HasSubstr(R"( - Function )" + p->get_module().GetSymbol("main").to_str() + - R"( -> __void + const auto program_ast = p->get_program().to_str(); + EXPECT_THAT(program_ast, HasSubstr(R"( + Function )" + p->get_program().GetSymbol("main").to_str() + + R"( -> __void () {)")); } @@ -199,9 +199,9 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module_ast, HasSubstr(R"( + const auto program_ast = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program_ast, HasSubstr(R"( Function leaf -> __u32 () { @@ -253,7 +253,7 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) { } Return{} } -})")) << module_ast; +})")) << program_ast; } TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) { @@ -267,9 +267,9 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module_ast, HasSubstr(R"( + const auto program_ast = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program_ast, HasSubstr(R"( Function ret_float -> __f32 () { @@ -279,7 +279,7 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) { } } })")) - << module_ast; + << program_ast; } TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) { @@ -297,9 +297,9 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module_ast, HasSubstr(R"( + const auto program_ast = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program_ast, HasSubstr(R"( Function mixed_params -> __void ( VariableConst{ @@ -337,9 +337,9 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) { )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module_ast, HasSubstr(R"( + const auto program_ast = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program_ast, HasSubstr(R"( Function mixed_params -> __void ( VariableConst{ @@ -361,7 +361,7 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) { { Return{} })")) - << module_ast; + << program_ast; } } // namespace diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 8844c6cfc6..3bdd6e1f01 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -1129,9 +1129,9 @@ TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto module = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) << module; + const auto program = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << program; } INSTANTIATE_TEST_SUITE_P(Samplers, @@ -1306,12 +1306,12 @@ TEST_P(SpvParserTest_SampledImageAccessTest, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto module = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) - << "DECLARATIONS ARE BAD " << module; - EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin)) - << "TEXTURE BUILTIN IS BAD " << module << assembly; + const auto program = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) + << "DECLARATIONS ARE BAD " << program; + EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin)) + << "TEXTURE BUILTIN IS BAD " << program << assembly; } // TODO(dneto): Test variable declaration and texture builtins provoked by @@ -2556,12 +2556,12 @@ TEST_P(SpvParserTest_ImageAccessTest, Variable) { auto p = parser(test::Assemble(assembly)); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; EXPECT_TRUE(p->error().empty()) << p->error(); - const auto module = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); - EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) - << "DECLARATIONS ARE BAD " << module; - EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin)) - << "TEXTURE BUILTIN IS BAD " << module << assembly; + const auto program = + Demangler().Demangle(p->get_program(), p->get_program().to_str()); + EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) + << "DECLARATIONS ARE BAD " << program; + EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin)) + << "TEXTURE BUILTIN IS BAD " << program << assembly; } INSTANTIATE_TEST_SUITE_P(ImageWrite_OptionalParams, @@ -3712,7 +3712,7 @@ TEST_P(SpvParserTest_ImageCoordsTest, MakeCoordinateOperandsForImageAccess) { for (auto* expr : result) { ASSERT_NE(expr, nullptr); result_strings.push_back( - Demangler().Demangle(p->get_module(), expr->str())); + Demangler().Demangle(p->get_program(), expr->str())); } EXPECT_THAT(result_strings, ::testing::ContainerEq(GetParam().expected_expressions)); diff --git a/src/reader/spirv/parser_impl_import_test.cc b/src/reader/spirv/parser_impl_import_test.cc index cb01dff2f1..a949cda296 100644 --- a/src/reader/spirv/parser_impl_import_test.cc +++ b/src/reader/spirv/parser_impl_import_test.cc @@ -35,8 +35,8 @@ TEST_F(SpvParserTest, Import_NoImport) { auto p = parser(test::Assemble("%1 = OpTypeVoid")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->module().to_str(); - EXPECT_THAT(module_ast, Not(HasSubstr("Import"))); + const auto program_ast = p->program().to_str(); + EXPECT_THAT(program_ast, Not(HasSubstr("Import"))); } TEST_F(SpvParserTest, Import_ImportGlslStd450) { diff --git a/src/reader/spirv/parser_impl_module_var_test.cc b/src/reader/spirv/parser_impl_module_var_test.cc index aca14de092..fd35169165 100644 --- a/src/reader/spirv/parser_impl_module_var_test.cc +++ b/src/reader/spirv/parser_impl_module_var_test.cc @@ -70,8 +70,8 @@ TEST_F(SpvModuleScopeVarParserTest, NoVar) { auto p = parser(test::Assemble("")); EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); - const auto module_ast = p->module().to_str(); - EXPECT_THAT(module_ast, Not(HasSubstr("Variable"))); + const auto program_ast = p->program().to_str(); + EXPECT_THAT(program_ast, Not(HasSubstr("Variable"))); } TEST_F(SpvModuleScopeVarParserTest, BadStorageClass_NotAWebGPUStorageClass) { @@ -144,7 +144,7 @@ TEST_F(SpvModuleScopeVarParserTest, AnonWorkgroupVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ x_52 @@ -164,7 +164,7 @@ TEST_F(SpvModuleScopeVarParserTest, NamedWorkgroupVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ the_counter @@ -184,7 +184,7 @@ TEST_F(SpvModuleScopeVarParserTest, PrivateVar) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ my_own_private_idaho @@ -204,7 +204,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinVertexIndex) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ Decorations{ @@ -255,7 +255,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_MapsToModuleScopeVec4Var) { EXPECT_EQ(position_info.storage_class, SpvStorageClassOutput); EXPECT_EQ(position_info.per_vertex_var_id, 1u); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ Decorations{ @@ -336,7 +336,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_StorePosition) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Assignment{ Identifier[not set]{gl_Position} @@ -390,7 +390,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Assignment{ Identifier[not set]{gl_Position} @@ -422,7 +422,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Assignment{ MemberAccessor[not set]{ @@ -454,7 +454,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( { Assignment{ @@ -485,7 +485,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Write1_IsErased) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Variable{ Decorations{ @@ -542,7 +542,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_ReadReplaced) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Variable{ x_900 @@ -610,7 +610,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Variable{ Decorations{ @@ -662,7 +662,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_Write1_IsErased) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Function x_500 -> __void () @@ -707,7 +707,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_ReadReplaced) { EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Variable{ x_900 @@ -744,7 +744,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Function x_500 -> __void () @@ -772,7 +772,7 @@ TEST_F(SpvModuleScopeVarParserTest, EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error(); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_EQ(module_str, R"(Module{ Function x_500 -> __void () @@ -877,7 +877,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarInitializers) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_1 private @@ -935,7 +935,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarNullInitializers) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_1 private @@ -985,7 +985,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarUndefInitializers) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_1 private @@ -1030,7 +1030,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1054,7 +1054,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1078,7 +1078,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1102,7 +1102,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1126,7 +1126,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1150,7 +1150,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1174,7 +1174,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1198,7 +1198,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1222,7 +1222,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1252,7 +1252,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1289,7 +1289,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1326,7 +1326,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1364,7 +1364,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1388,7 +1388,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1412,7 +1412,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1438,7 +1438,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1468,7 +1468,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructNullInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1498,7 +1498,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructUndefInitializer) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"(Variable{ x_200 private @@ -1530,7 +1530,7 @@ TEST_F(SpvModuleScopeVarParserTest, LocationDecoration_Valid) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ Decorations{ @@ -1583,7 +1583,7 @@ TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ Decorations{ @@ -1638,7 +1638,7 @@ TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( Variable{ Decorations{ @@ -1693,7 +1693,7 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1725,7 +1725,7 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1755,7 +1755,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Dropped) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1805,7 +1805,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1835,7 +1835,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1868,7 +1868,7 @@ TEST_F( ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( S Struct{ [[block]] @@ -1893,7 +1893,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ Decorations{ @@ -1919,7 +1919,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_False) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ Decorations{ @@ -1945,7 +1945,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_U32) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ Decorations{ @@ -1971,7 +1971,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_I32) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ Decorations{ @@ -1997,7 +1997,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_F32) { ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ Decorations{ @@ -2024,7 +2024,7 @@ TEST_F(SpvModuleScopeVarParserTest, ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); EXPECT_TRUE(p->error().empty()); const auto module_str = - Demangler().Demangle(p->get_module(), p->get_module().to_str()); + Demangler().Demangle(p->get_program(), p->get_program().to_str()); EXPECT_THAT(module_str, HasSubstr(R"( VariableConst{ myconst @@ -2053,7 +2053,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) { FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(p->error().empty()); - EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"( + EXPECT_THAT(ToString(p->get_program(), fe.ast_body()), HasSubstr(R"( VariableConst{ x_1 none @@ -2066,7 +2066,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_UsedInFunction) { } } })")) - << ToString(p->get_module(), fe.ast_body()); + << ToString(p->get_program(), fe.ast_body()); } } // namespace diff --git a/src/reader/spirv/parser_impl_named_types_test.cc b/src/reader/spirv/parser_impl_named_types_test.cc index 13f9af90ea..d1c46f96c7 100644 --- a/src/reader/spirv/parser_impl_named_types_test.cc +++ b/src/reader/spirv/parser_impl_named_types_test.cc @@ -18,14 +18,14 @@ #include "gmock/gmock.h" #include "src/ast/struct.h" -#include "src/type/array_type.h" -#include "src/type/matrix_type.h" -#include "src/type/struct_type.h" -#include "src/type/vector_type.h" #include "src/demangler.h" #include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/spirv_tools_helpers_test.h" +#include "src/type/array_type.h" +#include "src/type/matrix_type.h" +#include "src/type/struct_type.h" +#include "src/type/vector_type.h" namespace tint { namespace reader { @@ -40,7 +40,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("S Struct")); } @@ -51,7 +51,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) { %s = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("mystruct Struct")); } @@ -62,7 +62,7 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) { %s2 = OpTypeStruct %uint %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr(R"(S Struct{ StructMember{field0: __u32} StructMember{field1: __u32} @@ -84,7 +84,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) { %arr = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("RTArr -> __array__u32_stride_8\n")); } @@ -97,7 +97,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) { %arr2 = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> " "__array__u32_stride_8\n")); } @@ -110,7 +110,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) { %arr = OpTypeRuntimeArray %uint )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("myrtarr -> __array__u32_stride_8\n")); } @@ -124,7 +124,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) { %arr2 = OpTypeArray %uint %uint_5 )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("myarr -> __array__u32_5_stride_8")); } @@ -138,7 +138,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) { %arr2 = OpTypeArray %uint %uint_5 )")); EXPECT_TRUE(p->BuildAndParseInternalModule()); - EXPECT_THAT(Demangler().Demangle(p->get_module(), p->get_module().to_str()), + EXPECT_THAT(Demangler().Demangle(p->get_program(), p->get_program().to_str()), HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> " "__array__u32_5_stride_8")); } diff --git a/src/reader/spirv/parser_impl_test_helper.h b/src/reader/spirv/parser_impl_test_helper.h index e8283c6de9..c296e87bf4 100644 --- a/src/reader/spirv/parser_impl_test_helper.h +++ b/src/reader/spirv/parser_impl_test_helper.h @@ -58,16 +58,16 @@ class SpvParserTestBase : public T { using SpvParserTest = SpvParserTestBase<::testing::Test>; /// Returns the string dump of a statement list. -/// @param mod the module +/// @param program the program /// @param stmts the statement list /// @returns the string dump of a statement list. -inline std::string ToString(const ast::Module& mod, +inline std::string ToString(const Program& program, const ast::StatementList& stmts) { std::ostringstream outs; for (const auto* stmt : stmts) { stmt->to_str(outs, 0); } - return Demangler().Demangle(mod, outs.str()); + return Demangler().Demangle(program, outs.str()); } } // namespace spirv diff --git a/src/reader/wgsl/parser.cc b/src/reader/wgsl/parser.cc index 9a16198eb5..aec5b682a6 100644 --- a/src/reader/wgsl/parser.cc +++ b/src/reader/wgsl/parser.cc @@ -35,8 +35,8 @@ bool Parser::Parse() { return ret; } -ast::Module Parser::module() { - return impl_->module(); +Program Parser::program() { + return impl_->program(); } } // namespace wgsl diff --git a/src/reader/wgsl/parser.h b/src/reader/wgsl/parser.h index 3aaca80487..42da6bb290 100644 --- a/src/reader/wgsl/parser.h +++ b/src/reader/wgsl/parser.h @@ -39,8 +39,8 @@ class Parser : public Reader { /// @returns true if the parse was successful, false otherwise. bool Parse() override; - /// @returns the module. The module in the parser will be reset after this. - ast::Module module() override; + /// @returns the program. The program in the parser will be reset after this. + Program program() override; private: std::unique_ptr impl_; diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 9521365581..284d87d37d 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -293,7 +293,7 @@ void ParserImpl::translation_unit() { } } - assert(module_.IsValid()); + assert(program_.IsValid()); } // global_decl @@ -323,7 +323,7 @@ Expect ParserImpl::expect_global_decl() { if (!expect("variable declaration", Token::Type::kSemicolon)) return Failure::kErrored; - module_.AddGlobalVariable(gv.value); + program_.AddGlobalVariable(gv.value); return true; } @@ -335,7 +335,7 @@ Expect ParserImpl::expect_global_decl() { if (!expect("constant declaration", Token::Type::kSemicolon)) return Failure::kErrored; - module_.AddGlobalVariable(gc.value); + program_.AddGlobalVariable(gc.value); return true; } @@ -347,7 +347,7 @@ Expect ParserImpl::expect_global_decl() { if (!expect("type alias", Token::Type::kSemicolon)) return Failure::kErrored; - module_.AddConstructedType(ta.value); + program_.AddConstructedType(ta.value); return true; } @@ -361,8 +361,8 @@ Expect ParserImpl::expect_global_decl() { auto* type = str.value; register_constructed( - module_.SymbolToName(type->As()->symbol()), type); - module_.AddConstructedType(type); + program_.SymbolToName(type->As()->symbol()), type); + program_.AddConstructedType(type); return true; } @@ -378,7 +378,7 @@ Expect ParserImpl::expect_global_decl() { if (func.errored) errored = true; if (func.matched) { - module_.Functions().Add(func.value); + program_.Functions().Add(func.value); return true; } @@ -435,8 +435,8 @@ Maybe ParserImpl::global_variable_decl( constructor = expr.value; } - return create(decl->source, // source - module_.RegisterSymbol(decl->name), // symbol + return create(decl->source, // source + program_.RegisterSymbol(decl->name), // symbol decl->storage_class, // storage_class decl->type, // type false, // is_const @@ -463,8 +463,8 @@ Maybe ParserImpl::global_constant_decl() { if (init.errored) return Failure::kErrored; - return create(decl->source, // source - module_.RegisterSymbol(decl->name), // symbol + return create(decl->source, // source + program_.RegisterSymbol(decl->name), // symbol ast::StorageClass::kNone, // storage_class decl->type, // type true, // is_const @@ -514,7 +514,7 @@ Maybe ParserImpl::texture_sampler_types() { if (subtype.errored) return Failure::kErrored; - return module_.create(dim.value, subtype.value); + return program_.create(dim.value, subtype.value); } auto ms_dim = multisampled_texture_type(); @@ -525,8 +525,8 @@ Maybe ParserImpl::texture_sampler_types() { if (subtype.errored) return Failure::kErrored; - return module_.create(ms_dim.value, - subtype.value); + return program_.create(ms_dim.value, + subtype.value); } auto storage = storage_texture_type(); @@ -539,7 +539,7 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - return module_.create(storage.value, format.value); + return program_.create(storage.value, format.value); } // DEPRECATED @@ -553,9 +553,9 @@ Maybe ParserImpl::texture_sampler_types() { if (format.errored) return Failure::kErrored; - return module_.create( + return program_.create( ac_storage->second, - module_.create(ac_storage->first, format.value)); + program_.create(ac_storage->first, format.value)); } return Failure::kNoMatch; @@ -566,10 +566,11 @@ Maybe ParserImpl::texture_sampler_types() { // | SAMPLER_COMPARISON Maybe ParserImpl::sampler_type() { if (match(Token::Type::kSampler)) - return module_.create(type::SamplerKind::kSampler); + return program_.create(type::SamplerKind::kSampler); if (match(Token::Type::kComparisonSampler)) - return module_.create(type::SamplerKind::kComparisonSampler); + return program_.create( + type::SamplerKind::kComparisonSampler); return Failure::kNoMatch; } @@ -714,16 +715,17 @@ ParserImpl::storage_texture_type_access_control() { // | TEXTURE_DEPTH_CUBE_ARRAY Maybe ParserImpl::depth_texture_type() { if (match(Token::Type::kTextureDepth2d)) - return module_.create(type::TextureDimension::k2d); + return program_.create(type::TextureDimension::k2d); if (match(Token::Type::kTextureDepth2dArray)) - return module_.create(type::TextureDimension::k2dArray); + return program_.create( + type::TextureDimension::k2dArray); if (match(Token::Type::kTextureDepthCube)) - return module_.create(type::TextureDimension::kCube); + return program_.create(type::TextureDimension::kCube); if (match(Token::Type::kTextureDepthCubeArray)) - return module_.create( + return program_.create( type::TextureDimension::kCubeArray); return Failure::kNoMatch; @@ -909,7 +911,7 @@ Expect ParserImpl::expect_variable_ident_decl( for (auto* deco : access_decos) { // If we have an access control decoration then we take it and wrap our // type up with that decoration - ty = module_.create( + ty = program_.create( deco->As()->value(), ty); } @@ -971,8 +973,8 @@ Maybe ParserImpl::type_alias() { if (!type.matched) return add_error(peek(), "invalid type alias"); - auto* alias = module_.create(module_.RegisterSymbol(name.value), - type.value); + auto* alias = program_.create( + program_.RegisterSymbol(name.value), type.value); register_constructed(name.value, alias); return alias; @@ -1030,16 +1032,16 @@ Maybe ParserImpl::type_decl(ast::DecorationList& decos) { } if (match(Token::Type::kBool)) - return module_.create(); + return program_.create(); if (match(Token::Type::kF32)) - return module_.create(); + return program_.create(); if (match(Token::Type::kI32)) - return module_.create(); + return program_.create(); if (match(Token::Type::kU32)) - return module_.create(); + return program_.create(); if (t.IsVec2() || t.IsVec3() || t.IsVec4()) { next(); // Consume the peek @@ -1097,7 +1099,7 @@ Expect ParserImpl::expect_type_decl_pointer() { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, sc.value); + return program_.create(subtype.value, sc.value); }); } @@ -1114,7 +1116,7 @@ Expect ParserImpl::expect_type_decl_vector(Token t) { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, count); + return program_.create(subtype.value, count); } Expect ParserImpl::expect_type_decl_array( @@ -1158,7 +1160,7 @@ Expect ParserImpl::expect_type_decl_matrix(Token t) { if (subtype.errored) return Failure::kErrored; - return module_.create(subtype.value, rows, columns); + return program_.create(subtype.value, rows, columns); } // storage_class @@ -1225,7 +1227,7 @@ Maybe ParserImpl::struct_decl(ast::DecorationList& decos) { return Failure::kErrored; return create( - module_.RegisterSymbol(name.value), + program_.RegisterSymbol(name.value), create(source, std::move(body.value), std::move(struct_decos.value))); } @@ -1280,7 +1282,7 @@ Expect ParserImpl::expect_struct_member( return Failure::kErrored; return create(decl->source, - module_.RegisterSymbol(decl->name), + program_.RegisterSymbol(decl->name), decl->type, std::move(member_decos.value)); } @@ -1317,7 +1319,7 @@ Maybe ParserImpl::function_decl(ast::DecorationList& decos) { return Failure::kErrored; return create( - header->source, module_.RegisterSymbol(header->name), header->params, + header->source, program_.RegisterSymbol(header->name), header->params, header->return_type, body.value, func_decos.value); } @@ -1326,7 +1328,7 @@ Maybe ParserImpl::function_decl(ast::DecorationList& decos) { // | VOID Maybe ParserImpl::function_type_decl() { if (match(Token::Type::kVoid)) - return module_.create(); + return program_.create(); return type_decl(); } @@ -1386,8 +1388,8 @@ Expect ParserImpl::expect_param_list() { ast::VariableList ret; for (;;) { auto* var = - create(decl->source, // source - module_.RegisterSymbol(decl->name), // symbol + create(decl->source, // source + program_.RegisterSymbol(decl->name), // symbol ast::StorageClass::kNone, // storage_class decl->type, // type true, // is_const @@ -1657,8 +1659,8 @@ Maybe ParserImpl::variable_stmt() { return add_error(peek(), "missing constructor for const declaration"); auto* var = - create(decl->source, // source - module_.RegisterSymbol(decl->name), // symbol + create(decl->source, // source + program_.RegisterSymbol(decl->name), // symbol ast::StorageClass::kNone, // storage_class decl->type, // type true, // is_const @@ -1686,8 +1688,8 @@ Maybe ParserImpl::variable_stmt() { } auto* var = - create(decl->source, // source - module_.RegisterSymbol(decl->name), // symbol + create(decl->source, // source + program_.RegisterSymbol(decl->name), // symbol decl->storage_class, // storage_class decl->type, // type false, // is_const @@ -2089,7 +2091,7 @@ Maybe ParserImpl::func_call_stmt() { Source{}, create(source, create( - source, module_.RegisterSymbol(name)), + source, program_.RegisterSymbol(name)), std::move(params))); } @@ -2162,7 +2164,7 @@ Maybe ParserImpl::primary_expression() { if (match(Token::Type::kIdentifier)) return create( - t.source(), module_.RegisterSymbol(t.to_str())); + t.source(), program_.RegisterSymbol(t.to_str())); auto type = type_decl(); if (type.errored) @@ -2238,7 +2240,7 @@ Maybe ParserImpl::postfix_expr(ast::Expression* prefix) { return postfix_expr(create( ident.source, prefix, create( - ident.source, module_.RegisterSymbol(ident.value)))); + ident.source, program_.RegisterSymbol(ident.value)))); } return prefix; @@ -2738,19 +2740,19 @@ Maybe ParserImpl::assignment_stmt() { Maybe ParserImpl::const_literal() { auto t = peek(); if (match(Token::Type::kTrue)) { - auto* type = module_.create(); + auto* type = program_.create(); return create(Source{}, type, true); } if (match(Token::Type::kFalse)) { - auto* type = module_.create(); + auto* type = program_.create(); return create(Source{}, type, false); } if (match(Token::Type::kSintLiteral)) { - auto* type = module_.create(); + auto* type = program_.create(); return create(Source{}, type, t.to_i32()); } if (match(Token::Type::kUintLiteral)) { - auto* type = module_.create(); + auto* type = program_.create(); return create(Source{}, type, t.to_u32()); } if (match(Token::Type::kFloatLiteral)) { @@ -2759,7 +2761,7 @@ Maybe ParserImpl::const_literal() { next(); // Consume 'f' add_error(p.source(), "float literals must not be suffixed with 'f'"); } - auto* type = module_.create(); + auto* type = program_.create(); return create(Source{}, type, t.to_f32()); } return Failure::kNoMatch; diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 838f0bb42d..cada77761f 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -38,7 +38,6 @@ #include "src/ast/if_statement.h" #include "src/ast/literal.h" #include "src/ast/loop_statement.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/return_statement.h" #include "src/ast/statement.h" @@ -53,6 +52,7 @@ #include "src/ast/variable_decoration.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" +#include "src/program.h" #include "src/reader/wgsl/parser_impl_detail.h" #include "src/reader/wgsl/token.h" #include "src/type/storage_texture_type.h" @@ -307,11 +307,11 @@ class ParserImpl { /// @returns the diagnostic messages diag::List& diagnostics() { return diags_; } - /// @returns the module. The module in the parser will be reset after this. - ast::Module module() { return std::move(module_); } + /// @returns the program. The program in the parser will be reset after this. + Program program() { return std::move(program_); } /// @returns a pointer to the module, without resetting it. - ast::Module& get_module() { return module_; } + Program& get_program() { return program_; } /// @returns the next token Token next(); @@ -829,7 +829,7 @@ class ParserImpl { /// @returns the node pointer template T* create(ARGS&&... args) { - return module_.create(std::forward(args)...); + return program_.create(std::forward(args)...); } diag::List diags_; @@ -839,7 +839,7 @@ class ParserImpl { std::vector sync_tokens_; int silence_errors_ = 0; std::unordered_map registered_constructs_; - ast::Module module_; + Program program_; size_t max_errors_ = 25; }; diff --git a/src/reader/wgsl/parser_impl_additive_expression_test.cc b/src/reader/wgsl/parser_impl_additive_expression_test.cc index 69b5623edd..f7fc99b436 100644 --- a/src/reader/wgsl/parser_impl_additive_expression_test.cc +++ b/src/reader/wgsl/parser_impl_additive_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_and_expression_test.cc b/src/reader/wgsl/parser_impl_and_expression_test.cc index e50c345192..68979f949a 100644 --- a/src/reader/wgsl/parser_impl_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_and_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AndExpression_Parses) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc index a7708953d9..5234057cf8 100644 --- a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) { ASSERT_TRUE(e->lhs()->Is()); auto* ident = e->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(e->rhs()->Is()); ASSERT_TRUE(e->rhs()->Is()); @@ -77,7 +77,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { ASSERT_TRUE(mem->member()->Is()); auto* ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("d")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("d")); ASSERT_TRUE(mem->structure()->Is()); auto* ary = mem->structure()->As(); @@ -93,18 +93,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { mem = ary->array()->As(); ASSERT_TRUE(mem->member()->Is()); ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("c")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("c")); ASSERT_TRUE(mem->structure()->Is()); mem = mem->structure()->As(); ASSERT_TRUE(mem->structure()->Is()); ident = mem->structure()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(mem->member()->Is()); ident = mem->member()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("b")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("b")); } TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) { diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index 1fd8f7742f..a8f385059f 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -38,7 +38,7 @@ TEST_F(ParserImplTest, Statement_Call) { ASSERT_TRUE(c->func()->Is()); auto* ident = c->func()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(c->params().size(), 0u); } @@ -56,7 +56,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { ASSERT_TRUE(c->func()->Is()); auto* ident = c->func()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(c->params().size(), 3u); EXPECT_TRUE(c->params()[0]->Is()); diff --git a/src/reader/wgsl/parser_impl_equality_expression_test.cc b/src/reader/wgsl/parser_impl_equality_expression_test.cc index fffec25c35..89600cb1c7 100644 --- a/src/reader/wgsl/parser_impl_equality_expression_test.cc +++ b/src/reader/wgsl/parser_impl_equality_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc index d50a6fa89d..cf821bfe64 100644 --- a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index 17b9fd1d70..4a58b0cc90 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -37,13 +37,13 @@ TEST_F(ParserImplTest, FunctionDecl) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); + EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 2u); - EXPECT_EQ(f->params()[0]->symbol(), p->get_module().RegisterSymbol("a")); - EXPECT_EQ(f->params()[1]->symbol(), p->get_module().RegisterSymbol("b")); + EXPECT_EQ(f->params()[0]->symbol(), p->get_program().RegisterSymbol("a")); + EXPECT_EQ(f->params()[1]->symbol(), p->get_program().RegisterSymbol("b")); ASSERT_NE(f->return_type(), nullptr); EXPECT_TRUE(f->return_type()->Is()); @@ -65,7 +65,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); + EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); @@ -103,7 +103,7 @@ fn main() -> void { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); + EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); @@ -148,7 +148,7 @@ fn main() -> void { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f->symbol(), p->get_module().RegisterSymbol("main")); + EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); ASSERT_NE(f->return_type(), nullptr); EXPECT_TRUE(f->return_type()->Is()); ASSERT_EQ(f->params().size(), 0u); diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc index 1a77313eb3..0b7fd8e220 100644 --- a/src/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/reader/wgsl/parser_impl_function_header_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, FunctionHeader) { EXPECT_EQ(f->name, "main"); ASSERT_EQ(f->params.size(), 2u); - EXPECT_EQ(f->params[0]->symbol(), p->get_module().RegisterSymbol("a")); - EXPECT_EQ(f->params[1]->symbol(), p->get_module().RegisterSymbol("b")); + EXPECT_EQ(f->params[0]->symbol(), p->get_program().RegisterSymbol("a")); + EXPECT_EQ(f->params[1]->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_TRUE(f->return_type->Is()); } diff --git a/src/reader/wgsl/parser_impl_function_type_decl_test.cc b/src/reader/wgsl/parser_impl_function_type_decl_test.cc index f3f16bf464..57cc4b047e 100644 --- a/src/reader/wgsl/parser_impl_function_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_type_decl_test.cc @@ -29,7 +29,7 @@ namespace { TEST_F(ParserImplTest, FunctionTypeDecl_Void) { auto p = parser("void"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* v = mod.create(); auto e = p->function_type_decl(); @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) { TEST_F(ParserImplTest, FunctionTypeDecl_Type) { auto p = parser("vec2"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* f32 = mod.create(); auto* vec2 = mod.create(f32, 2); diff --git a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc index 149b6d91e1..9bb96e306d 100644 --- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -33,7 +33,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) { ASSERT_NE(e.value, nullptr); EXPECT_TRUE(e->is_const()); - EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); EXPECT_TRUE(e->type()->Is()); diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index 3875ca009d..b1f7be625f 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -34,11 +34,11 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.global_variables().size(), 1u); auto* v = m.global_variables()[0]; - EXPECT_EQ(v->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); } TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) { @@ -60,11 +60,11 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConstant) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.global_variables().size(), 1u); auto* v = m.global_variables()[0]; - EXPECT_EQ(v->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); } TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) { @@ -86,7 +86,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.constructed_types().size(), 1u); ASSERT_TRUE(m.constructed_types()[0]->Is()); EXPECT_EQ( @@ -103,15 +103,15 @@ type B = A;)"); p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.constructed_types().size(), 2u); ASSERT_TRUE(m.constructed_types()[0]->Is()); auto* str = m.constructed_types()[0]->As(); - EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); + EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); ASSERT_TRUE(m.constructed_types()[1]->Is()); auto* alias = m.constructed_types()[1]->As(); - EXPECT_EQ(alias->symbol(), p->get_module().RegisterSymbol("B")); + EXPECT_EQ(alias->symbol(), p->get_program().RegisterSymbol("B")); EXPECT_EQ(alias->type(), str); } @@ -134,7 +134,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.Functions().size(), 1u); EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main"); } @@ -144,7 +144,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.Functions().size(), 1u); EXPECT_EQ(m.SymbolToName(m.Functions()[0]->symbol()), "main"); } @@ -161,7 +161,7 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.constructed_types().size(), 1u); auto* t = m.constructed_types()[0]; @@ -169,7 +169,7 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); + EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 2u); } @@ -180,7 +180,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.constructed_types().size(), 1u); auto* t = m.constructed_types()[0]; @@ -188,7 +188,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); + EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); @@ -204,7 +204,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { p->expect_global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(m.constructed_types().size(), 1u); auto* t = m.constructed_types()[0]; @@ -212,7 +212,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) { ASSERT_TRUE(t->Is()); auto* str = t->As(); - EXPECT_EQ(str->symbol(), p->get_module().RegisterSymbol("A")); + EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_TRUE(str->IsBlockDecorated()); } diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc index 84c392d1b2..28146d8e1b 100644 --- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -36,7 +36,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); @@ -59,7 +59,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); @@ -84,7 +84,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); @@ -114,7 +114,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_NE(e->type(), nullptr); EXPECT_TRUE(e->type()->Is()); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); diff --git a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc index 6612866ee8..b900de9988 100644 --- a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc index 7218c7044b..0a392b9d33 100644 --- a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc index 67f567438b..921d9ca365 100644 --- a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc index 8cc5101d32..c0b547c22f 100644 --- a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc +++ b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -85,7 +85,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_param_list_test.cc b/src/reader/wgsl/parser_impl_param_list_test.cc index a8a9106076..fb87002609 100644 --- a/src/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/reader/wgsl/parser_impl_param_list_test.cc @@ -30,7 +30,7 @@ namespace { TEST_F(ParserImplTest, ParamList_Single) { auto p = parser("a : i32"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto e = p->expect_param_list(); @@ -38,7 +38,7 @@ TEST_F(ParserImplTest, ParamList_Single) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.size(), 1u); - EXPECT_EQ(e.value[0]->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e.value[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e.value[0]->type(), i32); EXPECT_TRUE(e.value[0]->is_const()); @@ -51,7 +51,7 @@ TEST_F(ParserImplTest, ParamList_Single) { TEST_F(ParserImplTest, ParamList_Multiple) { auto p = parser("a : i32, b: f32, c: vec2"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto* f32 = mod.create(); auto* vec2 = mod.create(f32, 2); @@ -61,7 +61,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.size(), 3u); - EXPECT_EQ(e.value[0]->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e.value[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e.value[0]->type(), i32); EXPECT_TRUE(e.value[0]->is_const()); @@ -70,7 +70,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[0]->source().range.end.line, 1u); ASSERT_EQ(e.value[0]->source().range.end.column, 2u); - EXPECT_EQ(e.value[1]->symbol(), p->get_module().RegisterSymbol("b")); + EXPECT_EQ(e.value[1]->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_EQ(e.value[1]->type(), f32); EXPECT_TRUE(e.value[1]->is_const()); @@ -79,7 +79,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[1]->source().range.end.line, 1u); ASSERT_EQ(e.value[1]->source().range.end.column, 11u); - EXPECT_EQ(e.value[2]->symbol(), p->get_module().RegisterSymbol("c")); + EXPECT_EQ(e.value[2]->symbol(), p->get_program().RegisterSymbol("c")); EXPECT_EQ(e.value[2]->type(), vec2); EXPECT_TRUE(e.value[2]->is_const()); diff --git a/src/reader/wgsl/parser_impl_postfix_expression_test.cc b/src/reader/wgsl/parser_impl_postfix_expression_test.cc index afe83eaf13..e03eed2a08 100644 --- a/src/reader/wgsl/parser_impl_postfix_expression_test.cc +++ b/src/reader/wgsl/parser_impl_postfix_expression_test.cc @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) { ASSERT_TRUE(ary->array()->Is()); auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(ary->idx_expr()->Is()); ASSERT_TRUE(ary->idx_expr()->Is()); @@ -64,7 +64,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) { ASSERT_TRUE(ary->array()->Is()); auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(ary->idx_expr()->Is()); } @@ -112,7 +112,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_Empty) { ASSERT_TRUE(c->func()->Is()); auto* func = c->func()->As(); - EXPECT_EQ(func->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(func->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(c->params().size(), 0u); } @@ -130,7 +130,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) { ASSERT_TRUE(c->func()->Is()); auto* func = c->func()->As(); - EXPECT_EQ(func->symbol(), p->get_module().RegisterSymbol("test")); + EXPECT_EQ(func->symbol(), p->get_program().RegisterSymbol("test")); EXPECT_EQ(c->params().size(), 3u); EXPECT_TRUE(c->params()[0]->Is()); @@ -180,11 +180,11 @@ TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) { auto* m = e->As(); ASSERT_TRUE(m->structure()->Is()); EXPECT_EQ(m->structure()->As()->symbol(), - p->get_module().RegisterSymbol("a")); + p->get_program().RegisterSymbol("a")); ASSERT_TRUE(m->member()->Is()); EXPECT_EQ(m->member()->As()->symbol(), - p->get_module().RegisterSymbol("b")); + p->get_program().RegisterSymbol("b")); } TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) { diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index 74ddfc3465..072ade277f 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -41,7 +41,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); auto* ident = e->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { @@ -193,7 +193,7 @@ TEST_F(ParserImplTest, PrimaryExpression_ParenExpr_InvalidExpr) { TEST_F(ParserImplTest, PrimaryExpression_Cast) { auto p = parser("f32(1)"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* f32 = mod.create(); auto e = p->primary_expression(); @@ -215,7 +215,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { auto p = parser("bitcast(1)"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* f32 = mod.create(); auto e = p->primary_expression(); diff --git a/src/reader/wgsl/parser_impl_relational_expression_test.cc b/src/reader/wgsl/parser_impl_relational_expression_test.cc index b17292e6d1..57315db16e 100644 --- a/src/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/reader/wgsl/parser_impl_relational_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -85,7 +85,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -108,7 +108,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc index 41cee53885..5bdb2f0d54 100644 --- a/src/reader/wgsl/parser_impl_shift_expression_test.cc +++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); @@ -62,7 +62,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { ASSERT_TRUE(rel->lhs()->Is()); auto* ident = rel->lhs()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(rel->rhs()->Is()); ASSERT_TRUE(rel->rhs()->Is()); diff --git a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc index bbfdce15b8..5c4e0cf936 100644 --- a/src/reader/wgsl/parser_impl_struct_body_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_body_decl_test.cc @@ -25,7 +25,7 @@ namespace { TEST_F(ParserImplTest, StructBodyDecl_Parses) { auto p = parser("{a : i32;}"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto m = p->expect_struct_body_decl(); @@ -34,7 +34,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) { ASSERT_EQ(m.value.size(), 1u); const auto* mem = m.value[0]; - EXPECT_EQ(mem->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(mem->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(mem->type(), i32); EXPECT_EQ(mem->decorations().size(), 0u); } diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index 9680c4d987..ccaaddb2fd 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -14,9 +14,9 @@ #include "gtest/gtest.h" #include "src/ast/struct_block_decoration.h" -#include "src/type/struct_type.h" #include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl_test_helper.h" +#include "src/type/struct_type.h" namespace tint { namespace reader { @@ -39,12 +39,12 @@ struct S { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S")); + ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("S")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->symbol(), - p->get_module().RegisterSymbol("a")); + p->get_program().RegisterSymbol("a")); EXPECT_EQ(s->impl()->members()[1]->symbol(), - p->get_module().RegisterSymbol("b")); + p->get_program().RegisterSymbol("b")); } TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { @@ -63,12 +63,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); + ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->symbol(), - p->get_module().RegisterSymbol("a")); + p->get_program().RegisterSymbol("a")); EXPECT_EQ(s->impl()->members()[1]->symbol(), - p->get_module().RegisterSymbol("b")); + p->get_program().RegisterSymbol("b")); ASSERT_EQ(s->impl()->decorations().size(), 1u); EXPECT_TRUE(s->impl()->decorations()[0]->Is()); } @@ -90,12 +90,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s->symbol(), p->get_module().RegisterSymbol("S")); + ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("S")); ASSERT_EQ(s->impl()->members().size(), 2u); EXPECT_EQ(s->impl()->members()[0]->symbol(), - p->get_module().RegisterSymbol("a")); + p->get_program().RegisterSymbol("a")); EXPECT_EQ(s->impl()->members()[1]->symbol(), - p->get_module().RegisterSymbol("b")); + p->get_program().RegisterSymbol("b")); ASSERT_EQ(s->impl()->decorations().size(), 2u); EXPECT_TRUE(s->impl()->decorations()[0]->Is()); EXPECT_TRUE(s->impl()->decorations()[1]->Is()); diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc index 554e1d7b79..0460b8058f 100644 --- a/src/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_test.cc @@ -26,7 +26,7 @@ namespace { TEST_F(ParserImplTest, StructMember_Parses) { auto p = parser("a : i32;"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto decos = p->decoration_list(); @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, StructMember_Parses) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->decorations().size(), 0u); @@ -52,7 +52,7 @@ TEST_F(ParserImplTest, StructMember_Parses) { TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { auto p = parser("[[offset(2)]] a : i32;"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto decos = p->decoration_list(); @@ -65,7 +65,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->decorations().size(), 1u); EXPECT_TRUE(m->decorations()[0]->Is()); @@ -83,7 +83,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { auto p = parser(R"([[offset(2)]] [[offset(4)]] a : i32;)"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto decos = p->decoration_list(); @@ -96,7 +96,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->decorations().size(), 2u); EXPECT_TRUE(m->decorations()[0]->Is()); diff --git a/src/reader/wgsl/parser_impl_test.cc b/src/reader/wgsl/parser_impl_test.cc index 3065a086c4..6da4d6d2d7 100644 --- a/src/reader/wgsl/parser_impl_test.cc +++ b/src/reader/wgsl/parser_impl_test.cc @@ -39,7 +39,7 @@ fn main() -> void { )"); ASSERT_TRUE(p->Parse()) << p->error(); - auto& m = p->get_module(); + auto& m = p->get_program(); ASSERT_EQ(1u, m.Functions().size()); ASSERT_EQ(1u, m.global_variables().size()); } diff --git a/src/reader/wgsl/parser_impl_test_helper.h b/src/reader/wgsl/parser_impl_test_helper.h index 184edddc3e..7a7efa76a0 100644 --- a/src/reader/wgsl/parser_impl_test_helper.h +++ b/src/reader/wgsl/parser_impl_test_helper.h @@ -29,7 +29,7 @@ namespace reader { namespace wgsl { /// WGSL Parser test class -class ParserImplTest : public testing::Test, public ast::BuilderWithModule { +class ParserImplTest : public testing::Test, public ast::BuilderWithProgram { public: /// Constructor ParserImplTest(); @@ -52,7 +52,7 @@ class ParserImplTest : public testing::Test, public ast::BuilderWithModule { /// WGSL Parser test class with param template class ParserImplTestWithParam : public testing::TestWithParam, - public ast::BuilderWithModule { + public ast::BuilderWithProgram { public: /// Constructor ParserImplTestWithParam() = default; diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index da890b5158..414714bf6d 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -28,7 +28,7 @@ namespace { TEST_F(ParserImplTest, TypeDecl_ParsesType) { auto p = parser("type a = i32"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* i32 = mod.create(); auto t = p->type_alias(); @@ -45,7 +45,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { auto p = parser("type a = B"); - type::Struct str(p->get_module().RegisterSymbol("B"), {}); + type::Struct str(p->get_program().RegisterSymbol("B"), {}); p->register_constructed("B", &str); auto t = p->type_alias(); @@ -55,12 +55,12 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); auto* alias = t->As(); - EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "a"); + EXPECT_EQ(p->get_program().SymbolToName(alias->symbol()), "a"); ASSERT_TRUE(alias->type()->Is()); auto* s = alias->type()->As(); - EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); - EXPECT_EQ(s->symbol(), p->get_module().RegisterSymbol("B")); + EXPECT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); + EXPECT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); } TEST_F(ParserImplTest, TypeDecl_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index f82b065994..4164b9f7d9 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -46,7 +46,7 @@ TEST_F(ParserImplTest, TypeDecl_Invalid) { TEST_F(ParserImplTest, TypeDecl_Identifier) { auto p = parser("A"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* int_type = mod.create(); auto* alias_type = mod.create(mod.RegisterSymbol("A"), int_type); @@ -61,7 +61,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { ASSERT_TRUE(t->Is()); auto* alias = t->As(); - EXPECT_EQ(p->get_module().SymbolToName(alias->symbol()), "A"); + EXPECT_EQ(p->get_program().SymbolToName(alias->symbol()), "A"); EXPECT_EQ(alias->type(), int_type); } @@ -79,7 +79,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier_NotFound) { TEST_F(ParserImplTest, TypeDecl_Bool) { auto p = parser("bool"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* bool_type = mod.create(); auto t = p->type_decl(); @@ -93,7 +93,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { TEST_F(ParserImplTest, TypeDecl_F32) { auto p = parser("f32"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* float_type = mod.create(); auto t = p->type_decl(); @@ -107,7 +107,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) { TEST_F(ParserImplTest, TypeDecl_I32) { auto p = parser("i32"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* int_type = mod.create(); auto t = p->type_decl(); @@ -121,7 +121,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) { TEST_F(ParserImplTest, TypeDecl_U32) { auto p = parser("u32"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* uint_type = mod.create(); auto t = p->type_decl(); @@ -738,7 +738,7 @@ INSTANTIATE_TEST_SUITE_P(ParserImplTest, TEST_F(ParserImplTest, TypeDecl_Sampler) { auto p = parser("sampler"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* type = mod.create(type::SamplerKind::kSampler); auto t = p->type_decl(); @@ -753,7 +753,7 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) { TEST_F(ParserImplTest, TypeDecl_Texture_Old) { auto p = parser("texture_sampled_cube"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* type = mod.create(type::TextureDimension::kCube, ty.f32); @@ -770,7 +770,7 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) { TEST_F(ParserImplTest, TypeDecl_Texture) { auto p = parser("texture_cube"); - auto& mod = p->get_module(); + auto& mod = p->get_program(); auto* type = mod.create(type::TextureDimension::kCube, ty.f32); diff --git a/src/reader/wgsl/parser_impl_unary_expression_test.cc b/src/reader/wgsl/parser_impl_unary_expression_test.cc index 70a1098cef..c1f4f349cd 100644 --- a/src/reader/wgsl/parser_impl_unary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_unary_expression_test.cc @@ -38,7 +38,7 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) { auto* ary = e->As(); ASSERT_TRUE(ary->array()->Is()); auto* ident = ary->array()->As(); - EXPECT_EQ(ident->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_TRUE(ary->idx_expr()->Is()); ASSERT_TRUE(ary->idx_expr()->Is()); diff --git a/src/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/reader/wgsl/parser_impl_variable_stmt_test.cc index 1a4aebaa73..223c9dc589 100644 --- a/src/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -32,7 +32,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->variable()->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_EQ(e->source().range.begin.line, 1u); ASSERT_EQ(e->source().range.begin.column, 5u); @@ -51,7 +51,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable(), nullptr); - EXPECT_EQ(e->variable()->symbol(), p->get_module().RegisterSymbol("a")); + EXPECT_EQ(e->variable()->symbol(), p->get_program().RegisterSymbol("a")); ASSERT_EQ(e->source().range.begin.line, 1u); ASSERT_EQ(e->source().range.begin.column, 5u); diff --git a/src/reader/wgsl/parser_test.cc b/src/reader/wgsl/parser_test.cc index c4b2fe7c8f..54031cf101 100644 --- a/src/reader/wgsl/parser_test.cc +++ b/src/reader/wgsl/parser_test.cc @@ -41,7 +41,7 @@ fn main() -> void { Parser p(&file); ASSERT_TRUE(p.Parse()) << p.error(); - auto m = p.module(); + auto m = p.program(); ASSERT_EQ(1u, m.Functions().size()); ASSERT_EQ(1u, m.global_variables().size()); } diff --git a/src/scope_stack_test.cc b/src/scope_stack_test.cc index f5c9f841aa..9d45252870 100644 --- a/src/scope_stack_test.cc +++ b/src/scope_stack_test.cc @@ -22,7 +22,7 @@ namespace tint { namespace { -class ScopeStackTest : public ast::BuilderWithModule, public testing::Test {}; +class ScopeStackTest : public ast::BuilderWithProgram, public testing::Test {}; TEST_F(ScopeStackTest, Global) { ScopeStack s; diff --git a/src/transform/bound_array_accessors.cc b/src/transform/bound_array_accessors.cc index f94a953a09..271c575cfe 100644 --- a/src/transform/bound_array_accessors.cc +++ b/src/transform/bound_array_accessors.cc @@ -55,9 +55,9 @@ namespace transform { BoundArrayAccessors::BoundArrayAccessors() = default; BoundArrayAccessors::~BoundArrayAccessors() = default; -Transform::Output BoundArrayAccessors::Run(ast::Module* in) { +Transform::Output BoundArrayAccessors::Run(const Program* in) { Output out; - CloneContext(&out.module, in) + CloneContext(&out.program, in) .ReplaceAll([&](CloneContext* ctx, ast::ArrayAccessorExpression* expr) { return Transform(expr, ctx, &out.diagnostics); }) diff --git a/src/transform/bound_array_accessors.h b/src/transform/bound_array_accessors.h index 0d78df171b..7c97a8b773 100644 --- a/src/transform/bound_array_accessors.h +++ b/src/transform/bound_array_accessors.h @@ -19,8 +19,8 @@ #include "src/ast/array_accessor_expression.h" #include "src/ast/expression.h" -#include "src/ast/module.h" #include "src/ast/statement.h" +#include "src/program.h" #include "src/scope_stack.h" #include "src/transform/transform.h" @@ -38,13 +38,13 @@ class BoundArrayAccessors : public Transform { /// Destructor ~BoundArrayAccessors() override; - /// Runs the transform on `module`, returning the transformation result. + /// Runs the transform on `program`, returning the transformation result. /// @note Users of Tint should register the transform with transform manager /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform module state cleanup operations. - /// @param module the source module to transform + /// Calling Run() directly does not perform program state cleanup operations. + /// @param program the source program to transform /// @returns the transformation result - Output Run(ast::Module* module) override; + Output Run(const Program* program) override; private: ast::ArrayAccessorExpression* Transform(ast::ArrayAccessorExpression* expr, diff --git a/src/transform/emit_vertex_point_size.cc b/src/transform/emit_vertex_point_size.cc index 79dd09bf50..3c91f796ad 100644 --- a/src/transform/emit_vertex_point_size.cc +++ b/src/transform/emit_vertex_point_size.cc @@ -38,42 +38,42 @@ const char kPointSizeVar[] = "tint_pointsize"; EmitVertexPointSize::EmitVertexPointSize() = default; EmitVertexPointSize::~EmitVertexPointSize() = default; -Transform::Output EmitVertexPointSize::Run(ast::Module* in) { +Transform::Output EmitVertexPointSize::Run(const Program* in) { Output out; if (!in->Functions().HasStage(ast::PipelineStage::kVertex)) { // If the module doesn't have any vertex stages, then there's nothing to do. - out.module = in->Clone(); + out.program = in->Clone(); return out; } - auto* f32 = out.module.create(); + auto* f32 = out.program.create(); // Declare the pointsize builtin output variable. - auto* pointsize_var = out.module.create( - Source{}, // source - out.module.RegisterSymbol(kPointSizeVar), // symbol - ast::StorageClass::kOutput, // storage_class - f32, // type - false, // is_const - nullptr, // constructor + auto* pointsize_var = out.program.create( + Source{}, // source + out.program.RegisterSymbol(kPointSizeVar), // symbol + ast::StorageClass::kOutput, // storage_class + f32, // type + false, // is_const + nullptr, // constructor ast::VariableDecorationList{ // decorations - out.module.create(Source{}, - ast::Builtin::kPointSize), + out.program.create(Source{}, + ast::Builtin::kPointSize), }); - out.module.AddGlobalVariable(pointsize_var); + out.program.AddGlobalVariable(pointsize_var); // Build the AST expression & statement for assigning pointsize one. - auto* one = out.module.create( - Source{}, out.module.create(Source{}, f32, 1.0f)); - auto* pointsize_ident = out.module.create( - Source{}, out.module.RegisterSymbol(kPointSizeVar)); - auto* pointsize_assign = out.module.create( + auto* one = out.program.create( + Source{}, out.program.create(Source{}, f32, 1.0f)); + auto* pointsize_ident = out.program.create( + Source{}, out.program.RegisterSymbol(kPointSizeVar)); + auto* pointsize_assign = out.program.create( Source{}, pointsize_ident, one); // Add the pointsize assignment statement to the front of all vertex stages. - CloneContext(&out.module, in) + CloneContext(&out.program, in) .ReplaceAll( [&](CloneContext* ctx, ast::Function* func) -> ast::Function* { if (func->pipeline_stage() != ast::PipelineStage::kVertex) { diff --git a/src/transform/emit_vertex_point_size.h b/src/transform/emit_vertex_point_size.h index fc48002911..edd07fa527 100644 --- a/src/transform/emit_vertex_point_size.h +++ b/src/transform/emit_vertex_point_size.h @@ -21,10 +21,10 @@ namespace tint { namespace transform { /// EmitVertexPointSize is a Transform that adds a PointSize builtin global -/// output variable to the module which is assigned 1.0 as the new first +/// output variable to the program which is assigned 1.0 as the new first /// statement for all vertex stage entry points. -/// If the module does not contain a vertex pipeline stage entry point then then -/// this transform is a no-op. +/// If the program does not contain a vertex pipeline stage entry point then +/// then this transform is a no-op. class EmitVertexPointSize : public Transform { public: /// Constructor @@ -32,13 +32,13 @@ class EmitVertexPointSize : public Transform { /// Destructor ~EmitVertexPointSize() override; - /// Runs the transform on `module`, returning the transformation result. + /// Runs the transform on `program`, returning the transformation result. /// @note Users of Tint should register the transform with transform manager /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform module state cleanup operations. - /// @param module the source module to transform + /// Calling Run() directly does not perform program state cleanup operations. + /// @param program the source program to transform /// @returns the transformation result - Output Run(ast::Module* module) override; + Output Run(const Program* program) override; }; } // namespace transform diff --git a/src/transform/first_index_offset.cc b/src/transform/first_index_offset.cc index b2946f0795..5c6e18410e 100644 --- a/src/transform/first_index_offset.cc +++ b/src/transform/first_index_offset.cc @@ -81,11 +81,11 @@ FirstIndexOffset::FirstIndexOffset(uint32_t binding, uint32_t group) FirstIndexOffset::~FirstIndexOffset() = default; -Transform::Output FirstIndexOffset::Run(ast::Module* in) { +Transform::Output FirstIndexOffset::Run(const Program* in) { // First do a quick check to see if the transform has already been applied. for (ast::Variable* var : in->global_variables()) { if (auto* dec_var = var->As()) { - if (dec_var->symbol() == in->RegisterSymbol(kBufferName)) { + if (dec_var->symbol() == in->GetSymbol(kBufferName)) { diag::Diagnostic err; err.message = "First index offset transform has already been applied."; err.severity = diag::Severity::Error; @@ -99,7 +99,8 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) { // Running TypeDeterminer as we require local_referenced_builtin_variables() // to be populated. TODO(bclayton) - it should not be necessary to re-run the // type determiner if semantic information is already generated. Remove. - TypeDeterminer td(in); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + TypeDeterminer td(const_cast(in)); if (!td.Determine()) { diag::Diagnostic err; err.severity = diag::Severity::Error; @@ -115,9 +116,9 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) { // Lazilly construct the UniformBuffer on first call to // maybe_create_buffer_var() ast::Variable* buffer_var = nullptr; - auto maybe_create_buffer_var = [&](ast::Module* mod) { + auto maybe_create_buffer_var = [&](Program* program) { if (buffer_var == nullptr) { - buffer_var = AddUniformBuffer(mod); + buffer_var = AddUniformBuffer(program); } }; @@ -126,7 +127,7 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) { // these builtins. Output out; - CloneContext(&out.module, in) + CloneContext(&out.program, in) .ReplaceAll([&](CloneContext* ctx, ast::Variable* var) -> ast::Variable* { for (ast::VariableDecoration* dec : var->decorations()) { if (auto* blt_dec = dec->As()) { @@ -194,16 +195,16 @@ uint32_t FirstIndexOffset::GetFirstInstanceOffset() { return instance_index_offset_; } -ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) { - auto* u32_type = mod->create(); +ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) { + auto* u32_type = dst->create(); ast::StructMemberList members; uint32_t offset = 0; if (has_vertex_index_) { ast::StructMemberDecorationList member_dec; member_dec.push_back( - mod->create(Source{}, offset)); - members.push_back(mod->create( - Source{}, mod->RegisterSymbol(kFirstVertexName), u32_type, + dst->create(Source{}, offset)); + members.push_back(dst->create( + Source{}, dst->RegisterSymbol(kFirstVertexName), u32_type, std::move(member_dec))); vertex_index_offset_ = offset; offset += 4; @@ -212,36 +213,36 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) { if (has_instance_index_) { ast::StructMemberDecorationList member_dec; member_dec.push_back( - mod->create(Source{}, offset)); - members.push_back(mod->create( - Source{}, mod->RegisterSymbol(kFirstInstanceName), u32_type, + dst->create(Source{}, offset)); + members.push_back(dst->create( + Source{}, dst->RegisterSymbol(kFirstInstanceName), u32_type, std::move(member_dec))); instance_index_offset_ = offset; offset += 4; } ast::StructDecorationList decos; - decos.push_back(mod->create(Source{})); + decos.push_back(dst->create(Source{})); - auto* struct_type = mod->create( - mod->RegisterSymbol(kStructName), - mod->create(Source{}, std::move(members), std::move(decos))); + auto* struct_type = dst->create( + dst->RegisterSymbol(kStructName), + dst->create(Source{}, std::move(members), std::move(decos))); - auto* idx_var = mod->create( + auto* idx_var = dst->create( Source{}, // source - mod->RegisterSymbol(kBufferName), // symbol + dst->RegisterSymbol(kBufferName), // symbol ast::StorageClass::kUniform, // storage_class struct_type, // type false, // is_const nullptr, // constructor ast::VariableDecorationList{ - mod->create(Source{}, binding_), - mod->create(Source{}, group_), + dst->create(Source{}, binding_), + dst->create(Source{}, group_), }); // decorations - mod->AddGlobalVariable(idx_var); + dst->AddGlobalVariable(idx_var); - mod->AddConstructedType(struct_type); + dst->AddConstructedType(struct_type); return idx_var; } @@ -250,28 +251,28 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset( const std::string& original_name, const std::string& field_name, ast::Variable* buffer_var, - ast::Module* mod) { + Program* dst) { auto* buffer = - mod->create(Source{}, buffer_var->symbol()); + dst->create(Source{}, buffer_var->symbol()); auto lhs_name = kIndexOffsetPrefix + original_name; - auto* constructor = mod->create( + auto* constructor = dst->create( Source{}, ast::BinaryOp::kAdd, - mod->create(Source{}, - mod->RegisterSymbol(lhs_name)), - mod->create( + dst->create(Source{}, + dst->RegisterSymbol(lhs_name)), + dst->create( Source{}, buffer, - mod->create( - Source{}, mod->RegisterSymbol(field_name)))); + dst->create( + Source{}, dst->RegisterSymbol(field_name)))); auto* var = - mod->create(Source{}, // source - mod->RegisterSymbol(original_name), // symbol + dst->create(Source{}, // source + dst->RegisterSymbol(original_name), // symbol ast::StorageClass::kNone, // storage_class - mod->create(), // type + dst->create(), // type true, // is_const constructor, // constructor ast::VariableDecorationList{}); // decorations - return mod->create(Source{}, var); + return dst->create(Source{}, var); } } // namespace transform diff --git a/src/transform/first_index_offset.h b/src/transform/first_index_offset.h index 7a6e7f8c6a..b540ca8389 100644 --- a/src/transform/first_index_offset.h +++ b/src/transform/first_index_offset.h @@ -17,8 +17,8 @@ #include -#include "src/ast/module.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/symbol.h" #include "src/transform/transform.h" @@ -68,13 +68,13 @@ class FirstIndexOffset : public Transform { FirstIndexOffset(uint32_t binding, uint32_t group); ~FirstIndexOffset() override; - /// Runs the transform on `module`, returning the transformation result. + /// Runs the transform on `program`, returning the transformation result. /// @note Users of Tint should register the transform with transform manager /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform module state cleanup operations. - /// @param module the source module to transform + /// Calling Run() directly does not perform program state cleanup operations. + /// @param program the source program to transform /// @returns the transformation result - Output Run(ast::Module* module) override; + Output Run(const Program* program) override; /// @returns whether shader uses vertex_index bool HasVertexIndex(); @@ -89,19 +89,19 @@ class FirstIndexOffset : public Transform { uint32_t GetFirstInstanceOffset(); private: - /// Adds uniform buffer with firstVertex/Instance to module + /// Adds uniform buffer with firstVertex/Instance to `program` /// @returns variable of new uniform buffer - ast::Variable* AddUniformBuffer(ast::Module* mod); + ast::Variable* AddUniformBuffer(Program* program); /// Adds constant with modified original_name builtin to func /// @param original_name the name of the original builtin used in function /// @param field_name name of field in firstVertex/Instance buffer /// @param buffer_var variable of firstVertex/Instance buffer - /// @param module the target module to contain the new ast nodes + /// @param program the target program to contain the new ast nodes ast::VariableDeclStatement* CreateFirstIndexOffset( const std::string& original_name, const std::string& field_name, ast::Variable* buffer_var, - ast::Module* module); + Program* program); uint32_t binding_; uint32_t group_; diff --git a/src/transform/manager.cc b/src/transform/manager.cc index 7ba0fb71b6..1503d62d8b 100644 --- a/src/transform/manager.cc +++ b/src/transform/manager.cc @@ -22,23 +22,23 @@ namespace transform { Manager::Manager() = default; Manager::~Manager() = default; -Transform::Output Manager::Run(ast::Module* module) { +Transform::Output Manager::Run(const Program* program) { Output out; if (!transforms_.empty()) { for (auto& transform : transforms_) { - auto res = transform->Run(module); - out.module = std::move(res.module); + auto res = transform->Run(program); + out.program = std::move(res.program); out.diagnostics.add(std::move(res.diagnostics)); if (out.diagnostics.contains_errors()) { return out; } - module = &out.module; + program = &out.program; } } else { - out.module = module->Clone(); + out.program = program->Clone(); } - TypeDeterminer td(&out.module); + TypeDeterminer td(&out.program); if (!td.Determine()) { diag::Diagnostic err; err.severity = diag::Severity::Error; diff --git a/src/transform/manager.h b/src/transform/manager.h index 8f838e4956..0816ce0f0a 100644 --- a/src/transform/manager.h +++ b/src/transform/manager.h @@ -41,18 +41,10 @@ class Manager : public Transform { transforms_.push_back(std::move(transform)); } - /// Runs the transforms on `module`, returning the transformation result. - /// @param module the source module to transform - /// @returns the transformed module and diagnostics - Output Run(ast::Module* module) override; - - /// Runs the transform on `program`, returning the transformation result. - /// @note Users of Tint should register the transform with transform manager - /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform program state cleanup operations. + /// Runs the transforms on `program`, returning the transformation result. /// @param program the source program to transform - /// @returns the transformation result - Output Run(Program* program) { return Run(&program->module); } + /// @returns the transformed program and diagnostics + Output Run(const Program* program) override; private: std::vector> transforms_; diff --git a/src/transform/test_helper.h b/src/transform/test_helper.h index 73a90f8b6f..74d6a7ef3d 100644 --- a/src/transform/test_helper.h +++ b/src/transform/test_helper.h @@ -46,8 +46,8 @@ class TransformTest : public testing::Test { return "WGSL reader failed:\n" + parser.error(); } - auto module = parser.module(); - TypeDeterminer td(&module); + auto program = parser.program(); + TypeDeterminer td(&program); if (!td.Determine()) { return "Type determination failed:\n" + td.error(); } @@ -56,7 +56,7 @@ class TransformTest : public testing::Test { for (auto& transform : transforms) { manager.append(std::move(transform)); } - auto result = manager.Run(&module); + auto result = manager.Run(&program); if (result.diagnostics.contains_errors()) { diag::Formatter::Style style; @@ -65,10 +65,10 @@ class TransformTest : public testing::Test { diag::Formatter(style).format(result.diagnostics); } - // Release the source module to ensure there's no uncloned data in result - { auto tmp = std::move(module); } + // Release the source program to ensure there's no uncloned data in result + { auto tmp = std::move(program); } - writer::wgsl::Generator generator(std::move(result.module)); + writer::wgsl::Generator generator(&result.program); if (!generator.Generate()) { return "WGSL writer failed:\n" + generator.error(); } diff --git a/src/transform/transform.cc b/src/transform/transform.cc index 9daa76304c..63bf604c36 100644 --- a/src/transform/transform.cc +++ b/src/transform/transform.cc @@ -23,22 +23,16 @@ namespace transform { Transform::Output::Output() = default; -Transform::Output::Output(ast::Module&& mod) : program{std::move(mod)} {} +Transform::Output::Output(Program&& p) : program(std::move(p)) {} -Transform::Output::Output(ast::Module&& mod, diag::List&& d) - : program{std::move(mod)}, diagnostics(std::move(d)) {} +Transform::Output::Output(Program&& p, diag::List&& d) + : program(std::move(p)), diagnostics(std::move(d)) {} Transform::Output::~Output() = default; -Transform::Output::Output(Output&& rhs) - : program(std::move(rhs.program)), - diagnostics(std::move(rhs.diagnostics)) {} +Transform::Output::Output(Output&&) = default; -Transform::Output& Transform::Output::operator=(Output&& rhs) { - program = std::move(rhs.program); - diagnostics = std::move(rhs.diagnostics); - return *this; -} +Transform::Output& Transform::Output::operator=(Output&& rhs) = default; Transform::Transform() = default; diff --git a/src/transform/transform.h b/src/transform/transform.h index 9c359f2dcf..9f00ec00ec 100644 --- a/src/transform/transform.h +++ b/src/transform/transform.h @@ -19,14 +19,13 @@ #include #include -#include "src/ast/module.h" #include "src/diagnostic/diagnostic.h" #include "src/program.h" namespace tint { namespace transform { -/// Interface for ast::Module transforms +/// Interface for Program transforms class Transform { public: /// Constructor @@ -40,13 +39,13 @@ class Transform { Output(); /// Constructor - /// @param module the module to move into this Output - explicit Output(ast::Module&& module); + /// @param program the program to move into this Output + explicit Output(Program&& program); /// Constructor - /// @param module the module to move into this Output + /// @param program the program to move into this Output /// @param diags the list of diagnostics to move into this Output - Output(ast::Module&& module, diag::List&& diags); + Output(Program&& program, diag::List&& diags); /// Move constructor /// @param output the output to move into this Output @@ -64,25 +63,15 @@ class Transform { Program program; /// Diagnostics raised while running the Transform. diag::List diagnostics; - /// The transformed module. May be empty on error. - ast::Module& module{program.module}; }; - /// Runs the transform on `module`, returning the transformation result. - /// @note Users of Tint should register the transform with transform manager - /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform module state cleanup operations. - /// @param module the source module to transform - /// @returns the transformation result - virtual Output Run(ast::Module* module) = 0; - /// Runs the transform on `program`, returning the transformation result. /// @note Users of Tint should register the transform with transform manager /// and invoke its Run(), instead of directly calling the transform's Run(). /// Calling Run() directly does not perform program state cleanup operations. /// @param program the source program to transform /// @returns the transformation result - Output Run(Program* program) { return Run(&program->module); } + virtual Output Run(const Program* program) = 0; protected: /// Clones the function `in` adding `statements` to the beginning of the diff --git a/src/transform/vertex_pulling.cc b/src/transform/vertex_pulling.cc index 8a17e7b32e..2915a02a0a 100644 --- a/src/transform/vertex_pulling.cc +++ b/src/transform/vertex_pulling.cc @@ -73,7 +73,7 @@ void VertexPulling::SetPullingBufferBindingSet(uint32_t number) { cfg.pulling_group = number; } -Transform::Output VertexPulling::Run(ast::Module* in) { +Transform::Output VertexPulling::Run(const Program* in) { // Check SetVertexState was called if (!cfg.vertex_state_set) { diag::Diagnostic err; @@ -103,13 +103,13 @@ Transform::Output VertexPulling::Run(ast::Module* in) { // following stages will pass Output out; - State state{in, &out.module, cfg}; + State state{in, &out.program, cfg}; state.FindOrInsertVertexIndexIfUsed(); state.FindOrInsertInstanceIndexIfUsed(); state.ConvertVertexInputVariablesToPrivate(); state.AddVertexStorageBuffers(); - CloneContext(&out.module, in) + CloneContext(&out.program, in) .ReplaceAll([&](CloneContext* ctx, ast::Function* f) -> ast::Function* { if (f == func) { return CloneWithStatementsAtStart( @@ -126,7 +126,7 @@ VertexPulling::Config::Config() = default; VertexPulling::Config::Config(const Config&) = default; VertexPulling::Config::~Config() = default; -VertexPulling::State::State(ast::Module* i, ast::Module* o, const Config& c) +VertexPulling::State::State(const Program* i, Program* o, const Config& c) : in(i), out(o), cfg(c) {} VertexPulling::State::State(const State&) = default; @@ -231,7 +231,8 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() { } void VertexPulling::State::ConvertVertexInputVariablesToPrivate() { - for (auto*& v : in->global_variables()) { + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + for (auto*& v : const_cast(in)->global_variables()) { if (v->storage_class() != ast::StorageClass::kInput) { continue; } diff --git a/src/transform/vertex_pulling.h b/src/transform/vertex_pulling.h index 2a75cc5cf6..7569cb7ae0 100644 --- a/src/transform/vertex_pulling.h +++ b/src/transform/vertex_pulling.h @@ -22,9 +22,9 @@ #include "src/ast/expression.h" #include "src/ast/function.h" -#include "src/ast/module.h" #include "src/ast/statement.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/transform/transform.h" namespace tint { @@ -114,7 +114,7 @@ struct VertexBufferLayoutDescriptor { /// attributes using VertexStateDescriptor = std::vector; -/// Converts a module to use vertex pulling +/// Converts a program to use vertex pulling /// /// Variables which accept vertex input are var with a location decoration. /// This transform will convert those to be assigned from storage buffers @@ -159,13 +159,13 @@ class VertexPulling : public Transform { /// @param number the group number we will use void SetPullingBufferBindingGroup(uint32_t number); - /// Runs the transform on `module`, returning the transformation result. + /// Runs the transform on `program`, returning the transformation result. /// @note Users of Tint should register the transform with transform manager /// and invoke its Run(), instead of directly calling the transform's Run(). - /// Calling Run() directly does not perform module state cleanup operations. - /// @param module the source module to transform + /// Calling Run() directly does not perform program state cleanup operations. + /// @param program the source program to transform /// @returns the transformation result - Output Run(ast::Module* module) override; + Output Run(const Program* program) override; private: struct Config { @@ -183,7 +183,7 @@ class VertexPulling : public Transform { Config cfg; struct State { - State(ast::Module* in, ast::Module* out, const Config& c); + State(const Program* in, Program* out, const Config& c); explicit State(const State&); ~State(); @@ -263,8 +263,8 @@ class VertexPulling : public Transform { type::Type* GetI32Type() const; type::Type* GetF32Type() const; - ast::Module* const in; - ast::Module* const out; + const Program* const in; + Program* const out; Config const cfg; std::unordered_map location_to_var; diff --git a/src/type/access_control_type.cc b/src/type/access_control_type.cc index d694d8b9d7..5dafaa391f 100644 --- a/src/type/access_control_type.cc +++ b/src/type/access_control_type.cc @@ -16,8 +16,8 @@ #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::AccessControl); diff --git a/src/type/alias_type.cc b/src/type/alias_type.cc index a7253dd62f..0d10ad3645 100644 --- a/src/type/alias_type.cc +++ b/src/type/alias_type.cc @@ -16,8 +16,8 @@ #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Alias); diff --git a/src/type/array_type.cc b/src/type/array_type.cc index 881b90bb94..469b4ea42c 100644 --- a/src/type/array_type.cc +++ b/src/type/array_type.cc @@ -17,9 +17,9 @@ #include #include -#include "src/ast/module.h" #include "src/ast/stride_decoration.h" #include "src/clone_context.h" +#include "src/program.h" #include "src/type/vector_type.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Array); diff --git a/src/type/bool_type.cc b/src/type/bool_type.cc index 5f4eb3be17..de85009e0a 100644 --- a/src/type/bool_type.cc +++ b/src/type/bool_type.cc @@ -14,8 +14,8 @@ #include "src/type/bool_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Bool); diff --git a/src/type/depth_texture_type.cc b/src/type/depth_texture_type.cc index a5b39e8d29..bc8e584101 100644 --- a/src/type/depth_texture_type.cc +++ b/src/type/depth_texture_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::DepthTexture); diff --git a/src/type/f32_type.cc b/src/type/f32_type.cc index ad6ff66fe8..c60c1eba04 100644 --- a/src/type/f32_type.cc +++ b/src/type/f32_type.cc @@ -14,8 +14,8 @@ #include "src/type/f32_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::F32); diff --git a/src/type/i32_type.cc b/src/type/i32_type.cc index cac2b568df..402a8a903d 100644 --- a/src/type/i32_type.cc +++ b/src/type/i32_type.cc @@ -14,8 +14,8 @@ #include "src/type/i32_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::I32); diff --git a/src/type/matrix_type.cc b/src/type/matrix_type.cc index 9f0181052c..9b4d0978d1 100644 --- a/src/type/matrix_type.cc +++ b/src/type/matrix_type.cc @@ -16,8 +16,8 @@ #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/vector_type.h" diff --git a/src/type/multisampled_texture_type.cc b/src/type/multisampled_texture_type.cc index 22b4fe3bd3..504019b01b 100644 --- a/src/type/multisampled_texture_type.cc +++ b/src/type/multisampled_texture_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::MultisampledTexture); diff --git a/src/type/pointer_type.cc b/src/type/pointer_type.cc index 825bd02382..fd31228318 100644 --- a/src/type/pointer_type.cc +++ b/src/type/pointer_type.cc @@ -14,8 +14,8 @@ #include "src/type/pointer_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Pointer); diff --git a/src/type/sampled_texture_type.cc b/src/type/sampled_texture_type.cc index 1aab1ab6e2..119c547336 100644 --- a/src/type/sampled_texture_type.cc +++ b/src/type/sampled_texture_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::SampledTexture); diff --git a/src/type/sampler_type.cc b/src/type/sampler_type.cc index 139bea1e36..60fc8ffc62 100644 --- a/src/type/sampler_type.cc +++ b/src/type/sampler_type.cc @@ -14,8 +14,8 @@ #include "src/type/sampler_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Sampler); diff --git a/src/type/storage_texture_type.cc b/src/type/storage_texture_type.cc index 9eb69f2491..09afd489cb 100644 --- a/src/type/storage_texture_type.cc +++ b/src/type/storage_texture_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::StorageTexture); diff --git a/src/type/struct_type.cc b/src/type/struct_type.cc index 99ddc87c28..458aabfb15 100644 --- a/src/type/struct_type.cc +++ b/src/type/struct_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" #include "src/type/alias_type.h" #include "src/type/array_type.h" #include "src/type/matrix_type.h" diff --git a/src/type/test_helper.h b/src/type/test_helper.h index e161d04ece..3a96f7874e 100644 --- a/src/type/test_helper.h +++ b/src/type/test_helper.h @@ -21,15 +21,15 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" -#include "src/ast/module.h" #include "src/demangler.h" +#include "src/program.h" namespace tint { namespace type { /// Helper class for testing template -class TestHelperBase : public BASE, public ast::BuilderWithModule { +class TestHelperBase : public BASE, public ast::BuilderWithProgram { public: /// Demangles the given string /// @param s the string to demangle diff --git a/src/type/type.h b/src/type/type.h index c55d10abe4..847f5c8764 100644 --- a/src/type/type.h +++ b/src/type/type.h @@ -23,9 +23,7 @@ namespace tint { // Forward declarations class CloneContext; -namespace ast { -class Module; -} // namespace ast +class Program; namespace type { @@ -103,12 +101,12 @@ class Type : public Castable { /// A helper method for cloning the `Type` `t` if it is not null. /// If `t` is null, then `Clone()` returns null. - /// @param m the module to clone `n` into + /// @param p the program to clone `n` into /// @param t the `Type` to clone (if not null) /// @return the cloned type template - static T* Clone(ast::Module* m, const T* t) { - return (t != nullptr) ? static_cast(t->Clone(m)) : nullptr; + static T* Clone(Program* p, const T* t) { + return (t != nullptr) ? static_cast(t->Clone(p)) : nullptr; } }; diff --git a/src/type/u32_type.cc b/src/type/u32_type.cc index be514fd845..d98dbb66e2 100644 --- a/src/type/u32_type.cc +++ b/src/type/u32_type.cc @@ -14,8 +14,8 @@ #include "src/type/u32_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::U32); diff --git a/src/type/vector_type.cc b/src/type/vector_type.cc index 624e81d6c4..85a1683381 100644 --- a/src/type/vector_type.cc +++ b/src/type/vector_type.cc @@ -17,8 +17,8 @@ #include #include -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Vector); diff --git a/src/type/void_type.cc b/src/type/void_type.cc index 92a46dd3d3..2f9b6f8e53 100644 --- a/src/type/void_type.cc +++ b/src/type/void_type.cc @@ -14,8 +14,8 @@ #include "src/type/void_type.h" -#include "src/ast/module.h" #include "src/clone_context.h" +#include "src/program.h" TINT_INSTANTIATE_CLASS_ID(tint::type::Void); diff --git a/src/type_determiner.cc b/src/type_determiner.cc index fd4d657475..2cb1535597 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -59,10 +59,7 @@ namespace tint { -TypeDeterminer::TypeDeterminer(ast::Module* mod) : mod_(mod) {} - -TypeDeterminer::TypeDeterminer(Program* program) - : TypeDeterminer(&program->module) {} +TypeDeterminer::TypeDeterminer(Program* program) : program_(program) {} TypeDeterminer::~TypeDeterminer() = default; @@ -104,7 +101,7 @@ void TypeDeterminer::set_referenced_from_function_if_needed(ast::Variable* var, bool TypeDeterminer::Determine() { std::vector storage_textures; - for (auto& it : mod_->types()) { + for (auto& it : program_->types()) { if (auto* storage = it.second->UnwrapIfNeeded()->As()) { storage_textures.emplace_back(storage); @@ -119,7 +116,7 @@ bool TypeDeterminer::Determine() { } } - for (auto* var : mod_->global_variables()) { + for (auto* var : program_->global_variables()) { variable_stack_.set_global(var->symbol(), var); if (var->has_constructor()) { @@ -129,13 +126,13 @@ bool TypeDeterminer::Determine() { } } - if (!DetermineFunctions(mod_->Functions())) { + if (!DetermineFunctions(program_->Functions())) { return false; } // Walk over the caller to callee information and update functions with which // entry points call those functions. - for (auto* func : mod_->Functions()) { + for (auto* func : program_->Functions()) { if (!func->IsEntryPoint()) { continue; } @@ -354,7 +351,7 @@ bool TypeDeterminer::DetermineArrayAccessor( } else if (auto* vec = parent_type->As()) { ret = vec->type(); } else if (auto* mat = parent_type->As()) { - ret = mod_->create(mat->type(), mat->rows()); + ret = program_->create(mat->type(), mat->rows()); } else { set_error(expr->source(), "invalid parent type (" + parent_type->type_name() + @@ -364,13 +361,13 @@ bool TypeDeterminer::DetermineArrayAccessor( // If we're extracting from a pointer, we return a pointer. if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); + ret = program_->create(ret, ptr->storage_class()); } else if (auto* arr = parent_type->As()) { if (!arr->type()->is_scalar()) { // If we extract a non-scalar from an array then we also get a pointer. We // will generate a Function storage class variable to store this // into. - ret = mod_->create(ret, ast::StorageClass::kFunction); + ret = program_->create(ret, ast::StorageClass::kFunction); } } expr->set_result_type(ret); @@ -407,10 +404,11 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) { caller_to_callee_[current_function_->symbol()].push_back( ident->symbol()); - auto* callee_func = mod_->Functions().Find(ident->symbol()); + auto* callee_func = program_->Functions().Find(ident->symbol()); if (callee_func == nullptr) { - set_error(expr->source(), "unable to find called function: " + - mod_->SymbolToName(ident->symbol())); + set_error(expr->source(), + "unable to find called function: " + + program_->SymbolToName(ident->symbol())); return false; } @@ -436,7 +434,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) { auto func_sym = expr->func()->As()->symbol(); set_error(expr->source(), "v-0005: function must be declared before use: '" + - mod_->SymbolToName(func_sym) + "'"); + program_->SymbolToName(func_sym) + "'"); return false; } @@ -523,7 +521,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, if (ast::intrinsic::IsDerivative(ident->intrinsic())) { if (expr->params().size() != 1) { set_error(expr->source(), "incorrect number of parameters for " + - mod_->SymbolToName(ident->symbol())); + program_->SymbolToName(ident->symbol())); return false; } @@ -534,26 +532,26 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } if (ident->intrinsic() == ast::Intrinsic::kAny || ident->intrinsic() == ast::Intrinsic::kAll) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(program_->create()); return true; } if (ident->intrinsic() == ast::Intrinsic::kArrayLength) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(program_->create()); return true; } if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) { if (expr->params().size() != 1) { set_error(expr->source(), "incorrect number of parameters for " + - mod_->SymbolToName(ident->symbol())); + program_->SymbolToName(ident->symbol())); return false; } - auto* bool_type = mod_->create(); + auto* bool_type = program_->create(); auto* param_type = expr->params()[0]->result_type()->UnwrapPtrIfNeeded(); if (auto* vec = param_type->As()) { expr->func()->set_result_type( - mod_->create(bool_type, vec->size())); + program_->create(bool_type, vec->size())); } else { expr->func()->set_result_type(bool_type); } @@ -565,7 +563,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, auto* texture_param = expr->params()[0]; if (!texture_param->result_type()->UnwrapAll()->Is()) { set_error(expr->source(), "invalid first argument for " + - mod_->SymbolToName(ident->symbol())); + program_->SymbolToName(ident->symbol())); return false; } type::Texture* texture = @@ -677,7 +675,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, if (expr->params().size() != param.count) { set_error(expr->source(), "incorrect number of parameters for " + - mod_->SymbolToName(ident->symbol()) + ", got " + + program_->SymbolToName(ident->symbol()) + ", got " + std::to_string(expr->params().size()) + " and expected " + std::to_string(param.count)); return false; @@ -690,7 +688,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, type::Type* return_type = nullptr; switch (ident->intrinsic()) { case ast::Intrinsic::kTextureDimensions: { - auto* i32 = mod_->create(); + auto* i32 = program_->create(); switch (texture->dim()) { default: set_error(expr->source(), "invalid texture dimensions"); @@ -701,12 +699,12 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, break; case type::TextureDimension::k2d: case type::TextureDimension::k2dArray: - return_type = mod_->create(i32, 2); + return_type = program_->create(i32, 2); break; case type::TextureDimension::k3d: case type::TextureDimension::kCube: case type::TextureDimension::kCubeArray: - return_type = mod_->create(i32, 3); + return_type = program_->create(i32, 3); break; } break; @@ -714,14 +712,14 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, case ast::Intrinsic::kTextureNumLayers: case ast::Intrinsic::kTextureNumLevels: case ast::Intrinsic::kTextureNumSamples: - return_type = mod_->create(); + return_type = program_->create(); break; case ast::Intrinsic::kTextureStore: - return_type = mod_->create(); + return_type = program_->create(); break; default: { if (texture->Is()) { - return_type = mod_->create(); + return_type = program_->create(); } else { type::Type* type = nullptr; if (auto* storage = texture->As()) { @@ -736,7 +734,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, "unknown texture type for texture sampling"); return false; } - return_type = mod_->create(type, 4); + return_type = program_->create(type, 4); } } } @@ -745,13 +743,13 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, return true; } if (ident->intrinsic() == ast::Intrinsic::kDot) { - expr->func()->set_result_type(mod_->create()); + expr->func()->set_result_type(program_->create()); return true; } if (ident->intrinsic() == ast::Intrinsic::kSelect) { if (expr->params().size() != 3) { set_error(expr->source(), "incorrect number of parameters for " + - mod_->SymbolToName(ident->symbol()) + + program_->SymbolToName(ident->symbol()) + " expected 3 got " + std::to_string(expr->params().size())); return false; @@ -771,13 +769,14 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, } } if (data == nullptr) { - error_ = "unable to find intrinsic " + mod_->SymbolToName(ident->symbol()); + error_ = + "unable to find intrinsic " + program_->SymbolToName(ident->symbol()); return false; } if (expr->params().size() != data->param_count) { set_error(expr->source(), "incorrect number of parameters for " + - mod_->SymbolToName(ident->symbol()) + + program_->SymbolToName(ident->symbol()) + ". Expected " + std::to_string(data->param_count) + " got " + std::to_string(expr->params().size())); @@ -795,7 +794,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, !result_types.back()->is_integer_scalar_or_vector()) { set_error(expr->source(), "incorrect type for " + - mod_->SymbolToName(ident->symbol()) + ". " + + program_->SymbolToName(ident->symbol()) + ". " + "Requires float or int, scalar or vector values"); return false; } @@ -804,7 +803,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, if (!result_types.back()->is_float_scalar_or_vector()) { set_error(expr->source(), "incorrect type for " + - mod_->SymbolToName(ident->symbol()) + ". " + + program_->SymbolToName(ident->symbol()) + ". " + "Requires float scalar or float vector values"); return false; } @@ -814,34 +813,36 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, if (!result_types.back()->is_integer_scalar_or_vector()) { set_error(expr->source(), "incorrect type for " + - mod_->SymbolToName(ident->symbol()) + ". " + + program_->SymbolToName(ident->symbol()) + ". " + "Requires integer scalar or integer vector values"); return false; } break; case IntrinsicDataType::kFloatVector: if (!result_types.back()->is_float_vector()) { - set_error(expr->source(), "incorrect type for " + - mod_->SymbolToName(ident->symbol()) + - ". " + "Requires float vector values"); + set_error(expr->source(), + "incorrect type for " + + program_->SymbolToName(ident->symbol()) + ". " + + "Requires float vector values"); return false; } if (data->vector_size > 0 && result_types.back()->As()->size() != data->vector_size) { - set_error(expr->source(), "incorrect vector size for " + - mod_->SymbolToName(ident->symbol()) + - ". " + "Requires " + - std::to_string(data->vector_size) + - " elements"); + set_error(expr->source(), + "incorrect vector size for " + + program_->SymbolToName(ident->symbol()) + ". " + + "Requires " + std::to_string(data->vector_size) + + " elements"); return false; } break; case IntrinsicDataType::kMatrix: if (!result_types.back()->Is()) { - set_error(expr->source(), "incorrect type for " + - mod_->SymbolToName(ident->symbol()) + - ". Requires matrix value"); + set_error(expr->source(), + "incorrect type for " + + program_->SymbolToName(ident->symbol()) + + ". Requires matrix value"); return false; } break; @@ -852,7 +853,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident, for (size_t i = 1; i < data->param_count; ++i) { if (result_types[0] != result_types[i]) { set_error(expr->source(), "mismatched parameter types for " + - mod_->SymbolToName(ident->symbol())); + program_->SymbolToName(ident->symbol())); return false; } } @@ -903,7 +904,7 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) { expr->set_result_type(var->type()); } else { expr->set_result_type( - mod_->create(var->type(), var->storage_class())); + program_->create(var->type(), var->storage_class())); } set_referenced_from_function_if_needed(var, true); @@ -919,14 +920,14 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) { if (!SetIntrinsicIfNeeded(expr)) { set_error(expr->source(), "v-0006: identifier must be declared before use: " + - mod_->SymbolToName(symbol)); + program_->SymbolToName(symbol)); return false; } return true; } bool TypeDeterminer::SetIntrinsicIfNeeded(ast::IdentifierExpression* ident) { - auto name = mod_->SymbolToName(ident->symbol()); + auto name = program_->SymbolToName(ident->symbol()); if (name == "abs") { ident->set_intrinsic(ast::Intrinsic::kAbs); } else if (name == "acos") { @@ -1099,32 +1100,33 @@ bool TypeDeterminer::DetermineMemberAccessor( } if (ret == nullptr) { - set_error(expr->source(), - "struct member " + mod_->SymbolToName(symbol) + " not found"); + set_error( + expr->source(), + "struct member " + program_->SymbolToName(symbol) + " not found"); return false; } // If we're extracting from a pointer, we return a pointer. if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); + ret = program_->create(ret, ptr->storage_class()); } } else if (auto* vec = data_type->As()) { // TODO(dsinclair): Swizzle, record into the identifier experesion - auto size = mod_->SymbolToName(expr->member()->symbol()).size(); + auto size = program_->SymbolToName(expr->member()->symbol()).size(); if (size == 1) { // A single element swizzle is just the type of the vector. ret = vec->type(); // If we're extracting from a pointer, we return a pointer. if (auto* ptr = res->As()) { - ret = mod_->create(ret, ptr->storage_class()); + ret = program_->create(ret, ptr->storage_class()); } } else { // The vector will have a number of components equal to the length of the // swizzle. This assumes the validator will check that the swizzle // is correct. - ret = - mod_->create(vec->type(), static_cast(size)); + ret = program_->create(vec->type(), + static_cast(size)); } } else { set_error( @@ -1155,10 +1157,11 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) { if (expr->IsLogicalAnd() || expr->IsLogicalOr() || expr->IsEqual() || expr->IsNotEqual() || expr->IsLessThan() || expr->IsGreaterThan() || expr->IsLessThanEqual() || expr->IsGreaterThanEqual()) { - auto* bool_type = mod_->create(); + auto* bool_type = program_->create(); auto* param_type = expr->lhs()->result_type()->UnwrapPtrIfNeeded(); if (auto* vec = param_type->As()) { - expr->set_result_type(mod_->create(bool_type, vec->size())); + expr->set_result_type( + program_->create(bool_type, vec->size())); } else { expr->set_result_type(bool_type); } @@ -1175,14 +1178,14 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) { auto* lhs_vec = lhs_type->As(); auto* rhs_vec = rhs_type->As(); if (lhs_mat && rhs_mat) { - expr->set_result_type(mod_->create( + expr->set_result_type(program_->create( lhs_mat->type(), lhs_mat->rows(), rhs_mat->columns())); } else if (lhs_mat && rhs_vec) { expr->set_result_type( - mod_->create(lhs_mat->type(), lhs_mat->rows())); + program_->create(lhs_mat->type(), lhs_mat->rows())); } else if (lhs_vec && rhs_mat) { expr->set_result_type( - mod_->create(rhs_mat->type(), rhs_mat->columns())); + program_->create(rhs_mat->type(), rhs_mat->columns())); } else if (lhs_mat) { // matrix * scalar expr->set_result_type(lhs_type); @@ -1233,7 +1236,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(type::StorageTexture* tex) { case type::ImageFormat::kRg32Uint: case type::ImageFormat::kRgba16Uint: case type::ImageFormat::kRgba32Uint: { - tex->set_type(mod_->create()); + tex->set_type(program_->create()); return true; } @@ -1246,7 +1249,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(type::StorageTexture* tex) { case type::ImageFormat::kRg32Sint: case type::ImageFormat::kRgba16Sint: case type::ImageFormat::kRgba32Sint: { - tex->set_type(mod_->create()); + tex->set_type(program_->create()); return true; } @@ -1267,7 +1270,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(type::StorageTexture* tex) { case type::ImageFormat::kRg32Float: case type::ImageFormat::kRgba16Float: case type::ImageFormat::kRgba32Float: { - tex->set_type(mod_->create()); + tex->set_type(program_->create()); return true; } diff --git a/src/type_determiner.h b/src/type_determiner.h index be1e8ec441..5387714861 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -41,15 +41,11 @@ class Variable; } // namespace ast -/// Determines types for all items in the given tint module +/// Determines types for all items in the given tint program class TypeDeterminer { public: /// Constructor - /// @param mod the module to update with typing information - explicit TypeDeterminer(ast::Module* mod); - - /// Constructor - /// @param program the module to update with typing information + /// @param program the program to update with typing information explicit TypeDeterminer(Program* program); /// Destructor @@ -142,7 +138,7 @@ class TypeDeterminer { bool DetermineMemberAccessor(ast::MemberAccessorExpression* expr); bool DetermineUnaryOp(ast::UnaryOpExpression* expr); - ast::Module* mod_; + Program* program_; std::string error_; ScopeStack variable_stack_; std::unordered_map symbol_to_function_; diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 5138838c4f..068a1ceb24 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -87,9 +87,9 @@ class FakeExpr : public ast::Expression { void to_str(std::ostream&, size_t) const override {} }; -class TypeDeterminerHelper : public ast::BuilderWithModule { +class TypeDeterminerHelper : public ast::BuilderWithProgram { public: - TypeDeterminerHelper() : td_(std::make_unique(mod)) {} + TypeDeterminerHelper() : td_(std::make_unique(program)) {} TypeDeterminer* td() const { return td_.get(); } diff --git a/src/validator/validator.cc b/src/validator/validator.cc index 07466d90ce..c0e4aa8bfd 100644 --- a/src/validator/validator.cc +++ b/src/validator/validator.cc @@ -22,8 +22,8 @@ Validator::Validator() = default; Validator::~Validator() = default; -bool Validator::Validate(const ast::Module* module) { - ValidatorImpl impl(module); +bool Validator::Validate(const Program* program) { + ValidatorImpl impl(program); bool ret = impl.Validate(); diags_ = impl.diagnostics(); return ret; diff --git a/src/validator/validator.h b/src/validator/validator.h index 9d3fbc7d01..65b9777852 100644 --- a/src/validator/validator.h +++ b/src/validator/validator.h @@ -20,7 +20,6 @@ #include "src/ast/assignment_statement.h" #include "src/ast/expression.h" -#include "src/ast/module.h" #include "src/ast/statement.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" @@ -28,22 +27,17 @@ namespace tint { -/// Determines if the module is complete and valid +/// Determines if the program is complete and valid class Validator { public: /// Constructor Validator(); ~Validator(); - /// Runs the validator - /// @param module the module to validate - /// @returns true if the validation was successful - bool Validate(const ast::Module* module); - /// Runs the validator /// @param program the program to validate /// @returns true if the validation was successful - bool Validate(const Program* program) { return Validate(&program->module); } + bool Validate(const Program* program); /// @returns error messages from the validator std::string error() { diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc index 46831e9191..73befed8c9 100644 --- a/src/validator/validator_impl.cc +++ b/src/validator/validator_impl.cc @@ -40,7 +40,7 @@ namespace tint { -ValidatorImpl::ValidatorImpl(const ast::Module* module) : module_(*module) {} +ValidatorImpl::ValidatorImpl(const Program* program) : program_(program) {} ValidatorImpl::~ValidatorImpl() = default; @@ -65,16 +65,16 @@ void ValidatorImpl::add_error(const Source& src, const std::string& msg) { bool ValidatorImpl::Validate() { function_stack_.push_scope(); - if (!ValidateGlobalVariables(module_.global_variables())) { + if (!ValidateGlobalVariables(program_->global_variables())) { return false; } - if (!ValidateConstructedTypes(module_.constructed_types())) { + if (!ValidateConstructedTypes(program_->constructed_types())) { return false; } - if (!ValidateFunctions(module_.Functions())) { + if (!ValidateFunctions(program_->Functions())) { return false; } - if (!ValidateEntryPoint(module_.Functions())) { + if (!ValidateEntryPoint(program_->Functions())) { return false; } function_stack_.pop_scope(); @@ -99,7 +99,7 @@ bool ValidatorImpl::ValidateConstructedTypes( add_error(member->source(), "v-0031", "a struct containing a runtime-sized array " "must be in the 'storage' storage class: '" + - module_.SymbolToName(st->symbol()) + "'"); + program_->SymbolToName(st->symbol()) + "'"); return false; } } @@ -116,7 +116,7 @@ bool ValidatorImpl::ValidateGlobalVariables( if (variable_stack_.has(var->symbol())) { add_error(var->source(), "v-0011", "redeclared global identifier '" + - module_.SymbolToName(var->symbol()) + "'"); + program_->SymbolToName(var->symbol()) + "'"); return false; } if (!var->is_const() && var->storage_class() == ast::StorageClass::kNone) { @@ -140,7 +140,7 @@ bool ValidatorImpl::ValidateFunctions(const ast::FunctionList& funcs) { if (function_stack_.has(func->symbol())) { add_error(func->source(), "v-0016", "function names must be unique '" + - module_.SymbolToName(func->symbol()) + "'"); + program_->SymbolToName(func->symbol()) + "'"); return false; } @@ -163,14 +163,14 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) { if (!func->params().empty()) { add_error(func->source(), "v-0023", "Entry point function must accept no parameters: '" + - module_.SymbolToName(func->symbol()) + "'"); + program_->SymbolToName(func->symbol()) + "'"); return false; } if (!func->return_type()->Is()) { add_error(func->source(), "v-0024", "Entry point function must return void: '" + - module_.SymbolToName(func->symbol()) + "'"); + program_->SymbolToName(func->symbol()) + "'"); return false; } auto stage_deco_count = 0; @@ -275,7 +275,7 @@ bool ValidatorImpl::ValidateDeclStatement( error_code = "v-0013"; } add_error(decl->source(), error_code, - "redeclared identifier '" + module_.SymbolToName(symbol) + "'"); + "redeclared identifier '" + program_->SymbolToName(symbol) + "'"); return false; } // TODO(dneto): Check type compatibility of the initializer. @@ -415,13 +415,13 @@ bool ValidatorImpl::ValidateCallExpr(const ast::CallExpression* expr) { if (!function_stack_.has(symbol)) { add_error(expr->source(), "v-0005", "function must be declared before use: '" + - module_.SymbolToName(symbol) + "'"); + program_->SymbolToName(symbol) + "'"); return false; } if (symbol == current_function_->symbol()) { - add_error( - expr->source(), "v-0004", - "recursion is not allowed: '" + module_.SymbolToName(symbol) + "'"); + add_error(expr->source(), "v-0004", + "recursion is not allowed: '" + + program_->SymbolToName(symbol) + "'"); return false; } } @@ -447,7 +447,7 @@ bool ValidatorImpl::ValidateBadAssignmentToIdentifier( if (var->is_const()) { add_error(assign->source(), "v-0021", "cannot re-assign a constant: '" + - module_.SymbolToName(ident->symbol()) + "'"); + program_->SymbolToName(ident->symbol()) + "'"); return false; } } else { @@ -455,7 +455,7 @@ bool ValidatorImpl::ValidateBadAssignmentToIdentifier( // when validating the subexpression. add_error( ident->source(), "v-0006", - "'" + module_.SymbolToName(ident->symbol()) + "' is not declared"); + "'" + program_->SymbolToName(ident->symbol()) + "' is not declared"); return false; } return true; @@ -527,7 +527,7 @@ bool ValidatorImpl::ValidateIdentifier(const ast::IdentifierExpression* ident) { if (!variable_stack_.get(ident->symbol(), &var)) { add_error( ident->source(), "v-0006", - "'" + module_.SymbolToName(ident->symbol()) + "' is not declared"); + "'" + program_->SymbolToName(ident->symbol()) + "' is not declared"); return false; } return true; diff --git a/src/validator/validator_impl.h b/src/validator/validator_impl.h index 58aa2e106c..0ee8c059a6 100644 --- a/src/validator/validator_impl.h +++ b/src/validator/validator_impl.h @@ -24,7 +24,6 @@ #include "src/ast/call_expression.h" #include "src/ast/expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/statement.h" #include "src/ast/switch_statement.h" @@ -32,16 +31,17 @@ #include "src/ast/variable_decl_statement.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" +#include "src/program.h" #include "src/scope_stack.h" namespace tint { -/// Determines if the module is complete and valid +/// Determines if the program is complete and valid class ValidatorImpl { public: /// Constructor - /// @param module the module to validate - explicit ValidatorImpl(const ast::Module* module); + /// @param program the program to validate + explicit ValidatorImpl(const Program* program); ~ValidatorImpl(); /// Runs the validator @@ -159,7 +159,7 @@ class ValidatorImpl { } private: - const ast::Module& module_; + const Program* program_; diag::List diags_; ScopeStack variable_stack_; ScopeStack function_stack_; diff --git a/src/validator/validator_test_helper.h b/src/validator/validator_test_helper.h index 9500e80b08..25a59ddd53 100644 --- a/src/validator/validator_test_helper.h +++ b/src/validator/validator_test_helper.h @@ -28,13 +28,13 @@ namespace tint { /// A helper for testing validation -class ValidatorTestHelper : public ast::BuilderWithModule { +class ValidatorTestHelper : public ast::BuilderWithProgram { public: /// Constructor ValidatorTestHelper(); ~ValidatorTestHelper() override; - /// Builds and returns a validator from the module. + /// Builds and returns a validator from the program. /// @note The validator is only built once. Multiple calls to Build() will /// return the same ValidatorImpl without rebuilding. /// @return the built validator @@ -42,7 +42,7 @@ class ValidatorTestHelper : public ast::BuilderWithModule { if (val_) { return *val_; } - val_ = std::make_unique(mod); + val_ = std::make_unique(program); for (auto* var : vars_for_testing_) { val_->RegisterVariableForTesting(var); } diff --git a/src/writer/hlsl/generator.cc b/src/writer/hlsl/generator.cc index 90d78c6b14..15f2ee857f 100644 --- a/src/writer/hlsl/generator.cc +++ b/src/writer/hlsl/generator.cc @@ -20,12 +20,8 @@ namespace tint { namespace writer { namespace hlsl { -Generator::Generator(ast::Module module) - : module_(std::move(module)), - impl_(std::make_unique(&module_)) {} - -Generator::Generator(Program* program) - : impl_(std::make_unique(&program->module)) {} +Generator::Generator(const Program* program) + : impl_(std::make_unique(program)) {} Generator::~Generator() = default; diff --git a/src/writer/hlsl/generator.h b/src/writer/hlsl/generator.h index 1c3b58cb00..63e6c3dc66 100644 --- a/src/writer/hlsl/generator.h +++ b/src/writer/hlsl/generator.h @@ -30,13 +30,9 @@ namespace hlsl { /// Class to generate HLSL source class Generator : public Text { public: - /// Constructor - /// @param module the module to convert - explicit Generator(ast::Module module); - /// Constructor /// @param program the program to convert - explicit Generator(Program* program); + explicit Generator(const Program* program); /// Destructor ~Generator() override; @@ -59,7 +55,6 @@ class Generator : public Text { std::string error() const; private: - ast::Module module_; std::ostringstream out_; std::unique_ptr impl_; }; diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 93ab2e6f6d..6357d8f55e 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -125,7 +125,7 @@ const char* image_format_to_rwtexture_type(type::ImageFormat image_format) { } // namespace -GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {} +GeneratorImpl::GeneratorImpl(const Program* program) : program_(program) {} GeneratorImpl::~GeneratorImpl() = default; @@ -136,20 +136,20 @@ void GeneratorImpl::make_indent(std::ostream& out) { } bool GeneratorImpl::Generate(std::ostream& out) { - for (auto* global : module_->global_variables()) { + for (auto* global : program_->global_variables()) { register_global(global); } - for (auto* const ty : module_->constructed_types()) { + for (auto* const ty : program_->constructed_types()) { if (!EmitConstructedType(out, ty)) { return false; } } - if (!module_->constructed_types().empty()) { + if (!program_->constructed_types().empty()) { out << std::endl; } - for (auto* var : module_->global_variables()) { + for (auto* var : program_->global_variables()) { if (!var->is_const()) { continue; } @@ -160,7 +160,7 @@ bool GeneratorImpl::Generate(std::ostream& out) { std::unordered_set emitted_globals; // Make sure all entry point data is emitted before the entry point functions - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!func->IsEntryPoint()) { continue; } @@ -170,13 +170,13 @@ bool GeneratorImpl::Generate(std::ostream& out) { } } - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!EmitFunction(out, func)) { return false; } } - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!func->IsEntryPoint()) { continue; } @@ -232,7 +232,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, // HLSL typedef is for intrinsic types only. For an alias'd struct, // generate a secondary struct with the new name. if (auto* str = alias->type()->As()) { - if (!EmitStructType(out, str, module_->SymbolToName(alias->symbol()))) { + if (!EmitStructType(out, str, program_->SymbolToName(alias->symbol()))) { return false; } return true; @@ -241,10 +241,10 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, if (!EmitType(out, alias->type(), "")) { return false; } - out << " " << namer_.NameFor(module_->SymbolToName(alias->symbol())) << ";" + out << " " << namer_.NameFor(program_->SymbolToName(alias->symbol())) << ";" << std::endl; } else if (auto* str = ty->As()) { - if (!EmitStructType(out, str, module_->SymbolToName(str->symbol()))) { + if (!EmitStructType(out, str, program_->SymbolToName(str->symbol()))) { return false; } } else { @@ -623,7 +623,7 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, return true; } - auto name = module_->SymbolToName(ident->symbol()); + auto name = program_->SymbolToName(ident->symbol()); auto caller_sym = ident->symbol(); auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" + caller_sym.to_str()); @@ -631,10 +631,10 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, name = it->second; } - auto* func = module_->Functions().Find(ident->symbol()); + auto* func = program_->Functions().Find(ident->symbol()); if (func == nullptr) { error_ = - "Unable to find function: " + module_->SymbolToName(ident->symbol()); + "Unable to find function: " + program_->SymbolToName(ident->symbol()); return false; } @@ -868,7 +868,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, break; default: error_ = "Internal compiler error: Unhandled texture intrinsic '" + - module_->SymbolToName(ident->symbol()) + "'"; + program_->SymbolToName(ident->symbol()) + "'"; return false; } @@ -881,7 +881,8 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre, auto* param_coords = params[pidx.coords]; auto emit_vector_appended_with_i32_zero = [&](tint::ast::Expression* vector) { - auto* i32 = module_->create(); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + auto* i32 = const_cast(program_)->create(); ast::SintLiteral zero_lit(Source{}, i32, 0); ast::ScalarConstructorExpression zero(Source{}, &zero_lit); zero.set_result_type(i32); @@ -971,7 +972,7 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) { case ast::Intrinsic::kMax: case ast::Intrinsic::kMin: case ast::Intrinsic::kClamp: - out = module_->SymbolToName(ident->symbol()); + out = program_->SymbolToName(ident->symbol()); break; case ast::Intrinsic::kFaceForward: out = "faceforward"; @@ -987,7 +988,7 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) { break; default: error_ = - "Unknown builtin method: " + module_->SymbolToName(ident->symbol()); + "Unknown builtin method: " + program_->SymbolToName(ident->symbol()); return ""; } @@ -1167,7 +1168,7 @@ bool GeneratorImpl::EmitIdentifier(std::ostream&, out << name << "."; } } - out << namer_.NameFor(module_->SymbolToName(ident->symbol())); + out << namer_.NameFor(program_->SymbolToName(ident->symbol())); return true; } @@ -1329,12 +1330,12 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, auto ep_name = ep_sym.to_str(); // TODO(dsinclair): The SymbolToName should go away and just use // to_str() here when the conversion is complete. - name = generate_name(module_->SymbolToName(func->symbol()) + "_" + - module_->SymbolToName(ep_sym)); + name = generate_name(program_->SymbolToName(func->symbol()) + "_" + + program_->SymbolToName(ep_sym)); ep_func_name_remapped_[ep_name + "_" + func_name] = name; } else { // TODO(dsinclair): this should be updated to a remapped name - name = namer_.NameFor(module_->SymbolToName(func->symbol())); + name = namer_.NameFor(program_->SymbolToName(func->symbol())); } out << name << "("; @@ -1370,12 +1371,12 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, } first = false; - if (!EmitType(out, v->type(), module_->SymbolToName(v->symbol()))) { + if (!EmitType(out, v->type(), program_->SymbolToName(v->symbol()))) { return false; } // Array name is output as part of the type if (!v->type()->Is()) { - out << " " << module_->SymbolToName(v->symbol()); + out << " " << program_->SymbolToName(v->symbol()); } } @@ -1429,7 +1430,7 @@ bool GeneratorImpl::EmitEntryPointData( auto* binding = data.second.binding; if (binding == nullptr) { error_ = "unable to find binding information for uniform: " + - module_->SymbolToName(var->symbol()); + program_->SymbolToName(var->symbol()); return false; } // auto* set = data.second.set; @@ -1443,8 +1444,8 @@ bool GeneratorImpl::EmitEntryPointData( auto* type = var->type()->UnwrapIfNeeded(); if (auto* strct = type->As()) { - out << "ConstantBuffer<" << module_->SymbolToName(strct->symbol()) << "> " - << module_->SymbolToName(var->symbol()) << " : register(b" + out << "ConstantBuffer<" << program_->SymbolToName(strct->symbol()) + << "> " << program_->SymbolToName(var->symbol()) << " : register(b" << binding->value() << ");" << std::endl; } else { // TODO(dsinclair): There is outstanding spec work to require all uniform @@ -1453,7 +1454,7 @@ bool GeneratorImpl::EmitEntryPointData( // is not a block. // Relevant: https://github.com/gpuweb/gpuweb/issues/1004 // https://github.com/gpuweb/gpuweb/issues/1008 - auto name = "cbuffer_" + module_->SymbolToName(var->symbol()); + auto name = "cbuffer_" + program_->SymbolToName(var->symbol()); out << "cbuffer " << name << " : register(b" << binding->value() << ") {" << std::endl; @@ -1462,7 +1463,7 @@ bool GeneratorImpl::EmitEntryPointData( if (!EmitType(out, type, "")) { return false; } - out << " " << module_->SymbolToName(var->symbol()) << ";" << std::endl; + out << " " << program_->SymbolToName(var->symbol()) << ";" << std::endl; decrement_indent(); out << "};" << std::endl; } @@ -1494,7 +1495,7 @@ bool GeneratorImpl::EmitEntryPointData( if (ac->IsReadWrite()) { out << "RW"; } - out << "ByteAddressBuffer " << module_->SymbolToName(var->symbol()) + out << "ByteAddressBuffer " << program_->SymbolToName(var->symbol()) << " : register(u" << binding->value() << ");" << std::endl; emitted_storagebuffer = true; } @@ -1503,7 +1504,7 @@ bool GeneratorImpl::EmitEntryPointData( } if (!in_variables.empty()) { - auto in_struct_name = generate_name(module_->SymbolToName(func->symbol()) + + auto in_struct_name = generate_name(program_->SymbolToName(func->symbol()) + "_" + kInStructNameSuffix); auto in_var_name = generate_name(kTintStructInVarPrefix); ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name}; @@ -1518,11 +1519,11 @@ bool GeneratorImpl::EmitEntryPointData( auto* deco = data.second; make_indent(out); - if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { return false; } - out << " " << module_->SymbolToName(var->symbol()) << " : "; + out << " " << program_->SymbolToName(var->symbol()) << " : "; if (auto* location = deco->As()) { if (func->pipeline_stage() == ast::PipelineStage::kCompute) { error_ = "invalid location variable for pipeline stage"; @@ -1549,7 +1550,7 @@ bool GeneratorImpl::EmitEntryPointData( } if (!outvariables.empty()) { - auto outstruct_name = generate_name(module_->SymbolToName(func->symbol()) + + auto outstruct_name = generate_name(program_->SymbolToName(func->symbol()) + "_" + kOutStructNameSuffix); auto outvar_name = generate_name(kTintStructOutVarPrefix); ep_sym_to_out_data_[func->symbol()] = {outstruct_name, outvar_name}; @@ -1563,11 +1564,11 @@ bool GeneratorImpl::EmitEntryPointData( auto* deco = data.second; make_indent(out); - if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { return false; } - out << " " << module_->SymbolToName(var->symbol()) << " : "; + out << " " << program_->SymbolToName(var->symbol()) << " : "; if (auto* location = deco->As()) { auto loc = location->value(); @@ -1650,7 +1651,7 @@ bool GeneratorImpl::EmitEntryPointFunction(std::ostream& out, out << "void"; } // TODO(dsinclair): This should output the remapped name - out << " " << namer_.NameFor(module_->SymbolToName(current_ep_sym_)) << "("; + out << " " << namer_.NameFor(program_->SymbolToName(current_ep_sym_)) << "("; auto in_data = ep_sym_to_in_data_.find(current_ep_sym_); if (in_data != ep_sym_to_in_data_.end()) { @@ -1798,7 +1799,7 @@ bool GeneratorImpl::EmitLoop(std::ostream& out, ast::LoopStatement* stmt) { } out << pre.str(); - out << module_->SymbolToName(var->symbol()) << " = "; + out << program_->SymbolToName(var->symbol()) << " = "; if (var->constructor() != nullptr) { out << constructor_out.str(); } else { @@ -1861,7 +1862,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( // // This must be a single element swizzle if we've got a vector at this // point. - if (module_->SymbolToName(mem->member()->symbol()).size() != 1) { + if (program_->SymbolToName(mem->member()->symbol()).size() != 1) { error_ = "Encountered multi-element swizzle when should have only one " "level"; @@ -1873,7 +1874,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression( // f64 types. out << "(4 * " << convert_swizzle_to_index( - module_->SymbolToName(mem->member()->symbol())) + program_->SymbolToName(mem->member()->symbol())) << ")"; } else { error_ = @@ -2052,7 +2053,7 @@ bool GeneratorImpl::is_storage_buffer_access( // If the data is a multi-element swizzle then we will not load the swizzle // portion through the Load command. if (data_type->Is() && - module_->SymbolToName(expr->member()->symbol()).size() > 1) { + program_->SymbolToName(expr->member()->symbol()).size() > 1) { return false; } @@ -2204,7 +2205,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } if (auto* alias = type->As()) { - out << namer_.NameFor(module_->SymbolToName(alias->symbol())); + out << namer_.NameFor(program_->SymbolToName(alias->symbol())); } else if (auto* ary = type->As()) { type::Type* base_type = ary; std::vector sizes; @@ -2251,7 +2252,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } out << "State"; } else if (auto* str = type->As()) { - out << module_->SymbolToName(str->symbol()); + out << program_->SymbolToName(str->symbol()); } else if (auto* tex = type->As()) { if (tex->Is()) { out << "RW"; @@ -2335,12 +2336,12 @@ bool GeneratorImpl::EmitStructType(std::ostream& out, // TODO(dsinclair): Handle [[offset]] annotation on structs // https://bugs.chromium.org/p/tint/issues/detail?id=184 - if (!EmitType(out, mem->type(), module_->SymbolToName(mem->symbol()))) { + if (!EmitType(out, mem->type(), program_->SymbolToName(mem->symbol()))) { return false; } // Array member name will be output with the type if (!mem->type()->Is()) { - out << " " << namer_.NameFor(module_->SymbolToName(mem->symbol())); + out << " " << namer_.NameFor(program_->SymbolToName(mem->symbol())); } out << ";" << std::endl; } @@ -2399,11 +2400,11 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, if (var->is_const()) { out << "const "; } - if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { return false; } if (!var->type()->Is()) { - out << " " << module_->SymbolToName(var->symbol()); + out << " " << program_->SymbolToName(var->symbol()); } out << constructor_out.str() << ";" << std::endl; @@ -2448,19 +2449,19 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out, } out << "#endif" << std::endl; out << "static const "; - if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { return false; } - out << " " << module_->SymbolToName(var->symbol()) + out << " " << program_->SymbolToName(var->symbol()) << " = WGSL_SPEC_CONSTANT_" << const_id << ";" << std::endl; out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl; } else { out << "static const "; - if (!EmitType(out, var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { return false; } if (!var->type()->Is()) { - out << " " << module_->SymbolToName(var->symbol()); + out << " " << program_->SymbolToName(var->symbol()); } if (var->constructor() != nullptr) { @@ -2475,7 +2476,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out, std::string GeneratorImpl::get_buffer_name(ast::Expression* expr) { for (;;) { if (auto* ident = expr->As()) { - return module_->SymbolToName(ident->symbol()); + return program_->SymbolToName(ident->symbol()); } else if (auto* member = expr->As()) { expr = member->structure(); } else if (auto* array = expr->As()) { diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 834fd7cce6..9ac8e109e2 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -34,12 +34,12 @@ #include "src/ast/literal.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" +#include "src/program.h" #include "src/scope_stack.h" #include "src/type/struct_type.h" #include "src/writer/hlsl/namer.h" @@ -52,8 +52,8 @@ namespace hlsl { class GeneratorImpl { public: /// Constructor - /// @param module the module to generate - explicit GeneratorImpl(ast::Module* module); + /// @param program the program to generate + explicit GeneratorImpl(const Program* program); ~GeneratorImpl(); /// Increment the emitter indent level @@ -393,7 +393,7 @@ class GeneratorImpl { size_t indent_ = 0; Namer namer_; - ast::Module* module_ = nullptr; + const Program* program_ = nullptr; Symbol current_ep_sym_; bool generating_entry_point_ = false; uint32_t loop_emission_counter_ = 0; diff --git a/src/writer/hlsl/generator_impl_array_accessor_test.cc b/src/writer/hlsl/generator_impl_array_accessor_test.cc index 79cf085d94..503186ab38 100644 --- a/src/writer/hlsl/generator_impl_array_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_array_accessor_test.cc @@ -16,9 +16,9 @@ #include "src/ast/array_accessor_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_assign_test.cc b/src/writer/hlsl/generator_impl_assign_test.cc index c44681c2a9..be2f2dd9cc 100644 --- a/src/writer/hlsl/generator_impl_assign_test.cc +++ b/src/writer/hlsl/generator_impl_assign_test.cc @@ -17,7 +17,7 @@ #include "src/ast/assignment_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc index 704cb5af87..c0a0e03a60 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -24,13 +24,13 @@ #include "src/ast/function.h" #include "src/ast/identifier_expression.h" #include "src/ast/if_statement.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/bool_type.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" diff --git a/src/writer/hlsl/generator_impl_bitcast_test.cc b/src/writer/hlsl/generator_impl_bitcast_test.cc index f4c9f3930c..eecefe0cfb 100644 --- a/src/writer/hlsl/generator_impl_bitcast_test.cc +++ b/src/writer/hlsl/generator_impl_bitcast_test.cc @@ -16,7 +16,7 @@ #include "src/ast/bitcast_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" #include "src/type/u32_type.h" diff --git a/src/writer/hlsl/generator_impl_break_test.cc b/src/writer/hlsl/generator_impl_break_test.cc index e7b865c689..36715bfbda 100644 --- a/src/writer/hlsl/generator_impl_break_test.cc +++ b/src/writer/hlsl/generator_impl_break_test.cc @@ -16,7 +16,7 @@ #include #include "src/ast/break_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_call_test.cc b/src/writer/hlsl/generator_impl_call_test.cc index 5b3a25c405..c03e631825 100644 --- a/src/writer/hlsl/generator_impl_call_test.cc +++ b/src/writer/hlsl/generator_impl_call_test.cc @@ -18,7 +18,7 @@ #include "src/ast/call_statement.h" #include "src/ast/function.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_case_test.cc b/src/writer/hlsl/generator_impl_case_test.cc index b60e7e5c76..827ee1bc47 100644 --- a/src/writer/hlsl/generator_impl_case_test.cc +++ b/src/writer/hlsl/generator_impl_case_test.cc @@ -18,8 +18,8 @@ #include "src/ast/case_statement.h" #include "src/ast/fallthrough_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/sint_literal.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_cast_test.cc b/src/writer/hlsl/generator_impl_cast_test.cc index de0d39f958..a6ef210c80 100644 --- a/src/writer/hlsl/generator_impl_cast_test.cc +++ b/src/writer/hlsl/generator_impl_cast_test.cc @@ -15,8 +15,8 @@ #include #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/type_constructor_expression.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/vector_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_constructor_test.cc b/src/writer/hlsl/generator_impl_constructor_test.cc index 071d2403f9..1a284c613b 100644 --- a/src/writer/hlsl/generator_impl_constructor_test.cc +++ b/src/writer/hlsl/generator_impl_constructor_test.cc @@ -14,11 +14,11 @@ #include "src/ast/bool_literal.h" #include "src/ast/float_literal.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" #include "src/type/f32_type.h" diff --git a/src/writer/hlsl/generator_impl_continue_test.cc b/src/writer/hlsl/generator_impl_continue_test.cc index f87de21429..f9340782c8 100644 --- a/src/writer/hlsl/generator_impl_continue_test.cc +++ b/src/writer/hlsl/generator_impl_continue_test.cc @@ -16,7 +16,7 @@ #include #include "src/ast/continue_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_discard_test.cc b/src/writer/hlsl/generator_impl_discard_test.cc index 9d0c425bec..574c397d0f 100644 --- a/src/writer/hlsl/generator_impl_discard_test.cc +++ b/src/writer/hlsl/generator_impl_discard_test.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "src/ast/discard_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc index e29725fea0..5743f6acf5 100644 --- a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc @@ -19,11 +19,11 @@ #include "src/ast/identifier_expression.h" #include "src/ast/location_decoration.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/return_statement.h" #include "src/ast/stage_decoration.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type_determiner.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index d799d0fc76..a6350b47bc 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -23,7 +23,6 @@ #include "src/ast/if_statement.h" #include "src/ast/location_decoration.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" @@ -35,6 +34,7 @@ #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" diff --git a/src/writer/hlsl/generator_impl_identifier_test.cc b/src/writer/hlsl/generator_impl_identifier_test.cc index eaaebc1c33..0c311cce29 100644 --- a/src/writer/hlsl/generator_impl_identifier_test.cc +++ b/src/writer/hlsl/generator_impl_identifier_test.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_if_test.cc b/src/writer/hlsl/generator_impl_if_test.cc index 1e670707fe..314a103d1b 100644 --- a/src/writer/hlsl/generator_impl_if_test.cc +++ b/src/writer/hlsl/generator_impl_if_test.cc @@ -15,8 +15,8 @@ #include "src/ast/else_statement.h" #include "src/ast/identifier_expression.h" #include "src/ast/if_statement.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_import_test.cc b/src/writer/hlsl/generator_impl_import_test.cc index 8613a0d394..7b1f2b4faa 100644 --- a/src/writer/hlsl/generator_impl_import_test.cc +++ b/src/writer/hlsl/generator_impl_import_test.cc @@ -19,10 +19,10 @@ #include "src/ast/call_expression.h" #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/type_constructor_expression.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" #include "src/type/matrix_type.h" diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index a3b0a718c8..6f73c2c856 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -14,7 +14,7 @@ #include "src/ast/call_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/vector_type.h" #include "src/type_determiner.h" diff --git a/src/writer/hlsl/generator_impl_loop_test.cc b/src/writer/hlsl/generator_impl_loop_test.cc index 09befb2726..03d4e8422c 100644 --- a/src/writer/hlsl/generator_impl_loop_test.cc +++ b/src/writer/hlsl/generator_impl_loop_test.cc @@ -19,10 +19,10 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/loop_statement.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index e1ade73bdf..06be7a3b6d 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -18,7 +18,6 @@ #include "src/ast/assignment_statement.h" #include "src/ast/identifier_expression.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/stride_decoration.h" @@ -27,6 +26,7 @@ #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/struct_type.h" #include "src/type/vector_type.h" #include "src/type_determiner.h" diff --git a/src/writer/hlsl/generator_impl_module_constant_test.cc b/src/writer/hlsl/generator_impl_module_constant_test.cc index 057162fad0..1932b0a36f 100644 --- a/src/writer/hlsl/generator_impl_module_constant_test.cc +++ b/src/writer/hlsl/generator_impl_module_constant_test.cc @@ -17,10 +17,10 @@ #include "src/ast/constant_id_decoration.h" #include "src/ast/float_literal.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_return_test.cc b/src/writer/hlsl/generator_impl_return_test.cc index 4c04d9082b..7545928a16 100644 --- a/src/writer/hlsl/generator_impl_return_test.cc +++ b/src/writer/hlsl/generator_impl_return_test.cc @@ -16,8 +16,8 @@ #include #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_switch_test.cc b/src/writer/hlsl/generator_impl_switch_test.cc index 75039ebb9c..8106f85e93 100644 --- a/src/writer/hlsl/generator_impl_switch_test.cc +++ b/src/writer/hlsl/generator_impl_switch_test.cc @@ -17,9 +17,9 @@ #include "src/ast/break_statement.h" #include "src/ast/case_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index a42c4b93af..d3e36abe89 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -16,7 +16,7 @@ #include "src/ast/function.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/void_type.h" #include "src/writer/hlsl/test_helper.h" diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 2d69d2bc37..c4bf8ed067 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/module.h" #include "src/ast/struct.h" #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" diff --git a/src/writer/hlsl/generator_impl_unary_op_test.cc b/src/writer/hlsl/generator_impl_unary_op_test.cc index 48294c14c7..86704d2917 100644 --- a/src/writer/hlsl/generator_impl_unary_op_test.cc +++ b/src/writer/hlsl/generator_impl_unary_op_test.cc @@ -16,8 +16,8 @@ #include #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/unary_op_expression.h" +#include "src/program.h" #include "src/writer/hlsl/test_helper.h" namespace tint { diff --git a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc index 91ca67e629..eaa1232a96 100644 --- a/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/hlsl/generator_impl_variable_decl_statement_test.cc @@ -16,9 +16,9 @@ #include #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" #include "src/type/matrix_type.h" diff --git a/src/writer/hlsl/test_helper.h b/src/writer/hlsl/test_helper.h index af3d10a4fe..530b261a54 100644 --- a/src/writer/hlsl/test_helper.h +++ b/src/writer/hlsl/test_helper.h @@ -31,12 +31,12 @@ namespace hlsl { /// Helper class for testing template -class TestHelperBase : public BODY, public ast::BuilderWithModule { +class TestHelperBase : public BODY, public ast::BuilderWithProgram { public: - TestHelperBase() : td(mod) {} + TestHelperBase() : td(program) {} ~TestHelperBase() = default; - /// Builds and returns a GeneratorImpl from the module. + /// Builds and returns a GeneratorImpl from the program. /// @note The generator is only built once. Multiple calls to Build() will /// return the same GeneratorImpl without rebuilding. /// @return the built generator @@ -44,7 +44,7 @@ class TestHelperBase : public BODY, public ast::BuilderWithModule { if (gen_) { return *gen_; } - gen_ = std::make_unique(mod); + gen_ = std::make_unique(program); return *gen_; } diff --git a/src/writer/msl/generator.cc b/src/writer/msl/generator.cc index 5c6428c8e6..66b609bf9e 100644 --- a/src/writer/msl/generator.cc +++ b/src/writer/msl/generator.cc @@ -20,12 +20,8 @@ namespace tint { namespace writer { namespace msl { -Generator::Generator(ast::Module module) - : module_(std::move(module)), - impl_(std::make_unique(&module_)) {} - -Generator::Generator(Program* program) - : impl_(std::make_unique(&program->module)) {} +Generator::Generator(const Program* program) + : impl_(std::make_unique(program)) {} Generator::~Generator() = default; diff --git a/src/writer/msl/generator.h b/src/writer/msl/generator.h index 7586a5a706..a677958b6f 100644 --- a/src/writer/msl/generator.h +++ b/src/writer/msl/generator.h @@ -29,13 +29,9 @@ namespace msl { /// Class to generate MSL source class Generator : public Text { public: - /// Constructor - /// @param module the module to convert - explicit Generator(ast::Module module); - /// Constructor /// @param program the program to convert - explicit Generator(Program* program); + explicit Generator(const Program* program); /// Destructor ~Generator() override; @@ -58,7 +54,6 @@ class Generator : public Text { std::string error() const; private: - ast::Module module_; std::unique_ptr impl_; }; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index b0be9aaf4d..b88dd5a54d 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -96,8 +96,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) { } // namespace -GeneratorImpl::GeneratorImpl(ast::Module* module) - : TextGenerator(), module_(module) {} +GeneratorImpl::GeneratorImpl(const Program* program) + : TextGenerator(), program_(program) {} GeneratorImpl::~GeneratorImpl() = default; @@ -115,20 +115,20 @@ std::string GeneratorImpl::generate_name(const std::string& prefix) { bool GeneratorImpl::Generate() { out_ << "#include " << std::endl << std::endl; - for (auto* global : module_->global_variables()) { + for (auto* global : program_->global_variables()) { global_variables_.set(global->symbol(), global); } - for (auto* const ty : module_->constructed_types()) { + for (auto* const ty : program_->constructed_types()) { if (!EmitConstructedType(ty)) { return false; } } - if (!module_->constructed_types().empty()) { + if (!program_->constructed_types().empty()) { out_ << std::endl; } - for (auto* var : module_->global_variables()) { + for (auto* var : program_->global_variables()) { if (!var->is_const()) { continue; } @@ -138,7 +138,7 @@ bool GeneratorImpl::Generate() { } // Make sure all entry point data is emitted before the entry point functions - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!func->IsEntryPoint()) { continue; } @@ -148,13 +148,13 @@ bool GeneratorImpl::Generate() { } } - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!EmitFunction(func)) { return false; } } - for (auto* func : module_->Functions()) { + for (auto* func : program_->Functions()) { if (!func->IsEntryPoint()) { continue; } @@ -258,8 +258,8 @@ bool GeneratorImpl::EmitConstructedType(const type::Type* ty) { if (!EmitType(alias->type(), "")) { return false; } - out_ << " " << namer_.NameFor(module_->SymbolToName(alias->symbol())) << ";" - << std::endl; + out_ << " " << namer_.NameFor(program_->SymbolToName(alias->symbol())) + << ";" << std::endl; } else if (auto* str = ty->As()) { if (!EmitStructType(str)) { return false; @@ -517,7 +517,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { return true; } - auto name = module_->SymbolToName(ident->symbol()); + auto name = program_->SymbolToName(ident->symbol()); auto caller_sym = ident->symbol(); auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" + caller_sym.to_str()); @@ -525,10 +525,10 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { name = it->second; } - auto* func = module_->Functions().Find(ident->symbol()); + auto* func = program_->Functions().Find(ident->symbol()); if (func == nullptr) { error_ = - "Unable to find function: " + module_->SymbolToName(ident->symbol()); + "Unable to find function: " + program_->SymbolToName(ident->symbol()); return false; } @@ -562,7 +562,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { out_ << ", "; } first = false; - out_ << module_->SymbolToName(var->symbol()); + out_ << program_->SymbolToName(var->symbol()); } for (const auto& data : func->referenced_uniform_variables()) { @@ -571,7 +571,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { out_ << ", "; } first = false; - out_ << module_->SymbolToName(var->symbol()); + out_ << program_->SymbolToName(var->symbol()); } for (const auto& data : func->referenced_storagebuffer_variables()) { @@ -580,7 +580,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) { out_ << ", "; } first = false; - out_ << module_->SymbolToName(var->symbol()); + out_ << program_->SymbolToName(var->symbol()); } const auto& params = expr->params(); @@ -720,7 +720,7 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) { break; default: error_ = "Internal compiler error: Unhandled texture intrinsic '" + - module_->SymbolToName(ident->symbol()) + "'"; + program_->SymbolToName(ident->symbol()) + "'"; return false; } @@ -847,7 +847,7 @@ std::string GeneratorImpl::generate_builtin_name( case ast::Intrinsic::kTrunc: case ast::Intrinsic::kSign: case ast::Intrinsic::kClamp: - out += module_->SymbolToName(ident->symbol()); + out += program_->SymbolToName(ident->symbol()); break; case ast::Intrinsic::kAbs: if (ident->result_type()->Is()) { @@ -884,7 +884,7 @@ std::string GeneratorImpl::generate_builtin_name( break; default: error_ = - "Unknown import method: " + module_->SymbolToName(ident->symbol()); + "Unknown import method: " + program_->SymbolToName(ident->symbol()); return ""; } return out; @@ -1059,7 +1059,7 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { } if (!in_locations.empty()) { - auto in_struct_name = generate_name(module_->SymbolToName(func->symbol()) + + auto in_struct_name = generate_name(program_->SymbolToName(func->symbol()) + "_" + kInStructNameSuffix); auto in_var_name = generate_name(kTintStructInVarPrefix); ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name}; @@ -1074,11 +1074,11 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { uint32_t loc = data.second; make_indent(); - if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { return false; } - out_ << " " << module_->SymbolToName(var->symbol()) << " [["; + out_ << " " << program_->SymbolToName(var->symbol()) << " [["; if (func->pipeline_stage() == ast::PipelineStage::kVertex) { out_ << "attribute(" << loc << ")"; } else if (func->pipeline_stage() == ast::PipelineStage::kFragment) { @@ -1096,8 +1096,8 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { } if (!out_variables.empty()) { - auto out_struct_name = generate_name(module_->SymbolToName(func->symbol()) + - "_" + kOutStructNameSuffix); + auto out_struct_name = generate_name( + program_->SymbolToName(func->symbol()) + "_" + kOutStructNameSuffix); auto out_var_name = generate_name(kTintStructOutVarPrefix); ep_sym_to_out_data_[func->symbol()] = {out_struct_name, out_var_name}; @@ -1110,11 +1110,11 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) { auto* deco = data.second; make_indent(); - if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { return false; } - out_ << " " << module_->SymbolToName(var->symbol()) << " [["; + out_ << " " << program_->SymbolToName(var->symbol()) << " [["; if (auto* location = deco->As()) { auto loc = location->value(); @@ -1272,12 +1272,12 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, auto ep_name = ep_sym.to_str(); // TODO(dsinclair): The SymbolToName should go away and just use // to_str() here when the conversion is complete. - name = generate_name(module_->SymbolToName(func->symbol()) + "_" + - module_->SymbolToName(ep_sym)); + name = generate_name(program_->SymbolToName(func->symbol()) + "_" + + program_->SymbolToName(ep_sym)); ep_func_name_remapped_[ep_name + "_" + func_name] = name; } else { // TODO(dsinclair): this should be updated to a remapped name - name = namer_.NameFor(module_->SymbolToName(func->symbol())); + name = namer_.NameFor(program_->SymbolToName(func->symbol())); } out_ << name << "("; @@ -1320,7 +1320,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, if (!EmitType(var->type(), "")) { return false; } - out_ << "& " << module_->SymbolToName(var->symbol()); + out_ << "& " << program_->SymbolToName(var->symbol()); } for (const auto& data : func->referenced_uniform_variables()) { @@ -1335,7 +1335,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, if (!EmitType(var->type(), "")) { return false; } - out_ << "& " << module_->SymbolToName(var->symbol()); + out_ << "& " << program_->SymbolToName(var->symbol()); } for (const auto& data : func->referenced_storagebuffer_variables()) { @@ -1358,7 +1358,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, if (!EmitType(ac->type(), "")) { return false; } - out_ << "& " << module_->SymbolToName(var->symbol()); + out_ << "& " << program_->SymbolToName(var->symbol()); } for (auto* v : func->params()) { @@ -1367,12 +1367,12 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func, } first = false; - if (!EmitType(v->type(), module_->SymbolToName(v->symbol()))) { + if (!EmitType(v->type(), program_->SymbolToName(v->symbol()))) { return false; } // Array name is output as part of the type if (!v->type()->Is()) { - out_ << " " << module_->SymbolToName(v->symbol()); + out_ << " " << program_->SymbolToName(v->symbol()); } } @@ -1432,7 +1432,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { } else { out_ << "void"; } - out_ << " " << namer_.NameFor(module_->SymbolToName(func->symbol())) << "("; + out_ << " " << namer_.NameFor(program_->SymbolToName(func->symbol())) << "("; bool first = true; auto in_data = ep_sym_to_in_data_.find(current_ep_sym_); @@ -1464,7 +1464,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { error_ = "unknown builtin"; return false; } - out_ << " " << module_->SymbolToName(var->symbol()) << " [[" << attr + out_ << " " << program_->SymbolToName(var->symbol()) << " [[" << attr << "]]"; } @@ -1481,7 +1481,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { auto* binding = data.second.binding; if (binding == nullptr) { error_ = "unable to find binding information for uniform: " + - module_->SymbolToName(var->symbol()); + program_->SymbolToName(var->symbol()); return false; } // auto* set = data.second.set; @@ -1492,7 +1492,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (!EmitType(var->type(), "")) { return false; } - out_ << "& " << module_->SymbolToName(var->symbol()) << " [[buffer(" + out_ << "& " << program_->SymbolToName(var->symbol()) << " [[buffer(" << binding->value() << ")]]"; } @@ -1522,7 +1522,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) { if (!EmitType(ac->type(), "")) { return false; } - out_ << "& " << module_->SymbolToName(var->symbol()) << " [[buffer(" + out_ << "& " << program_->SymbolToName(var->symbol()) << " [[buffer(" << binding->value() << ")]]"; } @@ -1587,7 +1587,7 @@ bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) { out_ << name << "."; } } - out_ << namer_.NameFor(module_->SymbolToName(ident->symbol())); + out_ << namer_.NameFor(program_->SymbolToName(ident->symbol())); return true; } @@ -1646,7 +1646,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { make_indent(); auto* var = decl->variable(); - out_ << module_->SymbolToName(var->symbol()) << " = "; + out_ << program_->SymbolToName(var->symbol()) << " = "; if (var->constructor() != nullptr) { if (!EmitExpression(var->constructor())) { return false; @@ -1877,7 +1877,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) { } if (auto* alias = type->As()) { - out_ << namer_.NameFor(module_->SymbolToName(alias->symbol())); + out_ << namer_.NameFor(program_->SymbolToName(alias->symbol())); } else if (auto* ary = type->As()) { type::Type* base_type = ary; std::vector sizes; @@ -1920,7 +1920,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) { } else if (auto* str = type->As()) { // The struct type emits as just the name. The declaration would be emitted // as part of emitting the constructed types. - out_ << module_->SymbolToName(str->symbol()); + out_ << program_->SymbolToName(str->symbol()); } else if (auto* tex = type->As()) { if (tex->Is()) { out_ << "depth"; @@ -2002,7 +2002,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) { // TODO(dsinclair): Block decoration? // if (str->impl()->decoration() != ast::StructDecoration::kNone) { // } - out_ << "struct " << module_->SymbolToName(str->symbol()) << " {" + out_ << "struct " << program_->SymbolToName(str->symbol()) << " {" << std::endl; increment_indent(); @@ -2026,7 +2026,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) { } } - if (!EmitType(mem->type(), module_->SymbolToName(mem->symbol()))) { + if (!EmitType(mem->type(), program_->SymbolToName(mem->symbol()))) { return false; } auto size = calculate_alignment_size(mem->type()); @@ -2038,7 +2038,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) { // Array member name will be output with the type if (!mem->type()->Is()) { - out_ << " " << namer_.NameFor(module_->SymbolToName(mem->symbol())); + out_ << " " << namer_.NameFor(program_->SymbolToName(mem->symbol())); } out_ << ";" << std::endl; } @@ -2080,11 +2080,11 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var, bool skip_constructor) { if (var->is_const()) { out_ << "const "; } - if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { return false; } if (!var->type()->Is()) { - out_ << " " << module_->SymbolToName(var->symbol()); + out_ << " " << program_->SymbolToName(var->symbol()); } if (!skip_constructor) { @@ -2122,11 +2122,11 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { } out_ << "constant "; - if (!EmitType(var->type(), module_->SymbolToName(var->symbol()))) { + if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { return false; } if (!var->type()->Is()) { - out_ << " " << module_->SymbolToName(var->symbol()); + out_ << " " << program_->SymbolToName(var->symbol()); } if (var->HasConstantIdDecoration()) { diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index 95b6109a2d..d3b56d2b01 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -35,12 +35,12 @@ #include "src/ast/literal.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" +#include "src/program.h" #include "src/scope_stack.h" #include "src/type/struct_type.h" #include "src/writer/msl/namer.h" @@ -54,8 +54,8 @@ namespace msl { class GeneratorImpl : public TextGenerator { public: /// Constructor - /// @param module the module to generate - explicit GeneratorImpl(ast::Module* module); + /// @param program the program to generate + explicit GeneratorImpl(const Program* program); ~GeneratorImpl(); /// @returns true on successful generation; false otherwise @@ -284,7 +284,7 @@ class GeneratorImpl : public TextGenerator { ScopeStack global_variables_; Symbol current_ep_sym_; bool generating_entry_point_ = false; - const ast::Module* module_ = nullptr; + const Program* program_ = nullptr; uint32_t loop_emission_counter_ = 0; std::unordered_map ep_sym_to_in_data_; diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index 055d80479d..bd98cc2438 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/module.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" +#include "src/program.h" #include "src/type/struct_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_array_accessor_test.cc b/src/writer/msl/generator_impl_array_accessor_test.cc index e8e6ce3287..3ce8bb591b 100644 --- a/src/writer/msl/generator_impl_array_accessor_test.cc +++ b/src/writer/msl/generator_impl_array_accessor_test.cc @@ -17,9 +17,9 @@ #include "gtest/gtest.h" #include "src/ast/array_accessor_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_assign_test.cc b/src/writer/msl/generator_impl_assign_test.cc index 2266646377..a730acdbd0 100644 --- a/src/writer/msl/generator_impl_assign_test.cc +++ b/src/writer/msl/generator_impl_assign_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" #include "src/ast/assignment_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_binary_test.cc b/src/writer/msl/generator_impl_binary_test.cc index 70b4498423..75fb8ea6f1 100644 --- a/src/writer/msl/generator_impl_binary_test.cc +++ b/src/writer/msl/generator_impl_binary_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/binary_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_bitcast_test.cc b/src/writer/msl/generator_impl_bitcast_test.cc index fea3c59725..9af5fdbe33 100644 --- a/src/writer/msl/generator_impl_bitcast_test.cc +++ b/src/writer/msl/generator_impl_bitcast_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/bitcast_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_break_test.cc b/src/writer/msl/generator_impl_break_test.cc index 1c88fe29a5..e8047caac7 100644 --- a/src/writer/msl/generator_impl_break_test.cc +++ b/src/writer/msl/generator_impl_break_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/break_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 679bfb0fac..f2164d6897 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -19,7 +19,7 @@ #include "src/ast/call_statement.h" #include "src/ast/function.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/void_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index bb550b938b..e4cbeb5270 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -19,8 +19,8 @@ #include "src/ast/case_statement.h" #include "src/ast/fallthrough_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/sint_literal.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_cast_test.cc b/src/writer/msl/generator_impl_cast_test.cc index 85b8d6a51b..f22ecbdd52 100644 --- a/src/writer/msl/generator_impl_cast_test.cc +++ b/src/writer/msl/generator_impl_cast_test.cc @@ -16,8 +16,8 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/type_constructor_expression.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/vector_type.h" #include "src/writer/msl/generator_impl.h" diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index 3da5647296..3c9952c942 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -15,11 +15,11 @@ #include "gtest/gtest.h" #include "src/ast/bool_literal.h" #include "src/ast/float_literal.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" #include "src/type/f32_type.h" diff --git a/src/writer/msl/generator_impl_continue_test.cc b/src/writer/msl/generator_impl_continue_test.cc index 4ef8b55fe8..45b42ef7ec 100644 --- a/src/writer/msl/generator_impl_continue_test.cc +++ b/src/writer/msl/generator_impl_continue_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/continue_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_discard_test.cc b/src/writer/msl/generator_impl_discard_test.cc index c59bc5e432..e6249143d7 100644 --- a/src/writer/msl/generator_impl_discard_test.cc +++ b/src/writer/msl/generator_impl_discard_test.cc @@ -14,7 +14,7 @@ #include "gtest/gtest.h" #include "src/ast/discard_statement.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index 00298f6ece..50dc20d3ac 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -19,10 +19,10 @@ #include "src/ast/identifier_expression.h" #include "src/ast/location_decoration.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/stage_decoration.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" #include "src/type/vector_type.h" diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 0bec2fb555..994839e6c5 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -24,7 +24,6 @@ #include "src/ast/if_statement.h" #include "src/ast/location_decoration.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" @@ -37,6 +36,7 @@ #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" diff --git a/src/writer/msl/generator_impl_identifier_test.cc b/src/writer/msl/generator_impl_identifier_test.cc index af19be119b..6b4ebef971 100644 --- a/src/writer/msl/generator_impl_identifier_test.cc +++ b/src/writer/msl/generator_impl_identifier_test.cc @@ -14,7 +14,7 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_if_test.cc b/src/writer/msl/generator_impl_if_test.cc index b1167a3d13..ec8771c3ef 100644 --- a/src/writer/msl/generator_impl_if_test.cc +++ b/src/writer/msl/generator_impl_if_test.cc @@ -16,8 +16,8 @@ #include "src/ast/else_statement.h" #include "src/ast/identifier_expression.h" #include "src/ast/if_statement.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc index 49688a3ed1..110a6d1494 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc @@ -20,10 +20,10 @@ #include "src/ast/call_expression.h" #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/type_constructor_expression.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" #include "src/type/matrix_type.h" diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index 652d6ceb45..6ca651f74a 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -15,7 +15,7 @@ #include "gtest/gtest.h" #include "src/ast/call_expression.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/vector_type.h" #include "src/type_determiner.h" diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index 7c42a84d4c..1b7a756490 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -20,10 +20,10 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/loop_statement.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_member_accessor_test.cc b/src/writer/msl/generator_impl_member_accessor_test.cc index e1fdeaf681..89ac2c6afc 100644 --- a/src/writer/msl/generator_impl_member_accessor_test.cc +++ b/src/writer/msl/generator_impl_member_accessor_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_module_constant_test.cc b/src/writer/msl/generator_impl_module_constant_test.cc index 1b7022a921..8e4c7d5ab3 100644 --- a/src/writer/msl/generator_impl_module_constant_test.cc +++ b/src/writer/msl/generator_impl_module_constant_test.cc @@ -18,10 +18,10 @@ #include "gtest/gtest.h" #include "src/ast/constant_id_decoration.h" #include "src/ast/float_literal.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" #include "src/writer/msl/generator_impl.h" diff --git a/src/writer/msl/generator_impl_return_test.cc b/src/writer/msl/generator_impl_return_test.cc index f881498c9d..342600c5cf 100644 --- a/src/writer/msl/generator_impl_return_test.cc +++ b/src/writer/msl/generator_impl_return_test.cc @@ -17,8 +17,8 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index 435a1fd26d..42f4a8b843 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -18,9 +18,9 @@ #include "src/ast/break_statement.h" #include "src/ast/case_statement.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/sint_literal.h" #include "src/ast/switch_statement.h" +#include "src/program.h" #include "src/type/i32_type.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index 183c08d497..765205edc9 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -20,12 +20,12 @@ #include "gtest/gtest.h" #include "src/ast/function.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/stage_decoration.h" #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/program.h" #include "src/type/alias_type.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 74dcff668e..ce9f485619 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -13,13 +13,13 @@ // limitations under the License. #include "gtest/gtest.h" -#include "src/ast/module.h" #include "src/ast/struct.h" #include "src/ast/struct_block_decoration.h" #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" #include "src/ast/struct_member_decoration.h" #include "src/ast/struct_member_offset_decoration.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/array_type.h" #include "src/type/bool_type.h" diff --git a/src/writer/msl/generator_impl_unary_op_test.cc b/src/writer/msl/generator_impl_unary_op_test.cc index 3a689cab9d..40e4aa9901 100644 --- a/src/writer/msl/generator_impl_unary_op_test.cc +++ b/src/writer/msl/generator_impl_unary_op_test.cc @@ -17,8 +17,8 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/unary_op_expression.h" +#include "src/program.h" #include "src/writer/msl/generator_impl.h" #include "src/writer/msl/test_helper.h" diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index da4be9bc6a..0d72000737 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" -#include "src/ast/module.h" #include "src/ast/struct.h" #include "src/ast/struct_decoration.h" #include "src/ast/struct_member.h" @@ -25,6 +24,7 @@ #include "src/ast/struct_member_offset_decoration.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" #include "src/type/matrix_type.h" diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h index 1d1f0d5cb4..5d91a3a141 100644 --- a/src/writer/msl/test_helper.h +++ b/src/writer/msl/test_helper.h @@ -20,7 +20,7 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" @@ -30,12 +30,12 @@ namespace msl { /// Helper class for testing template -class TestHelperBase : public BASE, public ast::BuilderWithModule { +class TestHelperBase : public BASE, public ast::BuilderWithProgram { public: - TestHelperBase() : td(mod) {} + TestHelperBase() : td(program) {} ~TestHelperBase() = default; - /// Builds and returns a GeneratorImpl from the module. + /// Builds and returns a GeneratorImpl from the program. /// @note The generator is only built once. Multiple calls to Build() will /// return the same GeneratorImpl without rebuilding. /// @return the built generator @@ -43,7 +43,7 @@ class TestHelperBase : public BASE, public ast::BuilderWithModule { if (gen_) { return *gen_; } - gen_ = std::make_unique(mod); + gen_ = std::make_unique(program); return *gen_; } diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index d79f6222dd..8c0e43b4fd 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -285,7 +285,8 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {} Builder::AccessorInfo::~AccessorInfo() {} -Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {} +Builder::Builder(const Program* program) + : program_(program), scope_stack_({}) {} Builder::~Builder() = default; @@ -296,13 +297,13 @@ bool Builder::Build() { {Operand::Int(SpvAddressingModelLogical), Operand::Int(SpvMemoryModelGLSL450)}); - for (auto* var : mod_->global_variables()) { + for (auto* var : program_->global_variables()) { if (!GenerateGlobalVariable(var)) { return false; } } - for (auto* func : mod_->Functions()) { + for (auto* func : program_->Functions()) { if (!GenerateFunction(func)) { return false; } @@ -447,8 +448,9 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { return false; } - OperandList operands = {Operand::Int(stage), Operand::Int(id), - Operand::String(mod_->SymbolToName(func->symbol()))}; + OperandList operands = { + Operand::Int(stage), Operand::Int(id), + Operand::String(program_->SymbolToName(func->symbol()))}; for (const auto* var : func->referenced_module_variables()) { // For SPIR-V 1.3 we only output Input/output variables. If we update to @@ -461,7 +463,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { uint32_t var_id; if (!scope_stack_.get(var->symbol(), &var_id)) { error_ = "unable to find ID for global variable: " + - mod_->SymbolToName(var->symbol()); + program_->SymbolToName(var->symbol()); return false; } @@ -541,7 +543,7 @@ bool Builder::GenerateFunction(ast::Function* func) { push_debug(spv::Op::OpName, {Operand::Int(func_id), - Operand::String(mod_->SymbolToName(func->symbol()))}); + Operand::String(program_->SymbolToName(func->symbol()))}); auto ret_id = GenerateTypeIfNeeded(func->return_type()); if (ret_id == 0) { @@ -567,7 +569,7 @@ bool Builder::GenerateFunction(ast::Function* func) { push_debug(spv::Op::OpName, {Operand::Int(param_id), - Operand::String(mod_->SymbolToName(param->symbol()))}); + Operand::String(program_->SymbolToName(param->symbol()))}); params.push_back(Instruction{spv::Op::OpFunctionParameter, {Operand::Int(param_type_id), param_op}}); @@ -658,7 +660,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) { push_debug(spv::Op::OpName, {Operand::Int(var_id), - Operand::String(mod_->SymbolToName(var->symbol()))}); + Operand::String(program_->SymbolToName(var->symbol()))}); // TODO(dsinclair) We could detect if the constructor is fully const and emit // an initializer value for the variable instead of doing the OpLoad. @@ -710,7 +712,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { } push_debug(spv::Op::OpName, {Operand::Int(init_id), - Operand::String(mod_->SymbolToName(var->symbol()))}); + Operand::String(program_->SymbolToName(var->symbol()))}); scope_stack_.set_global(var->symbol(), init_id); spirv_id_to_variable_[init_id] = var; @@ -732,7 +734,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { push_debug(spv::Op::OpName, {Operand::Int(var_id), - Operand::String(mod_->SymbolToName(var->symbol()))}); + Operand::String(program_->SymbolToName(var->symbol()))}); OperandList ops = {Operand::Int(type_id), result, Operand::Int(ConvertStorageClass(sc))}; @@ -913,7 +915,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr, } // TODO(dsinclair): Swizzle stuff - auto swiz = mod_->SymbolToName(expr->member()->symbol()); + auto swiz = program_->SymbolToName(expr->member()->symbol()); // Single element swizzle is either an access chain or a composite extract if (swiz.size() == 1) { auto val = IndexFromName(swiz[0]); @@ -1121,7 +1123,7 @@ uint32_t Builder::GenerateIdentifierExpression( } error_ = "unable to find variable with identifier: " + - mod_->SymbolToName(expr->symbol()); + program_->SymbolToName(expr->symbol()); return 0; } @@ -1814,7 +1816,7 @@ uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) { auto func_id = func_symbol_to_id_[ident->symbol()]; if (func_id == 0) { error_ = "unable to find called function: " + - mod_->SymbolToName(ident->symbol()); + program_->SymbolToName(ident->symbol()); return 0; } ops.push_back(Operand::Int(func_id)); @@ -1946,7 +1948,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident, auto inst_id = intrinsic_to_glsl_method(ident->result_type(), ident->intrinsic()); if (inst_id == 0) { - error_ = "unknown method " + mod_->SymbolToName(ident->symbol()); + error_ = "unknown method " + program_->SymbolToName(ident->symbol()); return 0; } @@ -1958,7 +1960,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident, if (op == spv::Op::OpNop) { error_ = "unable to determine operator for: " + - mod_->SymbolToName(ident->symbol()); + program_->SymbolToName(ident->symbol()); return 0; } @@ -2041,8 +2043,10 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, // to calling append_result_type_and_id_to_spirv_params(). auto append_result_type_and_id_to_spirv_params_for_read = [&]() { if (texture_type->Is()) { - auto* f32 = mod_->create(); - auto* spirv_result_type = mod_->create(f32, 4); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + auto* f32 = const_cast(program_)->create(); + auto* spirv_result_type = + const_cast(program_)->create(f32, 4); auto spirv_result = result_op(); post_emission = [=] { return push_function_inst( @@ -2073,8 +2077,10 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, // OpImageQuerySize[Lod]. auto* element_type = ElementTypeOf(call->result_type()); auto spirv_result = result_op(); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! auto* spirv_result_type = - mod_->create(element_type, spirv_result_width); + const_cast(program_)->create( + element_type, spirv_result_width); if (swizzle.size() > 1) { post_emission = [=] { OperandList operands{ @@ -2192,7 +2198,9 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back(gen_param(pidx.level)); } else { - ast::SintLiteral i32_0(Source{}, mod_->create(), 0); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + ast::SintLiteral i32_0( + Source{}, const_cast(program_)->create(), 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -2227,7 +2235,9 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, texture_type->Is()) { op = spv::Op::OpImageQuerySize; } else { - ast::SintLiteral i32_0(Source{}, mod_->create(), 0); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + ast::SintLiteral i32_0( + Source{}, const_cast(program_)->create(), 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -2306,7 +2316,8 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, if (call->params()[pidx.level]->result_type()->Is()) { // Depth textures have i32 parameters for the level, but SPIR-V expects // F32. Cast. - auto* f32 = mod_->create(); + // TODO(https://crbug.com/tint/390): Remove this const_cast hack! + auto* f32 = const_cast(program_)->create(); ast::TypeConstructorExpression cast(Source{}, f32, {call->params()[pidx.level]}); level = Operand::Int(GenerateExpression(&cast)); @@ -2373,7 +2384,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, if (op == spv::Op::OpNop) { error_ = "unable to determine operator for: " + - mod_->SymbolToName(ident->symbol()); + program_->SymbolToName(ident->symbol()); return false; } @@ -2992,9 +3003,10 @@ bool Builder::GenerateStructType(type::Struct* struct_type, auto* impl = struct_type->impl(); if (struct_type->symbol().IsValid()) { - push_debug(spv::Op::OpName, - {Operand::Int(struct_id), - Operand::String(mod_->SymbolToName(struct_type->symbol()))}); + push_debug( + spv::Op::OpName, + {Operand::Int(struct_id), + Operand::String(program_->SymbolToName(struct_type->symbol()))}); } OperandList ops; @@ -3037,7 +3049,7 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id, ast::StructMember* member) { push_debug(spv::Op::OpMemberName, {Operand::Int(struct_id), Operand::Int(idx), - Operand::String(mod_->SymbolToName(member->symbol()))}); + Operand::String(program_->SymbolToName(member->symbol()))}); bool has_layout = false; for (auto* deco : member->decorations()) { diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index 9a76a0dbc3..aa6590f117 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -37,13 +37,13 @@ #include "src/ast/literal.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/struct_member.h" #include "src/ast/switch_statement.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable_decl_statement.h" +#include "src/program.h" #include "src/scope_stack.h" #include "src/type/access_control_type.h" #include "src/type/array_type.h" @@ -59,7 +59,7 @@ namespace tint { namespace writer { namespace spirv { -/// Builder class to create SPIR-V instructions from a module. +/// Builder class to create SPIR-V instructions from a program. class Builder { public: /// Contains information for generating accessor chains @@ -82,11 +82,11 @@ class Builder { }; /// Constructor - /// @param mod the module to generate from - explicit Builder(ast::Module* mod); + /// @param program the program to generate from + explicit Builder(const Program* program); ~Builder(); - /// Generates the SPIR-V instructions for the given module + /// Generates the SPIR-V instructions for the given program /// @returns true if the SPIR-V was successfully built bool Build(); @@ -98,7 +98,7 @@ class Builder { /// @returns the number of uint32_t's needed to make up the results uint32_t total_size() const; - /// @returns the id bound for this module + /// @returns the id bound for this program uint32_t id_bound() const { return next_id_; } /// @returns the next id to be used @@ -487,7 +487,7 @@ class Builder { /// automatically. Operand result_op(); - ast::Module* mod_; + const Program* program_; std::string error_; uint32_t next_id_ = 1; uint32_t current_label_id_ = 0; diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index 55510983ca..c9abc71570 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -19,7 +19,6 @@ #include "src/ast/float_literal.h" #include "src/ast/identifier_expression.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/sint_literal.h" #include "src/ast/struct.h" @@ -27,6 +26,7 @@ #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/array_type.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" diff --git a/src/writer/spirv/builder_bitcast_expression_test.cc b/src/writer/spirv/builder_bitcast_expression_test.cc index 33a717a905..80c564be8b 100644 --- a/src/writer/spirv/builder_bitcast_expression_test.cc +++ b/src/writer/spirv/builder_bitcast_expression_test.cc @@ -15,8 +15,8 @@ #include "gtest/gtest.h" #include "src/ast/bitcast_expression.h" #include "src/ast/float_literal.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" +#include "src/program.h" #include "src/type/f32_type.h" #include "src/type/u32_type.h" #include "src/type_determiner.h" diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index ec0838acb9..f9214b804f 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -23,13 +23,13 @@ #include "src/ast/float_literal.h" #include "src/ast/group_decoration.h" #include "src/ast/location_decoration.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/storage_class.h" #include "src/ast/struct.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/variable.h" #include "src/ast/variable_decoration.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/bool_type.h" #include "src/type/f32_type.h" diff --git a/src/writer/spirv/builder_test.cc b/src/writer/spirv/builder_test.cc index 9cedea71dd..3498566515 100644 --- a/src/writer/spirv/builder_test.cc +++ b/src/writer/spirv/builder_test.cc @@ -19,7 +19,7 @@ #include "gtest/gtest.h" #include "spirv/unified1/spirv.h" #include "spirv/unified1/spirv.hpp11" -#include "src/ast/module.h" +#include "src/program.h" #include "src/writer/spirv/spv_dump.h" #include "src/writer/spirv/test_helper.h" diff --git a/src/writer/spirv/generator.cc b/src/writer/spirv/generator.cc index ba367c51e9..4163e57101 100644 --- a/src/writer/spirv/generator.cc +++ b/src/writer/spirv/generator.cc @@ -20,13 +20,8 @@ namespace tint { namespace writer { namespace spirv { -Generator::Generator(ast::Module module) - : module_(std::move(module)), - builder_(std::make_unique(&module_)), - writer_(std::make_unique()) {} - -Generator::Generator(Program* program) - : builder_(std::make_unique(&program->module)), +Generator::Generator(const Program* program) + : builder_(std::make_unique(program)), writer_(std::make_unique()) {} Generator::~Generator() = default; diff --git a/src/writer/spirv/generator.h b/src/writer/spirv/generator.h index 82bff48645..c85fe4f749 100644 --- a/src/writer/spirv/generator.h +++ b/src/writer/spirv/generator.h @@ -19,7 +19,6 @@ #include #include -#include "src/ast/module.h" #include "src/program.h" #include "src/writer/spirv/binary_writer.h" #include "src/writer/spirv/builder.h" @@ -29,16 +28,12 @@ namespace tint { namespace writer { namespace spirv { -/// Class to generate SPIR-V from a Tint module +/// Class to generate SPIR-V from a Tint program class Generator : public writer::Writer { public: - /// Constructor - /// @param module the module to convert - explicit Generator(ast::Module module); - /// Constructor /// @param program the program to convert - explicit Generator(Program* program); + explicit Generator(const Program* program); /// Destructor ~Generator() override; @@ -58,7 +53,6 @@ class Generator : public writer::Writer { const std::vector& result() const { return writer_->result(); } private: - ast::Module module_; std::unique_ptr builder_; std::unique_ptr writer_; }; diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h index 6ee8b6454d..52c1aae0c5 100644 --- a/src/writer/spirv/test_helper.h +++ b/src/writer/spirv/test_helper.h @@ -20,7 +20,7 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" @@ -30,12 +30,12 @@ namespace spirv { /// Helper class for testing template -class TestHelperBase : public ast::BuilderWithModule, public BASE { +class TestHelperBase : public ast::BuilderWithProgram, public BASE { public: - TestHelperBase() : td(mod) {} + TestHelperBase() : td(program) {} ~TestHelperBase() override = default; - /// Builds and returns a spirv::Builder from the module. + /// Builds and returns a spirv::Builder from the program. /// @note The spirv::Builder is only built once. Multiple calls to Build() /// will return the same spirv::Builder without rebuilding. /// @return the built spirv::Builder @@ -43,7 +43,7 @@ class TestHelperBase : public ast::BuilderWithModule, public BASE { if (spirv_builder) { return *spirv_builder; } - spirv_builder = std::make_unique(mod); + spirv_builder = std::make_unique(program); return *spirv_builder; } diff --git a/src/writer/wgsl/generator.cc b/src/writer/wgsl/generator.cc index 368b5eff98..5fc91cc994 100644 --- a/src/writer/wgsl/generator.cc +++ b/src/writer/wgsl/generator.cc @@ -20,12 +20,8 @@ namespace tint { namespace writer { namespace wgsl { -Generator::Generator(ast::Module module) - : module_(std::move(module)), - impl_(std::make_unique(&module_)) {} - -Generator::Generator(Program* program) - : impl_(std::make_unique(&program->module)) {} +Generator::Generator(const Program* program) + : impl_(std::make_unique(program)) {} Generator::~Generator() = default; diff --git a/src/writer/wgsl/generator.h b/src/writer/wgsl/generator.h index 3ed31ecbd3..1c83faf275 100644 --- a/src/writer/wgsl/generator.h +++ b/src/writer/wgsl/generator.h @@ -29,13 +29,9 @@ namespace wgsl { /// Class to generate WGSL source class Generator : public Text { public: - /// Constructor - /// @param module the module to convert - explicit Generator(ast::Module module); - /// Constructor /// @param program the program to convert - explicit Generator(Program* program); + explicit Generator(const Program* program); /// Destructor ~Generator() override; @@ -58,7 +54,6 @@ class Generator : public Text { std::string error() const; private: - ast::Module module_; std::unique_ptr impl_; }; diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 520a59591c..3b26bece8a 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -78,30 +78,30 @@ namespace tint { namespace writer { namespace wgsl { -GeneratorImpl::GeneratorImpl(ast::Module* module) - : TextGenerator(), module_(*module) {} +GeneratorImpl::GeneratorImpl(const Program* program) + : TextGenerator(), program_(program) {} GeneratorImpl::~GeneratorImpl() = default; bool GeneratorImpl::Generate() { - for (auto* const ty : module_.constructed_types()) { + for (auto* const ty : program_->constructed_types()) { if (!EmitConstructedType(ty)) { return false; } } - if (!module_.constructed_types().empty()) + if (!program_->constructed_types().empty()) out_ << std::endl; - for (auto* var : module_.global_variables()) { + for (auto* var : program_->global_variables()) { if (!EmitVariable(var)) { return false; } } - if (!module_.global_variables().empty()) { + if (!program_->global_variables().empty()) { out_ << std::endl; } - for (auto* func : module_.Functions()) { + for (auto* func : program_->Functions()) { if (!EmitFunction(func)) { return false; } @@ -113,7 +113,7 @@ bool GeneratorImpl::Generate() { bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, const std::string& name) { - auto* func = module_.Functions().Find(module_.GetSymbol(name), stage); + auto* func = program_->Functions().Find(program_->GetSymbol(name), stage); if (func == nullptr) { error_ = "Unable to find requested entry point: " + name; return false; @@ -121,18 +121,18 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, // TODO(dsinclair): We always emit constructed types even if they aren't // strictly needed - for (auto* const ty : module_.constructed_types()) { + for (auto* const ty : program_->constructed_types()) { if (!EmitConstructedType(ty)) { return false; } } - if (!module_.constructed_types().empty()) { + if (!program_->constructed_types().empty()) { out_ << std::endl; } // TODO(dsinclair): This should be smarter and only emit needed const // variables - for (auto* var : module_.global_variables()) { + for (auto* var : program_->global_variables()) { if (!var->is_const()) { continue; } @@ -152,8 +152,8 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, out_ << std::endl; } - for (auto* f : module_.Functions()) { - if (!f->HasAncestorEntryPoint(module_.GetSymbol(name))) { + for (auto* f : program_->Functions()) { + if (!f->HasAncestorEntryPoint(program_->GetSymbol(name))) { continue; } @@ -174,7 +174,7 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, bool GeneratorImpl::EmitConstructedType(const type::Type* ty) { make_indent(); if (auto* alias = ty->As()) { - out_ << "type " << module_.SymbolToName(alias->symbol()) << " = "; + out_ << "type " << program_->SymbolToName(alias->symbol()) << " = "; if (!EmitType(alias->type())) { return false; } @@ -337,7 +337,7 @@ bool GeneratorImpl::EmitLiteral(ast::Literal* lit) { bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) { auto* ident = expr->As(); - out_ << module_.SymbolToName(ident->symbol()); + out_ << program_->SymbolToName(ident->symbol()); return true; } @@ -360,7 +360,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { } make_indent(); - out_ << "fn " << module_.SymbolToName(func->symbol()) << "("; + out_ << "fn " << program_->SymbolToName(func->symbol()) << "("; bool first = true; for (auto* v : func->params()) { @@ -369,7 +369,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { } first = false; - out_ << module_.SymbolToName(v->symbol()) << " : "; + out_ << program_->SymbolToName(v->symbol()) << " : "; if (!EmitType(v->type())) { return false; @@ -417,7 +417,7 @@ bool GeneratorImpl::EmitType(type::Type* type) { } return true; } else if (auto* alias = type->As()) { - out_ << module_.SymbolToName(alias->symbol()); + out_ << program_->SymbolToName(alias->symbol()); } else if (auto* ary = type->As()) { for (auto* deco : ary->decorations()) { if (auto* stride = deco->As()) { @@ -461,7 +461,7 @@ bool GeneratorImpl::EmitType(type::Type* type) { } else if (auto* str = type->As()) { // The struct, as a type, is just the name. We should have already emitted // the declaration through a call to |EmitStructType| earlier. - out_ << module_.SymbolToName(str->symbol()); + out_ << program_->SymbolToName(str->symbol()); } else if (auto* texture = type->As()) { out_ << "texture_"; if (texture->Is()) { @@ -549,7 +549,8 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) { deco->to_str(out_, 0); out_ << "]]" << std::endl; } - out_ << "struct " << module_.SymbolToName(str->symbol()) << " {" << std::endl; + out_ << "struct " << program_->SymbolToName(str->symbol()) << " {" + << std::endl; increment_indent(); for (auto* mem : impl->members()) { @@ -562,7 +563,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) { out_ << "[[offset(" << offset->offset() << ")]]" << std::endl; } make_indent(); - out_ << module_.SymbolToName(mem->symbol()) << " : "; + out_ << program_->SymbolToName(mem->symbol()) << " : "; if (!EmitType(mem->type())) { return false; } @@ -592,7 +593,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) { } } - out_ << " " << module_.SymbolToName(var->symbol()) << " : "; + out_ << " " << program_->SymbolToName(var->symbol()) << " : "; if (!EmitType(var->type())) { return false; } diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index 1b3d568134..fa4603b3f2 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -33,13 +33,13 @@ #include "src/ast/if_statement.h" #include "src/ast/loop_statement.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/switch_statement.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" #include "src/ast/variable.h" +#include "src/program.h" #include "src/type/storage_texture_type.h" #include "src/type/struct_type.h" #include "src/type/type.h" @@ -53,8 +53,8 @@ namespace wgsl { class GeneratorImpl : public TextGenerator { public: /// Constructor - /// @param mod the module to generate - explicit GeneratorImpl(ast::Module* mod); + /// @param program the program + explicit GeneratorImpl(const Program* program); ~GeneratorImpl(); /// Generates the result data @@ -205,7 +205,7 @@ class GeneratorImpl : public TextGenerator { bool EmitVariableDecorations(ast::Variable* var); private: - ast::Module& module_; + Program const* const program_; }; } // namespace wgsl diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 0176f7b957..7e4f2afc78 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -16,7 +16,6 @@ #include "src/ast/discard_statement.h" #include "src/ast/function.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" #include "src/ast/return_statement.h" #include "src/ast/stage_decoration.h" @@ -25,6 +24,7 @@ #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/workgroup_decoration.h" +#include "src/program.h" #include "src/type/access_control_type.h" #include "src/type/f32_type.h" #include "src/type/i32_type.h" diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index bf88db1527..449e795cbf 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -18,7 +18,7 @@ #include "gtest/gtest.h" #include "src/ast/function.h" -#include "src/ast/module.h" +#include "src/program.h" #include "src/type/void_type.h" #include "src/writer/wgsl/test_helper.h" diff --git a/src/writer/wgsl/test_helper.h b/src/writer/wgsl/test_helper.h index 6507d320f9..5195c04dcb 100644 --- a/src/writer/wgsl/test_helper.h +++ b/src/writer/wgsl/test_helper.h @@ -29,13 +29,13 @@ namespace wgsl { /// Helper class for testing template -class TestHelperBase : public BASE, public ast::BuilderWithModule { +class TestHelperBase : public BASE, public ast::BuilderWithProgram { public: - TestHelperBase() : td(mod) {} + TestHelperBase() : td(program) {} ~TestHelperBase() = default; - /// Builds and returns a GeneratorImpl from the module. + /// Builds and returns a GeneratorImpl from the program. /// @note The generator is only built once. Multiple calls to Build() will /// return the same GeneratorImpl without rebuilding. /// @return the built generator @@ -43,7 +43,7 @@ class TestHelperBase : public BASE, public ast::BuilderWithModule { if (gen_) { return *gen_; } - gen_ = std::make_unique(mod); + gen_ = std::make_unique(program); return *gen_; } diff --git a/src/writer/writer.h b/src/writer/writer.h index 7aa7a97630..1f6a18e47b 100644 --- a/src/writer/writer.h +++ b/src/writer/writer.h @@ -17,8 +17,8 @@ #include -#include "src/ast/module.h" #include "src/ast/pipeline_stage.h" +#include "src/program.h" namespace tint { namespace writer {