Skip to content

Commit 0431577

Browse files
committed
allow code_[llvm|native] to take custom params::CodegenParams
Also cleans up the implementations a bit.
1 parent 374563e commit 0431577

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

stdlib/InteractiveUtils/src/codeview.jl

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ function code_warntype(io::IO, @nospecialize(f), @nospecialize(t=Base.default_tt
154154
end
155155
nothing
156156
end
157-
code_warntype(@nospecialize(f), @nospecialize(t=Base.default_tt(f)); kwargs...) =
158-
code_warntype(stdout, f, t; kwargs...)
157+
code_warntype(args...; kwargs...) = (@nospecialize; code_warntype(stdout, f, t; kwargs...))
159158

160-
import Base.CodegenParams
159+
using Base: CodegenParams
161160

162161
const GENERIC_SIG_WARNING = "; WARNING: This code may not match what actually runs.\n"
163162
const OC_MISMATCH_WARNING =
@@ -170,15 +169,8 @@ const OC_MISMATCH_WARNING =
170169

171170
function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrapper::Bool,
172171
raw::Bool, dump_module::Bool, syntax::Symbol,
173-
optimize::Bool, debuginfo::Symbol, binary::Bool)
174-
params = CodegenParams(debug_info_kind=Cint(0),
175-
safepoint_on_entry=raw, gcstack_arg=raw)
176-
_dump_function(f, t, native, wrapper, raw, dump_module, syntax,
177-
optimize, debuginfo, binary, params)
178-
end
179-
function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrapper::Bool,
180-
raw::Bool, dump_module::Bool, syntax::Symbol,
181-
optimize::Bool, debuginfo::Symbol, binary::Bool, params::CodegenParams)
172+
optimize::Bool, debuginfo::Symbol, binary::Bool,
173+
params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
182174
ccall(:jl_is_in_pure_context, Bool, ()) && error("code reflection cannot be used from generated functions")
183175
if isa(f, Core.Builtin)
184176
throw(ArgumentError("argument is not a generic function"))
@@ -281,19 +273,17 @@ All metadata and dbg.* calls are removed from the printed bitcode. For the full
281273
To dump the entire module that encapsulates the function (with declarations), set the `dump_module` keyword to true.
282274
Keyword argument `debuginfo` may be one of source (default) or none, to specify the verbosity of code comments.
283275
"""
284-
function code_llvm(io::IO, @nospecialize(f), @nospecialize(types), raw::Bool,
285-
dump_module::Bool=false, optimize::Bool=true, debuginfo::Symbol=:default)
286-
d = _dump_function(f, types, false, false, raw, dump_module, :intel, optimize, debuginfo, false)
276+
function code_llvm(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
277+
raw::Bool=false, dump_module::Bool=false, optimize::Bool=true, debuginfo::Symbol=:default,
278+
params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
279+
d = _dump_function(f, types, false, false, raw, dump_module, :intel, optimize, debuginfo, false, params)
287280
if highlighting[:llvm] && get(io, :color, false)::Bool
288281
print_llvm(io, d)
289282
else
290283
print(io, d)
291284
end
292285
end
293-
code_llvm(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f)); raw::Bool=false, dump_module::Bool=false, optimize::Bool=true, debuginfo::Symbol=:default) =
294-
code_llvm(io, f, types, raw, dump_module, optimize, debuginfo)
295-
code_llvm(@nospecialize(f), @nospecialize(types=Base.default_tt(f)); raw=false, dump_module=false, optimize=true, debuginfo::Symbol=:default) =
296-
code_llvm(stdout, f, types; raw, dump_module, optimize, debuginfo)
286+
code_llvm(args...; kwargs...) = (@nospecialize; code_llvm(stdout, args...; kwargs...))
297287

298288
"""
299289
code_native([io=stdout,], f, types; syntax=:intel, debuginfo=:default, binary=false, dump_module=true)
@@ -311,17 +301,16 @@ See also: [`@code_native`](@ref), [`code_llvm`](@ref), [`code_typed`](@ref) and
311301
"""
312302
function code_native(io::IO, @nospecialize(f), @nospecialize(types=Base.default_tt(f));
313303
dump_module::Bool=true, syntax::Symbol=:intel, raw::Bool=false,
314-
debuginfo::Symbol=:default, binary::Bool=false)
315-
d = _dump_function(f, types, true, false, raw, dump_module, syntax, true, debuginfo, binary)
304+
debuginfo::Symbol=:default, binary::Bool=false,
305+
params::CodegenParams=CodegenParams(debug_info_kind=Cint(0), safepoint_on_entry=raw, gcstack_arg=raw))
306+
d = _dump_function(f, types, true, false, raw, dump_module, syntax, true, debuginfo, binary, params)
316307
if highlighting[:native] && get(io, :color, false)::Bool
317308
print_native(io, d)
318309
else
319310
print(io, d)
320311
end
321312
end
322-
code_native(@nospecialize(f), @nospecialize(types=Base.default_tt(f)); dump_module::Bool=true, syntax::Symbol=:intel, raw::Bool=false, debuginfo::Symbol=:default, binary::Bool=false) =
323-
code_native(stdout, f, types; dump_module, syntax, raw, debuginfo, binary)
324-
code_native(::IO, ::Any, ::Symbol) = error("invalid code_native call") # resolve ambiguous call
313+
code_native(args...; kwargs...) = (@nospecialize; code_native(stdout, args...; kwargs...))
325314

326315
## colorized IR and assembly printing
327316

0 commit comments

Comments
 (0)