seafoam 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/workflows.yml +39 -0
- data/.rubocop.yml +1 -1
- data/README.md +75 -2
- data/bin/bgv2isabelle +16 -45
- data/bin/bgv2json +18 -36
- data/bin/cfg2asm +24 -0
- data/bin/seafoam +1 -1
- data/demos/box-unbox-stats +65 -0
- data/docs/getting-graphs.md +4 -0
- data/examples/fib-java.bgv.gz +0 -0
- data/examples/fib.js +1 -1
- data/examples/java/JavaExamples.java +1 -1
- data/examples/ruby/clamps.rb +20 -0
- data/examples/ruby/graal.patch +15 -0
- data/examples/ruby/ruby_examples.rb +278 -0
- data/lib/seafoam.rb +5 -0
- data/lib/seafoam/annotators/graal.rb +1 -1
- data/lib/seafoam/cfg/cfg_parser.rb +93 -0
- data/lib/seafoam/cfg/disassembler.rb +70 -0
- data/lib/seafoam/commands.rb +185 -29
- data/lib/seafoam/graal/source.rb +23 -0
- data/lib/seafoam/isabelle_writer.rb +46 -0
- data/lib/seafoam/json_writer.rb +58 -0
- data/lib/seafoam/version.rb +1 -1
- data/seafoam.gemspec +2 -1
- data/spec/seafoam/annotators/graal_spec.rb +7 -7
- data/spec/seafoam/bgv/bgv_parser_spec.rb +2 -2
- data/spec/seafoam/cfg/cfg_parser_spec.rb +21 -0
- data/spec/seafoam/cfg/disassembler_spec.rb +32 -0
- data/spec/seafoam/command_spec.rb +78 -30
- data/spec/seafoam/json_writer_spec.rb +14 -0
- data/spec/seafoam/spec_helpers.rb +4 -0
- data/tools/render-all +2 -2
- metadata +36 -102
- data/.github/workflows/rubocop.yml +0 -10
- data/.github/workflows/specs.yml +0 -19
- data/examples/fib-java.bgv +0 -0
- data/examples/fib-js.bgv +0 -0
- data/examples/fib-ruby.bgv +0 -0
- data/examples/identity.bgv +0 -0
- data/examples/java/exampleArithOperator.bgv +0 -0
- data/examples/java/exampleArithOperator.cfg +0 -925
- data/examples/java/exampleArrayAllocation.bgv +0 -0
- data/examples/java/exampleArrayAllocation.cfg +0 -5268
- data/examples/java/exampleArrayRead.bgv +0 -0
- data/examples/java/exampleArrayRead.cfg +0 -2263
- data/examples/java/exampleArrayWrite.bgv +0 -0
- data/examples/java/exampleArrayWrite.cfg +0 -2315
- data/examples/java/exampleCatch.bgv +0 -0
- data/examples/java/exampleCatch.cfg +0 -4150
- data/examples/java/exampleCompareOperator.bgv +0 -0
- data/examples/java/exampleCompareOperator.cfg +0 -1109
- data/examples/java/exampleDoubleSynchronized.bgv +0 -0
- data/examples/java/exampleDoubleSynchronized.cfg +0 -26497
- data/examples/java/exampleExactArith.bgv +0 -0
- data/examples/java/exampleExactArith.cfg +0 -1888
- data/examples/java/exampleFieldRead.bgv +0 -0
- data/examples/java/exampleFieldRead.cfg +0 -1228
- data/examples/java/exampleFieldWrite.bgv +0 -0
- data/examples/java/exampleFieldWrite.cfg +0 -1102
- data/examples/java/exampleFor.bgv +0 -0
- data/examples/java/exampleFor.cfg +0 -3936
- data/examples/java/exampleFullEscape.bgv +0 -0
- data/examples/java/exampleFullEscape.cfg +0 -5893
- data/examples/java/exampleIf.bgv +0 -0
- data/examples/java/exampleIf.cfg +0 -2462
- data/examples/java/exampleIfNeverTaken.bgv +0 -0
- data/examples/java/exampleIfNeverTaken.cfg +0 -2476
- data/examples/java/exampleInstanceOfManyImpls.bgv +0 -0
- data/examples/java/exampleInstanceOfManyImpls.cfg +0 -6391
- data/examples/java/exampleInstanceOfOneImpl.bgv +0 -0
- data/examples/java/exampleInstanceOfOneImpl.cfg +0 -2604
- data/examples/java/exampleIntSwitch.bgv +0 -0
- data/examples/java/exampleIntSwitch.cfg +0 -3121
- data/examples/java/exampleInterfaceCallManyImpls.bgv +0 -0
- data/examples/java/exampleInterfaceCallManyImpls.cfg +0 -1358
- data/examples/java/exampleInterfaceCallOneImpl.bgv +0 -0
- data/examples/java/exampleInterfaceCallOneImpl.cfg +0 -3859
- data/examples/java/exampleLocalInstanceOf.bgv +0 -0
- data/examples/java/exampleLocalInstanceOf.cfg +0 -5276
- data/examples/java/exampleLocalSynchronized.bgv +0 -0
- data/examples/java/exampleLocalSynchronized.cfg +0 -1364
- data/examples/java/exampleLocalVariables.bgv +0 -0
- data/examples/java/exampleLocalVariables.cfg +0 -1195
- data/examples/java/exampleLocalVariablesState.bgv +0 -0
- data/examples/java/exampleLocalVariablesState.cfg +0 -1673
- data/examples/java/exampleNestedWhile.bgv +0 -0
- data/examples/java/exampleNestedWhile.cfg +0 -15499
- data/examples/java/exampleNestedWhileBreak.bgv +0 -0
- data/examples/java/exampleNestedWhileBreak.cfg +0 -11162
- data/examples/java/exampleNoEscape.bgv +0 -0
- data/examples/java/exampleNoEscape.cfg +0 -974
- data/examples/java/exampleObjectAllocation.bgv +0 -0
- data/examples/java/exampleObjectAllocation.cfg +0 -5287
- data/examples/java/examplePartialEscape.bgv +0 -0
- data/examples/java/examplePartialEscape.cfg +0 -7042
- data/examples/java/examplePhi.bgv +0 -0
- data/examples/java/examplePhi.cfg +0 -3227
- data/examples/java/exampleReducible.bgv +0 -0
- data/examples/java/exampleReducible.cfg +0 -5578
- data/examples/java/exampleSimpleCall.bgv +0 -0
- data/examples/java/exampleSimpleCall.cfg +0 -1435
- data/examples/java/exampleStamp.bgv +0 -0
- data/examples/java/exampleStamp.cfg +0 -913
- data/examples/java/exampleStaticCall.bgv +0 -0
- data/examples/java/exampleStaticCall.cfg +0 -1154
- data/examples/java/exampleStringSwitch.bgv +0 -0
- data/examples/java/exampleStringSwitch.cfg +0 -15377
- data/examples/java/exampleSynchronized.bgv +0 -0
- data/examples/java/exampleSynchronized.cfg +0 -26027
- data/examples/java/exampleThrow.bgv +0 -0
- data/examples/java/exampleThrow.cfg +0 -780
- data/examples/java/exampleThrowCatch.bgv +0 -0
- data/examples/java/exampleThrowCatch.cfg +0 -744
- data/examples/java/exampleUnsafeRead.bgv +0 -0
- data/examples/java/exampleUnsafeRead.cfg +0 -912
- data/examples/java/exampleUnsafeWrite.bgv +0 -0
- data/examples/java/exampleUnsafeWrite.cfg +0 -962
- data/examples/java/exampleWhile.bgv +0 -0
- data/examples/java/exampleWhile.cfg +0 -3936
- data/examples/java/exampleWhileBreak.bgv +0 -0
- data/examples/java/exampleWhileBreak.cfg +0 -5963
- data/examples/matmult-java.bgv +0 -0
- data/examples/matmult-ruby.bgv +0 -0
- data/examples/overflow.bgv +0 -0
- data/spec/seafoam/bgv/fixtures/not.bgv +0 -1
- data/spec/seafoam/bgv/fixtures/unsupported.bgv +0 -1
data/lib/seafoam/commands.rb
CHANGED
@@ -8,12 +8,31 @@ module Seafoam
|
|
8
8
|
@config = config
|
9
9
|
end
|
10
10
|
|
11
|
-
# Run
|
12
|
-
def
|
11
|
+
# Run the general seafoam command.
|
12
|
+
def seafoam(*args)
|
13
13
|
first, *args = args
|
14
14
|
case first
|
15
15
|
when nil, 'help', '-h', '--help', '-help'
|
16
|
-
|
16
|
+
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
17
|
+
|
18
|
+
@out.puts 'seafoam file.bgv info'
|
19
|
+
@out.puts ' file.bgv list'
|
20
|
+
@out.puts ' file.bgv[:graph][:node[-edge]] search term...'
|
21
|
+
@out.puts ' file.bgv[:graph][:node[-edge]] edges'
|
22
|
+
@out.puts ' file.bgv[:graph][:node[-edge]] props'
|
23
|
+
@out.puts ' file.bgv:graph:node source'
|
24
|
+
@out.puts ' file.bgv:graph render'
|
25
|
+
@out.puts ' --spotlight n,n,n...'
|
26
|
+
@out.puts ' --out graph.pdf'
|
27
|
+
@out.puts ' graph.svg'
|
28
|
+
@out.puts ' graph.png'
|
29
|
+
@out.puts ' graph.dot'
|
30
|
+
@out.puts ' --show-frame-state'
|
31
|
+
@out.puts ' --hide-floating'
|
32
|
+
@out.puts ' --no-reduce-edges'
|
33
|
+
@out.puts ' --option key value'
|
34
|
+
@out.puts ' --help'
|
35
|
+
@out.puts ' --version'
|
17
36
|
when 'version', '-v', '-version', '--version'
|
18
37
|
version(*args)
|
19
38
|
else
|
@@ -32,6 +51,8 @@ module Seafoam
|
|
32
51
|
edges name, *args
|
33
52
|
when 'props'
|
34
53
|
props name, *args
|
54
|
+
when 'source'
|
55
|
+
source name, *args
|
35
56
|
when 'render'
|
36
57
|
render name, *args
|
37
58
|
when 'debug'
|
@@ -42,6 +63,141 @@ module Seafoam
|
|
42
63
|
end
|
43
64
|
end
|
44
65
|
|
66
|
+
# Run the bgv2isabelle command.
|
67
|
+
def bgv2isabelle(*args)
|
68
|
+
case args.first
|
69
|
+
when nil, 'help', '-h', '--help', '-help'
|
70
|
+
args = args.drop(1)
|
71
|
+
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
72
|
+
|
73
|
+
@out.puts 'bgv2isabelle file.bgv...'
|
74
|
+
@out.puts ' --help'
|
75
|
+
@out.puts ' --version'
|
76
|
+
when 'version', '-v', '-version', '--version'
|
77
|
+
args = args.drop(1)
|
78
|
+
version(*args)
|
79
|
+
else
|
80
|
+
files = []
|
81
|
+
|
82
|
+
until args.empty?
|
83
|
+
arg = args.shift
|
84
|
+
if arg.start_with?('-')
|
85
|
+
raise ArgumentError, "unknown option #{arg}"
|
86
|
+
else
|
87
|
+
files.push arg
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
writer = IsabelleWriter.new(@out)
|
92
|
+
|
93
|
+
files.each do |file|
|
94
|
+
parser = Seafoam::BGV::BGVParser.new(file)
|
95
|
+
parser.read_file_header
|
96
|
+
parser.skip_document_props
|
97
|
+
|
98
|
+
loop do
|
99
|
+
index, = parser.read_graph_preheader
|
100
|
+
break unless index
|
101
|
+
|
102
|
+
graph_header = parser.read_graph_header
|
103
|
+
name = parser.graph_name(graph_header)
|
104
|
+
graph = parser.read_graph
|
105
|
+
|
106
|
+
writer.write index, name, graph
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def bgv2json(*args)
|
113
|
+
case args.first
|
114
|
+
when nil, 'help', '-h', '--help', '-help'
|
115
|
+
args = args.drop(1)
|
116
|
+
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
117
|
+
|
118
|
+
@out.puts 'bgv2json file.bgv...'
|
119
|
+
@out.puts ' --help'
|
120
|
+
@out.puts ' --version'
|
121
|
+
when 'version', '-v', '-version', '--version'
|
122
|
+
args = args.drop(1)
|
123
|
+
version(*args)
|
124
|
+
else
|
125
|
+
files = []
|
126
|
+
|
127
|
+
until args.empty?
|
128
|
+
arg = args.shift
|
129
|
+
if arg.start_with?('-')
|
130
|
+
raise ArgumentError, "unknown option #{arg}"
|
131
|
+
else
|
132
|
+
files.push arg
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
writer = JSONWriter.new(@out)
|
137
|
+
|
138
|
+
files.each do |file|
|
139
|
+
parser = Seafoam::BGV::BGVParser.new(file)
|
140
|
+
parser.read_file_header
|
141
|
+
parser.skip_document_props
|
142
|
+
|
143
|
+
loop do
|
144
|
+
index, = parser.read_graph_preheader
|
145
|
+
break unless index
|
146
|
+
|
147
|
+
graph_header = parser.read_graph_header
|
148
|
+
name = parser.graph_name(graph_header)
|
149
|
+
graph = parser.read_graph
|
150
|
+
|
151
|
+
writer.write name, graph
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def cfg2asm(*args)
|
158
|
+
case args.first
|
159
|
+
when nil, 'help', '-h', '--help', '-help'
|
160
|
+
args = args.drop(1)
|
161
|
+
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
162
|
+
|
163
|
+
@out.puts 'cfg2asm file.bgv...'
|
164
|
+
@out.puts ' --no-comments'
|
165
|
+
@out.puts ' --help'
|
166
|
+
@out.puts ' --version'
|
167
|
+
when 'version', '-v', '-version', '--version'
|
168
|
+
args = args.drop(1)
|
169
|
+
version(*args)
|
170
|
+
else
|
171
|
+
comments = true
|
172
|
+
files = []
|
173
|
+
|
174
|
+
until args.empty?
|
175
|
+
arg = args.shift
|
176
|
+
if arg.start_with?('-')
|
177
|
+
case arg
|
178
|
+
when '--no-comments'
|
179
|
+
comments = false
|
180
|
+
else
|
181
|
+
raise ArgumentError, "unknown option #{arg}"
|
182
|
+
end
|
183
|
+
else
|
184
|
+
files.push arg
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
files.each_with_index do |file, n|
|
189
|
+
parser = Seafoam::CFG::CFGParser.new(@out, file)
|
190
|
+
parser.skip_over_cfg 'After code installation'
|
191
|
+
nmethod = parser.read_nmethod
|
192
|
+
|
193
|
+
disassembler = Seafoam::CFG::Disassembler.new(@out)
|
194
|
+
@out.puts if n.positive?
|
195
|
+
@out.puts "[#{file}]"
|
196
|
+
disassembler.disassemble(nmethod, comments)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
45
201
|
private
|
46
202
|
|
47
203
|
# seafoam file.bgv info
|
@@ -218,7 +374,24 @@ module Seafoam
|
|
218
374
|
end
|
219
375
|
end
|
220
376
|
|
221
|
-
# seafoam file.bgv:
|
377
|
+
# seafoam file.bgv:n:n source
|
378
|
+
def source(name, *args)
|
379
|
+
file, graph_index, node_id, edge_id = parse_name(name)
|
380
|
+
raise ArgumentError, 'source needs a node' unless node_id
|
381
|
+
raise ArgumentError, 'source only works with a node' if edge_id
|
382
|
+
raise ArgumentError, 'source does not take arguments' unless args.empty?
|
383
|
+
|
384
|
+
with_graph(file, graph_index) do |parser|
|
385
|
+
parser.read_graph_header
|
386
|
+
graph = parser.read_graph
|
387
|
+
node = graph.nodes[node_id]
|
388
|
+
raise ArgumentError, 'node not found' unless node
|
389
|
+
|
390
|
+
@out.puts Graal::Source.render(node.props['nodeSourcePosition'])
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
# seafoam file.bgv:n render options...
|
222
395
|
def render(name, *args)
|
223
396
|
file, graph_index, *rest = parse_name(name)
|
224
397
|
raise ArgumentError, 'render needs at least a graph' unless graph_index
|
@@ -299,10 +472,14 @@ module Seafoam
|
|
299
472
|
writer.write_graph graph
|
300
473
|
end
|
301
474
|
else
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
475
|
+
begin
|
476
|
+
IO.popen(['dot', "-T#{out_format}", '-o', out_file], 'w') do |stream|
|
477
|
+
writer = GraphvizWriter.new(stream)
|
478
|
+
hidpi = out_format == :png
|
479
|
+
writer.write_graph graph, hidpi
|
480
|
+
end
|
481
|
+
rescue Errno::ENOENT
|
482
|
+
raise 'Could not run Graphviz - is it installed?'
|
306
483
|
end
|
307
484
|
autoopen out_file unless explicit_out_file
|
308
485
|
end
|
@@ -388,27 +565,6 @@ module Seafoam
|
|
388
565
|
raise ArgumentError, 'graph not found' unless graph_found
|
389
566
|
end
|
390
567
|
|
391
|
-
# Prints help.
|
392
|
-
def help(*args)
|
393
|
-
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
394
|
-
|
395
|
-
@out.puts 'seafoam file.bgv info'
|
396
|
-
@out.puts ' file.bgv list'
|
397
|
-
@out.puts ' file.bgv[:graph][:node[-edge]] search term...'
|
398
|
-
@out.puts ' file.bgv[:graph][:node[-edge]] edges'
|
399
|
-
@out.puts ' file.bgv[:graph][:node[-edge]] props'
|
400
|
-
@out.puts ' file.bgv:graph render'
|
401
|
-
@out.puts ' --spotlight n,n,n...'
|
402
|
-
@out.puts ' --out graph.pdf'
|
403
|
-
@out.puts ' graph.svg'
|
404
|
-
@out.puts ' graph.png'
|
405
|
-
@out.puts ' graph.dot'
|
406
|
-
@out.puts ' --show-frame-state'
|
407
|
-
@out.puts ' --hide-floating'
|
408
|
-
@out.puts ' --no-reduce-edges'
|
409
|
-
@out.puts ' --option key value'
|
410
|
-
end
|
411
|
-
|
412
568
|
# Prints the version.
|
413
569
|
def version(*args)
|
414
570
|
raise ArgumentError, "unexpected arguments #{args.join(' ')}" unless args.empty?
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Seafoam
|
2
|
+
module Graal
|
3
|
+
# Routines for understanding source positions in Graal.
|
4
|
+
module Source
|
5
|
+
def self.render(source_position)
|
6
|
+
lines = []
|
7
|
+
caller = source_position
|
8
|
+
while caller
|
9
|
+
method = caller[:method]
|
10
|
+
lines.push render_method(method)
|
11
|
+
caller = caller[:caller]
|
12
|
+
end
|
13
|
+
lines.join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.render_method(method)
|
17
|
+
declaring_class = method[:declaring_class]
|
18
|
+
name = method[:method_name]
|
19
|
+
"#{declaring_class}##{name}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Seafoam
|
2
|
+
# Write graphs in the Isabelle file format.
|
3
|
+
class IsabelleWriter
|
4
|
+
def initialize(out)
|
5
|
+
@out = out
|
6
|
+
end
|
7
|
+
|
8
|
+
def write(index, name, graph)
|
9
|
+
# definition eg_short_cut_or1 :: IRGraph where
|
10
|
+
# "eg_short_cut_or1 =
|
11
|
+
# (add_node 14 ReturnNode [13] []
|
12
|
+
# (add_node 13 PhiNode [10, 11, 12] []
|
13
|
+
# (add_node 12 (ConstantNode 0) [] []
|
14
|
+
# (add_node 11 (ConstantNode 42) [] []
|
15
|
+
# (add_node 10 MergeNode [7, 9] [14]
|
16
|
+
# (add_node 9 EndNode [] []
|
17
|
+
# (add_node 8 BeginNode [] [9]
|
18
|
+
# (add_node 7 EndNode [] []
|
19
|
+
# (add_node 6 BeginNode [] [7]
|
20
|
+
# (add_node 5 IfNode [3] [6, 8]
|
21
|
+
# (add_node 3 (ShortCircuitOrNode False False) [1, 2] []
|
22
|
+
# (add_node 2 (ParameterNode 1) [] []
|
23
|
+
# (add_node 1 (ParameterNode 0) [] []
|
24
|
+
# (add_node 0 StartNode [] [5]
|
25
|
+
# empty_graph))))))))))))))"
|
26
|
+
|
27
|
+
@out.puts "graph#{index} = # #{name}"
|
28
|
+
|
29
|
+
graph.nodes.each_value do |node|
|
30
|
+
node_class = node.props[:node_class][:node_class]
|
31
|
+
case node_class
|
32
|
+
when 'org.graalvm.compiler.nodes.ConstantNode'
|
33
|
+
desc = "(ConstantNode #{node.props['rawvalue']})"
|
34
|
+
when 'org.graalvm.compiler.nodes.ParameterNode'
|
35
|
+
desc = "(ParameterNode #{node.props['index']})"
|
36
|
+
else
|
37
|
+
desc = node_class.split('.').last
|
38
|
+
end
|
39
|
+
inputs = node.inputs.map(&:from).map(&:id)
|
40
|
+
outputs = node.outputs.map(&:to).map(&:id)
|
41
|
+
@out.puts " (add_node #{node.id} #{desc} #{inputs.inspect} #{outputs.inspect}"
|
42
|
+
end
|
43
|
+
@out.puts ' empty_graph' + (')' * graph.nodes.size)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Seafoam
|
4
|
+
# Write files in a JSON format.
|
5
|
+
class JSONWriter
|
6
|
+
def initialize(out)
|
7
|
+
@out = out
|
8
|
+
end
|
9
|
+
|
10
|
+
def write(name, graph)
|
11
|
+
nodes = []
|
12
|
+
edges = []
|
13
|
+
|
14
|
+
graph.nodes.each_value do |node|
|
15
|
+
nodes.push(
|
16
|
+
id: node.id,
|
17
|
+
props: node.props
|
18
|
+
)
|
19
|
+
|
20
|
+
node.outputs.each do |edge|
|
21
|
+
edges.push(
|
22
|
+
from: edge.from.id,
|
23
|
+
to: edge.to.id,
|
24
|
+
props: edge.props
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
object = {
|
30
|
+
name: name,
|
31
|
+
props: graph.props,
|
32
|
+
nodes: nodes,
|
33
|
+
edges: edges
|
34
|
+
}
|
35
|
+
|
36
|
+
@out.puts JSON.pretty_generate(prepare_json(object))
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def prepare_json(object)
|
42
|
+
case object
|
43
|
+
when Float
|
44
|
+
if object.nan?
|
45
|
+
'[NaN]'
|
46
|
+
else
|
47
|
+
object
|
48
|
+
end
|
49
|
+
when Array
|
50
|
+
object.map { |o| prepare_json(o) }
|
51
|
+
when Hash
|
52
|
+
object.transform_values { |v| prepare_json(v) }
|
53
|
+
else
|
54
|
+
object
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/seafoam/version.rb
CHANGED
data/seafoam.gemspec
CHANGED
@@ -8,13 +8,14 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.homepage = 'https://github.com/Shopify/seafoam'
|
9
9
|
spec.license = 'MIT'
|
10
10
|
|
11
|
-
spec.files = `git ls-files`.split("\n")
|
11
|
+
spec.files = `git ls-files`.split("\n").reject { |f| f.end_with?('.bgv') || f.end_with?('.cfg') }
|
12
12
|
spec.bindir = 'bin'
|
13
13
|
spec.executables = %w[seafoam bgv2json bgv2isabelle]
|
14
14
|
|
15
15
|
spec.required_ruby_version = '>= 2.5.8'
|
16
16
|
|
17
17
|
spec.add_development_dependency 'benchmark-ips', '~> 2.7'
|
18
|
+
spec.add_development_dependency 'crabstone', '~> 4.0'
|
18
19
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
19
20
|
spec.add_development_dependency 'rubocop', '~> 0.74'
|
20
21
|
end
|
@@ -20,7 +20,7 @@ describe Seafoam::Annotators::GraalAnnotator do
|
|
20
20
|
describe 'when run' do
|
21
21
|
describe 'without options' do
|
22
22
|
before :all do
|
23
|
-
@graph = Seafoam::SpecHelpers.example_graph('matmult-ruby',
|
23
|
+
@graph = Seafoam::SpecHelpers.example_graph('matmult-ruby', 8)
|
24
24
|
annotator = Seafoam::Annotators::GraalAnnotator.new({})
|
25
25
|
annotator.annotate @graph
|
26
26
|
end
|
@@ -37,14 +37,14 @@ describe Seafoam::Annotators::GraalAnnotator do
|
|
37
37
|
expect(@graph.edges.any? { |e| e.props[:kind].nil? }).to be_falsey
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'annotates negated GuardNodes with "Guard
|
41
|
-
expect(@graph.nodes[
|
42
|
-
expect(@graph.nodes[
|
40
|
+
it 'annotates not negated GuardNodes with "Guard, else ..."' do
|
41
|
+
expect(@graph.nodes[7101].props['negated']).to be false
|
42
|
+
expect(@graph.nodes[7101].props[:label]).to start_with 'Guard, else'
|
43
43
|
end
|
44
44
|
|
45
|
-
it 'annotates
|
46
|
-
expect(@graph.nodes[
|
47
|
-
expect(@graph.nodes[
|
45
|
+
it 'annotates negated GuardNodes with "Guard not, else ..."' do
|
46
|
+
expect(@graph.nodes[7102].props['negated']).to be true
|
47
|
+
expect(@graph.nodes[7102].props[:label]).to start_with 'Guard not, else'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -77,7 +77,7 @@ describe Seafoam::BGV::BGVParser do
|
|
77
77
|
describe '#read_file_header' do
|
78
78
|
it 'produces a version' do
|
79
79
|
parser = Seafoam::BGV::BGVParser.new(@fib_java_bgv)
|
80
|
-
expect(parser.read_file_header).to eq [
|
80
|
+
expect(parser.read_file_header).to eq [7, 0]
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'raises an error for files which are not BGV' do
|
@@ -108,7 +108,7 @@ describe Seafoam::BGV::BGVParser do
|
|
108
108
|
parser = Seafoam::BGV::BGVParser.new(@fib_java_bgv)
|
109
109
|
parser.read_file_header
|
110
110
|
parser.skip_document_props
|
111
|
-
|
111
|
+
54.times do
|
112
112
|
expect(parser.read_graph_preheader).to_not be_nil
|
113
113
|
parser.skip_graph_header
|
114
114
|
parser.skip_graph
|