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:
parent
573d8939f4
commit
685cb02ea8
|
@ -47,8 +47,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
tint::Source::File file("test.wgsl", str);
|
||||
|
||||
// Parse the wgsl, create the src module
|
||||
tint::Context ctx;
|
||||
tint::reader::wgsl::ParserImpl parser(&ctx, &file);
|
||||
tint::reader::wgsl::ParserImpl parser(&file);
|
||||
parser.set_max_errors(1);
|
||||
if (!parser.Parse()) {
|
||||
return 0;
|
||||
|
|
|
@ -22,8 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
std::vector<uint32_t> input(u32Data, u32Data + sizeInU32);
|
||||
|
||||
if (input.size() != 0) {
|
||||
tint::Context ctx;
|
||||
tint::reader::spirv::Parser parser(&ctx, input);
|
||||
tint::reader::spirv::Parser parser(input);
|
||||
parser.Parse();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
std::string str(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
tint::Source::File file("test.wgsl", str);
|
||||
|
||||
tint::Context ctx;
|
||||
tint::reader::wgsl::Parser parser(&ctx, &file);
|
||||
tint::reader::wgsl::Parser parser(&file);
|
||||
parser.Parse();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -418,8 +418,6 @@ int main(int argc, const char** argv) {
|
|||
options.format = Format::kSpvAsm;
|
||||
}
|
||||
|
||||
tint::Context ctx(std::make_unique<tint::NoopNamer>());
|
||||
|
||||
auto diag_printer = tint::diag::Printer::create(stderr, true);
|
||||
tint::diag::Formatter diag_formatter;
|
||||
|
||||
|
@ -435,8 +433,7 @@ int main(int argc, const char** argv) {
|
|||
}
|
||||
source_file = std::make_unique<tint::Source::File>(
|
||||
options.input_filename, std::string(data.begin(), data.end()));
|
||||
reader =
|
||||
std::make_unique<tint::reader::wgsl::Parser>(&ctx, source_file.get());
|
||||
reader = std::make_unique<tint::reader::wgsl::Parser>(source_file.get());
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_READER
|
||||
|
||||
|
@ -449,7 +446,7 @@ int main(int argc, const char** argv) {
|
|||
if (!ReadFile<uint32_t>(options.input_filename, &data)) {
|
||||
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
|
||||
if (options.input_filename.size() > 7 &&
|
||||
|
@ -471,7 +468,7 @@ int main(int argc, const char** argv) {
|
|||
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS)) {
|
||||
return 1;
|
||||
}
|
||||
reader = std::make_unique<tint::reader::spirv::Parser>(&ctx, data);
|
||||
reader = std::make_unique<tint::reader::spirv::Parser>(data);
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_READER
|
||||
|
||||
|
@ -490,7 +487,7 @@ int main(int argc, const char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
tint::TypeDeterminer td(&ctx, &mod);
|
||||
tint::TypeDeterminer td(&mod);
|
||||
if (!td.Determine()) {
|
||||
std::cerr << "Type Determination: " << td.error() << std::endl;
|
||||
return 1;
|
||||
|
@ -509,7 +506,7 @@ int main(int argc, const char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
tint::transform::Manager transform_manager(&ctx, &mod);
|
||||
tint::transform::Manager transform_manager;
|
||||
for (const auto& name : options.transforms) {
|
||||
// TODO(dsinclair): The vertex pulling transform requires setup code to
|
||||
// be run that needs user input. Should we find a way to support that here
|
||||
|
@ -518,13 +515,13 @@ int main(int argc, const char** argv) {
|
|||
if (name == "bound_array_accessors") {
|
||||
transform_manager.append(
|
||||
std::make_unique<tint::transform::BoundArrayAccessorsTransform>(
|
||||
&ctx, &mod));
|
||||
&mod));
|
||||
} else {
|
||||
std::cerr << "Unknown transform name: " << name << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!transform_manager.Run()) {
|
||||
if (!transform_manager.Run(&mod)) {
|
||||
std::cerr << "Transformer: " << transform_manager.error() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -533,29 +530,25 @@ int main(int argc, const char** argv) {
|
|||
|
||||
#if TINT_BUILD_SPV_WRITER
|
||||
if (options.format == Format::kSpirv || options.format == Format::kSpvAsm) {
|
||||
writer =
|
||||
std::make_unique<tint::writer::spirv::Generator>(&ctx, std::move(mod));
|
||||
writer = std::make_unique<tint::writer::spirv::Generator>(std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILD_SPV_WRITER
|
||||
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
if (options.format == Format::kWgsl) {
|
||||
writer =
|
||||
std::make_unique<tint::writer::wgsl::Generator>(&ctx, std::move(mod));
|
||||
writer = std::make_unique<tint::writer::wgsl::Generator>(std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILD_WGSL_WRITER
|
||||
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
if (options.format == Format::kMsl) {
|
||||
writer =
|
||||
std::make_unique<tint::writer::msl::Generator>(&ctx, std::move(mod));
|
||||
writer = std::make_unique<tint::writer::msl::Generator>(std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILD_MSL_WRITER
|
||||
|
||||
#if TINT_BUILD_HLSL_WRITER
|
||||
if (options.format == Format::kHlsl) {
|
||||
writer =
|
||||
std::make_unique<tint::writer::hlsl::Generator>(&ctx, std::move(mod));
|
||||
writer = std::make_unique<tint::writer::hlsl::Generator>(std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILD_HLSL_WRITER
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ TypesBuilder::TypesBuilder(Module* mod)
|
|||
void_(mod->create<type::Void>()),
|
||||
mod_(mod) {}
|
||||
|
||||
Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {}
|
||||
Builder::Builder(Module* m) : mod(m), ty(m) {}
|
||||
|
||||
Builder::~Builder() = default;
|
||||
|
||||
Variable* Builder::Var(const std::string& name,
|
||||
|
@ -36,10 +37,9 @@ Variable* Builder::Var(const std::string& name,
|
|||
return var;
|
||||
}
|
||||
|
||||
BuilderWithContextAndModule::BuilderWithContextAndModule()
|
||||
: Builder(new Context(), new Module()) {}
|
||||
BuilderWithContextAndModule::~BuilderWithContextAndModule() {
|
||||
delete ctx;
|
||||
BuilderWithModule::BuilderWithModule() : Builder(new Module()) {}
|
||||
|
||||
BuilderWithModule::~BuilderWithModule() {
|
||||
delete mod;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/context.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -186,9 +185,8 @@ class Builder {
|
|||
using f32 = float;
|
||||
|
||||
/// Constructor
|
||||
/// @param ctx the context to use in the builder
|
||||
/// @param mod the module to use in the builder
|
||||
explicit Builder(Context* ctx, Module* mod);
|
||||
explicit Builder(Module* mod);
|
||||
virtual ~Builder();
|
||||
|
||||
/// @param expr the expression
|
||||
|
@ -443,8 +441,6 @@ class Builder {
|
|||
return mod->create<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The builder module
|
||||
Context* const ctx;
|
||||
/// The builder module
|
||||
Module* const mod;
|
||||
/// The builder types
|
||||
|
@ -455,12 +451,11 @@ class Builder {
|
|||
virtual void OnVariableBuilt(Variable*) {}
|
||||
};
|
||||
|
||||
/// BuilderWithContextAndModule is a `Builder` that constructs and owns its
|
||||
/// `Context` and `Module`.
|
||||
class BuilderWithContextAndModule : public Builder {
|
||||
/// BuilderWithModule is a `Builder` that constructs and owns its `Module`.
|
||||
class BuilderWithModule : public Builder {
|
||||
public:
|
||||
BuilderWithContextAndModule();
|
||||
~BuilderWithContextAndModule() override;
|
||||
BuilderWithModule();
|
||||
~BuilderWithModule() override;
|
||||
};
|
||||
|
||||
//! @cond Doxygen_Suppress
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -41,12 +41,6 @@ class Context {
|
|||
explicit Context(std::unique_ptr<Namer> namer);
|
||||
/// Destructor
|
||||
~Context();
|
||||
|
||||
/// @returns the namer object
|
||||
Namer* namer() const { return namer_.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Namer> namer_;
|
||||
};
|
||||
|
||||
} // namespace tint
|
||||
|
|
|
@ -43,18 +43,12 @@
|
|||
namespace tint {
|
||||
namespace inspector {
|
||||
|
||||
Inspector::Inspector(const ast::Module& module)
|
||||
: ctx_(new Context()), context_is_owned_(true), module_(module) {}
|
||||
Inspector::Inspector(const ast::Module& module) : module_(module) {}
|
||||
|
||||
Inspector::Inspector(Context* ctx, const ast::Module& module)
|
||||
: ctx_(ctx), context_is_owned_(false), module_(module) {
|
||||
assert(ctx);
|
||||
}
|
||||
Inspector::Inspector(Context*, const ast::Module& module)
|
||||
: Inspector(std::move(module)) {}
|
||||
|
||||
Inspector::~Inspector() {
|
||||
if (context_is_owned_)
|
||||
delete ctx_;
|
||||
}
|
||||
Inspector::~Inspector() = default;
|
||||
|
||||
std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||
std::vector<EntryPoint> result;
|
||||
|
@ -66,7 +60,7 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
|||
|
||||
EntryPoint entry_point;
|
||||
entry_point.name = func->name();
|
||||
entry_point.remapped_name = ctx_->namer()->NameFor(func->name());
|
||||
entry_point.remapped_name = func->name();
|
||||
entry_point.stage = func->pipeline_stage();
|
||||
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
|
||||
entry_point.workgroup_size_z) = func->workgroup_size();
|
||||
|
@ -93,7 +87,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
|
|||
// if (!func) {
|
||||
// return {};
|
||||
// }
|
||||
// return ctx_->namer()->NameFor(entry_point);
|
||||
// return func->name();
|
||||
return entry_point;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,10 +72,10 @@ struct ResourceBinding {
|
|||
class Inspector {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module Shader module to extract information from.
|
||||
explicit Inspector(const ast::Module& module);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module Shader module to extract information from.
|
||||
Inspector(Context* ctx, const ast::Module& module);
|
||||
|
@ -133,8 +133,6 @@ class Inspector {
|
|||
const std::string& entry_point);
|
||||
|
||||
private:
|
||||
Context* ctx_ = nullptr;
|
||||
bool context_is_owned_ = false;
|
||||
const ast::Module& module_;
|
||||
std::string error_;
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@
|
|||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
#include "src/ast/workgroup_decoration.h"
|
||||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "tint/tint.h"
|
||||
|
||||
|
@ -70,7 +69,7 @@ namespace {
|
|||
class InspectorHelper {
|
||||
public:
|
||||
InspectorHelper()
|
||||
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)),
|
||||
: td_(std::make_unique<TypeDeterminer>(&mod_)),
|
||||
inspector_(std::make_unique<Inspector>(mod_)),
|
||||
sampler_type_(ast::type::SamplerKind::kSampler),
|
||||
comparison_sampler_type_(ast::type::SamplerKind::kComparisonSampler) {}
|
||||
|
@ -683,7 +682,6 @@ class InspectorHelper {
|
|||
}
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
std::unique_ptr<Inspector> inspector_;
|
||||
|
@ -771,12 +769,14 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
|
|||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(foo);
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetEntryPoints();
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
|
||||
ASSERT_EQ(1u, result.size());
|
||||
EXPECT_EQ("foo", result[0].name);
|
||||
EXPECT_EQ("tint_666f6f", result[0].remapped_name);
|
||||
EXPECT_EQ("foo", result[0].remapped_name);
|
||||
EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage);
|
||||
}
|
||||
|
||||
|
@ -791,15 +791,17 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
|
|||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
mod()->AddFunction(bar);
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetEntryPoints();
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
|
||||
ASSERT_EQ(2u, result.size());
|
||||
EXPECT_EQ("foo", result[0].name);
|
||||
EXPECT_EQ("tint_666f6f", result[0].remapped_name);
|
||||
EXPECT_EQ("foo", result[0].remapped_name);
|
||||
EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage);
|
||||
EXPECT_EQ("bar", result[1].name);
|
||||
EXPECT_EQ("tint_626172", result[1].remapped_name);
|
||||
EXPECT_EQ("bar", result[1].remapped_name);
|
||||
EXPECT_EQ(ast::PipelineStage::kCompute, result[1].stage);
|
||||
}
|
||||
|
||||
|
@ -817,15 +819,17 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
|
|||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
mod()->AddFunction(bar);
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetEntryPoints();
|
||||
EXPECT_FALSE(inspector()->has_error());
|
||||
|
||||
ASSERT_EQ(2u, result.size());
|
||||
EXPECT_EQ("foo", result[0].name);
|
||||
EXPECT_EQ("tint_666f6f", result[0].remapped_name);
|
||||
EXPECT_EQ("foo", result[0].remapped_name);
|
||||
EXPECT_EQ(ast::PipelineStage::kVertex, result[0].stage);
|
||||
EXPECT_EQ("bar", result[1].name);
|
||||
EXPECT_EQ("tint_626172", result[1].remapped_name);
|
||||
EXPECT_EQ("bar", result[1].remapped_name);
|
||||
EXPECT_EQ(ast::PipelineStage::kFragment, result[1].stage);
|
||||
}
|
||||
|
||||
|
@ -1017,20 +1021,22 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
|
|||
|
||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetEntryPoints();
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
|
||||
ASSERT_EQ(2u, result.size());
|
||||
|
||||
ASSERT_EQ("foo", result[0].name);
|
||||
ASSERT_EQ("tint_666f6f", result[0].remapped_name);
|
||||
ASSERT_EQ("foo", result[0].remapped_name);
|
||||
ASSERT_EQ(1u, result[0].input_variables.size());
|
||||
EXPECT_EQ("in_var", result[0].input_variables[0]);
|
||||
ASSERT_EQ(1u, result[0].output_variables.size());
|
||||
EXPECT_EQ("out2_var", result[0].output_variables[0]);
|
||||
|
||||
ASSERT_EQ("bar", result[1].name);
|
||||
ASSERT_EQ("tint_626172", result[1].remapped_name);
|
||||
ASSERT_EQ("bar", result[1].remapped_name);
|
||||
ASSERT_EQ(1u, result[1].input_variables.size());
|
||||
EXPECT_EQ("in2_var", result[1].input_variables[0]);
|
||||
ASSERT_EQ(1u, result[1].output_variables.size());
|
||||
|
@ -1056,13 +1062,15 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
|
|||
|
||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetEntryPoints();
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
|
||||
ASSERT_EQ(2u, result.size());
|
||||
|
||||
ASSERT_EQ("foo", result[0].name);
|
||||
ASSERT_EQ("tint_666f6f", result[0].remapped_name);
|
||||
ASSERT_EQ("foo", result[0].remapped_name);
|
||||
EXPECT_EQ(2u, result[0].input_variables.size());
|
||||
EXPECT_TRUE(ContainsString(result[0].input_variables, "in_var"));
|
||||
EXPECT_TRUE(ContainsString(result[0].input_variables, "in2_var"));
|
||||
|
@ -1071,7 +1079,7 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
|
|||
EXPECT_TRUE(ContainsString(result[0].output_variables, "out2_var"));
|
||||
|
||||
ASSERT_EQ("bar", result[1].name);
|
||||
ASSERT_EQ("tint_626172", result[1].remapped_name);
|
||||
ASSERT_EQ("bar", result[1].remapped_name);
|
||||
EXPECT_EQ(1u, result[1].input_variables.size());
|
||||
EXPECT_EQ("in2_var", result[1].input_variables[0]);
|
||||
EXPECT_EQ(1u, result[1].output_variables.size());
|
||||
|
@ -1106,10 +1114,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
|
|||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(foo);
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
|
||||
EXPECT_EQ("tint_666f6f", result);
|
||||
EXPECT_EQ("foo", result);
|
||||
}
|
||||
|
||||
// TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
|
||||
|
@ -1121,6 +1131,8 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
|
|||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
mod()->AddFunction(foo);
|
||||
|
||||
// TODO(dsinclair): Update to run the namer transform when available.
|
||||
|
||||
auto* bar = MakeEmptyBodyFunction("bar");
|
||||
bar->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
|
@ -1129,12 +1141,12 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest,
|
|||
{
|
||||
auto result = inspector()->GetRemappedNameForEntryPoint("foo");
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
EXPECT_EQ("tint_666f6f", result);
|
||||
EXPECT_EQ("foo", result);
|
||||
}
|
||||
{
|
||||
auto result = inspector()->GetRemappedNameForEntryPoint("bar");
|
||||
ASSERT_FALSE(inspector()->has_error()) << inspector()->error();
|
||||
EXPECT_EQ("tint_626172", result);
|
||||
EXPECT_EQ("bar", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace tint {
|
||||
namespace reader {
|
||||
|
||||
Reader::Reader(Context* ctx) : ctx_(*ctx) {}
|
||||
Reader::Reader() = default;
|
||||
|
||||
Reader::~Reader() = default;
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <utility>
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/diagnostic/diagnostic.h"
|
||||
#include "src/diagnostic/formatter.h"
|
||||
|
||||
|
@ -52,16 +51,12 @@ class Reader {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
explicit Reader(Context* ctx);
|
||||
Reader();
|
||||
|
||||
/// Sets the diagnostic messages
|
||||
/// @param diags the list of diagnostic messages
|
||||
void set_diagnostics(const diag::List& diags) { diags_ = diags; }
|
||||
|
||||
/// The Tint context object
|
||||
Context& ctx_;
|
||||
|
||||
/// All diagnostic messages from the reader.
|
||||
diag::List diags_;
|
||||
};
|
||||
|
|
|
@ -20,8 +20,11 @@ namespace tint {
|
|||
namespace reader {
|
||||
namespace spirv {
|
||||
|
||||
Parser::Parser(Context* ctx, const std::vector<uint32_t>& spv_binary)
|
||||
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, spv_binary)) {}
|
||||
Parser::Parser(const std::vector<uint32_t>& 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;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "src/context.h"
|
||||
#include "src/reader/reader.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -31,6 +32,10 @@ class ParserImpl;
|
|||
class Parser : public Reader {
|
||||
public:
|
||||
/// Creates a new parser
|
||||
/// @param input the input data to parse
|
||||
explicit Parser(const std::vector<uint32_t>& input);
|
||||
/// Creates a new parser
|
||||
/// DEPRECATED
|
||||
/// @param ctx the non-null context object
|
||||
/// @param input the input data to parse
|
||||
Parser(Context* ctx, const std::vector<uint32_t>& input);
|
||||
|
|
|
@ -192,8 +192,8 @@ bool AssumesResultSignednessMatchesBinaryFirstOperand(SpvOp opcode) {
|
|||
|
||||
} // namespace
|
||||
|
||||
ParserImpl::ParserImpl(Context* ctx, const std::vector<uint32_t>& spv_binary)
|
||||
: Reader(ctx),
|
||||
ParserImpl::ParserImpl(const std::vector<uint32_t>& spv_binary)
|
||||
: Reader(),
|
||||
spv_binary_(spv_binary),
|
||||
fail_stream_(&success_, &errors_),
|
||||
bool_type_(ast_module_.create<ast::type::Bool>()),
|
||||
|
|
|
@ -86,9 +86,8 @@ struct TypedExpression {
|
|||
class ParserImpl : Reader {
|
||||
public:
|
||||
/// Creates a new parser
|
||||
/// @param ctx the non-null context object
|
||||
/// @param input the input data to parse
|
||||
ParserImpl(Context* ctx, const std::vector<uint32_t>& input);
|
||||
explicit ParserImpl(const std::vector<uint32_t>& input);
|
||||
/// Destructor
|
||||
~ParserImpl() override;
|
||||
|
||||
|
@ -96,11 +95,6 @@ class ParserImpl : Reader {
|
|||
/// @returns true if the parse was successful, false otherwise.
|
||||
bool Parse() override;
|
||||
|
||||
/// @returns the Tint context.
|
||||
Context& context() {
|
||||
return ctx_; // Inherited from Reader
|
||||
}
|
||||
|
||||
/// @returns the module. The module in the parser will be reset after this.
|
||||
ast::Module module() override;
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "source/opt/ir_context.h"
|
||||
#include "src/context.h"
|
||||
#include "src/reader/spirv/parser_impl.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -40,7 +39,7 @@ class SpvParserTestBase : public T {
|
|||
/// @param input the SPIR-V binary to parse
|
||||
/// @returns a parser for the given binary
|
||||
std::unique_ptr<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.
|
||||
|
@ -52,9 +51,6 @@ class SpvParserTestBase : public T {
|
|||
spvtools::opt::Function* spirv_function(ParserImpl* parser, uint32_t id) {
|
||||
return parser->ir_context()->GetFunction(id);
|
||||
}
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
};
|
||||
|
||||
// Use this form when you don't need to template any further.
|
||||
|
|
|
@ -22,8 +22,10 @@ namespace tint {
|
|||
namespace reader {
|
||||
namespace wgsl {
|
||||
|
||||
Parser::Parser(Context* ctx, Source::File const* file)
|
||||
: Reader(ctx), impl_(std::make_unique<ParserImpl>(ctx, file)) {}
|
||||
Parser::Parser(Source::File const* file)
|
||||
: Reader(), impl_(std::make_unique<ParserImpl>(file)) {}
|
||||
|
||||
Parser::Parser(Context*, Source::File const* file) : Parser(file) {}
|
||||
|
||||
Parser::~Parser() = default;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "src/context.h"
|
||||
#include "src/reader/reader.h"
|
||||
#include "src/source.h"
|
||||
|
||||
|
@ -31,6 +32,10 @@ class ParserImpl;
|
|||
class Parser : public Reader {
|
||||
public:
|
||||
/// Creates a new parser from the given file.
|
||||
/// @param file the input source file to parse
|
||||
explicit Parser(Source::File const* file);
|
||||
/// Creates a new parser from the given file.
|
||||
/// DEPRECATED
|
||||
/// @param ctx the non-null context object
|
||||
/// @param file the input source file to parse
|
||||
Parser(Context* ctx, Source::File const* file);
|
||||
|
|
|
@ -186,7 +186,7 @@ struct BlockCounters {
|
|||
|
||||
} // namespace
|
||||
|
||||
ParserImpl::ParserImpl(Context*, Source::File const* file)
|
||||
ParserImpl::ParserImpl(Source::File const* file)
|
||||
: lexer_(std::make_unique<Lexer>(file)) {}
|
||||
|
||||
ParserImpl::~ParserImpl() = default;
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/ast/variable_decoration.h"
|
||||
#include "src/context.h"
|
||||
#include "src/diagnostic/diagnostic.h"
|
||||
#include "src/diagnostic/formatter.h"
|
||||
#include "src/reader/wgsl/parser_impl_detail.h"
|
||||
|
@ -231,9 +230,8 @@ class ParserImpl {
|
|||
};
|
||||
|
||||
/// Creates a new parser using the given file
|
||||
/// @param ctx the non-null context object
|
||||
/// @param file the input source file to parse
|
||||
ParserImpl(Context* ctx, Source::File const* file);
|
||||
explicit ParserImpl(Source::File const* file);
|
||||
~ParserImpl();
|
||||
|
||||
/// Run the parser
|
||||
|
|
|
@ -40,14 +40,13 @@ class ParserImplTest : public testing::Test {
|
|||
/// @returns the parser implementation
|
||||
std::unique_ptr<ParserImpl> parser(const std::string& 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));
|
||||
return impl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Source::File>> files_;
|
||||
Context ctx_;
|
||||
};
|
||||
|
||||
/// WGSL Parser test class with param
|
||||
|
@ -63,14 +62,13 @@ class ParserImplTestWithParam : public testing::TestWithParam<T> {
|
|||
/// @returns the parser implementation
|
||||
std::unique_ptr<ParserImpl> parser(const std::string& 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));
|
||||
return impl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Source::File>> files_;
|
||||
Context ctx_;
|
||||
};
|
||||
|
||||
} // namespace wgsl
|
||||
|
|
|
@ -49,9 +49,12 @@
|
|||
namespace tint {
|
||||
namespace transform {
|
||||
|
||||
BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context* ctx,
|
||||
BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(ast::Module* mod)
|
||||
: Transformer(mod) {}
|
||||
|
||||
BoundArrayAccessorsTransform::BoundArrayAccessorsTransform(Context*,
|
||||
ast::Module* mod)
|
||||
: Transformer(ctx, mod) {}
|
||||
: BoundArrayAccessorsTransform(mod) {}
|
||||
|
||||
BoundArrayAccessorsTransform::~BoundArrayAccessorsTransform() = default;
|
||||
|
||||
|
|
|
@ -35,9 +35,13 @@ namespace transform {
|
|||
class BoundArrayAccessorsTransform : public Transformer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param mod the module transform
|
||||
explicit BoundArrayAccessorsTransform(ast::Module* mod);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the Tint context object
|
||||
/// @param mod the module transform
|
||||
explicit BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod);
|
||||
BoundArrayAccessorsTransform(Context* ctx, ast::Module* mod);
|
||||
~BoundArrayAccessorsTransform() override;
|
||||
|
||||
/// Users of Tint should register the transform with transform manager and
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "src/ast/uint_literal.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/context.h"
|
||||
#include "src/transform/manager.h"
|
||||
#include "src/type_determiner.h"
|
||||
|
||||
|
@ -50,12 +49,10 @@ namespace {
|
|||
|
||||
class BoundArrayAccessorsTest : public testing::Test {
|
||||
public:
|
||||
BoundArrayAccessorsTest() : td_(&ctx_, &mod_) {
|
||||
auto transform =
|
||||
std::make_unique<BoundArrayAccessorsTransform>(&ctx_, &mod_);
|
||||
BoundArrayAccessorsTest() : td_(&mod_) {
|
||||
auto transform = std::make_unique<BoundArrayAccessorsTransform>(&mod_);
|
||||
transform_ = transform.get();
|
||||
manager_ = std::make_unique<Manager>(&ctx_, &mod_);
|
||||
manager_->append(std::move(transform));
|
||||
manager_.append(std::move(transform));
|
||||
}
|
||||
|
||||
ast::BlockStatement* SetupFunctionAndBody() {
|
||||
|
@ -74,7 +71,7 @@ class BoundArrayAccessorsTest : public testing::Test {
|
|||
|
||||
TypeDeterminer* td() { return &td_; }
|
||||
|
||||
Manager* manager() { return manager_.get(); }
|
||||
bool Run() { return manager_.Run(&mod_); }
|
||||
|
||||
/// Creates a new `ast::Node` owned by the Module. When the Module is
|
||||
/// destructed, the `ast::Node` will also be destructed.
|
||||
|
@ -86,11 +83,10 @@ class BoundArrayAccessorsTest : public testing::Test {
|
|||
}
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
TypeDeterminer td_;
|
||||
ast::type::Void void_type_;
|
||||
std::unique_ptr<Manager> manager_;
|
||||
Manager manager_;
|
||||
BoundArrayAccessorsTransform* transform_;
|
||||
ast::BlockStatement* body_ = nullptr;
|
||||
};
|
||||
|
@ -128,7 +124,7 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
|
|||
|
||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
ASSERT_TRUE(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
ASSERT_TRUE(ptr->idx_expr()->Is<ast::ConstructorExpression>());
|
||||
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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->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(manager()->Run());
|
||||
ASSERT_TRUE(Run());
|
||||
ASSERT_TRUE(ptr->Is<ast::ArrayAccessorExpression>());
|
||||
|
||||
ASSERT_TRUE(ptr->array()->Is<ast::ArrayAccessorExpression>());
|
||||
|
|
|
@ -19,12 +19,19 @@
|
|||
namespace tint {
|
||||
namespace transform {
|
||||
|
||||
Manager::Manager(Context* context, ast::Module* module)
|
||||
: context_(context), module_(module) {}
|
||||
Manager::Manager() = default;
|
||||
|
||||
Manager::Manager(Context*, ast::Module* module) : module_(module) {}
|
||||
|
||||
Manager::~Manager() = default;
|
||||
|
||||
bool Manager::Run() {
|
||||
return Run(module_);
|
||||
}
|
||||
|
||||
bool Manager::Run(ast::Module* module) {
|
||||
error_ = "";
|
||||
|
||||
for (auto& transform : transforms_) {
|
||||
if (!transform->Run()) {
|
||||
error_ = transform->error();
|
||||
|
@ -32,10 +39,10 @@ bool Manager::Run() {
|
|||
}
|
||||
}
|
||||
|
||||
if (context_ != nullptr && module_ != nullptr) {
|
||||
if (module != nullptr) {
|
||||
// The transformed have potentially inserted nodes into the AST, so the type
|
||||
// determinater needs to be run.
|
||||
TypeDeterminer td(context_, module_);
|
||||
TypeDeterminer td(module);
|
||||
if (!td.Determine()) {
|
||||
error_ = td.error();
|
||||
return false;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/context.h"
|
||||
#include "src/transform/transformer.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -31,6 +32,9 @@ namespace transform {
|
|||
class Manager {
|
||||
public:
|
||||
/// Constructor
|
||||
Manager();
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param context the tint context
|
||||
/// @param module the module to transform
|
||||
Manager(Context* context, ast::Module* module);
|
||||
|
@ -43,6 +47,11 @@ class Manager {
|
|||
}
|
||||
|
||||
/// Runs the transforms
|
||||
/// @param module the module to run the transforms on
|
||||
/// @returns true on success; false otherwise
|
||||
bool Run(ast::Module* module);
|
||||
/// Runs the transforms
|
||||
/// DEPRECATED
|
||||
/// @returns true on success; false otherwise
|
||||
bool Run();
|
||||
|
||||
|
@ -50,9 +59,8 @@ class Manager {
|
|||
std::string error() const { return error_; }
|
||||
|
||||
private:
|
||||
Context* context_;
|
||||
ast::Module* module_;
|
||||
std::vector<std::unique_ptr<Transformer>> transforms_;
|
||||
ast::Module* module_ = nullptr;
|
||||
|
||||
std::string error_;
|
||||
};
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
namespace tint {
|
||||
namespace transform {
|
||||
|
||||
Transformer::Transformer(Context* ctx, ast::Module* mod)
|
||||
: ctx_(ctx), mod_(mod) {}
|
||||
Transformer::Transformer(ast::Module* mod) : mod_(mod) {}
|
||||
|
||||
Transformer::~Transformer() = default;
|
||||
|
||||
|
|
|
@ -29,9 +29,8 @@ namespace transform {
|
|||
class Transformer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the Tint context
|
||||
/// @param mod the module to transform
|
||||
Transformer(Context* ctx, ast::Module* mod);
|
||||
explicit Transformer(ast::Module* mod);
|
||||
virtual ~Transformer();
|
||||
|
||||
/// Users of Tint should register the transform with transform manager and
|
||||
|
@ -53,8 +52,6 @@ class Transformer {
|
|||
return mod_->create<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The context
|
||||
Context* ctx_ = nullptr;
|
||||
/// The module
|
||||
ast::Module* mod_ = nullptr;
|
||||
/// Any error messages, or blank if no error
|
||||
|
|
|
@ -52,8 +52,11 @@ static const char kDefaultInstanceIndexName[] = "_tint_pulling_instance_index";
|
|||
|
||||
} // namespace
|
||||
|
||||
VertexPullingTransform::VertexPullingTransform(Context* ctx, ast::Module* mod)
|
||||
: Transformer(ctx, mod) {}
|
||||
VertexPullingTransform::VertexPullingTransform(ast::Module* mod)
|
||||
: Transformer(mod) {}
|
||||
|
||||
VertexPullingTransform::VertexPullingTransform(Context*, ast::Module* mod)
|
||||
: VertexPullingTransform(mod) {}
|
||||
|
||||
VertexPullingTransform::~VertexPullingTransform() = default;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/statement.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/context.h"
|
||||
#include "src/transform/transformer.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -147,6 +146,10 @@ struct VertexStateDescriptor {
|
|||
class VertexPullingTransform : public Transformer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param mod the module to convert to vertex pulling
|
||||
explicit VertexPullingTransform(ast::Module* mod);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the tint context
|
||||
/// @param mod the module to convert to vertex pulling
|
||||
VertexPullingTransform(Context* ctx, ast::Module* mod);
|
||||
|
|
|
@ -58,8 +58,10 @@
|
|||
|
||||
namespace tint {
|
||||
|
||||
TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod)
|
||||
: ctx_(*ctx), mod_(mod) {}
|
||||
TypeDeterminer::TypeDeterminer(ast::Module* mod) : mod_(mod) {}
|
||||
|
||||
TypeDeterminer::TypeDeterminer(Context*, ast::Module* mod)
|
||||
: TypeDeterminer(mod) {}
|
||||
|
||||
TypeDeterminer::~TypeDeterminer() = default;
|
||||
|
||||
|
|
|
@ -44,6 +44,10 @@ class Variable;
|
|||
class TypeDeterminer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param mod the module to update with typing information
|
||||
explicit TypeDeterminer(ast::Module* mod);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the tint context, must be non-null
|
||||
/// @param mod the module to update with typing information
|
||||
TypeDeterminer(Context* ctx, ast::Module* mod);
|
||||
|
@ -128,7 +132,6 @@ class TypeDeterminer {
|
|||
bool DetermineMemberAccessor(ast::MemberAccessorExpression* expr);
|
||||
bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
|
||||
|
||||
Context& ctx_;
|
||||
ast::Module* mod_;
|
||||
std::string error_;
|
||||
ScopeStack<ast::Variable*> variable_stack_;
|
||||
|
|
|
@ -84,9 +84,9 @@ class FakeExpr : public ast::Expression {
|
|||
void to_str(std::ostream&, size_t) const override {}
|
||||
};
|
||||
|
||||
class TypeDeterminerHelper : public ast::BuilderWithContextAndModule {
|
||||
class TypeDeterminerHelper : public ast::BuilderWithModule {
|
||||
public:
|
||||
TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(ctx, mod)) {}
|
||||
TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(mod)) {}
|
||||
|
||||
TypeDeterminer* td() const { return td_.get(); }
|
||||
|
||||
|
|
|
@ -22,18 +22,17 @@ namespace hlsl {
|
|||
|
||||
Generator::Generator(ast::Module 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)
|
||||
: Text(ctx, std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
Generator::Generator(Context*, ast::Module module)
|
||||
: Generator(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
out_ = std::ostringstream();
|
||||
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_);
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace hlsl {
|
|||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
|
|
|
@ -113,10 +113,7 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) {
|
|||
|
||||
} // namespace
|
||||
|
||||
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module)
|
||||
: ctx_(ctx), module_(module) {
|
||||
assert(ctx);
|
||||
}
|
||||
GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/context.h"
|
||||
#include "src/scope_stack.h"
|
||||
#include "src/writer/hlsl/namer.h"
|
||||
|
||||
|
@ -53,9 +52,8 @@ namespace hlsl {
|
|||
class GeneratorImpl {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the module to generate
|
||||
GeneratorImpl(Context* ctx, ast::Module* module);
|
||||
explicit GeneratorImpl(ast::Module* module);
|
||||
~GeneratorImpl();
|
||||
|
||||
/// Increment the emitter indent level
|
||||
|
@ -398,7 +396,6 @@ class GeneratorImpl {
|
|||
size_t indent_ = 0;
|
||||
|
||||
Namer namer_;
|
||||
Context* ctx_ = nullptr;
|
||||
ast::Module* module_ = nullptr;
|
||||
std::string current_ep_name_;
|
||||
bool generating_entry_point_ = false;
|
||||
|
|
|
@ -141,7 +141,7 @@ std::string expected_texture_overload(
|
|||
} // LINT - Ignore the length of this function
|
||||
|
||||
class HlslGeneratorIntrinsicTextureTest
|
||||
: public ast::BuilderWithContextAndModule,
|
||||
: public ast::BuilderWithModule,
|
||||
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
|
||||
protected:
|
||||
void OnVariableBuilt(ast::Variable* var) override {
|
||||
|
@ -154,9 +154,9 @@ class HlslGeneratorIntrinsicTextureTest
|
|||
std::string pre_result() const { return pre.str(); }
|
||||
|
||||
/// The type determiner
|
||||
TypeDeterminer td{ctx, mod};
|
||||
TypeDeterminer td{mod};
|
||||
/// The generator
|
||||
GeneratorImpl gen{ctx, mod};
|
||||
GeneratorImpl gen{mod};
|
||||
/// The output stream
|
||||
std::ostringstream out;
|
||||
/// The pre-output stream
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/hlsl/generator_impl.h"
|
||||
|
||||
|
@ -34,7 +33,7 @@ namespace hlsl {
|
|||
template <typename BODY>
|
||||
class TestHelperBase : public BODY {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
|
||||
TestHelperBase() : td(&mod), gen(&mod) {}
|
||||
~TestHelperBase() = default;
|
||||
|
||||
/// @returns the result string
|
||||
|
@ -52,8 +51,6 @@ class TestHelperBase : public BODY {
|
|||
return mod.create<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
ast::Module mod;
|
||||
/// The type determiner
|
||||
|
|
|
@ -22,17 +22,16 @@ namespace msl {
|
|||
|
||||
Generator::Generator(ast::Module 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)
|
||||
: Text(ctx, std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
Generator::Generator(Context*, ast::Module module)
|
||||
: Generator(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_);
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace msl {
|
|||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
|
|
|
@ -95,8 +95,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) {
|
|||
|
||||
} // namespace
|
||||
|
||||
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module)
|
||||
: TextGenerator(ctx), module_(module) {}
|
||||
GeneratorImpl::GeneratorImpl(ast::Module* module)
|
||||
: TextGenerator(), module_(module) {}
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
|
|
|
@ -54,9 +54,8 @@ namespace msl {
|
|||
class GeneratorImpl : public TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to generate
|
||||
GeneratorImpl(Context* ctx, ast::Module* module);
|
||||
explicit GeneratorImpl(ast::Module* module);
|
||||
~GeneratorImpl();
|
||||
|
||||
/// @returns true on successful generation; false otherwise
|
||||
|
|
|
@ -141,7 +141,7 @@ std::string expected_texture_overload(
|
|||
} // LINT - Ignore the length of this function
|
||||
|
||||
class MslGeneratorIntrinsicTextureTest
|
||||
: public ast::BuilderWithContextAndModule,
|
||||
: public ast::BuilderWithModule,
|
||||
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
|
||||
protected:
|
||||
void OnVariableBuilt(ast::Variable* var) override {
|
||||
|
@ -149,9 +149,9 @@ class MslGeneratorIntrinsicTextureTest
|
|||
}
|
||||
|
||||
/// The type determiner
|
||||
TypeDeterminer td{ctx, mod};
|
||||
TypeDeterminer td{mod};
|
||||
/// The generator
|
||||
GeneratorImpl gen{ctx, mod};
|
||||
GeneratorImpl gen{mod};
|
||||
};
|
||||
|
||||
TEST_P(MslGeneratorIntrinsicTextureTest, Call) {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
|
@ -32,7 +31,7 @@ namespace msl {
|
|||
template <typename BASE>
|
||||
class TestHelperBase : public BASE {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
|
||||
TestHelperBase() : td(&mod), gen(&mod) {}
|
||||
~TestHelperBase() = default;
|
||||
|
||||
/// Creates a new `ast::Node` owned by the Module. When the Module is
|
||||
|
@ -44,8 +43,6 @@ class TestHelperBase : public BASE {
|
|||
return mod.create<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
ast::Module mod;
|
||||
/// The type determiner
|
||||
|
|
|
@ -277,10 +277,9 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {}
|
|||
|
||||
Builder::AccessorInfo::~AccessorInfo() {}
|
||||
|
||||
Builder::Builder(Context* ctx, ast::Module* mod)
|
||||
: ctx_(ctx), mod_(mod), scope_stack_({}) {
|
||||
assert(ctx_);
|
||||
}
|
||||
Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {}
|
||||
|
||||
Builder::Builder(Context*, ast::Module* mod) : Builder(mod) {}
|
||||
|
||||
Builder::~Builder() = default;
|
||||
|
||||
|
@ -437,7 +436,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) {
|
|||
// the inspector and land the same change in MSL / HLSL to all roll into Dawn
|
||||
// at the same time.
|
||||
// OperandList operands = {Operand::Int(stage), Operand::Int(id),
|
||||
// Operand::String(ctx_.namer()->NameFor(func->name()))};
|
||||
// Operand::String(func->name())};
|
||||
OperandList operands = {Operand::Int(stage), Operand::Int(id),
|
||||
Operand::String(func->name())};
|
||||
|
||||
|
@ -522,8 +521,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
|
|||
auto func_id = func_op.to_i();
|
||||
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(func_id),
|
||||
Operand::String(ctx_->namer()->NameFor(func->name()))});
|
||||
{Operand::Int(func_id), Operand::String(func->name())});
|
||||
|
||||
auto ret_id = GenerateTypeIfNeeded(func->return_type());
|
||||
if (ret_id == 0) {
|
||||
|
@ -548,8 +546,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
|
|||
}
|
||||
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(param_id),
|
||||
Operand::String(ctx_->namer()->NameFor(param->name()))});
|
||||
{Operand::Int(param_id), Operand::String(param->name())});
|
||||
params.push_back(Instruction{spv::Op::OpFunctionParameter,
|
||||
{Operand::Int(param_type_id), param_op}});
|
||||
|
||||
|
@ -640,8 +637,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) {
|
|||
}
|
||||
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(var_id),
|
||||
Operand::String(ctx_->namer()->NameFor(var->name()))});
|
||||
{Operand::Int(var_id), Operand::String(var->name())});
|
||||
|
||||
// TODO(dsinclair) We could detect if the constructor is fully const and emit
|
||||
// an initializer value for the variable instead of doing the OpLoad.
|
||||
|
@ -689,8 +685,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
return false;
|
||||
}
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(init_id),
|
||||
Operand::String(ctx_->namer()->NameFor(var->name()))});
|
||||
{Operand::Int(init_id), Operand::String(var->name())});
|
||||
|
||||
scope_stack_.set_global(var->name(), init_id);
|
||||
spirv_id_to_variable_[init_id] = var;
|
||||
|
@ -711,8 +706,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
}
|
||||
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(var_id),
|
||||
Operand::String(ctx_->namer()->NameFor(var->name()))});
|
||||
{Operand::Int(var_id), Operand::String(var->name())});
|
||||
|
||||
auto* type = var->type()->UnwrapAll();
|
||||
|
||||
|
@ -2633,8 +2627,7 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type,
|
|||
|
||||
if (!struct_type->name().empty()) {
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(struct_id),
|
||||
Operand::String(ctx_->namer()->NameFor(struct_type->name()))});
|
||||
{Operand::Int(struct_id), Operand::String(struct_type->name())});
|
||||
}
|
||||
|
||||
OperandList ops;
|
||||
|
@ -2675,9 +2668,8 @@ bool Builder::GenerateStructType(ast::type::Struct* struct_type,
|
|||
uint32_t Builder::GenerateStructMember(uint32_t struct_id,
|
||||
uint32_t idx,
|
||||
ast::StructMember* member) {
|
||||
push_debug(spv::Op::OpMemberName,
|
||||
{Operand::Int(struct_id), Operand::Int(idx),
|
||||
Operand::String(ctx_->namer()->NameFor(member->name()))});
|
||||
push_debug(spv::Op::OpMemberName, {Operand::Int(struct_id), Operand::Int(idx),
|
||||
Operand::String(member->name())});
|
||||
|
||||
bool has_layout = false;
|
||||
for (auto* deco : member->decorations()) {
|
||||
|
|
|
@ -83,6 +83,10 @@ class Builder {
|
|||
};
|
||||
|
||||
/// Constructor
|
||||
/// @param mod the module to generate from
|
||||
explicit Builder(ast::Module* mod);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param mod the module to generate from
|
||||
Builder(Context* ctx, ast::Module* mod);
|
||||
|
@ -495,7 +499,6 @@ class Builder {
|
|||
return func_name_to_id_[name];
|
||||
}
|
||||
|
||||
Context* ctx_ = nullptr;
|
||||
ast::Module* mod_;
|
||||
std::string error_;
|
||||
uint32_t next_id_ = 1;
|
||||
|
|
|
@ -74,10 +74,10 @@ TEST_F(BuilderTest, Expression_Call) {
|
|||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 14u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
OpName %4 "tint_61"
|
||||
OpName %5 "tint_62"
|
||||
OpName %12 "tint_6d61696e"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
|
||||
OpName %4 "a"
|
||||
OpName %5 "b"
|
||||
OpName %12 "main"
|
||||
%2 = OpTypeFloat 32
|
||||
%1 = OpTypeFunction %2 %2 %2
|
||||
%11 = OpTypeVoid
|
||||
|
@ -136,10 +136,10 @@ TEST_F(BuilderTest, Statement_Call) {
|
|||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateStatement(&expr)) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63"
|
||||
OpName %5 "tint_61"
|
||||
OpName %6 "tint_62"
|
||||
OpName %12 "tint_6d61696e"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
|
||||
OpName %5 "a"
|
||||
OpName %6 "b"
|
||||
OpName %12 "main"
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeFloat 32
|
||||
%1 = OpTypeFunction %2 %3 %3
|
||||
|
|
|
@ -110,10 +110,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
|||
mod->AddGlobalVariable(v_wg);
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e"
|
||||
OpName %4 "tint_6d795f6f7574"
|
||||
OpName %7 "tint_6d795f7767"
|
||||
OpName %11 "tint_6d61696e"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in"
|
||||
OpName %4 "my_out"
|
||||
OpName %7 "my_wg"
|
||||
OpName %11 "main"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Input %3
|
||||
|
@ -173,10 +173,10 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
|||
mod->AddGlobalVariable(v_wg);
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f696e"
|
||||
OpName %4 "tint_6d795f6f7574"
|
||||
OpName %7 "tint_6d795f7767"
|
||||
OpName %11 "tint_6d61696e"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_in"
|
||||
OpName %4 "my_out"
|
||||
OpName %7 "my_wg"
|
||||
OpName %11 "main"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Input %3
|
||||
|
@ -252,8 +252,8 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
|
|||
OpEntryPoint Fragment %5 "main2"
|
||||
OpExecutionMode %3 OriginUpperLeft
|
||||
OpExecutionMode %5 OriginUpperLeft
|
||||
OpName %3 "tint_6d61696e31"
|
||||
OpName %5 "tint_6d61696e32"
|
||||
OpName %3 "main1"
|
||||
OpName %5 "main2"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%3 = OpFunction %2 None %1
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(BuilderTest, Function_Empty) {
|
|||
ast::Function func("a_func", {}, &void_type, create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%3 = OpFunction %2 None %1
|
||||
|
@ -71,7 +71,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) {
|
|||
ast::Function func("a_func", {}, &void_type, body);
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%3 = OpFunction %2 None %1
|
||||
|
@ -97,8 +97,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
|
|||
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -122,7 +122,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) {
|
|||
ast::Function func("a_func", {}, &void_type, body);
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%3 = OpFunction %2 None %1
|
||||
|
@ -155,9 +155,9 @@ TEST_F(BuilderTest, Function_WithParams) {
|
|||
EXPECT_TRUE(td.DetermineFunction(&func));
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63"
|
||||
OpName %5 "tint_61"
|
||||
OpName %6 "tint_62"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
|
||||
OpName %5 "a"
|
||||
OpName %6 "b"
|
||||
%2 = OpTypeFloat 32
|
||||
%3 = OpTypeInt 32 1
|
||||
%1 = OpTypeFunction %2 %2 %3
|
||||
|
@ -179,7 +179,7 @@ TEST_F(BuilderTest, Function_WithBody) {
|
|||
ast::Function func("a_func", {}, &void_type, body);
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%3 = OpFunction %2 None %1
|
||||
|
@ -302,13 +302,13 @@ OpEntryPoint GLCompute %7 "a"
|
|||
OpEntryPoint GLCompute %17 "b"
|
||||
OpExecutionMode %7 LocalSize 1 1 1
|
||||
OpExecutionMode %17 LocalSize 1 1 1
|
||||
OpName %3 "tint_44617461"
|
||||
OpMemberName %3 0 "tint_64"
|
||||
OpName %1 "tint_64617461"
|
||||
OpName %7 "tint_61"
|
||||
OpName %14 "tint_76"
|
||||
OpName %17 "tint_62"
|
||||
OpName %21 "tint_76"
|
||||
OpName %3 "Data"
|
||||
OpMemberName %3 0 "d"
|
||||
OpName %1 "data"
|
||||
OpName %7 "a"
|
||||
OpName %14 "v"
|
||||
OpName %17 "b"
|
||||
OpName %21 "v"
|
||||
OpDecorate %3 Block
|
||||
OpMemberDecorate %3 0 Offset 0
|
||||
OpDecorate %1 Binding 0
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
|||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Function %3
|
||||
|
@ -90,7 +90,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
|
@ -135,7 +135,7 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
|||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 2
|
||||
|
@ -180,8 +180,8 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
|
|||
EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_76"
|
||||
OpName %7 "tint_7632"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v"
|
||||
OpName %7 "v2"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
%2 = OpConstant %1 1
|
||||
|
@ -226,7 +226,7 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
|
|||
EXPECT_TRUE(b.GenerateFunctionVariable(&v2)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_76"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
%2 = OpConstant %1 1
|
||||
|
|
|
@ -56,7 +56,7 @@ TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
|
|||
ast::Variable v("var", ast::StorageClass::kNone, &f32);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Private %3
|
||||
|
@ -70,7 +70,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
|
|||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Output %3
|
||||
|
@ -84,7 +84,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
|||
ast::Variable v("var", ast::StorageClass::kInput, &f32);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Input %3
|
||||
|
@ -115,7 +115,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
|||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
|
@ -151,7 +151,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %5 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
|
@ -249,7 +249,7 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
|||
dv.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Location 5
|
||||
)");
|
||||
|
@ -271,7 +271,7 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
|
|||
dv.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2
|
||||
OpDecorate %1 DescriptorSet 3
|
||||
|
@ -294,7 +294,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
|||
dv.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn Position
|
||||
)");
|
||||
|
@ -318,7 +318,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
|||
create<ast::BoolLiteral>(&bool_type, true)));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 1200
|
||||
)");
|
||||
|
@ -340,7 +340,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
|||
v.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 1200
|
||||
)");
|
||||
|
@ -364,7 +364,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
|||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %2 SpecId 0
|
||||
)");
|
||||
|
@ -386,7 +386,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
|||
v.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
|
||||
)");
|
||||
|
@ -408,7 +408,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
|||
v.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
|
||||
)");
|
||||
|
@ -430,7 +430,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
|||
v.set_decorations(decos);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %4 SpecId 0
|
||||
)");
|
||||
|
@ -498,10 +498,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
|
|||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
OpMemberDecorate %3 1 NonWritable
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41"
|
||||
OpMemberName %3 0 "tint_61"
|
||||
OpMemberName %3 1 "tint_62"
|
||||
OpName %1 "tint_62"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
|
||||
OpMemberName %3 0 "a"
|
||||
OpMemberName %3 1 "b"
|
||||
OpName %1 "b"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
|
||||
%3 = OpTypeStruct %4 %4
|
||||
|
@ -533,9 +533,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
|
|||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41"
|
||||
OpMemberName %3 0 "tint_61"
|
||||
OpName %1 "tint_62"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
|
||||
OpMemberName %3 0 "a"
|
||||
OpName %1 "b"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
|
||||
%3 = OpTypeStruct %4
|
||||
|
@ -567,9 +567,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
|
|||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41"
|
||||
OpMemberName %3 0 "tint_61"
|
||||
OpName %1 "tint_62"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
|
||||
OpMemberName %3 0 "a"
|
||||
OpName %1 "b"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
|
||||
%3 = OpTypeStruct %4
|
||||
|
@ -603,12 +603,12 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
|
|||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_41"
|
||||
OpMemberName %3 0 "tint_61"
|
||||
OpName %1 "tint_62"
|
||||
OpName %7 "tint_41"
|
||||
OpMemberName %7 0 "tint_61"
|
||||
OpName %5 "tint_63"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "A"
|
||||
OpMemberName %3 0 "a"
|
||||
OpName %1 "b"
|
||||
OpName %7 "A"
|
||||
OpMemberName %7 0 "a"
|
||||
OpName %5 "c"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
|
||||
%3 = OpTypeStruct %4
|
||||
|
|
|
@ -84,7 +84,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
|||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Output %3
|
||||
|
@ -141,7 +141,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
|||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Function %3
|
||||
|
|
|
@ -52,15 +52,15 @@ namespace writer {
|
|||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
class IntrinsicBuilderTest : public ast::BuilderWithContextAndModule,
|
||||
class IntrinsicBuilderTest : public ast::BuilderWithModule,
|
||||
public testing::Test {
|
||||
protected:
|
||||
void OnVariableBuilt(ast::Variable* var) override {
|
||||
td.RegisterVariableForTesting(var);
|
||||
}
|
||||
|
||||
TypeDeterminer td{ctx, mod};
|
||||
spirv::Builder b{ctx, mod};
|
||||
TypeDeterminer td{mod};
|
||||
spirv::Builder b{mod};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -646,8 +646,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 9u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%10 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %1 "tint_6964656e74"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
OpName %1 "ident"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeFloat 32
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -677,7 +677,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -703,7 +703,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeFloat 32
|
||||
|
@ -755,7 +755,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -778,7 +778,7 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -803,7 +803,7 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeFloat 32
|
||||
|
@ -833,7 +833,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -860,7 +860,7 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeFloat 32
|
||||
|
@ -895,7 +895,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -919,7 +919,7 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -946,7 +946,7 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeFloat 32
|
||||
|
@ -975,7 +975,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeFloat 32
|
||||
|
@ -1003,7 +1003,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeFloat 32
|
||||
|
@ -1042,7 +1042,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 1
|
||||
|
@ -1068,7 +1068,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 1
|
||||
|
@ -1101,7 +1101,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 0
|
||||
|
@ -1127,7 +1127,7 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 0
|
||||
|
@ -1160,7 +1160,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 1
|
||||
|
@ -1186,7 +1186,7 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 1
|
||||
|
@ -1220,7 +1220,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 0
|
||||
|
@ -1246,7 +1246,7 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 0
|
||||
|
@ -1280,7 +1280,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 1
|
||||
|
@ -1308,7 +1308,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 1
|
||||
|
@ -1341,7 +1341,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%7 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%6 = OpTypeInt 32 0
|
||||
|
@ -1369,7 +1369,7 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) {
|
|||
|
||||
EXPECT_EQ(b.GenerateCallExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%8 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %3 "a_func"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%7 = OpTypeInt 32 0
|
||||
|
@ -1402,8 +1402,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) {
|
|||
EXPECT_EQ(b.GenerateCallExpression(&expr), 11u) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(%12 = OpExtInstImport "GLSL.std.450"
|
||||
OpName %3 "tint_615f66756e63"
|
||||
OpName %5 "tint_766172"
|
||||
OpName %3 "a_func"
|
||||
OpName %5 "var"
|
||||
%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
%9 = OpTypeFloat 32
|
||||
|
|
|
@ -1491,15 +1491,15 @@ expected_texture_overload_spirv expected_texture_overload(
|
|||
} // NOLINT - Ignore the length of this function
|
||||
|
||||
class IntrinsicTextureTest
|
||||
: public ast::BuilderWithContextAndModule,
|
||||
: public ast::BuilderWithModule,
|
||||
public testing::TestWithParam<ast::intrinsic::test::TextureOverloadCase> {
|
||||
protected:
|
||||
void OnVariableBuilt(ast::Variable* var) override {
|
||||
td.RegisterVariableForTesting(var);
|
||||
}
|
||||
|
||||
TypeDeterminer td{ctx, mod};
|
||||
spirv::Builder b{ctx, mod};
|
||||
TypeDeterminer td{mod};
|
||||
spirv::Builder b{mod};
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
|
@ -116,9 +116,9 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
|||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76"
|
||||
OpName %5 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -180,9 +180,9 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
|||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76"
|
||||
OpName %5 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -263,9 +263,9 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76"
|
||||
OpName %5 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -355,9 +355,9 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76"
|
||||
OpName %5 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -477,9 +477,9 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
|||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "tint_76"
|
||||
OpName %5 "tint_61"
|
||||
OpName %7 "tint_615f66756e63"
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
OpName %7 "a_func"
|
||||
%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
|
|
@ -287,7 +287,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
|||
EXPECT_EQ(id, 1u);
|
||||
|
||||
EXPECT_EQ(b.types().size(), 1u);
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct
|
||||
)");
|
||||
|
@ -310,8 +310,8 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
|
|||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeStruct %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct"
|
||||
OpMemberName %1 0 "a"
|
||||
)");
|
||||
}
|
||||
|
||||
|
@ -335,8 +335,8 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
|
|||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeStruct %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_6d795f737472756374"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct"
|
||||
OpMemberName %1 0 "a"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Block
|
||||
)");
|
||||
|
@ -364,9 +364,9 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
|
|||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeStruct %2 %2
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
OpMemberName %1 1 "tint_62"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
|
||||
OpMemberName %1 0 "a"
|
||||
OpMemberName %1 1 "b"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
|
||||
OpMemberDecorate %1 1 Offset 8
|
||||
|
@ -404,10 +404,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
|
|||
%7 = OpTypeMatrix %8 4
|
||||
%1 = OpTypeStruct %2 %5 %7
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
OpMemberName %1 1 "tint_62"
|
||||
OpMemberName %1 2 "tint_63"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
|
||||
OpMemberName %1 0 "a"
|
||||
OpMemberName %1 1 "b"
|
||||
OpMemberName %1 2 "c"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), "");
|
||||
}
|
||||
|
@ -447,10 +447,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
|
|||
%7 = OpTypeMatrix %8 4
|
||||
%1 = OpTypeStruct %2 %5 %7
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
OpMemberName %1 1 "tint_62"
|
||||
OpMemberName %1 2 "tint_63"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
|
||||
OpMemberName %1 0 "a"
|
||||
OpMemberName %1 1 "b"
|
||||
OpMemberName %1 2 "c"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
|
||||
OpMemberDecorate %1 0 ColMajor
|
||||
|
@ -508,10 +508,10 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
|
|||
%7 = OpTypeMatrix %8 4
|
||||
%1 = OpTypeStruct %2 %5 %7
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_53"
|
||||
OpMemberName %1 0 "tint_61"
|
||||
OpMemberName %1 1 "tint_62"
|
||||
OpMemberName %1 2 "tint_63"
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
|
||||
OpMemberName %1 0 "a"
|
||||
OpMemberName %1 1 "b"
|
||||
OpMemberName %1 2 "c"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
|
||||
OpMemberDecorate %1 0 ColMajor
|
||||
|
|
|
@ -22,18 +22,16 @@ namespace spirv {
|
|||
|
||||
Generator::Generator(ast::Module module)
|
||||
: writer::Writer(std::move(module)),
|
||||
builder_(std::make_unique<Builder>(ctx_, &module_)),
|
||||
builder_(std::make_unique<Builder>(&module_)),
|
||||
writer_(std::make_unique<BinaryWriter>()) {}
|
||||
|
||||
Generator::Generator(Context* ctx, ast::Module module)
|
||||
: writer::Writer(ctx, std::move(module)),
|
||||
builder_(std::make_unique<Builder>(ctx, &module_)),
|
||||
writer_(std::make_unique<BinaryWriter>()) {}
|
||||
Generator::Generator(Context*, ast::Module module)
|
||||
: Generator(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
builder_ = std::make_unique<Builder>(ctx_, &module_);
|
||||
builder_ = std::make_unique<Builder>(&module_);
|
||||
writer_ = std::make_unique<BinaryWriter>();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ namespace spirv {
|
|||
class Generator : public writer::Writer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
|
||||
|
@ -31,9 +30,9 @@ namespace spirv {
|
|||
|
||||
/// Helper class for testing
|
||||
template <typename BASE>
|
||||
class TestHelperBase : public ast::BuilderWithContextAndModule, public BASE {
|
||||
class TestHelperBase : public ast::BuilderWithModule, public BASE {
|
||||
public:
|
||||
TestHelperBase() : td(ctx, mod), b(ctx, mod) {}
|
||||
TestHelperBase() : td(mod), b(mod) {}
|
||||
~TestHelperBase() override = default;
|
||||
|
||||
/// The type determiner
|
||||
|
|
|
@ -21,8 +21,6 @@ namespace writer {
|
|||
|
||||
Text::Text(ast::Module module) : Writer(std::move(module)) {}
|
||||
|
||||
Text::Text(Context* ctx, ast::Module module) : Writer(ctx, std::move(module)) {}
|
||||
|
||||
Text::~Text() = default;
|
||||
|
||||
} // namespace writer
|
||||
|
|
|
@ -26,13 +26,8 @@ namespace writer {
|
|||
class Text : public Writer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Text(ast::Module module);
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the module to convert
|
||||
Text(Context* ctx, ast::Module module);
|
||||
~Text() override;
|
||||
|
||||
/// @returns the result data
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
TextGenerator::TextGenerator(Context* ctx) : ctx_(ctx) {
|
||||
assert(ctx_);
|
||||
}
|
||||
TextGenerator::TextGenerator() = default;
|
||||
|
||||
TextGenerator::~TextGenerator() = default;
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "src/context.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
|
@ -27,8 +25,7 @@ namespace writer {
|
|||
class TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
explicit TextGenerator(Context* ctx);
|
||||
TextGenerator();
|
||||
~TextGenerator();
|
||||
|
||||
/// Increment the emitter indent level
|
||||
|
@ -52,8 +49,6 @@ class TextGenerator {
|
|||
std::string error() const { return error_; }
|
||||
|
||||
protected:
|
||||
/// The context
|
||||
Context* ctx_ = nullptr;
|
||||
/// The text output stream
|
||||
std::ostringstream out_;
|
||||
/// Error generated by the generator
|
||||
|
|
|
@ -21,17 +21,16 @@ namespace writer {
|
|||
namespace wgsl {
|
||||
|
||||
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)
|
||||
: Text(ctx, std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_)) {}
|
||||
Generator::Generator(Context*, ast::Module module)
|
||||
: Generator(std::move(module)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
impl_ = std::make_unique<GeneratorImpl>(ctx_);
|
||||
impl_ = std::make_unique<GeneratorImpl>();
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace wgsl {
|
|||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace tint {
|
|||
namespace writer {
|
||||
namespace wgsl {
|
||||
|
||||
GeneratorImpl::GeneratorImpl(Context* ctx) : TextGenerator(ctx) {}
|
||||
GeneratorImpl::GeneratorImpl() : TextGenerator() {}
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ namespace wgsl {
|
|||
class GeneratorImpl : public TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
explicit GeneratorImpl(Context* ctx);
|
||||
GeneratorImpl();
|
||||
~GeneratorImpl();
|
||||
|
||||
/// Generates the result data
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
|
@ -32,7 +31,7 @@ namespace wgsl {
|
|||
template <typename BASE>
|
||||
class TestHelperBase : public BASE {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&ctx) {}
|
||||
TestHelperBase() : td(&mod), gen() {}
|
||||
|
||||
~TestHelperBase() = default;
|
||||
|
||||
|
@ -45,8 +44,6 @@ class TestHelperBase : public BASE {
|
|||
return mod.create<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
ast::Module mod;
|
||||
/// The type determiner
|
||||
|
|
|
@ -19,18 +19,9 @@
|
|||
namespace tint {
|
||||
namespace writer {
|
||||
|
||||
Writer::Writer(ast::Module module)
|
||||
: ctx_(new Context()),
|
||||
context_is_owned_(true),
|
||||
module_(std::move(module)) {}
|
||||
Writer::Writer(ast::Module module) : module_(std::move(module)) {}
|
||||
|
||||
Writer::Writer(Context* ctx, ast::Module module)
|
||||
: ctx_(ctx), context_is_owned_(false), module_(std::move(module)) {}
|
||||
|
||||
Writer::~Writer() {
|
||||
if (context_is_owned_)
|
||||
delete ctx_;
|
||||
}
|
||||
Writer::~Writer() = default;
|
||||
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
|
|
@ -50,25 +50,15 @@ class Writer {
|
|||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the tint module to convert
|
||||
explicit Writer(ast::Module module);
|
||||
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the tint module to convert
|
||||
Writer(Context* ctx, ast::Module module);
|
||||
|
||||
/// Sets the error string
|
||||
/// @param msg the error message
|
||||
void set_error(const std::string& msg) { error_ = msg; }
|
||||
|
||||
/// An error message, if an error was encountered
|
||||
std::string error_;
|
||||
/// The context
|
||||
Context* ctx_ = nullptr;
|
||||
/// Tracks if we own the context
|
||||
bool context_is_owned_ = false;
|
||||
/// The module being converted
|
||||
ast::Module module_;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue