Class: CodeTools::Compiler::MethodPrinter

Inherits:
Printer show all
Defined in:
lib/rubinius/code/compiler/printers.rb

Constant Summary collapse

SEPARATOR_SIZE =
40

Instance Attribute Summary collapse

Attributes inherited from Stage

#next_stage, #printer

Instance Method Summary collapse

Methods inherited from Printer

#initialize

Methods inherited from Stage

#create_next_stage, #initialize, #input, #insert, next_stage, next_stage_class, #processor, #run_next, stage, stage_name

Constructor Details

This class inherits a constructor from CodeTools::Compiler::Printer

Instance Attribute Details

#assemblyObject

Returns the value of attribute assembly.



29
30
31
# File 'lib/rubinius/code/compiler/printers.rb', line 29

def assembly
  @assembly
end

#bytecodeObject

Returns the value of attribute bytecode.



29
30
31
# File 'lib/rubinius/code/compiler/printers.rb', line 29

def bytecode
  @bytecode
end

Instance Method Details

#match?(name) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/rubinius/code/compiler/printers.rb', line 38

def match?(name)
  return true unless @method_names
  @method_names.include? name
end

#method_names=(names) ⇒ Object



33
34
35
36
# File 'lib/rubinius/code/compiler/printers.rb', line 33

def method_names=(names)
  return if names.empty?
  @method_names = names.map { |n| n.to_sym }
end


72
73
74
# File 'lib/rubinius/code/compiler/printers.rb', line 72

def print_footer
  puts "-" * SEPARATOR_SIZE
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rubinius/code/compiler/printers.rb', line 43

def print_header(code)
  name = code.name.inspect
  size = (SEPARATOR_SIZE - name.size - 2) / 2
  size = 1 if size <= 0
  puts "\n#{"=" * size} #{name} #{"=" * (size + name.size % 2)}"
  print "Arguments:   "
  print "#{code.required_args} required, "
  print "#{code.post_args} post, "
  print "#{code.total_args} total"
  print code.splat ? ", (splat #{code.splat})\n" : "\n"
  puts "Arity:       #{code.arity}"
  print "Locals:      #{code.local_count}"
  print code.local_count > 0 ? ": #{code.local_names.join ", "}\n" : "\n"
  puts "Stack size:  #{code.stack_size}"
  puts "Registers:   #{code.registers}"
  literals = code.literals.collect do |literal|
    case literal
    when Rubinius::CompiledCode
      "<compiled code>"
    else
      literal.inspect
    end
  end
  print "Literals:    #{literals.size}"
  print code.literals.size > 0 ? ": #{literals.join ", "}\n" : "\n"
  print_lines code
  puts
end


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rubinius/code/compiler/printers.rb', line 76

def print_lines(code)
  lines = code.lines
  size = lines.size - 1
  i = 1

  if lines[0] == -1
    puts  "Line:        #{lines[1]}"
    i += 2
  end

  print "Lines to IP: "
  while i < size
    print "#{lines[i]}: #{lines[i - 1]}..#{lines[i + 1] - 1}"
    i += 2
    print ", " if i < size
  end
  puts
end


95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rubinius/code/compiler/printers.rb', line 95

def print_method(code)
  if match? code.name
    print_header code
    puts code.decode if @bytecode
    print_footer
  end

  code.literals.each do |m|
    next unless m.kind_of? Rubinius::CompiledCode
    print_method m
  end
end

#runObject



108
109
110
111
112
113
# File 'lib/rubinius/code/compiler/printers.rb', line 108

def run
  print_method @input

  @output = @input
  run_next
end