Place the namer into the context object.
This CL moves the namer into the context object and makes it a parameter to the various generators. The old constructor is maintained until we've updated downstream repos. Bug: tint:273 Change-Id: I49b2519c4250be21fb73374b16e7c702b727078f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32580 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
8ca4561b25
commit
196e097730
3
BUILD.gn
3
BUILD.gn
|
@ -904,6 +904,7 @@ source_set("tint_unittests_spv_writer_src") {
|
|||
"src/writer/spirv/operand_test.cc",
|
||||
"src/writer/spirv/spv_dump.cc",
|
||||
"src/writer/spirv/spv_dump.h",
|
||||
"src/writer/spirv/test_helper.h",
|
||||
]
|
||||
|
||||
configs += [
|
||||
|
@ -1049,6 +1050,7 @@ source_set("tint_unittests_wgsl_writer_src") {
|
|||
"src/writer/wgsl/generator_impl_unary_op_test.cc",
|
||||
"src/writer/wgsl/generator_impl_variable_decl_statement_test.cc",
|
||||
"src/writer/wgsl/generator_impl_variable_test.cc",
|
||||
"src/writer/wgsl/test_helper.h",
|
||||
]
|
||||
|
||||
configs += [
|
||||
|
@ -1101,6 +1103,7 @@ source_set("tint_unittests_msl_writer_src") {
|
|||
"src/writer/msl/generator_impl_unary_op_test.cc",
|
||||
"src/writer/msl/generator_impl_variable_decl_statement_test.cc",
|
||||
"src/writer/msl/namer_test.cc",
|
||||
"src/writer/msl/test_helper.h",
|
||||
]
|
||||
|
||||
configs += [
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/context.h"
|
||||
#include "src/diagnostic/printer.h"
|
||||
#include "src/inspector/inspector.h"
|
||||
#include "src/namer.h"
|
||||
#include "src/reader/reader.h"
|
||||
#include "src/transform/bound_array_accessors_transform.h"
|
||||
#include "src/transform/manager.h"
|
||||
|
|
|
@ -418,7 +418,7 @@ int main(int argc, const char** argv) {
|
|||
options.format = Format::kSpvAsm;
|
||||
}
|
||||
|
||||
tint::Context ctx;
|
||||
tint::Context ctx(std::make_unique<tint::NoopNamer>());
|
||||
|
||||
std::unique_ptr<tint::reader::Reader> reader;
|
||||
std::unique_ptr<tint::Source::File> source_file;
|
||||
|
@ -532,25 +532,29 @@ 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>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::spirv::Generator>(&ctx, 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>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::wgsl::Generator>(&ctx, 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>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::msl::Generator>(&ctx, 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>(std::move(mod));
|
||||
writer =
|
||||
std::make_unique<tint::writer::hlsl::Generator>(&ctx, std::move(mod));
|
||||
}
|
||||
#endif // TINT_BUILD_HLSL_WRITER
|
||||
|
||||
|
|
|
@ -568,6 +568,7 @@ if(${TINT_BUILD_SPV_WRITER})
|
|||
writer/spirv/operand_test.cc
|
||||
writer/spirv/spv_dump.cc
|
||||
writer/spirv/spv_dump.h
|
||||
writer/spirv/test_helper.h
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -599,6 +600,7 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
writer/wgsl/generator_impl_unary_op_test.cc
|
||||
writer/wgsl/generator_impl_variable_decl_statement_test.cc
|
||||
writer/wgsl/generator_impl_variable_test.cc
|
||||
writer/wgsl/test_helper.h
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -633,6 +635,7 @@ if(${TINT_BUILD_MSL_WRITER})
|
|||
writer/msl/generator_impl_unary_op_test.cc
|
||||
writer/msl/generator_impl_variable_decl_statement_test.cc
|
||||
writer/msl/namer_test.cc
|
||||
writer/msl/test_helper.h
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include "src/namer.h"
|
||||
#include "src/type_manager.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
Context::Context() = default;
|
||||
Context::Context() : namer_(std::make_unique<HashingNamer>()) {}
|
||||
|
||||
Context::Context(std::unique_ptr<Namer> namer) : namer_(std::move(namer)) {}
|
||||
|
||||
Context::~Context() = default;
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#ifndef SRC_CONTEXT_H_
|
||||
#define SRC_CONTEXT_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "src/namer.h"
|
||||
#include "src/type_manager.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -23,8 +26,11 @@ namespace tint {
|
|||
/// the system.
|
||||
class Context {
|
||||
public:
|
||||
/// Constructs a context with an empty type manager.
|
||||
/// Constructor
|
||||
Context();
|
||||
/// Constructor
|
||||
/// @param namer the namer to set into the context
|
||||
explicit Context(std::unique_ptr<Namer> namer);
|
||||
/// Destructor
|
||||
~Context();
|
||||
/// Resets the state of this context.
|
||||
|
@ -33,8 +39,12 @@ class Context {
|
|||
/// @returns the Type Manager
|
||||
TypeManager& type_mgr() { return type_mgr_; }
|
||||
|
||||
/// @returns the namer object
|
||||
Namer* namer() const { return namer_.get(); }
|
||||
|
||||
private:
|
||||
TypeManager type_mgr_;
|
||||
std::unique_ptr<Namer> namer_;
|
||||
};
|
||||
|
||||
} // namespace tint
|
||||
|
|
|
@ -36,14 +36,22 @@
|
|||
#include "src/ast/type/type.h"
|
||||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/namer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace inspector {
|
||||
|
||||
Inspector::Inspector(const ast::Module& module) : module_(module) {}
|
||||
Inspector::Inspector(const ast::Module& module)
|
||||
: ctx_(new Context()), context_is_owned_(true), module_(module) {}
|
||||
|
||||
Inspector::~Inspector() = default;
|
||||
Inspector::Inspector(Context* ctx, const ast::Module& module)
|
||||
: ctx_(ctx), context_is_owned_(false), module_(module) {
|
||||
assert(ctx);
|
||||
}
|
||||
|
||||
Inspector::~Inspector() {
|
||||
if (context_is_owned_)
|
||||
delete ctx_;
|
||||
}
|
||||
|
||||
std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||
std::vector<EntryPoint> result;
|
||||
|
@ -55,7 +63,7 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
|||
|
||||
EntryPoint entry_point;
|
||||
entry_point.name = func->name();
|
||||
entry_point.remapped_name = namer_.NameFor(func->name());
|
||||
entry_point.remapped_name = ctx_->namer()->NameFor(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();
|
||||
|
@ -82,7 +90,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
|
|||
// if (!func) {
|
||||
// return {};
|
||||
// }
|
||||
// return namer_.NameFor(entry_point);
|
||||
// return ctx_->namer()->NameFor(entry_point);
|
||||
return entry_point;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/pipeline_stage.h"
|
||||
#include "src/context.h"
|
||||
#include "src/inspector/entry_point.h"
|
||||
#include "src/inspector/scalar.h"
|
||||
#include "src/namer.h"
|
||||
|
||||
namespace tint {
|
||||
namespace inspector {
|
||||
|
@ -72,8 +72,13 @@ struct ResourceBinding {
|
|||
class Inspector {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module Shader module to extract information from.
|
||||
explicit Inspector(const ast::Module& module);
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module Shader module to extract information from.
|
||||
Inspector(Context* ctx, const ast::Module& module);
|
||||
~Inspector();
|
||||
|
||||
/// @returns error messages from the Inspector
|
||||
|
@ -128,9 +133,10 @@ class Inspector {
|
|||
const std::string& entry_point);
|
||||
|
||||
private:
|
||||
Context* ctx_ = nullptr;
|
||||
bool context_is_owned_ = false;
|
||||
const ast::Module& module_;
|
||||
std::string error_;
|
||||
tint::Namer namer_;
|
||||
|
||||
/// @param name name of the entry point to find
|
||||
/// @returns a pointer to the entry point if it exists, otherwise returns
|
||||
|
|
21
src/namer.cc
21
src/namer.cc
|
@ -24,7 +24,16 @@ Namer::Namer() = default;
|
|||
|
||||
Namer::~Namer() = default;
|
||||
|
||||
std::string Namer::NameFor(const std::string& name) {
|
||||
bool Namer::IsMapped(const std::string& name) {
|
||||
auto it = name_map_.find(name);
|
||||
return it != name_map_.end();
|
||||
}
|
||||
|
||||
HashingNamer::HashingNamer() = default;
|
||||
|
||||
HashingNamer::~HashingNamer() = default;
|
||||
|
||||
std::string HashingNamer::NameFor(const std::string& name) {
|
||||
auto it = name_map_.find(name);
|
||||
if (it != name_map_.end()) {
|
||||
return it->second;
|
||||
|
@ -42,9 +51,13 @@ std::string Namer::NameFor(const std::string& name) {
|
|||
return ret_name.str();
|
||||
}
|
||||
|
||||
bool Namer::IsMapped(const std::string& name) {
|
||||
auto it = name_map_.find(name);
|
||||
return it != name_map_.end();
|
||||
NoopNamer::NoopNamer() = default;
|
||||
|
||||
NoopNamer::~NoopNamer() = default;
|
||||
|
||||
std::string NoopNamer::NameFor(const std::string& name) {
|
||||
name_map_[name] = name;
|
||||
return name;
|
||||
}
|
||||
|
||||
} // namespace tint
|
||||
|
|
33
src/namer.h
33
src/namer.h
|
@ -21,29 +21,52 @@
|
|||
|
||||
namespace tint {
|
||||
|
||||
/// Remaps maps names to a hashed version. This keeps the provided user input
|
||||
/// from traveling through to the backend compiler.
|
||||
/// Base class for the namers.
|
||||
class Namer {
|
||||
public:
|
||||
/// Constructor
|
||||
Namer();
|
||||
~Namer();
|
||||
virtual ~Namer();
|
||||
|
||||
/// Returns a sanitized version of |name|
|
||||
/// @param name the name to sanitize
|
||||
/// @returns the sanitized version of |name|
|
||||
std::string NameFor(const std::string& name);
|
||||
virtual std::string NameFor(const std::string& name) = 0;
|
||||
|
||||
/// Returns if the given name has been mapped already
|
||||
/// @param name the name to check
|
||||
/// @returns true if the name has been mapped
|
||||
bool IsMapped(const std::string& name);
|
||||
|
||||
private:
|
||||
protected:
|
||||
/// Map of original name to new name.
|
||||
std::unordered_map<std::string, std::string> name_map_;
|
||||
};
|
||||
|
||||
/// A namer class which hashes the name
|
||||
class HashingNamer : public Namer {
|
||||
public:
|
||||
HashingNamer();
|
||||
~HashingNamer() override;
|
||||
|
||||
/// Returns a sanitized version of |name|
|
||||
/// @param name the name to sanitize
|
||||
/// @returns the sanitized version of |name|
|
||||
std::string NameFor(const std::string& name) override;
|
||||
};
|
||||
|
||||
/// A namer which just returns the provided string
|
||||
class NoopNamer : public Namer {
|
||||
public:
|
||||
NoopNamer();
|
||||
~NoopNamer() override;
|
||||
|
||||
/// Returns |name|
|
||||
/// @param name the name
|
||||
/// @returns |name|
|
||||
std::string NameFor(const std::string& name) override;
|
||||
};
|
||||
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_NAMER_H_
|
||||
|
|
|
@ -19,26 +19,47 @@
|
|||
namespace tint {
|
||||
namespace {
|
||||
|
||||
using NamerTest = testing::Test;
|
||||
using Namer_HashingNamer_Test = testing::Test;
|
||||
|
||||
TEST_F(NamerTest, ReturnsName) {
|
||||
Namer n;
|
||||
TEST_F(Namer_HashingNamer_Test, ReturnsName) {
|
||||
HashingNamer n;
|
||||
EXPECT_EQ("tint_6d795f6e616d65", n.NameFor("my_name"));
|
||||
}
|
||||
|
||||
TEST_F(NamerTest, ReturnsSameValueForSameName) {
|
||||
Namer n;
|
||||
TEST_F(Namer_HashingNamer_Test, ReturnsSameValueForSameName) {
|
||||
HashingNamer n;
|
||||
EXPECT_EQ("tint_6e616d6531", n.NameFor("name1"));
|
||||
EXPECT_EQ("tint_6e616d6532", n.NameFor("name2"));
|
||||
EXPECT_EQ("tint_6e616d6531", n.NameFor("name1"));
|
||||
}
|
||||
|
||||
TEST_F(NamerTest, IsMapped) {
|
||||
Namer n;
|
||||
TEST_F(Namer_HashingNamer_Test, IsMapped) {
|
||||
HashingNamer n;
|
||||
EXPECT_FALSE(n.IsMapped("my_name"));
|
||||
EXPECT_EQ("tint_6d795f6e616d65", n.NameFor("my_name"));
|
||||
EXPECT_TRUE(n.IsMapped("my_name"));
|
||||
}
|
||||
|
||||
using Namer_NoopNamer_Test = testing::Test;
|
||||
|
||||
TEST_F(Namer_NoopNamer_Test, ReturnsName) {
|
||||
NoopNamer n;
|
||||
EXPECT_EQ("my_name", n.NameFor("my_name"));
|
||||
}
|
||||
|
||||
TEST_F(Namer_NoopNamer_Test, ReturnsSameValueForSameName) {
|
||||
NoopNamer n;
|
||||
EXPECT_EQ("name1", n.NameFor("name1"));
|
||||
EXPECT_EQ("name2", n.NameFor("name2"));
|
||||
EXPECT_EQ("name1", n.NameFor("name1"));
|
||||
}
|
||||
|
||||
TEST_F(Namer_NoopNamer_Test, IsMapped) {
|
||||
NoopNamer n;
|
||||
EXPECT_FALSE(n.IsMapped("my_name"));
|
||||
EXPECT_EQ("my_name", n.NameFor("my_name"));
|
||||
EXPECT_TRUE(n.IsMapped("my_name"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
|
|
@ -44,7 +44,7 @@ class Variable;
|
|||
class TypeDeterminer {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the tint context
|
||||
/// @param ctx the tint context, must be non-null
|
||||
/// @param mod the module to update with typing information
|
||||
TypeDeterminer(Context* ctx, ast::Module* mod);
|
||||
~TypeDeterminer();
|
||||
|
|
|
@ -22,14 +22,18 @@ namespace hlsl {
|
|||
|
||||
Generator::Generator(ast::Module module)
|
||||
: Text(std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(&module_)) {}
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
|
||||
Generator::Generator(Context* ctx, ast::Module module)
|
||||
: Text(ctx, std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
out_ = std::ostringstream();
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_);
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -30,8 +30,13 @@ namespace hlsl {
|
|||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
~Generator() override;
|
||||
|
||||
/// Resets the generator
|
||||
|
|
|
@ -104,7 +104,10 @@ uint32_t convert_swizzle_to_index(const std::string& swizzle) {
|
|||
|
||||
} // namespace
|
||||
|
||||
GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
|
||||
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module)
|
||||
: ctx_(ctx), module_(module) {
|
||||
assert(ctx);
|
||||
}
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "src/ast/scalar_constructor_expression.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/context.h"
|
||||
#include "src/scope_stack.h"
|
||||
#include "src/writer/hlsl/namer.h"
|
||||
|
||||
|
@ -36,8 +37,9 @@ namespace hlsl {
|
|||
class GeneratorImpl {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the module to generate
|
||||
explicit GeneratorImpl(ast::Module* module);
|
||||
GeneratorImpl(Context* ctx, ast::Module* module);
|
||||
~GeneratorImpl();
|
||||
|
||||
/// Increment the emitter indent level
|
||||
|
@ -371,6 +373,7 @@ 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;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/struct.h"
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/struct_member_decoration.h"
|
||||
|
@ -33,7 +32,7 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_F32) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("a", &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructedType(out(), &alias)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(typedef float a;
|
||||
)");
|
||||
}
|
||||
|
@ -42,7 +41,7 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_NameCollision) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("float", &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructedType(out(), &alias)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(typedef float float_tint_0;
|
||||
)");
|
||||
}
|
||||
|
@ -67,9 +66,7 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) {
|
|||
ast::type::StructType s("A", std::move(str));
|
||||
ast::type::AliasType alias("B", &s);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(gen().EmitConstructedType(out(), &alias)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct B {
|
||||
float a;
|
||||
int b;
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "ary[5]");
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "ary[idx]");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
|
|||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(), " lhs = rhs;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
|
|||
return out;
|
||||
}
|
||||
|
||||
using HlslBinaryTest = TestHelperBase<testing::TestWithParam<BinaryData>>;
|
||||
using HlslBinaryTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(HlslBinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
|
@ -59,7 +59,7 @@ TEST_P(HlslBinaryTest, Emit) {
|
|||
|
||||
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -90,7 +90,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
|
|||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(left),
|
||||
std::move(right));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "(_tint_tmp)");
|
||||
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left;
|
||||
if (_tint_tmp) {
|
||||
|
@ -113,7 +113,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
|
|||
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||
std::move(c), std::move(d)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "(_tint_tmp_0)");
|
||||
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
|
||||
if (_tint_tmp) {
|
||||
|
@ -137,7 +137,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
|
|||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(left),
|
||||
std::move(right));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "(_tint_tmp)");
|
||||
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left;
|
||||
if (!_tint_tmp) {
|
||||
|
@ -190,7 +190,7 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
|
|||
std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
|
||||
if (_tint_tmp) {
|
||||
_tint_tmp = b;
|
||||
|
@ -223,7 +223,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
|
|||
std::move(a), std::move(b)),
|
||||
std::move(c)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
|
||||
if (_tint_tmp) {
|
||||
_tint_tmp = b;
|
||||
|
@ -251,7 +251,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
|
|||
std::move(b), std::move(c)),
|
||||
std::move(d)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
||||
if (!_tint_tmp) {
|
||||
_tint_tmp = c;
|
||||
|
@ -282,7 +282,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
|
|||
|
||||
ast::VariableDeclStatement expr(std::move(var));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(bool _tint_tmp = b;
|
||||
if (_tint_tmp) {
|
||||
_tint_tmp = c;
|
||||
|
@ -309,7 +309,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
|
|||
std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalOr, std::move(b), std::move(c))));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
|
||||
if (_tint_tmp) {
|
||||
bool _tint_tmp_0 = b;
|
||||
|
@ -329,7 +329,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
|
|||
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("foo", ast::VariableList{}, &void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::BinaryExpression>(
|
||||
|
@ -354,7 +354,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
|
|||
ast::CallStatement expr(std::make_unique<ast::CallExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"), std::move(params)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(bool _tint_tmp = a;
|
||||
if (_tint_tmp) {
|
||||
_tint_tmp = b;
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
|
|||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(id)");
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
|
|||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::BitcastExpression bitcast(&i32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
|
||||
EXPECT_EQ(result(), "asint(id)");
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
|
|||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::BitcastExpression bitcast(&u32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &bitcast)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
|
||||
EXPECT_EQ(result(), "asuint(id)");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
|
|||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &b)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( {
|
||||
discard;
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
|
|||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitBlock(out(), &b)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitBlock(out, &b)) << gen.error();
|
||||
EXPECT_EQ(result(), R"({
|
||||
discard;
|
||||
})");
|
||||
|
|
|
@ -29,9 +29,9 @@ using HlslGeneratorImplTest_Break = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
|
||||
ast::BreakStatement b;
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &b)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error();
|
||||
EXPECT_EQ(result(), " break;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &call)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
||||
EXPECT_EQ(result(), "my_func()");
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &call)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
||||
EXPECT_EQ(result(), "my_func(param1, param2)");
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,9 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
gen().increment_indent();
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &call)) << gen().error();
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();
|
||||
EXPECT_EQ(result(), " my_func(param1, param2);\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitCase(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::make_unique<ast::BlockStatement>());
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitCase(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -75,9 +75,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitCase(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( case 5: {
|
||||
/* fallthrough */
|
||||
}
|
||||
|
@ -95,9 +95,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 6));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitCase(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( case 5:
|
||||
case 6: {
|
||||
break;
|
||||
|
@ -112,9 +112,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
|
|||
body->append(std::make_unique<ast::BreakStatement>());
|
||||
c.set_body(std::move(body));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitCase(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &cast)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
|
||||
EXPECT_EQ(result(), "float(id)");
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &cast)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
|
||||
EXPECT_EQ(result(), "vector<float, 3>(id)");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
|
|||
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "false");
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
|
|||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "-12345");
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
|
|||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "56779u");
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
|
|||
&f32, static_cast<float>((1 << 30) - 4));
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "1.07374182e+09f");
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&f32, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "float(-1.20000004e-05f)");
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&b, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "bool(true)");
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&i32, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "int(-12345)");
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&u32, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "uint(12345u)");
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&vec, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
"vector<float, 3>(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
|
|||
ast::ExpressionList values;
|
||||
ast::TypeConstructorExpression expr(&vec, std::move(values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "vector<float, 3>(0.0f)");
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
|
||||
// A matrix of type T with n columns and m rows can also be constructed from
|
||||
// n vectors of type T with m components.
|
||||
|
@ -233,7 +233,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
|
||||
|
||||
ASSERT_TRUE(gen().EmitConstructor(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
std::string("{") +
|
||||
"vector<float, 3>(1.00000000f, 2.00000000f, 3.00000000f), " +
|
||||
|
|
|
@ -29,9 +29,9 @@ using HlslGeneratorImplTest_Continue = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
|
||||
ast::ContinueStatement c;
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &c)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &c)) << gen.error();
|
||||
EXPECT_EQ(result(), " continue;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,9 @@ using HlslGeneratorImplTest_Discard = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
|
||||
ast::DiscardStatement stmt;
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " discard;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -65,11 +65,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
|
@ -87,13 +87,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct vtx_main_in {
|
||||
float foo : TEXCOORD0;
|
||||
int bar : TEXCOORD1;
|
||||
|
@ -127,11 +126,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
|
@ -149,13 +148,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct vtx_main_out {
|
||||
float foo : TEXCOORD0;
|
||||
int bar : TEXCOORD1;
|
||||
|
@ -189,11 +187,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
|
@ -210,13 +208,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct main_in {
|
||||
float foo : TEXCOORD0;
|
||||
int bar : TEXCOORD1;
|
||||
|
@ -250,11 +247,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
|
@ -271,13 +268,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct main_out {
|
||||
float foo : SV_Target0;
|
||||
int bar : SV_Target1;
|
||||
|
@ -308,11 +304,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
|
@ -329,14 +325,13 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_FALSE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
EXPECT_EQ(gen().error(), R"(invalid location variable for pipeline stage)");
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_FALSE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||
|
@ -361,11 +356,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
|
@ -382,14 +377,13 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_FALSE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
EXPECT_EQ(gen().error(), R"(invalid location variable for pipeline stage)");
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_FALSE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_EntryPoint,
|
||||
|
@ -425,11 +419,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td().RegisterVariableForTesting(depth_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod()->AddGlobalVariable(std::move(depth_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
|
@ -446,13 +440,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
std::make_unique<ast::IdentifierExpression>("x"))));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
std::unordered_set<std::string> globals;
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().EmitEntryPointData(out(), func_ptr, globals))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(out, func_ptr, globals)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct main_in {
|
||||
vector<float, 4> coord : SV_Position;
|
||||
};
|
||||
|
|
|
@ -64,10 +64,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
gen().increment_indent();
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( void my_func() {
|
||||
return;
|
||||
}
|
||||
|
@ -85,10 +85,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
gen().increment_indent();
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( void GeometryShader_tint_0() {
|
||||
return;
|
||||
}
|
||||
|
@ -114,10 +114,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
gen().increment_indent();
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( void my_func(float a, int b) {
|
||||
return;
|
||||
}
|
||||
|
@ -142,11 +142,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -161,10 +161,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct frag_main_in {
|
||||
float foo : TEXCOORD0;
|
||||
};
|
||||
|
@ -204,11 +204,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td().RegisterVariableForTesting(depth_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod()->AddGlobalVariable(std::move(depth_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -225,10 +225,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct frag_main_in {
|
||||
vector<float, 4> coord : SV_Position;
|
||||
};
|
||||
|
@ -261,8 +261,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -281,10 +281,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(cbuffer : register(b0) {
|
||||
vector<float, 4> coord;
|
||||
};
|
||||
|
@ -316,15 +316,15 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"uniforms", ast::StorageClass::kUniform, &s));
|
||||
|
||||
mod()->AddConstructedType(&s);
|
||||
mod.AddConstructedType(&s);
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::BindingDecoration>(0, Source{}));
|
||||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -345,10 +345,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct Uniforms {
|
||||
vector<float, 4> coord;
|
||||
};
|
||||
|
@ -397,8 +397,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -417,10 +417,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(RWByteAddressBuffer coord : register(u0);
|
||||
|
||||
void frag_main() {
|
||||
|
@ -465,8 +465,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -485,10 +485,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(ByteAddressBuffer coord : register(u0);
|
||||
|
||||
void frag_main() {
|
||||
|
@ -533,9 +533,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
|
@ -555,10 +555,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(RWByteAddressBuffer coord : register(u0);
|
||||
|
||||
void frag_main() {
|
||||
|
@ -592,13 +592,13 @@ TEST_F(
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
val_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(foo_var.get());
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
td().RegisterVariableForTesting(val_var.get());
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(val_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(foo_var));
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
mod()->AddGlobalVariable(std::move(val_var));
|
||||
mod.AddGlobalVariable(std::move(foo_var));
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
mod.AddGlobalVariable(std::move(val_var));
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(std::make_unique<ast::Variable>(
|
||||
|
@ -617,7 +617,7 @@ TEST_F(
|
|||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
sub_func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(sub_func));
|
||||
mod.AddFunction(std::move(sub_func));
|
||||
|
||||
auto func_1 =
|
||||
std::make_unique<ast::Function>("ep_1", std::move(params), &void_type);
|
||||
|
@ -637,10 +637,10 @@ TEST_F(
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func_1->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func_1));
|
||||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct ep_1_in {
|
||||
float foo : TEXCOORD0;
|
||||
};
|
||||
|
@ -680,9 +680,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(depth_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(depth_var));
|
||||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(std::make_unique<ast::Variable>(
|
||||
|
@ -695,7 +695,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
std::make_unique<ast::IdentifierExpression>("param")));
|
||||
sub_func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(sub_func));
|
||||
mod.AddFunction(std::move(sub_func));
|
||||
|
||||
auto func_1 =
|
||||
std::make_unique<ast::Function>("ep_1", std::move(params), &void_type);
|
||||
|
@ -715,10 +715,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func_1->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func_1));
|
||||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct ep_1_out {
|
||||
float depth : SV_Depth;
|
||||
};
|
||||
|
@ -759,11 +759,11 @@ TEST_F(
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td().RegisterVariableForTesting(depth_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod()->AddGlobalVariable(std::move(depth_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(std::make_unique<ast::Variable>(
|
||||
|
@ -781,7 +781,7 @@ TEST_F(
|
|||
std::make_unique<ast::IdentifierExpression>("param")));
|
||||
sub_func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(sub_func));
|
||||
mod.AddFunction(std::move(sub_func));
|
||||
|
||||
auto func_1 =
|
||||
std::make_unique<ast::Function>("ep_1", std::move(params), &void_type);
|
||||
|
@ -801,10 +801,10 @@ TEST_F(
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func_1->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func_1));
|
||||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct ep_1_in {
|
||||
vector<float, 4> coord : SV_Position;
|
||||
};
|
||||
|
@ -842,9 +842,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(std::make_unique<ast::Variable>(
|
||||
|
@ -859,7 +859,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
std::make_unique<ast::IdentifierExpression>("x"))));
|
||||
sub_func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(sub_func));
|
||||
mod.AddFunction(std::move(sub_func));
|
||||
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
&void_type);
|
||||
|
@ -881,10 +881,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(cbuffer : register(b0) {
|
||||
vector<float, 4> coord;
|
||||
};
|
||||
|
@ -916,9 +916,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(std::make_unique<ast::Variable>(
|
||||
|
@ -933,7 +933,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
std::make_unique<ast::IdentifierExpression>("x"))));
|
||||
sub_func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(sub_func));
|
||||
mod.AddFunction(std::move(sub_func));
|
||||
|
||||
auto func = std::make_unique<ast::Function>("frag_main", std::move(params),
|
||||
&void_type);
|
||||
|
@ -955,10 +955,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(RWByteAddressBuffer coord : register(u0);
|
||||
|
||||
float sub_func(float param) {
|
||||
|
@ -985,8 +985,8 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td().RegisterVariableForTesting(bar_var.get());
|
||||
mod()->AddGlobalVariable(std::move(bar_var));
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func_1 =
|
||||
|
@ -1015,10 +1015,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func_1->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func_1));
|
||||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct ep_1_out {
|
||||
float bar : SV_Target1;
|
||||
};
|
||||
|
@ -1044,9 +1044,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(void GeometryShader_tint_0() {
|
||||
}
|
||||
|
||||
|
@ -1067,10 +1067,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"([numthreads(1, 1, 1)]
|
||||
void main() {
|
||||
return;
|
||||
|
@ -1095,10 +1095,10 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"([numthreads(2, 4, 6)]
|
||||
void main() {
|
||||
return;
|
||||
|
@ -1123,10 +1123,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
gen().increment_indent();
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( void my_func(float a[5]) {
|
||||
return;
|
||||
}
|
||||
|
@ -1180,9 +1180,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(0, Source{}));
|
||||
data_var->set_decorations(std::move(decos));
|
||||
|
||||
mod()->AddConstructedType(&s);
|
||||
td().RegisterVariableForTesting(data_var.get());
|
||||
mod()->AddGlobalVariable(std::move(data_var));
|
||||
mod.AddConstructedType(&s);
|
||||
td.RegisterVariableForTesting(data_var.get());
|
||||
mod.AddGlobalVariable(std::move(data_var));
|
||||
|
||||
{
|
||||
ast::VariableList params;
|
||||
|
@ -1202,7 +1202,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1223,11 +1223,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct Data {
|
||||
float d;
|
||||
};
|
||||
|
|
|
@ -25,14 +25,14 @@ using HlslGeneratorImplTest_Identifier = TestHelper;
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) {
|
||||
ast::IdentifierExpression i("foo");
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), "foo");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Identifier,
|
||||
EmitIdentifierExpression_Single_WithCollision) {
|
||||
ast::IdentifierExpression i("virtual");
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), "virtual_tint_0");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,9 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( if (cond) {
|
||||
return;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( if (cond) {
|
||||
return;
|
||||
} else {
|
||||
|
@ -84,9 +84,9 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( if (cond) {
|
||||
return;
|
||||
} else {
|
||||
|
@ -116,9 +116,9 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &i)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( if (cond) {
|
||||
return;
|
||||
} else {
|
||||
|
|
|
@ -47,8 +47,7 @@ inline std::ostream& operator<<(std::ostream& out, HlslImportData data) {
|
|||
return out;
|
||||
}
|
||||
|
||||
using HlslImportData_SingleParamTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_SingleParamTest = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -61,8 +60,8 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
|
|||
auto ident = std::make_unique<ast::IdentifierExpression>(param.name);
|
||||
ast::CallExpression expr(std::move(ident), std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.00000000f)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
||||
|
@ -93,8 +92,7 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
|||
HlslImportData{"tanh", "tanh"},
|
||||
HlslImportData{"trunc", "trunc"}));
|
||||
|
||||
using HlslImportData_SingleIntParamTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_SingleIntParamTest = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -108,16 +106,15 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
||||
HlslImportData_SingleIntParamTest,
|
||||
testing::Values(HlslImportData{"abs", "abs"}));
|
||||
|
||||
using HlslImportData_DualParamTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_DualParamTest = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_DualParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -133,8 +130,8 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
std::string(param.hlsl_name) + "(1.00000000f, 2.00000000f)");
|
||||
}
|
||||
|
@ -148,8 +145,7 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
|||
HlslImportData{"reflect", "reflect"},
|
||||
HlslImportData{"step", "step"}));
|
||||
|
||||
using HlslImportData_DualParam_VectorTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_DualParam_VectorTest = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -181,8 +177,8 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
std::string(param.hlsl_name) +
|
||||
"(vector<float, 3>(1.00000000f, 2.00000000f, 3.00000000f), "
|
||||
|
@ -192,8 +188,7 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
|||
HlslImportData_DualParam_VectorTest,
|
||||
testing::Values(HlslImportData{"cross", "cross"}));
|
||||
|
||||
using HlslImportData_DualParam_Int_Test =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_DualParam_Int_Test = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -209,8 +204,8 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
||||
|
@ -218,8 +213,7 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
|||
testing::Values(HlslImportData{"max", "max"},
|
||||
HlslImportData{"min", "min"}));
|
||||
|
||||
using HlslImportData_TripleParamTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_TripleParamTest = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -237,8 +231,8 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(param.hlsl_name) +
|
||||
"(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
}
|
||||
|
@ -254,8 +248,7 @@ TEST_F(HlslGeneratorImplTest_Import, DISABLED_HlslImportData_FMix) {
|
|||
FAIL();
|
||||
}
|
||||
|
||||
using HlslImportData_TripleParam_Int_Test =
|
||||
TestHelperBase<testing::TestWithParam<HlslImportData>>;
|
||||
using HlslImportData_TripleParam_Int_Test = TestParamHelper<HlslImportData>;
|
||||
TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -273,8 +266,8 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2, 3)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
|
||||
|
@ -295,12 +288,12 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
|
|||
std::make_unique<ast::IdentifierExpression>("determinant"),
|
||||
std::move(params));
|
||||
|
||||
mod()->AddGlobalVariable(std::move(var));
|
||||
mod.AddGlobalVariable(std::move(var));
|
||||
|
||||
// Register the global
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitCall(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string("determinant(var)"));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ inline std::ostream& operator<<(std::ostream& out, IntrinsicData data) {
|
|||
out << data.hlsl_name;
|
||||
return out;
|
||||
}
|
||||
using HlslIntrinsicTest = TestHelperBase<testing::TestWithParam<IntrinsicData>>;
|
||||
using HlslIntrinsicTest = TestParamHelper<IntrinsicData>;
|
||||
TEST_P(HlslIntrinsicTest, Emit) {
|
||||
auto param = GetParam();
|
||||
EXPECT_EQ(gen().generate_intrinsic_name(param.intrinsic), param.hlsl_name);
|
||||
EXPECT_EQ(gen.generate_intrinsic_name(param.intrinsic), param.hlsl_name);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
HlslGeneratorImplTest_Intrinsic,
|
||||
|
@ -89,22 +89,22 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
|
|||
std::make_unique<ast::IdentifierExpression>("outer_product"),
|
||||
std::move(params));
|
||||
|
||||
td().RegisterVariableForTesting(a.get());
|
||||
td().RegisterVariableForTesting(b.get());
|
||||
td.RegisterVariableForTesting(a.get());
|
||||
td.RegisterVariableForTesting(b.get());
|
||||
|
||||
mod()->AddGlobalVariable(std::move(a));
|
||||
mod()->AddGlobalVariable(std::move(b));
|
||||
mod.AddGlobalVariable(std::move(a));
|
||||
mod.AddGlobalVariable(std::move(b));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&call)) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
|
||||
gen().increment_indent();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &call)) << gen().error();
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
||||
EXPECT_EQ(result(), " float3x2(a * b[0], a * b[1], a * b[2])");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Bad_Name) {
|
||||
EXPECT_EQ(gen().generate_intrinsic_name(ast::Intrinsic::kNone), "");
|
||||
EXPECT_EQ(gen.generate_intrinsic_name(ast::Intrinsic::kNone), "");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
||||
|
@ -121,13 +121,13 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
|||
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);
|
||||
ast::Variable v2("param2", ast::StorageClass::kFunction, &vec);
|
||||
|
||||
td().RegisterVariableForTesting(&v1);
|
||||
td().RegisterVariableForTesting(&v2);
|
||||
td.RegisterVariableForTesting(&v1);
|
||||
td.RegisterVariableForTesting(&v2);
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&call)) << td().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
|
||||
gen().increment_indent();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &call)) << gen().error();
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
|
||||
EXPECT_EQ(result(), " dot(param1, param2)");
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
|||
body->append(std::make_unique<ast::DiscardStatement>());
|
||||
|
||||
ast::LoopStatement l(std::move(body), {});
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &l)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( for(;;) {
|
||||
discard;
|
||||
}
|
||||
|
@ -55,9 +55,9 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
|||
continuing->append(std::make_unique<ast::ReturnStatement>());
|
||||
|
||||
ast::LoopStatement l(std::move(body), std::move(continuing));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &l)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( {
|
||||
bool tint_hlsl_is_first_1 = true;
|
||||
for(;;) {
|
||||
|
@ -95,9 +95,9 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
|||
std::move(lhs), std::move(rhs)));
|
||||
|
||||
ast::LoopStatement outer(std::move(body), std::move(continuing));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &outer)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( {
|
||||
bool tint_hlsl_is_first_1 = true;
|
||||
for(;;) {
|
||||
|
@ -165,9 +165,9 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
|
|||
std::move(lhs), std::move(rhs)));
|
||||
|
||||
ast::LoopStatement outer(std::move(body), std::move(continuing));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &outer)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( {
|
||||
bool tint_hlsl_is_first_1 = true;
|
||||
float lhs;
|
||||
|
|
|
@ -69,12 +69,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
|
|||
|
||||
ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
|
||||
|
||||
td().RegisterVariableForTesting(str_var.get());
|
||||
gen().register_global(str_var.get());
|
||||
mod()->AddGlobalVariable(std::move(str_var));
|
||||
td.RegisterVariableForTesting(str_var.get());
|
||||
gen.register_global(str_var.get());
|
||||
mod.AddGlobalVariable(std::move(str_var));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "str.mem");
|
||||
}
|
||||
|
||||
|
@ -117,14 +117,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load(4))");
|
||||
}
|
||||
|
||||
|
@ -167,14 +167,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asint(data.Load(0))");
|
||||
}
|
||||
TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
||||
|
@ -225,17 +225,17 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
td().RegisterVariableForTesting(b_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
gen().register_global(b_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
mod()->AddGlobalVariable(std::move(b_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(b_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
gen.register_global(b_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
mod.AddGlobalVariable(std::move(b_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(matrix<float, 3, 2> _tint_tmp = b;
|
||||
data.Store3(4 + 0, asuint(_tint_tmp[0]));
|
||||
data.Store3(4 + 16, asuint(_tint_tmp[1]));
|
||||
|
@ -289,14 +289,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
R"(matrix<float, 3, 2> _tint_tmp = matrix<float, 3, 2>(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
@ -346,14 +346,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
"asfloat(matrix<uint, 2, 3>(data.Load2(4 + 0), data.Load2(4 + 8), "
|
||||
"data.Load2(4 + 16)))");
|
||||
|
@ -403,14 +403,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
"asfloat(matrix<uint, 3, 2>(data.Load3(4 + 0), data.Load3(4 + 16)))");
|
||||
|
@ -451,14 +451,14 @@ TEST_F(
|
|||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
"asfloat(matrix<uint, 3, 3>(data.Load3(0 + 0), data.Load3(0 + 16), "
|
||||
"data.Load3(0 + 32)))");
|
||||
|
@ -510,14 +510,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load((4 * 1) + (16 * 2) + 16))");
|
||||
}
|
||||
|
||||
|
@ -560,14 +560,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asint(data.Load((4 * 2) + 0))");
|
||||
}
|
||||
|
||||
|
@ -618,14 +618,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr)) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asint(data.Load((4 * ((2 + 4) - 3)) + 0))");
|
||||
}
|
||||
|
||||
|
@ -665,11 +665,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &s));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
|
@ -678,8 +678,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f));
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(data.Store(4, asuint(2.00000000f));
|
||||
)");
|
||||
}
|
||||
|
@ -717,11 +717,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &s));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lhs = std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
|
@ -733,8 +733,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign)) << td().error();
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(data.Store((4 * 2) + 0, asuint(2));
|
||||
)");
|
||||
}
|
||||
|
@ -775,11 +775,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &s));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
|
@ -788,8 +788,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(data.Store(0, asuint(2));
|
||||
)");
|
||||
}
|
||||
|
@ -832,18 +832,18 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &s));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load3(16))");
|
||||
}
|
||||
|
||||
|
@ -885,11 +885,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &s));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f);
|
||||
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f);
|
||||
|
@ -910,8 +910,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
R"(data.Store3(16, asuint(vector<float, 3>(1.00000000f, 2.00000000f, 3.00000000f)));
|
||||
|
@ -974,11 +974,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
|
@ -989,8 +989,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load3(16 + (32 * 2) + 0))");
|
||||
}
|
||||
|
||||
|
@ -1050,11 +1050,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
|
@ -1067,8 +1067,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::IdentifierExpression>("b")),
|
||||
std::make_unique<ast::IdentifierExpression>("xy"));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load3(16 + (32 * 2) + 0)).xy");
|
||||
}
|
||||
|
||||
|
@ -1129,11 +1129,11 @@ TEST_F(
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
|
@ -1146,8 +1146,8 @@ TEST_F(
|
|||
std::make_unique<ast::IdentifierExpression>("b")),
|
||||
std::make_unique<ast::IdentifierExpression>("g"));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load((4 * 1) + 16 + (32 * 2) + 0))");
|
||||
}
|
||||
|
||||
|
@ -1207,11 +1207,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
ast::ArrayAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
|
@ -1225,8 +1225,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &expr)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr));
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
|
||||
EXPECT_EQ(result(), "asfloat(data.Load((4 * 1) + 16 + (32 * 2) + 0))");
|
||||
}
|
||||
|
||||
|
@ -1286,11 +1286,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
|
@ -1317,8 +1317,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
R"(data.Store3(16 + (32 * 2) + 0, asuint(vector<float, 3>(1.00000000f, 2.00000000f, 3.00000000f)));
|
||||
|
@ -1381,11 +1381,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &pre_struct));
|
||||
|
||||
td().RegisterVariableForTesting(coord_var.get());
|
||||
gen().register_global(coord_var.get());
|
||||
mod()->AddGlobalVariable(std::move(coord_var));
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
gen.register_global(coord_var.get());
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ASSERT_TRUE(td().Determine()) << td().error();
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
auto lhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
|
@ -1403,8 +1403,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td().DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &assign)) << gen().error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign));
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error();
|
||||
EXPECT_EQ(result(),
|
||||
R"(data.Store((4 * 1) + 16 + (32 * 2) + 0, asuint(1.00000000f));
|
||||
)");
|
||||
|
|
|
@ -51,8 +51,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
|
|||
var->set_constructor(
|
||||
std::make_unique<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitProgramConstVariable(out(), var.get()))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
"static const float pos[3] = {1.00000000f, 2.00000000f, 3.00000000f};\n");
|
||||
|
@ -71,8 +70,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
|
|||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
ASSERT_TRUE(gen().EmitProgramConstVariable(out(), var.get()))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error();
|
||||
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
|
||||
#define WGSL_SPEC_CONSTANT_23 3.00000000f
|
||||
#endif
|
||||
|
@ -92,8 +90,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
|
|||
var->set_decorations(std::move(decos));
|
||||
var->set_is_const(true);
|
||||
|
||||
ASSERT_TRUE(gen().EmitProgramConstVariable(out(), var.get()))
|
||||
<< gen().error();
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error();
|
||||
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
|
||||
#error spec constant required for constant id 23
|
||||
#endif
|
||||
|
|
|
@ -29,18 +29,18 @@ using HlslGeneratorImplTest_Return = TestHelper;
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
|
||||
ast::ReturnStatement r;
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &r)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error();
|
||||
EXPECT_EQ(result(), " return;\n");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
ast::ReturnStatement r(std::move(expr));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &r)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error();
|
||||
EXPECT_EQ(result(), " return expr;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
|
|||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
ast::SwitchStatement s(std::move(cond), std::move(body));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &s)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error();
|
||||
EXPECT_EQ(result(), R"( switch(cond) {
|
||||
case 5: {
|
||||
break;
|
||||
|
|
|
@ -31,9 +31,9 @@ TEST_F(HlslGeneratorImplTest, Generate) {
|
|||
ast::type::VoidType void_type;
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod()->AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen().Generate(out())) << gen().error();
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(void my_func() {
|
||||
}
|
||||
|
||||
|
@ -41,22 +41,22 @@ TEST_F(HlslGeneratorImplTest, Generate) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest, InputStructName) {
|
||||
ASSERT_EQ(gen().generate_name("func_main_in"), "func_main_in");
|
||||
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) {
|
||||
// Register the struct name as existing.
|
||||
auto* namer = gen().namer_for_testing();
|
||||
auto* namer = gen.namer_for_testing();
|
||||
namer->NameFor("func_main_out");
|
||||
|
||||
ASSERT_EQ(gen().generate_name("func_main_out"), "func_main_out_0");
|
||||
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_0");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) {
|
||||
ASSERT_EQ(gen().generate_name("func_main_in"), "func_main_in");
|
||||
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
|
||||
|
||||
ast::IdentifierExpression ident("func_main_in");
|
||||
ASSERT_TRUE(gen().EmitIdentifier(pre(), out(), &ident));
|
||||
ASSERT_TRUE(gen.EmitIdentifier(pre, out, &ident));
|
||||
EXPECT_EQ(result(), "func_main_in_0");
|
||||
}
|
||||
|
||||
|
@ -68,11 +68,10 @@ inline std::ostream& operator<<(std::ostream& out, HlslBuiltinData data) {
|
|||
out << data.builtin;
|
||||
return out;
|
||||
}
|
||||
using HlslBuiltinConversionTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslBuiltinData>>;
|
||||
using HlslBuiltinConversionTest = TestParamHelper<HlslBuiltinData>;
|
||||
TEST_P(HlslBuiltinConversionTest, Emit) {
|
||||
auto params = GetParam();
|
||||
EXPECT_EQ(gen().builtin_to_attribute(params.builtin),
|
||||
EXPECT_EQ(gen.builtin_to_attribute(params.builtin),
|
||||
std::string(params.attribute_name));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
|
@ -47,7 +47,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("alias", &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &alias, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "alias");
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("bool", &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &alias, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool_tint_0");
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) {
|
|||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &a, "ary")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &a, "ary")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool ary[4]");
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
|
|||
ast::type::ArrayType a(&b, 4);
|
||||
ast::type::ArrayType c(&a, 5);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &c, "ary")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &c, "ary")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool ary[5][4]");
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ TEST_F(HlslGeneratorImplTest_Type,
|
|||
ast::type::ArrayType c(&a, 5);
|
||||
ast::type::ArrayType d(&c);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &c, "ary")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &c, "ary")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool ary[5][4][1]");
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
|
|||
ast::type::ArrayType c(&a, 5);
|
||||
ast::type::ArrayType d(&c, 6);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &d, "ary")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &d, "ary")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool ary[6][5][4]");
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_NameCollision) {
|
|||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &a, "bool")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &a, "bool")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool bool_tint_0[4]");
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
|
|||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &a, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &a, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool[4]");
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) {
|
|||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &a, "ary")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &a, "ary")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool ary[]");
|
||||
}
|
||||
|
||||
|
@ -127,28 +127,28 @@ TEST_F(HlslGeneratorImplTest_Type,
|
|||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &a, "double")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &a, "double")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool double_tint_0[]");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
|
||||
ast::type::BoolType b;
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &b, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &b, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "bool");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &f32, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &f32, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "float");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &i32, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &i32, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "int");
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType m(&f32, 3, 2);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &m, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &m, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "matrix<float, 3, 2>");
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::PointerType p(&f32, ast::StorageClass::kWorkgroup);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &p, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &p, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "float*");
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStructType(out(), &s, "S")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct S {
|
||||
int a;
|
||||
float b;
|
||||
|
@ -215,7 +215,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "S");
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct {
|
||||
int8_t pad_0[4];
|
||||
int a;
|
||||
|
@ -274,7 +274,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStructType(out(), &s, "S")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct S {
|
||||
int double_tint_0;
|
||||
float float_tint_0;
|
||||
|
@ -305,7 +305,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ASSERT_TRUE(gen().EmitStructType(out(), &s, "B")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStructType(out, &s, "B")) << gen.error();
|
||||
EXPECT_EQ(result(), R"(struct B {
|
||||
int a;
|
||||
float b;
|
||||
|
@ -315,7 +315,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
|
||||
ast::type::U32Type u32;
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &u32, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &u32, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "uint");
|
||||
}
|
||||
|
||||
|
@ -323,28 +323,28 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VectorType v(&f32, 3);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &v, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &v, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "vector<float, 3>");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
|
||||
ast::type::VoidType v;
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &v, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &v, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "void");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
|
||||
ast::type::SamplerType sampler(ast::type::SamplerKind::kSampler);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &sampler, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "SamplerState");
|
||||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
|
||||
ast::type::SamplerType sampler(ast::type::SamplerKind::kComparisonSampler);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &sampler, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &sampler, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "SamplerComparisonState");
|
||||
}
|
||||
|
||||
|
@ -356,14 +356,13 @@ inline std::ostream& operator<<(std::ostream& out, HlslDepthTextureData data) {
|
|||
out << data.dim;
|
||||
return out;
|
||||
}
|
||||
using HlslDepthtexturesTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslDepthTextureData>>;
|
||||
using HlslDepthtexturesTest = TestParamHelper<HlslDepthTextureData>;
|
||||
TEST_P(HlslDepthtexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::type::DepthTextureType s(params.dim);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -385,15 +384,14 @@ inline std::ostream& operator<<(std::ostream& out, HlslTextureData data) {
|
|||
out << data.dim;
|
||||
return out;
|
||||
}
|
||||
using HlslSampledtexturesTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslTextureData>>;
|
||||
using HlslSampledtexturesTest = TestParamHelper<HlslTextureData>;
|
||||
TEST_P(HlslSampledtexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::type::F32Type f32;
|
||||
ast::type::SampledTextureType s(params.dim, &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -415,7 +413,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::MultisampledTextureType s(ast::type::TextureDimension::k2d, &f32);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), "Texture2D");
|
||||
}
|
||||
|
||||
|
@ -429,8 +427,7 @@ inline std::ostream& operator<<(std::ostream& out,
|
|||
out << data.dim << (data.ro ? "ReadOnly" : "WriteOnly");
|
||||
return out;
|
||||
}
|
||||
using HlslStoragetexturesTest =
|
||||
TestHelperBase<testing::TestWithParam<HlslStorageTextureData>>;
|
||||
using HlslStoragetexturesTest = TestParamHelper<HlslStorageTextureData>;
|
||||
TEST_P(HlslStoragetexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
|
@ -439,7 +436,7 @@ TEST_P(HlslStoragetexturesTest, Emit) {
|
|||
: ast::AccessControl::kWriteOnly,
|
||||
ast::type::ImageFormat::kR16Float);
|
||||
|
||||
ASSERT_TRUE(gen().EmitType(out(), &s, "")) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
|
||||
EXPECT_EQ(result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
|
@ -33,14 +33,14 @@ inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
|||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using HlslUnaryOpTest = TestHelperBase<testing::TestWithParam<UnaryOpData>>;
|
||||
using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(HlslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
ast::UnaryOpExpression op(params.op, std::move(expr));
|
||||
|
||||
ASSERT_TRUE(gen().EmitExpression(pre(), out(), &op)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error();
|
||||
EXPECT_EQ(result(), std::string(params.name) + "(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_UnaryOp,
|
||||
|
|
|
@ -38,9 +38,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
|||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " float a;\n");
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
|
|||
var->set_is_const(true);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " const float a;\n");
|
||||
}
|
||||
|
||||
|
@ -65,9 +65,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
|
|||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &ary);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " float a[5];\n");
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " float a;\n");
|
||||
}
|
||||
|
||||
|
@ -90,9 +90,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
|
|||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
gen().increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), " float a;\n");
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
var->set_constructor(std::move(ident));
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(float a = initializer;
|
||||
)");
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
var->set_constructor(std::move(zero_vec));
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(result(), R"(vector<float, 3> a = vector<float, 3>(0.0f);
|
||||
)");
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
var->set_constructor(std::move(zero_mat));
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
ASSERT_TRUE(gen().EmitStatement(out(), &stmt)) << gen().error();
|
||||
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
|
||||
EXPECT_EQ(
|
||||
result(),
|
||||
R"(matrix<float, 3, 2> a = matrix<float, 3, 2>(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
|
|
@ -32,40 +32,34 @@ namespace hlsl {
|
|||
template <typename T>
|
||||
class TestHelperBase : public T {
|
||||
public:
|
||||
TestHelperBase() : td_(&ctx_, &mod_), impl_(&mod_) {}
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
|
||||
~TestHelperBase() = default;
|
||||
|
||||
/// @returns the generator implementation
|
||||
GeneratorImpl& gen() { return impl_; }
|
||||
|
||||
/// @returns the module
|
||||
ast::Module* mod() { return &mod_; }
|
||||
|
||||
/// @returns the type determiner
|
||||
TypeDeterminer& td() { return td_; }
|
||||
|
||||
/// @returns the output stream
|
||||
std::ostream& out() { return out_; }
|
||||
|
||||
/// @returns the pre stream
|
||||
std::ostream& pre() { return pre_; }
|
||||
|
||||
/// @returns the result string
|
||||
std::string result() const { return out_.str(); }
|
||||
std::string result() const { return out.str(); }
|
||||
|
||||
/// @returns the pre result string
|
||||
std::string pre_result() const { return pre_.str(); }
|
||||
std::string pre_result() const { return pre.str(); }
|
||||
|
||||
private:
|
||||
Context ctx_;
|
||||
ast::Module mod_;
|
||||
TypeDeterminer td_;
|
||||
GeneratorImpl impl_;
|
||||
std::ostringstream out_;
|
||||
std::ostringstream pre_;
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
ast::Module mod;
|
||||
/// The type determiner
|
||||
TypeDeterminer td;
|
||||
/// The generator
|
||||
GeneratorImpl gen;
|
||||
|
||||
/// The output stream
|
||||
std::ostringstream out;
|
||||
/// The pre-output stream
|
||||
std::ostringstream pre;
|
||||
};
|
||||
using TestHelper = TestHelperBase<testing::Test>;
|
||||
|
||||
template <typename T>
|
||||
using TestParamHelper = TestHelperBase<testing::TestWithParam<T>>;
|
||||
|
||||
} // namespace hlsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
|
|
@ -22,13 +22,17 @@ namespace msl {
|
|||
|
||||
Generator::Generator(ast::Module module)
|
||||
: Text(std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(&module_)) {}
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
|
||||
Generator::Generator(Context* ctx, ast::Module module)
|
||||
: Text(ctx, std::move(module)),
|
||||
impl_(std::make_unique<GeneratorImpl>(ctx_, &module_)) {}
|
||||
|
||||
Generator::~Generator() = default;
|
||||
|
||||
void Generator::Reset() {
|
||||
set_error("");
|
||||
impl_ = std::make_unique<GeneratorImpl>(&module_);
|
||||
impl_ = std::make_unique<GeneratorImpl>(ctx_, &module_);
|
||||
}
|
||||
|
||||
bool Generator::Generate() {
|
||||
|
|
|
@ -29,8 +29,13 @@ namespace msl {
|
|||
class Generator : public Text {
|
||||
public:
|
||||
/// Constructor
|
||||
/// DEPRECATED
|
||||
/// @param module the module to convert
|
||||
explicit Generator(ast::Module module);
|
||||
/// Constructor
|
||||
/// @param ctx the context object, must be non-null
|
||||
/// @param module the module to convert
|
||||
Generator(Context* ctx, ast::Module module);
|
||||
~Generator() override;
|
||||
|
||||
/// Resets the generator
|
||||
|
|
|
@ -92,7 +92,8 @@ uint32_t adjust_for_alignment(uint32_t count, uint32_t alignment) {
|
|||
|
||||
} // namespace
|
||||
|
||||
GeneratorImpl::GeneratorImpl(ast::Module* module) : module_(module) {}
|
||||
GeneratorImpl::GeneratorImpl(Context* ctx, ast::Module* module)
|
||||
: TextGenerator(ctx), module_(module) {}
|
||||
|
||||
GeneratorImpl::~GeneratorImpl() = default;
|
||||
|
||||
|
|
|
@ -37,8 +37,9 @@ namespace msl {
|
|||
class GeneratorImpl : public TextGenerator {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param module the module to generate
|
||||
explicit GeneratorImpl(ast::Module* module);
|
||||
GeneratorImpl(Context* ctx, ast::Module* module);
|
||||
~GeneratorImpl();
|
||||
|
||||
/// @returns true on successful generation; false otherwise
|
||||
|
@ -245,7 +246,7 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @returns the string name of the builtin or blank on error
|
||||
std::string builtin_to_attribute(ast::Builtin builtin) const;
|
||||
|
||||
/// @returns the namer for testing
|
||||
/// @returns the namer for testing purposes
|
||||
Namer* namer_for_testing() { return &namer_; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -22,22 +22,21 @@
|
|||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructedType_F32) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("a", &f32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructedType(&alias)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(typedef float a;
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef float a;
|
||||
)");
|
||||
}
|
||||
|
||||
|
@ -45,10 +44,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_NameCollision) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("float", &f32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructedType(&alias)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(typedef float float_tint_0;
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef float float_tint_0;
|
||||
)");
|
||||
}
|
||||
|
||||
|
@ -71,10 +68,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) {
|
|||
|
||||
ast::type::StructType s("a", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructedType(&s)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct a {
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct a {
|
||||
float a;
|
||||
int b;
|
||||
};
|
||||
|
@ -101,10 +96,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
|
|||
ast::type::StructType s("b", std::move(str));
|
||||
ast::type::AliasType alias("a", &s);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructedType(&alias)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(typedef b a;
|
||||
ASSERT_TRUE(gen.EmitConstructedType(&alias)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(typedef b a;
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include "src/ast/sint_literal.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||
ast::type::I32Type i32;
|
||||
|
@ -38,10 +39,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "ary[5]");
|
||||
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "ary[5]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
|
||||
|
@ -50,10 +49,8 @@ TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitArrayAccessor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "ary[idx]");
|
||||
ASSERT_TRUE(gen.EmitArrayAccessor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "ary[idx]");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -20,25 +20,24 @@
|
|||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Assign) {
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&assign)) << g.error();
|
||||
EXPECT_EQ(g.result(), " lhs = rhs;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&assign)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " lhs = rhs;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
@ -33,7 +34,7 @@ inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
|
|||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using MslBinaryTest = testing::TestWithParam<BinaryData>;
|
||||
using MslBinaryTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(MslBinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
|
@ -42,10 +43,8 @@ TEST_P(MslBinaryTest, Emit) {
|
|||
|
||||
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), params.result);
|
||||
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
|
|
@ -20,23 +20,22 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&bitcast)) << g.error();
|
||||
EXPECT_EQ(g.result(), "as_type<float>(id)");
|
||||
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "as_type<float>(id)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -18,24 +18,23 @@
|
|||
#include "src/ast/block_statement.h"
|
||||
#include "src/ast/discard_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Block) {
|
||||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&b)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( {
|
||||
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
discard_fragment();
|
||||
}
|
||||
)");
|
||||
|
@ -45,12 +44,10 @@ TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
|||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitBlock(&b)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"({
|
||||
ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"({
|
||||
discard_fragment();
|
||||
})");
|
||||
}
|
||||
|
|
|
@ -19,23 +19,22 @@
|
|||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Break) {
|
||||
ast::BreakStatement b;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&b)) << g.error();
|
||||
EXPECT_EQ(g.result(), " break;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " break;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||
ast::type::VoidType void_type;
|
||||
|
@ -38,13 +39,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&call)) << g.error();
|
||||
EXPECT_EQ(g.result(), "my_func()");
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "my_func()");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||
|
@ -58,13 +56,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&call)) << g.error();
|
||||
EXPECT_EQ(g.result(), "my_func(param1, param2)");
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "my_func(param1, param2)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
||||
|
@ -79,14 +74,11 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
|||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
ASSERT_TRUE(g.EmitStatement(&call)) << g.error();
|
||||
EXPECT_EQ(g.result(), " my_func(param1, param2);\n");
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitStatement(&call)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " my_func(param1, param2);\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
#include "src/ast/sint_literal.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||
ast::type::I32Type i32;
|
||||
|
@ -41,12 +42,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitCase(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( case 5: {
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
)");
|
||||
|
@ -59,12 +58,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::make_unique<ast::BlockStatement>());
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitCase(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( case 5: {
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
)");
|
||||
|
@ -80,12 +77,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitCase(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( case 5: {
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
/* fallthrough */
|
||||
}
|
||||
)");
|
||||
|
@ -102,12 +97,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 6));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitCase(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( case 5:
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5:
|
||||
case 6: {
|
||||
break;
|
||||
}
|
||||
|
@ -121,12 +114,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
|||
body->append(std::make_unique<ast::BreakStatement>());
|
||||
c.set_body(std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitCase(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( default: {
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
)");
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -37,10 +38,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&cast)) << g.error();
|
||||
EXPECT_EQ(g.result(), "float(id)");
|
||||
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(id)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
||||
|
@ -52,10 +51,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&cast)) << g.error();
|
||||
EXPECT_EQ(g.result(), "float3(id)");
|
||||
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(id)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -28,23 +28,22 @@
|
|||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/uint_literal.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
|
||||
ast::type::BoolType bool_type;
|
||||
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "false");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "false");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
||||
|
@ -52,10 +51,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
|||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "-12345");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "-12345");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
||||
|
@ -63,10 +60,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
|||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "56779u");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "56779u");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
||||
|
@ -76,10 +71,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
|||
&f32, static_cast<float>((1 << 30) - 4));
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "1.07374182e+09f");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "1.07374182e+09f");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
|
@ -92,10 +85,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&f32, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "float(-1.20000004e-05f)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(-1.20000004e-05f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
|
@ -108,10 +99,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&b, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool(true)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool(true)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
|
@ -124,10 +113,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&i32, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "int(-12345)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "int(-12345)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
|
@ -140,10 +127,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&u32, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "uint(12345u)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "uint(12345u)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
||||
|
@ -163,10 +148,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
|||
|
||||
ast::TypeConstructorExpression expr(&vec, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "float3(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
|
||||
|
@ -176,10 +159,8 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
|
|||
ast::ExpressionList values;
|
||||
ast::TypeConstructorExpression expr(&vec, std::move(values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "float3(0.0f)");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(0.0f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||
|
@ -213,15 +194,12 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
|
||||
// A matrix of type T with n columns and m rows can also be constructed from
|
||||
// n vectors of type T with m components.
|
||||
EXPECT_EQ(
|
||||
g.result(),
|
||||
gen.result(),
|
||||
std::string("float2x3(float3(1.00000000f, 2.00000000f, 3.00000000f), ") +
|
||||
"float3(3.00000000f, 4.00000000f, 5.00000000f))");
|
||||
}
|
||||
|
@ -254,14 +232,12 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
|||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("{") +
|
||||
"float3(1.00000000f, 2.00000000f, 3.00000000f), " +
|
||||
"float3(4.00000000f, 5.00000000f, 6.00000000f), " +
|
||||
"float3(7.00000000f, 8.00000000f, 9.00000000f)}");
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(),
|
||||
std::string("{") +
|
||||
"float3(1.00000000f, 2.00000000f, 3.00000000f), " +
|
||||
"float3(4.00000000f, 5.00000000f, 6.00000000f), " +
|
||||
"float3(7.00000000f, 8.00000000f, 9.00000000f)}");
|
||||
}
|
||||
|
||||
// TODO(dsinclair): Add struct constructor test.
|
||||
|
|
|
@ -19,23 +19,22 @@
|
|||
#include "src/ast/continue_statement.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Continue) {
|
||||
ast::ContinueStatement c;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), " continue;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " continue;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -16,23 +16,22 @@
|
|||
#include "src/ast/discard_statement.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Discard) {
|
||||
ast::DiscardStatement stmt;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " discard_fragment();\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " discard_fragment();\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
||||
// [[location 0]] var<in> foo : f32;
|
||||
|
@ -63,9 +64,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -92,9 +90,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct vtx_main_in {
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct vtx_main_in {
|
||||
float foo [[attribute(0)]];
|
||||
int bar [[attribute(1)]];
|
||||
};
|
||||
|
@ -126,9 +123,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -155,9 +149,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct vtx_main_out {
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct vtx_main_out {
|
||||
float foo [[user(locn0)]];
|
||||
int bar [[user(locn1)]];
|
||||
};
|
||||
|
@ -189,9 +182,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -217,9 +207,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct main_in {
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct main_in {
|
||||
float foo [[user(locn0)]];
|
||||
int bar [[user(locn1)]];
|
||||
};
|
||||
|
@ -251,9 +240,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -279,9 +265,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct main_out {
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct main_out {
|
||||
float foo [[color(0)]];
|
||||
int bar [[color(1)]];
|
||||
};
|
||||
|
@ -310,9 +295,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -338,9 +320,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_FALSE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.error(), R"(invalid location variable for pipeline stage)");
|
||||
ASSERT_FALSE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
||||
|
@ -364,9 +345,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -392,9 +370,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_FALSE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.error(), R"(invalid location variable for pipeline stage)");
|
||||
ASSERT_FALSE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
||||
|
@ -428,9 +405,6 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
|
@ -456,9 +430,8 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitEntryPointData(func_ptr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct main_out {
|
||||
ASSERT_TRUE(gen.EmitEntryPointData(func_ptr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct main_out {
|
||||
float depth [[depth(any)]];
|
||||
};
|
||||
|
||||
|
|
|
@ -48,13 +48,14 @@
|
|||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function) {
|
||||
ast::type::VoidType void_type;
|
||||
|
@ -66,14 +67,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
void my_func() {
|
||||
return;
|
||||
|
@ -92,14 +90,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
void main_tint_0() {
|
||||
return;
|
||||
|
@ -126,14 +121,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
gen.increment_indent();
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
void my_func(float a, int b) {
|
||||
return;
|
||||
|
@ -158,9 +150,6 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
|
||||
|
@ -184,9 +173,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct frag_main_in {
|
||||
float foo [[user(locn0)]];
|
||||
|
@ -227,9 +215,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
|
@ -255,9 +240,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct frag_main_out {
|
||||
float depth [[depth(any)]];
|
||||
|
@ -286,9 +270,6 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
@ -314,9 +295,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
fragment void frag_main(constant float4& coord [[buffer(0)]]) {
|
||||
float v = coord.x;
|
||||
|
@ -331,7 +311,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
ast::Module mod;
|
||||
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList a_deco;
|
||||
|
@ -363,8 +342,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
@ -389,10 +366,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
|
@ -412,7 +387,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
ast::Module mod;
|
||||
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList a_deco;
|
||||
|
@ -444,8 +418,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
@ -471,9 +443,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
|
@ -511,9 +482,6 @@ TEST_F(
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
val_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
td.RegisterVariableForTesting(val_var.get());
|
||||
|
@ -563,9 +531,8 @@ TEST_F(
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct ep_1_in {
|
||||
float foo [[user(locn0)]];
|
||||
|
@ -606,9 +573,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
@ -648,9 +612,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct ep_1_out {
|
||||
float depth [[depth(any)]];
|
||||
|
@ -692,9 +655,6 @@ TEST_F(
|
|||
ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
td.RegisterVariableForTesting(depth_var.get());
|
||||
|
||||
|
@ -740,10 +700,8 @@ TEST_F(
|
|||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct ep_1_out {
|
||||
float depth [[depth(any)]];
|
||||
|
@ -778,9 +736,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
@ -823,10 +778,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
float sub_func(constant float4& coord, float param) {
|
||||
return coord.x;
|
||||
|
@ -845,7 +798,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
ast::Module mod;
|
||||
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList a_deco;
|
||||
|
@ -877,10 +829,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
|
@ -922,9 +871,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
|
@ -948,7 +896,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
ast::Module mod;
|
||||
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList a_deco;
|
||||
|
@ -980,10 +927,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(1, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
||||
mod.AddGlobalVariable(std::move(coord_var));
|
||||
|
||||
ast::VariableList params;
|
||||
|
@ -1025,9 +969,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
|
@ -1058,9 +1001,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(bar_var.get());
|
||||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
|
@ -1094,10 +1034,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
mod.AddFunction(std::move(func_1));
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct ep_1_out {
|
||||
float bar [[color(1)]];
|
||||
|
@ -1124,12 +1062,10 @@ TEST_F(MslGeneratorImplTest,
|
|||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
kernel void main_tint_0() {
|
||||
}
|
||||
|
@ -1153,14 +1089,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
|
|||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
void my_func(float a[5]) {
|
||||
return;
|
||||
|
@ -1215,10 +1149,6 @@ TEST_F(MslGeneratorImplTest,
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(0, Source{}));
|
||||
data_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
mod.AddConstructedType(&s);
|
||||
|
||||
td.RegisterVariableForTesting(data_var.get());
|
||||
|
@ -1268,9 +1198,8 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
struct Data {
|
||||
float d;
|
||||
|
|
|
@ -16,30 +16,27 @@
|
|||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) {
|
||||
ast::IdentifierExpression i("foo");
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), "foo");
|
||||
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "foo");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression_Single_WithCollision) {
|
||||
ast::IdentifierExpression i("virtual");
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), "virtual_tint_0");
|
||||
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "virtual_tint_0");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_If) {
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
|
@ -34,12 +35,10 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
|
|||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( if (cond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
}
|
||||
)");
|
||||
|
@ -61,12 +60,10 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( if (cond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else if (else_cond) {
|
||||
return;
|
||||
|
@ -88,12 +85,10 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( if (cond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
|
@ -122,12 +117,10 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
|||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&i)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( if (cond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else if (else_cond) {
|
||||
return;
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
struct MslImportData {
|
||||
const char* name;
|
||||
|
@ -47,7 +48,7 @@ inline std::ostream& operator<<(std::ostream& out, MslImportData data) {
|
|||
out << data.name;
|
||||
return out;
|
||||
}
|
||||
using MslImportData_SingleParamTest = testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_SingleParamTest = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_SingleParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -62,15 +63,10 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
|
|||
|
||||
ast::CallExpression call(std::move(ident), std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
// The call type determination will set the intrinsic data for the ident
|
||||
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_EQ(g.generate_builtin_name(ident_ptr),
|
||||
ASSERT_EQ(gen.generate_builtin_name(ident_ptr),
|
||||
std::string("metal::") + param.msl_name);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
@ -109,18 +105,13 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
|
|||
ast::CallExpression expr(std::make_unique<ast::IdentifierExpression>("abs"),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(metal::abs(1))");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(metal::abs(1))");
|
||||
}
|
||||
|
||||
using MslImportData_DualParamTest = testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_DualParamTest = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_DualParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -136,16 +127,10 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name +
|
||||
"(1.00000000f, 2.00000000f)");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
|
||||
"(1.00000000f, 2.00000000f)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslImportData_DualParamTest,
|
||||
|
@ -157,8 +142,7 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
|||
MslImportData{"reflect", "reflect"},
|
||||
MslImportData{"step", "step"}));
|
||||
|
||||
using MslImportData_DualParam_VectorTest =
|
||||
testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_DualParam_VectorTest = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -190,23 +174,17 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name +
|
||||
"(float3(1.00000000f, 2.00000000f, 3.00000000f), "
|
||||
"float3(4.00000000f, 5.00000000f, 6.00000000f))");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
|
||||
"(float3(1.00000000f, 2.00000000f, 3.00000000f), "
|
||||
"float3(4.00000000f, 5.00000000f, 6.00000000f))");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslImportData_DualParam_VectorTest,
|
||||
testing::Values(MslImportData{"cross", "cross"}));
|
||||
|
||||
using MslImportData_DualParam_Int_Test = testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_DualParam_Int_Test = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -222,22 +200,16 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name + "(1, 2)");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name + "(1, 2)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslImportData_DualParam_Int_Test,
|
||||
testing::Values(MslImportData{"max", "max"},
|
||||
MslImportData{"min", "min"}));
|
||||
|
||||
using MslImportData_TripleParamTest = testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_TripleParamTest = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_TripleParamTest, FloatScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -255,16 +227,10 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name +
|
||||
"(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
|
||||
"(1.00000000f, 2.00000000f, 3.00000000f)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
@ -275,8 +241,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
MslImportData{"clamp", "clamp"},
|
||||
MslImportData{"smoothStep", "smoothstep"}));
|
||||
|
||||
using MslImportData_TripleParam_Int_Test =
|
||||
testing::TestWithParam<MslImportData>;
|
||||
using MslImportData_TripleParam_Int_Test = TestParamHelper<MslImportData>;
|
||||
TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -294,15 +259,10 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
|
|||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::") + param.msl_name + "(1, 2, 3)");
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(),
|
||||
std::string("metal::") + param.msl_name + "(1, 2, 3)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslImportData_TripleParam_Int_Test,
|
||||
|
@ -323,18 +283,13 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
|||
std::make_unique<ast::IdentifierExpression>("determinant"),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
mod.AddGlobalVariable(std::move(var));
|
||||
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
// Register the global
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitCall(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string("metal::determinant(var)"));
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::determinant(var)"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
struct IntrinsicData {
|
||||
ast::Intrinsic intrinsic;
|
||||
|
@ -37,13 +38,10 @@ inline std::ostream& operator<<(std::ostream& out, IntrinsicData data) {
|
|||
out << data.msl_name;
|
||||
return out;
|
||||
}
|
||||
using MslIntrinsicTest = testing::TestWithParam<IntrinsicData>;
|
||||
using MslIntrinsicTest = TestParamHelper<IntrinsicData>;
|
||||
TEST_P(MslIntrinsicTest, Emit) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(g.generate_intrinsic_name(param.intrinsic), param.msl_name);
|
||||
EXPECT_EQ(gen.generate_intrinsic_name(param.intrinsic), param.msl_name);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
@ -86,29 +84,22 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
|
|||
std::make_unique<ast::IdentifierExpression>("outer_product"),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module m;
|
||||
TypeDeterminer td(&ctx, &m);
|
||||
td.RegisterVariableForTesting(a.get());
|
||||
td.RegisterVariableForTesting(b.get());
|
||||
|
||||
m.AddGlobalVariable(std::move(a));
|
||||
m.AddGlobalVariable(std::move(b));
|
||||
mod.AddGlobalVariable(std::move(a));
|
||||
mod.AddGlobalVariable(std::move(b));
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
|
||||
g.increment_indent();
|
||||
ASSERT_TRUE(g.EmitExpression(&call)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float3x2(a * b[0], a * b[1], a * b[2])");
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float3x2(a * b[0], a * b[1], a * b[2])");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Intrinsic_Bad_Name) {
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(g.generate_intrinsic_name(ast::Intrinsic::kNone), "");
|
||||
EXPECT_EQ(gen.generate_intrinsic_name(ast::Intrinsic::kNone), "");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
||||
|
@ -122,10 +113,6 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
|||
ast::CallExpression call(std::make_unique<ast::IdentifierExpression>("dot"),
|
||||
std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module m;
|
||||
TypeDeterminer td(&ctx, &m);
|
||||
|
||||
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);
|
||||
ast::Variable v2("param2", ast::StorageClass::kFunction, &vec);
|
||||
|
||||
|
@ -134,10 +121,9 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
ASSERT_TRUE(g.EmitExpression(&call)) << g.error();
|
||||
EXPECT_EQ(g.result(), " dot(param1, param2)");
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " dot(param1, param2)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
|
@ -40,12 +41,10 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
|||
|
||||
ast::LoopStatement l(std::move(body), {});
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&l)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( for(;;) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( for(;;) {
|
||||
discard_fragment();
|
||||
}
|
||||
)");
|
||||
|
@ -60,12 +59,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
|||
|
||||
ast::LoopStatement l(std::move(body), std::move(continuing));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&l)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( {
|
||||
ASSERT_TRUE(gen.EmitStatement(&l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
for(;;) {
|
||||
if (!tint_msl_is_first_1) {
|
||||
|
@ -103,12 +100,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
|||
|
||||
ast::LoopStatement outer(std::move(body), std::move(continuing));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&outer)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( {
|
||||
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
for(;;) {
|
||||
if (!tint_msl_is_first_1) {
|
||||
|
@ -174,14 +169,12 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
|||
continuing->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::move(lhs), std::move(rhs)));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ast::LoopStatement outer(std::move(body), std::move(continuing));
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&outer)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( {
|
||||
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
float lhs;
|
||||
float other;
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
#include "src/ast/member_accessor_expression.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||
auto str = std::make_unique<ast::IdentifierExpression>("str");
|
||||
|
@ -33,10 +34,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
|||
|
||||
ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&expr)) << g.error();
|
||||
EXPECT_EQ(g.result(), "str.mem");
|
||||
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "str.mem");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -52,11 +53,9 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
|||
var->set_constructor(
|
||||
std::make_unique<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitProgramConstVariable(var.get())) << g.error();
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error();
|
||||
EXPECT_EQ(
|
||||
g.result(),
|
||||
gen.result(),
|
||||
"constant float pos[3] = {1.00000000f, 2.00000000f, 3.00000000f};\n");
|
||||
}
|
||||
|
||||
|
@ -73,10 +72,8 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
|
|||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitProgramConstVariable(var.get())) << g.error();
|
||||
EXPECT_EQ(g.result(), "constant float pos [[function_constant(23)]];\n");
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "constant float pos [[function_constant(23)]];\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -20,35 +20,32 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Return) {
|
||||
ast::ReturnStatement r;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&r)) << g.error();
|
||||
EXPECT_EQ(g.result(), " return;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&r)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " return;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
ast::ReturnStatement r(std::move(expr));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&r)) << g.error();
|
||||
EXPECT_EQ(g.result(), " return expr;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&r)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " return expr;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/i32_type.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
||||
auto def = std::make_unique<ast::CaseStatement>();
|
||||
|
@ -54,12 +55,10 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
|||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
ast::SwitchStatement s(std::move(cond), std::move(body));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&s)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( switch(cond) {
|
||||
ASSERT_TRUE(gen.EmitStatement(&s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( switch(cond) {
|
||||
case 5: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -38,28 +38,26 @@
|
|||
#include "src/ast/type/vector_type.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/writer/msl/namer.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Generate) {
|
||||
ast::type::VoidType void_type;
|
||||
ast::Module m;
|
||||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
m.AddFunction(std::move(func));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
GeneratorImpl g(&m);
|
||||
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(#include <metal_stdlib>
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||
|
||||
kernel void my_func() {
|
||||
}
|
||||
|
@ -68,30 +66,20 @@ kernel void my_func() {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, InputStructName) {
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_EQ(g.generate_name("func_main_in"), "func_main_in");
|
||||
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, InputStructName_ConflictWithExisting) {
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
|
||||
// Register the struct name as existing.
|
||||
auto* namer = g.namer_for_testing();
|
||||
namer->NameFor("func_main_out");
|
||||
|
||||
ASSERT_EQ(g.generate_name("func_main_out"), "func_main_out_0");
|
||||
gen.namer_for_testing()->NameFor("func_main_out");
|
||||
ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_0");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, NameConflictWith_InputStructName) {
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_EQ(g.generate_name("func_main_in"), "func_main_in");
|
||||
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
|
||||
|
||||
ast::IdentifierExpression ident("func_main_in");
|
||||
ASSERT_TRUE(g.EmitIdentifier(&ident));
|
||||
EXPECT_EQ(g.result(), "func_main_in_0");
|
||||
ASSERT_TRUE(gen.EmitIdentifier(&ident));
|
||||
EXPECT_EQ(gen.result(), "func_main_in_0");
|
||||
}
|
||||
|
||||
struct MslBuiltinData {
|
||||
|
@ -102,13 +90,11 @@ inline std::ostream& operator<<(std::ostream& out, MslBuiltinData data) {
|
|||
out << data.builtin;
|
||||
return out;
|
||||
}
|
||||
using MslBuiltinConversionTest = testing::TestWithParam<MslBuiltinData>;
|
||||
using MslBuiltinConversionTest = TestParamHelper<MslBuiltinData>;
|
||||
TEST_P(MslBuiltinConversionTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(g.builtin_to_attribute(params.builtin),
|
||||
EXPECT_EQ(gen.builtin_to_attribute(params.builtin),
|
||||
std::string(params.attribute_name));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -130,54 +116,40 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_alias) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("a", &f32);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u, g.calculate_alignment_size(&alias));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&alias));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_array) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::ArrayType ary(&f32, 4);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u * 4u, g.calculate_alignment_size(&ary));
|
||||
EXPECT_EQ(4u * 4u, gen.calculate_alignment_size(&ary));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_bool) {
|
||||
ast::type::BoolType bool_type;
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(1u, g.calculate_alignment_size(&bool_type));
|
||||
EXPECT_EQ(1u, gen.calculate_alignment_size(&bool_type));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_f32) {
|
||||
ast::type::F32Type f32;
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u, g.calculate_alignment_size(&f32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&f32));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_i32) {
|
||||
ast::type::I32Type i32;
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u, g.calculate_alignment_size(&i32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&i32));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_matrix) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat(&f32, 3, 2);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u * 3u * 2u, g.calculate_alignment_size(&mat));
|
||||
EXPECT_EQ(4u * 3u * 2u, gen.calculate_alignment_size(&mat));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_pointer) {
|
||||
ast::type::BoolType bool_type;
|
||||
ast::type::PointerType ptr(&bool_type, ast::StorageClass::kPrivate);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(0u, g.calculate_alignment_size(&ptr));
|
||||
EXPECT_EQ(0u, gen.calculate_alignment_size(&ptr));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
|
||||
|
@ -207,9 +179,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(132u, g.calculate_alignment_size(&s));
|
||||
EXPECT_EQ(132u, gen.calculate_alignment_size(&s));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
||||
|
@ -260,16 +230,12 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
|||
|
||||
ast::type::StructType outer_s("Outer", std::move(outer_str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(80u, g.calculate_alignment_size(&outer_s));
|
||||
EXPECT_EQ(80u, gen.calculate_alignment_size(&outer_s));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_u32) {
|
||||
ast::type::U32Type u32;
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(4u, g.calculate_alignment_size(&u32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&u32));
|
||||
}
|
||||
|
||||
struct MslVectorSizeData {
|
||||
|
@ -280,15 +246,13 @@ inline std::ostream& operator<<(std::ostream& out, MslVectorSizeData data) {
|
|||
out << data.elements;
|
||||
return out;
|
||||
}
|
||||
using MslVectorSizeBoolTest = testing::TestWithParam<MslVectorSizeData>;
|
||||
using MslVectorSizeBoolTest = TestParamHelper<MslVectorSizeData>;
|
||||
TEST_P(MslVectorSizeBoolTest, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::BoolType bool_type;
|
||||
ast::type::VectorType vec(&bool_type, param.elements);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(param.byte_size, g.calculate_alignment_size(&vec));
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslVectorSizeBoolTest,
|
||||
|
@ -296,15 +260,13 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
|||
MslVectorSizeData{3u, 4u},
|
||||
MslVectorSizeData{4u, 4u}));
|
||||
|
||||
using MslVectorSizeI32Test = testing::TestWithParam<MslVectorSizeData>;
|
||||
using MslVectorSizeI32Test = TestParamHelper<MslVectorSizeData>;
|
||||
TEST_P(MslVectorSizeI32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::type::VectorType vec(&i32, param.elements);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(param.byte_size, g.calculate_alignment_size(&vec));
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslVectorSizeI32Test,
|
||||
|
@ -312,15 +274,13 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
|||
MslVectorSizeData{3u, 16u},
|
||||
MslVectorSizeData{4u, 16u}));
|
||||
|
||||
using MslVectorSizeU32Test = testing::TestWithParam<MslVectorSizeData>;
|
||||
using MslVectorSizeU32Test = TestParamHelper<MslVectorSizeData>;
|
||||
TEST_P(MslVectorSizeU32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32Type u32;
|
||||
ast::type::VectorType vec(&u32, param.elements);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(param.byte_size, g.calculate_alignment_size(&vec));
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslVectorSizeU32Test,
|
||||
|
@ -328,15 +288,13 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
|||
MslVectorSizeData{3u, 16u},
|
||||
MslVectorSizeData{4u, 16u}));
|
||||
|
||||
using MslVectorSizeF32Test = testing::TestWithParam<MslVectorSizeData>;
|
||||
using MslVectorSizeF32Test = TestParamHelper<MslVectorSizeData>;
|
||||
TEST_P(MslVectorSizeF32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, param.elements);
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
EXPECT_EQ(param.byte_size, g.calculate_alignment_size(&vec));
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslVectorSizeF32Test,
|
||||
|
|
|
@ -38,42 +38,37 @@
|
|||
#include "src/context.h"
|
||||
#include "src/type_determiner.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Alias) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("alias", &f32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&alias, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "alias");
|
||||
ASSERT_TRUE(gen.EmitType(&alias, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "alias");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Alias_NameCollision) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::AliasType alias("bool", &f32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&alias, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool_tint_0");
|
||||
ASSERT_TRUE(gen.EmitType(&alias, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool_tint_0");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&a, "ary")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool ary[4]");
|
||||
ASSERT_TRUE(gen.EmitType(&a, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
||||
|
@ -81,10 +76,8 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
|||
ast::type::ArrayType a(&b, 4);
|
||||
ast::type::ArrayType c(&a, 5);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&c, "ary")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool ary[5][4]");
|
||||
ASSERT_TRUE(gen.EmitType(&c, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[5][4]");
|
||||
}
|
||||
|
||||
// TODO(dsinclair): Is this possible? What order should it output in?
|
||||
|
@ -94,10 +87,8 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) {
|
|||
ast::type::ArrayType c(&a, 5);
|
||||
ast::type::ArrayType d(&c);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&c, "ary")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool ary[5][4][1]");
|
||||
ASSERT_TRUE(gen.EmitType(&c, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[5][4][1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
||||
|
@ -106,87 +97,69 @@ TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
|||
ast::type::ArrayType c(&a, 5);
|
||||
ast::type::ArrayType d(&c, 6);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&d, "ary")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool ary[6][5][4]");
|
||||
ASSERT_TRUE(gen.EmitType(&d, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[6][5][4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array_NameCollision) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&a, "bool")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool bool_tint_0[4]");
|
||||
ASSERT_TRUE(gen.EmitType(&a, "bool")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool bool_tint_0[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b, 4);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&a, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool[4]");
|
||||
ASSERT_TRUE(gen.EmitType(&a, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&a, "ary")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool ary[1]");
|
||||
ASSERT_TRUE(gen.EmitType(&a, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray_NameCollision) {
|
||||
ast::type::BoolType b;
|
||||
ast::type::ArrayType a(&b);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&a, "discard_fragment")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool discard_fragment_tint_0[1]");
|
||||
ASSERT_TRUE(gen.EmitType(&a, "discard_fragment")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool discard_fragment_tint_0[1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Bool) {
|
||||
ast::type::BoolType b;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&b, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "bool");
|
||||
ASSERT_TRUE(gen.EmitType(&b, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_F32) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&f32, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "float");
|
||||
ASSERT_TRUE(gen.EmitType(&f32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_I32) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&i32, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "int");
|
||||
ASSERT_TRUE(gen.EmitType(&i32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "int");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Matrix) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType m(&f32, 3, 2);
|
||||
|
||||
ast::Module mod;
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.EmitType(&m, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "float2x3");
|
||||
ASSERT_TRUE(gen.EmitType(&m, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float2x3");
|
||||
}
|
||||
|
||||
// TODO(dsinclair): How to annotate as workgroup?
|
||||
|
@ -194,10 +167,8 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Pointer) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::PointerType p(&f32, ast::StorageClass::kWorkgroup);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&p, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "float*");
|
||||
ASSERT_TRUE(gen.EmitType(&p, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float*");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
||||
|
@ -219,10 +190,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "S");
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "S");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
||||
|
@ -244,10 +213,8 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitStructType(&s)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct S {
|
||||
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct S {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
@ -281,10 +248,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitStructType(&s)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct S {
|
||||
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct S {
|
||||
int8_t pad_0[4];
|
||||
int a;
|
||||
int8_t pad_1[24];
|
||||
|
@ -312,10 +277,8 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitStructType(&s)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct S {
|
||||
ASSERT_TRUE(gen.EmitStructType(&s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct S {
|
||||
int main_tint_0;
|
||||
float float_tint_0;
|
||||
};
|
||||
|
@ -344,10 +307,8 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(struct {
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(struct {
|
||||
int a;
|
||||
float b;
|
||||
})");
|
||||
|
@ -356,47 +317,37 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
TEST_F(MslGeneratorImplTest, EmitType_U32) {
|
||||
ast::type::U32Type u32;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&u32, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "uint");
|
||||
ASSERT_TRUE(gen.EmitType(&u32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "uint");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::VectorType v(&f32, 3);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&v, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "float3");
|
||||
ASSERT_TRUE(gen.EmitType(&v, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
||||
ast::type::VoidType v;
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&v, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "void");
|
||||
ASSERT_TRUE(gen.EmitType(&v, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "void");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
||||
ast::type::SamplerType sampler(ast::type::SamplerKind::kSampler);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&sampler, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "sampler");
|
||||
ASSERT_TRUE(gen.EmitType(&sampler, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "sampler");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
||||
ast::type::SamplerType sampler(ast::type::SamplerKind::kComparisonSampler);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&sampler, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "sampler");
|
||||
ASSERT_TRUE(gen.EmitType(&sampler, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "sampler");
|
||||
}
|
||||
|
||||
struct MslDepthTextureData {
|
||||
|
@ -407,16 +358,14 @@ inline std::ostream& operator<<(std::ostream& out, MslDepthTextureData data) {
|
|||
out << data.dim;
|
||||
return out;
|
||||
}
|
||||
using MslDepthTexturesTest = testing::TestWithParam<MslDepthTextureData>;
|
||||
using MslDepthTexturesTest = TestParamHelper<MslDepthTextureData>;
|
||||
TEST_P(MslDepthTexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::type::DepthTextureType s(params.dim);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), params.result);
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
@ -439,17 +388,15 @@ inline std::ostream& operator<<(std::ostream& out, MslTextureData data) {
|
|||
out << data.dim;
|
||||
return out;
|
||||
}
|
||||
using MslSampledtexturesTest = testing::TestWithParam<MslTextureData>;
|
||||
using MslSampledtexturesTest = TestParamHelper<MslTextureData>;
|
||||
TEST_P(MslSampledtexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::type::F32Type f32;
|
||||
ast::type::SampledTextureType s(params.dim, &f32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), params.result);
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
@ -474,10 +421,8 @@ TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) {
|
|||
ast::type::U32Type u32;
|
||||
ast::type::MultisampledTextureType s(ast::type::TextureDimension::k2d, &u32);
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), "texture2d_ms<uint, access::sample>");
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "texture2d_ms<uint, access::sample>");
|
||||
}
|
||||
|
||||
struct MslStorageTextureData {
|
||||
|
@ -489,7 +434,7 @@ inline std::ostream& operator<<(std::ostream& out, MslStorageTextureData data) {
|
|||
out << data.dim << (data.ro ? "ReadOnly" : "WriteOnly");
|
||||
return out;
|
||||
}
|
||||
using MslStorageTexturesTest = testing::TestWithParam<MslStorageTextureData>;
|
||||
using MslStorageTexturesTest = TestParamHelper<MslStorageTextureData>;
|
||||
TEST_P(MslStorageTexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
|
@ -498,13 +443,9 @@ TEST_P(MslStorageTexturesTest, Emit) {
|
|||
: ast::AccessControl::kWriteOnly,
|
||||
ast::type::ImageFormat::kR16Float);
|
||||
|
||||
Context ctx;
|
||||
ast::Module m;
|
||||
TypeDeterminer td(&ctx, &m);
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error();
|
||||
ASSERT_TRUE(g.EmitType(&s, "")) << g.error();
|
||||
EXPECT_EQ(g.result(), params.result);
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MslGeneratorImplTest,
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "src/ast/module.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
@ -34,17 +35,15 @@ inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
|||
out << data.op;
|
||||
return out;
|
||||
}
|
||||
using MslUnaryOpTest = testing::TestWithParam<UnaryOpData>;
|
||||
using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(MslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
ast::UnaryOpExpression op(params.op, std::move(expr));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitExpression(&op)) << g.error();
|
||||
EXPECT_EQ(g.result(), std::string(params.name) + "(expr)");
|
||||
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
MslUnaryOpTest,
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
#include "src/writer/msl/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -46,12 +47,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float a = 0.0f;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||
|
@ -62,12 +61,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " const float a = 0.0f;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " const float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
||||
|
@ -79,12 +76,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float a[5] = {0.0f};\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a[5] = {0.0f};\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
||||
|
@ -109,12 +104,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( S a = {};
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( S a = {};
|
||||
)");
|
||||
}
|
||||
|
||||
|
@ -127,12 +120,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float2 a = 0.0f;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float2 a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||
|
@ -143,12 +134,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float3x2 a = 0.0f;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float3x2 a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||
|
@ -158,12 +147,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
g.increment_indent();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), " float a = 0.0f;\n");
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
||||
|
@ -176,10 +163,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(float a = initializer;
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(float a = initializer;
|
||||
)");
|
||||
}
|
||||
|
||||
|
@ -197,10 +182,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
|||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(float3 a = float3(0.0f);
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_WRITER_MSL_TEST_HELPER_H_
|
||||
#define SRC_WRITER_MSL_TEST_HELPER_H_
|
||||
|
||||
#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"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
|
||||
/// Helper class for testing
|
||||
template <typename T>
|
||||
class TestHelperBase : public T {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
|
||||
~TestHelperBase() = default;
|
||||
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
ast::Module mod;
|
||||
/// The type determiner
|
||||
TypeDeterminer td;
|
||||
/// The generator
|
||||
GeneratorImpl gen;
|
||||
};
|
||||
using TestHelper = TestHelperBase<testing::Test>;
|
||||
|
||||
template <typename T>
|
||||
using TestParamHelper = TestHelperBase<testing::TestWithParam<T>>;
|
||||
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_WRITER_MSL_TEST_HELPER_H_
|
|
@ -19,17 +19,16 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "spirv/unified1/spirv.hpp11"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BinaryWriterTest = testing::Test;
|
||||
using BinaryWriterTest = TestHelper;
|
||||
|
||||
TEST_F(BinaryWriterTest, Preamble) {
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
BinaryWriter bw;
|
||||
bw.WriteHeader(5);
|
||||
|
||||
|
@ -43,8 +42,6 @@ TEST_F(BinaryWriterTest, Preamble) {
|
|||
}
|
||||
|
||||
TEST_F(BinaryWriterTest, Float) {
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_annot(spv::Op::OpKill, {Operand::Float(2.4f)});
|
||||
BinaryWriter bw;
|
||||
bw.WriteBuilder(&b);
|
||||
|
@ -57,8 +54,6 @@ TEST_F(BinaryWriterTest, Float) {
|
|||
}
|
||||
|
||||
TEST_F(BinaryWriterTest, Int) {
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_annot(spv::Op::OpKill, {Operand::Int(2)});
|
||||
BinaryWriter bw;
|
||||
bw.WriteBuilder(&b);
|
||||
|
@ -69,8 +64,6 @@ TEST_F(BinaryWriterTest, Int) {
|
|||
}
|
||||
|
||||
TEST_F(BinaryWriterTest, String) {
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_annot(spv::Op::OpKill, {Operand::String("my_string")});
|
||||
BinaryWriter bw;
|
||||
bw.WriteBuilder(&b);
|
||||
|
@ -94,8 +87,6 @@ TEST_F(BinaryWriterTest, String) {
|
|||
}
|
||||
|
||||
TEST_F(BinaryWriterTest, String_Multiple4Length) {
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_annot(spv::Op::OpKill, {Operand::String("mystring")});
|
||||
BinaryWriter bw;
|
||||
bw.WriteBuilder(&b);
|
||||
|
|
|
@ -270,7 +270,10 @@ Builder::AccessorInfo::AccessorInfo() : source_id(0), source_type(nullptr) {}
|
|||
|
||||
Builder::AccessorInfo::~AccessorInfo() {}
|
||||
|
||||
Builder::Builder(ast::Module* mod) : mod_(mod), scope_stack_({}) {}
|
||||
Builder::Builder(Context* ctx, ast::Module* mod)
|
||||
: ctx_(ctx), mod_(mod), scope_stack_({}) {
|
||||
assert(ctx_);
|
||||
}
|
||||
|
||||
Builder::~Builder() = default;
|
||||
|
||||
|
@ -424,7 +427,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(namer_.NameFor(func->name()))};
|
||||
// Operand::String(ctx_.namer()->NameFor(func->name()))};
|
||||
OperandList operands = {Operand::Int(stage), Operand::Int(id),
|
||||
Operand::String(func->name())};
|
||||
|
||||
|
@ -508,8 +511,9 @@ bool Builder::GenerateFunction(ast::Function* func) {
|
|||
auto func_op = result_op();
|
||||
auto func_id = func_op.to_i();
|
||||
|
||||
push_debug(spv::Op::OpName, {Operand::Int(func_id),
|
||||
Operand::String(namer_.NameFor(func->name()))});
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(func_id),
|
||||
Operand::String(ctx_->namer()->NameFor(func->name()))});
|
||||
|
||||
auto ret_id = GenerateTypeIfNeeded(func->return_type());
|
||||
if (ret_id == 0) {
|
||||
|
@ -535,7 +539,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
|
|||
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(param_id),
|
||||
Operand::String(namer_.NameFor(param->name()))});
|
||||
Operand::String(ctx_->namer()->NameFor(param->name()))});
|
||||
params.push_back(Instruction{spv::Op::OpFunctionParameter,
|
||||
{Operand::Int(param_type_id), param_op}});
|
||||
|
||||
|
@ -624,8 +628,9 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) {
|
|||
return false;
|
||||
}
|
||||
|
||||
push_debug(spv::Op::OpName, {Operand::Int(var_id),
|
||||
Operand::String(namer_.NameFor(var->name()))});
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(var_id),
|
||||
Operand::String(ctx_->namer()->NameFor(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.
|
||||
|
@ -673,8 +678,9 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
error_ = "missing constructor for constant";
|
||||
return false;
|
||||
}
|
||||
push_debug(spv::Op::OpName, {Operand::Int(init_id),
|
||||
Operand::String(namer_.NameFor(var->name()))});
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(init_id),
|
||||
Operand::String(ctx_->namer()->NameFor(var->name()))});
|
||||
|
||||
scope_stack_.set_global(var->name(), init_id);
|
||||
spirv_id_to_variable_[init_id] = var;
|
||||
|
@ -694,8 +700,9 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||
return false;
|
||||
}
|
||||
|
||||
push_debug(spv::Op::OpName, {Operand::Int(var_id),
|
||||
Operand::String(namer_.NameFor(var->name()))});
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(var_id),
|
||||
Operand::String(ctx_->namer()->NameFor(var->name()))});
|
||||
|
||||
auto* type = var->type()->UnwrapAll();
|
||||
|
||||
|
@ -2474,7 +2481,7 @@ bool Builder::GenerateStructType(ast::type::StructType* struct_type,
|
|||
if (!struct_type->name().empty()) {
|
||||
push_debug(spv::Op::OpName,
|
||||
{Operand::Int(struct_id),
|
||||
Operand::String(namer_.NameFor(struct_type->name()))});
|
||||
Operand::String(ctx_->namer()->NameFor(struct_type->name()))});
|
||||
}
|
||||
|
||||
OperandList ops;
|
||||
|
@ -2517,7 +2524,7 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id,
|
|||
ast::StructMember* member) {
|
||||
push_debug(spv::Op::OpMemberName,
|
||||
{Operand::Int(struct_id), Operand::Int(idx),
|
||||
Operand::String(namer_.NameFor(member->name()))});
|
||||
Operand::String(ctx_->namer()->NameFor(member->name()))});
|
||||
|
||||
bool has_layout = false;
|
||||
for (const auto& deco : member->decorations()) {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "src/ast/type/access_control_type.h"
|
||||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type_constructor_expression.h"
|
||||
#include "src/namer.h"
|
||||
#include "src/context.h"
|
||||
#include "src/scope_stack.h"
|
||||
#include "src/writer/spirv/function.h"
|
||||
#include "src/writer/spirv/instruction.h"
|
||||
|
@ -61,8 +61,9 @@ class Builder {
|
|||
};
|
||||
|
||||
/// Constructor
|
||||
/// @param ctx the context, must be non-null
|
||||
/// @param mod the module to generate from
|
||||
explicit Builder(ast::Module* mod);
|
||||
Builder(Context* ctx, ast::Module* mod);
|
||||
~Builder();
|
||||
|
||||
/// Generates the SPIR-V instructions for the given module
|
||||
|
@ -469,9 +470,9 @@ class Builder {
|
|||
return func_name_to_id_[name];
|
||||
}
|
||||
|
||||
Context* ctx_ = nullptr;
|
||||
ast::Module* mod_;
|
||||
std::string error_;
|
||||
Namer namer_;
|
||||
uint32_t next_id_ = 1;
|
||||
uint32_t current_label_id_ = 0;
|
||||
InstructionList capabilities_;
|
||||
|
|
|
@ -37,13 +37,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, ArrayAccessor) {
|
||||
ast::type::I32Type i32;
|
||||
|
@ -61,13 +62,9 @@ TEST_F(BuilderTest, ArrayAccessor) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -106,14 +103,10 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
|
|||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
td.RegisterVariableForTesting(&idx);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&idx)) << b.error();
|
||||
|
@ -159,13 +152,9 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -208,13 +197,9 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -258,13 +243,9 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
|
|||
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||
std::make_unique<ast::IdentifierExpression>("xy"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
EXPECT_EQ(b.GenerateAccessorExpression(&expr), 15u);
|
||||
|
@ -317,13 +298,9 @@ TEST_F(BuilderTest, MemberAccessor) {
|
|||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -382,13 +359,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
|
|||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -451,13 +424,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
|
|||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -523,13 +492,9 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
|||
|
||||
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -597,14 +562,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
|
|||
|
||||
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
td.RegisterVariableForTesting(&store);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&store)) << b.error();
|
||||
|
@ -644,13 +605,9 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
|||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("y"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -684,13 +641,9 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
|||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("yx"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -725,13 +678,9 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
|||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||
std::make_unique<ast::IdentifierExpression>("xz"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -767,13 +716,9 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
|||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||
std::make_unique<ast::IdentifierExpression>("x"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -810,13 +755,9 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -895,13 +836,9 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
|||
std::make_unique<ast::IdentifierExpression>("baz")),
|
||||
std::make_unique<ast::IdentifierExpression>("yx"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
|
||||
|
@ -982,14 +919,10 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
EXPECT_EQ(b.GenerateAccessorExpression(&expr), 18u) << b.error();
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Assign_Var) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -52,14 +53,10 @@ TEST_F(BuilderTest, Assign_Var) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -91,14 +88,10 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -142,13 +135,9 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
|||
ast::AssignmentStatement assign(
|
||||
std::make_unique<ast::IdentifierExpression>("var"), std::move(init));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -195,13 +184,9 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
|||
ast::AssignmentStatement assign(
|
||||
std::make_unique<ast::IdentifierExpression>("var"), std::move(init));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -254,14 +239,10 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -306,14 +287,10 @@ TEST_F(BuilderTest, Assign_Vector) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -351,14 +328,10 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -401,14 +374,10 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
|||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
struct BinaryData {
|
||||
ast::BinaryOp op;
|
||||
|
@ -50,7 +51,7 @@ inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
|
|||
return out;
|
||||
}
|
||||
|
||||
using BinaryArithSignedIntegerTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryArithSignedIntegerTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -63,12 +64,8 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -104,15 +101,10 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -136,13 +128,9 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 7u) << b.error();
|
||||
|
@ -177,7 +165,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
|
||||
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
|
||||
|
||||
using BinaryArithUnsignedIntegerTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryArithUnsignedIntegerTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -190,12 +178,8 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -231,15 +215,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -266,7 +245,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kSubtract, "OpISub"},
|
||||
BinaryData{ast::BinaryOp::kXor, "OpBitwiseXor"}));
|
||||
|
||||
using BinaryArithFloatTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryArithFloatTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryArithFloatTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -279,12 +258,7 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -321,15 +295,10 @@ TEST_P(BinaryArithFloatTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -350,7 +319,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kMultiply, "OpFMul"},
|
||||
BinaryData{ast::BinaryOp::kSubtract, "OpFSub"}));
|
||||
|
||||
using BinaryCompareUnsignedIntegerTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryCompareUnsignedIntegerTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -363,12 +332,8 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -406,15 +371,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -439,7 +399,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kLessThanEqual, "OpULessThanEqual"},
|
||||
BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
|
||||
|
||||
using BinaryCompareSignedIntegerTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryCompareSignedIntegerTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -452,12 +412,8 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -495,15 +451,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -528,7 +479,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kLessThanEqual, "OpSLessThanEqual"},
|
||||
BinaryData{ast::BinaryOp::kNotEqual, "OpINotEqual"}));
|
||||
|
||||
using BinaryCompareFloatTest = testing::TestWithParam<BinaryData>;
|
||||
using BinaryCompareFloatTest = TestParamHelper<BinaryData>;
|
||||
TEST_P(BinaryCompareFloatTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
|
@ -541,12 +492,8 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
|
|||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
|
@ -584,15 +531,10 @@ TEST_P(BinaryCompareFloatTest, Vector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -634,16 +576,11 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
|||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -673,16 +610,11 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
|
@ -705,9 +637,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
|||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
|
@ -715,7 +644,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -743,9 +671,6 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
|
@ -753,7 +678,6 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -790,9 +714,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
|||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
|
@ -800,7 +721,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -839,9 +759,6 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
|||
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
|
@ -849,7 +766,6 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -878,9 +794,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
auto lhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
|
@ -888,7 +801,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -923,16 +835,11 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
|
@ -972,9 +879,6 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
|||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("b");
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(a_var.get());
|
||||
td.RegisterVariableForTesting(b_var.get());
|
||||
|
||||
|
@ -983,7 +887,6 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
|
@ -1028,16 +931,11 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
|
@ -1077,9 +975,6 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
|||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("b");
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(a_var.get());
|
||||
td.RegisterVariableForTesting(b_var.get());
|
||||
|
||||
|
@ -1088,7 +983,6 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Bitcast) {
|
||||
ast::type::U32Type u32;
|
||||
|
@ -39,12 +40,8 @@ TEST_F(BuilderTest, Bitcast) {
|
|||
&u32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
|
||||
|
@ -64,12 +61,8 @@ TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
|||
&f32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Block) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -64,12 +65,8 @@ TEST_F(BuilderTest, Block) {
|
|||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
|
|
@ -30,13 +30,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Expression_Call) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -69,14 +70,10 @@ TEST_F(BuilderTest, Expression_Call) {
|
|||
std::make_unique<ast::IdentifierExpression>("a_func"),
|
||||
std::move(call_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&a_func)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
|
@ -137,14 +134,10 @@ TEST_F(BuilderTest, Statement_Call) {
|
|||
std::make_unique<ast::IdentifierExpression>("a_func"),
|
||||
std::move(call_params)));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&a_func)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
|
|
|
@ -41,21 +41,20 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Constructor_Const) {
|
||||
ast::type::F32Type f32;
|
||||
auto fl = std::make_unique<ast::FloatLiteral>(&f32, 42.2f);
|
||||
ast::ScalarConstructorExpression c(std::move(fl));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &c, true), 2u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -78,12 +77,8 @@ TEST_F(BuilderTest, Constructor_Type) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &t, true), 5u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -115,12 +110,8 @@ TEST_F(BuilderTest, Constructor_Type_WithCasts) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 7u);
|
||||
|
@ -153,12 +144,8 @@ TEST_F(BuilderTest, Constructor_Type_WithAlias) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&alias, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -185,13 +172,9 @@ TEST_F(BuilderTest, Constructor_Type_IdentifierExpression_Param) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateFunctionVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -227,12 +210,8 @@ TEST_F(BuilderTest, Constructor_Vector_Bitcast_Params) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 7u);
|
||||
|
@ -268,12 +247,8 @@ TEST_F(BuilderTest, Constructor_Type_NonConst_Value_Fails) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &t, true), 0u);
|
||||
EXPECT_TRUE(b.has_error());
|
||||
EXPECT_EQ(b.error(), R"(constructor must be a constant expression)");
|
||||
|
@ -288,12 +263,8 @@ TEST_F(BuilderTest, Constructor_Type_Bool_With_Bool) {
|
|||
|
||||
ast::TypeConstructorExpression t(&bool_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 1u);
|
||||
|
@ -316,12 +287,8 @@ TEST_F(BuilderTest, Constructor_Type_I32_With_I32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&i32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -342,12 +309,8 @@ TEST_F(BuilderTest, Constructor_Type_U32_With_U32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&u32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -368,12 +331,8 @@ TEST_F(BuilderTest, Constructor_Type_F32_With_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -397,12 +356,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec2_With_F32_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 4u);
|
||||
|
||||
|
@ -427,12 +382,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_F32_F32_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 4u);
|
||||
|
||||
|
@ -462,12 +413,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_F32_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -503,12 +450,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec3_With_Vec2_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -541,12 +484,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_F32_F32_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 4u);
|
||||
|
||||
|
@ -578,12 +517,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_F32_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -621,12 +556,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_Vec2_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -664,12 +595,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec2_F32_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -711,12 +638,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec2_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 10u);
|
||||
|
||||
|
@ -756,12 +679,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_F32_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 9u);
|
||||
|
||||
|
@ -800,12 +719,8 @@ TEST_F(BuilderTest, Constructor_Type_Vec4_With_Vec3_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 9u);
|
||||
|
||||
|
@ -842,12 +757,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec3_With_F32_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 11u);
|
||||
|
||||
|
@ -884,12 +795,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec3_With_Vec2_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 11u);
|
||||
|
||||
|
@ -928,12 +835,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_F32_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 11u);
|
||||
|
||||
|
@ -972,12 +875,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_Vec2_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 11u);
|
||||
|
||||
|
@ -1016,12 +915,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec2_F32_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 11u);
|
||||
|
||||
|
@ -1064,12 +959,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec2_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 13u);
|
||||
|
||||
|
@ -1110,12 +1001,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_F32_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 13u);
|
||||
|
||||
|
@ -1156,12 +1043,8 @@ TEST_F(BuilderTest, Constructor_Type_ModuleScope_Vec4_With_Vec3_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&vec4, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateConstructorExpression(nullptr, &cast, true), 13u);
|
||||
|
||||
|
@ -1206,12 +1089,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x2_With_Vec2_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1257,12 +1136,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x2_With_Vec2_Vec2_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1316,12 +1191,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x2_With_Vec2_Vec2_Vec2_Vec2) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1363,12 +1234,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x3_With_Vec3_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1420,12 +1287,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x3_With_Vec3_Vec3_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1487,12 +1350,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x3_With_Vec3_Vec3_Vec3_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1538,12 +1397,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat2x4_With_Vec4_Vec4) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1601,12 +1456,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat3x4_With_Vec4_Vec4_Vec4) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1676,12 +1527,8 @@ TEST_F(BuilderTest, Constructor_Type_Mat4x4_With_Vec4_Vec4_Vec4_Vec4) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&mat, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1712,12 +1559,8 @@ TEST_F(BuilderTest, Constructor_Type_Array_5_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&ary, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u);
|
||||
|
||||
|
@ -1759,12 +1602,8 @@ TEST_F(BuilderTest, Constructor_Type_Array_2_Vec3) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&ary, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 8u);
|
||||
|
||||
|
@ -1809,12 +1648,8 @@ TEST_F(BuilderTest, Constructor_Type_Struct) {
|
|||
|
||||
ast::TypeConstructorExpression t(&s_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 6u);
|
||||
|
@ -1835,12 +1670,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_F32) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&f32, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 2u);
|
||||
|
@ -1857,12 +1688,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_I32) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&i32, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 2u);
|
||||
|
@ -1879,12 +1706,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_U32) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&u32, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 2u);
|
||||
|
@ -1901,12 +1724,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Bool) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&bool_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 2u);
|
||||
|
@ -1924,12 +1743,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Vector) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 3u);
|
||||
|
@ -1948,12 +1763,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Matrix) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&mat, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 4u);
|
||||
|
@ -1973,12 +1784,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Array) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&ary, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 5u);
|
||||
|
@ -2006,12 +1813,8 @@ TEST_F(BuilderTest, Constructor_Type_ZeroInit_Struct) {
|
|||
ast::ExpressionList vals;
|
||||
ast::TypeConstructorExpression t(&s_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&t), 3u);
|
||||
|
@ -2033,12 +1836,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_U32_To_I32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&i32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2061,12 +1860,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_I32_To_U32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&u32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2089,12 +1884,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_F32_To_I32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&i32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2117,12 +1908,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_F32_To_U32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&u32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2145,12 +1932,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_I32_To_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2173,12 +1956,8 @@ TEST_F(BuilderTest, Constructor_Type_Convert_U32_To_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
|
||||
|
@ -2205,13 +1984,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_U32_to_I32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&ivec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2244,13 +2019,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_F32_to_I32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&ivec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2283,13 +2054,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_I32_to_U32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&uvec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2322,13 +2089,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_F32_to_U32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&uvec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2361,13 +2124,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_I32_to_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&fvec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2400,13 +2159,9 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_U32_to_F32) {
|
|||
|
||||
ast::TypeConstructorExpression cast(&fvec3, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 6u) << b.error();
|
||||
|
@ -2439,12 +2194,8 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalVectorWithAllConstConstructors) {
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 3.f)));
|
||||
ast::TypeConstructorExpression t(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.is_constructor_const(&t, true));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2460,10 +2211,6 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalVector_WithIdent) {
|
|||
params.push_back(std::make_unique<ast::IdentifierExpression>("c"));
|
||||
ast::TypeConstructorExpression t(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
|
||||
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);
|
||||
ast::Variable var_c("c", ast::StorageClass::kPrivate, &f32);
|
||||
|
@ -2473,7 +2220,6 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalVector_WithIdent) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, true));
|
||||
EXPECT_TRUE(b.has_error());
|
||||
EXPECT_EQ(b.error(), "constructor must be a constant expression");
|
||||
|
@ -2510,12 +2256,8 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalArrayWithAllConstConstructors) {
|
|||
ary_params.push_back(std::move(second));
|
||||
ast::TypeConstructorExpression t(&ary, std::move(ary_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.is_constructor_const(&t, true));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2541,12 +2283,8 @@ TEST_F(BuilderTest,
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, true));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2572,12 +2310,8 @@ TEST_F(BuilderTest, IsConstructorConst_GlobalWithTypeCastConstructor) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, true));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2596,12 +2330,8 @@ TEST_F(BuilderTest, IsConstructorConst_VectorWithAllConstConstructors) {
|
|||
std::make_unique<ast::FloatLiteral>(&f32, 3.f)));
|
||||
ast::TypeConstructorExpression t(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2617,10 +2347,6 @@ TEST_F(BuilderTest, IsConstructorConst_Vector_WithIdent) {
|
|||
params.push_back(std::make_unique<ast::IdentifierExpression>("c"));
|
||||
ast::TypeConstructorExpression t(&vec, std::move(params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
|
||||
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);
|
||||
ast::Variable var_c("c", ast::StorageClass::kPrivate, &f32);
|
||||
|
@ -2630,7 +2356,6 @@ TEST_F(BuilderTest, IsConstructorConst_Vector_WithIdent) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2666,12 +2391,8 @@ TEST_F(BuilderTest, IsConstructorConst_ArrayWithAllConstConstructors) {
|
|||
ary_params.push_back(std::move(second));
|
||||
ast::TypeConstructorExpression t(&ary, std::move(ary_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2697,12 +2418,8 @@ TEST_F(BuilderTest, IsConstructorConst_VectorWith_TypeCastConstConstructors) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2728,12 +2445,8 @@ TEST_F(BuilderTest, IsConstructorConst_WithTypeCastConstructor) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vec_params));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2751,12 +2464,8 @@ TEST_F(BuilderTest, IsConstructorConst_BitCastScalars) {
|
|||
|
||||
ast::TypeConstructorExpression t(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2791,12 +2500,8 @@ TEST_F(BuilderTest, IsConstructorConst_Struct) {
|
|||
|
||||
ast::TypeConstructorExpression t(&s_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
@ -2830,10 +2535,6 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) {
|
|||
|
||||
ast::TypeConstructorExpression t(&s_type, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::Variable var_a("a", ast::StorageClass::kPrivate, &f32);
|
||||
ast::Variable var_b("b", ast::StorageClass::kPrivate, &f32);
|
||||
td.RegisterVariableForTesting(&var_a);
|
||||
|
@ -2841,7 +2542,6 @@ TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&t)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_FALSE(b.is_constructor_const(&t, false));
|
||||
EXPECT_FALSE(b.has_error());
|
||||
}
|
||||
|
|
|
@ -18,19 +18,18 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Discard) {
|
||||
ast::DiscardStatement expr;
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateStatement(&expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpKill
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
@ -30,14 +31,11 @@ inline std::ostream& operator<<(std::ostream& out, TestData data) {
|
|||
out << data.ast_format;
|
||||
return out;
|
||||
}
|
||||
using ImageFormatConversionTest = testing::TestWithParam<TestData>;
|
||||
using ImageFormatConversionTest = TestParamHelper<TestData>;
|
||||
|
||||
TEST_P(ImageFormatConversionTest, ImageFormatConversion) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
|
||||
EXPECT_EQ(b.convert_image_format_to_spv(param.ast_format), param.spv_format);
|
||||
|
||||
if (param.extended_format) {
|
||||
|
|
|
@ -30,13 +30,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_Stage) {
|
||||
ast::type::VoidType void_type;
|
||||
|
@ -45,8 +46,6 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
|
|||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.entry_points()),
|
||||
R"(OpEntryPoint Vertex %3 "main"
|
||||
|
@ -61,7 +60,7 @@ inline std::ostream& operator<<(std::ostream& out, FunctionStageData data) {
|
|||
out << data.stage;
|
||||
return out;
|
||||
}
|
||||
using FunctionDecoration_StageTest = testing::TestWithParam<FunctionStageData>;
|
||||
using FunctionDecoration_StageTest = TestParamHelper<FunctionStageData>;
|
||||
TEST_P(FunctionDecoration_StageTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
|
@ -71,8 +70,6 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
|
|||
func.add_decoration(
|
||||
std::make_unique<ast::StageDecoration>(params.stage, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
auto preamble = b.entry_points();
|
||||
|
@ -106,8 +103,6 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
|||
auto v_wg = std::make_unique<ast::Variable>(
|
||||
"my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_in.get())) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_out.get())) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_wg.get())) << b.error();
|
||||
|
@ -166,17 +161,12 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
|||
auto v_wg = std::make_unique<ast::Variable>(
|
||||
"my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(v_in.get());
|
||||
td.RegisterVariableForTesting(v_out.get());
|
||||
td.RegisterVariableForTesting(v_wg.get());
|
||||
|
||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_in.get())) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_out.get())) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_wg.get())) << b.error();
|
||||
|
@ -214,8 +204,6 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
|||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
R"(OpExecutionMode %3 OriginUpperLeft
|
||||
|
@ -229,8 +217,6 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) {
|
|||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
R"(OpExecutionMode %3 LocalSize 1 1 1
|
||||
|
@ -246,8 +232,6 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) {
|
|||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
R"(OpExecutionMode %3 LocalSize 2 4 6
|
||||
|
@ -265,8 +249,6 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
|
|||
func2.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func1)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(&func2)) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b),
|
||||
|
|
|
@ -37,22 +37,20 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Function_Empty) {
|
||||
ast::type::VoidType void_type;
|
||||
ast::Function func("a_func", {}, &void_type);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_615f66756e63"
|
||||
)");
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
|
||||
|
@ -87,14 +85,10 @@ TEST_F(BuilderTest, Function_WithParams) {
|
|||
std::make_unique<ast::IdentifierExpression>("a")));
|
||||
func.set_body(std::move(body));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(func.params()[0].get());
|
||||
td.RegisterVariableForTesting(func.params()[1].get());
|
||||
EXPECT_TRUE(td.DetermineFunction(&func));
|
||||
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "tint_615f66756e63"
|
||||
OpName %5 "tint_61"
|
||||
|
@ -120,8 +114,6 @@ TEST_F(BuilderTest, Function_WithBody) {
|
|||
ast::Function func("a_func", {}, &void_type);
|
||||
func.set_body(std::move(body));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "tint_615f66756e63"
|
||||
%2 = OpTypeVoid
|
||||
|
@ -137,8 +129,6 @@ TEST_F(BuilderTest, FunctionType) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::Function func("a_func", {}, &void_type);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func));
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
|
||||
%1 = OpTypeFunction %2
|
||||
|
@ -150,8 +140,6 @@ TEST_F(BuilderTest, FunctionType_DeDuplicate) {
|
|||
ast::Function func1("a_func", {}, &void_type);
|
||||
ast::Function func2("b_func", {}, &void_type);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.GenerateFunction(&func1));
|
||||
ASSERT_TRUE(b.GenerateFunction(&func2));
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
|
||||
|
@ -204,10 +192,6 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
decos.push_back(std::make_unique<ast::SetDecoration>(0, Source{}));
|
||||
data_var->set_decorations(std::move(decos));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
mod.AddConstructedType(&s);
|
||||
|
||||
td.RegisterVariableForTesting(data_var.get());
|
||||
|
@ -257,7 +241,6 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
ASSERT_TRUE(b.Build());
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
|
|
|
@ -37,20 +37,19 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
||||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kNone, &f32);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
|
@ -81,9 +80,6 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -91,7 +87,6 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -132,16 +127,12 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kFunction, &vec);
|
||||
v.set_constructor(std::move(init));
|
||||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -189,9 +180,6 @@ TEST_F(BuilderTest, FunctionVar_Const) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -200,7 +188,6 @@ TEST_F(BuilderTest, FunctionVar_Const) {
|
|||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
|
|
@ -42,20 +42,19 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_NoStorageClass) {
|
||||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kNone, &f32);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -70,8 +69,6 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass) {
|
|||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -86,8 +83,6 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
|||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kInput, &f32);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -112,16 +107,12 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
v.set_constructor(std::move(init));
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -152,9 +143,6 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -162,7 +150,6 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
v.set_is_const(true);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -190,9 +177,6 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -200,7 +184,6 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
|||
v.set_is_const(true);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -233,9 +216,6 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -243,7 +223,6 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
v.set_is_const(true);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -273,8 +252,6 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
|||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -298,8 +275,6 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
|
|||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -324,8 +299,6 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
|||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&dv)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -350,8 +323,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
|||
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true)));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
)");
|
||||
|
@ -374,8 +345,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
|||
"var", ast::StorageClass::kNone, &bool_type));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -400,8 +369,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
|||
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
)");
|
||||
|
@ -424,8 +391,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
|||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &f32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -448,8 +413,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
|||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &i32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -472,8 +435,6 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
|||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &u32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
)");
|
||||
|
@ -494,12 +455,9 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
|
|||
out << data.builtin;
|
||||
return out;
|
||||
}
|
||||
using BuiltinDataTest = testing::TestWithParam<BuiltinData>;
|
||||
using BuiltinDataTest = TestParamHelper<BuiltinData>;
|
||||
TEST_P(BuiltinDataTest, Convert) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_EQ(b.ConvertBuiltin(params.builtin), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -544,8 +502,6 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
|
|||
|
||||
ast::Variable var("b", ast::StorageClass::kStorageBuffer, &ac);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
|
@ -584,8 +540,6 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
|
|||
|
||||
ast::Variable var("b", ast::StorageClass::kStorageBuffer, &ac);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
|
@ -622,8 +576,6 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
|
|||
|
||||
ast::Variable var("b", ast::StorageClass::kStorageBuffer, &B);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %3 0 NonWritable
|
||||
|
@ -661,8 +613,6 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
|
|||
ast::Variable var_b("b", ast::StorageClass::kStorageBuffer, &read);
|
||||
ast::Variable var_c("c", ast::StorageClass::kStorageBuffer, &rw);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&var_b)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&var_c)) << b.error();
|
||||
|
||||
|
|
|
@ -29,13 +29,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||
ast::type::F32Type f32;
|
||||
|
@ -52,9 +53,6 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -63,7 +61,6 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
|||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -84,12 +81,8 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
|||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
|
@ -120,9 +113,6 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
|||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
@ -130,7 +120,6 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
|||
v.set_is_const(true);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
|
@ -150,12 +139,8 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
|||
ast::type::F32Type f32;
|
||||
ast::Variable v("var", ast::StorageClass::kNone, &f32);
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&v);
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "tint_766172"
|
||||
|
@ -178,10 +163,6 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
|
|||
TEST_F(BuilderTest, IdentifierExpression_Load) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
|
@ -194,7 +175,6 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||
|
||||
|
@ -214,10 +194,6 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
|||
TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
||||
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
|
@ -233,7 +209,6 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
|||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||
|
||||
|
|
|
@ -32,13 +32,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, If_Empty) {
|
||||
ast::type::BoolType bool_type;
|
||||
|
@ -51,12 +52,8 @@ TEST_F(BuilderTest, If_Empty) {
|
|||
ast::IfStatement expr(std::move(cond),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
|
@ -93,13 +90,9 @@ TEST_F(BuilderTest, If_WithStatements) {
|
|||
|
||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -156,14 +149,10 @@ TEST_F(BuilderTest, If_WithElse) {
|
|||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -227,14 +216,10 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
|||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -322,14 +307,10 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
|||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -397,13 +378,8 @@ TEST_F(BuilderTest, If_WithBreak) {
|
|||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -456,13 +432,8 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
|||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -511,13 +482,8 @@ TEST_F(BuilderTest, If_WithContinue) {
|
|||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -570,13 +536,8 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
|||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -616,13 +577,8 @@ TEST_F(BuilderTest, If_WithReturn) {
|
|||
|
||||
ast::IfStatement expr(std::move(cond), std::move(if_body));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
|
@ -653,13 +609,8 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
|||
|
||||
ast::IfStatement expr(std::move(cond), std::move(if_body));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
@ -66,7 +67,7 @@ class IntrinsicBuilderTest : public ast::Builder, public testing::Test {
|
|||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td{&ctx, &mod};
|
||||
spirv::Builder b{&mod};
|
||||
spirv::Builder b{&ctx, &mod};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -25,19 +25,18 @@
|
|||
#include "src/ast/uint_literal.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Literal_Bool_True) {
|
||||
ast::type::BoolType bool_type;
|
||||
ast::BoolLiteral b_true(&bool_type, true);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &b_true);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
@ -51,8 +50,6 @@ TEST_F(BuilderTest, Literal_Bool_False) {
|
|||
ast::type::BoolType bool_type;
|
||||
ast::BoolLiteral b_false(&bool_type, false);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &b_false);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
@ -67,8 +64,6 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) {
|
|||
ast::BoolLiteral b_true(&bool_type, true);
|
||||
ast::BoolLiteral b_false(&bool_type, false);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &b_true), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &b_false), 0u);
|
||||
|
@ -86,8 +81,6 @@ TEST_F(BuilderTest, Literal_I32) {
|
|||
ast::type::I32Type i32;
|
||||
ast::SintLiteral i(&i32, -23);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
@ -102,8 +95,6 @@ TEST_F(BuilderTest, Literal_I32_Dedup) {
|
|||
ast::SintLiteral i1(&i32, -23);
|
||||
ast::SintLiteral i2(&i32, -23);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -117,8 +108,6 @@ TEST_F(BuilderTest, Literal_U32) {
|
|||
ast::type::U32Type u32;
|
||||
ast::UintLiteral i(&u32, 23);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
@ -133,8 +122,6 @@ TEST_F(BuilderTest, Literal_U32_Dedup) {
|
|||
ast::UintLiteral i1(&u32, 23);
|
||||
ast::UintLiteral i2(&u32, 23);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -148,8 +135,6 @@ TEST_F(BuilderTest, Literal_F32) {
|
|||
ast::type::F32Type f32;
|
||||
ast::FloatLiteral i(&f32, 23.245f);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
@ -164,8 +149,6 @@ TEST_F(BuilderTest, Literal_F32_Dedup) {
|
|||
ast::FloatLiteral i1(&f32, 23.245f);
|
||||
ast::FloatLiteral i2(&f32, 23.245f);
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
|
|
@ -27,13 +27,14 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Loop_Empty) {
|
||||
// loop {
|
||||
|
@ -41,12 +42,7 @@ TEST_F(BuilderTest, Loop_Empty) {
|
|||
|
||||
ast::LoopStatement expr;
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -81,13 +77,9 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
|||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -137,13 +129,9 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
|||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||
|
||||
|
@ -180,12 +168,8 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
|||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
@ -212,12 +196,8 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
|||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
|
|
|
@ -26,19 +26,18 @@
|
|||
#include "src/type_determiner.h"
|
||||
#include "src/writer/spirv/builder.h"
|
||||
#include "src/writer/spirv/spv_dump.h"
|
||||
#include "src/writer/spirv/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace spirv {
|
||||
namespace {
|
||||
|
||||
using BuilderTest = testing::Test;
|
||||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Return) {
|
||||
ast::ReturnStatement ret;
|
||||
|
||||
ast::Module mod;
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret));
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -64,12 +63,8 @@ TEST_F(BuilderTest, Return_WithValue) {
|
|||
|
||||
ast::ReturnStatement ret(std::move(val));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret));
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
@ -93,13 +88,9 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
|
|||
ast::ReturnStatement ret(
|
||||
std::make_unique<ast::IdentifierExpression>("param"));
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
td.RegisterVariableForTesting(&var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
|
||||
|
||||
Builder b(&mod);
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(&var)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret)) << b.error();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue