Class: Cfg2asm::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/cfg2asm/commands.rb

Overview

Implementations of the command-line commands that you can run in cfg2asm.

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Commands

Returns a new instance of Commands.



7
8
9
# File 'lib/cfg2asm/commands.rb', line 7

def initialize(out)
  @out = out
end

Instance Method Details

#cfg2asm(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cfg2asm/commands.rb', line 11

def cfg2asm(*args)
  case args.first
  when nil, 'help', '-h', '--help', '-help'
    args = args.drop(1)
    raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?

    @out.puts 'cfg2asm file.bgv...'
    @out.puts '            --no-comments'
    @out.puts '        --help'
    @out.puts '        --version'
  when 'version', '-v', '-version', '--version'
    args = args.drop(1)
    version(*args)
  else
    comments = true
    files = []

    until args.empty?
      arg = args.shift
      if arg.start_with?('-')
        case arg
        when '--no-comments'
          comments = false
        else
          raise ArgumentError, "unknown option #{arg}"
        end
      else
        files.push arg
      end
    end

    files.each_with_index do |file, n|
      parser = Cfg2asm::CFG::CFGParser.new(@out, file)
      parser.skip_over_cfg 'After code installation'
      nmethod = parser.read_nmethod

      disassembler = Cfg2asm::CFG::Disassembler.new(@out)
      @out.puts if n.positive?
      @out.puts "[#{file}]"
      disassembler.disassemble(nmethod, comments)
    end
  end
end

#version(*args) ⇒ Object

Prints the version.

Raises:

  • (ArgumentError)


56
57
58
59
60
# File 'lib/cfg2asm/commands.rb', line 56

def version(*args)
  raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?

  @out.puts "cfg2asm #{VERSION}"
end