diff --git a/toolchain/check/BUILD b/toolchain/check/BUILD index 0f7f755b4780..1250f96fa9ef 100644 --- a/toolchain/check/BUILD +++ b/toolchain/check/BUILD @@ -205,7 +205,6 @@ cc_library( "//common:vlog", "//toolchain/parse:node_kind", "//toolchain/parse:tree", - "//toolchain/sem_ir:formatter", "//toolchain/sem_ir:ids", "@llvm-project//llvm:Support", ], diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 219ed62b1e59..ecdfdb937951 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -1314,12 +1314,11 @@ auto Context::PrintForStackDump(llvm::raw_ostream& output) const -> void { // spaces then add a couple to indent past the Context label. constexpr int Indent = 10; - SemIR::Formatter formatter(*tokens_, *parse_tree_, *sem_ir_); - node_stack_.PrintForStackDump(formatter, Indent, output); - inst_block_stack_.PrintForStackDump(formatter, Indent, output); - pattern_block_stack_.PrintForStackDump(formatter, Indent, output); - param_and_arg_refs_stack_.PrintForStackDump(formatter, Indent, output); - args_type_info_stack_.PrintForStackDump(formatter, Indent, output); + node_stack_.PrintForStackDump(Indent, output); + inst_block_stack_.PrintForStackDump(Indent, output); + pattern_block_stack_.PrintForStackDump(Indent, output); + param_and_arg_refs_stack_.PrintForStackDump(Indent, output); + args_type_info_stack_.PrintForStackDump(Indent, output); } auto Context::DumpFormattedFile() const -> void { diff --git a/toolchain/check/inst_block_stack.cpp b/toolchain/check/inst_block_stack.cpp index d225c05383cb..4b47d0891396 100644 --- a/toolchain/check/inst_block_stack.cpp +++ b/toolchain/check/inst_block_stack.cpp @@ -61,17 +61,19 @@ auto InstBlockStack::PopAndDiscard() -> void { CARBON_VLOG("{0} PopAndDiscard {1}\n", name_, id_stack_.size()); } -auto InstBlockStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, +auto InstBlockStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void { output.indent(indent); output << name_ << ":\n"; for (const auto& [i, id] : llvm::enumerate(id_stack_)) { output.indent(indent + 2); - output << i << ". " << id; - formatter.PrintPartialTrailingCodeBlock(insts_stack_.PeekArrayAt(i), - indent + 4, output); - output << "\n"; + output << i << ".\t" << id << "\t{"; + llvm::ListSeparator sep; + for (auto id : insts_stack_.PeekArrayAt(i)) { + output << sep << id; + } + output << "}\n"; } } diff --git a/toolchain/check/inst_block_stack.h b/toolchain/check/inst_block_stack.h index df718a099a92..6e047bb7c6d7 100644 --- a/toolchain/check/inst_block_stack.h +++ b/toolchain/check/inst_block_stack.h @@ -70,8 +70,7 @@ class InstBlockStack { } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void; + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void; // Runs verification that the processing cleanly finished. auto VerifyOnFinish() const -> void { diff --git a/toolchain/check/node_stack.cpp b/toolchain/check/node_stack.cpp index 3d7ca19cecdd..e4123f94a6a3 100644 --- a/toolchain/check/node_stack.cpp +++ b/toolchain/check/node_stack.cpp @@ -8,19 +8,15 @@ namespace Carbon::Check { -auto NodeStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void { +auto NodeStack::PrintForStackDump(int indent, llvm::raw_ostream& output) const + -> void { auto print_id = [&](Id id) { if constexpr (Kind == Id::Kind::None) { - output << "no value\n"; + output << "no value"; } else if constexpr (Kind == Id::Kind::Invalid) { CARBON_FATAL("Should not be in node stack"); - } else if constexpr (Kind == Id::KindFor()) { - output << "\n"; - formatter.PrintInst(id.As()>(), indent + 4, - output); } else { - output << id.As() << "\n"; + output << id.As(); } }; @@ -37,6 +33,7 @@ auto NodeStack::PrintForStackDump(SemIR::Formatter& formatter, int indent, break; #include "toolchain/parse/node_kind.def" } + output << "\n"; } } diff --git a/toolchain/check/node_stack.h b/toolchain/check/node_stack.h index 86aae588c8ea..04070d66b547 100644 --- a/toolchain/check/node_stack.h +++ b/toolchain/check/node_stack.h @@ -11,7 +11,6 @@ #include "toolchain/parse/node_kind.h" #include "toolchain/parse/tree.h" #include "toolchain/parse/typed_nodes.h" -#include "toolchain/sem_ir/formatter.h" #include "toolchain/sem_ir/id_kind.h" #include "toolchain/sem_ir/ids.h" @@ -335,8 +334,7 @@ class NodeStack { } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void; + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void; auto empty() const -> bool { return stack_.empty(); } auto size() const -> size_t { return stack_.size(); } diff --git a/toolchain/check/param_and_arg_refs_stack.h b/toolchain/check/param_and_arg_refs_stack.h index 1905926572b1..44b28e931d41 100644 --- a/toolchain/check/param_and_arg_refs_stack.h +++ b/toolchain/check/param_and_arg_refs_stack.h @@ -72,9 +72,8 @@ class ParamAndArgRefsStack { auto VerifyOnFinish() -> void { stack_.VerifyOnFinish(); } // Prints the stack for a stack dump. - auto PrintForStackDump(SemIR::Formatter& formatter, int indent, - llvm::raw_ostream& output) const -> void { - return stack_.PrintForStackDump(formatter, indent, output); + auto PrintForStackDump(int indent, llvm::raw_ostream& output) const -> void { + return stack_.PrintForStackDump(indent, output); } private: diff --git a/toolchain/sem_ir/formatter.cpp b/toolchain/sem_ir/formatter.cpp index 02f8a68beb4e..67901006868d 100644 --- a/toolchain/sem_ir/formatter.cpp +++ b/toolchain/sem_ir/formatter.cpp @@ -78,34 +78,6 @@ class FormatterImpl { out_ << "\n"; } - // Prints a code block. - auto FormatPartialTrailingCodeBlock(llvm::ArrayRef block) - -> void { - out_ << ' '; - OpenBrace(); - constexpr int NumPrintedOnSkip = 9; - // Avoid only skipping one item. - if (block.size() > NumPrintedOnSkip + 1) { - Indent(); - out_ << "... skipping " << (block.size() - NumPrintedOnSkip) - << " insts ...\n"; - block = block.take_back(NumPrintedOnSkip); - } - FormatCodeBlock(block); - CloseBrace(); - } - - // Prints a single instruction. - auto FormatInst(InstId inst_id) -> void { - if (!inst_id.is_valid()) { - Indent(); - out_ << "invalid\n"; - return; - } - - FormatInst(inst_id, sem_ir_.insts().Get(inst_id)); - } - private: enum class AddSpace : bool { Before, After }; @@ -560,6 +532,17 @@ class FormatterImpl { } } + // Prints a single instruction. + auto FormatInst(InstId inst_id) -> void { + if (!inst_id.is_valid()) { + Indent(); + out_ << "invalid\n"; + return; + } + + FormatInst(inst_id, sem_ir_.insts().Get(inst_id)); + } + auto FormatInst(InstId inst_id, Inst inst) -> void { CARBON_KIND_SWITCH(inst) { #define CARBON_SEM_IR_INST_KIND(InstT) \ @@ -1180,17 +1163,4 @@ auto Formatter::Print(llvm::raw_ostream& out) -> void { formatter.Format(); } -auto Formatter::PrintPartialTrailingCodeBlock( - llvm::ArrayRef block, int indent, llvm::raw_ostream& out) - -> void { - FormatterImpl formatter(sem_ir_, &inst_namer_, out, indent); - formatter.FormatPartialTrailingCodeBlock(block); -} - -auto Formatter::PrintInst(SemIR::InstId inst_id, int indent, - llvm::raw_ostream& out) -> void { - FormatterImpl formatter(sem_ir_, &inst_namer_, out, indent); - formatter.FormatInst(inst_id); -} - } // namespace Carbon::SemIR diff --git a/toolchain/sem_ir/formatter.h b/toolchain/sem_ir/formatter.h index 7a2ff326159b..82dc0053d2fb 100644 --- a/toolchain/sem_ir/formatter.h +++ b/toolchain/sem_ir/formatter.h @@ -22,14 +22,6 @@ class Formatter { // Prints the full IR. auto Print(llvm::raw_ostream& out) -> void; - // Prints a single code block. Only prints the last several instructions of - // large blocks. - auto PrintPartialTrailingCodeBlock(llvm::ArrayRef block, - int indent, llvm::raw_ostream& out) - -> void; - // Prints a single instruction. - auto PrintInst(SemIR::InstId inst_id, int indent, llvm::raw_ostream& out) - -> void; private: const File& sem_ir_;