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 <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-12-02 21:17:58 +00:00 committed by Commit Bot service account
parent 573d8939f4
commit 685cb02ea8
73 changed files with 362 additions and 420 deletions

View File

@ -47,8 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::Source::File file("test.wgsl", str); tint::Source::File file("test.wgsl", str);
// Parse the wgsl, create the src module // Parse the wgsl, create the src module
tint::Context ctx; tint::reader::wgsl::ParserImpl parser(&file);
tint::reader::wgsl::ParserImpl parser(&ctx, &file);
parser.set_max_errors(1); parser.set_max_errors(1);
if (!parser.Parse()) { if (!parser.Parse()) {
return 0; return 0;

View File

@ -22,8 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::vector<uint32_t> input(u32Data, u32Data + sizeInU32); std::vector<uint32_t> input(u32Data, u32Data + sizeInU32);
if (input.size() != 0) { if (input.size() != 0) {
tint::Context ctx; tint::reader::spirv::Parser parser(input);
tint::reader::spirv::Parser parser(&ctx, input);
parser.Parse(); parser.Parse();
} }

View File

@ -20,9 +20,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::string str(reinterpret_cast<const char*>(data), size); std::string str(reinterpret_cast<const char*>(data), size);
tint::Source::File file("test.wgsl", str); tint::Source::File file("test.wgsl", str);
tint::reader::wgsl::Parser parser(&file);
tint::Context ctx;
tint::reader::wgsl::Parser parser(&ctx, &file);
parser.Parse(); parser.Parse();
return 0; return 0;

View File

@ -418,8 +418,6 @@ int main(int argc, const char** argv) {
options.format = Format::kSpvAsm; options.format = Format::kSpvAsm;
} }
tint::Context ctx(std::make_unique<tint::NoopNamer>());
auto diag_printer = tint::diag::Printer::create(stderr, true); auto diag_printer = tint::diag::Printer::create(stderr, true);
tint::diag::Formatter diag_formatter; tint::diag::Formatter diag_formatter;
@ -435,8 +433,7 @@ int main(int argc, const char** argv) {
} }
source_file = std::make_unique<tint::Source::File>( source_file = std::make_unique<tint::Source::File>(
options.input_filename, std::string(data.begin(), data.end())); options.input_filename, std::string(data.begin(), data.end()));
reader = reader = std::make_unique<tint::reader::wgsl::Parser>(source_file.get());
std::make_unique<tint::reader::wgsl::Parser>(&ctx, source_file.get());
} }
#endif // TINT_BUILD_WGSL_READER #endif // TINT_BUILD_WGSL_READER
@ -449,7 +446,7 @@ int main(int argc, const char** argv) {
if (!ReadFile<uint32_t>(options.input_filename, &data)) { if (!ReadFile<uint32_t>(options.input_filename, &data)) {
return 1; return 1;
} }
reader = std::make_unique<tint::reader::spirv::Parser>(&ctx, data); reader = std::make_unique<tint::reader::spirv::Parser>(data);
} }
// Handle SPIR-V assembly input, in files ending with .spvasm // Handle SPIR-V assembly input, in files ending with .spvasm
if (options.input_filename.size() > 7 && 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)) { SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS)) {
return 1; return 1;
} }
reader = std::make_unique<tint::reader::spirv::Parser>(&ctx, data); reader = std::make_unique<tint::reader::spirv::Parser>(data);
} }
#endif // TINT_BUILD_SPV_READER #endif // TINT_BUILD_SPV_READER
@ -490,7 +487,7 @@ int main(int argc, const char** argv) {
return 1; return 1;
} }
tint::TypeDeterminer td(&ctx, &mod); tint::TypeDeterminer td(&mod);
if (!td.Determine()) { if (!td.Determine()) {
std::cerr << "Type Determination: " << td.error() << std::endl; std::cerr << "Type Determination: " << td.error() << std::endl;
return 1; return 1;
@ -509,7 +506,7 @@ int main(int argc, const char** argv) {
return 1; return 1;
} }
tint::transform::Manager transform_manager(&ctx, &mod); tint::transform::Manager transform_manager;
for (const auto& name : options.transforms) { for (const auto& name : options.transforms) {
// TODO(dsinclair): The vertex pulling transform requires setup code to // 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 // 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") { if (name == "bound_array_accessors") {
transform_manager.append( transform_manager.append(
std::make_unique<tint::transform::BoundArrayAccessorsTransform>( std::make_unique<tint::transform::BoundArrayAccessorsTransform>(
&ctx, &mod)); &mod));
} else { } else {
std::cerr << "Unknown transform name: " << name << std::endl; std::cerr << "Unknown transform name: " << name << std::endl;
return 1; return 1;
} }
} }
if (!transform_manager.Run()) { if (!transform_manager.Run(&mod)) {
std::cerr << "Transformer: " << transform_manager.error() << std::endl; std::cerr << "Transformer: " << transform_manager.error() << std::endl;
return 1; return 1;
} }
@ -533,29 +530,25 @@ int main(int argc, const char** argv) {
#if TINT_BUILD_SPV_WRITER #if TINT_BUILD_SPV_WRITER
if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) { if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) {
writer = writer = std::make_unique<tint::writer::spirv::Generator>(std::move(mod));
std::make_unique<tint::writer::spirv::Generator>(&ctx, std::move(mod));
} }
#endif // TINT_BUILD_SPV_WRITER #endif // TINT_BUILD_SPV_WRITER
#if TINT_BUILD_WGSL_WRITER #if TINT_BUILD_WGSL_WRITER
if (options.format == Format::kWgsl) { if (options.format == Format::kWgsl) {
writer = writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(mod));
std::make_unique<tint::writer::wgsl::Generator>(&ctx, std::move(mod));
} }
#endif // TINT_BUILD_WGSL_WRITER #endif // TINT_BUILD_WGSL_WRITER
#if TINT_BUILD_MSL_WRITER #if TINT_BUILD_MSL_WRITER
if (options.format == Format::kMsl) { if (options.format == Format::kMsl) {
writer = writer = std::make_unique<tint::writer::msl::Generator>(std::move(mod));
std::make_unique<tint::writer::msl::Generator>(&ctx, std::move(mod));
} }
#endif // TINT_BUILD_MSL_WRITER #endif // TINT_BUILD_MSL_WRITER
#if TINT_BUILD_HLSL_WRITER #if TINT_BUILD_HLSL_WRITER
if (options.format == Format::kHlsl) { if (options.format == Format::kHlsl) {
writer = writer = std::make_unique<tint::writer::hlsl::Generator>(std::move(mod));
std::make_unique<tint::writer::hlsl::Generator>(&ctx, std::move(mod));
} }
#endif // TINT_BUILD_HLSL_WRITER #endif // TINT_BUILD_HLSL_WRITER

View File

@ -25,7 +25,8 @@ TypesBuilder::TypesBuilder(Module* mod)
void_(mod->create<type::Void>()), void_(mod->create<type::Void>()),
mod_(mod) {} 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; Builder::~Builder() = default;
Variable* Builder::Var(const std::string& name, Variable* Builder::Var(const std::string& name,
@ -36,10 +37,9 @@ Variable* Builder::Var(const std::string& name,
return var; return var;
} }
BuilderWithContextAndModule::BuilderWithContextAndModule() BuilderWithModule::BuilderWithModule() : Builder(new Module()) {}
: Builder(new Context(), new Module()) {}
BuilderWithContextAndModule::~BuilderWithContextAndModule() { BuilderWithModule::~BuilderWithModule() {
delete ctx;
delete mod; delete mod;
} }

View File

@ -38,7 +38,6 @@
#include "src/ast/type_constructor_expression.h" #include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h" #include "src/ast/uint_literal.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/context.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -186,9 +185,8 @@ class Builder {
using f32 = float; using f32 = float;
/// Constructor /// Constructor
/// @param ctx the context to use in the builder
/// @param mod the module 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(); virtual ~Builder();
/// @param expr the expression /// @param expr the expression
@ -443,8 +441,6 @@ class Builder {
return mod->create<T>(std::forward<ARGS>(args)...); return mod->create<T>(std::forward<ARGS>(args)...);
} }
/// The builder module
Context* const ctx;
/// The builder module /// The builder module
Module* const mod; Module* const mod;
/// The builder types /// The builder types
@ -455,12 +451,11 @@ class Builder {
virtual void OnVariableBuilt(Variable*) {} virtual void OnVariableBuilt(Variable*) {}
}; };
/// BuilderWithContextAndModule is a `Builder` that constructs and owns its /// BuilderWithModule is a `Builder` that constructs and owns its `Module`.
/// `Context` and `Module`. class BuilderWithModule : public Builder {
class BuilderWithContextAndModule : public Builder {
public: public:
BuilderWithContextAndModule(); BuilderWithModule();
~BuilderWithContextAndModule() override; ~BuilderWithModule() override;
}; };
//! @cond Doxygen_Suppress //! @cond Doxygen_Suppress

View File

@ -21,9 +21,9 @@
namespace tint { namespace tint {
Context::Context() : namer_(std::make_unique<HashingNamer>()) {} Context::Context() = default;
Context::Context(std::unique_ptr<Namer> namer) : namer_(std::move(namer)) {} Context::Context(std::unique_ptr<Namer>) {}
Context::~Context() = default; Context::~Context() = default;

View File

@ -41,12 +41,6 @@ class Context {
explicit Context(std::unique_ptr<Namer> namer); explicit Context(std::unique_ptr<Namer> namer);
/// Destructor /// Destructor
~Context(); ~Context();
/// @returns the namer object
Namer* namer() const { return namer_.get(); }
private:
std::unique_ptr<Namer> namer_;
}; };
} // namespace tint } // namespace tint

View File

@ -43,18 +43,12 @@
namespace tint { namespace tint {
namespace inspector { namespace inspector {
Inspector::Inspector(const ast::Module& module) Inspector::Inspector(const ast::Module& module) : module_(module) {}
: ctx_(new Context()), context_is_owned_(true), module_(module) {}
Inspector::Inspector(Context* ctx, const ast::Module& module) Inspector::Inspector(Context*, const ast::Module& module)
: ctx_(ctx), context_is_owned_(false), module_(module) { : Inspector(std::move(module)) {}
assert(ctx);
}
Inspector::~Inspector() { Inspector::~Inspector() = default;
if (context_is_owned_)
delete ctx_;
}
std::vector<EntryPoint> Inspector::GetEntryPoints() { std::vector<EntryPoint> Inspector::GetEntryPoints() {
std::vector<EntryPoint> result; std::vector<EntryPoint> result;
@ -66,7 +60,7 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
EntryPoint entry_point; EntryPoint entry_point;
entry_point.name = func->name(); 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(); entry_point.stage = func->pipeline_stage();
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y, std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
entry_point.workgroup_size_z) = func->workgroup_size(); entry_point.workgroup_size_z) = func->workgroup_size();
@ -93,7 +87,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
// if (!func) { // if (!func) {
// return {}; // return {};
// } // }
// return ctx_->namer()->NameFor(entry_point); // return func->name();
return entry_point; return entry_point;
} }

View File

@ -72,10 +72,10 @@ struct ResourceBinding {
class Inspector { class Inspector {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module Shader module to extract information from. /// @param module Shader module to extract information from.
explicit Inspector(const ast::Module& module); explicit Inspector(const ast::Module& module);
/// Constructor /// Constructor
/// DEPRECATED
/// @param ctx the context, must be non-null /// @param ctx the context, must be non-null
/// @param module Shader module to extract information from. /// @param module Shader module to extract information from.
Inspector(Context* ctx, const ast::Module& module); Inspector(Context* ctx, const ast::Module& module);
@ -133,8 +133,6 @@ class Inspector {
const std::string& entry_point); const std::string& entry_point);
private: private:
Context* ctx_ = nullptr;
bool context_is_owned_ = false;
const ast::Module& module_; const ast::Module& module_;
std::string error_; std::string error_;

View File

@ -59,7 +59,6 @@
#include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h" #include "src/ast/variable_decoration.h"
#include "src/ast/workgroup_decoration.h" #include "src/ast/workgroup_decoration.h"
#include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "tint/tint.h" #include "tint/tint.h"
@ -70,7 +69,7 @@ namespace {
class InspectorHelper { class InspectorHelper {
public: public:
InspectorHelper() InspectorHelper()
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)), : td_(std::make_unique<TypeDeterminer>(&mod_)),
inspector_(std::make_unique<Inspector>(mod_)), inspector_(std::make_unique<Inspector>(mod_)),
sampler_type_(ast::type::SamplerKind::kSampler), sampler_type_(ast::type::SamplerKind::kSampler),
comparison_sampler_type_(ast::type::SamplerKind::kComparisonSampler) {} comparison_sampler_type_(ast::type::SamplerKind::kComparisonSampler) {}
@ -683,7 +682,6 @@ class InspectorHelper {
} }
private: private:
Context ctx_;
ast::Module mod_; ast::Module mod_;
std::unique_ptr<TypeDeterminer> td_; std::unique_ptr<TypeDeterminer> td_;
std::unique_ptr<Inspector> inspector_; std::unique_ptr<Inspector> inspector_;
@ -771,12 +769,14 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(foo); mod()->AddFunction(foo);
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(1u, result.size()); ASSERT_EQ(1u, result.size());
EXPECT_EQ("foo", result[0].name); 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(ast::PipelineStage::kVertex, result[0].stage);
} }
@ -791,15 +791,17 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
mod()->AddFunction(bar); mod()->AddFunction(bar);
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(2u, result.size()); ASSERT_EQ(2u, result.size());
EXPECT_EQ("foo", result[0].name); 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(ast::PipelineStage::kVertex, result[0].stage);
EXPECT_EQ("bar", result[1].name); 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); EXPECT_EQ(ast::PipelineStage::kCompute, result[1].stage);
} }
@ -817,15 +819,17 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(bar); mod()->AddFunction(bar);
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
EXPECT_FALSE(inspector()->has_error()); EXPECT_FALSE(inspector()->has_error());
ASSERT_EQ(2u, result.size()); ASSERT_EQ(2u, result.size());
EXPECT_EQ("foo", result[0].name); 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(ast::PipelineStage::kVertex, result[0].stage);
EXPECT_EQ("bar", result[1].name); 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); EXPECT_EQ(ast::PipelineStage::kFragment, result[1].stage);
} }
@ -1017,20 +1021,22 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(2u, result.size()); ASSERT_EQ(2u, result.size());
ASSERT_EQ("foo", result[0].name); 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()); ASSERT_EQ(1u, result[0].input_variables.size());
EXPECT_EQ("in_var", result[0].input_variables[0]); EXPECT_EQ("in_var", result[0].input_variables[0]);
ASSERT_EQ(1u, result[0].output_variables.size()); ASSERT_EQ(1u, result[0].output_variables.size());
EXPECT_EQ("out2_var", result[0].output_variables[0]); EXPECT_EQ("out2_var", result[0].output_variables[0]);
ASSERT_EQ("bar", result[1].name); 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()); ASSERT_EQ(1u, result[1].input_variables.size());
EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ("in2_var", result[1].input_variables[0]);
ASSERT_EQ(1u, result[1].output_variables.size()); ASSERT_EQ(1u, result[1].output_variables.size());
@ -1056,13 +1062,15 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetEntryPoints(); auto result = inspector()->GetEntryPoints();
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
ASSERT_EQ(2u, result.size()); ASSERT_EQ(2u, result.size());
ASSERT_EQ("foo", result[0].name); 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_EQ(2u, result[0].input_variables.size());
EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var")); EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var"));
EXPECT_TRUE(ContainsString(result[0].input_variables, "in2_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")); EXPECT_TRUE(ContainsString(result[0].output_variables, "out2_var"));
ASSERT_EQ("bar", result[1].name); 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(1u, result[1].input_variables.size());
EXPECT_EQ("in2_var", result[1].input_variables[0]); EXPECT_EQ("in2_var", result[1].input_variables[0]);
EXPECT_EQ(1u, result[1].output_variables.size()); EXPECT_EQ(1u, result[1].output_variables.size());
@ -1106,10 +1114,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(foo); mod()->AddFunction(foo);
// TODO(dsinclair): Update to run the namer transform when available.
auto result = inspector()->GetRemappedNameForEntryPoint("foo"); auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); 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 // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
@ -1121,6 +1131,8 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(foo); mod()->AddFunction(foo);
// TODO(dsinclair): Update to run the namer transform when available.
auto* bar = MakeEmptyBodyFunction("bar"); auto* bar = MakeEmptyBodyFunction("bar");
bar->add_decoration( bar->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
@ -1129,12 +1141,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
{ {
auto result = inspector()->GetRemappedNameForEntryPoint("foo"); auto result = inspector()->GetRemappedNameForEntryPoint("foo");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
EXPECT_EQ("tint_666f6f", result); EXPECT_EQ("foo", result);
} }
{ {
auto result = inspector()->GetRemappedNameForEntryPoint("bar"); auto result = inspector()->GetRemappedNameForEntryPoint("bar");
ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
EXPECT_EQ("tint_626172", result); EXPECT_EQ("bar", result);
} }
} }

View File

@ -17,7 +17,7 @@
namespace tint { namespace tint {
namespace reader { namespace reader {
Reader::Reader(Context* ctx) : ctx_(*ctx) {} Reader::Reader() = default;
Reader::~Reader() = default; Reader::~Reader() = default;

View File

@ -19,7 +19,6 @@
#include <utility> #include <utility>
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h"
#include "src/diagnostic/diagnostic.h" #include "src/diagnostic/diagnostic.h"
#include "src/diagnostic/formatter.h" #include "src/diagnostic/formatter.h"
@ -52,16 +51,12 @@ class Reader {
protected: protected:
/// Constructor /// Constructor
/// @param ctx the context object, must be non-null Reader();
explicit Reader(Context* ctx);
/// Sets the diagnostic messages /// Sets the diagnostic messages
/// @param diags the list of diagnostic messages /// @param diags the list of diagnostic messages
void set_diagnostics(const diag::List& diags) { diags_ = diags; } void set_diagnostics(const diag::List& diags) { diags_ = diags; }
/// The Tint context object
Context& ctx_;
/// All diagnostic messages from the reader. /// All diagnostic messages from the reader.
diag::List diags_; diag::List diags_;
}; };

View File

@ -20,8 +20,11 @@ namespace tint {
namespace reader { namespace reader {
namespace spirv { namespace spirv {
Parser::Parser(Context* ctx, const std::vector<uint32_t>& spv_binary) Parser::Parser(const std::vector<uint32_t>& spv_binary)
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, spv_binary)) {} : Reader(), impl_(std::make_unique<ParserImpl>(spv_binary)) {}
Parser::Parser(Context*, const std::vector<uint32_t>& spv_binary)
: Parser(spv_binary) {}
Parser::~Parser() = default; Parser::~Parser() = default;

View File

@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "src/context.h"
#include "src/reader/reader.h" #include "src/reader/reader.h"
namespace tint { namespace tint {
@ -31,6 +32,10 @@ class ParserImpl;
class Parser : public Reader { class Parser : public Reader {
public: public:
/// Creates a new parser /// Creates a new parser
/// @param input the input data to parse
explicit Parser(const std::vector<uint32_t>& input);
/// Creates a new parser
/// DEPRECATED
/// @param ctx the non-null context object /// @param ctx the non-null context object
/// @param input the input data to parse /// @param input the input data to parse
Parser(Context* ctx, const std::vector<uint32_t>& input); Parser(Context* ctx, const std::vector<uint32_t>& input);

View File

@ -192,8 +192,8 @@ bool AssumesResultSignednessMatchesBinaryFirstOperand(SpvOp opcode) {
} // namespace } // namespace
ParserImpl::ParserImpl(Context* ctx, const std::vector<uint32_t>& spv_binary) ParserImpl::ParserImpl(const std::vector<uint32_t>& spv_binary)
: Reader(ctx), : Reader(),
spv_binary_(spv_binary), spv_binary_(spv_binary),
fail_stream_(&success_, &errors_), fail_stream_(&success_, &errors_),
bool_type_(ast_module_.create<ast::type::Bool>()), bool_type_(ast_module_.create<ast::type::Bool>()),

View File

@ -86,9 +86,8 @@ struct TypedExpression {
class ParserImpl : Reader { class ParserImpl : Reader {
public: public:
/// Creates a new parser /// Creates a new parser
/// @param ctx the non-null context object
/// @param input the input data to parse /// @param input the input data to parse
ParserImpl(Context* ctx, const std::vector<uint32_t>& input); explicit ParserImpl(const std::vector<uint32_t>& input);
/// Destructor /// Destructor
~ParserImpl() override; ~ParserImpl() override;
@ -96,11 +95,6 @@ class ParserImpl : Reader {
/// @returns true if the parse was successful, false otherwise. /// @returns true if the parse was successful, false otherwise.
bool Parse() override; 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. /// @returns the module. The module in the parser will be reset after this.
ast::Module module() override; ast::Module module() override;

View File

@ -22,7 +22,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/opt/ir_context.h" #include "source/opt/ir_context.h"
#include "src/context.h"
#include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl.h"
namespace tint { namespace tint {
@ -40,7 +39,7 @@ class SpvParserTestBase : public T {
/// @param input the SPIR-V binary to parse /// @param input the SPIR-V binary to parse
/// @returns a parser for the given binary /// @returns a parser for the given binary
std::unique_ptr<ParserImpl> parser(const std::vector<uint32_t>& input) { std::unique_ptr<ParserImpl> parser(const std::vector<uint32_t>& input) {
return std::make_unique<ParserImpl>(&ctx_, input); return std::make_unique<ParserImpl>(input);
} }
/// Gets the internal representation of the function with the given ID. /// 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) { spvtools::opt::Function* spirv_function(ParserImpl* parser, uint32_t id) {
return parser->ir_context()->GetFunction(id); return parser->ir_context()->GetFunction(id);
} }
private:
Context ctx_;
}; };
// Use this form when you don't need to template any further. // Use this form when you don't need to template any further.

View File

@ -22,8 +22,10 @@ namespace tint {
namespace reader { namespace reader {
namespace wgsl { namespace wgsl {
Parser::Parser(Context* ctx, Source::File const* file) Parser::Parser(Source::File const* file)
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, file)) {} : Reader(), impl_(std::make_unique<ParserImpl>(file)) {}
Parser::Parser(Context*, Source::File const* file) : Parser(file) {}
Parser::~Parser() = default; Parser::~Parser() = default;

View File

@ -18,6 +18,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "src/context.h"
#include "src/reader/reader.h" #include "src/reader/reader.h"
#include "src/source.h" #include "src/source.h"
@ -31,6 +32,10 @@ class ParserImpl;
class Parser : public Reader { class Parser : public Reader {
public: public:
/// Creates a new parser from the given file. /// 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 ctx the non-null context object
/// @param file the input source file to parse /// @param file the input source file to parse
Parser(Context* ctx, Source::File const* file); Parser(Context* ctx, Source::File const* file);

View File

@ -186,7 +186,7 @@ struct BlockCounters {
} // namespace } // namespace
ParserImpl::ParserImpl(Context*, Source::File const* file) ParserImpl::ParserImpl(Source::File const* file)
: lexer_(std::make_unique<Lexer>(file)) {} : lexer_(std::make_unique<Lexer>(file)) {}
ParserImpl::~ParserImpl() = default; ParserImpl::~ParserImpl() = default;

View File

@ -55,7 +55,6 @@
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h" #include "src/ast/variable_decoration.h"
#include "src/context.h"
#include "src/diagnostic/diagnostic.h" #include "src/diagnostic/diagnostic.h"
#include "src/diagnostic/formatter.h" #include "src/diagnostic/formatter.h"
#include "src/reader/wgsl/parser_impl_detail.h" #include "src/reader/wgsl/parser_impl_detail.h"
@ -231,9 +230,8 @@ class ParserImpl {
}; };
/// Creates a new parser using the given file /// Creates a new parser using the given file
/// @param ctx the non-null context object
/// @param file the input source file to parse /// @param file the input source file to parse
ParserImpl(Context* ctx, Source::File const* file); explicit ParserImpl(Source::File const* file);
~ParserImpl(); ~ParserImpl();
/// Run the parser /// Run the parser

View File

@ -40,14 +40,13 @@ class ParserImplTest : public testing::Test {
/// @returns the parser implementation /// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) { std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str); auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(&ctx_, file.get()); auto impl = std::make_unique<ParserImpl>(file.get());
files_.emplace_back(std::move(file)); files_.emplace_back(std::move(file));
return impl; return impl;
} }
private: private:
std::vector<std::unique_ptr<Source::File>> files_; std::vector<std::unique_ptr<Source::File>> files_;
Context ctx_;
}; };
/// WGSL Parser test class with param /// WGSL Parser test class with param
@ -63,14 +62,13 @@ class ParserImplTestWithParam : public testing::TestWithParam<T> {
/// @returns the parser implementation /// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) { std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str); auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(&ctx_, file.get()); auto impl = std::make_unique<ParserImpl>(file.get());
files_.emplace_back(std::move(file)); files_.emplace_back(std::move(file));
return impl; return impl;
} }
private: private:
std::vector<std::unique_ptr<Source::File>> files_; std::vector<std::unique_ptr<Source::File>> files_;
Context ctx_;
}; };
} // namespace wgsl } // namespace wgsl

View File

@ -49,9 +49,12 @@
namespace tint { namespace tint {
namespace transform { namespace transform {
BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context* ctx, BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(ast::Module* mod)
: Transformer(mod) {}
BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context*,
ast::Module* mod) ast::Module* mod)
: Transformer(ctx, mod) {} : BoundArrayAccessorsTransform(mod) {}
BoundArrayAccessorsTransform::~BoundArrayAccessorsTransform() = default; BoundArrayAccessorsTransform::~BoundArrayAccessorsTransform() = default;

View File

@ -35,9 +35,13 @@ namespace transform {
class BoundArrayAccessorsTransform : public Transformer { class BoundArrayAccessorsTransform : public Transformer {
public: public:
/// Constructor /// Constructor
/// @param mod the module transform
explicit BoundArrayAccessorsTransform(ast::Module* mod);
/// Constructor
/// DEPRECATED
/// @param ctx the Tint context object /// @param ctx the Tint context object
/// @param mod the module transform /// @param mod the module transform
explicit BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod); BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod);
~BoundArrayAccessorsTransform() override; ~BoundArrayAccessorsTransform() override;
/// Users of Tint should register the transform with transform manager and /// Users of Tint should register the transform with transform manager and

View File

@ -40,7 +40,6 @@
#include "src/ast/uint_literal.h" #include "src/ast/uint_literal.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decl_statement.h"
#include "src/context.h"
#include "src/transform/manager.h" #include "src/transform/manager.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
@ -50,12 +49,10 @@ namespace {
class BoundArrayAccessorsTest : public testing::Test { class BoundArrayAccessorsTest : public testing::Test {
public: public:
BoundArrayAccessorsTest() : td_(&ctx_, &mod_) { BoundArrayAccessorsTest() : td_(&mod_) {
auto transform = auto transform = std::make_unique<BoundArrayAccessorsTransform>(&mod_);
std::make_unique<BoundArrayAccessorsTransform>(&ctx_, &mod_);
transform_ = transform.get(); transform_ = transform.get();
manager_ = std::make_unique<Manager>(&ctx_, &mod_); manager_.append(std::move(transform));
manager_->append(std::move(transform));
} }
ast::BlockStatement* SetupFunctionAndBody() { ast::BlockStatement* SetupFunctionAndBody() {
@ -74,7 +71,7 @@ class BoundArrayAccessorsTest : public testing::Test {
TypeDeterminer* td() { return &td_; } 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 /// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed. /// destructed, the `ast::Node` will also be destructed.
@ -86,11 +83,10 @@ class BoundArrayAccessorsTest : public testing::Test {
} }
private: private:
Context ctx_;
ast::Module mod_; ast::Module mod_;
TypeDeterminer td_; TypeDeterminer td_;
ast::type::Void void_type_; ast::type::Void void_type_;
std::unique_ptr<Manager> manager_; Manager manager_;
BoundArrayAccessorsTransform* transform_; BoundArrayAccessorsTransform* transform_;
ast::BlockStatement* body_ = nullptr; ast::BlockStatement* body_ = nullptr;
}; };
@ -128,7 +124,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
@ -191,7 +187,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
@ -268,7 +264,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -316,7 +312,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
@ -369,7 +365,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -408,7 +404,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -447,7 +443,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -495,7 +491,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::CallExpression>());
@ -547,7 +543,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -586,7 +582,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ptr->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -628,7 +624,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -692,7 +688,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -771,7 +767,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -839,7 +835,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -893,7 +889,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -948,7 +944,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
@ -1003,7 +999,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
ASSERT_TRUE(td()->Determine()) << td()->error(); ASSERT_TRUE(td()->Determine()) << td()->error();
ASSERT_TRUE(manager()->Run()); ASSERT_TRUE(Run());
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());

View File

@ -19,12 +19,19 @@
namespace tint { namespace tint {
namespace transform { namespace transform {
Manager::Manager(Context* context, ast::Module* module) Manager::Manager() = default;
: context_(context), module_(module) {}
Manager::Manager(Context*, ast::Module* module) : module_(module) {}
Manager::~Manager() = default; Manager::~Manager() = default;
bool Manager::Run() { bool Manager::Run() {
return Run(module_);
}
bool Manager::Run(ast::Module* module) {
error_ = "";
for (auto& transform : transforms_) { for (auto& transform : transforms_) {
if (!transform->Run()) { if (!transform->Run()) {
error_ = transform->error(); 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 // The transformed have potentially inserted nodes into the AST, so the type
// determinater needs to be run. // determinater needs to be run.
TypeDeterminer td(context_, module_); TypeDeterminer td(module);
if (!td.Determine()) { if (!td.Determine()) {
error_ = td.error(); error_ = td.error();
return false; return false;

View File

@ -20,6 +20,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "src/context.h"
#include "src/transform/transformer.h" #include "src/transform/transformer.h"
namespace tint { namespace tint {
@ -31,6 +32,9 @@ namespace transform {
class Manager { class Manager {
public: public:
/// Constructor /// Constructor
Manager();
/// Constructor
/// DEPRECATED
/// @param context the tint context /// @param context the tint context
/// @param module the module to transform /// @param module the module to transform
Manager(Context* context, ast::Module* module); Manager(Context* context, ast::Module* module);
@ -43,6 +47,11 @@ class Manager {
} }
/// Runs the transforms /// 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 /// @returns true on success; false otherwise
bool Run(); bool Run();
@ -50,9 +59,8 @@ class Manager {
std::string error() const { return error_; } std::string error() const { return error_; }
private: private:
Context* context_;
ast::Module* module_;
std::vector<std::unique_ptr<Transformer>> transforms_; std::vector<std::unique_ptr<Transformer>> transforms_;
ast::Module* module_ = nullptr;
std::string error_; std::string error_;
}; };

View File

@ -17,8 +17,7 @@
namespace tint { namespace tint {
namespace transform { namespace transform {
Transformer::Transformer(Context* ctx, ast::Module* mod) Transformer::Transformer(ast::Module* mod) : mod_(mod) {}
: ctx_(ctx), mod_(mod) {}
Transformer::~Transformer() = default; Transformer::~Transformer() = default;

View File

@ -29,9 +29,8 @@ namespace transform {
class Transformer { class Transformer {
public: public:
/// Constructor /// Constructor
/// @param ctx the Tint context
/// @param mod the module to transform /// @param mod the module to transform
Transformer(Context* ctx, ast::Module* mod); explicit Transformer(ast::Module* mod);
virtual ~Transformer(); virtual ~Transformer();
/// Users of Tint should register the transform with transform manager and /// Users of Tint should register the transform with transform manager and
@ -53,8 +52,6 @@ class Transformer {
return mod_->create<T>(std::forward<ARGS>(args)...); return mod_->create<T>(std::forward<ARGS>(args)...);
} }
/// The context
Context* ctx_ = nullptr;
/// The module /// The module
ast::Module* mod_ = nullptr; ast::Module* mod_ = nullptr;
/// Any error messages, or blank if no error /// Any error messages, or blank if no error

View File

@ -52,8 +52,11 @@ static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index";
} // namespace } // namespace
VertexPullingTransform::VertexPullingTransform(Context* ctx, ast::Module* mod) VertexPullingTransform::VertexPullingTransform(ast::Module* mod)
: Transformer(ctx, mod) {} : Transformer(mod) {}
VertexPullingTransform::VertexPullingTransform(Context*, ast::Module* mod)
: VertexPullingTransform(mod) {}
VertexPullingTransform::~VertexPullingTransform() = default; VertexPullingTransform::~VertexPullingTransform() = default;

View File

@ -25,7 +25,6 @@
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/statement.h" #include "src/ast/statement.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/context.h"
#include "src/transform/transformer.h" #include "src/transform/transformer.h"
namespace tint { namespace tint {
@ -147,6 +146,10 @@ struct VertexStateDescriptor {
class VertexPullingTransform : public Transformer { class VertexPullingTransform : public Transformer {
public: public:
/// Constructor /// Constructor
/// @param mod the module to convert to vertex pulling
explicit VertexPullingTransform(ast::Module* mod);
/// Constructor
/// DEPRECATED
/// @param ctx the tint context /// @param ctx the tint context
/// @param mod the module to convert to vertex pulling /// @param mod the module to convert to vertex pulling
VertexPullingTransform(Context* ctx, ast::Module* mod); VertexPullingTransform(Context* ctx, ast::Module* mod);

View File

@ -58,8 +58,10 @@
namespace tint { namespace tint {
TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod) TypeDeterminer::TypeDeterminer(ast::Module* mod) : mod_(mod) {}
: ctx_(*ctx), mod_(mod) {}
TypeDeterminer::TypeDeterminer(Context*, ast::Module* mod)
: TypeDeterminer(mod) {}
TypeDeterminer::~TypeDeterminer() = default; TypeDeterminer::~TypeDeterminer() = default;

View File

@ -44,6 +44,10 @@ class Variable;
class TypeDeterminer { class TypeDeterminer {
public: public:
/// Constructor /// 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 ctx the tint context, must be non-null
/// @param mod the module to update with typing information /// @param mod the module to update with typing information
TypeDeterminer(Context* ctx, ast::Module* mod); TypeDeterminer(Context* ctx, ast::Module* mod);
@ -128,7 +132,6 @@ class TypeDeterminer {
bool DetermineMemberAccessor(ast::MemberAccessorExpression* expr); bool DetermineMemberAccessor(ast::MemberAccessorExpression* expr);
bool DetermineUnaryOp(ast::UnaryOpExpression* expr); bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
Context& ctx_;
ast::Module* mod_; ast::Module* mod_;
std::string error_; std::string error_;
ScopeStack<ast::Variable*> variable_stack_; ScopeStack<ast::Variable*> variable_stack_;

View File

@ -84,9 +84,9 @@ class FakeExpr : public ast::Expression {
void to_str(std::ostream&, size_t) const override {} void to_str(std::ostream&, size_t) const override {}
}; };
class TypeDeterminerHelper : public ast::BuilderWithContextAndModule { class TypeDeterminerHelper : public ast::BuilderWithModule {
public: public:
TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(ctx, mod)) {} TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(mod)) {}
TypeDeterminer* td() const { return td_.get(); } TypeDeterminer* td() const { return td_.get(); }

View File

@ -22,18 +22,17 @@ namespace hlsl {
Generator::Generator(ast::Module module) Generator::Generator(ast::Module module)
: Text(std::move(module)), : Text(std::move(module)),
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {} impl_(std::make_unique<GeneratorImpl>(&module_)) {}
Generator::Generator(Context* ctx, ast::Module module) Generator::Generator(Context*, ast::Module module)
: Text(ctx, std::move(module)), : Generator(std::move(module)) {}
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
Generator::~Generator() = default; Generator::~Generator() = default;
void Generator::Reset() { void Generator::Reset() {
set_error(""); set_error("");
out_ = std::ostringstream(); out_ = std::ostringstream();
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_); impl_ = std::make_unique<GeneratorImpl>(&module_);
} }
bool Generator::Generate() { bool Generator::Generate() {

View File

@ -30,10 +30,10 @@ namespace hlsl {
class Generator : public Text { class Generator : public Text {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the module to convert /// @param module the module to convert
explicit Generator(ast::Module module); explicit Generator(ast::Module module);
/// Constructor /// Constructor
/// DEPRECATED
/// @param ctx the context, must be non-null /// @param ctx the context, must be non-null
/// @param module the module to convert /// @param module the module to convert
Generator(Context* ctx, ast::Module module); Generator(Context* ctx, ast::Module module);

View File

@ -113,10 +113,7 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) {
} // namespace } // namespace
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module) GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
: ctx_(ctx), module_(module) {
assert(ctx);
}
GeneratorImpl::~GeneratorImpl() = default; GeneratorImpl::~GeneratorImpl() = default;

View File

@ -41,7 +41,6 @@
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type_constructor_expression.h" #include "src/ast/type_constructor_expression.h"
#include "src/ast/unary_op_expression.h" #include "src/ast/unary_op_expression.h"
#include "src/context.h"
#include "src/scope_stack.h" #include "src/scope_stack.h"
#include "src/writer/hlsl/namer.h" #include "src/writer/hlsl/namer.h"
@ -53,9 +52,8 @@ namespace hlsl {
class GeneratorImpl { class GeneratorImpl {
public: public:
/// Constructor /// Constructor
/// @param ctx the context object, must be non-null
/// @param module the module to generate /// @param module the module to generate
GeneratorImpl(Context* ctx, ast::Module* module); explicit GeneratorImpl(ast::Module* module);
~GeneratorImpl(); ~GeneratorImpl();
/// Increment the emitter indent level /// Increment the emitter indent level
@ -398,7 +396,6 @@ class GeneratorImpl {
size_t indent_ = 0; size_t indent_ = 0;
Namer namer_; Namer namer_;
Context* ctx_ = nullptr;
ast::Module* module_ = nullptr; ast::Module* module_ = nullptr;
std::string current_ep_name_; std::string current_ep_name_;
bool generating_entry_point_ = false; bool generating_entry_point_ = false;

View File

@ -141,7 +141,7 @@ std::string expected_texture_overload(
} // LINT - Ignore the length of this function } // LINT - Ignore the length of this function
class HlslGeneratorIntrinsicTextureTest class HlslGeneratorIntrinsicTextureTest
: public ast::BuilderWithContextAndModule, : public ast::BuilderWithModule,
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> { public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
protected: protected:
void OnVariableBuilt(ast::Variable* var) override { void OnVariableBuilt(ast::Variable* var) override {
@ -154,9 +154,9 @@ class HlslGeneratorIntrinsicTextureTest
std::string pre_result() const { return pre.str(); } std::string pre_result() const { return pre.str(); }
/// The type determiner /// The type determiner
TypeDeterminer td{ctx, mod}; TypeDeterminer td{mod};
/// The generator /// The generator
GeneratorImpl gen{ctx, mod}; GeneratorImpl gen{mod};
/// The output stream /// The output stream
std::ostringstream out; std::ostringstream out;
/// The pre-output stream /// The pre-output stream

View File

@ -22,7 +22,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/hlsl/generator_impl.h" #include "src/writer/hlsl/generator_impl.h"
@ -34,7 +33,7 @@ namespace hlsl {
template <typename BODY> template <typename BODY>
class TestHelperBase : public BODY { class TestHelperBase : public BODY {
public: public:
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} TestHelperBase() : td(&mod), gen(&mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// @returns the result string /// @returns the result string
@ -52,8 +51,6 @@ class TestHelperBase : public BODY {
return mod.create<T>(std::forward<ARGS>(args)...); return mod.create<T>(std::forward<ARGS>(args)...);
} }
/// The context
Context ctx;
/// The module /// The module
ast::Module mod; ast::Module mod;
/// The type determiner /// The type determiner

View File

@ -22,17 +22,16 @@ namespace msl {
Generator::Generator(ast::Module module) Generator::Generator(ast::Module module)
: Text(std::move(module)), : Text(std::move(module)),
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {} impl_(std::make_unique<GeneratorImpl>(&module_)) {}
Generator::Generator(Context* ctx, ast::Module module) Generator::Generator(Context*, ast::Module module)
: Text(ctx, std::move(module)), : Generator(std::move(module)) {}
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
Generator::~Generator() = default; Generator::~Generator() = default;
void Generator::Reset() { void Generator::Reset() {
set_error(""); set_error("");
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_); impl_ = std::make_unique<GeneratorImpl>(&module_);
} }
bool Generator::Generate() { bool Generator::Generate() {

View File

@ -29,10 +29,10 @@ namespace msl {
class Generator : public Text { class Generator : public Text {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the module to convert /// @param module the module to convert
explicit Generator(ast::Module module); explicit Generator(ast::Module module);
/// Constructor /// Constructor
/// DEPRECATED
/// @param ctx the context object, must be non-null /// @param ctx the context object, must be non-null
/// @param module the module to convert /// @param module the module to convert
Generator(Context* ctx, ast::Module module); Generator(Context* ctx, ast::Module module);

View File

@ -95,8 +95,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) {
} // namespace } // namespace
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module) GeneratorImpl::GeneratorImpl(ast::Module* module)
: TextGenerator(ctx), module_(module) {} : TextGenerator(), module_(module) {}
GeneratorImpl::~GeneratorImpl() = default; GeneratorImpl::~GeneratorImpl() = default;

View File

@ -54,9 +54,8 @@ namespace msl {
class GeneratorImpl : public TextGenerator { class GeneratorImpl : public TextGenerator {
public: public:
/// Constructor /// Constructor
/// @param ctx the context, must be non-null
/// @param module the module to generate /// @param module the module to generate
GeneratorImpl(Context* ctx, ast::Module* module); explicit GeneratorImpl(ast::Module* module);
~GeneratorImpl(); ~GeneratorImpl();
/// @returns true on successful generation; false otherwise /// @returns true on successful generation; false otherwise

View File

@ -141,7 +141,7 @@ std::string expected_texture_overload(
} // LINT - Ignore the length of this function } // LINT - Ignore the length of this function
class MslGeneratorIntrinsicTextureTest class MslGeneratorIntrinsicTextureTest
: public ast::BuilderWithContextAndModule, : public ast::BuilderWithModule,
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> { public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
protected: protected:
void OnVariableBuilt(ast::Variable* var) override { void OnVariableBuilt(ast::Variable* var) override {
@ -149,9 +149,9 @@ class MslGeneratorIntrinsicTextureTest
} }
/// The type determiner /// The type determiner
TypeDeterminer td{ctx, mod}; TypeDeterminer td{mod};
/// The generator /// The generator
GeneratorImpl gen{ctx, mod}; GeneratorImpl gen{mod};
}; };
TEST_P(MslGeneratorIntrinsicTextureTest, Call) { TEST_P(MslGeneratorIntrinsicTextureTest, Call) {

View File

@ -20,7 +20,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/msl/generator_impl.h" #include "src/writer/msl/generator_impl.h"
@ -32,7 +31,7 @@ namespace msl {
template <typename BASE> template <typename BASE>
class TestHelperBase : public BASE { class TestHelperBase : public BASE {
public: public:
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} TestHelperBase() : td(&mod), gen(&mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// Creates a new `ast::Node` owned by the Module. When the Module is /// Creates a new `ast::Node` owned by the Module. When the Module is
@ -44,8 +43,6 @@ class TestHelperBase : public BASE {
return mod.create<T>(std::forward<ARGS>(args)...); return mod.create<T>(std::forward<ARGS>(args)...);
} }
/// The context
Context ctx;
/// The module /// The module
ast::Module mod; ast::Module mod;
/// The type determiner /// The type determiner

View File

@ -277,10 +277,9 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {}
Builder::AccessorInfo::~AccessorInfo() {} Builder::AccessorInfo::~AccessorInfo() {}
Builder::Builder(Context* ctx, ast::Module* mod) Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {}
: ctx_(ctx), mod_(mod), scope_stack_({}) {
assert(ctx_); Builder::Builder(Context*, ast::Module* mod) : Builder(mod) {}
}
Builder::~Builder() = default; 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 // the inspector and land the same change in MSL / HLSL to all roll into Dawn
// at the same time. // at the same time.
// OperandList operands = {Operand::Int(stage), Operand::Int(id), // 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), OperandList operands = {Operand::Int(stage), Operand::Int(id),
Operand::String(func->name())}; Operand::String(func->name())};
@ -522,8 +521,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
auto func_id = func_op.to_i(); auto func_id = func_op.to_i();
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(func_id), {Operand::Int(func_id), Operand::String(func->name())});
Operand::String(ctx_->namer()->NameFor(func->name()))});
auto ret_id = GenerateTypeIfNeeded(func->return_type()); auto ret_id = GenerateTypeIfNeeded(func->return_type());
if (ret_id == 0) { if (ret_id == 0) {
@ -548,8 +546,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
} }
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(param_id), {Operand::Int(param_id), Operand::String(param->name())});
Operand::String(ctx_->namer()->NameFor(param->name()))});
params.push_back(Instruction{spv::Op::OpFunctionParameter, params.push_back(Instruction{spv::Op::OpFunctionParameter,
{Operand::Int(param_type_id), param_op}}); {Operand::Int(param_type_id), param_op}});
@ -640,8 +637,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) {
} }
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(var_id), {Operand::Int(var_id), Operand::String(var->name())});
Operand::String(ctx_->namer()->NameFor(var->name()))});
// TODO(dsinclair) We could detect if the constructor is fully const and emit // TODO(dsinclair) We could detect if the constructor is fully const and emit
// an initializer value for the variable instead of doing the OpLoad. // an initializer value for the variable instead of doing the OpLoad.
@ -689,8 +685,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
return false; return false;
} }
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(init_id), {Operand::Int(init_id), Operand::String(var->name())});
Operand::String(ctx_->namer()->NameFor(var->name()))});
scope_stack_.set_global(var->name(), init_id); scope_stack_.set_global(var->name(), init_id);
spirv_id_to_variable_[init_id] = var; spirv_id_to_variable_[init_id] = var;
@ -711,8 +706,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
} }
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(var_id), {Operand::Int(var_id), Operand::String(var->name())});
Operand::String(ctx_->namer()->NameFor(var->name()))});
auto* type = var->type()->UnwrapAll(); auto* type = var->type()->UnwrapAll();
@ -2633,8 +2627,7 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type,
if (!struct_type->name().empty()) { if (!struct_type->name().empty()) {
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(struct_id), {Operand::Int(struct_id), Operand::String(struct_type->name())});
Operand::String(ctx_->namer()->NameFor(struct_type->name()))});
} }
OperandList ops; OperandList ops;
@ -2675,9 +2668,8 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type,
uint32_t Builder::GenerateStructMember(uint32_t struct_id, uint32_t Builder::GenerateStructMember(uint32_t struct_id,
uint32_t idx, uint32_t idx,
ast::StructMember* member) { ast::StructMember* member) {
push_debug(spv::Op::OpMemberName, push_debug(spv::Op::OpMemberName, {Operand::Int(struct_id), Operand::Int(idx),
{Operand::Int(struct_id), Operand::Int(idx), Operand::String(member->name())});
Operand::String(ctx_->namer()->NameFor(member->name()))});
bool has_layout = false; bool has_layout = false;
for (auto* deco : member->decorations()) { for (auto* deco : member->decorations()) {

View File

@ -83,6 +83,10 @@ class Builder {
}; };
/// Constructor /// Constructor
/// @param mod the module to generate from
explicit Builder(ast::Module* mod);
/// Constructor
/// DEPRECATED
/// @param ctx the context, must be non-null /// @param ctx the context, must be non-null
/// @param mod the module to generate from /// @param mod the module to generate from
Builder(Context* ctx, ast::Module* mod); Builder(Context* ctx, ast::Module* mod);
@ -495,7 +499,6 @@ class Builder {
return func_name_to_id_[name]; return func_name_to_id_[name];
} }
Context* ctx_ = nullptr;
ast::Module* mod_; ast::Module* mod_;
std::string error_; std::string error_;
uint32_t next_id_ = 1; uint32_t next_id_ = 1;

View File

@ -74,10 +74,10 @@ TEST_F(BuilderTest, Expression_Call) {
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(b.GenerateCallExpression(&expr), 14u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 14u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63" EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
OpName %4 "tint_61" OpName %4 "a"
OpName %5 "tint_62" OpName %5 "b"
OpName %12 "tint_6d61696e" OpName %12 "main"
%2 = OpTypeFloat 32 %2 = OpTypeFloat 32
%1 = OpTypeFunction %2 %2 %2 %1 = OpTypeFunction %2 %2 %2
%11 = OpTypeVoid %11 = OpTypeVoid
@ -136,10 +136,10 @@ TEST_F(BuilderTest, Statement_Call) {
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_TRUE(b.GenerateStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63" EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
OpName %5 "tint_61" OpName %5 "a"
OpName %6 "tint_62" OpName %6 "b"
OpName %12 "tint_6d61696e" OpName %12 "main"
%2 = OpTypeVoid %2 = OpTypeVoid
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%1 = OpTypeFunction %2 %3 %3 %1 = OpTypeFunction %2 %3 %3

View File

@ -110,10 +110,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
mod->AddGlobalVariable(v_wg); mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in"
OpName %4 "tint_6d795f6f7574" OpName %4 "my_out"
OpName %7 "tint_6d795f7767" OpName %7 "my_wg"
OpName %11 "tint_6d61696e" OpName %11 "main"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -173,10 +173,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
mod->AddGlobalVariable(v_wg); mod->AddGlobalVariable(v_wg);
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in"
OpName %4 "tint_6d795f6f7574" OpName %4 "my_out"
OpName %7 "tint_6d795f7767" OpName %7 "my_wg"
OpName %11 "tint_6d61696e" OpName %11 "main"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -252,8 +252,8 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
OpEntryPoint Fragment %5 "main2" OpEntryPoint Fragment %5 "main2"
OpExecutionMode %3 OriginUpperLeft OpExecutionMode %3 OriginUpperLeft
OpExecutionMode %5 OriginUpperLeft OpExecutionMode %5 OriginUpperLeft
OpName %3 "tint_6d61696e31" OpName %3 "main1"
OpName %5 "tint_6d61696e32" OpName %5 "main2"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1

View File

@ -52,7 +52,7 @@ TEST_F(BuilderTest, Function_Empty) {
ast::Function func("a_func", {}, &void_type, create<ast::BlockStatement>()); ast::Function func("a_func", {}, &void_type, create<ast::BlockStatement>());
ASSERT_TRUE(b.GenerateFunction(&func)); 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 %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -71,7 +71,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) {
ast::Function func("a_func", {}, &void_type, body); ast::Function func("a_func", {}, &void_type, body);
ASSERT_TRUE(b.GenerateFunction(&func)); 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 %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %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.GenerateGlobalVariable(var_a)) << b.error();
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_61" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -122,7 +122,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) {
ast::Function func("a_func", {}, &void_type, body); ast::Function func("a_func", {}, &void_type, body);
ASSERT_TRUE(b.GenerateFunction(&func)); 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 %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -155,9 +155,9 @@ TEST_F(BuilderTest, Function_WithParams) {
EXPECT_TRUE(td.DetermineFunction(&func)); EXPECT_TRUE(td.DetermineFunction(&func));
ASSERT_TRUE(b.GenerateFunction(&func)); ASSERT_TRUE(b.GenerateFunction(&func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63" EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
OpName %5 "tint_61" OpName %5 "a"
OpName %6 "tint_62" OpName %6 "b"
%2 = OpTypeFloat 32 %2 = OpTypeFloat 32
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%1 = OpTypeFunction %2 %2 %3 %1 = OpTypeFunction %2 %2 %3
@ -179,7 +179,7 @@ TEST_F(BuilderTest, Function_WithBody) {
ast::Function func("a_func", {}, &void_type, body); ast::Function func("a_func", {}, &void_type, body);
ASSERT_TRUE(b.GenerateFunction(&func)); 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 %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%3 = OpFunction %2 None %1 %3 = OpFunction %2 None %1
@ -302,13 +302,13 @@ OpEntryPoint GLCompute %7 "a"
OpEntryPoint GLCompute %17 "b" OpEntryPoint GLCompute %17 "b"
OpExecutionMode %7 LocalSize 1 1 1 OpExecutionMode %7 LocalSize 1 1 1
OpExecutionMode %17 LocalSize 1 1 1 OpExecutionMode %17 LocalSize 1 1 1
OpName %3 "tint_44617461" OpName %3 "Data"
OpMemberName %3 0 "tint_64" OpMemberName %3 0 "d"
OpName %1 "tint_64617461" OpName %1 "data"
OpName %7 "tint_61" OpName %7 "a"
OpName %14 "tint_76" OpName %14 "v"
OpName %17 "tint_62" OpName %17 "b"
OpName %21 "tint_76" OpName %21 "v"
OpDecorate %3 Block OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0 OpMemberDecorate %3 0 Offset 0
OpDecorate %1 Binding 0 OpDecorate %1 Binding 0

View File

@ -52,7 +52,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3 %2 = OpTypePointer Function %3
@ -90,7 +90,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
ASSERT_FALSE(b.has_error()) << 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -135,7 +135,7 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
ASSERT_FALSE(b.has_error()) << 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 2 %1 = OpTypeVector %2 2
@ -180,8 +180,8 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error();
ASSERT_FALSE(b.has_error()) << 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"
OpName %7 "tint_7632" OpName %7 "v2"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1 %2 = OpConstant %1 1
@ -226,7 +226,7 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error(); EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error();
ASSERT_FALSE(b.has_error()) << 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1 %2 = OpConstant %1 1

View File

@ -56,7 +56,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
ast::Variable v("var", ast::StorageClass::kNone, &f32); ast::Variable v("var", ast::StorageClass::kNone, &f32);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
@ -70,7 +70,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
ast::Variable v("var", ast::StorageClass::kOutput, &f32); ast::Variable v("var", ast::StorageClass::kOutput, &f32);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Output %3 %2 = OpTypePointer Output %3
@ -84,7 +84,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
ast::Variable v("var", ast::StorageClass::kInput, &f32); ast::Variable v("var", ast::StorageClass::kInput, &f32);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Input %3 %2 = OpTypePointer Input %3
@ -115,7 +115,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
ASSERT_FALSE(b.has_error()) << 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -151,7 +151,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
ASSERT_FALSE(b.has_error()) << 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3 %1 = OpTypeVector %2 3
@ -249,7 +249,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
dv.set_decorations(decos); dv.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5
)"); )");
@ -271,7 +271,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
dv.set_decorations(decos); dv.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2
OpDecorate %1 DescriptorSet 3 OpDecorate %1 DescriptorSet 3
@ -294,7 +294,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
dv.set_decorations(decos); dv.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position
)"); )");
@ -318,7 +318,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
create<ast::BoolLiteral>(&bool_type, true))); create<ast::BoolLiteral>(&bool_type, true)));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 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); v.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200
)"); )");
@ -364,7 +364,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
create<ast::FloatLiteral>(&f32, 2.0))); create<ast::FloatLiteral>(&f32, 2.0)));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 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); v.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 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); v.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 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); v.set_decorations(decos);
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 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 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
OpMemberDecorate %3 1 NonWritable OpMemberDecorate %3 1 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
OpMemberName %3 0 "tint_61" OpMemberName %3 0 "a"
OpMemberName %3 1 "tint_62" OpMemberName %3 1 "b"
OpName %1 "tint_62" OpName %1 "b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %4 %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.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
OpMemberName %3 0 "tint_61" OpMemberName %3 0 "a"
OpName %1 "tint_62" OpName %1 "b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %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.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
OpMemberName %3 0 "tint_61" OpMemberName %3 0 "a"
OpName %1 "tint_62" OpName %1 "b"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %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.annots()), R"(OpMemberDecorate %3 0 NonWritable
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
OpMemberName %3 0 "tint_61" OpMemberName %3 0 "a"
OpName %1 "tint_62" OpName %1 "b"
OpName %7 "tint_41" OpName %7 "A"
OpMemberName %7 0 "tint_61" OpMemberName %7 0 "a"
OpName %5 "tint_63" OpName %5 "c"
)"); )");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1 EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeStruct %4 %3 = OpTypeStruct %4

View File

@ -84,7 +84,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Output %3 %2 = OpTypePointer Output %3
@ -141,7 +141,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
b.push_function(Function{}); b.push_function(Function{});
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error(); 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3 %2 = OpTypePointer Function %3

View File

@ -52,15 +52,15 @@ namespace writer {
namespace spirv { namespace spirv {
namespace { namespace {
class IntrinsicBuilderTest : public ast::BuilderWithContextAndModule, class IntrinsicBuilderTest : public ast::BuilderWithModule,
public testing::Test { public testing::Test {
protected: protected:
void OnVariableBuilt(ast::Variable* var) override { void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
} }
TypeDeterminer td{ctx, mod}; TypeDeterminer td{mod};
spirv::Builder b{ctx, mod}; spirv::Builder b{mod};
}; };
template <typename T> template <typename T>
@ -646,8 +646,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 9u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 9u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450"
OpName %1 "tint_6964656e74" OpName %1 "ident"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeFloat 32 %3 = OpTypeFloat 32
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -755,7 +755,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -778,7 +778,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -803,7 +803,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %7 = OpTypeFloat 32
@ -895,7 +895,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -919,7 +919,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %6 = OpTypeFloat 32
@ -946,7 +946,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeFloat 32 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 1 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%6 = OpTypeInt 32 0 %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(b.GenerateCallExpression(&expr), 5u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%7 = OpTypeInt 32 0 %7 = OpTypeInt 32 0
@ -1402,8 +1402,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
EXPECT_EQ(b.GenerateCallExpression(&expr), 11u) << b.error(); EXPECT_EQ(b.GenerateCallExpression(&expr), 11u) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450" EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450"
OpName %3 "tint_615f66756e63" OpName %3 "a_func"
OpName %5 "tint_766172" OpName %5 "var"
%2 = OpTypeVoid %2 = OpTypeVoid
%1 = OpTypeFunction %2 %1 = OpTypeFunction %2
%9 = OpTypeFloat 32 %9 = OpTypeFloat 32

View File

@ -1491,15 +1491,15 @@ expected_texture_overload_spirv expected_texture_overload(
} // NOLINT - Ignore the length of this function } // NOLINT - Ignore the length of this function
class IntrinsicTextureTest class IntrinsicTextureTest
: public ast::BuilderWithContextAndModule, : public ast::BuilderWithModule,
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> { public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
protected: protected:
void OnVariableBuilt(ast::Variable* var) override { void OnVariableBuilt(ast::Variable* var) override {
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
} }
TypeDeterminer td{ctx, mod}; TypeDeterminer td{mod};
spirv::Builder b{ctx, mod}; spirv::Builder b{mod};
}; };
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(

View File

@ -116,9 +116,9 @@ TEST_F(BuilderTest, Switch_WithCase) {
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
OpName %5 "tint_61" OpName %5 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -180,9 +180,9 @@ TEST_F(BuilderTest, Switch_WithDefault) {
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
OpName %5 "tint_61" OpName %5 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -263,9 +263,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
OpName %5 "tint_61" OpName %5 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -355,9 +355,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
OpName %5 "tint_61" OpName %5 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3
@ -477,9 +477,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error(); EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76" EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
OpName %5 "tint_61" OpName %5 "a"
OpName %7 "tint_615f66756e63" OpName %7 "a_func"
%3 = OpTypeInt 32 1 %3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3 %2 = OpTypePointer Private %3
%4 = OpConstantNull %3 %4 = OpConstantNull %3

View File

@ -287,7 +287,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
EXPECT_EQ(id, 1u); EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 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 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %1 = OpTypeStruct %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
)"); )");
} }
@ -335,8 +335,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %1 = OpTypeStruct %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block 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 EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeStruct %2 %2 %1 = OpTypeStruct %2 %2
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
OpMemberName %1 1 "tint_62" OpMemberName %1 1 "b"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 1 Offset 8 OpMemberDecorate %1 1 Offset 8
@ -404,10 +404,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
OpMemberName %1 1 "tint_62" OpMemberName %1 1 "b"
OpMemberName %1 2 "tint_63" OpMemberName %1 2 "c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), ""); EXPECT_EQ(DumpInstructions(b.annots()), "");
} }
@ -447,10 +447,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
OpMemberName %1 1 "tint_62" OpMemberName %1 1 "b"
OpMemberName %1 2 "tint_63" OpMemberName %1 2 "c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor OpMemberDecorate %1 0 ColMajor
@ -508,10 +508,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
%7 = OpTypeMatrix %8 4 %7 = OpTypeMatrix %8 4
%1 = OpTypeStruct %2 %5 %7 %1 = OpTypeStruct %2 %5 %7
)"); )");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
OpMemberName %1 0 "tint_61" OpMemberName %1 0 "a"
OpMemberName %1 1 "tint_62" OpMemberName %1 1 "b"
OpMemberName %1 2 "tint_63" OpMemberName %1 2 "c"
)"); )");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0 EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor OpMemberDecorate %1 0 ColMajor

View File

@ -22,18 +22,16 @@ namespace spirv {
Generator::Generator(ast::Module module) Generator::Generator(ast::Module module)
: writer::Writer(std::move(module)), : writer::Writer(std::move(module)),
builder_(std::make_unique<Builder>(ctx_, &module_)), builder_(std::make_unique<Builder>(&module_)),
writer_(std::make_unique<BinaryWriter>()) {} writer_(std::make_unique<BinaryWriter>()) {}
Generator::Generator(Context* ctx, ast::Module module) Generator::Generator(Context*, ast::Module module)
: writer::Writer(ctx, std::move(module)), : Generator(std::move(module)) {}
builder_(std::make_unique<Builder>(ctx, &module_)),
writer_(std::make_unique<BinaryWriter>()) {}
Generator::~Generator() = default; Generator::~Generator() = default;
void Generator::Reset() { void Generator::Reset() {
builder_ = std::make_unique<Builder>(ctx_, &module_); builder_ = std::make_unique<Builder>(&module_);
writer_ = std::make_unique<BinaryWriter>(); writer_ = std::make_unique<BinaryWriter>();
} }

View File

@ -32,10 +32,10 @@ namespace spirv {
class Generator : public writer::Writer { class Generator : public writer::Writer {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the module to convert /// @param module the module to convert
explicit Generator(ast::Module module); explicit Generator(ast::Module module);
/// Constructor /// Constructor
/// DEPRECATED
/// @param ctx the context, must be non-null /// @param ctx the context, must be non-null
/// @param module the module to convert /// @param module the module to convert
Generator(Context* ctx, ast::Module module); Generator(Context* ctx, ast::Module module);

View File

@ -21,7 +21,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/builder.h" #include "src/ast/builder.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/spirv/builder.h" #include "src/writer/spirv/builder.h"
@ -31,9 +30,9 @@ namespace spirv {
/// Helper class for testing /// Helper class for testing
template <typename BASE> template <typename BASE>
class TestHelperBase : public ast::BuilderWithContextAndModule, public BASE { class TestHelperBase : public ast::BuilderWithModule, public BASE {
public: public:
TestHelperBase() : td(ctx, mod), b(ctx, mod) {} TestHelperBase() : td(mod), b(mod) {}
~TestHelperBase() override = default; ~TestHelperBase() override = default;
/// The type determiner /// The type determiner

View File

@ -21,8 +21,6 @@ namespace writer {
Text::Text(ast::Module module) : Writer(std::move(module)) {} Text::Text(ast::Module module) : Writer(std::move(module)) {}
Text::Text(Context* ctx, ast::Module module) : Writer(ctx, std::move(module)) {}
Text::~Text() = default; Text::~Text() = default;
} // namespace writer } // namespace writer

View File

@ -26,13 +26,8 @@ namespace writer {
class Text : public Writer { class Text : public Writer {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the module to convert /// @param module the module to convert
explicit Text(ast::Module module); 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; ~Text() override;
/// @returns the result data /// @returns the result data

View File

@ -21,9 +21,7 @@
namespace tint { namespace tint {
namespace writer { namespace writer {
TextGenerator::TextGenerator(Context* ctx) : ctx_(ctx) { TextGenerator::TextGenerator() = default;
assert(ctx_);
}
TextGenerator::~TextGenerator() = default; TextGenerator::~TextGenerator() = default;

View File

@ -18,8 +18,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "src/context.h"
namespace tint { namespace tint {
namespace writer { namespace writer {
@ -27,8 +25,7 @@ namespace writer {
class TextGenerator { class TextGenerator {
public: public:
/// Constructor /// Constructor
/// @param ctx the context object, must be non-null TextGenerator();
explicit TextGenerator(Context* ctx);
~TextGenerator(); ~TextGenerator();
/// Increment the emitter indent level /// Increment the emitter indent level
@ -52,8 +49,6 @@ class TextGenerator {
std::string error() const { return error_; } std::string error() const { return error_; }
protected: protected:
/// The context
Context* ctx_ = nullptr;
/// The text output stream /// The text output stream
std::ostringstream out_; std::ostringstream out_;
/// Error generated by the generator /// Error generated by the generator

View File

@ -21,17 +21,16 @@ namespace writer {
namespace wgsl { namespace wgsl {
Generator::Generator(ast::Module module) Generator::Generator(ast::Module module)
: Text(std::move(module)), impl_(std::make_unique<GeneratorImpl>(ctx_)) {} : Text(std::move(module)), impl_(std::make_unique<GeneratorImpl>()) {}
Generator::Generator(Context* ctx, ast::Module module) Generator::Generator(Context*, ast::Module module)
: Text(ctx, std::move(module)), : Generator(std::move(module)) {}
impl_(std::make_unique<GeneratorImpl>(ctx_)) {}
Generator::~Generator() = default; Generator::~Generator() = default;
void Generator::Reset() { void Generator::Reset() {
set_error(""); set_error("");
impl_ = std::make_unique<GeneratorImpl>(ctx_); impl_ = std::make_unique<GeneratorImpl>();
} }
bool Generator::Generate() { bool Generator::Generate() {

View File

@ -29,10 +29,10 @@ namespace wgsl {
class Generator : public Text { class Generator : public Text {
public: public:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the module to convert /// @param module the module to convert
explicit Generator(ast::Module module); explicit Generator(ast::Module module);
/// Constructor /// Constructor
/// DEPRECATED
/// @param ctx the context, must be non-null /// @param ctx the context, must be non-null
/// @param module the module to convert /// @param module the module to convert
Generator(Context* ctx, ast::Module module); Generator(Context* ctx, ast::Module module);

View File

@ -78,7 +78,7 @@ namespace tint {
namespace writer { namespace writer {
namespace wgsl { namespace wgsl {
GeneratorImpl::GeneratorImpl(Context* ctx) : TextGenerator(ctx) {} GeneratorImpl::GeneratorImpl() : TextGenerator() {}
GeneratorImpl::~GeneratorImpl() = default; GeneratorImpl::~GeneratorImpl() = default;

View File

@ -54,8 +54,7 @@ namespace wgsl {
class GeneratorImpl : public TextGenerator { class GeneratorImpl : public TextGenerator {
public: public:
/// Constructor /// Constructor
/// @param ctx the context, must be non-null GeneratorImpl();
explicit GeneratorImpl(Context* ctx);
~GeneratorImpl(); ~GeneratorImpl();
/// Generates the result data /// Generates the result data

View File

@ -20,7 +20,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/generator_impl.h"
@ -32,7 +31,7 @@ namespace wgsl {
template <typename BASE> template <typename BASE>
class TestHelperBase : public BASE { class TestHelperBase : public BASE {
public: public:
TestHelperBase() : td(&ctx, &mod), gen(&ctx) {} TestHelperBase() : td(&mod), gen() {}
~TestHelperBase() = default; ~TestHelperBase() = default;
@ -45,8 +44,6 @@ class TestHelperBase : public BASE {
return mod.create<T>(std::forward<ARGS>(args)...); return mod.create<T>(std::forward<ARGS>(args)...);
} }
/// The context
Context ctx;
/// The module /// The module
ast::Module mod; ast::Module mod;
/// The type determiner /// The type determiner

View File

@ -19,18 +19,9 @@
namespace tint { namespace tint {
namespace writer { namespace writer {
Writer::Writer(ast::Module module) Writer::Writer(ast::Module module) : module_(std::move(module)) {}
: ctx_(new Context()),
context_is_owned_(true),
module_(std::move(module)) {}
Writer::Writer(Context* ctx, ast::Module module) Writer::~Writer() = default;
: ctx_(ctx), context_is_owned_(false), module_(std::move(module)) {}
Writer::~Writer() {
if (context_is_owned_)
delete ctx_;
}
} // namespace writer } // namespace writer
} // namespace tint } // namespace tint

View File

@ -50,25 +50,15 @@ class Writer {
protected: protected:
/// Constructor /// Constructor
/// DEPRECATED
/// @param module the tint module to convert /// @param module the tint module to convert
explicit Writer(ast::Module module); 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 /// Sets the error string
/// @param msg the error message /// @param msg the error message
void set_error(const std::string& msg) { error_ = msg; } void set_error(const std::string& msg) { error_ = msg; }
/// An error message, if an error was encountered /// An error message, if an error was encountered
std::string error_; std::string error_;
/// The context
Context* ctx_ = nullptr;
/// Tracks if we own the context
bool context_is_owned_ = false;
/// The module being converted /// The module being converted
ast::Module module_; ast::Module module_;
}; };