summaryrefslogtreecommitdiff
path: root/chapter07/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter07/src/main/java')
-rw-r--r--chapter07/src/main/java/com/seaofnodes/simple/Parser.java4
-rw-r--r--chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java12
2 files changed, 10 insertions, 6 deletions
diff --git a/chapter07/src/main/java/com/seaofnodes/simple/Parser.java b/chapter07/src/main/java/com/seaofnodes/simple/Parser.java
index c3972be9..3bc532c2 100644
--- a/chapter07/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter07/src/main/java/com/seaofnodes/simple/Parser.java
@@ -87,14 +87,14 @@ public class Parser {
public StopNode parse() { return parse(false); }
public StopNode parse(boolean show) {
- _xScopes.push(_scope);
+ _xScopes.push(_scope);
// Enter a new scope for the initial control and arguments
_scope.push();
_scope.define(ScopeNode.CTRL, new ProjNode(START, 0, ScopeNode.CTRL).peephole());
_scope.define(ScopeNode.ARG0, new ProjNode(START, 1, ScopeNode.ARG0).peephole());
parseBlock();
_scope.pop();
- _xScopes.pop();
+ _xScopes.pop();
if (!_lexer.isEOF()) throw error("Syntax error, unexpected " + _lexer.getAnyNextToken());
STOP.peephole();
if( show ) showGraph();
diff --git a/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java b/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
index b5ce997b..a83ae1a7 100644
--- a/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
+++ b/chapter07/src/main/java/com/seaofnodes/simple/node/ScopeNode.java
@@ -142,11 +142,12 @@ public class ScopeNode extends Node {
// 3) Ensure that the order of defs is the same to allow easy merging
for( HashMap<String,Integer> syms : _scopes )
dup._scopes.push(new HashMap<>(syms));
- String[] names = reverseNames(); // Get the variable names
+
dup.addDef(ctrl()); // Control input is just copied
for( int i=1; i<nIns(); i++ ) {
if ( !loop ) { dup.addDef(in(i)); }
else {
+ String[] names = reverseNames(); // Get the variable names
// Create a phi node with second input as null - to be filled in
// by endLoop() below
dup.addDef(new PhiNode(names[i], ctrl(), in(i), null).peephole());
@@ -169,9 +170,12 @@ public class ScopeNode extends Node {
RegionNode r = (RegionNode) ctrl(new RegionNode(null,ctrl(), that.ctrl()).keep());
String[] ns = reverseNames();
// Note that we skip i==0, which is bound to '$ctrl'
- for (int i = 1; i < nIns(); i++)
- if( in(i) != that.in(i) ) // No need for redundant Phis
- setDef(i, new PhiNode(ns[i], r, in(i), that.in(i)).peephole());
+ for (int i = 1; i < nIns(); i++) {
+ if( in(i) != that.in(i) ) { // No need for redundant Phis
+ Node phi = new PhiNode(ns[i], r, in(i), that.in(i)).peephole();
+ setDef(i, phi);
+ }
+ }
that.kill(); // Kill merged scope
return r.unkeep().peephole();
}