Convert HLSL generator over to utils::StringStream.
This CL converts the HLSL generator to use utils::StringStream instead
of std::stringstream.
Bug: tint:1686
Change-Id: I69d4deec9b65bbcba6afe319cc1266879cd7c373
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121900
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index 14f1d0c..0d628e7 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -75,6 +75,7 @@
#include "src/tint/utils/map.h"
#include "src/tint/utils/scoped_assignment.h"
#include "src/tint/utils/string.h"
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/append_vector.h"
#include "src/tint/writer/check_supported_extensions.h"
#include "src/tint/writer/float_to_string.h"
@@ -114,7 +115,7 @@
}
}
-void PrintF32(std::ostream& out, float value) {
+void PrintF32(utils::StringStream& out, float value) {
if (std::isinf(value)) {
out << "0.0f " << (value >= 0 ? "/* inf */" : "/* -inf */");
} else if (std::isnan(value)) {
@@ -124,7 +125,7 @@
}
}
-void PrintF16(std::ostream& out, float value) {
+void PrintF16(utils::StringStream& out, float value) {
if (std::isinf(value)) {
out << "0.0h " << (value >= 0 ? "/* inf */" : "/* -inf */");
} else if (std::isnan(value)) {
@@ -143,7 +144,7 @@
sem::BindingPoint const binding_point;
};
-std::ostream& operator<<(std::ostream& s, const RegisterAndSpace& rs) {
+utils::StringStream& operator<<(utils::StringStream& s, const RegisterAndSpace& rs) {
s << " : register(" << rs.reg << rs.binding_point.binding << ", space" << rs.binding_point.group
<< ")";
return s;
@@ -377,7 +378,7 @@
auto name = utils::GetOrCreate(dynamic_vector_write_, vec, [&]() -> std::string {
std::string fn;
{
- std::ostringstream ss;
+ utils::StringStream ss;
if (!EmitType(ss, vec, tint::builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, "")) {
return "";
@@ -451,7 +452,7 @@
auto name = utils::GetOrCreate(dynamic_matrix_vector_write_, mat, [&]() -> std::string {
std::string fn;
{
- std::ostringstream ss;
+ utils::StringStream ss;
if (!EmitType(ss, mat, tint::builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, "")) {
return "";
@@ -520,7 +521,7 @@
auto name = utils::GetOrCreate(dynamic_matrix_scalar_write_, mat, [&]() -> std::string {
std::string fn;
{
- std::ostringstream ss;
+ utils::StringStream ss;
if (!EmitType(ss, mat, tint::builtin::AddressSpace::kUndefined,
builtin::Access::kUndefined, "")) {
return "";
@@ -616,7 +617,8 @@
return true;
}
-bool GeneratorImpl::EmitIndexAccessor(std::ostream& out, const ast::IndexAccessorExpression* expr) {
+bool GeneratorImpl::EmitIndexAccessor(utils::StringStream& out,
+ const ast::IndexAccessorExpression* expr) {
if (!EmitExpression(out, expr->object)) {
return false;
}
@@ -630,7 +632,7 @@
return true;
}
-bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression* expr) {
+bool GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr) {
auto* type = TypeOf(expr);
if (auto* vec = type->UnwrapRef()->As<type::Vector>()) {
type = vec->type();
@@ -698,7 +700,7 @@
return true;
}
-bool GeneratorImpl::EmitBinary(std::ostream& out, const ast::BinaryExpression* expr) {
+bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr) {
if (expr->op == ast::BinaryOp::kLogicalAnd || expr->op == ast::BinaryOp::kLogicalOr) {
auto name = UniqueIdentifier(kTempNamePrefix);
@@ -755,7 +757,7 @@
return true;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
if (!EmitExpression(out, expr->lhs)) {
return false;
@@ -873,7 +875,7 @@
return true;
}
-bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) {
+bool GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression* expr) {
auto* call = builder_.Sem().Get<sem::Call>(expr);
auto* target = call->Target();
return Switch(
@@ -888,7 +890,7 @@
});
}
-bool GeneratorImpl::EmitFunctionCall(std::ostream& out,
+bool GeneratorImpl::EmitFunctionCall(utils::StringStream& out,
const sem::Call* call,
const sem::Function* func) {
auto* expr = call->Declaration();
@@ -944,7 +946,7 @@
return true;
}
-bool GeneratorImpl::EmitBuiltinCall(std::ostream& out,
+bool GeneratorImpl::EmitBuiltinCall(utils::StringStream& out,
const sem::Call* call,
const sem::Builtin* builtin) {
const auto type = builtin->Type();
@@ -1029,7 +1031,7 @@
return true;
}
-bool GeneratorImpl::EmitValueConversion(std::ostream& out,
+bool GeneratorImpl::EmitValueConversion(utils::StringStream& out,
const sem::Call* call,
const sem::ValueConversion* conv) {
if (!EmitType(out, conv->Target(), builtin::AddressSpace::kUndefined,
@@ -1046,7 +1048,7 @@
return true;
}
-bool GeneratorImpl::EmitValueConstructor(std::ostream& out,
+bool GeneratorImpl::EmitValueConstructor(utils::StringStream& out,
const sem::Call* call,
const sem::ValueConstructor* ctor) {
auto* type = call->Type();
@@ -1110,7 +1112,7 @@
}
bool GeneratorImpl::EmitUniformBufferAccess(
- std::ostream& out,
+ utils::StringStream& out,
const ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic) {
auto const buffer = program_->Symbols().NameFor(intrinsic->buffer);
@@ -1182,7 +1184,7 @@
out << ")";
return result;
};
- auto load_u32_to = [&](std::ostream& target) {
+ auto load_u32_to = [&](utils::StringStream& target) {
target << buffer;
if (scalar_offset_constant) {
target << "[" << (scalar_offset_index / 4) << "]."
@@ -1195,7 +1197,7 @@
};
auto load_u32 = [&] { return load_u32_to(out); };
// Has a minimum alignment of 8 bytes, so is either .xy or .zw
- auto load_vec2_u32_to = [&](std::ostream& target) {
+ auto load_vec2_u32_to = [&](utils::StringStream& target) {
if (scalar_offset_constant) {
target << buffer << "[" << (scalar_offset_index / 4) << "]"
<< ((scalar_offset_index & 2) == 0 ? ".xy" : ".zw");
@@ -1398,7 +1400,7 @@
}
bool GeneratorImpl::EmitStorageBufferAccess(
- std::ostream& out,
+ utils::StringStream& out,
const ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic) {
auto const buffer = program_->Symbols().NameFor(intrinsic->buffer);
@@ -1417,7 +1419,7 @@
if (n > 1) {
out << n;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
if (!EmitExpression(out, offset)) {
return false;
}
@@ -1431,7 +1433,7 @@
// to emit `buffer.Load<float16_t>(offset)`.
auto templated_load = [&](const char* type) {
out << buffer << ".Load<" << type << ">"; // templated load
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
if (!EmitExpression(out, offset)) {
return false;
}
@@ -1483,12 +1485,12 @@
if (n > 1) {
out << n;
}
- ScopedParen sp1(out);
+ ScopedParen sp1(out.stream());
if (!EmitExpression(out, offset)) {
return false;
}
out << ", asuint";
- ScopedParen sp2(out);
+ ScopedParen sp2(out.stream());
if (!EmitExpression(out, value)) {
return false;
}
@@ -1499,7 +1501,7 @@
// to emit `buffer.Store<float16_t>(offset)`.
auto templated_store = [&](const char* type) {
out << buffer << ".Store<" << type << ">"; // templated store
- ScopedParen sp1(out);
+ ScopedParen sp1(out.stream());
if (!EmitExpression(out, offset)) {
return false;
}
@@ -1763,7 +1765,7 @@
return false;
}
-bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
+bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
std::string result = UniqueIdentifier("atomic_result");
@@ -1847,7 +1849,7 @@
out << "InterlockedExchange";
{
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
if (!EmitExpression(out, expr->args[0])) {
return false;
}
@@ -1938,11 +1940,11 @@
return false;
}
-bool GeneratorImpl::EmitSelectCall(std::ostream& out, const ast::CallExpression* expr) {
+bool GeneratorImpl::EmitSelectCall(utils::StringStream& out, const ast::CallExpression* expr) {
auto* expr_false = expr->args[0];
auto* expr_true = expr->args[1];
auto* expr_cond = expr->args[2];
- ScopedParen paren(out);
+ ScopedParen paren(out.stream());
if (!EmitExpression(out, expr_cond)) {
return false;
}
@@ -1962,7 +1964,7 @@
return true;
}
-bool GeneratorImpl::EmitModfCall(std::ostream& out,
+bool GeneratorImpl::EmitModfCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(
@@ -1995,7 +1997,7 @@
});
}
-bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
+bool GeneratorImpl::EmitFrexpCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(
@@ -2036,7 +2038,7 @@
});
}
-bool GeneratorImpl::EmitDegreesCall(std::ostream& out,
+bool GeneratorImpl::EmitDegreesCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(out, expr, builtin,
@@ -2047,7 +2049,7 @@
});
}
-bool GeneratorImpl::EmitRadiansCall(std::ostream& out,
+bool GeneratorImpl::EmitRadiansCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(out, expr, builtin,
@@ -2061,7 +2063,9 @@
// The HLSL `sign` method always returns an `int` result (scalar or vector). In WGSL the result is
// expected to be the same type as the argument. This injects a cast to the expected WGSL result
// type after the call to `sign`.
-bool GeneratorImpl::EmitSignCall(std::ostream& out, const sem::Call* call, const sem::Builtin*) {
+bool GeneratorImpl::EmitSignCall(utils::StringStream& out,
+ const sem::Call* call,
+ const sem::Builtin*) {
auto* arg = call->Arguments()[0];
if (!EmitType(out, arg->Type(), builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite,
"")) {
@@ -2075,7 +2079,7 @@
return true;
}
-bool GeneratorImpl::EmitQuantizeToF16Call(std::ostream& out,
+bool GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
// Emulate by casting to min16float and back again.
@@ -2091,7 +2095,7 @@
return true;
}
-bool GeneratorImpl::EmitDataPackingCall(std::ostream& out,
+bool GeneratorImpl::EmitDataPackingCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(
@@ -2154,7 +2158,7 @@
});
}
-bool GeneratorImpl::EmitDataUnpackingCall(std::ostream& out,
+bool GeneratorImpl::EmitDataUnpackingCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
return CallBuiltinHelper(
@@ -2221,7 +2225,7 @@
});
}
-bool GeneratorImpl::EmitDP4aCall(std::ostream& out,
+bool GeneratorImpl::EmitDP4aCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
// TODO(crbug.com/tint/1497): support the polyfill version of DP4a functions.
@@ -2249,7 +2253,7 @@
});
}
-bool GeneratorImpl::EmitBarrierCall(std::ostream& out, const sem::Builtin* builtin) {
+bool GeneratorImpl::EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin) {
// TODO(crbug.com/tint/661): Combine sequential barriers to a single
// instruction.
if (builtin->Type() == sem::BuiltinType::kWorkgroupBarrier) {
@@ -2264,7 +2268,7 @@
return true;
}
-bool GeneratorImpl::EmitTextureCall(std::ostream& out,
+bool GeneratorImpl::EmitTextureCall(utils::StringStream& out,
const sem::Call* call,
const sem::Builtin* builtin) {
using Usage = sem::ParameterUsage;
@@ -2773,7 +2777,7 @@
return true;
}
-bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) {
+bool GeneratorImpl::EmitExpression(utils::StringStream& out, const ast::Expression* expr) {
if (auto* sem = builder_.Sem().GetVal(expr)) {
if (auto* constant = sem->ConstantValue()) {
bool is_variable_initializer = false;
@@ -2802,7 +2806,8 @@
});
}
-bool GeneratorImpl::EmitIdentifier(std::ostream& out, const ast::IdentifierExpression* expr) {
+bool GeneratorImpl::EmitIdentifier(utils::StringStream& out,
+ const ast::IdentifierExpression* expr) {
out << builder_.Symbols().NameFor(expr->identifier->symbol);
return true;
}
@@ -3276,7 +3281,7 @@
return true;
}
-bool GeneratorImpl::EmitConstant(std::ostream& out,
+bool GeneratorImpl::EmitConstant(utils::StringStream& out,
const constant::Value* constant,
bool is_variable_initializer) {
return Switch(
@@ -3307,7 +3312,7 @@
[&](const type::Vector* v) {
if (constant->AllEqual()) {
{
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
if (!EmitConstant(out, constant->Index(0), is_variable_initializer)) {
return false;
}
@@ -3324,7 +3329,7 @@
return false;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
for (size_t i = 0; i < v->Width(); i++) {
if (i > 0) {
@@ -3342,7 +3347,7 @@
return false;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
for (size_t i = 0; i < m->columns(); i++) {
if (i > 0) {
@@ -3396,7 +3401,7 @@
return true;
}
- auto emit_member_values = [&](std::ostream& o) {
+ auto emit_member_values = [&](utils::StringStream& o) {
o << "{";
for (size_t i = 0; i < s->Members().Length(); i++) {
if (i > 0) {
@@ -3438,7 +3443,7 @@
});
}
-bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit) {
+bool GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit) {
return Switch(
lit,
[&](const ast::BoolLiteralExpression* l) {
@@ -3474,7 +3479,7 @@
});
}
-bool GeneratorImpl::EmitValue(std::ostream& out, const type::Type* type, int value) {
+bool GeneratorImpl::EmitValue(utils::StringStream& out, const type::Type* type, int value) {
return Switch(
type,
[&](const type::Bool*) {
@@ -3502,7 +3507,7 @@
"")) {
return false;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
for (uint32_t i = 0; i < vec->Width(); i++) {
if (i != 0) {
out << ", ";
@@ -3518,7 +3523,7 @@
"")) {
return false;
}
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
if (i != 0) {
out << ", ";
@@ -3549,7 +3554,7 @@
});
}
-bool GeneratorImpl::EmitZeroValue(std::ostream& out, const type::Type* type) {
+bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* type) {
return EmitValue(out, type, 0);
}
@@ -3598,7 +3603,7 @@
}
TextBuffer cond_pre;
- std::stringstream cond_buf;
+ utils::StringStream cond_buf;
if (auto* cond = stmt->condition) {
TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre);
if (!EmitExpression(cond_buf, cond)) {
@@ -3690,7 +3695,7 @@
bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) {
TextBuffer cond_pre;
- std::stringstream cond_buf;
+ utils::StringStream cond_buf;
{
auto* cond = stmt->condition;
TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre);
@@ -3738,7 +3743,7 @@
return true;
}
-bool GeneratorImpl::EmitMemberAccessor(std::ostream& out,
+bool GeneratorImpl::EmitMemberAccessor(utils::StringStream& out,
const ast::MemberAccessorExpression* expr) {
if (!EmitExpression(out, expr->object)) {
return false;
@@ -3911,7 +3916,7 @@
return true;
}
-bool GeneratorImpl::EmitType(std::ostream& out,
+bool GeneratorImpl::EmitType(utils::StringStream& out,
const type::Type* type,
builtin::AddressSpace address_space,
builtin::Access access,
@@ -4138,7 +4143,7 @@
});
}
-bool GeneratorImpl::EmitTypeAndName(std::ostream& out,
+bool GeneratorImpl::EmitTypeAndName(utils::StringStream& out,
const type::Type* type,
builtin::AddressSpace address_space,
builtin::Access access,
@@ -4249,7 +4254,7 @@
return true;
}
-bool GeneratorImpl::EmitUnaryOp(std::ostream& out, const ast::UnaryOpExpression* expr) {
+bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr) {
switch (expr->op) {
case ast::UnaryOp::kIndirection:
case ast::UnaryOp::kAddressOf:
@@ -4321,7 +4326,7 @@
}
template <typename F>
-bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
+bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out,
const ast::CallExpression* call,
const sem::Builtin* builtin,
F&& build) {
@@ -4377,7 +4382,7 @@
// Call the helper
out << fn;
{
- ScopedParen sp(out);
+ ScopedParen sp(out.stream());
bool first = true;
for (auto* arg : call->args) {
if (!first) {
diff --git a/src/tint/writer/hlsl/generator_impl.h b/src/tint/writer/hlsl/generator_impl.h
index 6db120c..f7adc9f 100644
--- a/src/tint/writer/hlsl/generator_impl.h
+++ b/src/tint/writer/hlsl/generator_impl.h
@@ -88,7 +88,7 @@
/// @param out the output of the expression stream
/// @param expr the expression to emit
/// @returns true if the index accessor was emitted
- bool EmitIndexAccessor(std::ostream& out, const ast::IndexAccessorExpression* expr);
+ bool EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr);
/// Handles an assignment statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
@@ -97,12 +97,12 @@
/// @param out the output of the expression stream
/// @param expr the binary expression
/// @returns true if the expression was emitted, false otherwise
- bool EmitBinary(std::ostream& out, const ast::BinaryExpression* expr);
+ bool EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr);
/// Handles generating a bitcast expression
/// @param out the output of the expression stream
/// @param expr the as expression
/// @returns true if the bitcast was emitted
- bool EmitBitcast(std::ostream& out, const ast::BitcastExpression* expr);
+ bool EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr);
/// Emits a list of statements
/// @param stmts the statement list
/// @returns true if the statements were emitted successfully
@@ -127,25 +127,29 @@
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
- bool EmitCall(std::ostream& out, const ast::CallExpression* expr);
+ bool EmitCall(utils::StringStream& out, const ast::CallExpression* expr);
/// Handles generating a function call expression
/// @param out the output of the expression stream
/// @param call the call expression
/// @param function the function being called
/// @returns true if the expression is emitted
- bool EmitFunctionCall(std::ostream& out, const sem::Call* call, const sem::Function* function);
+ bool EmitFunctionCall(utils::StringStream& out,
+ const sem::Call* call,
+ const sem::Function* function);
/// Handles generating a builtin call expression
/// @param out the output of the expression stream
/// @param call the call expression
/// @param builtin the builtin being called
/// @returns true if the expression is emitted
- bool EmitBuiltinCall(std::ostream& out, const sem::Call* call, const sem::Builtin* builtin);
+ bool EmitBuiltinCall(utils::StringStream& out,
+ const sem::Call* call,
+ const sem::Builtin* builtin);
/// Handles generating a value conversion expression
/// @param out the output of the expression stream
/// @param call the call expression
/// @param conv the value conversion
/// @returns true if the expression is emitted
- bool EmitValueConversion(std::ostream& out,
+ bool EmitValueConversion(utils::StringStream& out,
const sem::Call* call,
const sem::ValueConversion* conv);
/// Handles generating a value constructor expression
@@ -153,7 +157,7 @@
/// @param call the call expression
/// @param ctor the value constructor
/// @returns true if the expression is emitted
- bool EmitValueConstructor(std::ostream& out,
+ bool EmitValueConstructor(utils::StringStream& out,
const sem::Call* call,
const sem::ValueConstructor* ctor);
/// Handles generating a call expression to a
@@ -162,7 +166,7 @@
/// @param expr the call expression
/// @param intrinsic the transform::DecomposeMemoryAccess::Intrinsic
/// @returns true if the call expression is emitted
- bool EmitUniformBufferAccess(std::ostream& out,
+ bool EmitUniformBufferAccess(utils::StringStream& out,
const ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic);
/// Handles generating a call expression to a
@@ -171,20 +175,20 @@
/// @param expr the call expression
/// @param intrinsic the transform::DecomposeMemoryAccess::Intrinsic
/// @returns true if the call expression is emitted
- bool EmitStorageBufferAccess(std::ostream& out,
+ bool EmitStorageBufferAccess(utils::StringStream& out,
const ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic);
/// Handles generating a barrier intrinsic call
/// @param out the output of the expression stream
/// @param builtin the semantic information for the barrier builtin
/// @returns true if the call expression is emitted
- bool EmitBarrierCall(std::ostream& out, const sem::Builtin* builtin);
+ bool EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin);
/// Handles generating an atomic intrinsic call for a storage buffer variable
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param intrinsic the atomic intrinsic
/// @returns true if the call expression is emitted
- bool EmitStorageAtomicCall(std::ostream& out,
+ bool EmitStorageAtomicCall(utils::StringStream& out,
const ast::CallExpression* expr,
const transform::DecomposeMemoryAccess::Intrinsic* intrinsic);
/// Handles generating the helper function for the atomic intrinsic function
@@ -198,7 +202,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the atomic builtin
/// @returns true if the call expression is emitted
- bool EmitWorkgroupAtomicCall(std::ostream& out,
+ bool EmitWorkgroupAtomicCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to a texture function (`textureSample`,
@@ -207,18 +211,20 @@
/// @param call the call expression
/// @param builtin the semantic information for the texture builtin
/// @returns true if the call expression is emitted
- bool EmitTextureCall(std::ostream& out, const sem::Call* call, const sem::Builtin* builtin);
+ bool EmitTextureCall(utils::StringStream& out,
+ const sem::Call* call,
+ const sem::Builtin* builtin);
/// Handles generating a call to the `select()` builtin
/// @param out the output of the expression stream
/// @param expr the call expression
/// @returns true if the call expression is emitted
- bool EmitSelectCall(std::ostream& out, const ast::CallExpression* expr);
+ bool EmitSelectCall(utils::StringStream& out, const ast::CallExpression* expr);
/// Handles generating a call to the `modf()` builtin
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitModfCall(std::ostream& out,
+ bool EmitModfCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to the `frexp()` builtin
@@ -226,7 +232,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitFrexpCall(std::ostream& out,
+ bool EmitFrexpCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to the `degrees()` builtin
@@ -234,7 +240,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitDegreesCall(std::ostream& out,
+ bool EmitDegreesCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to the `radians()` builtin
@@ -242,7 +248,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitRadiansCall(std::ostream& out,
+ bool EmitRadiansCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to the `sign()` builtin
@@ -250,13 +256,13 @@
/// @param call the call semantic node
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitSignCall(std::ostream& out, const sem::Call* call, const sem::Builtin* builtin);
+ bool EmitSignCall(utils::StringStream& out, const sem::Call* call, const sem::Builtin* builtin);
/// Handles generating a call to data packing builtin
/// @param out the output of the expression stream
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitDataPackingCall(std::ostream& out,
+ bool EmitDataPackingCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to data unpacking builtin
@@ -264,7 +270,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitDataUnpackingCall(std::ostream& out,
+ bool EmitDataUnpackingCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to the `quantizeToF16()` intrinsic
@@ -272,7 +278,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitQuantizeToF16Call(std::ostream& out,
+ bool EmitQuantizeToF16Call(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles generating a call to DP4a builtins (dot4I8Packed and dot4U8Packed)
@@ -280,7 +286,7 @@
/// @param expr the call expression
/// @param builtin the semantic information for the builtin
/// @returns true if the call expression is emitted
- bool EmitDP4aCall(std::ostream& out,
+ bool EmitDP4aCall(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin);
/// Handles a case statement
@@ -300,7 +306,7 @@
/// @param out the output of the expression stream
/// @param expr the expression
/// @returns true if the expression was emitted
- bool EmitExpression(std::ostream& out, const ast::Expression* expr);
+ bool EmitExpression(utils::StringStream& out, const ast::Expression* expr);
/// Handles generating a function
/// @param func the function to generate
/// @returns true if the function was emitted
@@ -357,14 +363,14 @@
/// @param is_variable_initializer true if the constant is used as the RHS of a variable
/// initializer
/// @returns true if the constant value was successfully emitted
- bool EmitConstant(std::ostream& out,
+ bool EmitConstant(utils::StringStream& out,
const constant::Value* constant,
bool is_variable_initializer);
/// Handles a literal
/// @param out the output stream
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted
- bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit);
+ bool EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit);
/// Handles a loop statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted
@@ -381,12 +387,12 @@
/// @param out the output of the expression stream
/// @param expr the identifier expression
/// @returns true if the identifeir was emitted
- bool EmitIdentifier(std::ostream& out, const ast::IdentifierExpression* expr);
+ bool EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr);
/// Handles a member accessor expression
/// @param out the output of the expression stream
/// @param expr the member accessor expression
/// @returns true if the member accessor was emitted
- bool EmitMemberAccessor(std::ostream& out, const ast::MemberAccessorExpression* expr);
+ bool EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr);
/// Handles return statements
/// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted
@@ -412,7 +418,7 @@
/// @param name_printed (optional) if not nullptr and an array was printed
/// then the boolean is set to true.
/// @returns true if the type is emitted
- bool EmitType(std::ostream& out,
+ bool EmitType(utils::StringStream& out,
const type::Type* type,
builtin::AddressSpace address_space,
builtin::Access access,
@@ -425,7 +431,7 @@
/// @param access the access control type of the variable
/// @param name the name to emit
/// @returns true if the type is emitted
- bool EmitTypeAndName(std::ostream& out,
+ bool EmitTypeAndName(utils::StringStream& out,
const type::Type* type,
builtin::AddressSpace address_space,
builtin::Access access,
@@ -440,18 +446,18 @@
/// @param out the output of the expression stream
/// @param expr the expression to emit
/// @returns true if the expression was emitted
- bool EmitUnaryOp(std::ostream& out, const ast::UnaryOpExpression* expr);
+ bool EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr);
/// Emits `value` for the given type
/// @param out the output stream
/// @param type the type to emit the value for
/// @param value the value to emit
/// @returns true if the value was successfully emitted.
- bool EmitValue(std::ostream& out, const type::Type* type, int value);
+ bool EmitValue(utils::StringStream& out, const type::Type* type, int value);
/// Emits the zero value for the given type
/// @param out the output stream
/// @param type the type to emit the value for
/// @returns true if the zero value was successfully emitted.
- bool EmitZeroValue(std::ostream& out, const type::Type* type);
+ bool EmitZeroValue(utils::StringStream& out, const type::Type* type);
/// Handles generating a 'var' declaration
/// @param var the variable to generate
/// @returns true if the variable was emitted
@@ -541,7 +547,7 @@
/// `params` is the name of all the generated function parameters
/// @returns true if the call expression is emitted
template <typename F>
- bool CallBuiltinHelper(std::ostream& out,
+ bool CallBuiltinHelper(utils::StringStream& out,
const ast::CallExpression* call,
const sem::Builtin* builtin,
F&& build);
diff --git a/src/tint/writer/hlsl/generator_impl_array_accessor_test.cc b/src/tint/writer/hlsl/generator_impl_array_accessor_test.cc
index 73eea96..df68694 100644
--- a/src/tint/writer/hlsl/generator_impl_array_accessor_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_array_accessor_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -28,7 +29,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "ary[5]");
}
diff --git a/src/tint/writer/hlsl/generator_impl_binary_test.cc b/src/tint/writer/hlsl/generator_impl_binary_test.cc
index c99ae54..630fc09 100644
--- a/src/tint/writer/hlsl/generator_impl_binary_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_binary_test.cc
@@ -14,6 +14,7 @@
#include "src/tint/ast/call_statement.h"
#include "src/tint/ast/variable_decl_statement.h"
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -62,7 +63,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
@@ -94,7 +95,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
@@ -117,7 +118,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
@@ -145,7 +146,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), params.result);
}
@@ -182,7 +183,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(1.0f).xxx");
}
@@ -199,7 +200,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(float16_t(1.0h)).xxx");
}
@@ -214,7 +215,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(1.0f).xxx");
}
@@ -231,7 +232,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(float16_t(1.0h)).xxx");
}
@@ -246,7 +247,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(mat * 1.0f)");
}
@@ -263,7 +264,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(mat * float16_t(1.0h))");
}
@@ -278,7 +279,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(1.0f * mat)");
}
@@ -295,7 +296,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(float16_t(1.0h) * mat)");
}
@@ -310,7 +311,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul((1.0f).xxx, mat)");
}
@@ -327,7 +328,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul((float16_t(1.0h)).xxx, mat)");
}
@@ -342,7 +343,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(mat, (1.0f).xxx)");
}
@@ -359,7 +360,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(mat, (float16_t(1.0h)).xxx)");
}
@@ -373,7 +374,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(rhs, lhs)");
}
@@ -389,7 +390,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "mul(rhs, lhs)");
}
@@ -403,7 +404,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
@@ -428,7 +429,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = a;
@@ -455,7 +456,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error();
EXPECT_EQ(out.str(), "(tint_tmp)");
EXPECT_EQ(gen.result(), R"(bool tint_tmp = a;
diff --git a/src/tint/writer/hlsl/generator_impl_bitcast_test.cc b/src/tint/writer/hlsl/generator_impl_bitcast_test.cc
index 5c4b9cc..3061fbe7 100644
--- a/src/tint/writer/hlsl/generator_impl_bitcast_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_bitcast_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -28,7 +29,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asfloat(a)");
}
@@ -40,7 +41,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asint(a)");
}
@@ -52,7 +53,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.error();
EXPECT_EQ(out.str(), "asuint(a)");
}
diff --git a/src/tint/writer/hlsl/generator_impl_builtin_test.cc b/src/tint/writer/hlsl/generator_impl_builtin_test.cc
index 3dbbe7d..229213b 100644
--- a/src/tint/writer/hlsl/generator_impl_builtin_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_builtin_test.cc
@@ -16,6 +16,7 @@
#include "src/tint/ast/call_statement.h"
#include "src/tint/ast/stage_attribute.h"
#include "src/tint/sem/call.h"
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using ::testing::HasSubstr;
@@ -64,8 +65,8 @@
CallParamType type,
ProgramBuilder* builder) {
std::string name;
- std::ostringstream str(name);
- str << builtin;
+ utils::StringStream str;
+ str << name << builtin;
switch (builtin) {
case BuiltinType::kAcos:
case BuiltinType::kAsin:
@@ -347,7 +348,7 @@
GeneratorImpl& gen = Build();
gen.increment_indent();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "dot(param1, param2)");
}
@@ -360,7 +361,7 @@
GeneratorImpl& gen = Build();
gen.increment_indent();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "(true ? b : a)");
}
@@ -373,7 +374,7 @@
GeneratorImpl& gen = Build();
gen.increment_indent();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "(bool2(true, false) ? b : a)");
}
diff --git a/src/tint/writer/hlsl/generator_impl_call_test.cc b/src/tint/writer/hlsl/generator_impl_call_test.cc
index 9947a08..50909bb 100644
--- a/src/tint/writer/hlsl/generator_impl_call_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_call_test.cc
@@ -13,6 +13,7 @@
// limitations under the License.
#include "src/tint/ast/call_statement.h"
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -30,7 +31,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "my_func()");
}
@@ -50,7 +51,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.error();
EXPECT_EQ(out.str(), "my_func(param1, param2)");
}
diff --git a/src/tint/writer/hlsl/generator_impl_cast_test.cc b/src/tint/writer/hlsl/generator_impl_cast_test.cc
index 4c522a3..7bb77da 100644
--- a/src/tint/writer/hlsl/generator_impl_cast_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_cast_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -27,7 +28,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
EXPECT_EQ(out.str(), "1.0f");
}
@@ -38,7 +39,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.error();
EXPECT_EQ(out.str(), "float3(1.0f, 2.0f, 3.0f)");
}
diff --git a/src/tint/writer/hlsl/generator_impl_identifier_test.cc b/src/tint/writer/hlsl/generator_impl_identifier_test.cc
index 1e2b47b..db09c45 100644
--- a/src/tint/writer/hlsl/generator_impl_identifier_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_identifier_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
namespace tint::writer::hlsl {
@@ -27,7 +28,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, i)) << gen.error();
EXPECT_EQ(out.str(), "foo");
}
diff --git a/src/tint/writer/hlsl/generator_impl_import_test.cc b/src/tint/writer/hlsl/generator_impl_import_test.cc
index 425c663..28b72dc 100644
--- a/src/tint/writer/hlsl/generator_impl_import_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_import_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using namespace tint::number_suffixes; // NOLINT
@@ -39,7 +40,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f)");
}
@@ -77,7 +78,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1)");
}
@@ -94,7 +95,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(),
std::string(param.hlsl_name) + "(float3(0.100000001f, 0.200000003f, 0.300000012f))");
@@ -134,7 +135,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f, 2.0f)");
}
@@ -156,7 +157,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) +
"(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f))");
@@ -181,7 +182,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1, 2)");
}
@@ -199,7 +200,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1.0f, 2.0f, 3.0f)");
}
@@ -220,7 +221,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(
out.str(),
@@ -243,7 +244,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string(param.hlsl_name) + "(1, 2, 3)");
}
@@ -259,7 +260,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("determinant(var)"));
}
@@ -272,7 +273,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("float(min16float(v))"));
}
@@ -285,7 +286,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("float3(min16float3(v))"));
}
diff --git a/src/tint/writer/hlsl/generator_impl_type_test.cc b/src/tint/writer/hlsl/generator_impl_type_test.cc
index 71fe338..4ee8a22 100644
--- a/src/tint/writer/hlsl/generator_impl_type_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_type_test.cc
@@ -21,6 +21,7 @@
#include "src/tint/type/sampler.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/type/texture_dimension.h"
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
using ::testing::HasSubstr;
@@ -38,7 +39,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, "ary"))
<< gen.error();
@@ -51,7 +52,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, "ary"))
<< gen.error();
@@ -64,7 +65,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, "ary"))
<< gen.error();
@@ -77,7 +78,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -89,7 +90,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, bool_, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -101,7 +102,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, f16, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -113,7 +114,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, f32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -125,7 +126,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, i32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -139,7 +140,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -153,7 +154,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -203,7 +204,7 @@
GeneratorImpl& gen = Build();
auto* sem_s = program->TypeOf(s)->As<sem::Struct>();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, sem_s, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -251,7 +252,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, u32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -264,7 +265,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, vec3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -276,7 +277,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, void_, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -288,7 +289,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -300,7 +301,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined,
builtin::Access::kReadWrite, ""))
<< gen.error();
@@ -511,7 +512,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(
gen.EmitType(out, s, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""))
<< gen.error();
diff --git a/src/tint/writer/hlsl/generator_impl_unary_op_test.cc b/src/tint/writer/hlsl/generator_impl_unary_op_test.cc
index 4bf4329..1ac6851 100644
--- a/src/tint/writer/hlsl/generator_impl_unary_op_test.cc
+++ b/src/tint/writer/hlsl/generator_impl_unary_op_test.cc
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "src/tint/utils/string_stream.h"
#include "src/tint/writer/hlsl/test_helper.h"
namespace tint::writer::hlsl {
@@ -26,7 +27,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "expr");
}
@@ -38,7 +39,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "~(expr)");
}
@@ -51,7 +52,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "expr");
}
@@ -63,7 +64,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "!(expr)");
}
@@ -75,7 +76,7 @@
GeneratorImpl& gen = Build();
- std::stringstream out;
+ utils::StringStream out;
ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error();
EXPECT_EQ(out.str(), "-(expr)");
}