Convert IR over to `utils::StringStream`.
This Cl updates the IR to use the `utils::StringStream` instead of `std::stringstream`. Bug: tint:1686 Change-Id: Iee9063db554bc75e7a730a8629d7f3403ff1a190 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121860 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
7ca41fffb7
commit
a4637ad8a3
|
@ -29,7 +29,7 @@ Binary::Binary(Kind kind, Value* result, Value* lhs, Value* rhs)
|
|||
|
||||
Binary::~Binary() = default;
|
||||
|
||||
std::ostream& Binary::ToString(std::ostream& out, const SymbolTable& st) const {
|
||||
utils::StringStream& Binary::ToString(utils::StringStream& out, const SymbolTable& st) const {
|
||||
Result()->ToString(out, st) << " = ";
|
||||
lhs_->ToString(out, st) << " ";
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/tint/ir/instruction.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/type/type.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -79,7 +80,7 @@ class Binary : public Castable<Binary, Instruction> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
std::ostream& ToString(std::ostream& out, const SymbolTable& st) const override;
|
||||
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override;
|
||||
|
||||
private:
|
||||
Kind kind_;
|
||||
|
@ -87,8 +88,6 @@ class Binary : public Castable<Binary, Instruction> {
|
|||
Value* rhs_ = nullptr;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Binary&);
|
||||
|
||||
} // namespace tint::ir
|
||||
|
||||
#endif // SRC_TINT_IR_BINARY_H_
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "src/tint/ir/instruction.h"
|
||||
#include "src/tint/ir/test_helper.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
@ -47,7 +48,7 @@ TEST_F(IR_InstructionTest, CreateAnd) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 & 2");
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ TEST_F(IR_InstructionTest, CreateOr) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 | 2");
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ TEST_F(IR_InstructionTest, CreateXor) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 ^ 2");
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ TEST_F(IR_InstructionTest, CreateLogicalAnd) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 && 2");
|
||||
}
|
||||
|
@ -155,7 +156,7 @@ TEST_F(IR_InstructionTest, CreateLogicalOr) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 || 2");
|
||||
}
|
||||
|
@ -182,7 +183,7 @@ TEST_F(IR_InstructionTest, CreateEqual) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 == 2");
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ TEST_F(IR_InstructionTest, CreateNotEqual) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 != 2");
|
||||
}
|
||||
|
@ -236,7 +237,7 @@ TEST_F(IR_InstructionTest, CreateLessThan) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 < 2");
|
||||
}
|
||||
|
@ -263,7 +264,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThan) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 > 2");
|
||||
}
|
||||
|
@ -290,7 +291,7 @@ TEST_F(IR_InstructionTest, CreateLessThanEqual) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 <= 2");
|
||||
}
|
||||
|
@ -317,7 +318,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (bool) = 4 >= 2");
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ TEST_F(IR_InstructionTest, CreateShiftLeft) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 << 2");
|
||||
}
|
||||
|
@ -371,7 +372,7 @@ TEST_F(IR_InstructionTest, CreateShiftRight) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 >> 2");
|
||||
}
|
||||
|
@ -398,7 +399,7 @@ TEST_F(IR_InstructionTest, CreateAdd) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 + 2");
|
||||
}
|
||||
|
@ -425,7 +426,7 @@ TEST_F(IR_InstructionTest, CreateSubtract) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 - 2");
|
||||
}
|
||||
|
@ -452,7 +453,7 @@ TEST_F(IR_InstructionTest, CreateMultiply) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 * 2");
|
||||
}
|
||||
|
@ -479,7 +480,7 @@ TEST_F(IR_InstructionTest, CreateDivide) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 / 2");
|
||||
}
|
||||
|
@ -506,7 +507,7 @@ TEST_F(IR_InstructionTest, CreateModulo) {
|
|||
ASSERT_TRUE(rhs->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = 4 % 2");
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ Bitcast::Bitcast(Value* result, Value* val) : Base(result), val_(val) {
|
|||
|
||||
Bitcast::~Bitcast() = default;
|
||||
|
||||
std::ostream& Bitcast::ToString(std::ostream& out, const SymbolTable& st) const {
|
||||
utils::StringStream& Bitcast::ToString(utils::StringStream& out, const SymbolTable& st) const {
|
||||
Result()->ToString(out, st);
|
||||
out << " = bitcast(";
|
||||
val_->ToString(out, st);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "src/tint/ir/instruction.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/type/type.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -45,14 +46,12 @@ class Bitcast : public Castable<Bitcast, Instruction> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
std::ostream& ToString(std::ostream& out, const SymbolTable& st) const override;
|
||||
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override;
|
||||
|
||||
private:
|
||||
Value* val_ = nullptr;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Bitcast&);
|
||||
|
||||
} // namespace tint::ir
|
||||
|
||||
#endif // SRC_TINT_IR_BITCAST_H_
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "src/tint/ir/instruction.h"
|
||||
#include "src/tint/ir/test_helper.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
@ -40,7 +41,7 @@ TEST_F(IR_InstructionTest, Bitcast) {
|
|||
ASSERT_TRUE(val->Is<constant::Scalar<i32>>());
|
||||
EXPECT_EQ(4_i, val->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
instr->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ(str.str(), "%42 (i32) = bitcast(4)");
|
||||
}
|
||||
|
|
|
@ -1836,8 +1836,8 @@ TEST_F(IR_BuilderImplTest, EmitExpression_Binary_Compound) {
|
|||
EXPECT_EQ(d.AsString(), R"(%1 (u32) = 3 >> 4
|
||||
%2 (u32) = %1 (u32) + 9
|
||||
%3 (bool) = 1 < %2 (u32)
|
||||
%4 (f32) = 2.3 * 5.5
|
||||
%5 (f32) = 6.7 / %4 (f32)
|
||||
%4 (f32) = 2.299999952 * 5.5
|
||||
%5 (f32) = 6.699999809 / %4 (f32)
|
||||
%6 (bool) = 2.5 > %5 (f32)
|
||||
%7 (bool) = %3 (bool) && %6 (bool)
|
||||
)");
|
||||
|
|
|
@ -28,7 +28,7 @@ Constant::Constant(const constant::Value* val) : value(val) {}
|
|||
|
||||
Constant::~Constant() = default;
|
||||
|
||||
std::ostream& Constant::ToString(std::ostream& out, const SymbolTable& st) const {
|
||||
utils::StringStream& Constant::ToString(utils::StringStream& out, const SymbolTable& st) const {
|
||||
std::function<void(const constant::Value*)> emit = [&](const constant::Value* c) {
|
||||
Switch(
|
||||
c,
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "src/tint/constant/value.h"
|
||||
#include "src/tint/ir/value.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -38,7 +39,7 @@ class Constant : public Castable<Constant, Value> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
std::ostream& ToString(std::ostream& out, const SymbolTable& st) const override;
|
||||
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override;
|
||||
|
||||
/// The constants value
|
||||
const constant::Value* const value;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "src/tint/ir/test_helper.h"
|
||||
#include "src/tint/ir/value.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
@ -27,13 +28,13 @@ using IR_ConstantTest = TestHelper;
|
|||
TEST_F(IR_ConstantTest, f32) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
|
||||
auto* c = b.builder.Constant(1.2_f);
|
||||
EXPECT_EQ(1.2_f, c->value->As<constant::Scalar<f32>>()->ValueAs<f32>());
|
||||
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("1.2", str.str());
|
||||
EXPECT_EQ("1.200000048", str.str());
|
||||
|
||||
EXPECT_TRUE(c->value->Is<constant::Scalar<f32>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f16>>());
|
||||
|
@ -45,13 +46,13 @@ TEST_F(IR_ConstantTest, f32) {
|
|||
TEST_F(IR_ConstantTest, f16) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
|
||||
auto* c = b.builder.Constant(1.1_h);
|
||||
EXPECT_EQ(1.1_h, c->value->As<constant::Scalar<f16>>()->ValueAs<f16>());
|
||||
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("1.09961", str.str());
|
||||
EXPECT_EQ("1.099609375", str.str());
|
||||
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
|
||||
EXPECT_TRUE(c->value->Is<constant::Scalar<f16>>());
|
||||
|
@ -63,7 +64,7 @@ TEST_F(IR_ConstantTest, f16) {
|
|||
TEST_F(IR_ConstantTest, i32) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
|
||||
auto* c = b.builder.Constant(1_i);
|
||||
EXPECT_EQ(1_i, c->value->As<constant::Scalar<i32>>()->ValueAs<i32>());
|
||||
|
@ -81,7 +82,7 @@ TEST_F(IR_ConstantTest, i32) {
|
|||
TEST_F(IR_ConstantTest, u32) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
|
||||
auto* c = b.builder.Constant(2_u);
|
||||
EXPECT_EQ(2_u, c->value->As<constant::Scalar<u32>>()->ValueAs<u32>());
|
||||
|
@ -99,26 +100,30 @@ TEST_F(IR_ConstantTest, u32) {
|
|||
TEST_F(IR_ConstantTest, bool) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
{
|
||||
utils::StringStream str;
|
||||
|
||||
auto* c = b.builder.Constant(false);
|
||||
EXPECT_FALSE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
|
||||
auto* c = b.builder.Constant(false);
|
||||
EXPECT_FALSE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
|
||||
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("false", str.str());
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("false", str.str());
|
||||
}
|
||||
|
||||
str.str("");
|
||||
c = b.builder.Constant(true);
|
||||
EXPECT_TRUE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
|
||||
{
|
||||
utils::StringStream str;
|
||||
auto c = b.builder.Constant(true);
|
||||
EXPECT_TRUE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
|
||||
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("true", str.str());
|
||||
c->ToString(str, b.builder.ir.symbols);
|
||||
EXPECT_EQ("true", str.str());
|
||||
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f16>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<i32>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<u32>>());
|
||||
EXPECT_TRUE(c->value->Is<constant::Scalar<bool>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<f16>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<i32>>());
|
||||
EXPECT_FALSE(c->value->Is<constant::Scalar<u32>>());
|
||||
EXPECT_TRUE(c->value->Is<constant::Scalar<bool>>());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/tint/ir/loop.h"
|
||||
#include "src/tint/ir/switch.h"
|
||||
#include "src/tint/ir/terminator.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -33,7 +34,7 @@ std::string Debug::AsDotGraph(const Module* mod) {
|
|||
std::unordered_set<const FlowNode*> visited;
|
||||
std::unordered_set<const FlowNode*> merge_nodes;
|
||||
std::unordered_map<const FlowNode*, std::string> node_to_name;
|
||||
std::stringstream out;
|
||||
utils::StringStream out;
|
||||
|
||||
auto name_for = [&](const FlowNode* node) -> std::string {
|
||||
if (node_to_name.count(node) > 0) {
|
||||
|
|
|
@ -53,7 +53,7 @@ Disassembler::Disassembler(const Module& mod) : mod_(mod) {}
|
|||
|
||||
Disassembler::~Disassembler() = default;
|
||||
|
||||
std::ostream& Disassembler::Indent() {
|
||||
utils::StringStream& Disassembler::Indent() {
|
||||
for (uint32_t i = 0; i < indent_size_; i++) {
|
||||
out_ << " ";
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "src/tint/ir/flow_node.h"
|
||||
#include "src/tint/ir/module.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -45,12 +46,12 @@ class Disassembler {
|
|||
std::string AsString() const { return out_.str(); }
|
||||
|
||||
private:
|
||||
std::ostream& Indent();
|
||||
utils::StringStream& Indent();
|
||||
void Walk(const FlowNode* node);
|
||||
size_t GetIdForNode(const FlowNode* node);
|
||||
|
||||
const Module& mod_;
|
||||
std::stringstream out_;
|
||||
utils::StringStream out_;
|
||||
std::unordered_set<const FlowNode*> visited_;
|
||||
std::unordered_set<const FlowNode*> stop_nodes_;
|
||||
std::unordered_map<const FlowNode*, size_t> flow_node_to_id_;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "src/tint/castable.h"
|
||||
#include "src/tint/ir/value.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -41,7 +42,8 @@ class Instruction : public Castable<Instruction> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
virtual std::ostream& ToString(std::ostream& out, const SymbolTable& st) const = 0;
|
||||
virtual utils::StringStream& ToString(utils::StringStream& out,
|
||||
const SymbolTable& st) const = 0;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
|
|
|
@ -24,7 +24,7 @@ Temp::Temp(const type::Type* type, Id id) : type_(type), id_(id) {}
|
|||
|
||||
Temp::~Temp() = default;
|
||||
|
||||
std::ostream& Temp::ToString(std::ostream& out, const SymbolTable& st) const {
|
||||
utils::StringStream& Temp::ToString(utils::StringStream& out, const SymbolTable& st) const {
|
||||
out << "%" << std::to_string(AsId()) << " (" << type_->FriendlyName(st) << ")";
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "src/tint/ir/value.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
|
||||
|
@ -52,7 +53,7 @@ class Temp : public Castable<Temp, Value> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
std::ostream& ToString(std::ostream& out, const SymbolTable& st) const override;
|
||||
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override;
|
||||
|
||||
private:
|
||||
const type::Type* type_ = nullptr;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "src/tint/ir/temp.h"
|
||||
#include "src/tint/ir/test_helper.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
|
||||
namespace tint::ir {
|
||||
namespace {
|
||||
|
@ -27,7 +28,7 @@ using IR_TempTest = TestHelper;
|
|||
TEST_F(IR_TempTest, id) {
|
||||
auto& b = CreateEmptyBuilder();
|
||||
|
||||
std::stringstream str;
|
||||
utils::StringStream str;
|
||||
|
||||
b.builder.next_temp_id = Temp::Id(4);
|
||||
auto* val = b.builder.Temp(b.builder.ir.types.Get<type::I32>());
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "src/tint/castable.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
#include "src/tint/type/type.h"
|
||||
#include "src/tint/utils/string_stream.h"
|
||||
#include "src/tint/utils/unique_vector.h"
|
||||
|
||||
// Forward declarations
|
||||
|
@ -56,7 +57,8 @@ class Value : public Castable<Value> {
|
|||
/// @param out the stream to write to
|
||||
/// @param st the symbol table
|
||||
/// @returns the stream
|
||||
virtual std::ostream& ToString(std::ostream& out, const SymbolTable& st) const = 0;
|
||||
virtual utils::StringStream& ToString(utils::StringStream& out,
|
||||
const SymbolTable& st) const = 0;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
|
|
|
@ -25,12 +25,6 @@ namespace {
|
|||
|
||||
using StringStreamTest = testing::Test;
|
||||
|
||||
TEST_F(StringStreamTest, Endl) {
|
||||
StringStream s;
|
||||
s << std::endl;
|
||||
EXPECT_EQ(s.str(), "\n");
|
||||
}
|
||||
|
||||
TEST_F(StringStreamTest, Zero) {
|
||||
StringStream s;
|
||||
s << 0.0f;
|
||||
|
|
Loading…
Reference in New Issue