diff options
| author | Cliff Click <cliffc@acm.org> | 2024-08-05 11:46:17 -0700 |
|---|---|---|
| committer | Dibyendu Majumdar <dibyendumajumdar@users.noreply.github.com> | 2024-08-06 00:50:58 +0100 |
| commit | 0fb76e75be3a35d6b4741e9ae4378fa04868a840 (patch) | |
| tree | 4f531ef7ccfd3f032687177c057628bb64ad7c10 /chapter13/src/test/java/com/seaofnodes | |
| parent | 5dad6618f075aac78023183354f0456e5dcc1d54 (diff) | |
| download | Simple-0fb76e75be3a35d6b4741e9ae4378fa04868a840.tar.gz Simple-0fb76e75be3a35d6b4741e9ae4378fa04868a840.zip | |
Ref types working
GCM uses a breadth-first pass for schedule-late instead of a post-order; the post-order walk depends on StoreNodes being pinned, which is true in C2 but not Simple.
Move GCM call out of IterPeeps.
Struct field init is "makeInit()" not integer zero.
Rename Type._print to print.
Store,Load prints include field name.
Diffstat (limited to 'chapter13/src/test/java/com/seaofnodes')
7 files changed, 82 insertions, 34 deletions
diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter05Test.java index 64f3a1d9..d48bde7f 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -37,7 +37,7 @@ if (arg == 1) { } return c;""", TypeInteger.BOT); StopNode ret = parser.parse().iterate(true); - assertEquals("return Phi(Region18,4,3);", ret.toString()); + assertEquals("return Phi(Region19,4,3);", ret.toString()); } @Test @@ -116,7 +116,7 @@ if( arg==0 ) return arg+a+b; #showGraph;""", TypeInteger.BOT); StopNode stop = parser.parse(); - assertEquals("return ((arg+Phi(Region15,1,0))+Phi(Region30,2,0));", stop.toString()); + assertEquals("return ((arg+Phi(Region17,1,0))+Phi(Region33,2,0));", stop.toString()); } @Test @@ -130,7 +130,7 @@ if( arg==1 ) } return a;"""); StopNode ret = parser.parse().iterate(); - assertEquals("return (arg==Phi(Region18,3,2));", ret.toString()); + assertEquals("return (arg==Phi(Region19,3,2));", ret.toString()); } @Test diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter06Test.java index fed34465..472e2db3 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter06Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter06Test.java @@ -30,7 +30,7 @@ if (arg) return (arg < a) < 3; """); StopNode stop = parser.parse().iterate(); - assertEquals("return ((arg<Phi(Region14,2,1))<3);", stop.toString()); + assertEquals("return ((arg<Phi(Region16,2,1))<3);", stop.toString()); } @Test @@ -200,7 +200,7 @@ if( arg ) { return a+b; """); StopNode ret = parser.parse().iterate(true); - assertEquals("return Phi(Region26,4,1);", ret.toString()); + assertEquals("return Phi(Region28,4,1);", ret.toString()); } @@ -251,7 +251,7 @@ if( arg ) { return a+b+c; """); StopNode ret = parser.parse().iterate(true); - assertEquals("return (Phi(Region38,Phi(Region25,2,3),0)+Phi(Region,3,1));", ret.toString()); + assertEquals("return (Phi(Region40,Phi(Region25,2,3),0)+Phi(Region,3,1));", ret.toString()); } diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter08Test.java index ac891050..aa650022 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter08Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter08Test.java @@ -23,7 +23,7 @@ while(arg < 10) { return arg; """); StopNode stop = parser.parse().iterate(true); - assertEquals("return Phi(Region36,Phi(Region26,Phi(Loop8,arg,(Phi_arg+1)),Add),Add);", stop.toString()); + assertEquals("return Phi(Region37,Phi(Region26,Phi(Loop8,arg,(Phi_arg+1)),Add),Add);", stop.toString()); assertTrue(stop.ret().ctrl() instanceof RegionNode); Assert.assertEquals(5L, Evaluator.evaluate(stop, 1)); Assert.assertEquals(10L, Evaluator.evaluate(stop, 6)); @@ -46,7 +46,7 @@ while(arg < 10) { return a; """); StopNode stop = parser.parse().iterate(true); - assertEquals("return Phi(Loop9,1,Phi(Region41,Phi_a,(Phi_a+1)));", stop.toString()); + assertEquals("return Phi(Loop9,1,Phi(Region43,Phi_a,(Phi_a+1)));", stop.toString()); assertTrue(stop.ret().ctrl() instanceof CProjNode); System.out.println(IRPrinter.prettyPrint(stop,99)); } @@ -66,7 +66,7 @@ while(arg < 10) { return arg; """); StopNode stop = parser.parse().iterate(true); - assertEquals("return Phi(Region34,Phi(Loop8,arg,(Phi_arg+1)),Add);", stop.toString()); + assertEquals("return Phi(Region35,Phi(Loop8,arg,(Phi_arg+1)),Add);", stop.toString()); assertTrue(stop.ret().ctrl() instanceof RegionNode); } diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java index 06065702..65bd1170 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -1,12 +1,7 @@ package com.seaofnodes.simple; -import com.seaofnodes.simple.node.Node; import com.seaofnodes.simple.node.StopNode; -import com.seaofnodes.simple.type.*; import org.junit.Test; - -import java.util.Arrays; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -110,7 +105,7 @@ while (arg) { return bar.a; """); StopNode stop = parser.parse(false).iterate(true); - assertEquals("return Phi(Loop11,0,(Phi_a+2));", stop.toString()); + assertEquals("return Phi(Loop12,0,(Phi_a+2));", stop.toString()); } @Test @@ -162,7 +157,7 @@ if( bar ) bar.a = 1; return bar; """); StopNode stop = parser.parse(false).iterate(true); - assertEquals("return Phi(Region16,null,new Bar);", stop.toString()); + assertEquals("return Phi(Region31,(*void)Phi(Region19,null,new Bar),null);", stop.toString()); } @Test @@ -178,7 +173,7 @@ else bar.a = 1; return rez; """); StopNode stop = parser.parse(false).iterate(true); - assertEquals("return Phi(Region33,4,3);", stop.toString()); + assertEquals("return Phi(Region37,4,3);", stop.toString()); } @Test @@ -232,7 +227,7 @@ while( i.x < i.len ) { return sum; """); StopNode stop = parser.parse().iterate(true); - assertEquals("return Phi(Loop15,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString()); + assertEquals("return Phi(Loop17,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString()); } @@ -254,7 +249,7 @@ return ret; """); StopNode stop = parser.parse(true).iterate(true); System.out.println(IRPrinter.prettyPrint(stop, 99, true)); - assertEquals("return Phi(Loop11,new s0,Phi(Region31,new s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop12,new s0,Phi(Region34,new s0,Phi_ret));", stop.toString()); } @Test @@ -273,7 +268,7 @@ return ret; """); StopNode stop = parser.parse(true).iterate(true); System.out.println(IRPrinter.prettyPrint(stop, 99, true)); - assertEquals("return Phi(Loop13,new s0,Phi(Region32,new s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop15,new s0,Phi(Region35,new s0,Phi_ret));", stop.toString()); } @@ -291,7 +286,7 @@ return ret; """); StopNode stop = parser.parse(true).iterate(true); System.out.println(IRPrinter.prettyPrint(stop, 99, true)); - assertEquals("return Phi(Loop11,new s0,Phi(Region30,new s0,Phi_ret));", stop.toString()); + assertEquals("return Phi(Loop12,new s0,Phi(Region33,new s0,Phi_ret));", stop.toString()); } @Test diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java index 6c1f7938..e367184c 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter11Test.java @@ -324,7 +324,7 @@ while( prime <= arg ) { return primeCount; """); StopNode stop = parser.parse(false).iterate(true); - assertEquals("Stop[ return 0; return Phi(Loop19,1,Phi(Region81,Phi_primeCount,Phi(Region76,(Phi_primeCount+1),Phi_primeCount))); ]", stop.toString()); + assertEquals("Stop[ return 0; return Phi(Loop20,1,Phi(Region87,Phi_primeCount,Phi(Region81,(Phi_primeCount+1),Phi_primeCount))); ]", stop.toString()); assertEquals(0L, Evaluator.evaluate(stop, 1)); // No primes 1 or below assertEquals(1L, Evaluator.evaluate(stop, 2)); // 2 assertEquals(2L, Evaluator.evaluate(stop, 3)); // 2, 3 @@ -366,7 +366,7 @@ if (arg) { return i; """); StopNode stop = parser.parse(false).iterate(true); - assertEquals("return Phi(Region31,.f,0);", stop.toString()); + assertEquals("return Phi(Region34,.f,0);", stop.toString()); } @Test @@ -472,7 +472,7 @@ while(arg) { return arg; """); StopNode stop = parser.parse(false).iterate(false); - assertEquals("return Phi(Loop13,arg,Phi(Region35,.f,0));", stop.toString()); + assertEquals("return Phi(Loop15,arg,Phi(Region37,.f,0));", stop.toString()); } @Test diff --git a/chapter13/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter13/src/test/java/com/seaofnodes/simple/Chapter12Test.java index af8fdfe9..903fe676 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/Chapter12Test.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/Chapter12Test.java @@ -2,9 +2,8 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.evaluator.Evaluator; import com.seaofnodes.simple.node.StopNode; +import org.junit.Ignore; import org.junit.Test; - - import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -61,4 +60,46 @@ return x+1==x; assertEquals(0L, Evaluator.evaluate(stop, 1)); } + + @Test + public void testLinkedList0() { + Parser parser = new Parser( +""" +struct LLI { LLI? next; int i; } +LLI? head = null; +while( arg ) { + LLI x = new LLI; + x.next = head; + x.i = arg; + head = x; + arg = arg-1; +} +return head.next.i; +"""); + try { parser.parse(true).iterate(true); fail(); } + catch( Exception e ) { assertEquals("Might be null accessing 'i'",e.getMessage()); } + } + + @Test + public void testLinkedList1() { + Parser parser = new Parser( +""" +struct LLI { LLI? next; int i; } +LLI? head = null; +while( arg ) { + LLI x = new LLI; + x.next = head; + x.i = arg; + head = x; + arg = arg-1; +} +if( !head ) return 0; +LLI? next = head.next; +if( next==null ) return 1; +return next.i; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("Stop[ return 0; return 1; return .i; ]", stop.toString()); + assertEquals(2L, Evaluator.evaluate(stop, 3)); + } } diff --git a/chapter13/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter13/src/test/java/com/seaofnodes/simple/TypeTest.java index f9c580cc..9e8a1418 100644 --- a/chapter13/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/chapter13/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -2,8 +2,8 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.type.*; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; @@ -36,9 +36,9 @@ public class TypeTest { Assert.assertEquals(TypeMem .BOT, m2.meet(m3)); Assert.assertEquals(TypeMem .BOT, m3.meet(m4)); - Assert.assertEquals(TypeMem.BOT, m1.glb()); - Assert.assertEquals(m1, m1.dual()); - Assert.assertEquals(TypeMem.TOP, m1.glb().dual()); + Assert.assertEquals(m1, m1.glb()); + Assert.assertEquals(TypeMem.make(1), m1.dual()); + Assert.assertEquals(m1.dual(), m1.glb().dual()); TypeMemPtr ptr1 = TypeMemPtr.make(s1); Assert.assertEquals(s1, ptr1._obj); @@ -128,10 +128,13 @@ public class TypeTest { private static void check_symmetric( Type t0, Type t1 ) { if( t1==t0 ) return; Type mt = t0.meet(t1); - Type ta = mt.dual().meet(t1.dual()); - Type tb = mt.dual().meet(t0.dual()); - assertSame(ta,t1.dual()); - assertSame(tb,t0.dual()); + Type dm = mt.dual(); + Type d0 = t0.dual(); + Type d1 = t1.dual(); + Type ta = dm.meet(d1); + Type tb = dm.meet(d0); + assertSame(ta,d1); + assertSame(tb,d0); } private static void assoc( Type t0, Type t1, Type t2 ) { @@ -142,4 +145,13 @@ public class TypeTest { assertSame(t01_2,t0_12); } + // Test cyclic types and meets + @Test + public void testCyclic0() { + Type d0 = TypeStruct.S1.dual(); + Type d1 = d0.dual(); + assertSame(TypeStruct.S1,d1); + } + + } |
