seafoam 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/.github/probots.yml +2 -0
  3. data/.github/workflows/rubocop.yml +10 -0
  4. data/.github/workflows/specs.yml +19 -0
  5. data/.gitignore +7 -0
  6. data/.rubocop.yml +34 -0
  7. data/.ruby-version +1 -0
  8. data/.seafoam/config +1 -0
  9. data/CODE_OF_CONDUCT.md +128 -0
  10. data/CONTRIBUTING.md +5 -0
  11. data/Gemfile +2 -0
  12. data/LICENSE.md +7 -0
  13. data/README.md +298 -0
  14. data/bin/bgv2isabelle +53 -0
  15. data/bin/bgv2json +42 -0
  16. data/bin/seafoam +24 -0
  17. data/docs/annotators.md +43 -0
  18. data/docs/bgv.md +284 -0
  19. data/docs/getting-graphs.md +47 -0
  20. data/examples/Fib.java +24 -0
  21. data/examples/MatMult.java +39 -0
  22. data/examples/fib-java.bgv +0 -0
  23. data/examples/fib-js.bgv +0 -0
  24. data/examples/fib-ruby.bgv +0 -0
  25. data/examples/fib.js +15 -0
  26. data/examples/fib.rb +15 -0
  27. data/examples/identity.bgv +0 -0
  28. data/examples/identity.rb +13 -0
  29. data/examples/java/Irreducible.j +35 -0
  30. data/examples/java/IrreducibleDecompiled.java +21 -0
  31. data/examples/java/JavaExamples.java +418 -0
  32. data/examples/java/exampleArithOperator.bgv +0 -0
  33. data/examples/java/exampleArithOperator.cfg +925 -0
  34. data/examples/java/exampleArrayAllocation.bgv +0 -0
  35. data/examples/java/exampleArrayAllocation.cfg +5268 -0
  36. data/examples/java/exampleArrayRead.bgv +0 -0
  37. data/examples/java/exampleArrayRead.cfg +2263 -0
  38. data/examples/java/exampleArrayWrite.bgv +0 -0
  39. data/examples/java/exampleArrayWrite.cfg +2315 -0
  40. data/examples/java/exampleCatch.bgv +0 -0
  41. data/examples/java/exampleCatch.cfg +4150 -0
  42. data/examples/java/exampleCompareOperator.bgv +0 -0
  43. data/examples/java/exampleCompareOperator.cfg +1109 -0
  44. data/examples/java/exampleDoubleSynchronized.bgv +0 -0
  45. data/examples/java/exampleDoubleSynchronized.cfg +26497 -0
  46. data/examples/java/exampleExactArith.bgv +0 -0
  47. data/examples/java/exampleExactArith.cfg +1888 -0
  48. data/examples/java/exampleFieldRead.bgv +0 -0
  49. data/examples/java/exampleFieldRead.cfg +1228 -0
  50. data/examples/java/exampleFieldWrite.bgv +0 -0
  51. data/examples/java/exampleFieldWrite.cfg +1102 -0
  52. data/examples/java/exampleFor.bgv +0 -0
  53. data/examples/java/exampleFor.cfg +3936 -0
  54. data/examples/java/exampleFullEscape.bgv +0 -0
  55. data/examples/java/exampleFullEscape.cfg +5893 -0
  56. data/examples/java/exampleIf.bgv +0 -0
  57. data/examples/java/exampleIf.cfg +2462 -0
  58. data/examples/java/exampleIfNeverTaken.bgv +0 -0
  59. data/examples/java/exampleIfNeverTaken.cfg +2476 -0
  60. data/examples/java/exampleInstanceOfManyImpls.bgv +0 -0
  61. data/examples/java/exampleInstanceOfManyImpls.cfg +6391 -0
  62. data/examples/java/exampleInstanceOfOneImpl.bgv +0 -0
  63. data/examples/java/exampleInstanceOfOneImpl.cfg +2604 -0
  64. data/examples/java/exampleIntSwitch.bgv +0 -0
  65. data/examples/java/exampleIntSwitch.cfg +3121 -0
  66. data/examples/java/exampleInterfaceCallManyImpls.bgv +0 -0
  67. data/examples/java/exampleInterfaceCallManyImpls.cfg +1358 -0
  68. data/examples/java/exampleInterfaceCallOneImpl.bgv +0 -0
  69. data/examples/java/exampleInterfaceCallOneImpl.cfg +3859 -0
  70. data/examples/java/exampleLocalInstanceOf.bgv +0 -0
  71. data/examples/java/exampleLocalInstanceOf.cfg +5276 -0
  72. data/examples/java/exampleLocalSynchronized.bgv +0 -0
  73. data/examples/java/exampleLocalSynchronized.cfg +1364 -0
  74. data/examples/java/exampleLocalVariables.bgv +0 -0
  75. data/examples/java/exampleLocalVariables.cfg +1195 -0
  76. data/examples/java/exampleLocalVariablesState.bgv +0 -0
  77. data/examples/java/exampleLocalVariablesState.cfg +1673 -0
  78. data/examples/java/exampleNestedWhile.bgv +0 -0
  79. data/examples/java/exampleNestedWhile.cfg +15499 -0
  80. data/examples/java/exampleNestedWhileBreak.bgv +0 -0
  81. data/examples/java/exampleNestedWhileBreak.cfg +11162 -0
  82. data/examples/java/exampleNoEscape.bgv +0 -0
  83. data/examples/java/exampleNoEscape.cfg +974 -0
  84. data/examples/java/exampleObjectAllocation.bgv +0 -0
  85. data/examples/java/exampleObjectAllocation.cfg +5287 -0
  86. data/examples/java/examplePartialEscape.bgv +0 -0
  87. data/examples/java/examplePartialEscape.cfg +7042 -0
  88. data/examples/java/examplePhi.bgv +0 -0
  89. data/examples/java/examplePhi.cfg +3227 -0
  90. data/examples/java/exampleReducible.bgv +0 -0
  91. data/examples/java/exampleReducible.cfg +5578 -0
  92. data/examples/java/exampleSimpleCall.bgv +0 -0
  93. data/examples/java/exampleSimpleCall.cfg +1435 -0
  94. data/examples/java/exampleStamp.bgv +0 -0
  95. data/examples/java/exampleStamp.cfg +913 -0
  96. data/examples/java/exampleStaticCall.bgv +0 -0
  97. data/examples/java/exampleStaticCall.cfg +1154 -0
  98. data/examples/java/exampleStringSwitch.bgv +0 -0
  99. data/examples/java/exampleStringSwitch.cfg +15377 -0
  100. data/examples/java/exampleSynchronized.bgv +0 -0
  101. data/examples/java/exampleSynchronized.cfg +26027 -0
  102. data/examples/java/exampleThrow.bgv +0 -0
  103. data/examples/java/exampleThrow.cfg +780 -0
  104. data/examples/java/exampleThrowCatch.bgv +0 -0
  105. data/examples/java/exampleThrowCatch.cfg +744 -0
  106. data/examples/java/exampleUnsafeRead.bgv +0 -0
  107. data/examples/java/exampleUnsafeRead.cfg +912 -0
  108. data/examples/java/exampleUnsafeWrite.bgv +0 -0
  109. data/examples/java/exampleUnsafeWrite.cfg +962 -0
  110. data/examples/java/exampleWhile.bgv +0 -0
  111. data/examples/java/exampleWhile.cfg +3936 -0
  112. data/examples/java/exampleWhileBreak.bgv +0 -0
  113. data/examples/java/exampleWhileBreak.cfg +5963 -0
  114. data/examples/matmult-java.bgv +0 -0
  115. data/examples/matmult-ruby.bgv +0 -0
  116. data/examples/matmult.rb +29 -0
  117. data/examples/overflow.bgv +0 -0
  118. data/examples/overflow.rb +13 -0
  119. data/lib/seafoam.rb +13 -0
  120. data/lib/seafoam/annotators.rb +54 -0
  121. data/lib/seafoam/annotators/fallback.rb +27 -0
  122. data/lib/seafoam/annotators/graal.rb +376 -0
  123. data/lib/seafoam/bgv/bgv_parser.rb +602 -0
  124. data/lib/seafoam/binary/binary_reader.rb +21 -0
  125. data/lib/seafoam/binary/io_binary_reader.rb +88 -0
  126. data/lib/seafoam/colors.rb +18 -0
  127. data/lib/seafoam/commands.rb +447 -0
  128. data/lib/seafoam/config.rb +34 -0
  129. data/lib/seafoam/graph.rb +91 -0
  130. data/lib/seafoam/graphviz_writer.rb +213 -0
  131. data/lib/seafoam/spotlight.rb +28 -0
  132. data/lib/seafoam/version.rb +5 -0
  133. data/seafoam.gemspec +20 -0
  134. data/spec/seafoam/annotators/fallback_spec.rb +69 -0
  135. data/spec/seafoam/annotators/graal_spec.rb +96 -0
  136. data/spec/seafoam/annotators_spec.rb +61 -0
  137. data/spec/seafoam/bgv/bgv_parser_spec.rb +144 -0
  138. data/spec/seafoam/bgv/fixtures/not.bgv +1 -0
  139. data/spec/seafoam/bgv/fixtures/unsupported.bgv +1 -0
  140. data/spec/seafoam/binary/io_binary_reader_spec.rb +176 -0
  141. data/spec/seafoam/command_spec.rb +252 -0
  142. data/spec/seafoam/graph_spec.rb +172 -0
  143. data/spec/seafoam/graphviz_writer_spec.rb +63 -0
  144. data/spec/seafoam/spec_helpers.rb +30 -0
  145. data/spec/seafoam/spotlight_spec.rb +38 -0
  146. data/tools/render-all +36 -0
  147. metadata +238 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 841e61f7601b4121b7367e9974b9920f8b8513fd6ca7a827c1be0e340bc2b3cf
4
+ data.tar.gz: 559e28e6b6a49964f31ac73bc1b1ed8c72fefae9d81381bb3e433bc39d57d0d7
5
+ SHA512:
6
+ metadata.gz: 75c306c0d6b9b8dffae51f62538a6b5e529150b59e5b6ea6ccbcf1b27ca9505fc8b7548086f2826d4f9bb8589648e2281e750a2caabd7b91f7da164065756883
7
+ data.tar.gz: c0c307acef6945d1841cc23d2cf5c00bbc52ed70cd74aaa95fc9365f83e796379b86009a16eef522b849e6a279b147e4d8350291b5fcdbebfa81d2ef4178bed5
@@ -0,0 +1,2 @@
1
+ enabled:
2
+ - cla
@@ -0,0 +1,10 @@
1
+ name: Rubocop
2
+ on: [push]
3
+ jobs:
4
+ rubocop:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v2
8
+ - uses: ruby/setup-ruby@v1
9
+ - run: bundle install
10
+ - run: bundle exec rubocop
@@ -0,0 +1,19 @@
1
+ name: Specs
2
+ on: [push]
3
+ jobs:
4
+ specs:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu, macos]
9
+ ruby: [2.5, 2.6, 2.7]
10
+ runs-on: ${{ matrix.os }}-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: if [[ $(uname) == "Darwin" ]]; then brew install graphviz; else sudo apt-get install graphviz; fi
18
+ - run: bundle install
19
+ - run: bundle exec rspec
@@ -0,0 +1,7 @@
1
+ *.pdf
2
+ *.dot
3
+ *.png
4
+ *.svg
5
+ *.class
6
+ /.idea
7
+ /Gemfile.lock
@@ -0,0 +1,34 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - examples/*
5
+
6
+ Style/FrozenStringLiteralComment:
7
+ Enabled: false
8
+
9
+ Style/MutableConstant:
10
+ Enabled: false
11
+
12
+ Metrics:
13
+ Enabled: false
14
+
15
+ Lint/EmptyWhen:
16
+ Enabled: false
17
+
18
+ Style/ConditionalAssignment:
19
+ Enabled: false
20
+
21
+ Style/GuardClause:
22
+ Enabled: false
23
+
24
+ Style/IfUnlessModifier:
25
+ Enabled: false
26
+
27
+ Lint/InterpolationCheck:
28
+ Enabled: false
29
+
30
+ Security/Eval:
31
+ Enabled: false
32
+
33
+ Naming/FileName:
34
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.5.8
@@ -0,0 +1 @@
1
+ # Empty configuration file
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ opensource@shopify.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,5 @@
1
+ # Contribution
2
+
3
+ Contributions welcome. Please discuss big ideas in an issue first.
4
+
5
+ You'll need to sign the Shopify Contributor License Agreement (CLA) https://cla.shopify.com/.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,7 @@
1
+ Copyright 2019-present, Shopify Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,298 @@
1
+ # Seafoam
2
+
3
+ *Seafoam* is a tool for working with compiler graphs. It's designed primarily
4
+ for working with the graph files dumped by the GraalVM compiler, such as in
5
+ TruffleRuby, but it could be used with other compilers and graph dump file
6
+ formats.
7
+
8
+ The *Ideal Graph Visualizer*, or *IGV*, is the tool usually used to work with
9
+ GraalVM compiler graphs. Seafoam aims to solve several problems with IGV. Unlike
10
+ IGV, Seafoam:
11
+
12
+ * is open source and can be used according to the MIT license
13
+ * is able to some extent seek BGV files to load specific graphs without loading the rest of the file
14
+ * has a command-line interface
15
+ * can be used as a library
16
+ * has easy PDF, SVG and PNG output
17
+ * is designed for accessibility
18
+ * looks prettier, in our opinion
19
+
20
+ Admittedly, Seafoam does not yet have:
21
+
22
+ * an interactive user interface
23
+ * diffing of graphs
24
+ * visualization of basic blocks
25
+ * breaking of edges for very congested graphs
26
+ * the same speed in rendering big graphs - Seafoam is best suited for looking at graphs before lowering, which is what language developers are usually doing, or use spotlight
27
+
28
+ ## Seafoam compared to IGV
29
+
30
+ <p>
31
+ <img src="docs/images/seafoam.png" width="350">
32
+ <img src="docs/images/igv.png" width="350">
33
+ </p>
34
+
35
+ ## Installation
36
+
37
+ ### macOS
38
+
39
+ ```
40
+ $ brew install graphviz
41
+ $ gem install seafoam
42
+ $ seafoam --version
43
+ seafoam 0.1
44
+ ```
45
+
46
+ ### Ubuntu
47
+
48
+ ```
49
+ $ sudo apt-get install ruby graphviz
50
+ $ gem install seafoam
51
+ $ seafoam --version
52
+ seafoam 0.1
53
+ ```
54
+
55
+ #### RedHat
56
+
57
+ ```
58
+ $ sudo yum install ruby graphviz
59
+ $ gem install seafoam
60
+ $ seafoam --version
61
+ seafoam 0.1
62
+ ```
63
+
64
+ ## Quick-start demo
65
+
66
+ ```
67
+ $ seafoam examples/fib-java.bgv:0 render
68
+ ```
69
+
70
+ ## Getting compiler graphs
71
+
72
+ If you are just experimenting, there are example graphs such as
73
+ `examples/fib-java.bgv`.
74
+
75
+ This is just a quick summary - see more information on
76
+ [getting graphs out of compilers](docs/getting-graphs.md).
77
+
78
+ ### GraalVM for Java
79
+
80
+ ```
81
+ $ javac Fib.java
82
+ $ java -XX:CompileOnly=::fib -Dgraal.Dump=:2 Fib 14
83
+ ```
84
+
85
+ ### TruffleRuby and other Truffle languages
86
+
87
+ ```
88
+ $ ruby --experimental-options --engine.CompileOnly=fib --engine.Inlining=false --engine.OSR=false --vm.Dgraal.Dump=Truffle:2 fib.rb 14
89
+ ```
90
+
91
+ You will usually want to look at the *After TruffleTier* graph.
92
+
93
+ ## Name syntax
94
+
95
+ When using a command-line interface, Seafoam refers to
96
+ `file.bgv[:graph][:node[-edge]]`, where `file.bgv` is a file, `graph` is a graph
97
+ index, `node` is a node index, and `to` is another node index to form an edge
98
+ from `node` to another node `edge`.
99
+
100
+ Note that a *graph ID* is an ID found in BGV files, but is not unique. A
101
+ *graph index* is what we use in names, and is unique.
102
+
103
+ ## Use cases
104
+
105
+ #### Print information about a file
106
+
107
+ ```
108
+ $ seafoam examples/fib-java.bgv info
109
+ BGV 6.1
110
+ ```
111
+
112
+ #### List graphs in a file
113
+
114
+ ```
115
+ $ seafoam examples/fib-java.bgv list
116
+ examples/fib-java.bgv:0 2:Fib.fib(int)/After phase org.graalvm.compiler.java.GraphBuilderPhase
117
+ examples/fib-java.bgv:1 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.PhaseSuite
118
+ examples/fib-java.bgv:2 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.DeadCodeEliminationPhase
119
+ examples/fib-java.bgv:3 2:Fib.fib(int)/After parsing
120
+ examples/fib-java.bgv:4 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.CanonicalizerPhase
121
+ examples/fib-java.bgv:5 2:Fib.fib(int)/After phase org.graalvm.compiler.phases.common.inlining.InliningPhase
122
+ ...
123
+ ```
124
+
125
+ #### Search for strings in a graph, or node or edge within a graph
126
+
127
+ ```
128
+ $ seafoam examples/fib-java.bgv:0 search Start
129
+ examples/fib-java.bgv:0:0 ...node_class":"org.graalvm.compiler.nodes.StartNode","name_template":"Start","inputs":[...
130
+ examples/fib-java.bgv:0:0 ...piler.nodes.StartNode","name_template":"Start","inputs":[{"direct":true,"name":"state...
131
+ ```
132
+
133
+ #### Print edges of a graph, or node or edge within a graph
134
+
135
+ ```
136
+ $ seafoam examples/fib-java.bgv:0 edges
137
+ 22 nodes, 30 edges
138
+ $ seafoam examples/fib-java.bgv:0:13 edges
139
+ Input:
140
+ 13 (Call Fib.fib) <-() 6 (Begin)
141
+ 13 (Call Fib.fib) <-() 14 (@{:declaring_class=>"Fib", :method_name=>"fib", :signature=>{:args=>["I"], :ret=>"I"}, :modifiers=>9}:13)
142
+ 13 (Call Fib.fib) <-() 12 (MethodCallTarget)
143
+ Output:
144
+ 13 (Call Fib.fib) ->() 18 (Call Fib.fib)
145
+ 13 (Call Fib.fib) ->(values) 14 (@{:declaring_class=>"Fib", :method_name=>"fib", :signature=>{:args=>["I"], :ret=>"I"}, :modifiers=>9}:13)
146
+ 13 (Call Fib.fib) ->(values) 19 (@{:declaring_class=>"Fib", :method_name=>"fib", :signature=>{:args=>["I"], :ret=>"I"}, :modifiers=>9}:19)
147
+ 13 (Call Fib.fib) ->(x) 20 (+)
148
+ $ seafoam examples/fib-java.bgv:0:13-20 edges
149
+ 13 (Call Fib.fib) ->(x) 20 (+)
150
+ ```
151
+
152
+ #### Print properties of a file, graph, or node or edge within a graph
153
+
154
+ ```
155
+ $ seafoam examples/fib-java.bgv:0 props
156
+ {
157
+ "group": [
158
+ {
159
+ "name": "2:Fib.fib(int)",
160
+ "short_name": "2:Fib.fib(int)",
161
+ "method": null,
162
+ ...
163
+ $ seafoam examples/fib-java.bgv:0:13 props
164
+ {
165
+ "nodeSourcePosition": {
166
+ "method": {
167
+ "declaring_class": "Fib",
168
+ "method_name": "fib",
169
+ "signature": {
170
+ ...
171
+ $ seafoam examples/fib-java.bgv:0:13-20 props
172
+ {
173
+ "direct": true,
174
+ "name": "x",
175
+ "type": "Value"
176
+ }
177
+ ```
178
+
179
+ #### Render a graph
180
+
181
+ Render a graph as a PDF image and have it opened automatically.
182
+
183
+ ```
184
+ $ seafoam examples/fib-java.bgv:0 render
185
+ ```
186
+
187
+ Render a graph showing just a few nodes and those surrounding them, similar to
188
+ the IGV feature of gradually revealing nodes.
189
+
190
+ ```
191
+ $ seafoam examples/fib-java.bgv:0 render --spotlight 13,20
192
+ ```
193
+
194
+ <p>
195
+ <img src="docs/images/spotlight-seafoam.png" width="200">
196
+ <img src="docs/images/spotlight-igv.png" width="350">
197
+ </p>
198
+
199
+ `render` supports these options:
200
+
201
+ * `--out filename.pdf` or `.pdf`, `.svg`, `.png`, `.dot`
202
+ * `--option key value` for custom annotators
203
+
204
+ #### Convert a file
205
+
206
+ Convert a BGV file to the Isabelle graph format.
207
+
208
+ ```
209
+ $ bgv2isabelle examples/fib-java.bgv
210
+ graph0 = # 2:Fib.fib(int)/After phase org.graalvm.compiler.java.GraphBuilderPhase
211
+ (add_node 0 StartNode [2] [8]
212
+ (add_node 1 (ParameterNode 0) [] [2, 5, 9, 11, 14, 16]
213
+ (add_node 2 FrameState [1] [0]
214
+ (add_node 3 (ConstantNode 1) [] []
215
+ (add_node 4 (ConstantNode 2) [] [5]
216
+ (add_node 5 IntegerLessThanNode [1, 4] [8]
217
+ (add_node 6 BeginNode [8] [13]
218
+ (add_node 7 BeginNode [8] [9]
219
+ (add_node 8 IfNode [0, 5] [7, 6]
220
+ ...
221
+ ```
222
+
223
+ ## Options for GraalVM graphs
224
+
225
+ * `--show-frame-state` shows frame state nodes, which are hidden by default
226
+ * `--hide-floating` hides nodes that aren't fixed by control flow
227
+ * `--no-reduce-edges` turns off the option to reduce the number of edges by inlining simple nodes above their users
228
+
229
+ ## Configuration
230
+
231
+ Seafoam loads and runs a Ruby script called `~/.seafoam/config` in the first
232
+ directory it finds starting with the current working directory and moving up.
233
+ You can require or configure extra [annotators](docs/annotators.md) in this
234
+ file.
235
+
236
+ ## Debugging
237
+
238
+ Exception backtraces are printed if `$DEBUG` (`-d`) is set.
239
+
240
+ Use `seafoam file.bgv debug` to debug file parsing.
241
+
242
+ ## More documentation
243
+
244
+ * [Graph annotators](docs/annotators.md)
245
+ * [Details of the BGV file format](docs/bgv.md)
246
+ * [How to get graphs from various compilers](docs/getting-graphs.md)
247
+
248
+ ## Frequently asked questions
249
+
250
+ #### Why is it called *Seafoam*?
251
+
252
+ GraalVM graphs are *seas of nodes*. Seafoam is a shade of green, and Seafoam was
253
+ written at Shopify, which has green as a brand colour. Graphs can sometimes be
254
+ very complicated, appearing like a foam without any structure - Seafoam tries to
255
+ help you make sense of it all.
256
+
257
+ #### What do you mean by *graphs*, and *seas* or *soups* of nodes?
258
+
259
+ Graphs, as in edges and nodes, are the data structure some compilers use to
260
+ represent your program while they're compiling it. It's a form of *intermediate
261
+ representation*. Graphs are how the compiler understands the programs and if the
262
+ compiler isn't doing what you want you need to look at the graph and make sense
263
+ of it. Some graphs are loosely structured and large, making them like a sea or
264
+ soup of nodes.
265
+
266
+ #### Doesn't *reduce edges* actually introduce more edges?
267
+
268
+ Yes, but they're shorter edges, and it achieves the intended effect of less
269
+ edges crossing over the graph.
270
+
271
+ ## Related work
272
+
273
+ The graph layout algorithm we use, via Graphviz, is
274
+
275
+ * E. R. Gansner, et al, [*A Technique for Drawing Directed Graphs*](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.3.8982), IEEE Transactions on Software Engineering, 1993
276
+
277
+ IGV is the existing tool for working with Graal graphs. It uses a *hierarchical*
278
+ layout algorithm, rather than the *force directed* algorithm we use when we use
279
+ Graphviz. It's based on the NetBeans IDE platform. It's related to the *C1
280
+ Visualiser*, for control-flow graphs. The C1 Visualiser can also be used with
281
+ Graal as the backend of Graal is similar enough to C1. IGV is closed-source and
282
+ available under a proprietary licence.
283
+
284
+ * T. Würthinger, [*Visualization of Program Dependence Graphs*](http://www.ssw.uni-linz.ac.at/Research/Papers/Wuerthinger07Master/), Master Thesis, Linz 2007
285
+ * T. Würthinger, [*Visualization of Java Control Flow Graphs*](http://www.ssw.uni-linz.ac.at/General/Staff/TW/Wuerthinger06Bachelor.pdf), Bachelor Thesis, Linz 2006
286
+
287
+ [*Turbolizer*][turbolizer] is a similar tool for the intermediate representation
288
+ in the V8 JavaScript compiler.
289
+
290
+ [turbolizer]: https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/tools/turbolizer
291
+
292
+ ## Author
293
+
294
+ Seafoam was written by Chris Seaton at Shopify, chris.seaton@shopify.com.
295
+
296
+ ## License
297
+
298
+ MIT