Convert TextGenerator over to utils::StringStream.
This CL updates the TextGenerator base class to use utils::StringStream. Bug: tint:1686 Change-Id: Ie36f55cf32e63773c4bee2cf89cdef19ab1fba28 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121960 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
88fea2a9c3
commit
b2ba57b15d
|
@ -103,10 +103,6 @@ class StringStream {
|
||||||
/// @returns the string contents of the stream
|
/// @returns the string contents of the stream
|
||||||
std::string str() const { return sstream_.str(); }
|
std::string str() const { return sstream_.str(); }
|
||||||
|
|
||||||
/// [DEPRECATED] This should not be called.
|
|
||||||
/// @returns the underlying stream
|
|
||||||
std::ostream& stream() { return sstream_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::stringstream sstream_;
|
std::stringstream sstream_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -381,7 +381,7 @@ bool GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpr
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->expr)) {
|
if (!EmitExpression(out, expr->expr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,7 @@ bool GeneratorImpl::EmitVectorRelational(utils::StringStream& out,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -445,14 +445,14 @@ bool GeneratorImpl::EmitBitwiseBoolOp(utils::StringStream& out, const ast::Binar
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen outerCastParen(out.stream());
|
ScopedParen outerCastParen(out);
|
||||||
// Cast LHS to uint scalar or vector type.
|
// Cast LHS to uint scalar or vector type.
|
||||||
if (!EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite,
|
if (!EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite,
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ScopedParen innerCastParen(out.stream());
|
ScopedParen innerCastParen(out);
|
||||||
// Emit LHS.
|
// Emit LHS.
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -473,7 +473,7 @@ bool GeneratorImpl::EmitBitwiseBoolOp(utils::StringStream& out, const ast::Binar
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ScopedParen innerCastParen(out.stream());
|
ScopedParen innerCastParen(out);
|
||||||
// Emit RHS.
|
// Emit RHS.
|
||||||
if (!EmitExpression(out, expr->rhs)) {
|
if (!EmitExpression(out, expr->rhs)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -532,7 +532,7 @@ bool GeneratorImpl::EmitFloatModulo(utils::StringStream& out, const ast::BinaryE
|
||||||
// Call the helper
|
// Call the helper
|
||||||
out << fn;
|
out << fn;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -592,7 +592,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
return EmitFloatModulo(out, expr);
|
return EmitFloatModulo(out, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -731,7 +731,7 @@ bool GeneratorImpl::EmitFunctionCall(utils::StringStream& out,
|
||||||
auto* ident = fn->Declaration()->name;
|
auto* ident = fn->Declaration()->name;
|
||||||
|
|
||||||
out << builder_.Symbols().NameFor(ident->symbol);
|
out << builder_.Symbols().NameFor(ident->symbol);
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : args) {
|
for (auto* arg : args) {
|
||||||
|
@ -813,7 +813,7 @@ bool GeneratorImpl::EmitBuiltinCall(utils::StringStream& out,
|
||||||
}
|
}
|
||||||
|
|
||||||
out << name;
|
out << name;
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : call->Arguments()) {
|
for (auto* arg : call->Arguments()) {
|
||||||
|
@ -837,7 +837,7 @@ bool GeneratorImpl::EmitValueConversion(utils::StringStream& out,
|
||||||
builtin::Access::kReadWrite, "")) {
|
builtin::Access::kReadWrite, "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (!EmitExpression(out, call->Arguments()[0]->Declaration())) {
|
if (!EmitExpression(out, call->Arguments()[0]->Declaration())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -860,7 +860,7 @@ bool GeneratorImpl::EmitValueConstructor(utils::StringStream& out,
|
||||||
if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) {
|
if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : call->Arguments()) {
|
for (auto* arg : call->Arguments()) {
|
||||||
|
@ -883,7 +883,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out,
|
||||||
auto call = [&](const char* name) {
|
auto call = [&](const char* name) {
|
||||||
out << name;
|
out << name;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (size_t i = 0; i < expr->args.Length(); i++) {
|
for (size_t i = 0; i < expr->args.Length(); i++) {
|
||||||
auto* arg = expr->args[i];
|
auto* arg = expr->args[i];
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -903,7 +903,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out,
|
||||||
// atomicOr using 0 as the OR value
|
// atomicOr using 0 as the OR value
|
||||||
out << "atomicOr";
|
out << "atomicOr";
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->args[0])) {
|
if (!EmitExpression(out, expr->args[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1101,7 @@ bool GeneratorImpl::EmitSelectCall(utils::StringStream& out, const ast::CallExpr
|
||||||
out << ")";
|
out << ")";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ScopedParen paren(out.stream());
|
ScopedParen paren(out);
|
||||||
if (!EmitExpression(out, expr_cond)) {
|
if (!EmitExpression(out, expr_cond)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1182,7 +1182,7 @@ bool GeneratorImpl::EmitDotCall(utils::StringStream& out,
|
||||||
}
|
}
|
||||||
|
|
||||||
out << fn;
|
out << fn;
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (!EmitExpression(out, expr->args[0])) {
|
if (!EmitExpression(out, expr->args[0])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1378,7 +1378,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
|
||||||
return EmitExpression(out, e);
|
return EmitExpression(out, e);
|
||||||
}
|
}
|
||||||
emit_signed_int_type(ty);
|
emit_signed_int_type(ty);
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
return EmitExpression(out, e);
|
return EmitExpression(out, e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1388,7 +1388,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
|
||||||
// textureSize() / imageSize() returns a signed scalar / vector in GLSL.
|
// textureSize() / imageSize() returns a signed scalar / vector in GLSL.
|
||||||
// Cast.
|
// Cast.
|
||||||
emit_unsigned_int_type(call->Type());
|
emit_unsigned_int_type(call->Type());
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (texture_type->Is<type::StorageTexture>()) {
|
if (texture_type->Is<type::StorageTexture>()) {
|
||||||
out << "imageSize(";
|
out << "imageSize(";
|
||||||
|
@ -1427,7 +1427,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
|
||||||
// textureSize() / imageSize() returns a signed scalar / vector in GLSL.
|
// textureSize() / imageSize() returns a signed scalar / vector in GLSL.
|
||||||
// Cast.
|
// Cast.
|
||||||
out << "uint";
|
out << "uint";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (texture_type->Is<type::StorageTexture>()) {
|
if (texture_type->Is<type::StorageTexture>()) {
|
||||||
out << "imageSize(";
|
out << "imageSize(";
|
||||||
|
@ -1461,7 +1461,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
|
||||||
// textureQueryLevels() returns a signed scalar in GLSL.
|
// textureQueryLevels() returns a signed scalar in GLSL.
|
||||||
// Cast.
|
// Cast.
|
||||||
out << "uint";
|
out << "uint";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
out << "textureQueryLevels(";
|
out << "textureQueryLevels(";
|
||||||
if (!EmitExpression(out, texture)) {
|
if (!EmitExpression(out, texture)) {
|
||||||
|
@ -1475,7 +1475,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
|
||||||
// textureSamples() returns a signed scalar in GLSL.
|
// textureSamples() returns a signed scalar in GLSL.
|
||||||
// Cast.
|
// Cast.
|
||||||
out << "uint";
|
out << "uint";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
out << "textureSamples(";
|
out << "textureSamples(";
|
||||||
if (!EmitExpression(out, texture)) {
|
if (!EmitExpression(out, texture)) {
|
||||||
|
@ -2367,7 +2367,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (constant->AllEqual()) {
|
if (constant->AllEqual()) {
|
||||||
return EmitConstant(out, constant->Index(0));
|
return EmitConstant(out, constant->Index(0));
|
||||||
|
@ -2389,7 +2389,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
for (size_t column_idx = 0; column_idx < m->columns(); column_idx++) {
|
for (size_t column_idx = 0; column_idx < m->columns(); column_idx++) {
|
||||||
if (column_idx > 0) {
|
if (column_idx > 0) {
|
||||||
|
@ -2407,7 +2407,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
auto count = a->ConstantCount();
|
auto count = a->ConstantCount();
|
||||||
if (!count) {
|
if (!count) {
|
||||||
|
@ -2434,7 +2434,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
|
|
||||||
out << StructName(s);
|
out << StructName(s);
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
for (size_t i = 0; i < s->Members().Length(); i++) {
|
for (size_t i = 0; i < s->Members().Length(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -2499,7 +2499,7 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (uint32_t i = 0; i < vec->Width(); i++) {
|
for (uint32_t i = 0; i < vec->Width(); i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
|
@ -2513,7 +2513,7 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
|
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
|
@ -2528,7 +2528,7 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool first = true;
|
bool first = true;
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (auto* member : str->Members()) {
|
for (auto* member : str->Members()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
|
@ -2542,7 +2542,7 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
auto count = arr->ConstantCount();
|
auto count = arr->ConstantCount();
|
||||||
if (!count) {
|
if (!count) {
|
||||||
|
@ -3111,7 +3111,7 @@ bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpr
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->expr)) {
|
if (!EmitExpression(out, expr->expr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3243,7 +3243,7 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out,
|
||||||
// Call the helper
|
// Call the helper
|
||||||
out << fn;
|
out << fn;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : call->args) {
|
for (auto* arg : call->args) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
|
|
|
@ -757,7 +757,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1419,7 +1419,7 @@ bool GeneratorImpl::EmitStorageBufferAccess(
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
out << n;
|
out << n;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, offset)) {
|
if (!EmitExpression(out, offset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1433,7 +1433,7 @@ bool GeneratorImpl::EmitStorageBufferAccess(
|
||||||
// to emit `buffer.Load<float16_t>(offset)`.
|
// to emit `buffer.Load<float16_t>(offset)`.
|
||||||
auto templated_load = [&](const char* type) {
|
auto templated_load = [&](const char* type) {
|
||||||
out << buffer << ".Load<" << type << ">"; // templated load
|
out << buffer << ".Load<" << type << ">"; // templated load
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, offset)) {
|
if (!EmitExpression(out, offset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1485,12 +1485,12 @@ bool GeneratorImpl::EmitStorageBufferAccess(
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
out << n;
|
out << n;
|
||||||
}
|
}
|
||||||
ScopedParen sp1(out.stream());
|
ScopedParen sp1(out);
|
||||||
if (!EmitExpression(out, offset)) {
|
if (!EmitExpression(out, offset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out << ", asuint";
|
out << ", asuint";
|
||||||
ScopedParen sp2(out.stream());
|
ScopedParen sp2(out);
|
||||||
if (!EmitExpression(out, value)) {
|
if (!EmitExpression(out, value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1501,7 +1501,7 @@ bool GeneratorImpl::EmitStorageBufferAccess(
|
||||||
// to emit `buffer.Store<float16_t>(offset)`.
|
// to emit `buffer.Store<float16_t>(offset)`.
|
||||||
auto templated_store = [&](const char* type) {
|
auto templated_store = [&](const char* type) {
|
||||||
out << buffer << ".Store<" << type << ">"; // templated store
|
out << buffer << ".Store<" << type << ">"; // templated store
|
||||||
ScopedParen sp1(out.stream());
|
ScopedParen sp1(out);
|
||||||
if (!EmitExpression(out, offset)) {
|
if (!EmitExpression(out, offset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1849,7 +1849,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out,
|
||||||
|
|
||||||
out << "InterlockedExchange";
|
out << "InterlockedExchange";
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->args[0])) {
|
if (!EmitExpression(out, expr->args[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1944,7 +1944,7 @@ bool GeneratorImpl::EmitSelectCall(utils::StringStream& out, const ast::CallExpr
|
||||||
auto* expr_false = expr->args[0];
|
auto* expr_false = expr->args[0];
|
||||||
auto* expr_true = expr->args[1];
|
auto* expr_true = expr->args[1];
|
||||||
auto* expr_cond = expr->args[2];
|
auto* expr_cond = expr->args[2];
|
||||||
ScopedParen paren(out.stream());
|
ScopedParen paren(out);
|
||||||
if (!EmitExpression(out, expr_cond)) {
|
if (!EmitExpression(out, expr_cond)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3312,7 +3312,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
|
||||||
[&](const type::Vector* v) {
|
[&](const type::Vector* v) {
|
||||||
if (constant->AllEqual()) {
|
if (constant->AllEqual()) {
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitConstant(out, constant->Index(0), is_variable_initializer)) {
|
if (!EmitConstant(out, constant->Index(0), is_variable_initializer)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3329,7 +3329,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
for (size_t i = 0; i < v->Width(); i++) {
|
for (size_t i = 0; i < v->Width(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -3347,7 +3347,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
for (size_t i = 0; i < m->columns(); i++) {
|
for (size_t i = 0; i < m->columns(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -3507,7 +3507,7 @@ bool GeneratorImpl::EmitValue(utils::StringStream& out, const type::Type* type,
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (uint32_t i = 0; i < vec->Width(); i++) {
|
for (uint32_t i = 0; i < vec->Width(); i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
|
@ -3523,7 +3523,7 @@ bool GeneratorImpl::EmitValue(utils::StringStream& out, const type::Type* type,
|
||||||
"")) {
|
"")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
|
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
|
@ -4382,7 +4382,7 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out,
|
||||||
// Call the helper
|
// Call the helper
|
||||||
out << fn;
|
out << fn;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : call->args) {
|
for (auto* arg : call->args) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
|
|
|
@ -525,7 +525,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
// Handle fmod
|
// Handle fmod
|
||||||
if (expr->op == ast::BinaryOp::kModulo && lhs_type->is_float_scalar_or_vector()) {
|
if (expr->op == ast::BinaryOp::kModulo && lhs_type->is_float_scalar_or_vector()) {
|
||||||
out << "fmod";
|
out << "fmod";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +549,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
// WGSL defines behaviour for signed overflow, MSL does not. For these
|
// WGSL defines behaviour for signed overflow, MSL does not. For these
|
||||||
// cases, bitcast operands to unsigned, then cast result to signed.
|
// cases, bitcast operands to unsigned, then cast result to signed.
|
||||||
ScopedBitCast outer_int_cast(this, out, target_type, signed_type_of(target_type));
|
ScopedBitCast outer_int_cast(this, out, target_type, signed_type_of(target_type));
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
{
|
{
|
||||||
ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(target_type));
|
ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(target_type));
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
|
@ -576,7 +576,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
// Shift left: discards top bits, so convert first operand to unsigned
|
// Shift left: discards top bits, so convert first operand to unsigned
|
||||||
// first, then convert result back to signed
|
// first, then convert result back to signed
|
||||||
ScopedBitCast outer_int_cast(this, out, lhs_type, signed_type_of(lhs_type));
|
ScopedBitCast outer_int_cast(this, out, lhs_type, signed_type_of(lhs_type));
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
{
|
{
|
||||||
ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(lhs_type));
|
ScopedBitCast lhs_uint_cast(this, out, lhs_type, unsigned_type_of(lhs_type));
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
|
@ -595,7 +595,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
// Handle '&' and '|' of booleans.
|
// Handle '&' and '|' of booleans.
|
||||||
if ((expr->IsAnd() || expr->IsOr()) && lhs_type->Is<type::Bool>()) {
|
if ((expr->IsAnd() || expr->IsOr()) && lhs_type->Is<type::Bool>()) {
|
||||||
out << "bool";
|
out << "bool";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit as usual
|
// Emit as usual
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->lhs)) {
|
if (!EmitExpression(out, expr->lhs)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -748,7 +748,7 @@ bool GeneratorImpl::EmitBuiltinCall(utils::StringStream& out,
|
||||||
if (sem->Type()->UnwrapRef()->is_scalar()) {
|
if (sem->Type()->UnwrapRef()->is_scalar()) {
|
||||||
// Emulate scalar overload using fabs(x - y);
|
// Emulate scalar overload using fabs(x - y);
|
||||||
out << "fabs";
|
out << "fabs";
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
if (!EmitExpression(out, expr->args[0])) {
|
if (!EmitExpression(out, expr->args[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -866,7 +866,7 @@ bool GeneratorImpl::EmitAtomicCall(utils::StringStream& out,
|
||||||
auto call = [&](const std::string& name, bool append_memory_order_relaxed) {
|
auto call = [&](const std::string& name, bool append_memory_order_relaxed) {
|
||||||
out << name;
|
out << name;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
for (size_t i = 0; i < expr->args.Length(); i++) {
|
for (size_t i = 0; i < expr->args.Length(); i++) {
|
||||||
auto* arg = expr->args[i];
|
auto* arg = expr->args[i];
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -1646,7 +1646,7 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty
|
||||||
if (!EmitType(out, mat, "")) {
|
if (!EmitType(out, mat, "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
return EmitZeroValue(out, mat->type());
|
return EmitZeroValue(out, mat->type());
|
||||||
},
|
},
|
||||||
[&](const type::Array*) {
|
[&](const type::Array*) {
|
||||||
|
@ -1693,7 +1693,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
if (constant->AllEqual()) {
|
if (constant->AllEqual()) {
|
||||||
if (!EmitConstant(out, constant->Index(0))) {
|
if (!EmitConstant(out, constant->Index(0))) {
|
||||||
|
@ -1717,7 +1717,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
|
|
||||||
for (size_t i = 0; i < m->columns(); i++) {
|
for (size_t i = 0; i < m->columns(); i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
@ -3286,7 +3286,7 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out,
|
||||||
// Call the helper
|
// Call the helper
|
||||||
out << fn;
|
out << fn;
|
||||||
{
|
{
|
||||||
ScopedParen sp(out.stream());
|
ScopedParen sp(out);
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto* arg : call->args) {
|
for (auto* arg : call->args) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ void TextGenerator::TextBuffer::Insert(const TextBuffer& tb, size_t before, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TextGenerator::TextBuffer::String(uint32_t indent /* = 0 */) const {
|
std::string TextGenerator::TextBuffer::String(uint32_t indent /* = 0 */) const {
|
||||||
std::stringstream ss;
|
utils::StringStream ss;
|
||||||
for (auto& line : lines) {
|
for (auto& line : lines) {
|
||||||
if (!line.content.empty()) {
|
if (!line.content.empty()) {
|
||||||
for (uint32_t i = 0; i < indent + line.indent; i++) {
|
for (uint32_t i = 0; i < indent + line.indent; i++) {
|
||||||
|
@ -127,7 +127,7 @@ std::string TextGenerator::TextBuffer::String(uint32_t indent /* = 0 */) const {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextGenerator::ScopedParen::ScopedParen(std::ostream& stream) : s(stream) {
|
TextGenerator::ScopedParen::ScopedParen(utils::StringStream& stream) : s(stream) {
|
||||||
s << "(";
|
s << "(";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,9 +140,6 @@ class TextGenerator {
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~LineWriter();
|
~LineWriter();
|
||||||
|
|
||||||
/// [DEPRECATED] Remove when utils::StringStream conversion is done
|
|
||||||
/// @returns the utils::StringStream
|
|
||||||
operator std::ostream&() { return os.stream(); }
|
|
||||||
/// @returns the utils::StringStream
|
/// @returns the utils::StringStream
|
||||||
operator utils::StringStream&() { return os; }
|
operator utils::StringStream&() { return os; }
|
||||||
|
|
||||||
|
@ -164,9 +161,8 @@ class TextGenerator {
|
||||||
/// Helper for writing a '(' on construction and a ')' destruction.
|
/// Helper for writing a '(' on construction and a ')' destruction.
|
||||||
struct ScopedParen {
|
struct ScopedParen {
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// [DEPRECATED] This should be utils::StringStream when conversion is done
|
/// @param stream the utils::StringStream that will be written to
|
||||||
/// @param stream the std::ostream that will be written to
|
explicit ScopedParen(utils::StringStream& stream);
|
||||||
explicit ScopedParen(std::ostream& stream);
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~ScopedParen();
|
~ScopedParen();
|
||||||
|
|
||||||
|
@ -174,7 +170,7 @@ class TextGenerator {
|
||||||
ScopedParen(ScopedParen&& rhs) = delete;
|
ScopedParen(ScopedParen&& rhs) = delete;
|
||||||
ScopedParen(const ScopedParen&) = delete;
|
ScopedParen(const ScopedParen&) = delete;
|
||||||
ScopedParen& operator=(const ScopedParen&) = delete;
|
ScopedParen& operator=(const ScopedParen&) = delete;
|
||||||
std::ostream& s;
|
utils::StringStream& s;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Helper for incrementing indentation on construction and decrementing
|
/// Helper for incrementing indentation on construction and decrementing
|
||||||
|
|
Loading…
Reference in New Issue