Skip to content

Julia 1.11: add ssaflags to Canvas #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/CodeInfoTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ struct Canvas
defs::Vector{Tuple{Int, Int}}
code::Vector{Any}
codelocs::Vector{Int32}
ssaflags::Vector{UInt32}
end
Canvas() = Canvas(Tuple{Int, Int}[], [], Int32[])
Canvas() = Canvas(Tuple{Int, Int}[], [], Int32[], UInt32[])

Base.isempty(canv::Canvas) = Base.isempty(canv.defs)

Expand Down Expand Up @@ -193,6 +194,7 @@ getindex(c::Canvas, v::Variable) = getindex(c, v.id)
function push!(c::Canvas, stmt::Statement)
push!(c.code, stmt)
push!(c.codelocs, Int32(1))
push!(c.ssaflags, UInt32(0))
l = length(c.defs) + 1
push!(c.defs, (l, l))
return Variable(length(c.defs))
Expand All @@ -201,6 +203,7 @@ end
function push!(c::Canvas, node)
push!(c.code, Statement(node))
push!(c.codelocs, Int32(1))
push!(c.ssaflags, UInt32(0))
l = length(c.defs) + 1
push!(c.defs, (l, l))
return Variable(length(c.defs))
Expand All @@ -211,6 +214,7 @@ function insert!(c::Canvas, idx::Int, x::Statement)
@assert(ind > 0)
push!(c.code, x)
push!(c.codelocs, Int32(1))
push!(c.ssaflags, UInt32(0))
for i in 1 : length(c.defs)
r, k = c.defs[i]
if k > 0 && k >= ind
Expand Down Expand Up @@ -290,7 +294,7 @@ function renumber(c::Canvas)
ind = first.(s)
swap = walk(k -> _get(d, k, k), c.code, Val(:catch_jumps))
return Canvas(Tuple{Int, Int}[(i, i) for i in 1 : length(s)],
getindex(swap, ind), getindex(c.codelocs, ind))
getindex(swap, ind), getindex(c.codelocs, ind), getindex(c.ssaflags, ind))
end

#####
Expand Down Expand Up @@ -512,6 +516,7 @@ function finish(b::Builder; validate = true)
c = renumber(b.to)
new_ci.code = map(unwrap, c.code)
new_ci.codelocs = c.codelocs
new_ci.ssaflags = c.ssaflags
new_ci.slotnames = copy(b.from.slotnames)
append!(new_ci.slotnames, b.slots)
new_ci.slotflags = copy(b.from.slotflags)
Expand Down
1 change: 1 addition & 0 deletions test/canvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
for i in 1 : 5
@test c.defs[i] == (i, i)
@test c.codelocs[i] == Int32(1)
@test c.ssaflags[i] == UInt32(0)
@test unwrap(getindex(c, i)) == Expr(:call, rand)
end
end
Expand Down