transform tests: Replace std::make_unique<T> -> create<T>
create() is currently just a simple forwarder to std::make_unique<>, but will be later replaced with a function that returns a raw pointer, and owned by the context. Bug: tint:322 Change-Id: I630ce57017fe84b5d00e9bd74902f47547a13f3a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32669 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
68f6afe2a4
commit
a1f4d4fda9
|
@ -52,9 +52,8 @@ class BoundArrayAccessorsTest : public testing::Test {
|
||||||
BoundArrayAccessorsTest() : td_(&ctx_, &mod_), transform_(&ctx_, &mod_) {}
|
BoundArrayAccessorsTest() : td_(&ctx_, &mod_), transform_(&ctx_, &mod_) {}
|
||||||
|
|
||||||
ast::BlockStatement* SetupFunctionAndBody() {
|
ast::BlockStatement* SetupFunctionAndBody() {
|
||||||
auto func = std::make_unique<ast::Function>("func", ast::VariableList{},
|
auto func = create<ast::Function>("func", ast::VariableList{}, &void_type_);
|
||||||
&void_type_);
|
auto block = create<ast::BlockStatement>();
|
||||||
auto block = std::make_unique<ast::BlockStatement>();
|
|
||||||
body_ = block.get();
|
body_ = block.get();
|
||||||
func->set_body(std::move(block));
|
func->set_body(std::move(block));
|
||||||
mod_.AddFunction(std::move(func));
|
mod_.AddFunction(std::move(func));
|
||||||
|
@ -63,13 +62,20 @@ class BoundArrayAccessorsTest : public testing::Test {
|
||||||
|
|
||||||
void DeclareVariable(std::unique_ptr<ast::Variable> var) {
|
void DeclareVariable(std::unique_ptr<ast::Variable> var) {
|
||||||
ASSERT_NE(body_, nullptr);
|
ASSERT_NE(body_, nullptr);
|
||||||
body_->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
body_->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeDeterminer* td() { return &td_; }
|
TypeDeterminer* td() { return &td_; }
|
||||||
|
|
||||||
BoundArrayAccessorsTransform* transform() { return &transform_; }
|
BoundArrayAccessorsTransform* transform() { return &transform_; }
|
||||||
|
|
||||||
|
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
|
||||||
|
/// @param args the arguments to forward to the constructor for `T`
|
||||||
|
template <typename T, typename... ARGS>
|
||||||
|
std::unique_ptr<T> create(ARGS&&... args) {
|
||||||
|
return std::make_unique<T>(std::forward<ARGS>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
ast::Module mod_;
|
ast::Module mod_;
|
||||||
|
@ -93,22 +99,20 @@ TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
||||||
|
|
||||||
auto c_var =
|
auto c_var = create<ast::Variable>("c", ast::StorageClass::kFunction, &u32);
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &u32);
|
|
||||||
c_var->set_is_const(true);
|
c_var->set_is_const(true);
|
||||||
DeclareVariable(std::move(c_var));
|
DeclareVariable(std::move(c_var));
|
||||||
|
|
||||||
auto access_idx = std::make_unique<ast::IdentifierExpression>("c");
|
auto access_idx = create<ast::IdentifierExpression>("c");
|
||||||
auto* access_ptr = access_idx.get();
|
auto* access_ptr = access_idx.get();
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"), std::move(access_idx));
|
create<ast::IdentifierExpression>("a"), std::move(access_idx));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b = std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction,
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &ptr_type);
|
||||||
&ptr_type);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
b->set_is_const(true);
|
b->set_is_const(true);
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
@ -156,27 +160,24 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Nested_Scalar) {
|
||||||
ast::type::ArrayType ary5(&f32, 5);
|
ast::type::ArrayType ary5(&f32, 5);
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(std::make_unique<ast::Variable>(
|
|
||||||
"a", ast::StorageClass::kFunction, &ary3));
|
|
||||||
DeclareVariable(std::make_unique<ast::Variable>(
|
|
||||||
"b", ast::StorageClass::kFunction, &ary5));
|
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("i", ast::StorageClass::kFunction, &u32));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary3));
|
||||||
|
DeclareVariable(
|
||||||
|
create<ast::Variable>("b", ast::StorageClass::kFunction, &ary5));
|
||||||
|
DeclareVariable(
|
||||||
|
create<ast::Variable>("i", ast::StorageClass::kFunction, &u32));
|
||||||
|
|
||||||
auto b_access_idx = std::make_unique<ast::IdentifierExpression>("i");
|
auto b_access_idx = create<ast::IdentifierExpression>("i");
|
||||||
auto* b_access_ptr = b_access_idx.get();
|
auto* b_access_ptr = b_access_idx.get();
|
||||||
|
|
||||||
auto a_access_idx = std::make_unique<ast::ArrayAccessorExpression>(
|
auto a_access_idx = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("b"),
|
create<ast::IdentifierExpression>("b"), std::move(b_access_idx));
|
||||||
std::move(b_access_idx));
|
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"), std::move(a_access_idx));
|
||||||
std::move(a_access_idx));
|
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("c", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -241,16 +242,15 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Scalar) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
create<ast::UintLiteral>(&u32, 1u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -282,26 +282,24 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
create<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
||||||
|
|
||||||
auto access_idx = std::make_unique<ast::BinaryExpression>(
|
auto access_idx = create<ast::BinaryExpression>(
|
||||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("c"),
|
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("c"),
|
||||||
std::make_unique<ast::BinaryExpression>(
|
create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
|
||||||
ast::BinaryOp::kSubtract,
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 2)),
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2)),
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 3))));
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3))));
|
|
||||||
auto* access_ptr = access_idx.get();
|
auto* access_ptr = access_idx.get();
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"), std::move(access_idx));
|
create<ast::IdentifierExpression>("a"), std::move(access_idx));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -346,16 +344,15 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Negative) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, -1)));
|
create<ast::SintLiteral>(&i32, -1)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -386,16 +383,15 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_OutOfBounds) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &ary));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3u)));
|
create<ast::UintLiteral>(&u32, 3u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -426,16 +422,15 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Scalar) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
create<ast::UintLiteral>(&u32, 1u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -467,26 +462,24 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
create<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
||||||
|
|
||||||
auto access_idx = std::make_unique<ast::BinaryExpression>(
|
auto access_idx = create<ast::BinaryExpression>(
|
||||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("c"),
|
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("c"),
|
||||||
std::make_unique<ast::BinaryExpression>(
|
create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
|
||||||
ast::BinaryOp::kSubtract,
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 2)),
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2)),
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 3))));
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3))));
|
|
||||||
auto* access_ptr = access_idx.get();
|
auto* access_ptr = access_idx.get();
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"), std::move(access_idx));
|
create<ast::IdentifierExpression>("a"), std::move(access_idx));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -530,16 +523,15 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Negative) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, -1)));
|
create<ast::SintLiteral>(&i32, -1)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -570,16 +562,15 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_OutOfBounds) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &vec));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3u)));
|
create<ast::UintLiteral>(&u32, 3u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -610,19 +601,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Scalar) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2u))),
|
create<ast::UintLiteral>(&u32, 2u))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
create<ast::UintLiteral>(&u32, 1u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -667,30 +657,27 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
create<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
||||||
|
|
||||||
auto access_idx = std::make_unique<ast::BinaryExpression>(
|
auto access_idx = create<ast::BinaryExpression>(
|
||||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("c"),
|
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("c"),
|
||||||
std::make_unique<ast::BinaryExpression>(
|
create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
|
||||||
ast::BinaryOp::kSubtract,
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 2)),
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2)),
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 3))));
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3))));
|
|
||||||
auto* access_ptr = access_idx.get();
|
auto* access_ptr = access_idx.get();
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"), std::move(access_idx)),
|
||||||
std::move(access_idx)),
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 1u)));
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -749,30 +736,28 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
create<ast::Variable>("c", ast::StorageClass::kFunction, &u32));
|
||||||
|
|
||||||
auto access_idx = std::make_unique<ast::BinaryExpression>(
|
auto access_idx = create<ast::BinaryExpression>(
|
||||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("c"),
|
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("c"),
|
||||||
std::make_unique<ast::BinaryExpression>(
|
create<ast::BinaryExpression>(ast::BinaryOp::kSubtract,
|
||||||
ast::BinaryOp::kSubtract,
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 2)),
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2)),
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::UintLiteral>(&u32, 3))));
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 3))));
|
|
||||||
auto* access_ptr = access_idx.get();
|
auto* access_ptr = access_idx.get();
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u))),
|
create<ast::UintLiteral>(&u32, 1u))),
|
||||||
std::move(access_idx));
|
std::move(access_idx));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -829,19 +814,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Column) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, -1))),
|
create<ast::SintLiteral>(&i32, -1))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
create<ast::SintLiteral>(&i32, 1)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -884,19 +868,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Negative_Row) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
create<ast::SintLiteral>(&i32, 2))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::SintLiteral>(&i32, -1)));
|
create<ast::SintLiteral>(&i32, -1)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -940,19 +923,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Column) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 5u))),
|
create<ast::UintLiteral>(&u32, 5u))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 1u)));
|
create<ast::UintLiteral>(&u32, 1u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
@ -996,19 +978,18 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_OutOfBounds_Row) {
|
||||||
|
|
||||||
SetupFunctionAndBody();
|
SetupFunctionAndBody();
|
||||||
DeclareVariable(
|
DeclareVariable(
|
||||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
create<ast::Variable>("a", ast::StorageClass::kFunction, &mat));
|
||||||
|
|
||||||
auto accessor = std::make_unique<ast::ArrayAccessorExpression>(
|
auto accessor = create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
create<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<ast::IdentifierExpression>("a"),
|
create<ast::IdentifierExpression>("a"),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 2u))),
|
create<ast::UintLiteral>(&u32, 2u))),
|
||||||
std::make_unique<ast::ScalarConstructorExpression>(
|
create<ast::ScalarConstructorExpression>(
|
||||||
std::make_unique<ast::UintLiteral>(&u32, 5u)));
|
create<ast::UintLiteral>(&u32, 5u)));
|
||||||
auto* ptr = accessor.get();
|
auto* ptr = accessor.get();
|
||||||
|
|
||||||
auto b =
|
auto b = create<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
||||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32);
|
|
||||||
b->set_constructor(std::move(accessor));
|
b->set_constructor(std::move(accessor));
|
||||||
DeclareVariable(std::move(b));
|
DeclareVariable(std::move(b));
|
||||||
|
|
||||||
|
|
|
@ -35,17 +35,17 @@ namespace {
|
||||||
class VertexPullingTransformHelper {
|
class VertexPullingTransformHelper {
|
||||||
public:
|
public:
|
||||||
VertexPullingTransformHelper() {
|
VertexPullingTransformHelper() {
|
||||||
mod_ = std::make_unique<ast::Module>();
|
mod_ = create<ast::Module>();
|
||||||
transform_ = std::make_unique<VertexPullingTransform>(&ctx_, mod_.get());
|
transform_ = std::make_unique<VertexPullingTransform>(&ctx_, mod_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create basic module with an entry point and vertex function
|
// Create basic module with an entry point and vertex function
|
||||||
void InitBasicModule() {
|
void InitBasicModule() {
|
||||||
auto func = std::make_unique<ast::Function>(
|
auto func = create<ast::Function>(
|
||||||
"main", ast::VariableList{},
|
"main", ast::VariableList{},
|
||||||
ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
||||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
func->add_decoration(
|
||||||
ast::PipelineStage ::kVertex, Source{}));
|
create<ast::StageDecoration>(ast::PipelineStage ::kVertex, Source{}));
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +65,11 @@ class VertexPullingTransformHelper {
|
||||||
void AddVertexInputVariable(uint32_t location,
|
void AddVertexInputVariable(uint32_t location,
|
||||||
std::string name,
|
std::string name,
|
||||||
ast::type::Type* type) {
|
ast::type::Type* type) {
|
||||||
auto var = std::make_unique<ast::DecoratedVariable>(
|
auto var = create<ast::DecoratedVariable>(
|
||||||
std::make_unique<ast::Variable>(name, ast::StorageClass::kInput, type));
|
create<ast::Variable>(name, ast::StorageClass::kInput, type));
|
||||||
|
|
||||||
ast::VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(
|
decorations.push_back(create<ast::LocationDecoration>(location, Source{}));
|
||||||
std::make_unique<ast::LocationDecoration>(location, Source{}));
|
|
||||||
|
|
||||||
var->set_decorations(std::move(decorations));
|
var->set_decorations(std::move(decorations));
|
||||||
mod_->AddGlobalVariable(std::move(var));
|
mod_->AddGlobalVariable(std::move(var));
|
||||||
|
@ -80,6 +79,13 @@ class VertexPullingTransformHelper {
|
||||||
ast::Module* mod() { return mod_.get(); }
|
ast::Module* mod() { return mod_.get(); }
|
||||||
VertexPullingTransform* transform() { return transform_.get(); }
|
VertexPullingTransform* transform() { return transform_.get(); }
|
||||||
|
|
||||||
|
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
|
||||||
|
/// @param args the arguments to forward to the constructor for `T`
|
||||||
|
template <typename T, typename... ARGS>
|
||||||
|
std::unique_ptr<T> create(ARGS&&... args) {
|
||||||
|
return std::make_unique<T>(std::forward<ARGS>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Context ctx_;
|
Context ctx_;
|
||||||
std::unique_ptr<ast::Module> mod_;
|
std::unique_ptr<ast::Module> mod_;
|
||||||
|
@ -110,11 +116,11 @@ TEST_F(VertexPullingTransformTest, Error_InvalidEntryPoint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
|
TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
|
||||||
auto func = std::make_unique<ast::Function>(
|
auto func = create<ast::Function>(
|
||||||
"main", ast::VariableList{},
|
"main", ast::VariableList{},
|
||||||
ctx()->type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
ctx()->type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
||||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
func->add_decoration(
|
||||||
ast::PipelineStage::kFragment, Source{}));
|
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
|
|
||||||
InitTransform({});
|
InitTransform({});
|
||||||
|
@ -392,26 +398,26 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
|
||||||
|
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
{
|
{
|
||||||
auto vertex_index_var = std::make_unique<ast::DecoratedVariable>(
|
auto vertex_index_var =
|
||||||
std::make_unique<ast::Variable>("custom_vertex_index",
|
create<ast::DecoratedVariable>(create<ast::Variable>(
|
||||||
ast::StorageClass::kInput, &i32));
|
"custom_vertex_index", ast::StorageClass::kInput, &i32));
|
||||||
|
|
||||||
ast::VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(std::make_unique<ast::BuiltinDecoration>(
|
decorations.push_back(
|
||||||
ast::Builtin::kVertexIdx, Source{}));
|
create<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx, Source{}));
|
||||||
|
|
||||||
vertex_index_var->set_decorations(std::move(decorations));
|
vertex_index_var->set_decorations(std::move(decorations));
|
||||||
mod()->AddGlobalVariable(std::move(vertex_index_var));
|
mod()->AddGlobalVariable(std::move(vertex_index_var));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto instance_index_var = std::make_unique<ast::DecoratedVariable>(
|
auto instance_index_var =
|
||||||
std::make_unique<ast::Variable>("custom_instance_index",
|
create<ast::DecoratedVariable>(create<ast::Variable>(
|
||||||
ast::StorageClass::kInput, &i32));
|
"custom_instance_index", ast::StorageClass::kInput, &i32));
|
||||||
|
|
||||||
ast::VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(std::make_unique<ast::BuiltinDecoration>(
|
decorations.push_back(
|
||||||
ast::Builtin::kInstanceIdx, Source{}));
|
create<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx, Source{}));
|
||||||
|
|
||||||
instance_index_var->set_decorations(std::move(decorations));
|
instance_index_var->set_decorations(std::move(decorations));
|
||||||
mod()->AddGlobalVariable(std::move(instance_index_var));
|
mod()->AddGlobalVariable(std::move(instance_index_var));
|
||||||
|
|
Loading…
Reference in New Issue