Skip to content

Instantly share code, notes, and snippets.

@simonfxr
Created August 29, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonfxr/d85d537499f84abb9731b257d21b2284 to your computer and use it in GitHub Desktop.
Save simonfxr/d85d537499f84abb9731b257d21b2284 to your computer and use it in GitHub Desktop.
add less verbose code_llvm_nocomment and code_native_nocomment functions/macros
using InteractiveUtils
function _strip_comments(out::IO, inp::IO)
for ln in eachline(inp)
if !startswith(ln, ';')
println(out, ln)
end
end
end
function code_native_nocomment(
io::IO, @nospecialize(f), @nospecialize(types=Tuple);
syntax::Symbol = :intel)
tmpio = IOBuffer()
code_native(tmpio, f, types, syntax=syntax)
seekstart(tmpio)
_strip_comments(io, tmpio)
end
code_native_nocomment(
@nospecialize(f), @nospecialize(types=Tuple); syntax::Symbol = :att) =
code_native_nocomment(stdout, f, types, syntax = syntax)
code_native_nocomment(::IO, ::Any, ::Symbol) =
error("illegal code_native call") # resolve ambiguous call
function code_llvm_nocomment(
io::IO, @nospecialize(f), @nospecialize(types=Tuple),
strip_ir_metadata=true, dump_module=false, optimize=true)
tmpio = IOBuffer()
code_llvm(tmpio, f, types, strip_ir_metadata, dump_module, optimize)
seekstart(tmpio)
_strip_comments(io, tmpio)
end
code_llvm_nocomment(
@nospecialize(f), @nospecialize(types=Tuple);
raw=false, dump_module=false, optimize=true) =
code_llvm_nocomment(stdout, f, types, !raw, dump_module, optimize)
macro code_native_nocomment(ex0)
InteractiveUtils.gen_call_with_extracted_types(
__module__, :code_native_nocomment, ex0)
end
macro code_llvm_nocomment(ex0)
InteractiveUtils.gen_call_with_extracted_types(
__module__, :code_llvm_nocomment, ex0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment