summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/Chapter05Test.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-11-26 11:01:47 -0800
committerCliff Click <cliffc@acm.org>2025-01-14 15:17:03 -0800
commiteee5b806fabae0b480ff7d41159369c5a457d014 (patch)
tree576e6ed318eea76aa9e0de9e95af7616a0b8475a /src/test/java/com/seaofnodes/simple/Chapter05Test.java
parentc07510c1d75020d23d688f7f184149c57b13a39a (diff)
downloadSimple-linear-chapter18.tar.gz
Simple-linear-chapter18.zip
Chapter 18: Functionslinear-chapter18
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter05Test.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter05Test.java73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 9afb8f28..f4db5624 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -1,7 +1,6 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
-import com.seaofnodes.simple.type.TypeInteger;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -10,7 +9,7 @@ public class Chapter05Test {
@Test
public void testIfStmt() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a = 1;
if (arg == 1)
@@ -20,13 +19,13 @@ else {
}
return a;
""");
- StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region,(arg+2),(arg-3));", ret.toString());
+ code.parse().opto();
+ assertEquals("return Phi(Region,(arg+2),(arg-3));", code.print());
}
@Test
public void testTest() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int c = 3;
int b = 2;
@@ -34,27 +33,28 @@ if (arg == 1) {
b = 3;
c = 4;
}
-return c;""", TypeInteger.BOT);
- StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region,4,3);", ret.toString());
+return c;
+""");
+ code.parse().opto();
+ assertEquals("return Phi(Region,4,3);", code.print());
}
@Test
public void testReturn2() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
if( arg==1 )
return 3;
else
return 4;
-""", TypeInteger.BOT);
- StopNode stop = parser.parse();
- assertEquals("Stop[ return 3; return 4; ]", stop.toString());
+""");
+ code.parse();
+ assertEquals("return Phi(Region,3,4);", code.print());
}
@Test
public void testIfMergeB() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a=arg+1;
int b=0;
@@ -63,13 +63,13 @@ if( arg==1 )
else
b=a+1;
return a+b;""");
- StopNode ret = parser.parse().iterate();
- assertEquals("return ((arg*2)+Phi(Region,2,3));", ret.toString());
+ code.parse().opto();
+ assertEquals("return ((arg*2)+Phi(Region,2,3));", code.print());
}
@Test
public void testIfMerge2() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a=arg+1;
int b=arg+2;
@@ -78,13 +78,13 @@ if( arg==1 )
else
a=b+1;
return a+b;""");
- StopNode ret = parser.parse().iterate();
- assertEquals("return ((Phi(Region,(arg*2),arg)+arg)+Phi(Region,4,5));", ret.toString());
+ code.parse().opto();
+ assertEquals("return ((Phi(Region,(arg*2),arg)+arg)+Phi(Region,4,5));", code.print());
}
@Test
public void testMerge3() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a=1;
if( arg==1 )
@@ -97,14 +97,14 @@ else if( arg==3 )
else
a=5;
return a;
-""", TypeInteger.BOT);
- StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region,Phi(Region,2,3),Phi(Region,4,5));", stop.toString());
+""");
+ code.parse().opto();
+ assertEquals("return Phi(Region,Phi(Region,2,3),Phi(Region,4,5));", code.print());
}
@Test
public void testMerge4() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a=0;
int b=0;
@@ -113,38 +113,39 @@ if( arg )
if( arg==0 )
b=2;
return arg+a+b;
-""", TypeInteger.BOT);
- StopNode stop = parser.parse();
- assertEquals("return ((arg+Phi(Region,1,0))+Phi(Region,2,0));", stop.toString());
+""");
+ code.parse().opto();
+ assertEquals("return ((arg+Phi(Region,1,0))+Phi(Region,2,0));", code.print());
}
@Test
public void testMerge5() {
- Parser parser = new Parser(
+ CodeGen code = new CodeGen(
"""
int a=arg==2;
if( arg==1 )
{
a=arg==3;
}
-return a;""");
- StopNode ret = parser.parse().iterate();
- assertEquals("return (arg==Phi(Region,3,2));", ret.toString());
+return a;
+""");
+ code.parse().opto();
+ assertEquals("return (arg==Phi(Region,3,2));", code.print());
}
@Test
public void testTrue() {
StopNode stop = new Parser("return true;").parse();
- assertEquals("return 1;",stop.toString());
+ assertEquals("return 1;",stop.ret().print());
}
@Test
public void testHalfDef() {
try {
- new Parser("if( arg==1 ) int b=2; return b;").parse();
+ new CodeGen("if( arg==1 ) int b=2; return b;").parse();
fail();
} catch( RuntimeException e ) {
- assertEquals("Cannot define a new name on one arm of an if",e.getMessage());
+ assertEquals("Cannot define a 'b' on one arm of an if",e.getMessage());
}
}
@@ -161,10 +162,10 @@ return a;""");
@Test
public void testRegress1() {
try {
- new Parser("if(arg==2) int a=1; else int b=2; return a;").parse();
+ new CodeGen("if(arg==2) int a=1; else int b=2; return a;").parse();
fail();
} catch( RuntimeException e ) {
- assertEquals("Cannot define a new name on one arm of an if",e.getMessage());
+ assertEquals("Cannot define a 'a' on one arm of an if",e.getMessage());
}
}
@@ -202,7 +203,7 @@ return a;""");
@Test
public void testKeyword3() {
try {
- new Parser("int a=1; ififif(arg)inta=2;return a;").parse();
+ new CodeGen("int a=1; ififif(arg);a=2;return a;").parse();
fail();
} catch( RuntimeException e ) {
assertEquals("Undefined name 'ififif'",e.getMessage());