From 685cb02ea8d9afbad46d52ccbe4fa3728ac37693 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 2 Dec 2020 21:17:58 +0000 Subject: [PATCH] Remove internal usage of Context. This CL removes all internal usage of the Context object. It is still accepted as a parameter until we update Dawn, but all usage is removed. The namer has been removed from the SPIR-V backend with this change and the emitted names reverted to their non-modified version. Change-Id: Ie6c550fab1807b558182cd7188ab6450a627f154 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34740 Commit-Queue: dan sinclair Auto-Submit: dan sinclair Reviewed-by: Ryan Harrison --- fuzzers/tint_ast_clone_fuzzer.cc | 3 +- fuzzers/tint_spv_reader_fuzzer.cc | 3 +- fuzzers/tint_wgsl_reader_fuzzer.cc | 4 +- samples/main.cc | 29 ++++----- src/ast/builder.cc | 10 +-- src/ast/builder.h | 15 ++--- src/context.cc | 4 +- src/context.h | 6 -- src/inspector/inspector.cc | 18 ++---- src/inspector/inspector.h | 4 +- src/inspector/inspector_test.cc | 42 ++++++++----- src/reader/reader.cc | 2 +- src/reader/reader.h | 7 +-- src/reader/spirv/parser.cc | 7 ++- src/reader/spirv/parser.h | 5 ++ src/reader/spirv/parser_impl.cc | 4 +- src/reader/spirv/parser_impl.h | 8 +-- src/reader/spirv/parser_impl_test_helper.h | 6 +- src/reader/wgsl/parser.cc | 6 +- src/reader/wgsl/parser.h | 5 ++ src/reader/wgsl/parser_impl.cc | 2 +- src/reader/wgsl/parser_impl.h | 4 +- src/reader/wgsl/parser_impl_test_helper.h | 6 +- .../bound_array_accessors_transform.cc | 7 ++- .../bound_array_accessors_transform.h | 6 +- .../bound_array_accessors_transform_test.cc | 48 +++++++------- src/transform/manager.cc | 15 +++-- src/transform/manager.h | 12 +++- src/transform/transformer.cc | 3 +- src/transform/transformer.h | 5 +- src/transform/vertex_pulling_transform.cc | 7 ++- src/transform/vertex_pulling_transform.h | 5 +- src/type_determiner.cc | 6 +- src/type_determiner.h | 5 +- src/type_determiner_test.cc | 4 +- src/writer/hlsl/generator.cc | 9 ++- src/writer/hlsl/generator.h | 2 +- src/writer/hlsl/generator_impl.cc | 5 +- src/writer/hlsl/generator_impl.h | 5 +- .../generator_impl_intrinsic_texture_test.cc | 6 +- src/writer/hlsl/test_helper.h | 5 +- src/writer/msl/generator.cc | 9 ++- src/writer/msl/generator.h | 2 +- src/writer/msl/generator_impl.cc | 4 +- src/writer/msl/generator_impl.h | 3 +- .../generator_impl_intrinsic_texture_test.cc | 6 +- src/writer/msl/test_helper.h | 5 +- src/writer/spirv/builder.cc | 32 ++++------ src/writer/spirv/builder.h | 5 +- src/writer/spirv/builder_call_test.cc | 16 ++--- .../spirv/builder_function_decoration_test.cc | 20 +++--- src/writer/spirv/builder_function_test.cc | 32 +++++----- .../spirv/builder_function_variable_test.cc | 12 ++-- .../spirv/builder_global_variable_test.cc | 60 +++++++++--------- .../spirv/builder_ident_expression_test.cc | 4 +- src/writer/spirv/builder_intrinsic_test.cc | 62 +++++++++---------- .../spirv/builder_intrinsic_texture_test.cc | 6 +- src/writer/spirv/builder_switch_test.cc | 30 ++++----- src/writer/spirv/builder_type_test.cc | 40 ++++++------ src/writer/spirv/generator.cc | 10 ++- src/writer/spirv/generator.h | 2 +- src/writer/spirv/test_helper.h | 5 +- src/writer/text.cc | 2 - src/writer/text.h | 5 -- src/writer/text_generator.cc | 4 +- src/writer/text_generator.h | 7 +-- src/writer/wgsl/generator.cc | 9 ++- src/writer/wgsl/generator.h | 2 +- src/writer/wgsl/generator_impl.cc | 2 +- src/writer/wgsl/generator_impl.h | 3 +- src/writer/wgsl/test_helper.h | 5 +- src/writer/writer.cc | 13 +--- src/writer/writer.h | 10 --- 73 files changed, 362 insertions(+), 420 deletions(-) diff --git a/fuzzers/tint_ast_clone_fuzzer.cc b/fuzzers/tint_ast_clone_fuzzer.cc index 71c1e27c28..ff72174609 100644 --- a/fuzzers/tint_ast_clone_fuzzer.cc +++ b/fuzzers/tint_ast_clone_fuzzer.cc @@ -47,8 +47,7 @@ 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 - tint::Context ctx; - tint::reader::wgsl::ParserImpl parser(&ctx, &file); + tint::reader::wgsl::ParserImpl parser(&file); parser.set_max_errors(1); if (!parser.Parse()) { return 0; diff --git a/fuzzers/tint_spv_reader_fuzzer.cc b/fuzzers/tint_spv_reader_fuzzer.cc index 24983831d3..e809e5506f 100644 --- a/fuzzers/tint_spv_reader_fuzzer.cc +++ b/fuzzers/tint_spv_reader_fuzzer.cc @@ -22,8 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { std::vector input(u32Data, u32Data + sizeInU32); if (input.size() != 0) { - tint::Context ctx; - tint::reader::spirv::Parser parser(&ctx, input); + tint::reader::spirv::Parser parser(input); parser.Parse(); } diff --git a/fuzzers/tint_wgsl_reader_fuzzer.cc b/fuzzers/tint_wgsl_reader_fuzzer.cc index d9c0d4e0b8..d1a7507429 100644 --- a/fuzzers/tint_wgsl_reader_fuzzer.cc +++ b/fuzzers/tint_wgsl_reader_fuzzer.cc @@ -20,9 +20,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { std::string str(reinterpret_cast(data), size); tint::Source::File file("test.wgsl", str); - - tint::Context ctx; - tint::reader::wgsl::Parser parser(&ctx, &file); + tint::reader::wgsl::Parser parser(&file); parser.Parse(); return 0; diff --git a/samples/main.cc b/samples/main.cc index 5d4534c8c3..dcdea27398 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -418,8 +418,6 @@ int main(int argc, const char** argv) { options.format = Format::kSpvAsm; } - tint::Context ctx(std::make_unique()); - auto diag_printer = tint::diag::Printer::create(stderr, true); tint::diag::Formatter diag_formatter; @@ -435,8 +433,7 @@ int main(int argc, const char** argv) { } source_file = std::make_unique( options.input_filename, std::string(data.begin(), data.end())); - reader = - std::make_unique(&ctx, source_file.get()); + reader = std::make_unique(source_file.get()); } #endif // TINT_BUILD_WGSL_READER @@ -449,7 +446,7 @@ int main(int argc, const char** argv) { if (!ReadFile(options.input_filename, &data)) { return 1; } - reader = std::make_unique(&ctx, data); + reader = std::make_unique(data); } // Handle SPIR-V assembly input, in files ending with .spvasm if (options.input_filename.size() > 7 && @@ -471,7 +468,7 @@ int main(int argc, const char** argv) { SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS)) { return 1; } - reader = std::make_unique(&ctx, data); + reader = std::make_unique(data); } #endif // TINT_BUILD_SPV_READER @@ -490,7 +487,7 @@ int main(int argc, const char** argv) { return 1; } - tint::TypeDeterminer td(&ctx, &mod); + tint::TypeDeterminer td(&mod); if (!td.Determine()) { std::cerr << "Type Determination: " << td.error() << std::endl; return 1; @@ -509,7 +506,7 @@ int main(int argc, const char** argv) { return 1; } - tint::transform::Manager transform_manager(&ctx, &mod); + tint::transform::Manager transform_manager; for (const auto& name : options.transforms) { // TODO(dsinclair): The vertex pulling transform requires setup code to // be run that needs user input. Should we find a way to support that here @@ -518,13 +515,13 @@ int main(int argc, const char** argv) { if (name == "bound_array_accessors") { transform_manager.append( std::make_unique( - &ctx, &mod)); + &mod)); } else { std::cerr << "Unknown transform name: " << name << std::endl; return 1; } } - if (!transform_manager.Run()) { + if (!transform_manager.Run(&mod)) { std::cerr << "Transformer: " << transform_manager.error() << std::endl; return 1; } @@ -533,29 +530,25 @@ int main(int argc, const char** argv) { #if TINT_BUILD_SPV_WRITER if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) { - writer = - std::make_unique(&ctx, std::move(mod)); + writer = std::make_unique(std::move(mod)); } #endif // TINT_BUILD_SPV_WRITER #if TINT_BUILD_WGSL_WRITER if (options.format == Format::kWgsl) { - writer = - std::make_unique(&ctx, std::move(mod)); + writer = std::make_unique(std::move(mod)); } #endif // TINT_BUILD_WGSL_WRITER #if TINT_BUILD_MSL_WRITER if (options.format == Format::kMsl) { - writer = - std::make_unique(&ctx, std::move(mod)); + writer = std::make_unique(std::move(mod)); } #endif // TINT_BUILD_MSL_WRITER #if TINT_BUILD_HLSL_WRITER if (options.format == Format::kHlsl) { - writer = - std::make_unique(&ctx, std::move(mod)); + writer = std::make_unique(std::move(mod)); } #endif // TINT_BUILD_HLSL_WRITER diff --git a/src/ast/builder.cc b/src/ast/builder.cc index cdc683530c..9984977fb6 100644 --- a/src/ast/builder.cc +++ b/src/ast/builder.cc @@ -25,7 +25,8 @@ TypesBuilder::TypesBuilder(Module* mod) void_(mod->create()), mod_(mod) {} -Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {} +Builder::Builder(Module* m) : mod(m), ty(m) {} + Builder::~Builder() = default; Variable* Builder::Var(const std::string& name, @@ -36,10 +37,9 @@ Variable* Builder::Var(const std::string& name, return var; } -BuilderWithContextAndModule::BuilderWithContextAndModule() - : Builder(new Context(), new Module()) {} -BuilderWithContextAndModule::~BuilderWithContextAndModule() { - delete ctx; +BuilderWithModule::BuilderWithModule() : Builder(new Module()) {} + +BuilderWithModule::~BuilderWithModule() { delete mod; } diff --git a/src/ast/builder.h b/src/ast/builder.h index 7551f92741..eaa7ed7c13 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -38,7 +38,6 @@ #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable.h" -#include "src/context.h" namespace tint { namespace ast { @@ -186,9 +185,8 @@ class Builder { using f32 = float; /// Constructor - /// @param ctx the context to use in the builder /// @param mod the module to use in the builder - explicit Builder(Context* ctx, Module* mod); + explicit Builder(Module* mod); virtual ~Builder(); /// @param expr the expression @@ -443,8 +441,6 @@ class Builder { return mod->create(std::forward(args)...); } - /// The builder module - Context* const ctx; /// The builder module Module* const mod; /// The builder types @@ -455,12 +451,11 @@ class Builder { virtual void OnVariableBuilt(Variable*) {} }; -/// BuilderWithContextAndModule is a `Builder` that constructs and owns its -/// `Context` and `Module`. -class BuilderWithContextAndModule : public Builder { +/// BuilderWithModule is a `Builder` that constructs and owns its `Module`. +class BuilderWithModule : public Builder { public: - BuilderWithContextAndModule(); - ~BuilderWithContextAndModule() override; + BuilderWithModule(); + ~BuilderWithModule() override; }; //! @cond Doxygen_Suppress diff --git a/src/context.cc b/src/context.cc index 88e69f90c7..e63787960d 100644 --- a/src/context.cc +++ b/src/context.cc @@ -21,9 +21,9 @@ namespace tint { -Context::Context() : namer_(std::make_unique()) {} +Context::Context() = default; -Context::Context(std::unique_ptr namer) : namer_(std::move(namer)) {} +Context::Context(std::unique_ptr) {} Context::~Context() = default; diff --git a/src/context.h b/src/context.h index d21fc5bce1..89a89b3b10 100644 --- a/src/context.h +++ b/src/context.h @@ -41,12 +41,6 @@ class Context { explicit Context(std::unique_ptr namer); /// Destructor ~Context(); - - /// @returns the namer object - Namer* namer() const { return namer_.get(); } - - private: - std::unique_ptr namer_; }; } // namespace tint diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index 9914d85ed0..031723b7c6 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -43,18 +43,12 @@ namespace tint { namespace inspector { -Inspector::Inspector(const ast::Module& module) - : ctx_(new Context()), context_is_owned_(true), module_(module) {} +Inspector::Inspector(const ast::Module& module) : module_(module) {} -Inspector::Inspector(Context* ctx, const ast::Module& module) - : ctx_(ctx), context_is_owned_(false), module_(module) { - assert(ctx); -} +Inspector::Inspector(Context*, const ast::Module& module) + : Inspector(std::move(module)) {} -Inspector::~Inspector() { - if (context_is_owned_) - delete ctx_; -} +Inspector::~Inspector() = default; std::vector Inspector::GetEntryPoints() { std::vector result; @@ -66,7 +60,7 @@ std::vector Inspector::GetEntryPoints() { EntryPoint entry_point; entry_point.name = func->name(); - entry_point.remapped_name = ctx_->namer()->NameFor(func->name()); + entry_point.remapped_name = func->name(); 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(); @@ -93,7 +87,7 @@ std::string Inspector::GetRemappedNameForEntryPoint( // if (!func) { // return {}; // } - // return ctx_->namer()->NameFor(entry_point); + // return func->name(); return entry_point; } diff --git a/src/inspector/inspector.h b/src/inspector/inspector.h index d14c1df410..f1189b01e4 100644 --- a/src/inspector/inspector.h +++ b/src/inspector/inspector.h @@ -72,10 +72,10 @@ struct ResourceBinding { class Inspector { public: /// Constructor - /// DEPRECATED /// @param module Shader module to extract information from. explicit Inspector(const ast::Module& module); /// Constructor + /// DEPRECATED /// @param ctx the context, must be non-null /// @param module Shader module to extract information from. Inspector(Context* ctx, const ast::Module& module); @@ -133,8 +133,6 @@ class Inspector { const std::string& entry_point); private: - Context* ctx_ = nullptr; - bool context_is_owned_ = false; const ast::Module& module_; std::string error_; diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index f463ba361f..34c879653e 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -59,7 +59,6 @@ #include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decoration.h" #include "src/ast/workgroup_decoration.h" -#include "src/context.h" #include "src/type_determiner.h" #include "tint/tint.h" @@ -70,7 +69,7 @@ namespace { class InspectorHelper { public: InspectorHelper() - : td_(std::make_unique(&ctx_, &mod_)), + : td_(std::make_unique(&mod_)), inspector_(std::make_unique(mod_)), sampler_type_(ast::type::SamplerKind::kSampler), comparison_sampler_type_(ast::type::SamplerKind::kComparisonSampler) {} @@ -683,7 +682,6 @@ class InspectorHelper { } private: - Context ctx_; ast::Module mod_; std::unique_ptr td_; std::unique_ptr inspector_; @@ -771,12 +769,14 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) { create(ast::PipelineStage::kVertex, Source{})); mod()->AddFunction(foo); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetEntryPoints(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(1u, result.size()); EXPECT_EQ("foo", result[0].name); - EXPECT_EQ("tint_666f6f", result[0].remapped_name); + EXPECT_EQ("foo", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); } @@ -791,15 +791,17 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { create(ast::PipelineStage::kCompute, Source{})); mod()->AddFunction(bar); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetEntryPoints(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(2u, result.size()); EXPECT_EQ("foo", result[0].name); - EXPECT_EQ("tint_666f6f", result[0].remapped_name); + EXPECT_EQ("foo", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); EXPECT_EQ("bar", result[1].name); - EXPECT_EQ("tint_626172", result[1].remapped_name); + EXPECT_EQ("bar", result[1].remapped_name); EXPECT_EQ(ast::PipelineStage::kCompute, result[1].stage); } @@ -817,15 +819,17 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { create(ast::PipelineStage::kFragment, Source{})); mod()->AddFunction(bar); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetEntryPoints(); EXPECT_FALSE(inspector()->has_error()); ASSERT_EQ(2u, result.size()); EXPECT_EQ("foo", result[0].name); - EXPECT_EQ("tint_666f6f", result[0].remapped_name); + EXPECT_EQ("foo", result[0].remapped_name); EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage); EXPECT_EQ("bar", result[1].name); - EXPECT_EQ("tint_626172", result[1].remapped_name); + EXPECT_EQ("bar", result[1].remapped_name); EXPECT_EQ(ast::PipelineStage::kFragment, result[1].stage); } @@ -1017,20 +1021,22 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { ASSERT_TRUE(td()->Determine()) << td()->error(); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetEntryPoints(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(2u, result.size()); ASSERT_EQ("foo", result[0].name); - ASSERT_EQ("tint_666f6f", result[0].remapped_name); + ASSERT_EQ("foo", result[0].remapped_name); ASSERT_EQ(1u, result[0].input_variables.size()); EXPECT_EQ("in_var", result[0].input_variables[0]); ASSERT_EQ(1u, result[0].output_variables.size()); EXPECT_EQ("out2_var", result[0].output_variables[0]); ASSERT_EQ("bar", result[1].name); - ASSERT_EQ("tint_626172", result[1].remapped_name); + ASSERT_EQ("bar", result[1].remapped_name); ASSERT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0]); ASSERT_EQ(1u, result[1].output_variables.size()); @@ -1056,13 +1062,15 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { ASSERT_TRUE(td()->Determine()) << td()->error(); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetEntryPoints(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_EQ(2u, result.size()); ASSERT_EQ("foo", result[0].name); - ASSERT_EQ("tint_666f6f", result[0].remapped_name); + ASSERT_EQ("foo", result[0].remapped_name); EXPECT_EQ(2u, result[0].input_variables.size()); EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var")); EXPECT_TRUE(ContainsString(result[0].input_variables, "in2_var")); @@ -1071,7 +1079,7 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { EXPECT_TRUE(ContainsString(result[0].output_variables, "out2_var")); ASSERT_EQ("bar", result[1].name); - ASSERT_EQ("tint_626172", result[1].remapped_name); + ASSERT_EQ("bar", result[1].remapped_name); EXPECT_EQ(1u, result[1].input_variables.size()); EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ(1u, result[1].output_variables.size()); @@ -1106,10 +1114,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) { create(ast::PipelineStage::kVertex, Source{})); mod()->AddFunction(foo); + // TODO(dsinclair): Update to run the namer transform when available. + auto result = inspector()->GetRemappedNameForEntryPoint("foo"); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); - EXPECT_EQ("tint_666f6f", result); + EXPECT_EQ("foo", result); } // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass @@ -1121,6 +1131,8 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, create(ast::PipelineStage::kVertex, Source{})); mod()->AddFunction(foo); + // TODO(dsinclair): Update to run the namer transform when available. + auto* bar = MakeEmptyBodyFunction("bar"); bar->add_decoration( create(ast::PipelineStage::kCompute, Source{})); @@ -1129,12 +1141,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, { auto result = inspector()->GetRemappedNameForEntryPoint("foo"); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); - EXPECT_EQ("tint_666f6f", result); + EXPECT_EQ("foo", result); } { auto result = inspector()->GetRemappedNameForEntryPoint("bar"); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); - EXPECT_EQ("tint_626172", result); + EXPECT_EQ("bar", result); } } diff --git a/src/reader/reader.cc b/src/reader/reader.cc index c94f8999bb..6d902733d4 100644 --- a/src/reader/reader.cc +++ b/src/reader/reader.cc @@ -17,7 +17,7 @@ namespace tint { namespace reader { -Reader::Reader(Context* ctx) : ctx_(*ctx) {} +Reader::Reader() = default; Reader::~Reader() = default; diff --git a/src/reader/reader.h b/src/reader/reader.h index 481752fb80..8fa4c92016 100644 --- a/src/reader/reader.h +++ b/src/reader/reader.h @@ -19,7 +19,6 @@ #include #include "src/ast/module.h" -#include "src/context.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" @@ -52,16 +51,12 @@ class Reader { protected: /// Constructor - /// @param ctx the context object, must be non-null - explicit Reader(Context* ctx); + Reader(); /// Sets the diagnostic messages /// @param diags the list of diagnostic messages void set_diagnostics(const diag::List& diags) { diags_ = diags; } - /// The Tint context object - Context& ctx_; - /// All diagnostic messages from the reader. diag::List diags_; }; diff --git a/src/reader/spirv/parser.cc b/src/reader/spirv/parser.cc index 23b5acd453..751b59d9e8 100644 --- a/src/reader/spirv/parser.cc +++ b/src/reader/spirv/parser.cc @@ -20,8 +20,11 @@ namespace tint { namespace reader { namespace spirv { -Parser::Parser(Context* ctx, const std::vector& spv_binary) - : Reader(ctx), impl_(std::make_unique(ctx, spv_binary)) {} +Parser::Parser(const std::vector& spv_binary) + : Reader(), impl_(std::make_unique(spv_binary)) {} + +Parser::Parser(Context*, const std::vector& spv_binary) + : Parser(spv_binary) {} Parser::~Parser() = default; diff --git a/src/reader/spirv/parser.h b/src/reader/spirv/parser.h index d4d0974b15..e2084e2e53 100644 --- a/src/reader/spirv/parser.h +++ b/src/reader/spirv/parser.h @@ -19,6 +19,7 @@ #include #include +#include "src/context.h" #include "src/reader/reader.h" namespace tint { @@ -31,6 +32,10 @@ class ParserImpl; class Parser : public Reader { public: /// Creates a new parser + /// @param input the input data to parse + explicit Parser(const std::vector& input); + /// Creates a new parser + /// DEPRECATED /// @param ctx the non-null context object /// @param input the input data to parse Parser(Context* ctx, const std::vector& input); diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index ccdf5c5a2c..b0c01a9e93 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -192,8 +192,8 @@ bool AssumesResultSignednessMatchesBinaryFirstOperand(SpvOp opcode) { } // namespace -ParserImpl::ParserImpl(Context* ctx, const std::vector& spv_binary) - : Reader(ctx), +ParserImpl::ParserImpl(const std::vector& spv_binary) + : Reader(), spv_binary_(spv_binary), fail_stream_(&success_, &errors_), bool_type_(ast_module_.create()), diff --git a/src/reader/spirv/parser_impl.h b/src/reader/spirv/parser_impl.h index 856ecf8348..6530d9ec24 100644 --- a/src/reader/spirv/parser_impl.h +++ b/src/reader/spirv/parser_impl.h @@ -86,9 +86,8 @@ struct TypedExpression { class ParserImpl : Reader { public: /// Creates a new parser - /// @param ctx the non-null context object /// @param input the input data to parse - ParserImpl(Context* ctx, const std::vector& input); + explicit ParserImpl(const std::vector& input); /// Destructor ~ParserImpl() override; @@ -96,11 +95,6 @@ class ParserImpl : Reader { /// @returns true if the parse was successful, false otherwise. bool Parse() override; - /// @returns the Tint context. - Context& context() { - return ctx_; // Inherited from Reader - } - /// @returns the module. The module in the parser will be reset after this. ast::Module module() override; diff --git a/src/reader/spirv/parser_impl_test_helper.h b/src/reader/spirv/parser_impl_test_helper.h index 164bfaa577..0a915a8b8c 100644 --- a/src/reader/spirv/parser_impl_test_helper.h +++ b/src/reader/spirv/parser_impl_test_helper.h @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "source/opt/ir_context.h" -#include "src/context.h" #include "src/reader/spirv/parser_impl.h" namespace tint { @@ -40,7 +39,7 @@ class SpvParserTestBase : public T { /// @param input the SPIR-V binary to parse /// @returns a parser for the given binary std::unique_ptr parser(const std::vector& input) { - return std::make_unique(&ctx_, input); + return std::make_unique(input); } /// Gets the internal representation of the function with the given ID. @@ -52,9 +51,6 @@ class SpvParserTestBase : public T { spvtools::opt::Function* spirv_function(ParserImpl* parser, uint32_t id) { return parser->ir_context()->GetFunction(id); } - - private: - Context ctx_; }; // Use this form when you don't need to template any further. diff --git a/src/reader/wgsl/parser.cc b/src/reader/wgsl/parser.cc index 3b41c094bd..503910b53c 100644 --- a/src/reader/wgsl/parser.cc +++ b/src/reader/wgsl/parser.cc @@ -22,8 +22,10 @@ namespace tint { namespace reader { namespace wgsl { -Parser::Parser(Context* ctx, Source::File const* file) - : Reader(ctx), impl_(std::make_unique(ctx, file)) {} +Parser::Parser(Source::File const* file) + : Reader(), impl_(std::make_unique(file)) {} + +Parser::Parser(Context*, Source::File const* file) : Parser(file) {} Parser::~Parser() = default; diff --git a/src/reader/wgsl/parser.h b/src/reader/wgsl/parser.h index ddff63fc3f..110fafc9db 100644 --- a/src/reader/wgsl/parser.h +++ b/src/reader/wgsl/parser.h @@ -18,6 +18,7 @@ #include #include +#include "src/context.h" #include "src/reader/reader.h" #include "src/source.h" @@ -31,6 +32,10 @@ class ParserImpl; class Parser : public Reader { public: /// Creates a new parser from the given file. + /// @param file the input source file to parse + explicit Parser(Source::File const* file); + /// Creates a new parser from the given file. + /// DEPRECATED /// @param ctx the non-null context object /// @param file the input source file to parse Parser(Context* ctx, Source::File const* file); diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index fcbba85b91..0e7e9d752c 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -186,7 +186,7 @@ struct BlockCounters { } // namespace -ParserImpl::ParserImpl(Context*, Source::File const* file) +ParserImpl::ParserImpl(Source::File const* file) : lexer_(std::make_unique(file)) {} ParserImpl::~ParserImpl() = default; diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 760a1cd522..5ee8fe2ee6 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -55,7 +55,6 @@ #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decoration.h" -#include "src/context.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" #include "src/reader/wgsl/parser_impl_detail.h" @@ -231,9 +230,8 @@ class ParserImpl { }; /// Creates a new parser using the given file - /// @param ctx the non-null context object /// @param file the input source file to parse - ParserImpl(Context* ctx, Source::File const* file); + explicit ParserImpl(Source::File const* file); ~ParserImpl(); /// Run the parser diff --git a/src/reader/wgsl/parser_impl_test_helper.h b/src/reader/wgsl/parser_impl_test_helper.h index 73d29001fe..f1bdf3b15e 100644 --- a/src/reader/wgsl/parser_impl_test_helper.h +++ b/src/reader/wgsl/parser_impl_test_helper.h @@ -40,14 +40,13 @@ class ParserImplTest : public testing::Test { /// @returns the parser implementation std::unique_ptr parser(const std::string& str) { auto file = std::make_unique("test.wgsl", str); - auto impl = std::make_unique(&ctx_, file.get()); + auto impl = std::make_unique(file.get()); files_.emplace_back(std::move(file)); return impl; } private: std::vector> files_; - Context ctx_; }; /// WGSL Parser test class with param @@ -63,14 +62,13 @@ class ParserImplTestWithParam : public testing::TestWithParam { /// @returns the parser implementation std::unique_ptr parser(const std::string& str) { auto file = std::make_unique("test.wgsl", str); - auto impl = std::make_unique(&ctx_, file.get()); + auto impl = std::make_unique(file.get()); files_.emplace_back(std::move(file)); return impl; } private: std::vector> files_; - Context ctx_; }; } // namespace wgsl diff --git a/src/transform/bound_array_accessors_transform.cc b/src/transform/bound_array_accessors_transform.cc index f1ecc64be2..e13ecee130 100644 --- a/src/transform/bound_array_accessors_transform.cc +++ b/src/transform/bound_array_accessors_transform.cc @@ -49,9 +49,12 @@ namespace tint { namespace transform { -BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context* ctx, +BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(ast::Module* mod) + : Transformer(mod) {} + +BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context*, ast::Module* mod) - : Transformer(ctx, mod) {} + : BoundArrayAccessorsTransform(mod) {} BoundArrayAccessorsTransform::~BoundArrayAccessorsTransform() = default; diff --git a/src/transform/bound_array_accessors_transform.h b/src/transform/bound_array_accessors_transform.h index fb20428426..5da26b2f50 100644 --- a/src/transform/bound_array_accessors_transform.h +++ b/src/transform/bound_array_accessors_transform.h @@ -35,9 +35,13 @@ namespace transform { class BoundArrayAccessorsTransform : public Transformer { public: /// Constructor + /// @param mod the module transform + explicit BoundArrayAccessorsTransform(ast::Module* mod); + /// Constructor + /// DEPRECATED /// @param ctx the Tint context object /// @param mod the module transform - explicit BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod); + BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod); ~BoundArrayAccessorsTransform() override; /// Users of Tint should register the transform with transform manager and diff --git a/src/transform/bound_array_accessors_transform_test.cc b/src/transform/bound_array_accessors_transform_test.cc index 8df7a7cfd9..e48308235b 100644 --- a/src/transform/bound_array_accessors_transform_test.cc +++ b/src/transform/bound_array_accessors_transform_test.cc @@ -40,7 +40,6 @@ #include "src/ast/uint_literal.h" #include "src/ast/variable.h" #include "src/ast/variable_decl_statement.h" -#include "src/context.h" #include "src/transform/manager.h" #include "src/type_determiner.h" @@ -50,12 +49,10 @@ namespace { class BoundArrayAccessorsTest : public testing::Test { public: - BoundArrayAccessorsTest() : td_(&ctx_, &mod_) { - auto transform = - std::make_unique(&ctx_, &mod_); + BoundArrayAccessorsTest() : td_(&mod_) { + auto transform = std::make_unique(&mod_); transform_ = transform.get(); - manager_ = std::make_unique(&ctx_, &mod_); - manager_->append(std::move(transform)); + manager_.append(std::move(transform)); } ast::BlockStatement* SetupFunctionAndBody() { @@ -74,7 +71,7 @@ class BoundArrayAccessorsTest : public testing::Test { TypeDeterminer* td() { return &td_; } - Manager* manager() { return manager_.get(); } + bool Run() { return manager_.Run(&mod_); } /// Creates a new `ast::Node` owned by the Module. When the Module is /// destructed, the `ast::Node` will also be destructed. @@ -86,11 +83,10 @@ class BoundArrayAccessorsTest : public testing::Test { } private: - Context ctx_; ast::Module mod_; TypeDeterminer td_; ast::type::Void void_type_; - std::unique_ptr manager_; + Manager manager_; BoundArrayAccessorsTransform* transform_; ast::BlockStatement* body_ = nullptr; }; @@ -128,7 +124,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -191,7 +187,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -268,7 +264,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -316,7 +312,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -369,7 +365,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -408,7 +404,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -447,7 +443,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -495,7 +491,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -547,7 +543,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -586,7 +582,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); ASSERT_TRUE(ptr->idx_expr()->Is()); @@ -628,7 +624,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -692,7 +688,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -771,7 +767,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -839,7 +835,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -893,7 +889,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -948,7 +944,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); @@ -1003,7 +999,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) { ASSERT_TRUE(td()->Determine()) << td()->error(); - ASSERT_TRUE(manager()->Run()); + ASSERT_TRUE(Run()); ASSERT_TRUE(ptr->Is()); ASSERT_TRUE(ptr->array()->Is()); diff --git a/src/transform/manager.cc b/src/transform/manager.cc index 0cf8a553e5..8b30c2a582 100644 --- a/src/transform/manager.cc +++ b/src/transform/manager.cc @@ -19,12 +19,19 @@ namespace tint { namespace transform { -Manager::Manager(Context* context, ast::Module* module) - : context_(context), module_(module) {} +Manager::Manager() = default; + +Manager::Manager(Context*, ast::Module* module) : module_(module) {} Manager::~Manager() = default; bool Manager::Run() { + return Run(module_); +} + +bool Manager::Run(ast::Module* module) { + error_ = ""; + for (auto& transform : transforms_) { if (!transform->Run()) { error_ = transform->error(); @@ -32,10 +39,10 @@ bool Manager::Run() { } } - if (context_ != nullptr && module_ != nullptr) { + if (module != nullptr) { // The transformed have potentially inserted nodes into the AST, so the type // determinater needs to be run. - TypeDeterminer td(context_, module_); + TypeDeterminer td(module); if (!td.Determine()) { error_ = td.error(); return false; diff --git a/src/transform/manager.h b/src/transform/manager.h index 2ce8ca39f3..c0b3abc213 100644 --- a/src/transform/manager.h +++ b/src/transform/manager.h @@ -20,6 +20,7 @@ #include #include +#include "src/context.h" #include "src/transform/transformer.h" namespace tint { @@ -31,6 +32,9 @@ namespace transform { class Manager { public: /// Constructor + Manager(); + /// Constructor + /// DEPRECATED /// @param context the tint context /// @param module the module to transform Manager(Context* context, ast::Module* module); @@ -43,6 +47,11 @@ class Manager { } /// Runs the transforms + /// @param module the module to run the transforms on + /// @returns true on success; false otherwise + bool Run(ast::Module* module); + /// Runs the transforms + /// DEPRECATED /// @returns true on success; false otherwise bool Run(); @@ -50,9 +59,8 @@ class Manager { std::string error() const { return error_; } private: - Context* context_; - ast::Module* module_; std::vector> transforms_; + ast::Module* module_ = nullptr; std::string error_; }; diff --git a/src/transform/transformer.cc b/src/transform/transformer.cc index c3b7770603..cb48de3ca1 100644 --- a/src/transform/transformer.cc +++ b/src/transform/transformer.cc @@ -17,8 +17,7 @@ namespace tint { namespace transform { -Transformer::Transformer(Context* ctx, ast::Module* mod) - : ctx_(ctx), mod_(mod) {} +Transformer::Transformer(ast::Module* mod) : mod_(mod) {} Transformer::~Transformer() = default; diff --git a/src/transform/transformer.h b/src/transform/transformer.h index d1ec99054f..60f10aa035 100644 --- a/src/transform/transformer.h +++ b/src/transform/transformer.h @@ -29,9 +29,8 @@ namespace transform { class Transformer { public: /// Constructor - /// @param ctx the Tint context /// @param mod the module to transform - Transformer(Context* ctx, ast::Module* mod); + explicit Transformer(ast::Module* mod); virtual ~Transformer(); /// Users of Tint should register the transform with transform manager and @@ -53,8 +52,6 @@ class Transformer { return mod_->create(std::forward(args)...); } - /// The context - Context* ctx_ = nullptr; /// The module ast::Module* mod_ = nullptr; /// Any error messages, or blank if no error diff --git a/src/transform/vertex_pulling_transform.cc b/src/transform/vertex_pulling_transform.cc index 49b8ba625f..588bbfa8b2 100644 --- a/src/transform/vertex_pulling_transform.cc +++ b/src/transform/vertex_pulling_transform.cc @@ -52,8 +52,11 @@ static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index"; } // namespace -VertexPullingTransform::VertexPullingTransform(Context* ctx, ast::Module* mod) - : Transformer(ctx, mod) {} +VertexPullingTransform::VertexPullingTransform(ast::Module* mod) + : Transformer(mod) {} + +VertexPullingTransform::VertexPullingTransform(Context*, ast::Module* mod) + : VertexPullingTransform(mod) {} VertexPullingTransform::~VertexPullingTransform() = default; diff --git a/src/transform/vertex_pulling_transform.h b/src/transform/vertex_pulling_transform.h index ac19f4f89f..3ce7db9a2b 100644 --- a/src/transform/vertex_pulling_transform.h +++ b/src/transform/vertex_pulling_transform.h @@ -25,7 +25,6 @@ #include "src/ast/module.h" #include "src/ast/statement.h" #include "src/ast/variable.h" -#include "src/context.h" #include "src/transform/transformer.h" namespace tint { @@ -147,6 +146,10 @@ struct VertexStateDescriptor { class VertexPullingTransform : public Transformer { public: /// Constructor + /// @param mod the module to convert to vertex pulling + explicit VertexPullingTransform(ast::Module* mod); + /// Constructor + /// DEPRECATED /// @param ctx the tint context /// @param mod the module to convert to vertex pulling VertexPullingTransform(Context* ctx, ast::Module* mod); diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 6b46f9e811..41e143a95b 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -58,8 +58,10 @@ namespace tint { -TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod) - : ctx_(*ctx), mod_(mod) {} +TypeDeterminer::TypeDeterminer(ast::Module* mod) : mod_(mod) {} + +TypeDeterminer::TypeDeterminer(Context*, ast::Module* mod) + : TypeDeterminer(mod) {} TypeDeterminer::~TypeDeterminer() = default; diff --git a/src/type_determiner.h b/src/type_determiner.h index 98e1f232eb..1632af2840 100644 --- a/src/type_determiner.h +++ b/src/type_determiner.h @@ -44,6 +44,10 @@ class Variable; class TypeDeterminer { public: /// Constructor + /// @param mod the module to update with typing information + explicit TypeDeterminer(ast::Module* mod); + /// Constructor + /// DEPRECATED /// @param ctx the tint context, must be non-null /// @param mod the module to update with typing information TypeDeterminer(Context* ctx, ast::Module* mod); @@ -128,7 +132,6 @@ class TypeDeterminer { bool DetermineMemberAccessor(ast::MemberAccessorExpression* expr); bool DetermineUnaryOp(ast::UnaryOpExpression* expr); - Context& ctx_; ast::Module* mod_; std::string error_; ScopeStack variable_stack_; diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 2d240f01e9..af76cee1ef 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -84,9 +84,9 @@ class FakeExpr : public ast::Expression { void to_str(std::ostream&, size_t) const override {} }; -class TypeDeterminerHelper : public ast::BuilderWithContextAndModule { +class TypeDeterminerHelper : public ast::BuilderWithModule { public: - TypeDeterminerHelper() : td_(std::make_unique(ctx, mod)) {} + TypeDeterminerHelper() : td_(std::make_unique(mod)) {} TypeDeterminer* td() const { return td_.get(); } diff --git a/src/writer/hlsl/generator.cc b/src/writer/hlsl/generator.cc index fa76960af4..437d0d5fc6 100644 --- a/src/writer/hlsl/generator.cc +++ b/src/writer/hlsl/generator.cc @@ -22,18 +22,17 @@ namespace hlsl { Generator::Generator(ast::Module module) : Text(std::move(module)), - impl_(std::make_unique(ctx_, &module_)) {} + impl_(std::make_unique(&module_)) {} -Generator::Generator(Context* ctx, ast::Module module) - : Text(ctx, std::move(module)), - impl_(std::make_unique(ctx_, &module_)) {} +Generator::Generator(Context*, ast::Module module) + : Generator(std::move(module)) {} Generator::~Generator() = default; void Generator::Reset() { set_error(""); out_ = std::ostringstream(); - impl_ = std::make_unique(ctx_, &module_); + impl_ = std::make_unique(&module_); } bool Generator::Generate() { diff --git a/src/writer/hlsl/generator.h b/src/writer/hlsl/generator.h index 93213e6187..6f4fa1bd4f 100644 --- a/src/writer/hlsl/generator.h +++ b/src/writer/hlsl/generator.h @@ -30,10 +30,10 @@ namespace hlsl { class Generator : public Text { public: /// Constructor - /// DEPRECATED /// @param module the module to convert explicit Generator(ast::Module module); /// Constructor + /// DEPRECATED /// @param ctx the context, must be non-null /// @param module the module to convert Generator(Context* ctx, ast::Module module); diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index dc91175193..3bde2dad35 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -113,10 +113,7 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) { } // namespace -GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module) - : ctx_(ctx), module_(module) { - assert(ctx); -} +GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {} GeneratorImpl::~GeneratorImpl() = default; diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 44b4dd4610..6694e26040 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -41,7 +41,6 @@ #include "src/ast/type/struct_type.h" #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_op_expression.h" -#include "src/context.h" #include "src/scope_stack.h" #include "src/writer/hlsl/namer.h" @@ -53,9 +52,8 @@ namespace hlsl { class GeneratorImpl { public: /// Constructor - /// @param ctx the context object, must be non-null /// @param module the module to generate - GeneratorImpl(Context* ctx, ast::Module* module); + explicit GeneratorImpl(ast::Module* module); ~GeneratorImpl(); /// Increment the emitter indent level @@ -398,7 +396,6 @@ class GeneratorImpl { size_t indent_ = 0; Namer namer_; - Context* ctx_ = nullptr; ast::Module* module_ = nullptr; std::string current_ep_name_; bool generating_entry_point_ = false; diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index 9da97e15a9..cd385c4a49 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -141,7 +141,7 @@ std::string expected_texture_overload( } // LINT - Ignore the length of this function class HlslGeneratorIntrinsicTextureTest - : public ast::BuilderWithContextAndModule, + : public ast::BuilderWithModule, public testing::TestWithParam { protected: void OnVariableBuilt(ast::Variable* var) override { @@ -154,9 +154,9 @@ class HlslGeneratorIntrinsicTextureTest std::string pre_result() const { return pre.str(); } /// The type determiner - TypeDeterminer td{ctx, mod}; + TypeDeterminer td{mod}; /// The generator - GeneratorImpl gen{ctx, mod}; + GeneratorImpl gen{mod}; /// The output stream std::ostringstream out; /// The pre-output stream diff --git a/src/writer/hlsl/test_helper.h b/src/writer/hlsl/test_helper.h index aea3938da5..7f5386c324 100644 --- a/src/writer/hlsl/test_helper.h +++ b/src/writer/hlsl/test_helper.h @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "src/ast/module.h" -#include "src/context.h" #include "src/type_determiner.h" #include "src/writer/hlsl/generator_impl.h" @@ -34,7 +33,7 @@ namespace hlsl { template class TestHelperBase : public BODY { public: - TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} + TestHelperBase() : td(&mod), gen(&mod) {} ~TestHelperBase() = default; /// @returns the result string @@ -52,8 +51,6 @@ class TestHelperBase : public BODY { return mod.create(std::forward(args)...); } - /// The context - Context ctx; /// The module ast::Module mod; /// The type determiner diff --git a/src/writer/msl/generator.cc b/src/writer/msl/generator.cc index 418735ee01..5a9e810319 100644 --- a/src/writer/msl/generator.cc +++ b/src/writer/msl/generator.cc @@ -22,17 +22,16 @@ namespace msl { Generator::Generator(ast::Module module) : Text(std::move(module)), - impl_(std::make_unique(ctx_, &module_)) {} + impl_(std::make_unique(&module_)) {} -Generator::Generator(Context* ctx, ast::Module module) - : Text(ctx, std::move(module)), - impl_(std::make_unique(ctx_, &module_)) {} +Generator::Generator(Context*, ast::Module module) + : Generator(std::move(module)) {} Generator::~Generator() = default; void Generator::Reset() { set_error(""); - impl_ = std::make_unique(ctx_, &module_); + impl_ = std::make_unique(&module_); } bool Generator::Generate() { diff --git a/src/writer/msl/generator.h b/src/writer/msl/generator.h index 19bf085b2d..96752230e2 100644 --- a/src/writer/msl/generator.h +++ b/src/writer/msl/generator.h @@ -29,10 +29,10 @@ namespace msl { class Generator : public Text { public: /// Constructor - /// DEPRECATED /// @param module the module to convert explicit Generator(ast::Module module); /// Constructor + /// DEPRECATED /// @param ctx the context object, must be non-null /// @param module the module to convert Generator(Context* ctx, ast::Module module); diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 6fa0c6a06e..003401f65b 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -95,8 +95,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) { } // namespace -GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module) - : TextGenerator(ctx), module_(module) {} +GeneratorImpl::GeneratorImpl(ast::Module* module) + : TextGenerator(), module_(module) {} GeneratorImpl::~GeneratorImpl() = default; diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index 111ce81c88..0e4ef7d2eb 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -54,9 +54,8 @@ namespace msl { class GeneratorImpl : public TextGenerator { public: /// Constructor - /// @param ctx the context, must be non-null /// @param module the module to generate - GeneratorImpl(Context* ctx, ast::Module* module); + explicit GeneratorImpl(ast::Module* module); ~GeneratorImpl(); /// @returns true on successful generation; false otherwise diff --git a/src/writer/msl/generator_impl_intrinsic_texture_test.cc b/src/writer/msl/generator_impl_intrinsic_texture_test.cc index f38e3aad62..d3ece25a20 100644 --- a/src/writer/msl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_texture_test.cc @@ -141,7 +141,7 @@ std::string expected_texture_overload( } // LINT - Ignore the length of this function class MslGeneratorIntrinsicTextureTest - : public ast::BuilderWithContextAndModule, + : public ast::BuilderWithModule, public testing::TestWithParam { protected: void OnVariableBuilt(ast::Variable* var) override { @@ -149,9 +149,9 @@ class MslGeneratorIntrinsicTextureTest } /// The type determiner - TypeDeterminer td{ctx, mod}; + TypeDeterminer td{mod}; /// The generator - GeneratorImpl gen{ctx, mod}; + GeneratorImpl gen{mod}; }; TEST_P(MslGeneratorIntrinsicTextureTest, Call) { diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h index b336a47ff0..853b51a20c 100644 --- a/src/writer/msl/test_helper.h +++ b/src/writer/msl/test_helper.h @@ -20,7 +20,6 @@ #include "gtest/gtest.h" #include "src/ast/module.h" -#include "src/context.h" #include "src/type_determiner.h" #include "src/writer/msl/generator_impl.h" @@ -32,7 +31,7 @@ namespace msl { template class TestHelperBase : public BASE { public: - TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} + TestHelperBase() : td(&mod), gen(&mod) {} ~TestHelperBase() = default; /// Creates a new `ast::Node` owned by the Module. When the Module is @@ -44,8 +43,6 @@ class TestHelperBase : public BASE { return mod.create(std::forward(args)...); } - /// The context - Context ctx; /// The module ast::Module mod; /// The type determiner diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 14f839888c..dd7e1c178e 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -277,10 +277,9 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {} Builder::AccessorInfo::~AccessorInfo() {} -Builder::Builder(Context* ctx, ast::Module* mod) - : ctx_(ctx), mod_(mod), scope_stack_({}) { - assert(ctx_); -} +Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {} + +Builder::Builder(Context*, ast::Module* mod) : Builder(mod) {} Builder::~Builder() = default; @@ -437,7 +436,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) { // the inspector and land the same change in MSL / HLSL to all roll into Dawn // at the same time. // OperandList operands = {Operand::Int(stage), Operand::Int(id), - // Operand::String(ctx_.namer()->NameFor(func->name()))}; + // Operand::String(func->name())}; OperandList operands = {Operand::Int(stage), Operand::Int(id), Operand::String(func->name())}; @@ -522,8 +521,7 @@ bool Builder::GenerateFunction(ast::Function* func) { auto func_id = func_op.to_i(); push_debug(spv::Op::OpName, - {Operand::Int(func_id), - Operand::String(ctx_->namer()->NameFor(func->name()))}); + {Operand::Int(func_id), Operand::String(func->name())}); auto ret_id = GenerateTypeIfNeeded(func->return_type()); if (ret_id == 0) { @@ -548,8 +546,7 @@ bool Builder::GenerateFunction(ast::Function* func) { } push_debug(spv::Op::OpName, - {Operand::Int(param_id), - Operand::String(ctx_->namer()->NameFor(param->name()))}); + {Operand::Int(param_id), Operand::String(param->name())}); params.push_back(Instruction{spv::Op::OpFunctionParameter, {Operand::Int(param_type_id), param_op}}); @@ -640,8 +637,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) { } push_debug(spv::Op::OpName, - {Operand::Int(var_id), - Operand::String(ctx_->namer()->NameFor(var->name()))}); + {Operand::Int(var_id), Operand::String(var->name())}); // TODO(dsinclair) We could detect if the constructor is fully const and emit // an initializer value for the variable instead of doing the OpLoad. @@ -689,8 +685,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { return false; } push_debug(spv::Op::OpName, - {Operand::Int(init_id), - Operand::String(ctx_->namer()->NameFor(var->name()))}); + {Operand::Int(init_id), Operand::String(var->name())}); scope_stack_.set_global(var->name(), init_id); spirv_id_to_variable_[init_id] = var; @@ -711,8 +706,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) { } push_debug(spv::Op::OpName, - {Operand::Int(var_id), - Operand::String(ctx_->namer()->NameFor(var->name()))}); + {Operand::Int(var_id), Operand::String(var->name())}); auto* type = var->type()->UnwrapAll(); @@ -2633,8 +2627,7 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type, if (!struct_type->name().empty()) { push_debug(spv::Op::OpName, - {Operand::Int(struct_id), - Operand::String(ctx_->namer()->NameFor(struct_type->name()))}); + {Operand::Int(struct_id), Operand::String(struct_type->name())}); } OperandList ops; @@ -2675,9 +2668,8 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type, uint32_t Builder::GenerateStructMember(uint32_t struct_id, uint32_t idx, ast::StructMember* member) { - push_debug(spv::Op::OpMemberName, - {Operand::Int(struct_id), Operand::Int(idx), - Operand::String(ctx_->namer()->NameFor(member->name()))}); + push_debug(spv::Op::OpMemberName, {Operand::Int(struct_id), Operand::Int(idx), + Operand::String(member->name())}); bool has_layout = false; for (auto* deco : member->decorations()) { diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index f32db1205f..57ca018e5a 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -83,6 +83,10 @@ class Builder { }; /// Constructor + /// @param mod the module to generate from + explicit Builder(ast::Module* mod); + /// Constructor + /// DEPRECATED /// @param ctx the context, must be non-null /// @param mod the module to generate from Builder(Context* ctx, ast::Module* mod); @@ -495,7 +499,6 @@ class Builder { return func_name_to_id_[name]; } - Context* ctx_ = nullptr; ast::Module* mod_; std::string error_; uint32_t next_id_ = 1; diff --git a/src/writer/spirv/builder_call_test.cc b/src/writer/spirv/builder_call_test.cc index 67447cf998..af7ec5bfde 100644 --- a/src/writer/spirv/builder_call_test.cc +++ b/src/writer/spirv/builder_call_test.cc @@ -74,10 +74,10 @@ TEST_F(BuilderTest, Expression_Call) { ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 14u) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" -OpName %4 "tint_61" -OpName %5 "tint_62" -OpName %12 "tint_6d61696e" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" +OpName %4 "a" +OpName %5 "b" +OpName %12 "main" %2 = OpTypeFloat 32 %1 = OpTypeFunction %2 %2 %2 %11 = OpTypeVoid @@ -136,10 +136,10 @@ TEST_F(BuilderTest, Statement_Call) { ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); EXPECT_TRUE(b.GenerateStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63" -OpName %5 "tint_61" -OpName %6 "tint_62" -OpName %12 "tint_6d61696e" + EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" +OpName %5 "a" +OpName %6 "b" +OpName %12 "main" %2 = OpTypeVoid %3 = OpTypeFloat 32 %1 = OpTypeFunction %2 %3 %3 diff --git a/src/writer/spirv/builder_function_decoration_test.cc b/src/writer/spirv/builder_function_decoration_test.cc index e7ad94a732..179432dc43 100644 --- a/src/writer/spirv/builder_function_decoration_test.cc +++ b/src/writer/spirv/builder_function_decoration_test.cc @@ -110,10 +110,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) { mod->AddGlobalVariable(v_wg); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e" -OpName %4 "tint_6d795f6f7574" -OpName %7 "tint_6d795f7767" -OpName %11 "tint_6d61696e" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" +OpName %4 "my_out" +OpName %7 "my_wg" +OpName %11 "main" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -173,10 +173,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) { mod->AddGlobalVariable(v_wg); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e" -OpName %4 "tint_6d795f6f7574" -OpName %7 "tint_6d795f7767" -OpName %11 "tint_6d61696e" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in" +OpName %4 "my_out" +OpName %7 "my_wg" +OpName %11 "main" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -252,8 +252,8 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) { OpEntryPoint Fragment %5 "main2" OpExecutionMode %3 OriginUpperLeft OpExecutionMode %5 OriginUpperLeft -OpName %3 "tint_6d61696e31" -OpName %5 "tint_6d61696e32" +OpName %3 "main1" +OpName %5 "main2" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index 9e195c2e28..d9fb3c88e9 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -52,7 +52,7 @@ TEST_F(BuilderTest, Function_Empty) { ast::Function func("a_func", {}, &void_type, create()); ASSERT_TRUE(b.GenerateFunction(&func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -71,7 +71,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) { ast::Function func("a_func", {}, &void_type, body); ASSERT_TRUE(b.GenerateFunction(&func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -97,8 +97,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) { ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a" +OpName %7 "a_func" %3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -122,7 +122,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) { ast::Function func("a_func", {}, &void_type, body); ASSERT_TRUE(b.GenerateFunction(&func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -155,9 +155,9 @@ TEST_F(BuilderTest, Function_WithParams) { EXPECT_TRUE(td.DetermineFunction(&func)); ASSERT_TRUE(b.GenerateFunction(&func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63" -OpName %5 "tint_61" -OpName %6 "tint_62" + EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" +OpName %5 "a" +OpName %6 "b" %2 = OpTypeFloat 32 %3 = OpTypeInt 32 1 %1 = OpTypeFunction %2 %2 %3 @@ -179,7 +179,7 @@ TEST_F(BuilderTest, Function_WithBody) { ast::Function func("a_func", {}, &void_type, body); ASSERT_TRUE(b.GenerateFunction(&func)); - EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %3 = OpFunction %2 None %1 @@ -302,13 +302,13 @@ OpEntryPoint GLCompute %7 "a" OpEntryPoint GLCompute %17 "b" OpExecutionMode %7 LocalSize 1 1 1 OpExecutionMode %17 LocalSize 1 1 1 -OpName %3 "tint_44617461" -OpMemberName %3 0 "tint_64" -OpName %1 "tint_64617461" -OpName %7 "tint_61" -OpName %14 "tint_76" -OpName %17 "tint_62" -OpName %21 "tint_76" +OpName %3 "Data" +OpMemberName %3 0 "d" +OpName %1 "data" +OpName %7 "a" +OpName %14 "v" +OpName %17 "b" +OpName %21 "v" OpDecorate %3 Block OpMemberDecorate %3 0 Offset 0 OpDecorate %1 Binding 0 diff --git a/src/writer/spirv/builder_function_variable_test.cc b/src/writer/spirv/builder_function_variable_test.cc index b28e73bf42..ebc092f3f5 100644 --- a/src/writer/spirv/builder_function_variable_test.cc +++ b/src/writer/spirv/builder_function_variable_test.cc @@ -52,7 +52,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Function %3 @@ -90,7 +90,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) { EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -135,7 +135,7 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) { EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 2 @@ -180,8 +180,8 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) { EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_76" -OpName %7 "tint_7632" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" +OpName %7 "v2" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 %2 = OpConstant %1 1 @@ -226,7 +226,7 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) { EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_76" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 %2 = OpConstant %1 1 diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 0b4782c654..da997b1102 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -56,7 +56,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) { ast::Variable v("var", ast::StorageClass::kNone, &f32); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 @@ -70,7 +70,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) { ast::Variable v("var", ast::StorageClass::kOutput, &f32); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Output %3 @@ -84,7 +84,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) { ast::Variable v("var", ast::StorageClass::kInput, &f32); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Input %3 @@ -115,7 +115,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) { EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -151,7 +151,7 @@ TEST_F(BuilderTest, GlobalVar_Const) { EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 @@ -249,7 +249,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) { dv.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5 )"); @@ -271,7 +271,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) { dv.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2 OpDecorate %1 DescriptorSet 3 @@ -294,7 +294,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) { dv.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position )"); @@ -318,7 +318,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) { create(&bool_type, true))); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 1200 )"); @@ -340,7 +340,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) { v.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200 )"); @@ -364,7 +364,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) { create(&f32, 2.0))); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 0 )"); @@ -386,7 +386,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) { v.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -408,7 +408,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) { v.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -430,7 +430,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) { v.set_decorations(decos); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0 )"); @@ -498,10 +498,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable OpMemberDecorate %3 1 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" -OpMemberName %3 0 "tint_61" -OpMemberName %3 1 "tint_62" -OpName %1 "tint_62" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" +OpMemberName %3 0 "a" +OpMemberName %3 1 "b" +OpName %1 "b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 %4 @@ -533,9 +533,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" -OpMemberName %3 0 "tint_61" -OpName %1 "tint_62" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" +OpMemberName %3 0 "a" +OpName %1 "b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 @@ -567,9 +567,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" -OpMemberName %3 0 "tint_61" -OpName %1 "tint_62" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" +OpMemberName %3 0 "a" +OpName %1 "b" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 @@ -603,12 +603,12 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) { EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" -OpMemberName %3 0 "tint_61" -OpName %1 "tint_62" -OpName %7 "tint_41" -OpMemberName %7 0 "tint_61" -OpName %5 "tint_63" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A" +OpMemberName %3 0 "a" +OpName %1 "b" +OpName %7 "A" +OpMemberName %7 0 "a" +OpName %5 "c" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 %3 = OpTypeStruct %4 diff --git a/src/writer/spirv/builder_ident_expression_test.cc b/src/writer/spirv/builder_ident_expression_test.cc index 7be7907d8c..dd6b7e428c 100644 --- a/src/writer/spirv/builder_ident_expression_test.cc +++ b/src/writer/spirv/builder_ident_expression_test.cc @@ -84,7 +84,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Output %3 @@ -141,7 +141,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) { b.push_function(Function{}); EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 %2 = OpTypePointer Function %3 diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index 2f9c33dab2..37f18a9460 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -52,15 +52,15 @@ namespace writer { namespace spirv { namespace { -class IntrinsicBuilderTest : public ast::BuilderWithContextAndModule, +class IntrinsicBuilderTest : public ast::BuilderWithModule, public testing::Test { protected: void OnVariableBuilt(ast::Variable* var) override { td.RegisterVariableForTesting(var); } - TypeDeterminer td{ctx, mod}; - spirv::Builder b{ctx, mod}; + TypeDeterminer td{mod}; + spirv::Builder b{mod}; }; template @@ -646,8 +646,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) { EXPECT_EQ(b.GenerateCallExpression(&expr), 9u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450" -OpName %1 "tint_6964656e74" -OpName %7 "tint_615f66756e63" +OpName %1 "ident" +OpName %7 "a_func" %3 = OpTypeFloat 32 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -677,7 +677,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -703,7 +703,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -755,7 +755,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -778,7 +778,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -803,7 +803,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -833,7 +833,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -860,7 +860,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -895,7 +895,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -919,7 +919,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -946,7 +946,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -975,7 +975,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeFloat 32 @@ -1003,7 +1003,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeFloat 32 @@ -1042,7 +1042,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -1068,7 +1068,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -1101,7 +1101,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -1127,7 +1127,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1160,7 +1160,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -1186,7 +1186,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -1220,7 +1220,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -1246,7 +1246,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1280,7 +1280,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 1 @@ -1308,7 +1308,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 1 @@ -1341,7 +1341,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %6 = OpTypeInt 32 0 @@ -1369,7 +1369,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) { EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" +OpName %3 "a_func" %2 = OpTypeVoid %1 = OpTypeFunction %2 %7 = OpTypeInt 32 0 @@ -1402,8 +1402,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) { EXPECT_EQ(b.GenerateCallExpression(&expr), 11u) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450" -OpName %3 "tint_615f66756e63" -OpName %5 "tint_766172" +OpName %3 "a_func" +OpName %5 "var" %2 = OpTypeVoid %1 = OpTypeFunction %2 %9 = OpTypeFloat 32 diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index f5c8c064fc..c065cfc76e 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -1491,15 +1491,15 @@ expected_texture_overload_spirv expected_texture_overload( } // NOLINT - Ignore the length of this function class IntrinsicTextureTest - : public ast::BuilderWithContextAndModule, + : public ast::BuilderWithModule, public testing::TestWithParam { protected: void OnVariableBuilt(ast::Variable* var) override { td.RegisterVariableForTesting(var); } - TypeDeterminer td{ctx, mod}; - spirv::Builder b{ctx, mod}; + TypeDeterminer td{mod}; + spirv::Builder b{mod}; }; INSTANTIATE_TEST_SUITE_P( diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index 25158f3669..fb99a2ad68 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -116,9 +116,9 @@ TEST_F(BuilderTest, Switch_WithCase) { EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" -OpName %5 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" +OpName %5 "a" +OpName %7 "a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -180,9 +180,9 @@ TEST_F(BuilderTest, Switch_WithDefault) { EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" -OpName %5 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" +OpName %5 "a" +OpName %7 "a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -263,9 +263,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) { EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" -OpName %5 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" +OpName %5 "a" +OpName %7 "a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -355,9 +355,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) { EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" -OpName %5 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" +OpName %5 "a" +OpName %7 "a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 @@ -477,9 +477,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) { EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); - EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" -OpName %5 "tint_61" -OpName %7 "tint_615f66756e63" + EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v" +OpName %5 "a" +OpName %7 "a_func" %3 = OpTypeInt 32 1 %2 = OpTypePointer Private %3 %4 = OpConstantNull %3 diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 219fbe1f16..0a1c20060b 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -287,7 +287,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) { EXPECT_EQ(id, 1u); EXPECT_EQ(b.types().size(), 1u); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" )"); EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct )"); @@ -310,8 +310,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374" -OpMemberName %1 0 "tint_61" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" +OpMemberName %1 0 "a" )"); } @@ -335,8 +335,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374" -OpMemberName %1 0 "tint_61" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct" +OpMemberName %1 0 "a" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block )"); @@ -364,9 +364,9 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeStruct %2 %2 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" -OpMemberName %1 0 "tint_61" -OpMemberName %1 1 "tint_62" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" +OpMemberName %1 1 "b" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 1 Offset 8 @@ -404,10 +404,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" -OpMemberName %1 0 "tint_61" -OpMemberName %1 1 "tint_62" -OpMemberName %1 2 "tint_63" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" +OpMemberName %1 1 "b" +OpMemberName %1 2 "c" )"); EXPECT_EQ(DumpInstructions(b.annots()), ""); } @@ -447,10 +447,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" -OpMemberName %1 0 "tint_61" -OpMemberName %1 1 "tint_62" -OpMemberName %1 2 "tint_63" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" +OpMemberName %1 1 "b" +OpMemberName %1 2 "c" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 0 ColMajor @@ -508,10 +508,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) { %7 = OpTypeMatrix %8 4 %1 = OpTypeStruct %2 %5 %7 )"); - EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" -OpMemberName %1 0 "tint_61" -OpMemberName %1 1 "tint_62" -OpMemberName %1 2 "tint_63" + EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S" +OpMemberName %1 0 "a" +OpMemberName %1 1 "b" +OpMemberName %1 2 "c" )"); EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 OpMemberDecorate %1 0 ColMajor diff --git a/src/writer/spirv/generator.cc b/src/writer/spirv/generator.cc index 495ddd0710..1fac75e60c 100644 --- a/src/writer/spirv/generator.cc +++ b/src/writer/spirv/generator.cc @@ -22,18 +22,16 @@ namespace spirv { Generator::Generator(ast::Module module) : writer::Writer(std::move(module)), - builder_(std::make_unique(ctx_, &module_)), + builder_(std::make_unique(&module_)), writer_(std::make_unique()) {} -Generator::Generator(Context* ctx, ast::Module module) - : writer::Writer(ctx, std::move(module)), - builder_(std::make_unique(ctx, &module_)), - writer_(std::make_unique()) {} +Generator::Generator(Context*, ast::Module module) + : Generator(std::move(module)) {} Generator::~Generator() = default; void Generator::Reset() { - builder_ = std::make_unique(ctx_, &module_); + builder_ = std::make_unique(&module_); writer_ = std::make_unique(); } diff --git a/src/writer/spirv/generator.h b/src/writer/spirv/generator.h index 968796961c..97825ebc7f 100644 --- a/src/writer/spirv/generator.h +++ b/src/writer/spirv/generator.h @@ -32,10 +32,10 @@ namespace spirv { class Generator : public writer::Writer { public: /// Constructor - /// DEPRECATED /// @param module the module to convert explicit Generator(ast::Module module); /// Constructor + /// DEPRECATED /// @param ctx the context, must be non-null /// @param module the module to convert Generator(Context* ctx, ast::Module module); diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h index c8194b4edd..cbc3d0e4a9 100644 --- a/src/writer/spirv/test_helper.h +++ b/src/writer/spirv/test_helper.h @@ -21,7 +21,6 @@ #include "gtest/gtest.h" #include "src/ast/builder.h" #include "src/ast/module.h" -#include "src/context.h" #include "src/type_determiner.h" #include "src/writer/spirv/builder.h" @@ -31,9 +30,9 @@ namespace spirv { /// Helper class for testing template -class TestHelperBase : public ast::BuilderWithContextAndModule, public BASE { +class TestHelperBase : public ast::BuilderWithModule, public BASE { public: - TestHelperBase() : td(ctx, mod), b(ctx, mod) {} + TestHelperBase() : td(mod), b(mod) {} ~TestHelperBase() override = default; /// The type determiner diff --git a/src/writer/text.cc b/src/writer/text.cc index 52929cc353..319f32eb1e 100644 --- a/src/writer/text.cc +++ b/src/writer/text.cc @@ -21,8 +21,6 @@ namespace writer { Text::Text(ast::Module module) : Writer(std::move(module)) {} -Text::Text(Context* ctx, ast::Module module) : Writer(ctx, std::move(module)) {} - Text::~Text() = default; } // namespace writer diff --git a/src/writer/text.h b/src/writer/text.h index 5f7bb1cd91..7e4fffc05b 100644 --- a/src/writer/text.h +++ b/src/writer/text.h @@ -26,13 +26,8 @@ namespace writer { class Text : public Writer { public: /// Constructor - /// DEPRECATED /// @param module the module to convert explicit Text(ast::Module module); - /// Constructor - /// @param ctx the context object, must be non-null - /// @param module the module to convert - Text(Context* ctx, ast::Module module); ~Text() override; /// @returns the result data diff --git a/src/writer/text_generator.cc b/src/writer/text_generator.cc index 52f60e85eb..e057abe3ca 100644 --- a/src/writer/text_generator.cc +++ b/src/writer/text_generator.cc @@ -21,9 +21,7 @@ namespace tint { namespace writer { -TextGenerator::TextGenerator(Context* ctx) : ctx_(ctx) { - assert(ctx_); -} +TextGenerator::TextGenerator() = default; TextGenerator::~TextGenerator() = default; diff --git a/src/writer/text_generator.h b/src/writer/text_generator.h index d38d3edb12..46da1bcdfe 100644 --- a/src/writer/text_generator.h +++ b/src/writer/text_generator.h @@ -18,8 +18,6 @@ #include #include -#include "src/context.h" - namespace tint { namespace writer { @@ -27,8 +25,7 @@ namespace writer { class TextGenerator { public: /// Constructor - /// @param ctx the context object, must be non-null - explicit TextGenerator(Context* ctx); + TextGenerator(); ~TextGenerator(); /// Increment the emitter indent level @@ -52,8 +49,6 @@ class TextGenerator { std::string error() const { return error_; } protected: - /// The context - Context* ctx_ = nullptr; /// The text output stream std::ostringstream out_; /// Error generated by the generator diff --git a/src/writer/wgsl/generator.cc b/src/writer/wgsl/generator.cc index 93816edaa8..c96cafdeca 100644 --- a/src/writer/wgsl/generator.cc +++ b/src/writer/wgsl/generator.cc @@ -21,17 +21,16 @@ namespace writer { namespace wgsl { Generator::Generator(ast::Module module) - : Text(std::move(module)), impl_(std::make_unique(ctx_)) {} + : Text(std::move(module)), impl_(std::make_unique()) {} -Generator::Generator(Context* ctx, ast::Module module) - : Text(ctx, std::move(module)), - impl_(std::make_unique(ctx_)) {} +Generator::Generator(Context*, ast::Module module) + : Generator(std::move(module)) {} Generator::~Generator() = default; void Generator::Reset() { set_error(""); - impl_ = std::make_unique(ctx_); + impl_ = std::make_unique(); } bool Generator::Generate() { diff --git a/src/writer/wgsl/generator.h b/src/writer/wgsl/generator.h index 685f7cf8c3..e269ec949d 100644 --- a/src/writer/wgsl/generator.h +++ b/src/writer/wgsl/generator.h @@ -29,10 +29,10 @@ namespace wgsl { class Generator : public Text { public: /// Constructor - /// DEPRECATED /// @param module the module to convert explicit Generator(ast::Module module); /// Constructor + /// DEPRECATED /// @param ctx the context, must be non-null /// @param module the module to convert Generator(Context* ctx, ast::Module module); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 24d51a0788..1257e7b380 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -78,7 +78,7 @@ namespace tint { namespace writer { namespace wgsl { -GeneratorImpl::GeneratorImpl(Context* ctx) : TextGenerator(ctx) {} +GeneratorImpl::GeneratorImpl() : TextGenerator() {} GeneratorImpl::~GeneratorImpl() = default; diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index 3bc921a191..ba0544fef5 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -54,8 +54,7 @@ namespace wgsl { class GeneratorImpl : public TextGenerator { public: /// Constructor - /// @param ctx the context, must be non-null - explicit GeneratorImpl(Context* ctx); + GeneratorImpl(); ~GeneratorImpl(); /// Generates the result data diff --git a/src/writer/wgsl/test_helper.h b/src/writer/wgsl/test_helper.h index 57b14ce502..4b8055eaba 100644 --- a/src/writer/wgsl/test_helper.h +++ b/src/writer/wgsl/test_helper.h @@ -20,7 +20,6 @@ #include "gtest/gtest.h" #include "src/ast/module.h" -#include "src/context.h" #include "src/type_determiner.h" #include "src/writer/wgsl/generator_impl.h" @@ -32,7 +31,7 @@ namespace wgsl { template class TestHelperBase : public BASE { public: - TestHelperBase() : td(&ctx, &mod), gen(&ctx) {} + TestHelperBase() : td(&mod), gen() {} ~TestHelperBase() = default; @@ -45,8 +44,6 @@ class TestHelperBase : public BASE { return mod.create(std::forward(args)...); } - /// The context - Context ctx; /// The module ast::Module mod; /// The type determiner diff --git a/src/writer/writer.cc b/src/writer/writer.cc index c41b5561bc..545ed3b372 100644 --- a/src/writer/writer.cc +++ b/src/writer/writer.cc @@ -19,18 +19,9 @@ namespace tint { namespace writer { -Writer::Writer(ast::Module module) - : ctx_(new Context()), - context_is_owned_(true), - module_(std::move(module)) {} +Writer::Writer(ast::Module module) : module_(std::move(module)) {} -Writer::Writer(Context* ctx, ast::Module module) - : ctx_(ctx), context_is_owned_(false), module_(std::move(module)) {} - -Writer::~Writer() { - if (context_is_owned_) - delete ctx_; -} +Writer::~Writer() = default; } // namespace writer } // namespace tint diff --git a/src/writer/writer.h b/src/writer/writer.h index 3caf73edd1..46d88014cb 100644 --- a/src/writer/writer.h +++ b/src/writer/writer.h @@ -50,25 +50,15 @@ class Writer { protected: /// Constructor - /// DEPRECATED /// @param module the tint module to convert explicit Writer(ast::Module module); - /// Constructor - /// @param ctx the context object, must be non-null - /// @param module the tint module to convert - Writer(Context* ctx, ast::Module module); - /// Sets the error string /// @param msg the error message void set_error(const std::string& msg) { error_ = msg; } /// An error message, if an error was encountered std::string error_; - /// The context - Context* ctx_ = nullptr; - /// Tracks if we own the context - bool context_is_owned_ = false; /// The module being converted ast::Module module_; };