@@ -179,35 +179,44 @@ mutable struct DebugInfoStream
179179 def:: Union{MethodInstance,Symbol,Nothing}
180180 linetable:: Union{Nothing,Core.DebugInfo}
181181 edges:: Vector{Any} # Vector{Core.DebugInfo}
182+ firstline:: Int32 # the starting line for this block (specified by having an index of 0)
182183 codelocs:: Vector{Int32} # for each statement:
183184 # index into linetable (if defined), else a line number (in the file represented by def)
184185 # then index into edges
185186 # then index into edges[linetable]
186- function DebugInfoStream (def :: Union{MethodInstance,Nothing} , linetable :: Union{Nothing,DebugInfo} , edges :: Vector{Any} , codelocs:: Vector{Int32} )
187- return new (def, linetable, edges , codelocs)
187+ function DebugInfoStream (codelocs:: Vector{Int32} )
188+ return new (nothing , nothing , [], 0 , codelocs)
188189 end
189190 # DebugInfoStream(def::Union{MethodInstance,Nothing}, di::DebugInfo, nstmts::Int) =
190191 # if debuginfo_file1(di.def) === debuginfo_file1(di.def)
191- # new(def, di.linetable, Core.svec(di.edges...),
192- # ccall(:jl_uncompress_codelocs, Any, (Any, Int), di.codelocs, nstmts))
192+ # new(def, di.linetable, Core.svec(di.edges...), getdebugidx(di, 0),
193+ # ccall(:jl_uncompress_codelocs, Any, (Any, Int), di.codelocs, nstmts)::Vector{Int32} )
193194 # else
194195 function DebugInfoStream (def:: Union{MethodInstance,Nothing} , di:: DebugInfo , nstmts:: Int )
195196 codelocs = zeros (Int32, nstmts * 3 )
196197 for i = 1 : nstmts
197198 codelocs[3 i - 2 ] = i
198199 end
199- return new (def, di, Vector {Any} (), codelocs)
200+ return new (def, di, Vector {Any} (), 0 , codelocs)
200201 end
201- global copy (di:: DebugInfoStream ) = new (di. def, di. linetable, di. edges, di. codelocs)
202+ global copy (di:: DebugInfoStream ) = new (di. def, di. linetable, di. edges, di. firstline, di . codelocs)
202203end
203204
204205Core. DebugInfo (di:: DebugInfoStream , nstmts:: Int ) =
205206 Core. DebugInfo (something (di. def), di. linetable, Core. svec (di. edges... ),
206- ccall (:jl_compress_codelocs , Any, (Any, Int), di. codelocs, nstmts):: String )
207+ ccall (:jl_compress_codelocs , Any, (Int32, Any, Int), di . firstline , di. codelocs, nstmts):: String )
207208
208- getdebugidx (debuginfo:: Core.DebugInfo , pc:: Int ) = ccall (:jl_uncompress1_codeloc , NTuple{3 ,Int32}, (Any, Int), debuginfo. codelocs, (pc - 1 ))
209- getdebugidx (debuginfo:: DebugInfoStream , pc:: Int ) =
210- 3 <= 3 pc <= length (debuginfo. codelocs) ? (debuginfo. codelocs[3 pc - 2 ], debuginfo. codelocs[3 pc - 1 ], debuginfo. codelocs[3 pc - 0 ]) : (Int32 (- 1 ), Int32 (0 ), Int32 (0 ))
209+ getdebugidx (debuginfo:: Core.DebugInfo , pc:: Int ) = ccall (:jl_uncompress1_codeloc , NTuple{3 ,Int32}, (Any, Int), debuginfo. codelocs, pc)
210+
211+ function getdebugidx (debuginfo:: DebugInfoStream , pc:: Int )
212+ if 3 <= 3 pc <= length (debuginfo. codelocs)
213+ return (debuginfo. codelocs[3 pc - 2 ], debuginfo. codelocs[3 pc - 1 ], debuginfo. codelocs[3 pc - 0 ])
214+ elseif pc == 0
215+ return (Int32 (debuginfo. firstline), Int32 (0 ), Int32 (0 ))
216+ else
217+ return (Int32 (- 1 ), Int32 (0 ), Int32 (0 ))
218+ end
219+ end
211220
212221
213222# SSA values that need renaming
@@ -446,7 +455,7 @@ from the frontend or one of the caches.
446455"""
447456function IRCode ()
448457 stmts = InstructionStream (1 )
449- debuginfo = DebugInfoStream (nothing , nothing , Any[], stmts. line)
458+ debuginfo = DebugInfoStream (stmts. line)
450459 stmts. line[1 ] = 1
451460 ir = IRCode (stmts, CFG ([BasicBlock (1 : 1 , Int[], Int[])], Int[1 ]), debuginfo, Any[], Expr[], VarState[])
452461 ir[SSAValue (1 )][:stmt ] = ReturnNode (nothing )
0 commit comments