tint: ProgramBuilder: Rename Const() to Let()
These methods produce `let` declarations. With creation-time expressions, we'll need to add `const` declarations. Note that module-scope `let` declarations have been removed in the spec (for `const`). ProgramBuilder::GlobalConst() has not been renamed, although it still currently produces 'let' declarations. Bug: tint:1504 Change-Id: I34f6d62236f0572163fc9c2d8fddfe4503817422 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88305 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
3e9077d04e
commit
e85fe161cd
|
@ -1166,9 +1166,9 @@ TEST_F(InspectorGetStorageSizeTest, Simple_NonStruct) {
|
|||
AddStorageBuffer("rosb_var", ty.i32(), ast::Access::kRead, 1, 1);
|
||||
Func("ep_func", {}, ty.void_(),
|
||||
{
|
||||
Decl(Const("ub", nullptr, Expr("ub_var"))),
|
||||
Decl(Const("sb", nullptr, Expr("sb_var"))),
|
||||
Decl(Const("rosb", nullptr, Expr("rosb_var"))),
|
||||
Decl(Let("ub", nullptr, Expr("ub_var"))),
|
||||
Decl(Let("sb", nullptr, Expr("sb_var"))),
|
||||
Decl(Let("rosb", nullptr, Expr("rosb_var"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
|
@ -1206,7 +1206,7 @@ TEST_F(InspectorGetStorageSizeTest, NonStructVec3) {
|
|||
AddUniformBuffer("ub_var", ty.vec3<f32>(), 0, 0);
|
||||
Func("ep_func", {}, ty.void_(),
|
||||
{
|
||||
Decl(Const("ub", nullptr, Expr("ub_var"))),
|
||||
Decl(Let("ub", nullptr, Expr("ub_var"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
|
@ -1220,7 +1220,7 @@ TEST_F(InspectorGetStorageSizeTest, StructVec3) {
|
|||
AddUniformBuffer("ub_var", ty.Of(ub_struct_type), 0, 0);
|
||||
Func("ep_func", {}, ty.void_(),
|
||||
{
|
||||
Decl(Const("ub", nullptr, Expr("ub_var"))),
|
||||
Decl(Let("ub", nullptr, Expr("ub_var"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
|
|||
const ast::Statement* ProgramBuilder::WrapInStatement(
|
||||
const ast::Expression* expr) {
|
||||
// Create a temporary variable of inferred type from expr.
|
||||
return Decl(Const(symbols_.New(), nullptr, expr));
|
||||
return Decl(Let(symbols_.New(), nullptr, expr));
|
||||
}
|
||||
|
||||
const ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(
|
||||
|
|
|
@ -1368,9 +1368,9 @@ class ProgramBuilder {
|
|||
/// @param type the variable type
|
||||
/// @param constructor constructor expression
|
||||
/// @param attributes optional variable attributes
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
/// @returns an immutable `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
const ast::Variable* Const(NAME&& name,
|
||||
const ast::Variable* Let(NAME&& name,
|
||||
const ast::Type* type,
|
||||
const ast::Expression* constructor,
|
||||
ast::AttributeList attributes = {}) {
|
||||
|
@ -1385,9 +1385,9 @@ class ProgramBuilder {
|
|||
/// @param type the variable type
|
||||
/// @param constructor constructor expression
|
||||
/// @param attributes optional variable attributes
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
/// @returns an immutable `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
const ast::Variable* Const(const Source& source,
|
||||
const ast::Variable* Let(const Source& source,
|
||||
NAME&& name,
|
||||
const ast::Type* type,
|
||||
const ast::Expression* constructor,
|
||||
|
@ -1401,7 +1401,7 @@ class ProgramBuilder {
|
|||
/// @param name the parameter name
|
||||
/// @param type the parameter type
|
||||
/// @param attributes optional parameter attributes
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
/// @returns an immutable `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
const ast::Variable* Param(NAME&& name,
|
||||
const ast::Type* type,
|
||||
|
@ -1416,7 +1416,7 @@ class ProgramBuilder {
|
|||
/// @param name the parameter name
|
||||
/// @param type the parameter type
|
||||
/// @param attributes optional parameter attributes
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
/// @returns an immutable `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
const ast::Variable* Param(const Source& source,
|
||||
NAME&& name,
|
||||
|
@ -1488,8 +1488,8 @@ class ProgramBuilder {
|
|||
const ast::Type* type,
|
||||
const ast::Expression* constructor,
|
||||
ast::AttributeList attributes = {}) {
|
||||
auto* var = Const(std::forward<NAME>(name), type, constructor,
|
||||
std::move(attributes));
|
||||
auto* var =
|
||||
Let(std::forward<NAME>(name), type, constructor, std::move(attributes));
|
||||
AST().AddGlobalVariable(var);
|
||||
return var;
|
||||
}
|
||||
|
@ -1508,7 +1508,7 @@ class ProgramBuilder {
|
|||
const ast::Type* type,
|
||||
const ast::Expression* constructor,
|
||||
ast::AttributeList attributes = {}) {
|
||||
auto* var = Const(source, std::forward<NAME>(name), type, constructor,
|
||||
auto* var = Let(source, std::forward<NAME>(name), type, constructor,
|
||||
std::move(attributes));
|
||||
AST().AddGlobalVariable(var);
|
||||
return var;
|
||||
|
|
|
@ -206,7 +206,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
|||
// let a : array<f32, 3> = 0;
|
||||
// var idx : i32 = 0;
|
||||
// var f : f32 = a[idx];
|
||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* idx = Var("idx", ty.i32(), Construct(ty.i32()));
|
||||
auto* f = Var("f", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, idx)));
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
|
@ -224,7 +224,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
|||
TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
|
||||
// let a : array<f32, 3>;
|
||||
// var f : f32 = a[2.0f];
|
||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* f =
|
||||
Var("a_2", ty.f32(), IndexAccessor("a", Expr(Source{{12, 34}}, 2.0f)));
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
|
@ -241,7 +241,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
|
|||
TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) {
|
||||
// let a : array<f32, 3>;
|
||||
// var f : f32 = a[2];
|
||||
auto* a = Const("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* a = Let("a", ty.array<f32, 3>(), array<f32, 3>());
|
||||
auto* f = Var("a_2", ty.f32(), IndexAccessor("a", 2));
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
|
@ -260,7 +260,7 @@ TEST_F(ResolverIndexAccessorTest, EXpr_Deref_FuncGoodParent) {
|
|||
// }
|
||||
auto* p =
|
||||
Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
|
||||
auto* idx = Const("idx", ty.u32(), Construct(ty.u32()));
|
||||
auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
|
||||
auto* star_p = Deref(p);
|
||||
auto* accessor_expr = IndexAccessor(Source{{12, 34}}, star_p, idx);
|
||||
auto* x = Var("x", ty.f32(), accessor_expr);
|
||||
|
@ -277,7 +277,7 @@ TEST_F(ResolverIndexAccessorTest, EXpr_Deref_FuncBadParent) {
|
|||
// }
|
||||
auto* p =
|
||||
Param("p", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction));
|
||||
auto* idx = Const("idx", ty.u32(), Construct(ty.u32()));
|
||||
auto* idx = Let("idx", ty.u32(), Construct(ty.u32()));
|
||||
auto* accessor_expr = IndexAccessor(Source{{12, 34}}, p, idx);
|
||||
auto* star_p = Deref(accessor_expr);
|
||||
auto* x = Var("x", ty.f32(), star_p);
|
||||
|
|
|
@ -198,7 +198,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
|
|||
// *b = 2;
|
||||
const auto func = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", ty.i32(), func, Expr(2));
|
||||
auto* var_b = Const("b", ty.pointer<int>(func), AddressOf(Expr("a")));
|
||||
auto* var_b = Let("b", ty.pointer<int>(func), AddressOf(Expr("a")));
|
||||
WrapInFunction(var_a, var_b, Assign(Source{{12, 34}}, Deref("b"), 2));
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -209,7 +209,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) {
|
|||
// let a : i32 = 2;
|
||||
// a = 2
|
||||
// }
|
||||
auto* var = Const("a", ty.i32(), Expr(2));
|
||||
auto* var = Let("a", ty.i32(), Expr(2));
|
||||
WrapInFunction(var, Assign(Expr(Source{{12, 34}}, "a"), 2));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -117,7 +117,7 @@ TEST_P(ResolverBitcastValidationTestInvalidSrcTy, Test) {
|
|||
auto dst = std::get<1>(GetParam());
|
||||
|
||||
auto* cast = Bitcast(dst.ast(*this), Expr(Source{{12, 34}}, "src"));
|
||||
WrapInFunction(Const("src", nullptr, src.expr(*this, 0)), cast);
|
||||
WrapInFunction(Let("src", nullptr, src.expr(*this, 0)), cast);
|
||||
|
||||
auto expected = "12:34 error: '" + src.sem(*this)->FriendlyName(Symbols()) +
|
||||
"' cannot be bitcast";
|
||||
|
|
|
@ -101,7 +101,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_ConstIdentExpr) {
|
|||
Func("foo", {param}, ty.void_(), {});
|
||||
Func("main", {}, ty.void_(),
|
||||
{
|
||||
Decl(Const("z", ty.i32(), Expr(1))),
|
||||
Decl(Let("z", ty.i32(), Expr(1))),
|
||||
CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}}, "z")))),
|
||||
});
|
||||
|
||||
|
@ -144,7 +144,7 @@ TEST_F(ResolverCallValidationTest, PointerArgument_AddressOfMemberAccessor) {
|
|||
Func("foo", {param}, ty.void_(), {});
|
||||
Func("main", {}, ty.void_(),
|
||||
{
|
||||
Decl(Const("v", ty.Of(S), Construct(ty.Of(S)))),
|
||||
Decl(Let("v", ty.Of(S), Construct(ty.Of(S)))),
|
||||
CallStmt(Call("foo", AddressOf(Expr(Source{{12, 34}},
|
||||
MemberAccessor("v", "m"))))),
|
||||
});
|
||||
|
@ -203,7 +203,7 @@ TEST_F(ResolverCallValidationTest, LetPointer) {
|
|||
Func("x", {Param("p", ty.pointer<i32>(ast::StorageClass::kFunction))},
|
||||
ty.void_(), {});
|
||||
auto* v = Var("v", ty.i32());
|
||||
auto* p = Const("p", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
|
||||
auto* p = Let("p", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
|
||||
AddressOf(v));
|
||||
auto* c = Var("c", ty.i32(), ast::StorageClass::kNone,
|
||||
Call("x", Expr(Source{{12, 34}}, p)));
|
||||
|
@ -233,8 +233,8 @@ TEST_F(ResolverCallValidationTest, LetPointerPrivate) {
|
|||
Func("foo", {Param("p", ty.pointer<i32>(ast::StorageClass::kPrivate))},
|
||||
ty.void_(), {});
|
||||
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const("p", ty.pointer(ty.i32(), ast::StorageClass::kPrivate),
|
||||
AddressOf(v));
|
||||
auto* p =
|
||||
Let("p", ty.pointer(ty.i32(), ast::StorageClass::kPrivate), AddressOf(v));
|
||||
auto* c = Var("c", ty.i32(), ast::StorageClass::kNone,
|
||||
Call("foo", Expr(Source{{12, 34}}, p)));
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest,
|
|||
// *b += 2;
|
||||
const auto func = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", ty.i32(), func, Expr(2));
|
||||
auto* var_b = Const("b", ty.pointer<int>(func), AddressOf(Expr("a")));
|
||||
auto* var_b = Let("b", ty.pointer<int>(func), AddressOf(Expr("a")));
|
||||
WrapInFunction(
|
||||
var_a, var_b,
|
||||
CompoundAssign(Source{{12, 34}}, Deref("b"), 2, ast::BinaryOp::kAdd));
|
||||
|
@ -262,7 +262,7 @@ TEST_F(ResolverCompoundAssignmentValidationTest, ReadOnlyBuffer) {
|
|||
TEST_F(ResolverCompoundAssignmentValidationTest, LhsConstant) {
|
||||
// let a = 1;
|
||||
// a += 1;
|
||||
auto* a = Const(Source{{12, 34}}, "a", nullptr, Expr(1));
|
||||
auto* a = Let(Source{{12, 34}}, "a", nullptr, Expr(1));
|
||||
WrapInFunction(
|
||||
a, CompoundAssign(Expr(Source{{56, 78}}, "a"), 1, ast::BinaryOp::kAdd));
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ using ResolverDependencyGraphTest =
|
|||
/// kinds of symbol declarations.
|
||||
enum class SymbolDeclKind {
|
||||
GlobalVar,
|
||||
GlobalLet,
|
||||
GlobalConst,
|
||||
Alias,
|
||||
Struct,
|
||||
Function,
|
||||
|
@ -65,7 +65,7 @@ enum class SymbolDeclKind {
|
|||
};
|
||||
|
||||
static constexpr SymbolDeclKind kAllSymbolDeclKinds[] = {
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet,
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
|
||||
SymbolDeclKind::Alias, SymbolDeclKind::Struct,
|
||||
SymbolDeclKind::Function, SymbolDeclKind::Parameter,
|
||||
SymbolDeclKind::LocalVar, SymbolDeclKind::LocalLet,
|
||||
|
@ -78,15 +78,16 @@ static constexpr SymbolDeclKind kTypeDeclKinds[] = {
|
|||
};
|
||||
|
||||
static constexpr SymbolDeclKind kValueDeclKinds[] = {
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet,
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
|
||||
SymbolDeclKind::Parameter, SymbolDeclKind::LocalVar,
|
||||
SymbolDeclKind::LocalLet, SymbolDeclKind::NestedLocalVar,
|
||||
SymbolDeclKind::NestedLocalLet,
|
||||
};
|
||||
|
||||
static constexpr SymbolDeclKind kGlobalDeclKinds[] = {
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalLet, SymbolDeclKind::Alias,
|
||||
SymbolDeclKind::Struct, SymbolDeclKind::Function,
|
||||
SymbolDeclKind::GlobalVar, SymbolDeclKind::GlobalConst,
|
||||
SymbolDeclKind::Alias, SymbolDeclKind::Struct,
|
||||
SymbolDeclKind::Function,
|
||||
};
|
||||
|
||||
static constexpr SymbolDeclKind kLocalDeclKinds[] = {
|
||||
|
@ -97,7 +98,7 @@ static constexpr SymbolDeclKind kLocalDeclKinds[] = {
|
|||
|
||||
static constexpr SymbolDeclKind kGlobalValueDeclKinds[] = {
|
||||
SymbolDeclKind::GlobalVar,
|
||||
SymbolDeclKind::GlobalLet,
|
||||
SymbolDeclKind::GlobalConst,
|
||||
};
|
||||
|
||||
static constexpr SymbolDeclKind kFuncDeclKinds[] = {
|
||||
|
@ -183,7 +184,7 @@ std::ostream& operator<<(std::ostream& out, SymbolDeclKind kind) {
|
|||
switch (kind) {
|
||||
case SymbolDeclKind::GlobalVar:
|
||||
return out << "global var";
|
||||
case SymbolDeclKind::GlobalLet:
|
||||
case SymbolDeclKind::GlobalConst:
|
||||
return out << "global let";
|
||||
case SymbolDeclKind::Alias:
|
||||
return out << "alias";
|
||||
|
@ -322,7 +323,7 @@ std::string DiagString(SymbolUseKind kind) {
|
|||
int ScopeDepth(SymbolDeclKind kind) {
|
||||
switch (kind) {
|
||||
case SymbolDeclKind::GlobalVar:
|
||||
case SymbolDeclKind::GlobalLet:
|
||||
case SymbolDeclKind::GlobalConst:
|
||||
case SymbolDeclKind::Alias:
|
||||
case SymbolDeclKind::Struct:
|
||||
case SymbolDeclKind::Function:
|
||||
|
@ -430,7 +431,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
|
|||
switch (kind) {
|
||||
case SymbolDeclKind::GlobalVar:
|
||||
return b.Global(source, symbol, b.ty.i32(), ast::StorageClass::kPrivate);
|
||||
case SymbolDeclKind::GlobalLet:
|
||||
case SymbolDeclKind::GlobalConst:
|
||||
return b.GlobalConst(source, symbol, b.ty.i32(), b.Expr(1));
|
||||
case SymbolDeclKind::Alias:
|
||||
return b.Alias(source, symbol, b.ty.i32());
|
||||
|
@ -449,7 +450,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
|
|||
return node;
|
||||
}
|
||||
case SymbolDeclKind::LocalLet: {
|
||||
auto* node = b.Const(source, symbol, b.ty.i32(), b.Expr(1));
|
||||
auto* node = b.Let(source, symbol, b.ty.i32(), b.Expr(1));
|
||||
statements.emplace_back(b.Decl(node));
|
||||
return node;
|
||||
}
|
||||
|
@ -459,7 +460,7 @@ const ast::Node* SymbolTestHelper::Add(SymbolDeclKind kind,
|
|||
return node;
|
||||
}
|
||||
case SymbolDeclKind::NestedLocalLet: {
|
||||
auto* node = b.Const(source, symbol, b.ty.i32(), b.Expr(1));
|
||||
auto* node = b.Let(source, symbol, b.ty.i32(), b.Expr(1));
|
||||
nested_statements.emplace_back(b.Decl(node));
|
||||
return node;
|
||||
}
|
||||
|
@ -598,12 +599,12 @@ const ast::Node* SymbolTestHelper::Add(SymbolUseKind kind,
|
|||
}
|
||||
case SymbolUseKind::LocalLetType: {
|
||||
auto* node = b.ty.type_name(source, symbol);
|
||||
statements.emplace_back(b.Decl(b.Const(b.Sym(), node, b.Expr(1))));
|
||||
statements.emplace_back(b.Decl(b.Let(b.Sym(), node, b.Expr(1))));
|
||||
return node;
|
||||
}
|
||||
case SymbolUseKind::LocalLetValue: {
|
||||
auto* node = b.Expr(source, symbol);
|
||||
statements.emplace_back(b.Decl(b.Const(b.Sym(), b.ty.i32(), node)));
|
||||
statements.emplace_back(b.Decl(b.Let(b.Sym(), b.ty.i32(), node)));
|
||||
return node;
|
||||
}
|
||||
case SymbolUseKind::NestedLocalVarType: {
|
||||
|
@ -618,13 +619,12 @@ const ast::Node* SymbolTestHelper::Add(SymbolUseKind kind,
|
|||
}
|
||||
case SymbolUseKind::NestedLocalLetType: {
|
||||
auto* node = b.ty.type_name(source, symbol);
|
||||
nested_statements.emplace_back(b.Decl(b.Const(b.Sym(), node, b.Expr(1))));
|
||||
nested_statements.emplace_back(b.Decl(b.Let(b.Sym(), node, b.Expr(1))));
|
||||
return node;
|
||||
}
|
||||
case SymbolUseKind::NestedLocalLetValue: {
|
||||
auto* node = b.Expr(source, symbol);
|
||||
nested_statements.emplace_back(
|
||||
b.Decl(b.Const(b.Sym(), b.ty.i32(), node)));
|
||||
nested_statements.emplace_back(b.Decl(b.Let(b.Sym(), b.ty.i32(), node)));
|
||||
return node;
|
||||
}
|
||||
case SymbolUseKind::WorkgroupSizeValue: {
|
||||
|
@ -788,7 +788,7 @@ TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalVar) {
|
|||
12:34 note: var 'SYMBOL' references var 'SYMBOL' here)");
|
||||
}
|
||||
|
||||
TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalLet) {
|
||||
TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalConst) {
|
||||
const Symbol symbol = Sym("SYMBOL");
|
||||
GlobalConst(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123));
|
||||
Build(R"(error: cyclic dependency found: 'SYMBOL' -> 'SYMBOL'
|
||||
|
@ -805,7 +805,7 @@ TEST_F(ResolverDependencyGraphDeclSelfUse, LocalVar) {
|
|||
TEST_F(ResolverDependencyGraphDeclSelfUse, LocalLet) {
|
||||
const Symbol symbol = Sym("SYMBOL");
|
||||
WrapInFunction(
|
||||
Decl(Const(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123))));
|
||||
Decl(Let(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123))));
|
||||
Build("12:34 error: unknown identifier: 'SYMBOL'");
|
||||
}
|
||||
|
||||
|
@ -1180,14 +1180,12 @@ TEST_P(ResolverDependencyShadowTest, Test) {
|
|||
SymbolTestHelper helper(this);
|
||||
auto* outer = helper.Add(outer_kind, symbol, Source{{12, 34}});
|
||||
helper.Add(inner_kind, symbol, Source{{56, 78}});
|
||||
auto* inner_var = helper.nested_statements.size()
|
||||
? helper.nested_statements[0]
|
||||
auto* inner_var =
|
||||
helper.nested_statements.size() ? helper.nested_statements[0]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable
|
||||
: helper.statements.size()
|
||||
? helper.statements[0]
|
||||
->As<ast::VariableDeclStatement>()
|
||||
->variable
|
||||
? helper.statements[0]->As<ast::VariableDeclStatement>()->variable
|
||||
: helper.parameters[0];
|
||||
helper.Build();
|
||||
|
||||
|
@ -1255,7 +1253,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
|
|||
T, // Return type
|
||||
{
|
||||
Decl(Var(Sym(), T, V)), //
|
||||
Decl(Const(Sym(), T, V)), //
|
||||
Decl(Let(Sym(), T, V)), //
|
||||
CallStmt(Call(F, V)), //
|
||||
Block( //
|
||||
Assign(V, V)), //
|
||||
|
@ -1317,7 +1315,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, InferredType) {
|
|||
Global("a", nullptr, Expr(1));
|
||||
GlobalConst("b", nullptr, Expr(1));
|
||||
WrapInFunction(Var("c", nullptr, Expr(1)), //
|
||||
Const("d", nullptr, Expr(1)));
|
||||
Let("d", nullptr, Expr(1)));
|
||||
Build();
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST_F(ResolverFunctionValidationTest, LocalConflictsWithParameter) {
|
|||
// let common_name = 1;
|
||||
// }
|
||||
Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(),
|
||||
{Decl(Const(Source{{56, 78}}, "common_name", nullptr, Expr(1)))});
|
||||
{Decl(Let(Source{{56, 78}}, "common_name", nullptr, Expr(1)))});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), R"(56:78 error: redeclaration of 'common_name'
|
||||
|
@ -63,7 +63,7 @@ TEST_F(ResolverFunctionValidationTest, NestedLocalMayShadowParameter) {
|
|||
// }
|
||||
// }
|
||||
Func("func", {Param(Source{{12, 34}}, "common_name", ty.f32())}, ty.void_(),
|
||||
{Block(Decl(Const(Source{{56, 78}}, "common_name", nullptr, Expr(1))))});
|
||||
{Block(Decl(Let(Source{{56, 78}}, "common_name", nullptr, Expr(1))))});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) {
|
|||
// }
|
||||
|
||||
auto* bar = Param("bar", ty.f32());
|
||||
auto* baz = Const("baz", ty.f32(), Expr("bar"));
|
||||
auto* baz = Let("baz", ty.f32(), Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::AttributeList{});
|
||||
|
|
|
@ -63,7 +63,7 @@ TEST_F(ResolverIncrementDecrementValidationTest, ThroughPointer) {
|
|||
// let b : ptr<function,i32> = &a;
|
||||
// *b++;
|
||||
auto* var_a = Var("a", ty.i32(), ast::StorageClass::kFunction);
|
||||
auto* var_b = Const("b", ty.pointer<int>(ast::StorageClass::kFunction),
|
||||
auto* var_b = Let("b", ty.pointer<int>(ast::StorageClass::kFunction),
|
||||
AddressOf(Expr("a")));
|
||||
WrapInFunction(var_a, var_b, Increment(Source{{12, 34}}, Deref("b")));
|
||||
|
||||
|
@ -147,7 +147,7 @@ TEST_F(ResolverIncrementDecrementValidationTest, Literal) {
|
|||
TEST_F(ResolverIncrementDecrementValidationTest, Constant) {
|
||||
// let a = 1;
|
||||
// a++;
|
||||
auto* a = Const(Source{{12, 34}}, "a", nullptr, Expr(1));
|
||||
auto* a = Let(Source{{12, 34}}, "a", nullptr, Expr(1));
|
||||
WrapInFunction(a, Increment(Expr(Source{{56, 78}}, "a")));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -112,7 +112,7 @@ TEST_P(ResolverInferredTypeParamTest, LocalLet_Pass) {
|
|||
|
||||
// let a = <type constructor>;
|
||||
auto* ctor_expr = params.create_value(*this, 0);
|
||||
auto* var = Const("a", nullptr, ctor_expr);
|
||||
auto* var = Let("a", nullptr, ctor_expr);
|
||||
WrapInFunction(var);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -75,19 +75,19 @@ TEST_F(ResolverPtrRefTest, DefaultPtrStorageClass) {
|
|||
});
|
||||
|
||||
auto* function_ptr =
|
||||
Const("f_ptr", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
|
||||
Let("f_ptr", ty.pointer(ty.i32(), ast::StorageClass::kFunction),
|
||||
AddressOf(function));
|
||||
auto* private_ptr =
|
||||
Const("p_ptr", ty.pointer(ty.i32(), ast::StorageClass::kPrivate),
|
||||
Let("p_ptr", ty.pointer(ty.i32(), ast::StorageClass::kPrivate),
|
||||
AddressOf(private_));
|
||||
auto* workgroup_ptr =
|
||||
Const("w_ptr", ty.pointer(ty.i32(), ast::StorageClass::kWorkgroup),
|
||||
Let("w_ptr", ty.pointer(ty.i32(), ast::StorageClass::kWorkgroup),
|
||||
AddressOf(workgroup));
|
||||
auto* uniform_ptr =
|
||||
Const("ub_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kUniform),
|
||||
Let("ub_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kUniform),
|
||||
AddressOf(uniform));
|
||||
auto* storage_ptr =
|
||||
Const("sb_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kStorage),
|
||||
Let("sb_ptr", ty.pointer(ty.Of(buf), ast::StorageClass::kStorage),
|
||||
AddressOf(storage));
|
||||
|
||||
WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr,
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfLiteral) {
|
|||
TEST_F(ResolverPtrRefValidationTest, AddressOfLet) {
|
||||
// let l : i32 = 1;
|
||||
// &l
|
||||
auto* l = Const("l", ty.i32(), Expr(1));
|
||||
auto* l = Let("l", ty.i32(), Expr(1));
|
||||
auto* expr = AddressOf(Expr(Source{{12, 34}}, "l"));
|
||||
|
||||
WrapInFunction(l, expr);
|
||||
|
@ -156,7 +156,7 @@ TEST_F(ResolverPtrRefValidationTest, InferredPtrAccessMismatch) {
|
|||
auto* expr =
|
||||
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
|
||||
auto* ptr =
|
||||
Const(Source{{12, 34}}, "p", ty.pointer<i32>(ast::StorageClass::kStorage),
|
||||
Let(Source{{12, 34}}, "p", ty.pointer<i32>(ast::StorageClass::kStorage),
|
||||
AddressOf(expr));
|
||||
|
||||
WrapInFunction(ptr);
|
||||
|
|
|
@ -392,7 +392,7 @@ TEST_F(ResolverBehaviorTest, StmtIfTrue_ThenEmptyBlock_ElseCallFuncMayDiscard) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtLetDecl) {
|
||||
auto* stmt = Decl(Const("v", ty.i32(), Expr(1)));
|
||||
auto* stmt = Decl(Let("v", ty.i32(), Expr(1)));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -402,7 +402,7 @@ TEST_F(ResolverBehaviorTest, StmtLetDecl) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtLetDecl_RHSDiscardOrNext) {
|
||||
auto* stmt = Decl(Const("lhs", ty.i32(), Call("DiscardOrNext")));
|
||||
auto* stmt = Decl(Let("lhs", ty.i32(), Call("DiscardOrNext")));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -635,7 +635,7 @@ TEST_F(ResolverTest, Expr_Identifier_GlobalConstant) {
|
|||
|
||||
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
|
||||
auto* my_var_a = Expr("my_var");
|
||||
auto* var = Const("my_var", ty.f32(), Construct(ty.f32()));
|
||||
auto* var = Let("my_var", ty.f32(), Construct(ty.f32()));
|
||||
auto* decl = Decl(Var("b", ty.f32(), ast::StorageClass::kNone, my_var_a));
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
|
@ -711,7 +711,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
|
|||
auto* p = Expr("p");
|
||||
auto* v_decl = Decl(Var("v", ty.f32()));
|
||||
auto* p_decl = Decl(
|
||||
Const("p", ty.pointer<f32>(ast::StorageClass::kFunction), AddressOf(v)));
|
||||
Let("p", ty.pointer<f32>(ast::StorageClass::kFunction), AddressOf(v)));
|
||||
auto* assign = Assign(Deref(p), 1.23f);
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
|
@ -868,7 +868,7 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
|
|||
TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) {
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
Decl(Const("var", ty.f32(), Construct(ty.f32()))),
|
||||
Decl(Let("var", ty.f32(), Construct(ty.f32()))),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -881,7 +881,7 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionConstant) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, Function_NotRegisterFunctionParams) {
|
||||
auto* func = Func("my_func", {Const("var", ty.f32(), Construct(ty.f32()))},
|
||||
auto* func = Func("my_func", {Let("var", ty.f32(), Construct(ty.f32()))},
|
||||
ty.void_(), {});
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -1782,7 +1782,7 @@ TEST_F(ResolverTest, StorageClass_SetForTexture) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
|
||||
auto* var = Const("var", ty.i32(), Construct(ty.i32()));
|
||||
auto* var = Let("var", ty.i32(), Construct(ty.i32()));
|
||||
auto* stmt = Decl(var);
|
||||
Func("func", ast::VariableList{}, ty.void_(), {stmt}, ast::AttributeList{});
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ TEST_F(ResolverSourceVariableTest, GlobalOverride) {
|
|||
EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a);
|
||||
}
|
||||
|
||||
TEST_F(ResolverSourceVariableTest, GlobalLet) {
|
||||
TEST_F(ResolverSourceVariableTest, GlobalConst) {
|
||||
auto* a = GlobalConst("a", ty.f32(), Expr(1.f));
|
||||
auto* expr = Expr(a);
|
||||
WrapInFunction(expr);
|
||||
|
@ -115,7 +115,7 @@ TEST_F(ResolverSourceVariableTest, FunctionVar) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverSourceVariableTest, FunctionLet) {
|
||||
auto* a = Const("a", ty.f32(), Expr(1.f));
|
||||
auto* a = Let("a", ty.f32(), Expr(1.f));
|
||||
auto* expr = Expr(a);
|
||||
WrapInFunction(a, expr);
|
||||
|
||||
|
@ -143,7 +143,7 @@ TEST_F(ResolverSourceVariableTest, PointerParameter) {
|
|||
// }
|
||||
auto* param = Param("a", ty.pointer(ty.f32(), ast::StorageClass::kFunction));
|
||||
auto* expr_param = Expr(param);
|
||||
auto* let = Const("b", nullptr, expr_param);
|
||||
auto* let = Let("b", nullptr, expr_param);
|
||||
auto* expr_let = Expr("b");
|
||||
Func("foo", {param}, ty.void_(),
|
||||
{WrapInStatement(let), WrapInStatement(expr_let)});
|
||||
|
@ -181,7 +181,7 @@ TEST_F(ResolverSourceVariableTest, LetCopyVar) {
|
|||
// }
|
||||
auto* a = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* expr_a = Expr(a);
|
||||
auto* b = Const("b", ty.f32(), expr_a);
|
||||
auto* b = Let("b", ty.f32(), expr_a);
|
||||
auto* expr_b = Expr(b);
|
||||
WrapInFunction(a, b, expr_b);
|
||||
|
||||
|
@ -235,10 +235,10 @@ TEST_F(ResolverSourceVariableTest, ThroughPointers) {
|
|||
auto* address_of_1 = AddressOf(a);
|
||||
auto* deref_1 = Deref(address_of_1);
|
||||
auto* address_of_2 = AddressOf(deref_1);
|
||||
auto* a_ptr1 = Const("a_ptr1", nullptr, address_of_2);
|
||||
auto* a_ptr1 = Let("a_ptr1", nullptr, address_of_2);
|
||||
auto* deref_2 = Deref(a_ptr1);
|
||||
auto* address_of_3 = AddressOf(deref_2);
|
||||
auto* a_ptr2 = Const("a_ptr2", nullptr, address_of_3);
|
||||
auto* a_ptr2 = Let("a_ptr2", nullptr, address_of_3);
|
||||
WrapInFunction(a_ptr1, a_ptr2);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -371,7 +371,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FunctionConstant) {
|
|||
// let size = 10;
|
||||
// var a : array<f32, size>;
|
||||
// }
|
||||
auto* size = Const("size", nullptr, Expr(10));
|
||||
auto* size = Let("size", nullptr, Expr(10));
|
||||
auto* a = Var("a", ty.array(ty.f32(), Expr(Source{{12, 34}}, "size")));
|
||||
WrapInFunction(Block(Decl(size), Decl(a)));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -382,7 +382,7 @@ TEST_F(ResolverTypeValidationTest, ArraySize_FunctionConstant) {
|
|||
|
||||
TEST_F(ResolverTypeValidationTest, ArraySize_InvalidExpr) {
|
||||
// var a : array<f32, i32(4)>;
|
||||
auto* size = Const("size", nullptr, Expr(10));
|
||||
auto* size = Let("size", nullptr, Expr(10));
|
||||
auto* a =
|
||||
Var("a", ty.array(ty.f32(), Construct(Source{{12, 34}}, ty.i32(), 4)));
|
||||
WrapInFunction(Block(Decl(size), Decl(a)));
|
||||
|
|
|
@ -1304,7 +1304,7 @@ TEST_F(ResolverTest, Expr_Constructor_Cast_Pointer) {
|
|||
auto* c =
|
||||
Construct(Source{{12, 34}}, ty.pointer<i32>(ast::StorageClass::kFunction),
|
||||
ExprList(vf));
|
||||
auto* ip = Const("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c);
|
||||
auto* ip = Let("ip", ty.pointer<i32>(ast::StorageClass::kFunction), c);
|
||||
WrapInFunction(Decl(vf), Decl(ip));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -170,13 +170,13 @@ TEST_F(ResolverVarLetTest, LetDecl) {
|
|||
auto* a_c = Construct(ty.Of(A), Expr(1));
|
||||
auto* p_c = AddressOf(v);
|
||||
|
||||
auto* i = Const("i", ty.i32(), i_c);
|
||||
auto* u = Const("u", ty.u32(), u_c);
|
||||
auto* f = Const("f", ty.f32(), f_c);
|
||||
auto* b = Const("b", ty.bool_(), b_c);
|
||||
auto* s = Const("s", ty.Of(S), s_c);
|
||||
auto* a = Const("a", ty.Of(A), a_c);
|
||||
auto* p = Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), p_c);
|
||||
auto* i = Let("i", ty.i32(), i_c);
|
||||
auto* u = Let("u", ty.u32(), u_c);
|
||||
auto* f = Let("f", ty.f32(), f_c);
|
||||
auto* b = Let("b", ty.bool_(), b_c);
|
||||
auto* s = Let("s", ty.Of(S), s_c);
|
||||
auto* a = Let("a", ty.Of(A), a_c);
|
||||
auto* p = Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), p_c);
|
||||
|
||||
Func("F", {}, ty.void_(),
|
||||
{
|
||||
|
@ -299,7 +299,7 @@ TEST_F(ResolverVarLetTest, LetInheritsAccessFromOriginatingVariable) {
|
|||
|
||||
auto* expr =
|
||||
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
|
||||
auto* ptr = Const("p", nullptr, AddressOf(expr));
|
||||
auto* ptr = Let("p", nullptr, AddressOf(expr));
|
||||
|
||||
WrapInFunction(ptr);
|
||||
|
||||
|
@ -326,7 +326,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsAlias) {
|
|||
|
||||
auto* t = Alias("a", ty.i32());
|
||||
auto* v = Var("a", nullptr, Expr(false));
|
||||
auto* l = Const("a", nullptr, Expr(false));
|
||||
auto* l = Let("a", nullptr, Expr(false));
|
||||
Func("X", {}, ty.void_(), {Decl(v)});
|
||||
Func("Y", {}, ty.void_(), {Decl(l)});
|
||||
|
||||
|
@ -358,7 +358,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsStruct) {
|
|||
|
||||
auto* t = Structure("a", {Member("m", ty.i32())});
|
||||
auto* v = Var("a", nullptr, Expr(false));
|
||||
auto* l = Const("a", nullptr, Expr(false));
|
||||
auto* l = Let("a", nullptr, Expr(false));
|
||||
Func("X", {}, ty.void_(), {Decl(v)});
|
||||
Func("Y", {}, ty.void_(), {Decl(l)});
|
||||
|
||||
|
@ -385,7 +385,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsFunction) {
|
|||
// }
|
||||
|
||||
auto* v = Var("a", nullptr, Expr(false));
|
||||
auto* l = Const("b", nullptr, Expr(false));
|
||||
auto* l = Let("b", nullptr, Expr(false));
|
||||
auto* fa = Func("a", {}, ty.void_(), {Decl(v)});
|
||||
auto* fb = Func("b", {}, ty.void_(), {Decl(l)});
|
||||
|
||||
|
@ -418,7 +418,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsGlobalVar) {
|
|||
|
||||
auto* g = Global("a", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* v = Var("a", nullptr, Expr("a"));
|
||||
auto* l = Const("a", nullptr, Expr("a"));
|
||||
auto* l = Let("a", nullptr, Expr("a"));
|
||||
Func("X", {}, ty.void_(), {Decl(v)});
|
||||
Func("Y", {}, ty.void_(), {Decl(l)});
|
||||
|
||||
|
@ -459,7 +459,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsGlobalLet) {
|
|||
|
||||
auto* g = GlobalConst("a", ty.i32(), Expr(1));
|
||||
auto* v = Var("a", nullptr, Expr("a"));
|
||||
auto* l = Const("a", nullptr, Expr("a"));
|
||||
auto* l = Let("a", nullptr, Expr("a"));
|
||||
Func("X", {}, ty.void_(), {Decl(v)});
|
||||
Func("Y", {}, ty.void_(), {Decl(l)});
|
||||
|
||||
|
@ -500,7 +500,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsLocalVar) {
|
|||
|
||||
auto* s = Var("a", ty.i32(), Expr(1));
|
||||
auto* v = Var("a", nullptr, Expr("a"));
|
||||
auto* l = Const("a", nullptr, Expr("a"));
|
||||
auto* l = Let("a", nullptr, Expr("a"));
|
||||
Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -539,9 +539,9 @@ TEST_F(ResolverVarLetTest, LocalShadowsLocalLet) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto* s = Const("a", ty.i32(), Expr(1));
|
||||
auto* s = Let("a", ty.i32(), Expr(1));
|
||||
auto* v = Var("a", nullptr, Expr("a"));
|
||||
auto* l = Const("a", nullptr, Expr("a"));
|
||||
auto* l = Let("a", nullptr, Expr("a"));
|
||||
Func("X", {}, ty.void_(), {Decl(s), Block(Decl(v)), Block(Decl(l))});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -581,7 +581,7 @@ TEST_F(ResolverVarLetTest, LocalShadowsParam) {
|
|||
|
||||
auto* p = Param("a", ty.i32());
|
||||
auto* v = Var("a", nullptr, Expr("a"));
|
||||
auto* l = Const("a", nullptr, Expr("a"));
|
||||
auto* l = Let("a", nullptr, Expr("a"));
|
||||
Func("X", {p}, ty.void_(), {Block(Decl(v)), Block(Decl(l))});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -25,7 +25,7 @@ struct ResolverVarLetValidationTest : public resolver::TestHelper,
|
|||
|
||||
TEST_F(ResolverVarLetValidationTest, LetNoInitializer) {
|
||||
// let a : i32;
|
||||
WrapInFunction(Const(Source{{12, 34}}, "a", ty.i32(), nullptr));
|
||||
WrapInFunction(Let(Source{{12, 34}}, "a", ty.i32(), nullptr));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
@ -82,7 +82,7 @@ TEST_F(ResolverVarLetValidationTest, LetTypeNotConstructible) {
|
|||
auto* t1 =
|
||||
Global("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()),
|
||||
GroupAndBinding(0, 0));
|
||||
auto* t2 = Const(Source{{56, 78}}, "t2", nullptr, Expr(t1));
|
||||
auto* t2 = Let(Source{{56, 78}}, "t2", nullptr, Expr(t1));
|
||||
WrapInFunction(t2);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -92,7 +92,7 @@ TEST_F(ResolverVarLetValidationTest, LetTypeNotConstructible) {
|
|||
|
||||
TEST_F(ResolverVarLetValidationTest, LetConstructorWrongType) {
|
||||
// var v : i32 = 2u
|
||||
WrapInFunction(Const(Source{{3, 3}}, "v", ty.i32(), Expr(2u)));
|
||||
WrapInFunction(Let(Source{{3, 3}}, "v", ty.i32(), Expr(2u)));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(
|
||||
|
@ -113,7 +113,7 @@ TEST_F(ResolverVarLetValidationTest, VarConstructorWrongType) {
|
|||
|
||||
TEST_F(ResolverVarLetValidationTest, LetConstructorWrongTypeViaAlias) {
|
||||
auto* a = Alias("I32", ty.i32());
|
||||
WrapInFunction(Const(Source{{3, 3}}, "v", ty.Of(a), Expr(2u)));
|
||||
WrapInFunction(Let(Source{{3, 3}}, "v", ty.Of(a), Expr(2u)));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(
|
||||
|
@ -138,7 +138,7 @@ TEST_F(ResolverVarLetValidationTest, LetOfPtrConstructedWithRef) {
|
|||
const auto priv = ast::StorageClass::kFunction;
|
||||
auto* var_a = Var("a", ty.f32(), priv);
|
||||
auto* var_b =
|
||||
Const(Source{{12, 34}}, "b", ty.pointer<float>(priv), Expr("a"), {});
|
||||
Let(Source{{12, 34}}, "b", ty.pointer<float>(priv), Expr("a"), {});
|
||||
WrapInFunction(var_a, var_b);
|
||||
|
||||
ASSERT_FALSE(r()->Resolve());
|
||||
|
@ -151,8 +151,8 @@ TEST_F(ResolverVarLetValidationTest, LetOfPtrConstructedWithRef) {
|
|||
TEST_F(ResolverVarLetValidationTest, LocalLetRedeclared) {
|
||||
// let l : f32 = 1.;
|
||||
// let l : i32 = 0;
|
||||
auto* l1 = Const("l", ty.f32(), Expr(1.f));
|
||||
auto* l2 = Const(Source{{12, 34}}, "l", ty.i32(), Expr(0));
|
||||
auto* l1 = Let("l", ty.f32(), Expr(1.f));
|
||||
auto* l2 = Let(Source{{12, 34}}, "l", ty.i32(), Expr(0));
|
||||
WrapInFunction(l1, l2);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -235,8 +235,8 @@ TEST_F(ResolverVarLetValidationTest, InferredPtrStorageAccessMismatch) {
|
|||
|
||||
auto* expr =
|
||||
IndexAccessor(MemberAccessor(MemberAccessor(storage, "inner"), "arr"), 4);
|
||||
auto* ptr = Const(
|
||||
Source{{12, 34}}, "p",
|
||||
auto* ptr =
|
||||
Let(Source{{12, 34}}, "p",
|
||||
ty.pointer<i32>(ast::StorageClass::kStorage, ast::Access::kReadWrite),
|
||||
AddressOf(expr));
|
||||
|
||||
|
@ -309,8 +309,8 @@ TEST_F(ResolverVarLetValidationTest, InvalidStorageClassForInitializer) {
|
|||
|
||||
TEST_F(ResolverVarLetValidationTest, VectorLetNoType) {
|
||||
// let a : mat3x3 = mat3x3<f32>();
|
||||
WrapInFunction(Const("a", create<ast::Vector>(Source{{12, 34}}, nullptr, 3),
|
||||
vec3<f32>()));
|
||||
WrapInFunction(
|
||||
Let("a", create<ast::Vector>(Source{{12, 34}}, nullptr, 3), vec3<f32>()));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), "12:34 error: missing vector element type");
|
||||
|
@ -326,8 +326,7 @@ TEST_F(ResolverVarLetValidationTest, VectorVarNoType) {
|
|||
|
||||
TEST_F(ResolverVarLetValidationTest, MatrixLetNoType) {
|
||||
// let a : mat3x3 = mat3x3<f32>();
|
||||
WrapInFunction(Const("a",
|
||||
create<ast::Matrix>(Source{{12, 34}}, nullptr, 3, 3),
|
||||
WrapInFunction(Let("a", create<ast::Matrix>(Source{{12, 34}}, nullptr, 3, 3),
|
||||
mat3x3<f32>()));
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -59,41 +59,40 @@ struct BuiltinPolyfill::State {
|
|||
auto V = [&](uint32_t value) -> const ast::Expression* {
|
||||
return ScalarOrVector(width, value);
|
||||
};
|
||||
b.Func(
|
||||
name, {b.Param("v", T(ty))}, T(ty),
|
||||
b.Func(name, {b.Param("v", T(ty))}, T(ty),
|
||||
{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(0, 16, x <= 0x0000ffff);
|
||||
b.Decl(b.Const("b16", nullptr,
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(0), V(16),
|
||||
b.LessThanEqual("x", V(0x0000ffff))))),
|
||||
// x = x << b16;
|
||||
b.Assign("x", b.Shl("x", "b16")),
|
||||
// let b8 = select(0, 8, x <= 0x00ffffff);
|
||||
b.Decl(b.Const("b8", nullptr,
|
||||
b.Decl(b.Let("b8", nullptr,
|
||||
b.Call("select", V(0), V(8),
|
||||
b.LessThanEqual("x", V(0x00ffffff))))),
|
||||
// x = x << b8;
|
||||
b.Assign("x", b.Shl("x", "b8")),
|
||||
// let b4 = select(0, 4, x <= 0x0fffffff);
|
||||
b.Decl(b.Const("b4", nullptr,
|
||||
b.Decl(b.Let("b4", nullptr,
|
||||
b.Call("select", V(0), V(4),
|
||||
b.LessThanEqual("x", V(0x0fffffff))))),
|
||||
// x = x << b4;
|
||||
b.Assign("x", b.Shl("x", "b4")),
|
||||
// let b2 = select(0, 2, x <= 0x3fffffff);
|
||||
b.Decl(b.Const("b2", nullptr,
|
||||
b.Decl(b.Let("b2", nullptr,
|
||||
b.Call("select", V(0), V(2),
|
||||
b.LessThanEqual("x", V(0x3fffffff))))),
|
||||
// x = x << b2;
|
||||
b.Assign("x", b.Shl("x", "b2")),
|
||||
// let b1 = select(0, 1, x <= 0x7fffffff);
|
||||
b.Decl(b.Const("b1", nullptr,
|
||||
b.Decl(b.Let("b1", nullptr,
|
||||
b.Call("select", V(0), V(1),
|
||||
b.LessThanEqual("x", V(0x7fffffff))))),
|
||||
// let is_zero = select(0, 1, x == 0);
|
||||
b.Decl(b.Const("is_zero", nullptr,
|
||||
b.Decl(b.Let("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
// return R((b16 | b8 | b4 | b2 | b1) + zero);
|
||||
b.Return(b.Construct(
|
||||
|
@ -127,41 +126,40 @@ struct BuiltinPolyfill::State {
|
|||
}
|
||||
return b.Construct(b.ty.vec<bool>(width), value);
|
||||
};
|
||||
b.Func(
|
||||
name, {b.Param("v", T(ty))}, T(ty),
|
||||
b.Func(name, {b.Param("v", T(ty))}, T(ty),
|
||||
{
|
||||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(16, 0, bool(x & 0x0000ffff));
|
||||
b.Decl(b.Const(
|
||||
"b16", nullptr,
|
||||
b.Call("select", V(16), V(0), B(b.And("x", V(0x0000ffff)))))),
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(16), V(0),
|
||||
B(b.And("x", V(0x0000ffff)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(8, 0, bool(x & 0x000000ff));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b8", nullptr,
|
||||
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(4, 0, bool(x & 0x0000000f));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b4", nullptr,
|
||||
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(2, 0, bool(x & 0x00000003));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b2", nullptr,
|
||||
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(1, 0, bool(x & 0x00000001));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b1", nullptr,
|
||||
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
// let is_zero = select(0, 1, x == 0);
|
||||
b.Decl(b.Const("is_zero", nullptr,
|
||||
b.Decl(b.Let("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(1), b.Equal("x", V(0))))),
|
||||
// return R((b16 | b8 | b4 | b2 | b1) + zero);
|
||||
b.Return(b.Construct(
|
||||
|
@ -190,14 +188,14 @@ struct BuiltinPolyfill::State {
|
|||
};
|
||||
|
||||
ast::StatementList body = {
|
||||
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))),
|
||||
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
|
||||
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
|
||||
b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
|
||||
};
|
||||
|
||||
switch (polyfill.extract_bits) {
|
||||
case Level::kFull:
|
||||
body.emplace_back(b.Decl(b.Const("shl", nullptr, b.Sub(W, "e"))));
|
||||
body.emplace_back(b.Decl(b.Const("shr", nullptr, b.Add("shl", "s"))));
|
||||
body.emplace_back(b.Decl(b.Let("shl", nullptr, b.Sub(W, "e"))));
|
||||
body.emplace_back(b.Decl(b.Let("shr", nullptr, b.Add("shl", "s"))));
|
||||
body.emplace_back(b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))),
|
||||
vecN_u32(b.Expr("shr")))));
|
||||
break;
|
||||
|
@ -264,37 +262,37 @@ struct BuiltinPolyfill::State {
|
|||
// var x = select(U(v), ~U(v), v < 0); (signed)
|
||||
b.Decl(b.Var("x", nullptr, x)),
|
||||
// let b16 = select(0, 16, bool(x & 0xffff0000));
|
||||
b.Decl(b.Const("b16", nullptr,
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(0), V(16),
|
||||
B(b.And("x", V(0xffff0000)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(0, 8, bool(x & 0x0000ff00));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b8", nullptr,
|
||||
b.Call("select", V(0), V(8), B(b.And("x", V(0x0000ff00)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(0, 4, bool(x & 0x000000f0));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b4", nullptr,
|
||||
b.Call("select", V(0), V(4), B(b.And("x", V(0x000000f0)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(0, 2, bool(x & 0x0000000c));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b2", nullptr,
|
||||
b.Call("select", V(0), V(2), B(b.And("x", V(0x0000000c)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(0, 1, bool(x & 0x00000002));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b1", nullptr,
|
||||
b.Call("select", V(0), V(1), B(b.And("x", V(0x00000002)))))),
|
||||
// let is_zero = select(0, 0xffffffff, x == 0);
|
||||
b.Decl(b.Const("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff),
|
||||
b.Equal("x", V(0))))),
|
||||
b.Decl(b.Let(
|
||||
"is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
// return R(b16 | b8 | b4 | b2 | b1 | zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty),
|
||||
|
@ -332,37 +330,37 @@ struct BuiltinPolyfill::State {
|
|||
// var x = U(v);
|
||||
b.Decl(b.Var("x", nullptr, b.Construct(U(), b.Expr("v")))),
|
||||
// let b16 = select(16, 0, bool(x & 0x0000ffff));
|
||||
b.Decl(b.Const("b16", nullptr,
|
||||
b.Decl(b.Let("b16", nullptr,
|
||||
b.Call("select", V(16), V(0),
|
||||
B(b.And("x", V(0x0000ffff)))))),
|
||||
// x = x >> b16;
|
||||
b.Assign("x", b.Shr("x", "b16")),
|
||||
// let b8 = select(8, 0, bool(x & 0x000000ff));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b8", nullptr,
|
||||
b.Call("select", V(8), V(0), B(b.And("x", V(0x000000ff)))))),
|
||||
// x = x >> b8;
|
||||
b.Assign("x", b.Shr("x", "b8")),
|
||||
// let b4 = select(4, 0, bool(x & 0x0000000f));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b4", nullptr,
|
||||
b.Call("select", V(4), V(0), B(b.And("x", V(0x0000000f)))))),
|
||||
// x = x >> b4;
|
||||
b.Assign("x", b.Shr("x", "b4")),
|
||||
// let b2 = select(2, 0, bool(x & 0x00000003));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b2", nullptr,
|
||||
b.Call("select", V(2), V(0), B(b.And("x", V(0x00000003)))))),
|
||||
// x = x >> b2;
|
||||
b.Assign("x", b.Shr("x", "b2")),
|
||||
// let b1 = select(1, 0, bool(x & 0x00000001));
|
||||
b.Decl(b.Const(
|
||||
b.Decl(b.Let(
|
||||
"b1", nullptr,
|
||||
b.Call("select", V(1), V(0), B(b.And("x", V(0x00000001)))))),
|
||||
// let is_zero = select(0, 0xffffffff, x == 0);
|
||||
b.Decl(b.Const("is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff),
|
||||
b.Equal("x", V(0))))),
|
||||
b.Decl(b.Let(
|
||||
"is_zero", nullptr,
|
||||
b.Call("select", V(0), V(0xffffffff), b.Equal("x", V(0))))),
|
||||
// return R(b16 | b8 | b4 | b2 | b1 | is_zero);
|
||||
b.Return(b.Construct(
|
||||
T(ty),
|
||||
|
@ -399,14 +397,14 @@ struct BuiltinPolyfill::State {
|
|||
};
|
||||
|
||||
ast::StatementList body = {
|
||||
b.Decl(b.Const("s", nullptr, b.Call("min", "offset", W))),
|
||||
b.Decl(b.Const("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
|
||||
b.Decl(b.Let("s", nullptr, b.Call("min", "offset", W))),
|
||||
b.Decl(b.Let("e", nullptr, b.Call("min", W, b.Add("s", "count")))),
|
||||
};
|
||||
|
||||
switch (polyfill.insert_bits) {
|
||||
case Level::kFull:
|
||||
// let mask = ((1 << s) - 1) ^ ((1 << e) - 1)
|
||||
body.emplace_back(b.Decl(b.Const(
|
||||
body.emplace_back(b.Decl(b.Let(
|
||||
"mask", nullptr,
|
||||
b.Xor(b.Sub(b.Shl(1u, "s"), 1u), b.Sub(b.Shl(1u, "e"), 1u)))));
|
||||
// return ((n << s) & mask) | (v & ~mask)
|
||||
|
|
|
@ -215,7 +215,7 @@ void CalculateArrayLength::Run(CloneContext& ctx,
|
|||
}
|
||||
uint32_t array_stride = array_type->Size();
|
||||
auto* array_length_var = ctx.dst->Decl(
|
||||
ctx.dst->Const(name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Let(name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Div(total_size, array_stride)));
|
||||
|
||||
// Insert the array length calculations at the top of the block
|
||||
|
|
|
@ -562,8 +562,8 @@ struct CanonicalizeEntryPointIO::State {
|
|||
wrapper_body.push_back(ctx.dst->CallStmt(call_inner));
|
||||
} else {
|
||||
// Capture the result of calling the original function.
|
||||
auto* inner_result = ctx.dst->Const(
|
||||
ctx.dst->Symbols().New("inner_result"), nullptr, call_inner);
|
||||
auto* inner_result = ctx.dst->Let(ctx.dst->Symbols().New("inner_result"),
|
||||
nullptr, call_inner);
|
||||
wrapper_body.push_back(ctx.dst->Decl(inner_result));
|
||||
|
||||
// Process the original return type to determine the outputs that the
|
||||
|
|
|
@ -80,8 +80,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateDefaultStridedArray) {
|
|||
b.Global("arr", b.ty.array<f32, 4>(4), ast::StorageClass::kPrivate);
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array<f32, 4>(4), b.Expr("arr"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.Expr("arr"))),
|
||||
b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -117,8 +117,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateStridedArray) {
|
|||
b.Global("arr", b.ty.array<f32, 4>(32), ast::StorageClass::kPrivate);
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array<f32, 4>(32), b.Expr("arr"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4>(32), b.Expr("arr"))),
|
||||
b.Decl(b.Let("b", b.ty.f32(), b.IndexAccessor("arr", 1))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -163,9 +163,9 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformStridedArray) {
|
|||
b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array<f32, 4>(32),
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
|
||||
b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(),
|
||||
b.Decl(b.Let("b", b.ty.f32(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
|
||||
},
|
||||
{
|
||||
|
@ -214,14 +214,14 @@ TEST_F(DecomposeStridedArrayTest, ReadUniformDefaultStridedArray) {
|
|||
b.Structure("S", {b.Member("a", b.ty.array(b.ty.vec4<f32>(), 4, 16))});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array(b.ty.vec4<f32>(), 4, 16),
|
||||
b.Decl(b.Let("a", b.ty.array(b.ty.vec4<f32>(), 4, 16),
|
||||
b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const(
|
||||
"b", b.ty.f32(),
|
||||
b.IndexAccessor(b.IndexAccessor(b.MemberAccessor("s", "a"), 1),
|
||||
2))),
|
||||
b.Decl(b.Let("b", b.ty.f32(),
|
||||
b.IndexAccessor(
|
||||
b.IndexAccessor(b.MemberAccessor("s", "a"), 1), 2))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -266,9 +266,9 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageStridedArray) {
|
|||
b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array<f32, 4>(32),
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4>(32),
|
||||
b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(),
|
||||
b.Decl(b.Let("b", b.ty.f32(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
|
||||
},
|
||||
{
|
||||
|
@ -316,11 +316,11 @@ TEST_F(DecomposeStridedArrayTest, ReadStorageDefaultStridedArray) {
|
|||
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(4))});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.array<f32, 4>(4),
|
||||
b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(),
|
||||
b.Decl(b.Let("a", b.ty.array<f32, 4>(4), b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Let("b", b.ty.f32(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
|
||||
},
|
||||
{
|
||||
|
@ -476,16 +476,16 @@ TEST_F(DecomposeStridedArrayTest, ReadWriteViaPointerLets) {
|
|||
auto* S = b.Structure("S", {b.Member("a", b.ty.array<f32, 4>(32))});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
|
||||
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", nullptr,
|
||||
b.AddressOf(b.MemberAccessor("s", "a")))),
|
||||
b.Decl(b.Const("b", nullptr,
|
||||
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "a")))),
|
||||
b.Decl(b.Let("b", nullptr,
|
||||
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Const("c", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Const("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
|
||||
b.Assign(b.Deref("b"), b.Construct(b.ty.array<f32, 4>(32), 1.0f,
|
||||
2.0f, 3.0f, 4.0f)),
|
||||
b.Decl(b.Let("c", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Let("d", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
|
||||
b.Assign(b.Deref("b"),
|
||||
b.Construct(b.ty.array<f32, 4>(32), 1.0f, 2.0f, 3.0f, 4.0f)),
|
||||
b.Assign(b.IndexAccessor(b.Deref("b"), 1), 5.0f),
|
||||
},
|
||||
{
|
||||
|
@ -544,9 +544,8 @@ TEST_F(DecomposeStridedArrayTest, PrivateAliasedStridedArray) {
|
|||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(
|
||||
b.Const("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const("b", b.ty.f32(),
|
||||
b.Decl(b.Let("a", b.ty.type_name("ARR"), b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Let("b", b.ty.f32(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "a"), 1))),
|
||||
b.Assign(b.MemberAccessor("s", "a"),
|
||||
b.Construct(b.ty.type_name("ARR"))),
|
||||
|
@ -618,19 +617,19 @@ TEST_F(DecomposeStridedArrayTest, PrivateNestedStridedArray) {
|
|||
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("a", b.ty.type_name("ARR_B"),
|
||||
b.Decl(b.Let("a", b.ty.type_name("ARR_B"),
|
||||
b.MemberAccessor("s", "a"))),
|
||||
b.Decl(b.Const("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16),
|
||||
b.Decl(b.Let("b", b.ty.array(b.ty.type_name("ARR_A"), 3, 16),
|
||||
b.IndexAccessor( //
|
||||
b.MemberAccessor("s", "a"), //
|
||||
3))),
|
||||
b.Decl(b.Const("c", b.ty.type_name("ARR_A"),
|
||||
b.Decl(b.Let("c", b.ty.type_name("ARR_A"),
|
||||
b.IndexAccessor( //
|
||||
b.IndexAccessor( //
|
||||
b.MemberAccessor("s", "a"), //
|
||||
3),
|
||||
2))),
|
||||
b.Decl(b.Const("d", b.ty.f32(),
|
||||
b.Decl(b.Let("d", b.ty.f32(),
|
||||
b.IndexAccessor( //
|
||||
b.IndexAccessor( //
|
||||
b.IndexAccessor( //
|
||||
|
|
|
@ -79,10 +79,9 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
|
|||
});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -142,7 +141,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
|
|||
b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.vec2<f32>(),
|
||||
b.Decl(b.Let("x", b.ty.vec2<f32>(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
|
||||
},
|
||||
{
|
||||
|
@ -197,10 +196,9 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
|
|||
});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kUniform,
|
||||
b.GroupAndBinding(0, 0));
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -255,10 +253,9 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
|
|||
});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kStorage,
|
||||
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -318,7 +315,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
|
|||
ast::Access::kReadWrite, b.GroupAndBinding(0, 0));
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.vec2<f32>(),
|
||||
b.Decl(b.Let("x", b.ty.vec2<f32>(),
|
||||
b.IndexAccessor(b.MemberAccessor("s", "m"), 1))),
|
||||
},
|
||||
{
|
||||
|
@ -501,13 +498,12 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
|
|||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(
|
||||
b.Const("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
|
||||
b.Decl(b.Const("b", nullptr,
|
||||
b.Decl(b.Let("a", nullptr, b.AddressOf(b.MemberAccessor("s", "m")))),
|
||||
b.Decl(b.Let("b", nullptr,
|
||||
b.AddressOf(b.Deref(b.AddressOf(b.Deref("a")))))),
|
||||
b.Decl(b.Const("x", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Const("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
|
||||
b.Decl(b.Const("z", nullptr, b.IndexAccessor("x", 1))),
|
||||
b.Decl(b.Let("x", nullptr, b.Deref("b"))),
|
||||
b.Decl(b.Let("y", nullptr, b.IndexAccessor(b.Deref("b"), 1))),
|
||||
b.Decl(b.Let("z", nullptr, b.IndexAccessor("x", 1))),
|
||||
b.Assign(b.Deref("b"), b.mat2x2<f32>(b.vec2<f32>(1.0f, 2.0f),
|
||||
b.vec2<f32>(3.0f, 4.0f))),
|
||||
b.Assign(b.IndexAccessor(b.Deref("b"), 1), b.vec2<f32>(5.0f, 6.0f)),
|
||||
|
@ -575,10 +571,9 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
|
|||
}),
|
||||
});
|
||||
b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate);
|
||||
b.Func(
|
||||
"f", {}, b.ty.void_(),
|
||||
b.Func("f", {}, b.ty.void_(),
|
||||
{
|
||||
b.Decl(b.Const("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
b.Decl(b.Let("x", b.ty.mat2x2<f32>(), b.MemberAccessor("s", "m"))),
|
||||
},
|
||||
{
|
||||
b.Stage(ast::PipelineStage::kCompute),
|
||||
|
|
|
@ -83,7 +83,7 @@ class State {
|
|||
auto hoist_pointer_to = [&](const ast::Expression* expr) {
|
||||
auto name = b.Sym();
|
||||
auto* ptr = b.AddressOf(ctx.Clone(expr));
|
||||
auto* decl = b.Decl(b.Const(name, nullptr, ptr));
|
||||
auto* decl = b.Decl(b.Let(name, nullptr, ptr));
|
||||
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
|
||||
return name;
|
||||
};
|
||||
|
@ -91,7 +91,7 @@ class State {
|
|||
// Helper function to hoist `expr` to a let declaration.
|
||||
auto hoist_expr_to_let = [&](const ast::Expression* expr) {
|
||||
auto name = b.Sym();
|
||||
auto* decl = b.Decl(b.Const(name, nullptr, ctx.Clone(expr)));
|
||||
auto* decl = b.Decl(b.Let(name, nullptr, ctx.Clone(expr)));
|
||||
hoist_to_decl_before.InsertBefore(ctx.src->Sem().Get(stmt), decl);
|
||||
return name;
|
||||
};
|
||||
|
|
|
@ -162,7 +162,7 @@ class LocalizeStructArrayAssignment::State {
|
|||
// the value twice e.g. let tint_symbol = &(s.a1);
|
||||
auto mem_access_ptr = b.Sym();
|
||||
s.insert_before_stmts.push_back(
|
||||
b.Decl(b.Const(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
|
||||
b.Decl(b.Let(mem_access_ptr, nullptr, b.AddressOf(mem_access))));
|
||||
|
||||
// Disable further transforms when cloning
|
||||
TINT_SCOPED_ASSIGNMENT(s.process_nested_nodes, false);
|
||||
|
|
|
@ -241,9 +241,9 @@ struct ModuleScopeVarToEntryPointParam::State {
|
|||
auto* member_ptr = ctx.dst->AddressOf(ctx.dst->MemberAccessor(
|
||||
ctx.dst->Deref(workgroup_param()), member));
|
||||
auto* local_var =
|
||||
ctx.dst->Const(new_var_symbol,
|
||||
ctx.dst->ty.pointer(
|
||||
store_type(), ast::StorageClass::kWorkgroup),
|
||||
ctx.dst->Let(new_var_symbol,
|
||||
ctx.dst->ty.pointer(store_type(),
|
||||
ast::StorageClass::kWorkgroup),
|
||||
member_ptr);
|
||||
ctx.InsertFront(func_ast->body->statements,
|
||||
ctx.dst->Decl(local_var));
|
||||
|
|
|
@ -441,7 +441,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
|
|||
[&](const ast::Expression* e) -> const ast::Expression* {
|
||||
if (to_hoist.count(e)) {
|
||||
auto name = b.Symbols().New();
|
||||
auto* v = b.Const(name, nullptr, ctx.Clone(e));
|
||||
auto* v = b.Let(name, nullptr, ctx.Clone(e));
|
||||
auto* decl = b.Decl(v);
|
||||
curr_stmts->push_back(decl);
|
||||
return b.Expr(name);
|
||||
|
|
|
@ -184,7 +184,7 @@ struct SimplifyPointers::State {
|
|||
ctx.src->Symbols().NameFor(var->Declaration()->symbol) +
|
||||
"_save");
|
||||
auto* decl = ctx.dst->Decl(
|
||||
ctx.dst->Const(saved_name, nullptr, ctx.Clone(idx_expr)));
|
||||
ctx.dst->Let(saved_name, nullptr, ctx.Clone(idx_expr)));
|
||||
saved.emplace_back(decl);
|
||||
// Record the substitution of `idx_expr` to the saved variable
|
||||
// with the symbol `saved_name`. This will be used by the
|
||||
|
|
|
@ -211,7 +211,7 @@ class HoistToDeclBefore::State {
|
|||
auto name = b.Symbols().New(decl_name);
|
||||
|
||||
// Construct the let/var that holds the hoisted expr
|
||||
auto* v = as_const ? b.Const(name, nullptr, ctx.Clone(expr))
|
||||
auto* v = as_const ? b.Let(name, nullptr, ctx.Clone(expr))
|
||||
: b.Var(name, nullptr, ctx.Clone(expr));
|
||||
auto* decl = b.Decl(v);
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ struct State {
|
|||
|
||||
// let pulling_offset_n = <attribute_offset>
|
||||
stmts.emplace_back(ctx.dst->Decl(
|
||||
ctx.dst->Const(buffer_array_base, nullptr, attribute_offset)));
|
||||
ctx.dst->Let(buffer_array_base, nullptr, attribute_offset)));
|
||||
|
||||
for (const VertexAttributeDescriptor& attribute_desc :
|
||||
buffer_layout.attributes) {
|
||||
|
|
|
@ -351,7 +351,7 @@ struct ZeroInitWorkgroupMemory::State {
|
|||
ast::BinaryOp::kModulo, iteration(), b.Expr(index.modulo))
|
||||
: iteration();
|
||||
auto* div = (index.division != 1u) ? b.Div(mod, index.division) : mod;
|
||||
auto* decl = b.Decl(b.Const(name, b.ty.u32(), div));
|
||||
auto* decl = b.Decl(b.Let(name, b.ty.u32(), div));
|
||||
stmts.emplace_back(decl);
|
||||
}
|
||||
return stmts;
|
||||
|
|
|
@ -206,9 +206,9 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(),
|
||||
{
|
||||
Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))),
|
||||
Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))),
|
||||
Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
|
||||
Decl(Let("r", ty.f32(), MemberAccessor("inputs", "col1"))),
|
||||
Decl(Let("g", ty.f32(), MemberAccessor("inputs", "col2"))),
|
||||
Decl(Let("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace {
|
|||
using GlslGeneratorImplTest_ModuleConstant = TestHelper;
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
|
||||
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
|
||||
auto* var = Let("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
|
||||
WrapInFunction(Decl(var));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -115,8 +115,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) {
|
|||
create<ast::GroupAttribute>(2),
|
||||
});
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
auto* p = Let("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
|
||||
Func("a_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
|
@ -239,7 +239,7 @@ TEST_F(GlslSanitizerTest, InlinePtrLetsBasic) {
|
|||
// let x : i32 = *p;
|
||||
auto* v = Var("v", ty.i32());
|
||||
auto* p =
|
||||
Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
|
||||
Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
|
||||
auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p));
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
|
@ -280,15 +280,14 @@ TEST_F(GlslSanitizerTest, InlinePtrLetsComplexChain) {
|
|||
// let vp : ptr<function, vec4<f32>> = &(*mp)[2];
|
||||
// let v : vec4<f32> = *vp;
|
||||
auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4));
|
||||
auto* ap = Const(
|
||||
auto* ap = Let(
|
||||
"ap",
|
||||
ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction),
|
||||
AddressOf(a));
|
||||
auto* mp =
|
||||
Const("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
|
||||
Let("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
|
||||
AddressOf(IndexAccessor(Deref(ap), 3)));
|
||||
auto* vp =
|
||||
Const("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
|
||||
auto* vp = Let("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
|
||||
AddressOf(IndexAccessor(Deref(mp), 2)));
|
||||
auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp));
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ TEST_F(GlslUnaryOpTest, Complement) {
|
|||
|
||||
TEST_F(GlslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
auto* p =
|
||||
Let("expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
|||
}
|
||||
|
||||
TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* var = Let("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Vector_Assign_ConstantIndex) {
|
|||
{
|
||||
Decl(Var("lhs", ty.vec3<f32>())),
|
||||
Decl(Var("rhs", ty.f32())),
|
||||
Decl(Const("index", ty.u32(), Expr(0u))),
|
||||
Decl(Let("index", ty.u32(), Expr(0u))),
|
||||
Assign(IndexAccessor("lhs", "index"), "rhs"),
|
||||
});
|
||||
|
||||
|
@ -92,7 +92,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Matrix_Assign_Vector_ConstantIndex) {
|
|||
{
|
||||
Decl(Var("lhs", ty.mat4x2<f32>())),
|
||||
Decl(Var("rhs", ty.vec2<f32>())),
|
||||
Decl(Const("index", ty.u32(), Expr(0u))),
|
||||
Decl(Let("index", ty.u32(), Expr(0u))),
|
||||
Assign(IndexAccessor("lhs", "index"), "rhs"),
|
||||
});
|
||||
|
||||
|
@ -146,7 +146,7 @@ TEST_F(HlslGeneratorImplTest_Assign, Emit_Matrix_Assign_Scalar_ConstantIndex) {
|
|||
{
|
||||
Decl(Var("lhs", ty.mat4x2<f32>())),
|
||||
Decl(Var("rhs", ty.f32())),
|
||||
Decl(Const("index", ty.u32(), Expr(0u))),
|
||||
Decl(Let("index", ty.u32(), Expr(0u))),
|
||||
Assign(IndexAccessor(IndexAccessor("lhs", "index"), "index"), "rhs"),
|
||||
});
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.i32())),
|
||||
Decl(Const("r", nullptr, Op("a", 0))),
|
||||
Decl(Let("r", nullptr, Op("a", 0))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -573,7 +573,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_u32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.u32())),
|
||||
Decl(Const("r", nullptr, Op("a", 0u))),
|
||||
Decl(Let("r", nullptr, Op("a", 0u))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -591,7 +591,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_vec_by_vec_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))),
|
||||
Decl(Const("r", nullptr, Op("a", vec4<i32>(50, 0, 25, 0)))),
|
||||
Decl(Let("r", nullptr, Op("a", vec4<i32>(50, 0, 25, 0)))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -609,7 +609,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByLiteralZero_vec_by_scalar_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", nullptr, vec4<i32>(100, 100, 100, 100))),
|
||||
Decl(Const("r", nullptr, Op("a", 0))),
|
||||
Decl(Let("r", nullptr, Op("a", 0))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -627,7 +627,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_i32) {
|
|||
Func("fn", {Param("b", ty.i32())}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.i32())),
|
||||
Decl(Const("r", nullptr, Op("a", "b"))),
|
||||
Decl(Let("r", nullptr, Op("a", "b"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -645,7 +645,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_u32) {
|
|||
Func("fn", {Param("b", ty.u32())}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.u32())),
|
||||
Decl(Const("r", nullptr, Op("a", "b"))),
|
||||
Decl(Let("r", nullptr, Op("a", "b"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -663,7 +663,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_vec_by_vec_i32) {
|
|||
Func("fn", {Param("b", ty.vec3<i32>())}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.vec3<i32>())),
|
||||
Decl(Const("r", nullptr, Op("a", "b"))),
|
||||
Decl(Let("r", nullptr, Op("a", "b"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -681,7 +681,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByIdentifier_vec_by_scalar_i32) {
|
|||
Func("fn", {Param("b", ty.i32())}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.vec3<i32>())),
|
||||
Decl(Const("r", nullptr, Op("a", "b"))),
|
||||
Decl(Let("r", nullptr, Op("a", "b"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -704,7 +704,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.i32())),
|
||||
Decl(Const("r", nullptr, Op("a", Call("zero")))),
|
||||
Decl(Let("r", nullptr, Op("a", Call("zero")))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -735,7 +735,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_u32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.u32())),
|
||||
Decl(Const("r", nullptr, Op("a", Call("zero")))),
|
||||
Decl(Let("r", nullptr, Op("a", Call("zero")))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -766,7 +766,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_vec_by_vec_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.vec3<i32>())),
|
||||
Decl(Const("r", nullptr, Op("a", Call("zero")))),
|
||||
Decl(Let("r", nullptr, Op("a", Call("zero")))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -797,7 +797,7 @@ TEST_P(HlslGeneratorDivModTest, DivOrModByExpression_vec_by_scalar_i32) {
|
|||
Func("fn", {}, ty.void_(),
|
||||
{
|
||||
Decl(Var("a", ty.vec3<i32>())),
|
||||
Decl(Const("r", nullptr, Op("a", Call("zero")))),
|
||||
Decl(Let("r", nullptr, Op("a", Call("zero")))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -205,9 +205,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", {Param("inputs", ty.Of(interface_struct))}, ty.void_(),
|
||||
{
|
||||
Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))),
|
||||
Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))),
|
||||
Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
|
||||
Decl(Let("r", ty.f32(), MemberAccessor("inputs", "col1"))),
|
||||
Decl(Let("g", ty.f32(), MemberAccessor("inputs", "col2"))),
|
||||
Decl(Let("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace {
|
|||
using HlslGeneratorImplTest_ModuleConstant = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
|
||||
auto* var = Const("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
|
||||
auto* var = Let("pos", ty.array<f32, 3>(), array<f32, 3>(1.f, 2.f, 3.f));
|
||||
WrapInFunction(Decl(var));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -104,8 +104,8 @@ TEST_F(HlslSanitizerTest, Call_ArrayLength_ViaLets) {
|
|||
create<ast::GroupAttribute>(2),
|
||||
});
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
auto* p = Let("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
|
||||
Func("a_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
|
@ -259,7 +259,7 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsBasic) {
|
|||
// let x : i32 = *p;
|
||||
auto* v = Var("v", ty.i32());
|
||||
auto* p =
|
||||
Const("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
|
||||
Let("p", ty.pointer<i32>(ast::StorageClass::kFunction), AddressOf(v));
|
||||
auto* x = Var("x", ty.i32(), ast::StorageClass::kNone, Deref(p));
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
|
@ -293,15 +293,14 @@ TEST_F(HlslSanitizerTest, InlinePtrLetsComplexChain) {
|
|||
// let vp : ptr<function, vec4<f32>> = &(*mp)[2];
|
||||
// let v : vec4<f32> = *vp;
|
||||
auto* a = Var("a", ty.array(ty.mat4x4<f32>(), 4));
|
||||
auto* ap = Const(
|
||||
auto* ap = Let(
|
||||
"ap",
|
||||
ty.pointer(ty.array(ty.mat4x4<f32>(), 4), ast::StorageClass::kFunction),
|
||||
AddressOf(a));
|
||||
auto* mp =
|
||||
Const("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
|
||||
Let("mp", ty.pointer(ty.mat4x4<f32>(), ast::StorageClass::kFunction),
|
||||
AddressOf(IndexAccessor(Deref(ap), 3)));
|
||||
auto* vp =
|
||||
Const("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
|
||||
auto* vp = Let("vp", ty.pointer(ty.vec4<f32>(), ast::StorageClass::kFunction),
|
||||
AddressOf(IndexAccessor(Deref(mp), 2)));
|
||||
auto* v = Var("v", ty.vec4<f32>(), ast::StorageClass::kNone, Deref(vp));
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ TEST_F(HlslUnaryOpTest, Complement) {
|
|||
|
||||
TEST_F(HlslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
auto* p =
|
||||
Let("expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* var = Let("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, IndexAccessor) {
|
|||
TEST_F(MslGeneratorImplTest, IndexAccessor_OfDref) {
|
||||
Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("ary"));
|
||||
auto* p = Let("p", nullptr, AddressOf("ary"));
|
||||
auto* expr = IndexAccessor(Deref("p"), 5);
|
||||
WrapInFunction(p, expr);
|
||||
|
||||
|
|
|
@ -185,12 +185,11 @@ TEST_F(MslGeneratorImplTest,
|
|||
Construct(ty.vec4<f32>())))},
|
||||
{Stage(ast::PipelineStage::kVertex)});
|
||||
|
||||
Func("frag_main", {Param("colors", ty.Of(interface_struct))}, ty.void_(),
|
||||
Func(
|
||||
"frag_main", {Param("colors", ty.Of(interface_struct))}, ty.void_(),
|
||||
{
|
||||
WrapInStatement(
|
||||
Const("r", ty.f32(), MemberAccessor("colors", "col1"))),
|
||||
WrapInStatement(
|
||||
Const("g", ty.f32(), MemberAccessor("colors", "col2"))),
|
||||
WrapInStatement(Let("r", ty.f32(), MemberAccessor("colors", "col1"))),
|
||||
WrapInStatement(Let("g", ty.f32(), MemberAccessor("colors", "col2"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@ TEST_F(MslSanitizerTest, Call_ArrayLength_ViaLets) {
|
|||
create<ast::GroupAttribute>(2),
|
||||
});
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
auto* p = Let("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
|
||||
Func("a_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
|
|
|
@ -138,7 +138,7 @@ vertex Out vert_main() {
|
|||
TEST_F(MslGeneratorImplTest, WorkgroupMatrix) {
|
||||
Global("m", ty.mat2x2<f32>(), ast::StorageClass::kWorkgroup);
|
||||
Func("comp_main", ast::VariableList{}, ty.void_(),
|
||||
{Decl(Const("x", nullptr, Expr("m")))},
|
||||
{Decl(Let("x", nullptr, Expr("m")))},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -176,7 +176,7 @@ kernel void comp_main(threadgroup tint_symbol_3* tint_symbol_2 [[threadgroup(0)]
|
|||
TEST_F(MslGeneratorImplTest, WorkgroupMatrixInArray) {
|
||||
Global("m", ty.array(ty.mat2x2<f32>(), 4), ast::StorageClass::kWorkgroup);
|
||||
Func("comp_main", ast::VariableList{}, ty.void_(),
|
||||
{Decl(Const("x", nullptr, Expr("m")))},
|
||||
{Decl(Let("x", nullptr, Expr("m")))},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -226,7 +226,7 @@ TEST_F(MslGeneratorImplTest, WorkgroupMatrixInStruct) {
|
|||
});
|
||||
Global("s", ty.type_name("S2"), ast::StorageClass::kWorkgroup);
|
||||
Func("comp_main", ast::VariableList{}, ty.void_(),
|
||||
{Decl(Const("x", nullptr, Expr("s")))},
|
||||
{Decl(Let("x", nullptr, Expr("s")))},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -284,23 +284,23 @@ TEST_F(MslGeneratorImplTest, WorkgroupMatrix_Multiples) {
|
|||
Global("m9", ty.mat4x4<f32>(), ast::StorageClass::kWorkgroup);
|
||||
Func("main1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
Decl(Const("a1", nullptr, Expr("m1"))),
|
||||
Decl(Const("a2", nullptr, Expr("m2"))),
|
||||
Decl(Const("a3", nullptr, Expr("m3"))),
|
||||
Decl(Let("a1", nullptr, Expr("m1"))),
|
||||
Decl(Let("a2", nullptr, Expr("m2"))),
|
||||
Decl(Let("a3", nullptr, Expr("m3"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
Func("main2", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
Decl(Const("a1", nullptr, Expr("m4"))),
|
||||
Decl(Const("a2", nullptr, Expr("m5"))),
|
||||
Decl(Const("a3", nullptr, Expr("m6"))),
|
||||
Decl(Let("a1", nullptr, Expr("m4"))),
|
||||
Decl(Let("a2", nullptr, Expr("m5"))),
|
||||
Decl(Let("a3", nullptr, Expr("m6"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
Func("main3", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
Decl(Const("a1", nullptr, Expr("m7"))),
|
||||
Decl(Const("a2", nullptr, Expr("m8"))),
|
||||
Decl(Const("a3", nullptr, Expr("m9"))),
|
||||
Decl(Let("a1", nullptr, Expr("m7"))),
|
||||
Decl(Let("a2", nullptr, Expr("m8"))),
|
||||
Decl(Let("a3", nullptr, Expr("m9"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1)});
|
||||
Func("main4_no_usages", ast::VariableList{}, ty.void_(), {},
|
||||
|
|
|
@ -47,8 +47,8 @@ TEST_F(MslUnaryOpTest, Complement) {
|
|||
|
||||
TEST_F(MslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
auto* p =
|
||||
Let("expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* var = Let("a", ty.f32(), Construct(ty.f32()));
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ TEST_F(BuilderTest, MemberAccessor_NonPointer) {
|
|||
Member("b", ty.f32()),
|
||||
});
|
||||
|
||||
auto* var = Const("ident", ty.Of(s), Construct(ty.Of(s), 0.f, 0.f));
|
||||
auto* var = Let("ident", ty.Of(s), Construct(ty.Of(s), 0.f, 0.f));
|
||||
|
||||
auto* expr = MemberAccessor("ident", "b");
|
||||
WrapInFunction(var, expr);
|
||||
|
@ -351,7 +351,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_NonPointer) {
|
|||
auto* s_type = Structure("my_struct", {Member("inner", ty.Of(inner_struct))});
|
||||
|
||||
auto* var =
|
||||
Const("ident", ty.Of(s_type),
|
||||
Let("ident", ty.Of(s_type),
|
||||
Construct(ty.Of(s_type), Construct(ty.Of(inner_struct), 0.f, 0.f)));
|
||||
auto* expr = MemberAccessor(MemberAccessor("ident", "inner"), "b");
|
||||
WrapInFunction(var, expr);
|
||||
|
@ -754,8 +754,7 @@ TEST_F(BuilderTest, IndexAccessor_Of_Vec) {
|
|||
// vec2<f32>(0.5, -0.5));
|
||||
// pos[1]
|
||||
|
||||
auto* var =
|
||||
Const("pos", ty.array(ty.vec2<f32>(), 3),
|
||||
auto* var = Let("pos", ty.array(ty.vec2<f32>(), 3),
|
||||
Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f),
|
||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
|
||||
|
||||
|
@ -798,8 +797,7 @@ TEST_F(BuilderTest, IndexAccessor_Of_Array_Of_f32) {
|
|||
// array<f32, 2>(0.5, -0.5));
|
||||
// pos[2][1]
|
||||
|
||||
auto* var =
|
||||
Const("pos", ty.array(ty.vec2<f32>(), 3),
|
||||
auto* var = Let("pos", ty.array(ty.vec2<f32>(), 3),
|
||||
Construct(ty.array(ty.vec2<f32>(), 3), vec2<f32>(0.0f, 0.5f),
|
||||
vec2<f32>(-0.5f, -0.5f), vec2<f32>(0.5f, -0.5f)));
|
||||
|
||||
|
@ -841,7 +839,7 @@ TEST_F(BuilderTest, IndexAccessor_Vec_Literal) {
|
|||
// let pos : vec2<f32> = vec2<f32>(0.0, 0.5);
|
||||
// pos[1]
|
||||
|
||||
auto* var = Const("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
|
||||
auto* var = Let("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
|
||||
|
||||
auto* expr = IndexAccessor("pos", 1u);
|
||||
WrapInFunction(var, expr);
|
||||
|
@ -871,7 +869,7 @@ TEST_F(BuilderTest, IndexAccessor_Vec_Dynamic) {
|
|||
// idx : i32
|
||||
// pos[idx]
|
||||
|
||||
auto* var = Const("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
|
||||
auto* var = Let("pos", ty.vec2<f32>(), vec2<f32>(0.0f, 0.5f));
|
||||
auto* idx = Var("idx", ty.i32());
|
||||
auto* expr = IndexAccessor("pos", idx);
|
||||
|
||||
|
@ -906,7 +904,7 @@ TEST_F(BuilderTest, IndexAccessor_Array_Literal) {
|
|||
// let a : array<f32, 3>;
|
||||
// a[2]
|
||||
|
||||
auto* var = Const("a", ty.array<f32, 3>(),
|
||||
auto* var = Let("a", ty.array<f32, 3>(),
|
||||
Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
|
||||
auto* expr = IndexAccessor("a", 2);
|
||||
WrapInFunction(var, expr);
|
||||
|
@ -942,7 +940,7 @@ TEST_F(BuilderTest, IndexAccessor_Array_Dynamic) {
|
|||
// idx : i32
|
||||
// a[idx]
|
||||
|
||||
auto* var = Const("a", ty.array<f32, 3>(),
|
||||
auto* var = Let("a", ty.array<f32, 3>(),
|
||||
Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
|
||||
|
||||
auto* idx = Var("idx", ty.i32());
|
||||
|
@ -992,7 +990,7 @@ TEST_F(BuilderTest, IndexAccessor_Matrix_Dynamic) {
|
|||
// a[idx]
|
||||
|
||||
auto* var =
|
||||
Const("a", ty.mat2x2<f32>(),
|
||||
Let("a", ty.mat2x2<f32>(),
|
||||
Construct(ty.mat2x2<f32>(), Construct(ty.vec2<f32>(), 1.f, 2.f),
|
||||
Construct(ty.vec2<f32>(), 3.f, 4.f)));
|
||||
|
||||
|
|
|
@ -1577,8 +1577,8 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets) {
|
|||
create<ast::GroupAttribute>(2),
|
||||
});
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Const("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
auto* p = Let("p", nullptr, AddressOf("b"));
|
||||
auto* p2 = Let("p2", nullptr, AddressOf(MemberAccessor(Deref(p), "a")));
|
||||
auto* expr = Call("arrayLength", p2);
|
||||
|
||||
Func("a_func", {}, ty.void_(),
|
||||
|
@ -1637,9 +1637,9 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets_WithPtrNoise) {
|
|||
create<ast::GroupAttribute>(2),
|
||||
});
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf(Deref(AddressOf("b"))));
|
||||
auto* p2 = Const("p2", nullptr, AddressOf(Deref(p)));
|
||||
auto* p3 = Const("p3", nullptr, AddressOf(MemberAccessor(Deref(p2), "a")));
|
||||
auto* p = Let("p", nullptr, AddressOf(Deref(AddressOf("b"))));
|
||||
auto* p2 = Let("p2", nullptr, AddressOf(Deref(p)));
|
||||
auto* p3 = Let("p3", nullptr, AddressOf(MemberAccessor(Deref(p2), "a")));
|
||||
auto* expr = Call("arrayLength", AddressOf(Deref(p3)));
|
||||
|
||||
Func("a_func", {}, ty.void_(),
|
||||
|
@ -1704,9 +1704,9 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) {
|
|||
|
||||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Decl(Const("u", ty.u32(),
|
||||
Decl(Let("u", ty.u32(),
|
||||
Call("atomicLoad", AddressOf(MemberAccessor("b", "u"))))),
|
||||
Decl(Const("i", ty.i32(),
|
||||
Decl(Let("i", ty.i32(),
|
||||
Call("atomicLoad", AddressOf(MemberAccessor("b", "i"))))),
|
||||
},
|
||||
ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
|
||||
|
@ -1845,7 +1845,7 @@ TEST_P(Builtin_Builtin_AtomicRMW_i32, Test) {
|
|||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Decl(Var("v", nullptr, Expr(10))),
|
||||
Decl(Const("x", ty.i32(),
|
||||
Decl(Let("x", ty.i32(),
|
||||
Call(GetParam().name, AddressOf(MemberAccessor("b", "v")),
|
||||
"v"))),
|
||||
},
|
||||
|
@ -1920,7 +1920,7 @@ TEST_P(Builtin_Builtin_AtomicRMW_u32, Test) {
|
|||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Decl(Var("v", nullptr, Expr(10u))),
|
||||
Decl(Const("x", ty.u32(),
|
||||
Decl(Let("x", ty.u32(),
|
||||
Call(GetParam().name, AddressOf(MemberAccessor("b", "v")),
|
||||
"v"))),
|
||||
},
|
||||
|
@ -1998,12 +1998,12 @@ TEST_F(BuiltinBuilderTest, Call_AtomicExchange) {
|
|||
ast::StatementList{
|
||||
Decl(Var("u", nullptr, Expr(10u))),
|
||||
Decl(Var("i", nullptr, Expr(10))),
|
||||
Decl(Const("r", ty.u32(),
|
||||
Call("atomicExchange",
|
||||
AddressOf(MemberAccessor("b", "u")), "u"))),
|
||||
Decl(Const("s", ty.i32(),
|
||||
Call("atomicExchange",
|
||||
AddressOf(MemberAccessor("b", "i")), "i"))),
|
||||
Decl(Let("r", ty.u32(),
|
||||
Call("atomicExchange", AddressOf(MemberAccessor("b", "u")),
|
||||
"u"))),
|
||||
Decl(Let("s", ty.i32(),
|
||||
Call("atomicExchange", AddressOf(MemberAccessor("b", "i")),
|
||||
"i"))),
|
||||
},
|
||||
ast::AttributeList{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
@ -2074,10 +2074,10 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) {
|
|||
|
||||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Decl(Const("u", ty.vec2<u32>(),
|
||||
Decl(Let("u", ty.vec2<u32>(),
|
||||
Call("atomicCompareExchangeWeak",
|
||||
AddressOf(MemberAccessor("b", "u")), 10u, 20u))),
|
||||
Decl(Const("i", ty.vec2<i32>(),
|
||||
Decl(Let("i", ty.vec2<i32>(),
|
||||
Call("atomicCompareExchangeWeak",
|
||||
AddressOf(MemberAccessor("b", "i")), 10, 20))),
|
||||
},
|
||||
|
|
|
@ -174,7 +174,7 @@ OpStore %7 %6
|
|||
TEST_F(BuilderTest, FunctionVar_Const) {
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
|
||||
auto* v = Const("var", ty.vec3<f32>(), init);
|
||||
auto* v = Let("var", ty.vec3<f32>(), init);
|
||||
|
||||
WrapInFunction(v);
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
|||
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
|
||||
auto* v = Const("var", ty.vec3<f32>(), init);
|
||||
auto* v = Let("var", ty.vec3<f32>(), init);
|
||||
|
||||
auto* expr = Expr("var");
|
||||
WrapInFunction(v, expr);
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(WgslGeneratorImplTest, IndexAccessor) {
|
|||
TEST_F(WgslGeneratorImplTest, IndexAccessor_OfDref) {
|
||||
Global("ary", ty.array<i32, 10>(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("ary"));
|
||||
auto* p = Let("p", nullptr, AddressOf("ary"));
|
||||
auto* expr = IndexAccessor(Deref("p"), 5);
|
||||
WrapInFunction(p, expr);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_MemberAccessor_OfDref) {
|
|||
auto* s = Structure("Data", {Member("mem", ty.f32())});
|
||||
Global("str", ty.Of(s), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* p = Const("p", nullptr, AddressOf("str"));
|
||||
auto* p = Let("p", nullptr, AddressOf("str"));
|
||||
auto* expr = MemberAccessor(Deref("p"), "mem");
|
||||
WrapInFunction(p, expr);
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ TEST_F(WgslUnaryOpTest, Complement) {
|
|||
|
||||
TEST_F(WgslUnaryOpTest, Indirection) {
|
||||
Global("G", ty.f32(), ast::StorageClass::kPrivate);
|
||||
auto* p = Const(
|
||||
"expr", nullptr,
|
||||
auto* p =
|
||||
Let("expr", nullptr,
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kAddressOf, Expr("G")));
|
||||
auto* op =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kIndirection, Expr("expr"));
|
||||
|
|
|
@ -114,7 +114,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Constructor) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitVariable_Const) {
|
||||
auto* v = Const("a", ty.f32(), Expr(1.0f));
|
||||
auto* v = Let("a", ty.f32(), Expr(1.0f));
|
||||
WrapInFunction(Decl(v));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
Loading…
Reference in New Issue