seafoam 0.11 → 0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bgv2isabelle +3 -2
- data/bin/bgv2json +3 -2
- data/bin/seafoam +3 -2
- data/lib/seafoam/bgv/bgv_parser.rb +58 -50
- data/lib/seafoam/binary/io_binary_reader.rb +19 -17
- data/lib/seafoam/colors.rb +17 -11
- data/lib/seafoam/commands.rb +210 -202
- data/lib/seafoam/formatters/base.rb +2 -0
- data/lib/seafoam/formatters/formatters.rb +5 -3
- data/lib/seafoam/formatters/json.rb +8 -5
- data/lib/seafoam/formatters/text.rb +7 -4
- data/lib/seafoam/graal/graph_description.rb +10 -3
- data/lib/seafoam/graal/pi.rb +10 -6
- data/lib/seafoam/graal/source.rb +13 -9
- data/lib/seafoam/graph.rb +15 -9
- data/lib/seafoam/graphviz_writer.rb +129 -99
- data/lib/seafoam/isabelle_writer.rb +9 -7
- data/lib/seafoam/json_writer.rb +17 -13
- data/lib/seafoam/markdown_writer.rb +18 -0
- data/lib/seafoam/mermaid_writer.rb +52 -0
- data/lib/seafoam/passes/fallback.rb +10 -6
- data/lib/seafoam/passes/graal.rb +189 -161
- data/lib/seafoam/passes/truffle.rb +120 -22
- data/lib/seafoam/passes.rb +36 -29
- data/lib/seafoam/spotlight.rb +4 -2
- data/lib/seafoam/version.rb +3 -1
- data/lib/seafoam.rb +22 -20
- metadata +9 -40
- data/bin/cfg2asm +0 -20
- data/lib/seafoam/cfg/cfg_parser.rb +0 -93
- data/lib/seafoam/cfg/disassembler.rb +0 -70
data/lib/seafoam/json_writer.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
2
4
|
|
3
5
|
module Seafoam
|
4
6
|
# Write files in a JSON format.
|
@@ -30,26 +32,28 @@ module Seafoam
|
|
30
32
|
name: name,
|
31
33
|
props: graph.props,
|
32
34
|
nodes: nodes,
|
33
|
-
edges: edges
|
35
|
+
edges: edges,
|
34
36
|
}
|
35
37
|
|
36
38
|
@out.puts JSON.pretty_generate(prepare_json(object))
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
class << self
|
42
|
+
def prepare_json(object)
|
43
|
+
case object
|
44
|
+
when Float
|
45
|
+
if object.nan?
|
46
|
+
"[NaN]"
|
47
|
+
else
|
48
|
+
object
|
49
|
+
end
|
50
|
+
when Array
|
51
|
+
object.map { |o| prepare_json(o) }
|
52
|
+
when Hash
|
53
|
+
object.transform_values { |v| prepare_json(v) }
|
44
54
|
else
|
45
55
|
object
|
46
56
|
end
|
47
|
-
when Array
|
48
|
-
object.map { |o| prepare_json(o) }
|
49
|
-
when Hash
|
50
|
-
object.transform_values { |v| prepare_json(v) }
|
51
|
-
else
|
52
|
-
object
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seafoam
|
4
|
+
# A writer from graphs to Markdown format, with an embedded Mermaid graph.
|
5
|
+
class MarkdownWriter
|
6
|
+
def initialize(stream)
|
7
|
+
@stream = stream
|
8
|
+
end
|
9
|
+
|
10
|
+
# Write a graph.
|
11
|
+
def write_graph(graph)
|
12
|
+
@stream.puts "```mermaid"
|
13
|
+
mermaid = MermaidWriter.new(@stream)
|
14
|
+
mermaid.write_graph(graph)
|
15
|
+
@stream.puts "```"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Seafoam
|
4
|
+
# A writer from graphs to the Mermaid format. Re-uses the Graphviz writer,
|
5
|
+
# just adapting for the syntax. Attributes are cherry-picked, and more
|
6
|
+
# things are left to defaults.
|
7
|
+
class MermaidWriter < GraphvizWriter
|
8
|
+
def initialize(*args)
|
9
|
+
super(*args)
|
10
|
+
@link_style_counter = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def start_graph(_attrs)
|
16
|
+
# Ignore bgcolor, as I can't figure out how to do it in Mermaid
|
17
|
+
@stream.puts "flowchart TD"
|
18
|
+
end
|
19
|
+
|
20
|
+
def end_graph
|
21
|
+
# Nothing to do
|
22
|
+
end
|
23
|
+
|
24
|
+
def start_subgraph(id)
|
25
|
+
@stream.puts " subgraph B#{id}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def end_subgraph
|
29
|
+
@stream.puts " end"
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_node(indent, id, attrs)
|
33
|
+
case attrs[:shape]
|
34
|
+
when "rectangle"
|
35
|
+
shape = ["(", ")"]
|
36
|
+
when "oval"
|
37
|
+
shape = ["([", "])"]
|
38
|
+
when "diamond"
|
39
|
+
shape = ["{{", "}}"]
|
40
|
+
end
|
41
|
+
@stream.puts "#{indent}#{id}#{shape[0]}#{attrs[:label].inspect}#{shape[1]}"
|
42
|
+
@stream.puts "#{indent}style #{id} fill:#{attrs[:fillcolor]},stroke:#{attrs[:color]},color:#{attrs[:fontcolor]};"
|
43
|
+
end
|
44
|
+
|
45
|
+
def output_edge(from, to, attrs)
|
46
|
+
@stream.puts " #{from} --> #{to}"
|
47
|
+
link_counter = (@link_style_counter += 1) - 1
|
48
|
+
penwidth = attrs[:penwidth]
|
49
|
+
@stream.puts " linkStyle #{link_counter} stroke:#{attrs[:color]},stroke-width:#{penwidth}px;"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Seafoam
|
2
4
|
module Passes
|
3
5
|
# The fallback pass always applies, and adds some basic properties.
|
@@ -5,21 +7,23 @@ module Seafoam
|
|
5
7
|
# can emit a graph with 'label' properties and we can do something useful
|
6
8
|
# with it.
|
7
9
|
class FallbackPass < Pass
|
8
|
-
|
9
|
-
|
10
|
+
class << self
|
11
|
+
def applies?(_graph)
|
12
|
+
true
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def apply(graph)
|
13
17
|
graph.nodes.each_value do |node|
|
14
|
-
if node.props[:label].nil? && node.props[
|
15
|
-
node.props[:label] = node.props[
|
18
|
+
if node.props[:label].nil? && node.props["label"]
|
19
|
+
node.props[:label] = node.props["label"]
|
16
20
|
end
|
17
21
|
|
18
|
-
node.props[:kind] ||=
|
22
|
+
node.props[:kind] ||= "other"
|
19
23
|
end
|
20
24
|
|
21
25
|
graph.edges.each do |edge|
|
22
|
-
edge.props[:kind] ||=
|
26
|
+
edge.props[:kind] ||= "other"
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|