From ff11dd42bb845ad4a979b8924c678addb8681801 Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Sat, 11 Nov 2023 23:17:22 +0000 Subject: Chapter 6: Peepholes for If Co-authored-by: Cliff Click Co-authored-by: Thalia Archibald Co-authored-by: Yichen Yan Co-authored-by: Tamas Hadhazy Co-authored-by: Robert Obkircher --- .../java/com/seaofnodes/simple/Chapter06Test.java | 294 +++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 src/test/java/com/seaofnodes/simple/Chapter06Test.java (limited to 'src/test/java/com/seaofnodes/simple/Chapter06Test.java') diff --git a/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/src/test/java/com/seaofnodes/simple/Chapter06Test.java new file mode 100644 index 00000000..44b49d73 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/Chapter06Test.java @@ -0,0 +1,294 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.TypeInteger; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class Chapter06Test { + + @Test + public void testPeepholeReturn() { + Parser parser = new Parser( +""" +if( true ) return 2; +return 1; +"""); + StopNode stop = parser.parse(false); + assertEquals("return 2;", stop.toString()); + assertTrue(stop.ret().ctrl() instanceof ProjNode); + } + + @Test + public void testPeepholeRotate() { + Parser parser = new Parser( +""" +int a = 1; +if (arg) + a = 2; +return (arg < a) < 3; +"""); + StopNode stop = parser.parse(false); + assertEquals("return ((arg