Class: RubyVM::InstructionSequence

Inherits:
Object
  • Object
show all
Includes:
MethodSig
Defined in:
lib/decompiler/method/signature/iseq.rb,
lib/decompiler/vm/bytedecoder.rb,
lib/decompiler/vm/iseq/as_code.rb,
lib/decompiler/vm/iseq/as_expression.rb

Overview

YARV 1.9.2 and later

Instance Method Summary collapse

Methods included from MethodSig

#arguments

Instance Method Details

#args_nodeObject



23
24
25
# File 'lib/decompiler/method/signature/iseq.rb', line 23

def args_node
  return nil
end

#argument_namesObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/decompiler/method/signature/iseq.rb', line 11

def argument_names
  local_vars = self.local_vars
  opt_args = self.arg_opt_table
  opt_args.pop # last arg is a pointer to the start of the code
  num_args = \
    self.argc + \
    opt_args.size + \
    (rest_arg ? 1 : 0) + \
    (block_arg ? 1 : 0)
  return local_vars[0...num_args]
end

#as_code(indent = 0) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/decompiler/vm/iseq/as_code.rb', line 8

def as_code(indent=0)
  env = Internal::ByteDecoder::Environment.new(local_table())
  opt_pc = self.opt_pc
  self.bytedecode(env, opt_pc)
  expressions = env.expressions + env.stack
  if expressions.length == 0 then
    return nil
  elsif expressions.length == 1 and
     expressions[0].is_a?(Internal::ByteDecoder::Expression::Literal) and
     expressions[0].value == nil then
    return nil
  else
    expressions.map! { |e| "#{'  '*indent}#{e}" }
    return expressions.join("\n")
  end
end

#as_expressionObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/decompiler/vm/iseq/as_expression.rb', line 8

def as_expression
  env = Internal::ByteDecoder::Environment.new(local_table())
  opt_pc = self.opt_pc
  self.bytedecode(env, opt_pc)
  expressions = env.expressions + env.stack
  if expressions.length == 0 then
    return nil
  elsif expressions.length == 1 and
     expressions[0].is_a?(Internal::ByteDecoder::Expression::Literal) and
     expressions[0].value == nil then
    return nil
  else
    return expressions.join('; ')
  end
end

#block_argObject



32
33
34
35
# File 'lib/decompiler/method/signature/iseq.rb', line 32

def block_arg
  arg_block = self.arg_block
  return arg_block >= 0 ? arg_block : nil
end

#bytedecode(env, start_pc = 0, end_pc = nil, &block) ⇒ Object



788
789
790
791
792
793
794
795
796
797
# File 'lib/decompiler/vm/bytedecoder.rb', line 788

def bytedecode(env, start_pc=0, end_pc=nil, &block)
  self.each(start_pc) do |instruction|
    # p instruction
    instruction.bytedecode(env)
    # p env.stack
    env.advance(instruction.length)
    break if end_pc and env.pc >= end_pc
    break if block and block.call(instruction)
  end
end

#local_varsObject



6
7
8
9
# File 'lib/decompiler/method/signature/iseq.rb', line 6

def local_vars
  local_vars = self.local_table
  return local_vars
end

#opt_pcObject



799
800
801
802
# File 'lib/decompiler/vm/bytedecoder.rb', line 799

def opt_pc
  opt_table = self.arg_opt_table
  return opt_table.length > 0 ? opt_table[-1] : 0
end

#rest_argObject



27
28
29
30
# File 'lib/decompiler/method/signature/iseq.rb', line 27

def rest_arg
  arg_rest = self.arg_rest
  return arg_rest >= 0 ? arg_rest : nil
end

#set_optional_args(args, args_node, names) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/decompiler/method/signature/iseq.rb', line 37

def set_optional_args(args, args_node, names)
  opt_table = self.arg_opt_table
  opt_table.pop
  first_opt_idx =
    names.size -
    opt_table.size -
    (self.rest_arg ? 1 : 0) -
    (self.block_arg ? 1 : 0)
  opt_table.each_with_index do |pc, idx|
    name = names[first_opt_idx + idx]
    args[name] = YarvOptionalArgument.new(name, self, pc, idx, false, false)
  end
end