[tint][ir][ToProgram] Implement var expressions

Bug: tint:1902
Change-Id: I97c026adc113b4a8834b9b5e978b4084d777328a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133060
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2023-05-17 10:38:36 +00:00 committed by Dawn LUCI CQ
parent 83c5c8b151
commit 0b9cb101bf
2 changed files with 21 additions and 0 deletions

View File

@ -183,6 +183,7 @@ class State {
return Switch(
val, //
[&](const ir::Constant* c) { return ConstExpr(c); },
[&](const ir::Var* v) { return VarExpr(v); },
[&](Default) {
TINT_UNIMPLEMENTED(IR, b.Diagnostics())
<< "unhandled case in Switch(): " << val->TypeInfo().name;
@ -205,6 +206,8 @@ class State {
});
}
const ast::Expression* VarExpr(const ir::Var* v) { return b.Expr(NameOf(v)); }
const ast::Type Type(const type::Type* ty) {
return Switch(
ty, //

View File

@ -67,6 +67,14 @@ fn f() {
)");
}
TEST_F(IRToProgramRoundtripTest, FunctionScopeVar_i32) {
Test(R"(
fn f() {
var i : i32;
}
)");
}
TEST_F(IRToProgramRoundtripTest, FunctionScopeVar_i32_InitLiteral) {
Test(R"(
fn f() {
@ -75,5 +83,15 @@ fn f() {
)");
}
TEST_F(IRToProgramRoundtripTest, FunctionScopeVar_Chained) {
Test(R"(
fn f() {
var a : i32 = 42i;
var b : i32 = a;
var c : i32 = b;
}
)");
}
} // namespace
} // namespace tint::ir