Skip to content

Commit

Permalink
Use warn and always return nil if YJIT disasm not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Apr 30, 2024
1 parent 71d1eb4 commit f7b8997
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,27 @@ def self.disasm(iseq) # :nodoc:
# If a method or proc is passed in, get its iseq
iseq = RubyVM::InstructionSequence.of(iseq)

if self.enabled?
disasm_str = Primitive.rb_yjit_disasm_iseq(iseq)
if !self.enabled?
warn(
"YJIT needs to be enabled to produce disasm output, e.g.\n" +
"ruby --yjit-call-threshold=1 my_script.rb (see doc/yjit/yjit.md)"
)
return nil
end

if !disasm_str
$stderr.puts("YJIT disasm is only available when YJIT is built in dev mode, i.e.:\n")
$stderr.puts("./configure --enable-yjit=dev (see doc/yjit/yjit.md)\n")
else
# Produce the disassembly string
# Include the YARV iseq disasm in the string for additional context
iseq.disasm + "\n" + disasm_str
end
else
iseq.disasm
disasm_str = Primitive.rb_yjit_disasm_iseq(iseq)

if !disasm_str
warn(
"YJIT disasm is only available when YJIT is built in dev mode, i.e.\n" +
"./configure --enable-yjit=dev (see doc/yjit/yjit.md)\n"
)
return nil
end

# Produce the disassembly string
# Include the YARV iseq disasm in the string for additional context
iseq.disasm + "\n" + disasm_str
end

# Produce a list of instructions compiled by YJIT for an iseq
Expand Down

0 comments on commit f7b8997

Please sign in to comment.