@@ -4,23 +4,28 @@ using MacroTools: isexpr, prewalk
4
4
5
5
using .. Inner, .. IRTools
6
6
import .. Inner: IR, Variable, Statement, Branch, BasicBlock, Meta, block!,
7
- unreachable, varmap, argument!, branch!, return !
7
+ unreachable, varmap, argument!, branch!, return !, LineInfoNode
8
8
import Core: CodeInfo, GotoNode, SSAValue
9
9
import Core. Compiler: IRCode, CFG, GotoIfNot, ReturnNode, StmtRange
10
10
11
11
@static if VERSION > v " 1.6-"
12
12
import Core. Compiler: InstructionStream
13
13
end
14
14
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
17
20
18
21
@static if VERSION ≥ v " 1.12.0-DEV.173"
19
22
addline! (lines, li) = push! (lines, li, Int32 (0 ), Int32 (0 ))
20
23
else
21
24
addline! (lines, li) = push! (lines, li)
22
25
end
23
26
27
+ unvars (ex) = prewalk (x -> x isa Variable ? SSAValue (x. id) : x, ex)
28
+
24
29
function IRCode (ir:: IR )
25
30
defs = Dict ()
26
31
stmts, types, lines = [], [], Int32[]
@@ -108,7 +113,10 @@ function IRCode(ir::IR)
108
113
debuginfo. linetable = Core. DebugInfo (debuginfo. def, nothing , Core. svec (), codelocs)
109
114
IRCode (stmts, cfg, debuginfo, ir. blocks[1 ]. argtypes, meta, sps)
110
115
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)
112
120
end
113
121
else
114
122
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)
159
167
def = isnothing (meta) ? :var"n/a" : meta. instance
160
168
N = length (ci. code)
161
169
codelocs = fill (0 , N)
162
- linetable = Base . IRShow . LineInfoNode[]
170
+ linetable = LineInfoNode[]
163
171
164
172
# NOTE: we could be faster about decoding here and support inlining?
165
173
for pc in 1 : N
166
174
LI = Base. IRShow. buildLineInfoNode (ci. debuginfo, def, pc)
167
175
if ! isempty (LI)
168
- push! (linetable, first (LI))
176
+ linode = first (LI) # ::Base.IRShow.LineInfoNode
177
+ push! (linetable, LineInfoNode (linode. file, linode. line))
169
178
codelocs[pc] = length (linetable)
170
179
end
171
180
end
172
181
173
182
codelocs, linetable
174
183
else
175
- ci. codelocs, Core . LineInfoNode[ci . linetable ... ]
184
+ ci. codelocs, map (li -> LineInfoNode (li . file, li . line), ci . linetable)
176
185
end
177
186
ir = IR (linetable, meta = meta)
178
187
_rename = Dict ()
0 commit comments