Skip to content

Commit cc97588

Browse files
committed
move LineInfoNode definition in IRTools
1 parent 5b3617f commit cc97588

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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

@@ -108,7 +108,9 @@ function IRCode(ir::IR)
108108
debuginfo.linetable = Core.DebugInfo(debuginfo.def, nothing, Core.svec(), codelocs)
109109
IRCode(stmts, cfg, debuginfo, ir.blocks[1].argtypes, meta, sps)
110110
else
111-
IRCode(stmts, cfg, ir.lines, ir.blocks[1].argtypes, meta, sps)
111+
mod, meth = ir.meta isa Meta ? (ir.meta.method.module, ir.meta.method) : (Main, nothing)
112+
linetable = map(li -> Core.LineInfoNode(mod, meth, li.file, li.line, li.inlined_at), ir.lines)
113+
IRCode(stmts, cfg, linetable, ir.blocks[1].argtypes, meta, sps)
112114
end
113115
else
114116
IRCode(stmts, types, lines, flags, cfg, ir.lines, ir.blocks[1].argtypes, [], sps)
@@ -159,20 +161,21 @@ function IR(ci::CodeInfo, nargs::Integer; meta = nothing)
159161
def = isnothing(meta) ? :var"n/a" : meta.instance
160162
N = length(ci.code)
161163
codelocs = fill(0, N)
162-
linetable = Base.IRShow.LineInfoNode[]
164+
linetable = LineInfoNode[]
163165

164166
# NOTE: we could be faster about decoding here and support inlining?
165167
for pc in 1:N
166168
LI = Base.IRShow.buildLineInfoNode(ci.debuginfo, def, pc)
167169
if !isempty(LI)
168-
push!(linetable, first(LI))
170+
linode = first(LI) # ::Base.IRShow.LineInfoNode
171+
push!(linetable, LineInfoNode(linode.file, linode.line))
169172
codelocs[pc] = length(linetable)
170173
end
171174
end
172175

173176
codelocs, linetable
174177
else
175-
ci.codelocs, Core.LineInfoNode[ci.linetable...]
178+
ci.codelocs, map(li -> LineInfoNode(li.file, li.line), ci.linetable)
176179
end
177180
ir = IR(linetable, meta = meta)
178181
_rename = Dict()

0 commit comments

Comments
 (0)