200
200
end
201
201
202
202
"""
203
- Compute line number annotations for an IRCode
203
+ Compute line number annotations for an IRCode or CodeInfo.
204
204
205
205
This functions compute three sets of annotations for each IR line. Take the following
206
206
example (taken from `@code_typed sin(1.0)`):
@@ -259,7 +259,7 @@ to catch up and print the intermediate scopes. Which scope is printed is indicat
259
259
by the indentation of the method name and by an increased thickness of the appropriate
260
260
line for the scope.
261
261
"""
262
- function compute_ir_line_annotations (code:: IRCode )
262
+ function compute_ir_line_annotations (code:: Union{ IRCode,CodeInfo} )
263
263
loc_annotations = String[]
264
264
loc_methods = String[]
265
265
loc_lineno = String[]
@@ -269,7 +269,8 @@ function compute_ir_line_annotations(code::IRCode)
269
269
last_printed_depth = 0
270
270
debuginfo = code. debuginfo
271
271
def = :var"unknown scope"
272
- for idx in 1 : length (code. stmts)
272
+ n = isa (code, IRCode) ? length (code. stmts) : length (code. code)
273
+ for idx in 1 : n
273
274
buf = IOBuffer ()
274
275
print (buf, " │" )
275
276
stack = buildLineInfoNode (debuginfo, def, idx)
@@ -833,7 +834,7 @@ function new_nodes_iter(compact::IncrementalCompact)
833
834
end
834
835
835
836
# print only line numbers on the left, some of the method names and nesting depth on the right
836
- function inline_linfo_printer (code:: IRCode )
837
+ function inline_linfo_printer (code:: Union{ IRCode,CodeInfo} )
837
838
loc_annotations, loc_methods, loc_lineno = compute_ir_line_annotations (code)
838
839
max_loc_width = maximum (length, loc_annotations)
839
840
max_lineno_width = maximum (length, loc_lineno)
@@ -902,12 +903,15 @@ function stmts_used(::IO, code::CodeInfo)
902
903
return used
903
904
end
904
905
905
- function default_config (code:: IRCode ; verbose_linetable= false )
906
- return IRShowConfig (verbose_linetable ? statementidx_lineinfo_printer (code)
907
- : inline_linfo_printer (code);
908
- bb_color= :normal )
906
+ function default_config (code:: IRCode ; debuginfo = :source_inline )
907
+ return IRShowConfig (get_debuginfo_printer (code, debuginfo); bb_color= :normal )
908
+ end
909
+ default_config (code:: CodeInfo ; debuginfo = :source ) = IRShowConfig (get_debuginfo_printer (code, debuginfo))
910
+ function default_config (io:: IO , src)
911
+ debuginfo = get (io, :debuginfo , nothing )
912
+ debuginfo != = nothing && return default_config (src; debuginfo)
913
+ return default_config (src)
909
914
end
910
- default_config (code:: CodeInfo ) = IRShowConfig (statementidx_lineinfo_printer (code))
911
915
912
916
function show_ir_stmts (io:: IO , ir:: Union{IRCode, CodeInfo, IncrementalCompact} , inds, config:: IRShowConfig ,
913
917
sptypes:: Vector{VarState} , used:: BitSet , cfg:: CFG , bb_idx:: Int ; pop_new_node! = Returns (nothing ))
@@ -927,8 +931,7 @@ function finish_show_ir(io::IO, cfg::CFG, config::IRShowConfig)
927
931
return nothing
928
932
end
929
933
930
- function show_ir (io:: IO , ir:: IRCode , config:: IRShowConfig = default_config (ir);
931
- pop_new_node! = new_nodes_iter (ir))
934
+ function show_ir (io:: IO , ir:: IRCode , config:: IRShowConfig = default_config (io, ir); pop_new_node! = new_nodes_iter (ir))
932
935
used = stmts_used (io, ir)
933
936
cfg = ir. cfg
934
937
maxssaid = length (ir. stmts) + length (ir. new_nodes)
@@ -938,7 +941,7 @@ function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(ir);
938
941
finish_show_ir (io, cfg, config)
939
942
end
940
943
941
- function show_ir (io:: IO , ci:: CodeInfo , config:: IRShowConfig = default_config (ci);
944
+ function show_ir (io:: IO , ci:: CodeInfo , config:: IRShowConfig = default_config (io, ci);
942
945
pop_new_node! = Returns (nothing ))
943
946
used = stmts_used (io, ci)
944
947
cfg = compute_basic_blocks (ci. code)
@@ -952,7 +955,7 @@ function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(ci);
952
955
finish_show_ir (io, cfg, config)
953
956
end
954
957
955
- function show_ir (io:: IO , compact:: IncrementalCompact , config:: IRShowConfig = default_config (compact. ir))
958
+ function show_ir (io:: IO , compact:: IncrementalCompact , config:: IRShowConfig = default_config (io, compact. ir))
956
959
cfg = compact. ir. cfg
957
960
958
961
@@ -1154,3 +1157,35 @@ const __debuginfo = Dict{Symbol, Any}(
1154
1157
)
1155
1158
const default_debuginfo = Ref {Symbol} (:none )
1156
1159
debuginfo (sym) = sym === :default ? default_debuginfo[] : sym
1160
+
1161
+ const __debuginfo = Dict {Symbol, Any} (
1162
+ # :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information
1163
+ :source => src -> statementidx_lineinfo_printer (src),
1164
+ :source_inline => src -> inline_linfo_printer (src),
1165
+ # :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src),
1166
+ :none => src -> lineinfo_disabled,
1167
+ )
1168
+
1169
+ const debuginfo_modes = [:none , :source , :source_inline ]
1170
+ @assert Set (debuginfo_modes) == Set (keys (__debuginfo))
1171
+
1172
+ function validate_debuginfo_mode (mode:: Symbol )
1173
+ in (mode, debuginfo_modes) && return true
1174
+ throw (ArgumentError (" `debuginfo` must be one of the following: $(join ([repr (mode) for mode in debuginfo_modes], " , " )) " ))
1175
+ end
1176
+
1177
+ const default_debuginfo_mode = Ref {Symbol} (:none )
1178
+ function expand_debuginfo_mode (mode:: Symbol , default = default_debuginfo_mode[])
1179
+ if mode === :default
1180
+ mode = default
1181
+ end
1182
+ validate_debuginfo_mode (mode)
1183
+ return mode
1184
+ end
1185
+
1186
+ function get_debuginfo_printer (mode:: Symbol )
1187
+ mode = expand_debuginfo_mode (mode)
1188
+ return __debuginfo[mode]
1189
+ end
1190
+
1191
+ get_debuginfo_printer (src, mode:: Symbol ) = get_debuginfo_printer (mode)(src)
0 commit comments