summaryrefslogtreecommitdiff
path: root/chapter07/src/main/java/com
diff options
context:
space:
mode:
authorDibyendu Majumdar <dibyendumajumdar@users.noreply.github.com>2023-12-21 00:53:10 +0000
committerGitHub <noreply@github.com>2023-12-20 16:53:10 -0800
commit0671df6c0b76f160ec8c29c219a4af5249569aea (patch)
tree420eb9b4668366fd3898e1299f190e5e3ea76ce0 /chapter07/src/main/java/com
parent499906b94893cb808df96810d46441857ae432d4 (diff)
downloadSimple-0671df6c0b76f160ec8c29c219a4af5249569aea.tar.gz
Simple-0671df6c0b76f160ec8c29c219a4af5249569aea.zip
Chapter8 update to sync with latest changes (#53)
* #52 Update chapter8 to align with chapter7 * #52 Update chapter8 to align with chapter7 * #52 Fix spacing
Diffstat (limited to 'chapter07/src/main/java/com')
-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();
}