Skip to content

Commit 1f0968c

Browse files
committed
move LineInfoNode definition in IRTools
1 parent dd1aa0d commit 1f0968c

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/ir/ir.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
using Base.IRShow: LineInfoNode
21
import Base: push!, insert!, getindex, setindex!, iterate, length
32

43
# We have our own versions of these in order to
54
# (1) be more robust to Base IR changes, and
65
# (2) make sure that mistakes/bugs do not cause bad LLVM IR.
76

7+
"""
8+
LineInfoNode(file::Symbol, line::Int32, [inlined_at::Int32])
9+
10+
Represents line information about a statement; Inlined statements has a non-zero
11+
`inlined_at` which represents the "parent" location in the linetable array.
12+
"""
13+
struct LineInfoNode
14+
file::Symbol
15+
line::Int32
16+
inlined_at::Int32
17+
end
18+
LineInfoNode(file, line) = LineInfoNode(file, line, Int32(0))
19+
820
struct Undefined end
921
const undef = Undefined()
1022

src/ir/wrap.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@ using MacroTools: isexpr, prewalk
44

55
using ..Inner, ..IRTools
66
import ..Inner: IR, Variable, Statement, Branch, BasicBlock, Meta, block!,
7-
unreachable, varmap, argument!, branch!, return!
7+
unreachable, varmap, argument!, branch!, return!, LineInfoNode
88
import Core: CodeInfo, GotoNode, SSAValue
99
import Core.Compiler: IRCode, CFG, GotoIfNot, ReturnNode, StmtRange
1010

1111
@static if VERSION > v"1.6-"
1212
import Core.Compiler: InstructionStream
1313
end
1414

15-
unvars(ex) = prewalk(x -> x isa Variable ? SSAValue(x.id) : x, ex)
16-
15+
@static if VERSION v"1.9.0-DEV.502"
16+
const LineType = Int32
17+
else
18+
const LineType = Int
19+
end
1720

1821
@static if VERSION v"1.12.0-DEV.173"
1922
addline!(lines, li) = push!(lines, li, Int32(0), Int32(0))
2023
else
2124
addline!(lines, li) = push!(lines, li)
2225
end
2326

27+
unvars(ex) = prewalk(x -> x isa Variable ? SSAValue(x.id) : x, ex)
28+
2429
function IRCode(ir::IR)
2530
defs = Dict()
2631
stmts, types, lines = [], [], Int32[]
@@ -108,7 +113,10 @@ function IRCode(ir::IR)
108113
debuginfo.linetable = Core.DebugInfo(debuginfo.def, nothing, Core.svec(), codelocs)
109114
IRCode(stmts, cfg, debuginfo, ir.blocks[1].argtypes, meta, sps)
110115
else
111-
IRCode(stmts, cfg, ir.lines, ir.blocks[1].argtypes, meta, sps)
116+
mod, meth = ir.meta isa Meta ? (ir.meta.method.module, ir.meta.method) : (Main, nothing)
117+
linetable = map(li -> Core.LineInfoNode(mod, meth, li.file, LineType(li.line), LineType(li.inlined_at)),
118+
ir.lines)
119+
IRCode(stmts, cfg, linetable, ir.blocks[1].argtypes, meta, sps)
112120
end
113121
else
114122
IRCode(stmts, types, lines, flags, cfg, ir.lines, ir.blocks[1].argtypes, [], sps)
@@ -159,20 +167,21 @@ function IR(ci::CodeInfo, nargs::Integer; meta = nothing)
159167
def = isnothing(meta) ? :var"n/a" : meta.instance
160168
N = length(ci.code)
161169
codelocs = fill(0, N)
162-
linetable = Base.IRShow.LineInfoNode[]
170+
linetable = LineInfoNode[]
163171

164172
# NOTE: we could be faster about decoding here and support inlining?
165173
for pc in 1:N
166174
LI = Base.IRShow.buildLineInfoNode(ci.debuginfo, def, pc)
167175
if !isempty(LI)
168-
push!(linetable, first(LI))
176+
linode = first(LI) # ::Base.IRShow.LineInfoNode
177+
push!(linetable, LineInfoNode(linode.file, linode.line))
169178
codelocs[pc] = length(linetable)
170179
end
171180
end
172181

173182
codelocs, linetable
174183
else
175-
ci.codelocs, Core.LineInfoNode[ci.linetable...]
184+
ci.codelocs, map(li -> LineInfoNode(li.file, li.line), ci.linetable)
176185
end
177186
ir = IR(linetable, meta = meta)
178187
_rename = Dict()

0 commit comments

Comments
 (0)