summaryrefslogtreecommitdiff
path: root/chapter03
diff options
context:
space:
mode:
Diffstat (limited to 'chapter03')
-rw-r--r--chapter03/README.md5
-rw-r--r--chapter03/src/main/java/com/seaofnodes/simple/node/Node.java11
-rw-r--r--chapter03/src/test/java/com/seaofnodes/simple/Chapter02Test.java4
-rw-r--r--chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java9
4 files changed, 5 insertions, 24 deletions
diff --git a/chapter03/README.md b/chapter03/README.md
index ddb9fafa..39baf903 100644
--- a/chapter03/README.md
+++ b/chapter03/README.md
@@ -124,8 +124,9 @@ The variables `a`, `b`, and `c` are registered in this table.
* On line 5, a variable `b` is declared. `b` is registered in the symbol table at level 1. This then
hides the variable with the same name on line 2.
* On line 7, we update the variable `c`. Variable lookup will find it in the symbol table at level 0.
-The node graph is shown below (note that peephole opts are switched off here so that we can
-see the graph as its initially constructed).
+The schematic below shows the variable bindings and arithmetic before constant
+folding. The compiler applies peepholes as it builds the graph, so the actual
+result of this example is `return 4;`.
![Graph1](./docs/03-graph1.svg)
diff --git a/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java
index 3922533c..3fa0fd1e 100644
--- a/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter03/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -211,12 +211,6 @@ public abstract class Node {
// Mostly used for asserts and printing.
public boolean isDead() { return isUnused() && nIns()==0 && _type==null; }
/**
- * We allow disabling peephole opt so that we can observe the
- * full graph, vs the optimized graph.
- */
- public static boolean _disablePeephole = false;
-
- /**
* Try to peephole at this node and return a better replacement Node if
* possible. We compute a {@link Type} and then check and replace:
* <ul>
@@ -241,9 +235,6 @@ public abstract class Node {
// Compute initial or improved Type
Type type = _type = compute();
- if (_disablePeephole)
- return null; // Peephole optimizations turned off
-
// Replace constant computations from non-constants with a constant node
if (!(this instanceof ConstantNode) && type.isConstant()) {
kill(); // Kill `this` because replacing with a Constant
@@ -283,7 +274,7 @@ public abstract class Node {
* Used to allow repeating tests in the same JVM. This just resets the
* Node unique id generator, and is done as part of making a new Parser.
*/
- public static void reset() { UNIQUE_ID = 1; _disablePeephole=false; }
+ public static void reset() { UNIQUE_ID = 1; }
/**
* Debugging utility to find a Node by index
diff --git a/chapter03/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter03/src/test/java/com/seaofnodes/simple/Chapter02Test.java
index 9de09d21..6c816a23 100644
--- a/chapter03/src/test/java/com/seaofnodes/simple/Chapter02Test.java
+++ b/chapter03/src/test/java/com/seaofnodes/simple/Chapter02Test.java
@@ -11,10 +11,8 @@ public class Chapter02Test {
@Test
public void testParseGrammar() {
Parser parser = new Parser("return 1+2*3+-5;");
- Node._disablePeephole = true; // disable peephole so we can observe full graph
ReturnNode ret = parser.parse();
- assertEquals("return (1+((2*3)+(-5)));", ret.print());
- Node._disablePeephole = false;
+ assertEquals("return 2;", ret.print());
}
@Test
diff --git a/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
index b42f1433..78696633 100644
--- a/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
+++ b/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
@@ -29,15 +29,6 @@ public class Chapter03Test {
}
@Test
- public void testVarScopeNoPeephole() {
- Parser parser = new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b; } return c; ");
- Node._disablePeephole = true;
- ReturnNode ret = parser.parse();
- Node._disablePeephole = false;
- assertEquals("return (1+3);", ret.print());
- }
-
- @Test
public void testVarDist() {
Parser parser = new Parser("int x0=1; int y0=2; int x1=3; int y1=4; return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1); ");
ReturnNode ret = parser.parse();