Class: Seafoam::Commands

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

Overview

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

Defined Under Namespace

Classes: BGVDebugParser

Instance Method Summary collapse

Constructor Details

#initialize(out, config) ⇒ Commands

Returns a new instance of Commands.



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

def initialize(out, config)
  @out = out
  @config = config
end

Instance Method Details

#bgv2isabelle(*args) ⇒ Object

Run the bgv2isabelle command.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/seafoam/commands.rb', line 67

def bgv2isabelle(*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 'bgv2isabelle file.bgv...'
    @out.puts '             --help'
    @out.puts '             --version'
  when 'version', '-v', '-version', '--version'
    args = args.drop(1)
    version(*args)
  else
    files = []

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

    writer = IsabelleWriter.new(@out)

    files.each do |file|
      parser = Seafoam::BGV::BGVParser.new(file)
      parser.read_file_header
      parser.skip_document_props

      loop do
        index, = parser.read_graph_preheader
        break unless index

        graph_header = parser.read_graph_header
        name = parser.graph_name(graph_header)
        graph = parser.read_graph

        writer.write index, name, graph
      end
    end
  end
end

#bgv2json(*args) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/seafoam/commands.rb', line 112

def bgv2json(*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 'bgv2json file.bgv...'
    @out.puts '         --help'
    @out.puts '         --version'
  when 'version', '-v', '-version', '--version'
    args = args.drop(1)
    version(*args)
  else
    files = []

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

    writer = JSONWriter.new(@out)

    files.each do |file|
      parser = Seafoam::BGV::BGVParser.new(file)
      parser.read_file_header
      parser.skip_document_props

      loop do
        index, = parser.read_graph_preheader
        break unless index

        graph_header = parser.read_graph_header
        name = parser.graph_name(graph_header)
        graph = parser.read_graph

        writer.write name, graph
      end
    end
  end
end

#cfg2asm(*args) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/seafoam/commands.rb', line 157

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 = Seafoam::CFG::CFGParser.new(@out, file)
      parser.skip_over_cfg 'After code installation'
      nmethod = parser.read_nmethod

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

#seafoam(*args) ⇒ Object

Run the general seafoam command.



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
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/seafoam/commands.rb', line 12

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

    @out.puts 'seafoam file.bgv info'
    @out.puts '        file.bgv list'
    @out.puts '        file.bgv[:graph][:node[-edge]] search term...'
    @out.puts '        file.bgv[:graph][:node[-edge]] edges'
    @out.puts '        file.bgv[:graph][:node[-edge]] props'
    @out.puts '        file.bgv:graph:node source'
    @out.puts '        file.bgv:graph render'
    @out.puts '              --spotlight n,n,n...'
    @out.puts '              --out graph.pdf'
    @out.puts '                    graph.svg'
    @out.puts '                    graph.png'
    @out.puts '                    graph.dot'
    @out.puts '               --show-frame-state'
    @out.puts '               --hide-floating'
    @out.puts '               --no-reduce-edges'
    @out.puts '               --option key value'
    @out.puts '        --help'
    @out.puts '        --version'
  when 'version', '-v', '-version', '--version'
    version(*args)
  else
    name = first
    command, *args = args
    case command
    when nil
      help(*args)
    when 'info'
      info name, *args
    when 'list'
      list name, *args
    when 'search'
      search name, *args
    when 'edges'
      edges name, *args
    when 'props'
      props name, *args
    when 'source'
      source name, *args
    when 'render'
      render name, *args
    when 'debug'
      debug name, *args
    else
      raise ArgumentError, "unknown command #{command}"
    end
  end
end