diff options
Diffstat (limited to 'chapter10/src/test/java')
| -rw-r--r-- | chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java index 6bafe72a..36ad19ae 100644 --- a/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter10/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -30,9 +30,9 @@ bar.a = 1; bar.a = 2; return bar.a; """); - StopNode stop = parser.parse(true).iterate(true); + StopNode stop = parser.parse(false).iterate(true); System.out.println(IRPrinter.prettyPrint(stop, 99, true)); - assertEquals("return .a;", stop.toString()); + assertEquals("return 2;", stop.toString()); } @Test @@ -86,8 +86,8 @@ while (arg) { } return bar.a; """); - StopNode stop = parser.parse(true).iterate(true); - assertEquals("return .a;", stop.toString()); + StopNode stop = parser.parse(false).iterate(true); + assertEquals("return Phi(Loop10,0,(Phi_a+2));", stop.toString()); } @Test @@ -190,6 +190,31 @@ v1=new s0; } @Test + public void testIter() { + // Build and use an iterator + Parser parser = new Parser( +""" +struct Iter { + int x; + int len; +} +Iter i = new Iter; +i.len = arg; +int sum=0; +while( i.x < i.len ) { + sum = sum + i.x; + i.x = i.x + 1; +} +return sum; +"""); + StopNode stop = parser.parse().iterate(true); + assertEquals("return Phi(Loop14,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString()); + } + + + + + @Test public void test1() { Parser parser = new Parser(""" struct s0 {int v0;} |
