Emit assignment statement.
This CL updates the WGSL writer to emit the assignment statement nodes.
Bug: tint:4
Change-Id: I8a52f4e96c61ecb9e97cd3da41f4a1aa718e8d37
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17162
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index e0c8fef..7a728e1 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -19,6 +19,7 @@
#include "src/ast/array_accessor_expression.h"
#include "src/ast/as_expression.h"
+#include "src/ast/assignment_statement.h"
#include "src/ast/binding_decoration.h"
#include "src/ast/bool_literal.h"
#include "src/ast/builtin_decoration.h"
@@ -34,6 +35,7 @@
#include "src/ast/member_accessor_expression.h"
#include "src/ast/relational_expression.h"
#include "src/ast/set_decoration.h"
+#include "src/ast/statement.h"
#include "src/ast/struct.h"
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_offset_decoration.h"
@@ -639,6 +641,31 @@
return true;
}
+bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
+ if (stmt->IsAssign()) {
+ return EmitAssign(stmt->AsAssign());
+ }
+
+ error_ = "unknown statement type";
+ return false;
+}
+
+bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) {
+ if (!EmitExpression(stmt->lhs())) {
+ return false;
+ }
+
+ out_ << " = ";
+
+ if (!EmitExpression(stmt->rhs())) {
+ return false;
+ }
+
+ out_ << ";";
+
+ return true;
+}
+
} // namespace wgsl
} // namespace writer
} // namespace tint