summaryrefslogtreecommitdiff
path: root/chapter18/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
Diffstat (limited to 'chapter18/src/test/java/com/seaofnodes')
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter04Test.java6
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter10Test.java4
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java4
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/Eval2.java15
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/FuzzerWrap.java2
-rw-r--r--chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java9
6 files changed, 27 insertions, 13 deletions
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index 27d42c43..afed67d1 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -126,4 +126,10 @@ public class Chapter04Test {
assertEquals("return (-arg);", code.print());
}
+ @Test
+ public void testBug5() {
+ Parser parser = new Parser("return arg--2;");
+ StopNode ret = parser.parse();
+ assertEquals("return (arg--2);", ret.print());
+ }
}
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index cdb9e923..02029b3f 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -299,8 +299,8 @@ if(0) {
while(0) if(arg) continue;
int v0=0;
while(1) {
- int arg=-arg;
- v0=arg;
+ int v2=-arg;
+ v0=v2;
}
}
""");
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
index c127d1cb..7063ef26 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java
@@ -11,9 +11,9 @@ public class Chapter18Test {
@Test
public void testJig() {
CodeGen code = new CodeGen("""
-return 0;
+ return 0;
""");
- code.parse().opto().typeCheck().GCM();
+ code.parse(true).opto().typeCheck().GCM();
assertEquals("return 0;", code._stop.toString());
assertEquals("0", Eval2.eval(code, 0));
}
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java b/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java
index 580d3b0a..0e5e86a4 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java
@@ -32,7 +32,7 @@ public abstract class Eval2 {
// Evaluate until we return or timeout. Each outer loop step computes
// all data nodes under some new Control.
- SB sb = null; //new SB(); // TRACE
+ SB sb = null; // new SB(); // TRACE
IdentityHashMap visit = new IdentityHashMap();
while( true ) {
// Compute input path on Phis for this Region,
@@ -49,8 +49,17 @@ public abstract class Eval2 {
phiCache[i] = isArg(phi) ? arg : val(phi.in(path));
else break;
// Parallel assign; might assign before read, so read from cache
- for( int j=0; j < i; j++ )
- DATA[C.out(j)._nid] = phiCache[j];
+ for( int j=0; j < i; j++ ) {
+ Node n = C.out(j);
+ DATA[n._nid] = phiCache[j];
+ if( sb!=null ) {
+ IRPrinter.printLine(n,sb).unchar();
+ _print( n._type, DATA[n._nid], sb.p('\t'), visit );
+ System.out.println(sb);
+ sb.clear();
+ visit.clear();
+ }
+ }
// Now compute the rest of the nodes
for( ; i < C.nOuts(); i++ )
step(C.out(i), sb, visit);
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/chapter18/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index eaeed8e2..d67b2065 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -28,7 +28,7 @@ public class FuzzerWrap {
Random R = new Random(System.currentTimeMillis());
var fuzzer = new Fuzzer();
for (int i=0; i<100; i++)
- fuzzer.fuzzPeeps(R.nextLong());
+ fuzzer.fuzzPeeps( R.nextLong());
assertTrue(fuzzer.noExceptions());
}
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index 66395a74..a6bef4d3 100644
--- a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -1,10 +1,10 @@
package com.seaofnodes.simple.fuzzer;
import com.seaofnodes.simple.Utils;
+import com.seaofnodes.simple.Parser;
import com.seaofnodes.simple.Eval2;
import com.seaofnodes.simple.CodeGen;
import com.seaofnodes.simple.node.Node;
-import com.seaofnodes.simple.node.StopNode;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;
@@ -56,8 +56,7 @@ public class Fuzzer {
private static boolean neq(Object a, Object b) {
if (Objects.equals(a, b)) return false;
- // Deep compare?
- throw Utils.TODO();
+ return true;
}
/**
@@ -69,7 +68,7 @@ public class Fuzzer {
private static void checkGraphs(CodeGen code1, CodeGen code2, long in) {
var r1 = Eval2.eval(code1, in, EVAL_TIMEOUT);
var r2 = Eval2.eval(code2, in, EVAL_TIMEOUT);
- if( r1 == null || r2 == null ) return;
+ if( r1 == null || r2 == null ) return; // Timeout test invalid
if( neq(r1, r2) )
throw new RuntimeException("Different calculations values " + r1 + " vs " + r2);
}
@@ -90,7 +89,7 @@ public class Fuzzer {
FuzzerUtils.parse(script, true);
} catch (RuntimeException e2) {
if (FuzzerUtils.isExceptionFromSameCause(e1, e2)) {
- if (!valid || e1.getClass() == RuntimeException.class) return;
+ if (!valid || e1.getClass() == Parser.ParserException.class) return;
} else {
e1.addSuppressed(e2);
}