[hlsl] Stub out emitting lets and vars
This CL adds the basics for emitting `let` and `var` statements from the
HLSL backend.
Bug: 42251045
Change-Id: Ie874b40a17141e4fd83bb474c9f38827117516f8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/192960
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/hlsl/writer/printer/printer.cc b/src/tint/lang/hlsl/writer/printer/printer.cc
index 31c3676..8170310 100644
--- a/src/tint/lang/hlsl/writer/printer/printer.cc
+++ b/src/tint/lang/hlsl/writer/printer/printer.cc
@@ -47,6 +47,7 @@
#include "src/tint/lang/core/ir/return.h"
#include "src/tint/lang/core/ir/validator.h"
#include "src/tint/lang/core/ir/value.h"
+#include "src/tint/lang/core/ir/var.h"
#include "src/tint/lang/core/texel_format.h"
#include "src/tint/lang/core/type/array.h"
#include "src/tint/lang/core/type/array_count.h"
@@ -156,11 +157,42 @@
for (auto* inst : *block) {
Switch(
inst, //
+ [&](const core::ir::Var* v) { EmitVar(v); }, //
+ [&](const core::ir::Let* i) { EmitLet(i); }, //
[&](const core::ir::Return* i) { EmitReturn(i); }, //
TINT_ICE_ON_NO_MATCH);
}
}
+ void EmitVar(const core::ir::Var* var) {
+ auto out = Line();
+
+ // TODO(dsinclair): This isn't right, as some types contain their names
+ EmitType(out, var->Result(0)->Type());
+ out << " ";
+ out << NameOf(var->Result(0));
+
+ out << " = ";
+
+ // TODO(dsinclair): Add transform to create a 0-initializer if one not present
+ EmitValue(out, var->Initializer());
+ out << ";";
+ }
+
+ void EmitLet(const core::ir::Let* l) {
+ auto out = Line();
+
+ // TODO(dsinclair): This isn't right, as some types contain their names.
+ // TODO(dsinclair): Investigate using `const` here as well, the AST printer doesn't emit
+ // const with a let, but we should be able to.
+ EmitType(out, l->Result(0)->Type());
+ out << " ";
+ out << NameOf(l->Result(0));
+ out << " = ";
+ EmitValue(out, l->Value());
+ out << ";";
+ }
+
void EmitReturn(const core::ir::Return* r) {
// If this return has no arguments and the current block is for the function which is
// being returned, skip the return.