summaryrefslogtreecommitdiff
path: root/graph/src
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-10-01 12:01:57 -0700
committerCliff Click <cliffc@acm.org>2026-10-01 12:01:57 -0700
commit5ea32e69433d0c850d02bbc1e6c4a260bc095fec (patch)
treeba4917ded278097332ee8f9f33227be74d3ac104 /graph/src
parentbf7f603dd4e8ec781fe578243cdc18180322420b (diff)
downloadSimple-5ea32e69433d0c850d02bbc1e6c4a260bc095fec.tar.gz
Simple-5ea32e69433d0c850d02bbc1e6c4a260bc095fec.zip
Move debug printing into shared space
Same as the graph viewer, moves a lot of code out of all Nodes
Diffstat (limited to 'graph/src')
-rw-r--r--graph/src/main/java/com/seaofnodes/graph/GraphAdapter.java46
-rw-r--r--graph/src/main/java/com/seaofnodes/graph/GraphCapture.java3
2 files changed, 37 insertions, 12 deletions
diff --git a/graph/src/main/java/com/seaofnodes/graph/GraphAdapter.java b/graph/src/main/java/com/seaofnodes/graph/GraphAdapter.java
index eaa308f9..9014ce04 100644
--- a/graph/src/main/java/com/seaofnodes/graph/GraphAdapter.java
+++ b/graph/src/main/java/com/seaofnodes/graph/GraphAdapter.java
@@ -1,5 +1,7 @@
package com.seaofnodes.graph;
+import com.seaofnodes.print.BaseNode;
+import static com.seaofnodes.graph.GraphSnapshot.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@@ -10,18 +12,40 @@ import java.util.Comparator;
* Capture on the compiler thread, while the graph is not being modified.
* Hooks must only read the IR: no computing types, peepholes or scheduling.
*/
-public abstract class GraphAdapter<N> {
- protected abstract int id(N node);
- protected abstract int nIns(N node);
- protected abstract N in(N node, int idx);
- protected abstract int nOuts(N node);
- protected abstract N out(N node, int idx);
- protected abstract GraphSnapshot.Node desc(N node);
- protected abstract boolean dead(N node);
+public abstract class GraphAdapter<N extends BaseNode<N>> {
+ protected final int id(N n) { return n._nid; }
+ protected final int nIns(N n) { return n.nIns(); }
+ protected final N in(N n, int i) { return n.in(i); }
+ protected final int nOuts(N n) { return n.nOuts(); }
+ protected final N out(N n, int i) { return n.out(i); }
+ protected final boolean dead(N n) { return n.isDead(); }
+ protected final int nDeps(N n) { return n.nDeps(); }
+ protected final N dep(N n, int i) { return n.dep(i); }
+
+ // Chapters supply only semantic distinctions that their IR has introduced.
+ protected Kind kind(N n) { return n.isCFG() ? Kind.CTRL : Kind.DATA; }
+ protected Role role(N n, int i) { return i==0 ? Role.CTRL : Role.DATA; }
+ protected String[] edgeNames(N n) { return null; }
+ protected String edgeName(N n, int i) { return null; }
+ protected int edgeJump(N n, int i) { return 0; }
+ protected int projectionIndex(N n) { return -1; }
+ protected boolean folding(N n) { return false; }
// Omit cached helpers with no graph uses; still walk through them.
- protected boolean show(N node) { return true; }
- protected int nDeps(N node) { return 0; }
- protected N dep(N node, int idx) { throw new IndexOutOfBoundsException(idx); }
+ protected boolean show(N n) { return true; }
+
+ protected final GraphSnapshot.Node desc(N n) {
+ var edges=new ArrayList<Edge>();
+ String[] names=edgeNames(n);
+ for( int i=0; i<n.nIns(); i++ ) {
+ String name=names!=null && i<names.length ? names[i] : edgeName(n,i);
+ edges.add(new Edge(i,ref(n.in(i)),role(n,i),name,edgeJump(n,i)));
+ }
+ int idx=projectionIndex(n);
+ Projection proj=idx<0 ? null : new Projection(n.nIns()==0 ? 0 : ref(n.in(0)),idx);
+ String label=n.label();
+ return new GraphSnapshot.Node(n._nid,label==null ? n.getClass().getSimpleName() : label,
+ n.typeName(),kind(n),edges,proj,folding(n));
+ }
protected final int ref(N node) { return node == null ? 0 : id(node); }
diff --git a/graph/src/main/java/com/seaofnodes/graph/GraphCapture.java b/graph/src/main/java/com/seaofnodes/graph/GraphCapture.java
index 966dd701..10071755 100644
--- a/graph/src/main/java/com/seaofnodes/graph/GraphCapture.java
+++ b/graph/src/main/java/com/seaofnodes/graph/GraphCapture.java
@@ -1,12 +1,13 @@
package com.seaofnodes.graph;
+import com.seaofnodes.print.BaseNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.UUID;
/** Shared compilation lifecycle, capture, event nesting and neighborhoods. */
-public abstract class GraphCapture<N> extends GraphObserver<N> {
+public abstract class GraphCapture<N extends BaseNode<N>> extends GraphObserver<N> {
private final GraphAdapter<N> _graph;
private String _comp;