Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ import Base: show_unquoted
using Base: printstyled, with_output_color, prec_decl, @invoke

function Base.show(io::IO, cfg::CFG)
print(io, "CFG with $(length(cfg.blocks)) blocks:")
for (idx, block) in enumerate(cfg.blocks)
print(io, idx, "\t=>\t")
join(io, block.succs, ", ")
println(io)
print(io, "\n bb ", idx)
if block.stmts.start == block.stmts.stop
print(io, " (stmt ", block.stmts.start, ")")
else
print(io, " (stmts ", block.stmts.start, ":", block.stmts.stop, ")")
end
if !isempty(block.succs)
print(io, " → bb ")
join(io, block.succs, ", ")
end
end
end

Expand Down
14 changes: 14 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2516,3 +2516,17 @@ end
ir = Core.Compiler.complete(compact)
verify_display(ir)
end

@testset "IRCode: CFG display" begin
# get a cfg
function foo(i)
j = i+42
j == 1 ? 1 : 2
end
ir = only(Base.code_ircode(foo, (Int,)))[1]
cfg = ir.cfg

str = sprint(io->show(io, cfg))
@test contains(str, r"CFG with \d+ blocks")
@test contains(str, r"bb 1 \(stmt.+\) → bb.*")
end