summaryrefslogtreecommitdiff
path: root/chapter04
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2024-06-21 06:13:09 -0700
committerGitHub <noreply@github.com>2024-06-21 14:13:09 +0100
commite5f4f7b85fbb91a293a7d89d7b85adfbaeeb51f4 (patch)
tree9b6ecc7ef37b1ec7f08efed6f908f478dc551e03 /chapter04
parenta749c244bea3e2774d453165cbd18ed52863a8f5 (diff)
downloadSimple-e5f4f7b85fbb91a293a7d89d7b85adfbaeeb51f4.tar.gz
Simple-e5f4f7b85fbb91a293a7d89d7b85adfbaeeb51f4.zip
Format whitespace (#86)
* Trim trailing whitespace * Ensure final new lines * Convert line endings from CRLF to LF * Replace tabs with spaces
Diffstat (limited to 'chapter04')
-rw-r--r--chapter04/README.md14
-rw-r--r--chapter04/docs/04-grammar.md16
-rw-r--r--chapter04/docs/04-post-peephole.gv2
-rw-r--r--chapter04/docs/04-pre-peephole.gv2
-rw-r--r--chapter04/docs/build-graphs.sh1
-rw-r--r--chapter04/docs/lattice.gv2
-rw-r--r--chapter04/pom.xml2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/GraphVisualizer.java14
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/Parser.java12
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/Utils.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/AddNode.java16
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/BoolNode.java4
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/ConstantNode.java6
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/DivNode.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/MinusNode.java6
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/MulNode.java8
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/MultiNode.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/Node.java26
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/NotNode.java6
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/ProjNode.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/ReturnNode.java4
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/ScopeNode.java6
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/StartNode.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/node/SubNode.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/type/Type.java4
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/type/TypeInteger.java2
-rw-r--r--chapter04/src/main/java/com/seaofnodes/simple/type/TypeTuple.java2
-rw-r--r--chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java18
28 files changed, 92 insertions, 93 deletions
diff --git a/chapter04/README.md b/chapter04/README.md
index 4ae4d432..03c6c53f 100644
--- a/chapter04/README.md
+++ b/chapter04/README.md
@@ -19,7 +19,7 @@ Following are revised or new nodes
|-----------|----------------|------------------------------------------------|-----------------------|----------------------------------------------------------------------------|
| MultiNode | Abstract class | A node that has a tuple result | | A tuple |
| Start | Control | Start of function, now a MultiNode | | A tuple with a ctrl token and an `arg` data node |
-| Proj | Data | Projection nodes extract values from MultiNode | A MultiNode and index | Result is the extracted value from the input MultiNode at offset index |
+| Proj | Data | Projection nodes extract values from MultiNode | A MultiNode and index | Result is the extracted value from the input MultiNode at offset index |
| Bool | Data | Represents results of a comparison operator | Two data nodes | Result is a comparison, represented as integer value where 1=true, 0=false |
| Not | Data | Logical not | One data node | Result converts 0 to 1 and vice versa |
@@ -51,7 +51,7 @@ Start node.
## Changes to Type System
-In [Chapter 2](../chapter02/README.md) we introduced the Type System.
+In [Chapter 2](../chapter02/README.md) we introduced the Type System.
We annotate Nodes with Types.
@@ -128,7 +128,7 @@ clutter and help draw reader's attention to the more important aspects of the gr
## More Peephole Optimizations
-Now that we have non-constant integer values, we do additional optimizations, rearranging algebraic
+Now that we have non-constant integer values, we do additional optimizations, rearranging algebraic
expressions to enable constant folding. For example:
```
@@ -162,9 +162,9 @@ Here is a (partial) list of peepholes introduced in this Chapter:
| ((arg1 + con) + arg2) | ((arg1 + arg2) + con) | Move constants to right, to encourage folding |
| (arg + arg) | (arg * 2) | Sum-of-products form |
-## Code Walkthrough
+## Code Walkthrough
-The peephole optimizations introduced in this chapter are local. They are triggered during parsing
+The peephole optimizations introduced in this chapter are local. They are triggered during parsing
as new nodes are created, before the newly created node has any uses.
For example, when we parse a unary expression, and create a Node for the parsed expression,
@@ -199,7 +199,7 @@ by all subclasses of `Node`.
public final Node peephole( ) {
// Compute initial or improved Type
Type type = _type = compute();
-
+
// Replace constant computations from non-constants with a constant node
if (!(this instanceof ConstantNode) && type.isConstant())
return deadCodeElim(new ConstantNode(type).peephole());
@@ -209,7 +209,7 @@ public final Node peephole( ) {
if( n != null ) // Something changed
// Recursively optimize
return deadCodeElim(n.peephole());
-
+
return this; // No progress
}
```
diff --git a/chapter04/docs/04-grammar.md b/chapter04/docs/04-grammar.md
index 51d5dbea..48facd4c 100644
--- a/chapter04/docs/04-grammar.md
+++ b/chapter04/docs/04-grammar.md
@@ -10,7 +10,7 @@ program
statement
: returnStatement
| declStatement
- | blockStatment
+ | blockStatment
| expressionStatement
| metaStatement
;
@@ -38,15 +38,15 @@ returnStatement
expression
: comparisonExpression
;
-
+
comparisonExpression
: additiveExpression (('==' | '!='| '>'| '<'| '>='| '<=') additiveExpression)*
;
-
+
additiveExpression
- : multiplicativeExpression (('+' | '-') multiplicativeExpression)*
+ : multiplicativeExpression (('+' | '-') multiplicativeExpression)*
;
-
+
multiplicativeExpression
: unaryExpression (('*' | '/') unaryExpression)*
;
@@ -66,11 +66,11 @@ INTEGER_LITERAL
: [1-9][0-9]*
| [0]
;
-
+
IDENTIFIER
: NON_DIGIT (NON_DIGIT | DIGIT)*
;
-
+
NON_DIGIT: [a-zA-Z_];
DEC_DIGIT: [0-9];
-``` \ No newline at end of file
+```
diff --git a/chapter04/docs/04-post-peephole.gv b/chapter04/docs/04-post-peephole.gv
index 51e176bc..0a9f8e93 100644
--- a/chapter04/docs/04-post-peephole.gv
+++ b/chapter04/docs/04-post-peephole.gv
@@ -40,4 +40,4 @@ return 1+arg+2; #showGraph;
Return12 -> Add11[taillabel=1];
edge [style=dashed color=cornflowerblue];
Scope1_0:"Scope1_0_arg" -> Start2:p1;
-} \ No newline at end of file
+}
diff --git a/chapter04/docs/04-pre-peephole.gv b/chapter04/docs/04-pre-peephole.gv
index b6fefc2d..aefd81c4 100644
--- a/chapter04/docs/04-pre-peephole.gv
+++ b/chapter04/docs/04-pre-peephole.gv
@@ -44,4 +44,4 @@ return 1+arg+2; #showGraph;
Return9 -> Add8[taillabel=1];
edge [style=dashed color=cornflowerblue];
Scope1_0:"Scope1_0_arg" -> Start2:p1;
-} \ No newline at end of file
+}
diff --git a/chapter04/docs/build-graphs.sh b/chapter04/docs/build-graphs.sh
index d8038602..e736a386 100644
--- a/chapter04/docs/build-graphs.sh
+++ b/chapter04/docs/build-graphs.sh
@@ -1,2 +1 @@
dot -Tsvg lattice.gv > lattice.svg
-
diff --git a/chapter04/docs/lattice.gv b/chapter04/docs/lattice.gv
index 2644448e..1f286530 100644
--- a/chapter04/docs/lattice.gv
+++ b/chapter04/docs/lattice.gv
@@ -60,4 +60,4 @@ digraph Lattice {
INT_MAX; TUPLE}
{rank=same; INT_BOT}
{rank=same; BOT;}
-} \ No newline at end of file
+}
diff --git a/chapter04/pom.xml b/chapter04/pom.xml
index a69df6d0..0fdebb14 100644
--- a/chapter04/pom.xml
+++ b/chapter04/pom.xml
@@ -11,4 +11,4 @@
<artifactId>chapter04</artifactId>
<packaging>jar</packaging>
<name>Chapter 4</name>
-</project> \ No newline at end of file
+</project>
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/GraphVisualizer.java b/chapter04/src/main/java/com/seaofnodes/simple/GraphVisualizer.java
index f624cbde..62b434f3 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/GraphVisualizer.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/GraphVisualizer.java
@@ -21,7 +21,7 @@ public class GraphVisualizer {
sb.append("/*\n");
sb.append(parser.src());
sb.append("\n*/\n");
-
+
// To keep the Scopes below the graph and pointing up into the graph we
// need to group the Nodes in a subgraph cluster, and the scopes into a
// different subgraph cluster. THEN we can draw edges between the
@@ -35,10 +35,10 @@ public class GraphVisualizer {
// Merge multiple edges hitting the same node. Makes common shared
// nodes much prettier to look at.
sb.append("\tconcentrate=\"true\";\n");
-
+
// Just the Nodes first, in a cluster no edges
nodes(sb, all);
-
+
// Now the scopes, in a cluster no edges
scopes(sb, parser._scope);
@@ -47,7 +47,7 @@ public class GraphVisualizer {
// Walk the Scope edges
scopeEdges(sb, parser._scope);
-
+
sb.append("}\n");
return sb.toString();
}
@@ -88,7 +88,7 @@ public class GraphVisualizer {
}
sb.append("</TR>\n");
sb.append("\t\t\t</TABLE>>\n\t\t");
-
+
} else {
// control nodes have box shape
// other nodes are ellipses, i.e. default shape
@@ -156,7 +156,7 @@ public class GraphVisualizer {
}
}
}
-
+
// Walk the scope edges
private void scopeEdges( StringBuilder sb, ScopeNode scopenode ) {
sb.append("\tedge [style=dashed color=cornflowerblue];\n");
@@ -179,7 +179,7 @@ public class GraphVisualizer {
level++;
}
}
-
+
/**
* Finds all nodes in the graph.
*/
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java
index b517d20e..e42613e2 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java
@@ -14,7 +14,7 @@ import java.util.*;
*/
public class Parser {
-
+
/**
* A Global Static, unique to each compilation. This is a public, so we
* can make constants everywhere without having to thread the StartNode
@@ -56,12 +56,12 @@ public class Parser {
@Override
public String toString() { return _lexer.toString(); }
-
+
String src() { return new String( _lexer._input ); }
// Debugging utility to find a Node by index
public static Node find(int nid) { return START.find(nid); }
-
+
private Node ctrl() { return _scope.ctrl(); }
private Node ctrl(Node n) { return _scope.ctrl(n); }
@@ -395,7 +395,7 @@ public class Parser {
skipWhiteSpace();
return peek()==ch;
}
-
+
// Return an identifier or null
String matchId() {
skipWhiteSpace();
@@ -422,7 +422,7 @@ public class Parser {
return TypeInteger.constant(Long.parseLong(snum));
}
- // First letter of an identifier
+ // First letter of an identifier
private boolean isIdStart(char ch) {
return Character.isAlphabetic(ch) || ch == '_';
}
@@ -438,7 +438,7 @@ public class Parser {
return new String(_input, start, --_position - start);
}
- //
+ //
private boolean isPunctuation(char ch) {
return "=;[]<>()+-/*".indexOf(ch) != -1;
}
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/Utils.java b/chapter04/src/main/java/com/seaofnodes/simple/Utils.java
index 4d663c25..45f15327 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/Utils.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/Utils.java
@@ -36,4 +36,4 @@ public class Utils {
return i;
return -1;
}
-} \ No newline at end of file
+}
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/AddNode.java
index d9fc6ad9..5720aca4 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/AddNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/AddNode.java
@@ -6,7 +6,7 @@ public class AddNode extends Node {
public AddNode(Node lhs, Node rhs) { super(null, lhs, rhs); }
@Override public String label() { return "Add"; }
-
+
@Override public String glabel() { return "+"; }
@Override
@@ -15,7 +15,7 @@ public class AddNode extends Node {
in(2)._print0(sb.append("+"));
return sb.append(")");
}
-
+
@Override
public Type compute() {
@@ -42,13 +42,13 @@ public class AddNode extends Node {
// canonicalize to (x+0)
if( t2 instanceof TypeInteger i && i.value()==0 )
return lhs;
-
+
// Add of same to a multiply by 2
if( lhs==rhs )
return new MulNode(lhs,new ConstantNode(TypeInteger.constant(2)).peephole());
// Goal: a left-spine set of adds, with constants on the rhs (which then fold).
-
+
// Move non-adds to RHS
if( !(lhs instanceof AddNode) && rhs instanceof AddNode )
return swap12();
@@ -66,19 +66,19 @@ public class AddNode extends Node {
return spline_cmp(lhs,rhs) ? swap12() : null;
// Now we only see (add add non)
-
+
// Do we have (x + con1) + con2?
// Replace with (x + (con1+con2) which then fold the constants
if( lhs.in(2)._type.isConstant() && t2.isConstant() )
return new AddNode(lhs.in(1),new AddNode(lhs.in(2),rhs).peephole());
// Now we sort along the spline via rotates, to gather similar things together.
-
+
// Do we rotate (x + y) + z
// into (x + z) + y ?
if( spline_cmp(lhs.in(2),rhs) )
return new AddNode(new AddNode(lhs.in(1),rhs).peephole(),lhs.in(2));
-
+
return null;
}
@@ -94,5 +94,5 @@ public class AddNode extends Node {
// Same category of "others"
return lo._nid > hi._nid;
}
-
+
}
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/BoolNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/BoolNode.java
index be3ee46c..05495790 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/BoolNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/BoolNode.java
@@ -10,7 +10,7 @@ abstract public class BoolNode extends Node {
}
abstract String op(); // String opcode name
-
+
@Override
public String label() { return getClass().getSimpleName(); }
@@ -39,7 +39,7 @@ abstract public class BoolNode extends Node {
@Override
public Node idealize() {
- // Compare of same
+ // Compare of same
if( in(1)==in(2) )
return new ConstantNode(TypeInteger.constant(doOp(3,3)?1:0));
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/ConstantNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/ConstantNode.java
index ba6f55d7..1086037d 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/ConstantNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/ConstantNode.java
@@ -21,10 +21,10 @@ public class ConstantNode extends Node {
super(Parser.START);
_con = type;
}
-
+
@Override
public String label() { return ""+_con; }
-
+
@Override
public String uniqueName() { return "Con_" + _nid; }
@@ -32,7 +32,7 @@ public class ConstantNode extends Node {
StringBuilder _print1(StringBuilder sb) {
return _con._print(sb);
}
-
+
@Override
public Type compute() { return _con; }
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/DivNode.java
index 86b1e95c..1404c900 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/DivNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/DivNode.java
@@ -16,7 +16,7 @@ public class DivNode extends Node {
in(2)._print0(sb.append("/"));
return sb.append(")");
}
-
+
@Override
public Type compute() {
if (in(1)._type instanceof TypeInteger i0 &&
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/MinusNode.java
index 08924563..0d59ef25 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/MinusNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/MinusNode.java
@@ -7,15 +7,15 @@ public class MinusNode extends Node {
public MinusNode(Node in) { super(null, in); }
@Override public String label() { return "Minus"; }
-
+
@Override public String glabel() { return "-"; }
-
+
@Override
StringBuilder _print1(StringBuilder sb) {
in(1)._print0(sb.append("(-"));
return sb.append(")");
}
-
+
@Override
public Type compute() {
if (in(1)._type instanceof TypeInteger i0)
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/MulNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/MulNode.java
index 19f2a340..36d5eb3e 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/MulNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/MulNode.java
@@ -7,7 +7,7 @@ public class MulNode extends Node {
public MulNode(Node lhs, Node rhs) { super(null, lhs, rhs); }
@Override public String label() { return "Mul"; }
-
+
@Override public String glabel() { return "*"; }
@Override
@@ -34,16 +34,16 @@ public class MulNode extends Node {
Node rhs = in(2);
Type t1 = lhs._type;
Type t2 = rhs._type;
-
+
// Mul of 1. We do not check for (1*x) because this will already
// canonicalize to (x*1)
if ( t2.isConstant() && t2 instanceof TypeInteger i && i.value()==1 )
return lhs;
-
+
// Move constants to RHS: con*arg becomes arg*con
if ( t1.isConstant() && !t2.isConstant() )
return swap12();
-
+
return null;
}
}
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/MultiNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/MultiNode.java
index 81c90f68..7ba1aa19 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/MultiNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/MultiNode.java
@@ -1,7 +1,7 @@
package com.seaofnodes.simple.node;
public abstract class MultiNode extends Node {
-
+
public MultiNode(Node... inputs) { super(inputs); }
}
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java
index bebfd3a1..9fa0a95a 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -74,9 +74,9 @@ public abstract class Node {
// ------------------------------------------------------------------------
-
+
// Debugger Printing.
-
+
// {@code toString} is what you get in the debugger. It has to print 1
// line (because this is what a debugger typically displays by default) and
// has to be robust with broken graph/nodes.
@@ -100,7 +100,7 @@ public abstract class Node {
// Every Node implements this.
abstract StringBuilder _print1(StringBuilder sb);
-
+
/**
* Gets the ith input node
* @param i Offset of the input node
@@ -117,19 +117,19 @@ public abstract class Node {
public boolean isUnused() { return nOuts() == 0; }
public boolean isCFG() { return false; }
-
+
/**
* Change a <em>def</em> into a Node. Keeps the edges correct, by removing
* the corresponding <em>use->def</em> edge. This may make the original
* <em>def</em> go dead. This function is co-recursive with {@link #kill}.
* <p>
-
+
* This method is the normal path for altering a Node, because it does the
* proper default edge maintenance. It also <em>immediately</em> kills
* Nodes that lose their last use; at times care must be taken to avoid
* killing Nodes that are being used without having an output Node. This
* definitely happens in the middle of recursive {@link #peephole} calls.
- *
+ *
* @param idx which def to set
* @param new_def the new definition
* @return new_def for flow coding
@@ -188,7 +188,7 @@ public abstract class Node {
old_def.kill(); // Kill old def
}
}
-
+
/**
* Kill a Node with no <em>uses</em>, by setting all of its <em>defs</em>
* to null. This may recursively kill more Nodes and is basically dead
@@ -211,7 +211,7 @@ public abstract class Node {
public <N extends Node> N unkeep() { delUse(null); return (N)this; }
// ------------------------------------------------------------------------
// Graph-based optimizations
-
+
/**
* We allow disabling peephole opt so that we can observe the
* full graph, vs the optimized graph.
@@ -236,7 +236,7 @@ public abstract class Node {
public final Node peephole( ) {
// Compute initial or improved Type
Type type = _type = compute();
-
+
if (_disablePeephole)
return this; // Peephole optimizations turned off
@@ -245,13 +245,13 @@ public abstract class Node {
return deadCodeElim(new ConstantNode(type).peephole());
// Future chapter: Global Value Numbering goes here
-
+
// Ask each node for a better replacement
Node n = idealize();
if( n != null ) // Something changed
// Recursively optimize
return deadCodeElim(n.peephole());
-
+
return this; // No progress
}
@@ -271,7 +271,7 @@ public abstract class Node {
}
return m;
}
-
+
/**
* This function needs to be
* <a href="https://en.wikipedia.org/wiki/Monotonic_function">Monotonic</a>
@@ -340,7 +340,7 @@ public abstract class Node {
// ------------------------------------------------------------------------
// Peephole utilities
-
+
// Swap inputs without letting either input go dead during the swap.
Node swap12() {
Node tmp = in(1);
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/NotNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/NotNode.java
index 5dd6a86e..e3683646 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/NotNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/NotNode.java
@@ -7,15 +7,15 @@ public class NotNode extends Node {
public NotNode(Node in) { super(null, in); }
@Override public String label() { return "Not"; }
-
+
@Override public String glabel() { return "!"; }
-
+
@Override
StringBuilder _print1(StringBuilder sb) {
in(1)._print0(sb.append("(!"));
return sb.append(")");
}
-
+
@Override
public Type compute() {
if( in(1)._type instanceof TypeInteger i0 )
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/ProjNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/ProjNode.java
index 5dd7a2f0..2f49fe91 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/ProjNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/ProjNode.java
@@ -10,7 +10,7 @@ public class ProjNode extends Node {
// Debugging label
public final String _label;
-
+
public ProjNode(MultiNode ctrl, int idx, String label) {
super(ctrl);
_idx = idx;
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
index d0d3eb06..c9d6c9c8 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/ReturnNode.java
@@ -19,7 +19,7 @@ public class ReturnNode extends Node {
public Node ctrl() { return in(0); }
public Node expr() { return in(1); }
-
+
@Override
public String label() { return "Return"; }
@@ -29,7 +29,7 @@ public class ReturnNode extends Node {
}
@Override public boolean isCFG() { return true; }
-
+
@Override
public Type compute() {
return new TypeTuple(ctrl()._type,expr()._type);
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
index c930fc65..8ffeac64 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
@@ -28,8 +28,8 @@ public class ScopeNode extends Node {
_scopes = new Stack<>();
_type = Type.BOTTOM;
}
-
-
+
+
@Override public String label() { return "Scope"; }
@Override
@@ -65,7 +65,7 @@ public class ScopeNode extends Node {
names[syms.get(name)] = name;
return names;
}
-
+
@Override public Type compute() { return Type.BOTTOM; }
@Override public Node idealize() { return null; }
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/StartNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/StartNode.java
index e94c24e0..022e276d 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/StartNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/StartNode.java
@@ -13,7 +13,7 @@ import com.seaofnodes.simple.type.TypeTuple;
public class StartNode extends MultiNode {
final TypeTuple _args;
-
+
public StartNode(Type[] args) {
super();
_args = new TypeTuple(args);
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter04/src/main/java/com/seaofnodes/simple/node/SubNode.java
index ec2168e6..27e77f90 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/node/SubNode.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/node/SubNode.java
@@ -16,7 +16,7 @@ public class SubNode extends Node {
in(2)._print0(sb.append("-"));
return sb.append(")");
}
-
+
@Override
public Type compute() {
if (in(1)._type instanceof TypeInteger i0 &&
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/type/Type.java b/chapter04/src/main/java/com/seaofnodes/simple/type/Type.java
index 170325f0..1687f65a 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/type/Type.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/type/Type.java
@@ -4,7 +4,7 @@ package com.seaofnodes.simple.type;
/**
* These types are part of a Monotone Analysis Framework,
* @see <a href="https://www.cse.psu.edu/~gxt29/teaching/cse597s21/slides/08monotoneFramework.pdf">see for example this set of slides</a>.
- * <p>
+ * <p>
* The types form a lattice; @see <a href="https://en.wikipedia.org/wiki/Lattice_(order)">a symmetric complete bounded (ranked) lattice.</a>
* <p>
* This wild lattice theory will be needed later to allow us to easily beef up
@@ -15,7 +15,7 @@ package com.seaofnodes.simple.type;
* actual implementation is darn near trivial and is generally really obvious
* what we're doing with it. Right now, it's just simple integer math to do
* simple constant folding e.g. 1+2 == 3 stuff.
- */
+ */
public class Type {
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/type/TypeInteger.java b/chapter04/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
index 3037e45f..9fb4b853 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/type/TypeInteger.java
@@ -28,7 +28,7 @@ public class TypeInteger extends Type {
public boolean isTop() { return !_is_con && _con==0; }
public boolean isBot() { return !_is_con && _con==1; }
- @Override
+ @Override
public StringBuilder _print(StringBuilder sb) {
if (isTop()) return sb.append("IntTop");
if (isBot()) return sb.append("IntBot");
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/type/TypeTuple.java b/chapter04/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
index 513972aa..25663dda 100644
--- a/chapter04/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
+++ b/chapter04/src/main/java/com/seaofnodes/simple/type/TypeTuple.java
@@ -1,7 +1,7 @@
package com.seaofnodes.simple.type;
public class TypeTuple extends Type {
-
+
public final Type[] _types;
public TypeTuple(Type... _types) {
diff --git a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index 299399d2..5757fc59 100644
--- a/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/chapter04/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -40,7 +40,7 @@ public class Chapter04Test {
ReturnNode ret = parser.parse();
assertEquals("return (arg*2);", ret.print());
}
-
+
@Test
public void testChapter4Peephole3() {
Parser parser = new Parser("return 1+arg+2+arg+3; #showGraph;");
@@ -54,7 +54,7 @@ public class Chapter04Test {
ReturnNode ret = parser.parse();
assertEquals("return arg;", ret.print());
}
-
+
@Test
public void testChapter4VarArg() {
Parser parser = new Parser("return arg; #showGraph;", TypeInteger.BOT);
@@ -114,7 +114,7 @@ public class Chapter04Test {
@Test
public void testChapter4Bug3() {
- try {
+ try {
new Parser("inta=1; return a;").parse();
fail();
} catch( RuntimeException e ) {
@@ -128,7 +128,7 @@ public class Chapter04Test {
ReturnNode ret = parser.parse();
assertEquals("return (-arg);", ret.print());
}
-
+
@Test
public void testVarDecl() {
Parser parser = new Parser("int a=1; return a;");
@@ -168,7 +168,7 @@ public class Chapter04Test {
@Test
public void testSelfAssign() {
- try {
+ try {
new Parser("int a=a; return a;").parse();
fail();
} catch( RuntimeException e ) {
@@ -236,7 +236,7 @@ public class Chapter04Test {
Parser parser = new Parser("return 1;");
ReturnNode ret = parser.parse();
StartNode start = Parser.START;
-
+
assertTrue(ret.ctrl() instanceof ProjNode);
Node expr = ret.expr();
if( expr instanceof ConstantNode con ) {
@@ -259,7 +259,7 @@ public class Chapter04Test {
@Test
public void testBad1() {
- try {
+ try {
new Parser("ret").parse();
fail();
} catch( RuntimeException e ) {
@@ -269,7 +269,7 @@ public class Chapter04Test {
@Test
public void testBad2() {
- try {
+ try {
new Parser("return 0123;").parse();
fail();
} catch( RuntimeException e ) {
@@ -285,7 +285,7 @@ public class Chapter04Test {
@Test
public void testBad4() {
- try {
+ try {
new Parser("return 100").parse();
fail();
} catch( RuntimeException e ) {