Add break-if support.
This CL adds support for `break-if` to Tint.
Bug: tint:1633, tint:1451
Change-Id: I30dfd62a3e09255624ff76ebe0cdd3a3c7cf9c5f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106420
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: dan sinclair <dsinclair@google.com>
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index 1dc3b10..e42274d 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -942,6 +942,16 @@
return true;
}
+bool GeneratorImpl::EmitBreakIf(const ast::BreakIfStatement* b) {
+ auto out = line();
+ out << "if (";
+ if (!EmitExpression(out, b->condition)) {
+ return false;
+ }
+ out << ") { break; }";
+ return true;
+}
+
bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) {
auto* call = builder_.Sem().Get<sem::Call>(expr);
auto* target = call->Target();
@@ -3591,6 +3601,9 @@
[&](const ast::BreakStatement* b) { //
return EmitBreak(b);
},
+ [&](const ast::BreakIfStatement* b) { //
+ return EmitBreakIf(b);
+ },
[&](const ast::CallStatement* c) { //
auto out = line();
if (!EmitCall(out, c->expr)) {