seafoam 0.12 → 0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/seafoam/commands.rb +46 -18
- data/lib/seafoam/graal/graph_description.rb +1 -2
- data/lib/seafoam/markdown_writer.rb +16 -0
- data/lib/seafoam/mermaid_writer.rb +40 -0
- data/lib/seafoam/version.rb +1 -1
- data/lib/seafoam.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd98e20ee30268f65b81cdee7e286133d09d3daa1a5906500e46391fb8a77e8
|
4
|
+
data.tar.gz: 19e94f385a5e0b056b0431f9385b0ca75796b368e5b767a537406c4f87f83329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91d9279f98008fd449f4be3ecf4d45fdf2ddac3e3eb1f6eae0b0451a2dbb58d3a52b95fa12be3a805aa208ccb56033fe32b093f653331907cbc3d51b3d033f56
|
7
|
+
data.tar.gz: f2bb55b41d82f3176dcfc1bbfc46bdd01711ac8a4e61995338e5e127a196f43b40eff3ef81b2e16448dd86f4535a215d83accf7643f5f92787ff9b1d74c964b9
|
data/lib/seafoam/commands.rb
CHANGED
@@ -414,6 +414,28 @@ module Seafoam
|
|
414
414
|
out_file = args.shift
|
415
415
|
explicit_out_file = true
|
416
416
|
raise ArgumentError, 'no file for --out' unless out_file
|
417
|
+
|
418
|
+
out_ext = File.extname(out_file).downcase
|
419
|
+
case out_ext
|
420
|
+
when '.pdf'
|
421
|
+
out_format = :pdf
|
422
|
+
when '.svg'
|
423
|
+
out_format = :svg
|
424
|
+
when '.png'
|
425
|
+
out_format = :png
|
426
|
+
when '.dot'
|
427
|
+
out_format = :dot
|
428
|
+
when '.mmd'
|
429
|
+
out_format = :mmd
|
430
|
+
when '.md'
|
431
|
+
out_format = :md
|
432
|
+
else
|
433
|
+
raise ArgumentError, "unknown render format #{out_ext}"
|
434
|
+
end
|
435
|
+
when '--md'
|
436
|
+
out_file = @out
|
437
|
+
out_format = :md
|
438
|
+
explicit_out_file = true
|
417
439
|
when '--spotlight'
|
418
440
|
spotlight_arg = args.shift
|
419
441
|
raise ArgumentError, 'no list for --spotlight' unless spotlight_arg
|
@@ -445,20 +467,7 @@ module Seafoam
|
|
445
467
|
end
|
446
468
|
end
|
447
469
|
out_file ||= 'graph.pdf'
|
448
|
-
|
449
|
-
case out_ext
|
450
|
-
when '.pdf'
|
451
|
-
out_format = :pdf
|
452
|
-
when '.svg'
|
453
|
-
out_format = :svg
|
454
|
-
when '.png'
|
455
|
-
out_format = :png
|
456
|
-
when '.dot'
|
457
|
-
out_format = :dot
|
458
|
-
else
|
459
|
-
raise ArgumentError, "unknown render format #{out_ext}"
|
460
|
-
end
|
461
|
-
|
470
|
+
out_format ||= :pdf
|
462
471
|
with_graph(file, graph_index) do |parser|
|
463
472
|
parser.skip_graph_header
|
464
473
|
graph = parser.read_graph
|
@@ -473,10 +482,29 @@ module Seafoam
|
|
473
482
|
end
|
474
483
|
spotlight.shade
|
475
484
|
end
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
485
|
+
case out_format
|
486
|
+
when :dot, :mmd, :md
|
487
|
+
action = lambda do |stream|
|
488
|
+
case out_format
|
489
|
+
when :dot
|
490
|
+
writer = GraphvizWriter.new(stream)
|
491
|
+
writer.write_graph graph, false, draw_blocks
|
492
|
+
when :mmd
|
493
|
+
writer = MermaidWriter.new(stream)
|
494
|
+
writer.write_graph graph
|
495
|
+
when :md
|
496
|
+
writer = MarkdownWriter.new(stream)
|
497
|
+
writer.write_graph graph
|
498
|
+
else
|
499
|
+
raise
|
500
|
+
end
|
501
|
+
end
|
502
|
+
if out_file.is_a?(String)
|
503
|
+
File.open(out_file, 'w') do |stream|
|
504
|
+
action.call stream
|
505
|
+
end
|
506
|
+
else
|
507
|
+
action.call out_file
|
480
508
|
end
|
481
509
|
else
|
482
510
|
begin
|
@@ -4,13 +4,12 @@ module Seafoam
|
|
4
4
|
class GraphDescription
|
5
5
|
ATTRIBUTES = %i[branches calls deopts linear loops]
|
6
6
|
|
7
|
-
ATTRIBUTES.each { |attr| attr_accessor(attr) }
|
7
|
+
ATTRIBUTES.each { |attr| attr_accessor(attr) unless attr == :linear }
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@branches = false
|
11
11
|
@calls = false
|
12
12
|
@deopts = false
|
13
|
-
@linear = false
|
14
13
|
@loops = false
|
15
14
|
end
|
16
15
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Seafoam
|
2
|
+
# A writer from graphs to Markdown format, with an embedded Mermaid graph.
|
3
|
+
class MarkdownWriter
|
4
|
+
def initialize(stream)
|
5
|
+
@stream = stream
|
6
|
+
end
|
7
|
+
|
8
|
+
# Write a graph.
|
9
|
+
def write_graph(graph)
|
10
|
+
@stream.puts '```mermaid'
|
11
|
+
mermaid = MermaidWriter.new(@stream)
|
12
|
+
mermaid.write_graph graph
|
13
|
+
@stream.puts '```'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Seafoam
|
2
|
+
# A writer from graphs to the Mermaid format.
|
3
|
+
class MermaidWriter
|
4
|
+
def initialize(stream)
|
5
|
+
@stream = stream
|
6
|
+
end
|
7
|
+
|
8
|
+
# Write a graph.
|
9
|
+
def write_graph(graph)
|
10
|
+
@stream.puts 'flowchart TD'
|
11
|
+
write_nodes graph
|
12
|
+
write_edges graph
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Write node declarations.
|
18
|
+
def write_nodes(graph)
|
19
|
+
graph.nodes.each_value do |node|
|
20
|
+
write_node node
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_node(node)
|
25
|
+
@stream.puts " node#{node.id}[#{node.props[:label].inspect}]"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Write edge declarations.
|
29
|
+
|
30
|
+
def write_edges(graph)
|
31
|
+
graph.edges.each do |edge|
|
32
|
+
write_edge edge
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_edge(edge)
|
37
|
+
@stream.puts " node#{edge.from.id} --> node#{edge.to.id}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/seafoam/version.rb
CHANGED
data/lib/seafoam.rb
CHANGED
@@ -14,5 +14,7 @@ require 'seafoam/spotlight'
|
|
14
14
|
require 'seafoam/isabelle_writer'
|
15
15
|
require 'seafoam/json_writer'
|
16
16
|
require 'seafoam/graphviz_writer'
|
17
|
+
require 'seafoam/mermaid_writer'
|
18
|
+
require 'seafoam/markdown_writer'
|
17
19
|
require 'seafoam/commands'
|
18
20
|
require 'seafoam/formatters/formatters'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seafoam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.13'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Seaton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- lib/seafoam/graphviz_writer.rb
|
81
81
|
- lib/seafoam/isabelle_writer.rb
|
82
82
|
- lib/seafoam/json_writer.rb
|
83
|
+
- lib/seafoam/markdown_writer.rb
|
84
|
+
- lib/seafoam/mermaid_writer.rb
|
83
85
|
- lib/seafoam/passes.rb
|
84
86
|
- lib/seafoam/passes/fallback.rb
|
85
87
|
- lib/seafoam/passes/graal.rb
|