seafoam 0.7 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bgv2isabelle +1 -5
- data/bin/bgv2json +1 -5
- data/bin/cfg2asm +1 -5
- data/bin/seafoam +1 -5
- data/lib/seafoam/bgv/bgv_parser.rb +11 -4
- data/lib/seafoam/commands.rb +140 -58
- data/lib/seafoam/formatters/base.rb +88 -0
- data/lib/seafoam/formatters/formatters.rb +8 -0
- data/lib/seafoam/formatters/json.rb +82 -0
- data/lib/seafoam/formatters/text.rb +70 -0
- data/lib/seafoam/graal/graph_description.rb +22 -0
- data/lib/seafoam/graal/pi.rb +18 -0
- data/lib/seafoam/graal/source.rb +5 -9
- data/lib/seafoam/graph.rb +33 -1
- data/lib/seafoam/graphviz_writer.rb +24 -2
- data/lib/seafoam/json_writer.rb +1 -3
- data/lib/seafoam/{annotators → passes}/fallback.rb +4 -4
- data/lib/seafoam/{annotators → passes}/graal.rb +43 -15
- data/lib/seafoam/passes/truffle.rb +58 -0
- data/lib/seafoam/passes.rb +61 -0
- data/lib/seafoam/version.rb +1 -1
- data/lib/seafoam.rb +7 -4
- metadata +34 -63
- data/.github/probots.yml +0 -2
- data/.github/workflows/workflows.yml +0 -39
- data/.gitignore +0 -7
- data/.rubocop.yml +0 -37
- data/.ruby-version +0 -1
- data/.seafoam/config +0 -1
- data/CODE_OF_CONDUCT.md +0 -128
- data/CONTRIBUTING.md +0 -5
- data/Gemfile +0 -2
- data/LICENSE.md +0 -7
- data/README.md +0 -378
- data/demos/box-unbox-stats +0 -65
- data/docs/annotators.md +0 -43
- data/docs/bgv.md +0 -293
- data/docs/getting-graphs.md +0 -59
- data/docs/images/igv.png +0 -0
- data/docs/images/seafoam.png +0 -0
- data/docs/images/spotlight-igv.png +0 -0
- data/docs/images/spotlight-seafoam.png +0 -0
- data/docs/json.md +0 -35
- data/examples/Fib.java +0 -24
- data/examples/MatMult.java +0 -39
- data/examples/fib-java.bgv.gz +0 -0
- data/examples/fib.js +0 -15
- data/examples/fib.rb +0 -15
- data/examples/identity.rb +0 -13
- data/examples/java/Irreducible.class +0 -0
- data/examples/java/Irreducible.j +0 -35
- data/examples/java/IrreducibleDecompiled.java +0 -21
- data/examples/java/JavaExamples.java +0 -418
- data/examples/matmult.rb +0 -29
- data/examples/overflow.rb +0 -13
- data/examples/ruby/clamps.rb +0 -20
- data/examples/ruby/graal.patch +0 -15
- data/examples/ruby/ruby_examples.rb +0 -278
- data/lib/seafoam/annotators.rb +0 -54
- data/lib/seafoam/config.rb +0 -34
- data/seafoam.gemspec +0 -22
- data/spec/seafoam/annotators/fallback_spec.rb +0 -69
- data/spec/seafoam/annotators/graal_spec.rb +0 -96
- data/spec/seafoam/annotators_spec.rb +0 -61
- data/spec/seafoam/bgv/bgv_parser_spec.rb +0 -157
- data/spec/seafoam/binary/io_binary_reader_spec.rb +0 -176
- data/spec/seafoam/cfg/cfg_parser_spec.rb +0 -21
- data/spec/seafoam/cfg/disassembler_spec.rb +0 -32
- data/spec/seafoam/command_spec.rb +0 -316
- data/spec/seafoam/graph_spec.rb +0 -172
- data/spec/seafoam/graphviz_writer_spec.rb +0 -63
- data/spec/seafoam/json_writer_spec.rb +0 -14
- data/spec/seafoam/spec_helpers.rb +0 -34
- data/spec/seafoam/spotlight_spec.rb +0 -38
- data/tools/render-all +0 -36
@@ -0,0 +1,70 @@
|
|
1
|
+
module Seafoam
|
2
|
+
module Formatters
|
3
|
+
module Text
|
4
|
+
# A plain-text formatter for the `describe` command.
|
5
|
+
class DescribeFormatter < Seafoam::Formatters::Base::DescribeFormatter
|
6
|
+
def format
|
7
|
+
notes = Seafoam::Graal::GraphDescription::ATTRIBUTES.select { |attr| description.send(attr) }
|
8
|
+
|
9
|
+
["#{graph.nodes.size} nodes", *notes].join(', ')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# A plain-text formatter for the `edges` command.
|
14
|
+
class EdgesFormatter < Seafoam::Formatters::Base::EdgesFormatter
|
15
|
+
def render_edges_entry(edges)
|
16
|
+
edges.map do |edge|
|
17
|
+
"#{edge.from.id_and_label} ->(#{edge.props[:label]}) #{edge.to.id_and_label}"
|
18
|
+
end.join("\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_node_entry(node)
|
22
|
+
ret = ['Input:']
|
23
|
+
ret += node.inputs.map do |input|
|
24
|
+
" #{node.id_and_label} <-(#{input.props[:label]}) #{input.from.id_and_label}"
|
25
|
+
end
|
26
|
+
|
27
|
+
ret << 'Output:'
|
28
|
+
ret += node.outputs.map do |output|
|
29
|
+
" #{node.id_and_label} ->(#{output.props[:label]}) #{output.to.id_and_label}"
|
30
|
+
end
|
31
|
+
|
32
|
+
ret.join("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_summary_entry(node_count, edge_count)
|
36
|
+
"#{node_count} nodes, #{edge_count} edges"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# A plain-text formatter for the `info` command.
|
41
|
+
class InfoFormatter < Seafoam::Formatters::Base::InfoFormatter
|
42
|
+
def format
|
43
|
+
"BGV #{major_version}.#{minor_version}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# A plain-text formatter for the `list` command.
|
48
|
+
class ListFormatter < Seafoam::Formatters::Base::ListFormatter
|
49
|
+
def format
|
50
|
+
entries.map do |entry|
|
51
|
+
"#{entry.file}:#{entry.index} #{entry.graph_name_components.join('/')}"
|
52
|
+
end.join("\n")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# A plain-text formatter for the `source` command.
|
57
|
+
class SourceFormatter < Seafoam::Formatters::Base::SourceFormatter
|
58
|
+
def format
|
59
|
+
Seafoam::Graal::Source.walk(source_position, &method(:render_method)).join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_method(method)
|
63
|
+
declaring_class = method[:declaring_class]
|
64
|
+
name = method[:method_name]
|
65
|
+
"#{declaring_class}##{name}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Seafoam
|
2
|
+
module Graal
|
3
|
+
# Provides a high level description of a Graal graph's features.
|
4
|
+
class GraphDescription
|
5
|
+
ATTRIBUTES = %i[branches calls deopts linear loops]
|
6
|
+
|
7
|
+
ATTRIBUTES.each { |attr| attr_accessor(attr) }
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@branches = false
|
11
|
+
@calls = false
|
12
|
+
@deopts = false
|
13
|
+
@linear = false
|
14
|
+
@loops = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def linear
|
18
|
+
!branches && !loops
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Seafoam
|
2
|
+
module Graal
|
3
|
+
# Routines for understanding pi nodes in Graal.
|
4
|
+
module Pi
|
5
|
+
# Find the actual value behind potentially a chain of pi nodes.
|
6
|
+
def self.follow_pi_object(node)
|
7
|
+
node = node.edges.find { |edge| edge.props[:name] == 'object' }.from while PI_NODES.include?(node.props.dig(:node_class, :node_class))
|
8
|
+
node
|
9
|
+
end
|
10
|
+
|
11
|
+
# Pi nodes add type information.
|
12
|
+
PI_NODES = [
|
13
|
+
'org.graalvm.compiler.nodes.PiNode',
|
14
|
+
'org.graalvm.compiler.nodes.PiArrayNode'
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/seafoam/graal/source.rb
CHANGED
@@ -2,21 +2,17 @@ module Seafoam
|
|
2
2
|
module Graal
|
3
3
|
# Routines for understanding source positions in Graal.
|
4
4
|
module Source
|
5
|
-
def self.
|
6
|
-
|
5
|
+
def self.walk(source_position, &block)
|
6
|
+
results = []
|
7
|
+
|
7
8
|
caller = source_position
|
8
9
|
while caller
|
9
10
|
method = caller[:method]
|
10
|
-
|
11
|
+
results.push block.call(method)
|
11
12
|
caller = caller[:caller]
|
12
13
|
end
|
13
|
-
lines.join("\n")
|
14
|
-
end
|
15
14
|
|
16
|
-
|
17
|
-
declaring_class = method[:declaring_class]
|
18
|
-
name = method[:method_name]
|
19
|
-
"#{declaring_class}##{name}"
|
15
|
+
results
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
data/lib/seafoam/graph.rb
CHANGED
@@ -2,12 +2,14 @@ module Seafoam
|
|
2
2
|
# A graph, with properties, nodes, and edges. We don't encapsulate the graph
|
3
3
|
# too much - be careful.
|
4
4
|
class Graph
|
5
|
-
attr_reader :props, :nodes, :edges
|
5
|
+
attr_reader :props, :nodes, :edges, :blocks, :new_id
|
6
6
|
|
7
7
|
def initialize(props = nil)
|
8
8
|
@props = props || {}
|
9
9
|
@nodes = {}
|
10
10
|
@edges = []
|
11
|
+
@blocks = []
|
12
|
+
@new_id = 0
|
11
13
|
end
|
12
14
|
|
13
15
|
# Create a node.
|
@@ -15,6 +17,7 @@ module Seafoam
|
|
15
17
|
props ||= {}
|
16
18
|
node = Node.new(id, props)
|
17
19
|
@nodes[id] = node
|
20
|
+
@new_id = id + 1
|
18
21
|
node
|
19
22
|
end
|
20
23
|
|
@@ -27,6 +30,20 @@ module Seafoam
|
|
27
30
|
to.inputs.push edge
|
28
31
|
edge
|
29
32
|
end
|
33
|
+
|
34
|
+
# Add a new basic block with given id and node id list.
|
35
|
+
def create_block(id, node_ids)
|
36
|
+
nodes = node_ids.select { |n| @nodes.key? n }.map { |n| @nodes[n] }
|
37
|
+
block = Block.new(id, nodes)
|
38
|
+
@blocks.push block
|
39
|
+
block
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove_edge(edge)
|
43
|
+
edge.from.outputs.delete edge
|
44
|
+
edge.to.inputs.delete edge
|
45
|
+
edges.delete edge
|
46
|
+
end
|
30
47
|
end
|
31
48
|
|
32
49
|
# A node, with properties, input edges, and output edges.
|
@@ -88,4 +105,19 @@ module Seafoam
|
|
88
105
|
"<Edge #{from.id} -> #{to.id}>"
|
89
106
|
end
|
90
107
|
end
|
108
|
+
|
109
|
+
# A control-flow basic block
|
110
|
+
class Block
|
111
|
+
attr_reader :id, :nodes
|
112
|
+
|
113
|
+
def initialize(id, nodes)
|
114
|
+
@id = id
|
115
|
+
@nodes = nodes
|
116
|
+
end
|
117
|
+
|
118
|
+
# Inspect.
|
119
|
+
def inspect
|
120
|
+
"<Block #{id}>"
|
121
|
+
end
|
122
|
+
end
|
91
123
|
end
|
@@ -7,15 +7,16 @@ module Seafoam
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# Write a graph.
|
10
|
-
def write_graph(graph, hidpi = false)
|
10
|
+
def write_graph(graph, hidpi = false, draw_blocks = false)
|
11
11
|
inline_attrs = {}
|
12
12
|
attrs = {}
|
13
13
|
attrs[:dpi] = 200 if hidpi
|
14
|
-
attrs[:bgcolor] = '
|
14
|
+
attrs[:bgcolor] = 'white'
|
15
15
|
@stream.puts 'digraph G {'
|
16
16
|
@stream.puts " graph #{write_attrs(attrs)};"
|
17
17
|
write_nodes inline_attrs, graph
|
18
18
|
write_edges inline_attrs, graph
|
19
|
+
write_blocks graph if draw_blocks
|
19
20
|
@stream.puts '}'
|
20
21
|
end
|
21
22
|
|
@@ -99,6 +100,9 @@ module Seafoam
|
|
99
100
|
# from a shaded node.
|
100
101
|
next if edge.to.props[:hidden] && edge.from.props[:spotlight] != 'shaded'
|
101
102
|
|
103
|
+
# Skip the edge if it's hidden itself
|
104
|
+
next if edge.props[:hidden]
|
105
|
+
|
102
106
|
write_edge inline_attrs, edge
|
103
107
|
end
|
104
108
|
end
|
@@ -166,6 +170,24 @@ module Seafoam
|
|
166
170
|
end
|
167
171
|
end
|
168
172
|
|
173
|
+
# Write basic block outlines.
|
174
|
+
def write_blocks(graph)
|
175
|
+
graph.blocks.each do |block|
|
176
|
+
@stream.puts " subgraph cluster_block#{block.id} {"
|
177
|
+
@stream.puts ' fontname = "Arial";'
|
178
|
+
@stream.puts " label = \"B#{block.id}\";"
|
179
|
+
@stream.puts ' style=dotted;'
|
180
|
+
|
181
|
+
block.nodes.each do |node|
|
182
|
+
next if node.props[:hidden] || node.props[:inlined]
|
183
|
+
|
184
|
+
@stream.puts " node#{node.id};"
|
185
|
+
end
|
186
|
+
|
187
|
+
@stream.puts ' }'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
169
191
|
# Return attributes for a node or edge modified to 'shade' them in terms
|
170
192
|
# the spotlight functionality - so basically make them light grey.
|
171
193
|
def shade(attrs)
|
data/lib/seafoam/json_writer.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Seafoam
|
2
|
-
module
|
3
|
-
# The fallback
|
2
|
+
module Passes
|
3
|
+
# The fallback pass always applies, and adds some basic properties.
|
4
4
|
# Works for example with Truffle AST and call graphs, but also means anyone
|
5
5
|
# can emit a graph with 'label' properties and we can do something useful
|
6
6
|
# with it.
|
7
|
-
class
|
7
|
+
class FallbackPass < Pass
|
8
8
|
def self.applies?(_graph)
|
9
9
|
true
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def apply(graph)
|
13
13
|
graph.nodes.each_value do |node|
|
14
14
|
if node.props[:label].nil? && node.props['label']
|
15
15
|
node.props[:label] = node.props['label']
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module Seafoam
|
2
|
-
module
|
3
|
-
# The Graal
|
2
|
+
module Passes
|
3
|
+
# The Graal pass applies if it looks like it was compiled by Graal or
|
4
4
|
# Truffle.
|
5
|
-
class
|
5
|
+
class GraalPass < Pass
|
6
6
|
def self.applies?(graph)
|
7
7
|
graph.props.values.any? do |v|
|
8
8
|
TRIGGERS.any? { |t| v.to_s.include?(t) }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
12
|
+
def apply(graph)
|
13
|
+
apply_nodes graph
|
14
|
+
apply_edges graph
|
15
15
|
hide_frame_state graph if @options[:hide_frame_state]
|
16
|
+
hide_pi graph if @options[:hide_pi]
|
16
17
|
hide_floating graph if @options[:hide_floating]
|
17
18
|
reduce_edges graph if @options[:reduce_edges]
|
18
19
|
hide_unused_nodes graph
|
@@ -21,8 +22,10 @@ module Seafoam
|
|
21
22
|
private
|
22
23
|
|
23
24
|
# Annotate nodes with their label and kind
|
24
|
-
def
|
25
|
+
def apply_nodes(graph)
|
25
26
|
graph.nodes.each_value do |node|
|
27
|
+
next if node.props[:label]
|
28
|
+
|
26
29
|
# The Java class of the node.
|
27
30
|
node_class = node.props.dig(:node_class, :node_class)
|
28
31
|
|
@@ -93,6 +96,11 @@ module Seafoam
|
|
93
96
|
name_template = 'π'
|
94
97
|
end
|
95
98
|
|
99
|
+
# Use a symbol for PiArrayNode.
|
100
|
+
if node_class == 'org.graalvm.compiler.nodes.PiArrayNode'
|
101
|
+
name_template = '[π]'
|
102
|
+
end
|
103
|
+
|
96
104
|
# Use a symbol for PhiNode.
|
97
105
|
if node_class == 'org.graalvm.compiler.nodes.ValuePhiNode'
|
98
106
|
name_template = 'ϕ'
|
@@ -208,7 +216,7 @@ module Seafoam
|
|
208
216
|
end
|
209
217
|
|
210
218
|
# Annotate edges with their label and kind.
|
211
|
-
def
|
219
|
+
def apply_edges(graph)
|
212
220
|
graph.edges.each do |edge|
|
213
221
|
if edge.to.props.dig(:node_class, :node_class) == 'org.graalvm.compiler.nodes.ValuePhiNode' && edge.props[:name] == 'values'
|
214
222
|
merge_node = edge.to.edges.find { |e| e.props[:name] == 'merge' }.from
|
@@ -254,8 +262,6 @@ module Seafoam
|
|
254
262
|
# loopBegin edges point from LoopEndNode (continue) and LoopExitNode
|
255
263
|
# (break) to the LoopBeginNode. Both are drawn reversed.
|
256
264
|
when 'loopBegin'
|
257
|
-
edge.props[:hidden] = true
|
258
|
-
|
259
265
|
case edge.to.props.dig(:node_class, :node_class)
|
260
266
|
when 'org.graalvm.compiler.nodes.LoopEndNode'
|
261
267
|
# If it's from the LoopEnd then it's the control edge to follow.
|
@@ -311,6 +317,24 @@ module Seafoam
|
|
311
317
|
end
|
312
318
|
end
|
313
319
|
|
320
|
+
# Hide pi nodes - they add information for optimisation, but not generally
|
321
|
+
# useful day-to-day for understanding the graph. Connect the user to the
|
322
|
+
# actual object, which may be several steps away.
|
323
|
+
def hide_pi(graph)
|
324
|
+
loop do
|
325
|
+
umodified = true
|
326
|
+
graph.edges.each do |edge|
|
327
|
+
next unless Graal::Pi::PI_NODES.include?(edge.from.props.dig(:node_class, :node_class))
|
328
|
+
|
329
|
+
object = Graal::Pi.follow_pi_object(edge.from)
|
330
|
+
graph.create_edge object, edge.to, edge.props.merge({ synthetic: true })
|
331
|
+
graph.remove_edge edge
|
332
|
+
umodified = false
|
333
|
+
end
|
334
|
+
break if umodified
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
314
338
|
# Hide floating nodes. This highlights just the control flow backbone.
|
315
339
|
def hide_floating(graph)
|
316
340
|
graph.nodes.each_value do |node|
|
@@ -332,15 +356,19 @@ module Seafoam
|
|
332
356
|
end
|
333
357
|
end
|
334
358
|
|
335
|
-
# Hide nodes that have no non-hidden users and no control flow
|
336
|
-
# would display as a node floating unconnected to the rest of
|
337
|
-
# otherwise. An exception is made for node with an anchor edge
|
338
|
-
# as some guards are anchored like this.
|
359
|
+
# Hide nodes that have no non-hidden users or edges and no control flow
|
360
|
+
# in. These would display as a node floating unconnected to the rest of
|
361
|
+
# the graph otherwise. An exception is made for node with an anchor edge
|
362
|
+
# coming in, as some guards are anchored like this.
|
339
363
|
def hide_unused_nodes(graph)
|
340
364
|
loop do
|
341
365
|
modified = false
|
342
366
|
graph.nodes.each_value do |node|
|
343
|
-
|
367
|
+
# Call trees are like Graal graphs but don't have these edges -
|
368
|
+
# don't hide them.
|
369
|
+
next if node.props['truffleCallees']
|
370
|
+
|
371
|
+
next unless node.outputs.all? { |edge| edge.to.props[:hidden] || edge.props[:hidden] } &&
|
344
372
|
node.inputs.none? { |edge| edge.props[:kind] == 'control' } &&
|
345
373
|
node.inputs.none? { |edge| edge.props[:name] == 'anchor' }
|
346
374
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Seafoam
|
2
|
+
module Passes
|
3
|
+
# The Truffle pass applies if it looks like it was compiled by Truffle.
|
4
|
+
class TrufflePass < Pass
|
5
|
+
def self.applies?(graph)
|
6
|
+
graph.props.values.any? do |v|
|
7
|
+
TRIGGERS.any? { |t| v.to_s.include?(t) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply(graph)
|
12
|
+
simplify_truffle_args graph if @options[:simplify_truffle_args]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Simplify a Truffle argument load into a single, inlined, node very much
|
18
|
+
# like a Graal parameter node.
|
19
|
+
def simplify_truffle_args(graph)
|
20
|
+
graph.nodes.dup.each_value do |node|
|
21
|
+
next unless node.props.dig(:node_class, :node_class) == 'org.graalvm.compiler.nodes.java.LoadIndexedNode'
|
22
|
+
|
23
|
+
index_node = node.inputs.find { |edge| edge.props[:name] == 'index' }.from
|
24
|
+
array_node = Graal::Pi.follow_pi_object(node.inputs.find { |edge| edge.props[:name] == 'array' }.from)
|
25
|
+
|
26
|
+
next unless index_node.props.dig(:node_class, :node_class) == 'org.graalvm.compiler.nodes.ConstantNode'
|
27
|
+
next unless array_node.props.dig(:node_class, :node_class) == 'org.graalvm.compiler.nodes.ParameterNode'
|
28
|
+
|
29
|
+
node.props[:truffle_arg_load] = true
|
30
|
+
|
31
|
+
index = index_node.props['rawvalue']
|
32
|
+
|
33
|
+
arg_node = graph.create_node(graph.new_id, { synthetic: true, inlined: true, label: "T(#{index})", kind: 'input' })
|
34
|
+
|
35
|
+
node.outputs.each do |output|
|
36
|
+
next if output.props[:name] == 'next'
|
37
|
+
|
38
|
+
graph.create_edge arg_node, output.to, output.props.dup
|
39
|
+
graph.remove_edge output
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
graph.nodes.each_value.select { |node| node.props[:truffle_arg_load] }.each do |node|
|
44
|
+
control_in = node.inputs.find { |edge| edge.props[:name] == 'next' }
|
45
|
+
control_out = node.outputs.find { |edge| edge.props[:name] == 'next' }
|
46
|
+
graph.create_edge control_in.from, control_out.to, { name: 'next' }
|
47
|
+
graph.remove_edge control_in
|
48
|
+
graph.remove_edge control_out
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# If we see these in the graph properties it's probably a Truffle graph.
|
53
|
+
TRIGGERS = %w[
|
54
|
+
TruffleCompiler
|
55
|
+
]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Seafoam
|
2
|
+
# Passes are routines to read the graph and apply properties which tools,
|
3
|
+
# such as the render command, can use to show more understandable output.
|
4
|
+
module Passes
|
5
|
+
# Apply all applicable passes to a graph.
|
6
|
+
def self.apply(graph, options = {})
|
7
|
+
passes.each do |pass|
|
8
|
+
next unless pass.applies?(graph)
|
9
|
+
|
10
|
+
# Record for information that the pass was applied this graph.
|
11
|
+
passes_applied = graph.props[:passes_applied] ||= []
|
12
|
+
passes_applied.push pass
|
13
|
+
|
14
|
+
# Run the pass.
|
15
|
+
instance = pass.new(options)
|
16
|
+
instance.apply graph
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get a list of all passes in the system.
|
21
|
+
def self.passes
|
22
|
+
# We have a defined order for passes to run - these passes at the start.
|
23
|
+
pre_passes = [
|
24
|
+
TrufflePass,
|
25
|
+
GraalPass
|
26
|
+
]
|
27
|
+
|
28
|
+
# The fallback pass runs last.
|
29
|
+
post_passes = [
|
30
|
+
FallbackPass
|
31
|
+
]
|
32
|
+
|
33
|
+
# Any extra passes in the middle.
|
34
|
+
extra_passes = Pass::SUBCLASSES.dup - pre_passes - post_passes
|
35
|
+
|
36
|
+
pre_passes + extra_passes + post_passes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# The base class for all passes. You must subclass this to be recognized
|
41
|
+
# as an pass.
|
42
|
+
class Pass
|
43
|
+
SUBCLASSES = []
|
44
|
+
|
45
|
+
def initialize(options = {})
|
46
|
+
@options = options
|
47
|
+
end
|
48
|
+
|
49
|
+
def applies?(_graph)
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
|
53
|
+
def apply(_graph)
|
54
|
+
raise NotImplementedError
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.inherited(pass)
|
58
|
+
SUBCLASSES.push pass
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/seafoam/version.rb
CHANGED
data/lib/seafoam.rb
CHANGED
@@ -5,13 +5,16 @@ require 'seafoam/cfg/cfg_parser'
|
|
5
5
|
require 'seafoam/cfg/disassembler'
|
6
6
|
require 'seafoam/colors'
|
7
7
|
require 'seafoam/graph'
|
8
|
+
require 'seafoam/graal/graph_description'
|
8
9
|
require 'seafoam/graal/source'
|
9
|
-
require 'seafoam/
|
10
|
-
require 'seafoam/
|
11
|
-
require 'seafoam/
|
10
|
+
require 'seafoam/graal/pi'
|
11
|
+
require 'seafoam/passes'
|
12
|
+
require 'seafoam/passes/truffle'
|
13
|
+
require 'seafoam/passes/graal'
|
14
|
+
require 'seafoam/passes/fallback'
|
12
15
|
require 'seafoam/spotlight'
|
13
16
|
require 'seafoam/isabelle_writer'
|
14
17
|
require 'seafoam/json_writer'
|
15
18
|
require 'seafoam/graphviz_writer'
|
16
|
-
require 'seafoam/config'
|
17
19
|
require 'seafoam/commands'
|
20
|
+
require 'seafoam/formatters/formatters'
|