writer/hlsl: Fix emission of EmitStorageBufferAccessor()

Fix number of parentheses emitted for all control flows.

Add a TINT_UNIMPLEMENTED() for types that are not currently handled.

Change-Id: I987776e4d3b6d7c4d237f44db8b0eebb1a9a7fbd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46266
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-03-30 20:20:28 +00:00 committed by Commit Bot service account
parent 0f02a6de00
commit 3ac4a0e013
1 changed files with 23 additions and 19 deletions

View File

@ -95,6 +95,13 @@ std::ostream& operator<<(std::ostream& s, const RegisterAndSpace& rs) {
return s;
}
// Helper for writting a '(' on construction and a ')' destruction.
struct ScopedParen {
std::ostream& s_;
explicit ScopedParen(std::ostream& s) : s_(s) { s << "("; }
~ScopedParen() { s_ << ")"; }
};
} // namespace
GeneratorImpl::GeneratorImpl(const Program* program)
@ -2185,6 +2192,10 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
out << "asint(";
} else if (result_type->is_unsigned_scalar_or_vector()) {
out << "asuint(";
} else {
TINT_UNIMPLEMENTED(diagnostics_)
<< result_type->FriendlyName(builder_.Symbols());
return false;
}
}
@ -2229,8 +2240,8 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
return true;
}
out << "uint" << mat->rows() << "x" << mat->columns() << "(";
out << "uint" << mat->rows() << "x" << mat->columns();
ScopedParen p(out);
for (uint32_t i = 0; i < mat->columns(); i++) {
if (i != 0) {
out << ", ";
@ -2239,29 +2250,22 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
out << buffer_name << "." << access_method << "(" << idx << " + "
<< (i * stride) << ")";
}
// Close the matrix type and outer cast
out << "))";
return true;
}
out << buffer_name << "." << access_method << "(" << idx;
if (is_store) {
out << ", asuint(";
if (!EmitExpression(pre, out, rhs)) {
return false;
} else {
out << buffer_name << "." << access_method;
ScopedParen p(out);
out << idx;
if (is_store) {
out << ", asuint";
ScopedParen p2(out);
if (!EmitExpression(pre, out, rhs)) {
return false;
}
}
out << ")";
}
out << ")";
// Close the outer cast.
if (!is_store) {
out << ")";
}
return true;
}