diff options
| author | Cliff Click <cliffc@acm.org> | 2025-06-13 15:42:08 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-07-08 20:29:09 -0700 |
| commit | fcce1e13814a02d8358eae9a40e33a7e6f2b5400 (patch) | |
| tree | b9623369d88e22a0be21dbba472eebfa476d02ab /src/test/java/com/seaofnodes/simple/Chapter08Test.java | |
| parent | 664761624f4b0e3d6d1593b99e576854beec5949 (diff) | |
| download | Simple-linear-chapter24.tar.gz Simple-linear-chapter24.zip | |
Unifying Structs and Arrayslinear-chapter24
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter08Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter08Test.java | 208 |
1 files changed, 0 insertions, 208 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/src/test/java/com/seaofnodes/simple/Chapter08Test.java deleted file mode 100644 index 09669cc7..00000000 --- a/src/test/java/com/seaofnodes/simple/Chapter08Test.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.seaofnodes.simple; - -import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.node.*; -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class Chapter08Test { - - @Test - public void testEx6() { - CodeGen code = new CodeGen( - """ -while(arg < 10) { - arg = arg + 1; - if (arg == 5) - break; - if (arg == 6) - break; -} -return arg; - """); - code.parse().opto(); - assertEquals("return Phi(Region,(Phi(Loop,arg,Add)+1),Add,Phi_arg);", code.print()); - assertTrue(code.ctrl() instanceof RegionNode); - Assert.assertEquals( "5", Eval2.eval(code, 1)); - Assert.assertEquals("10", Eval2.eval(code, 6)); - } - - - @Test - public void testEx5() { - CodeGen code = new CodeGen( - """ -int a = 1; -while(arg < 10) { - arg = arg + 1; - if (arg == 5) - continue; - if (arg == 7) - continue; - a = a + 1; -} -return a; - """); - code.parse().opto(); - assertEquals("return Phi(Loop,1,Phi(Region,Phi_a,(Phi_a+1),Phi_a));", code.print()); - assertTrue(code.ctrl() instanceof CProjNode); - } - - - @Test - public void testEx4() { - CodeGen code = new CodeGen( - """ -while(arg < 10) { - arg = arg + 1; - if (arg == 5) - continue; - if (arg == 6) - break; -} -return arg; - """); - code.parse().opto(); - assertEquals("return Phi(Region,Phi(Loop,arg,(Phi_arg+1)),Add);", code.print()); - assertTrue(code.ctrl() instanceof RegionNode); - } - - @Test - public void testEx3() { - CodeGen code = new CodeGen( - """ -while(arg < 10) { - arg = arg + 1; - if (arg == 6) - break; -} -return arg; - """); - code.parse().opto(); - assertEquals("return Phi(Region,Phi(Loop,arg,(Phi_arg+1)),Add);", code.print()); - assertTrue(code.ctrl() instanceof RegionNode); - } - - - @Test - public void testEx2() { - CodeGen code = new CodeGen( - """ -while(arg < 10) { - arg = arg + 1; - if (arg == 5) - continue; - if (arg == 6) - continue; -} -return arg; - """); - code.parse().opto(); - assertEquals("return Phi(Loop,arg,(Phi_arg+1));", code.print()); - assertTrue(code.ctrl() instanceof CProjNode); - } - - - @Test - public void testEx1() { - CodeGen code = new CodeGen( - """ -while(arg < 10) { - arg = arg + 1; - if (arg == 5) - continue; -} -return arg; - """); - code.parse().opto(); - assertEquals("return Phi(Loop,arg,(Phi_arg+1));", code.print()); - assertTrue(code.ctrl() instanceof CProjNode); - } - - @Test - public void testRegress1() { - CodeGen code = new CodeGen( - """ -while( arg < 10 ) { - int a = arg+2; - if( a > 4 ) - break; -} -return arg; - """); - code.parse().opto(); - assertEquals("return arg;", code.print()); - } - - @Test - public void testRegress2() { - CodeGen code = new CodeGen("if(1) return 0; else while(arg>- -arg) arg=arg+1; return 0;"); - code.parse().opto(); - assertEquals("return 0;", code.print()); - } - - @Test - public void testBreakOutsideLoop() { - try { - new CodeGen(""" -if(arg <= 10) { - break; - arg = arg + 1; -} -return arg; -""").parse(); - fail(); - } catch( RuntimeException e ) { - assertEquals("No active loop for a break or continue",e.getMessage()); - } - } - - @Test - public void testRegress3() { - CodeGen code = new CodeGen(""" -while(arg < 10) { - break; -} -return arg; -"""); - code.parse().opto(); - assertEquals("return arg;", code.print()); - } - - @Test - public void testRegress4() { - CodeGen code = new CodeGen(""" -int a = 1; -while(arg < 10) { - a = a + 1; - if (arg > 2) { - int a = 17; - break; - } -} -return a; -"""); - code.parse().opto(); - assertEquals("return Phi(Region,Phi(Loop,1,(Phi_a+1)),Add);", code.print()); - assertTrue(code.ctrl() instanceof RegionNode); - } - - @Test - public void testRegress5() { - CodeGen code = new CodeGen(""" -int a = 1; -while(1) { - a = a + 1; - if (a<10) continue; - break; -} -return a; -"""); - code.parse().opto(); - assertEquals("return (Phi(Loop,1,Add)+1);", code.print()); - assertTrue(code.ctrl() instanceof CProjNode prj && prj._idx==1 ); - } - -} |
