diff options
| author | Cliff Click <cliffc@acm.org> | 2025-06-13 15:42:08 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-24 15:56:44 -0700 |
| commit | 89dd0a79da85b2c7102b7c8918a1466e6238fe94 (patch) | |
| tree | cfa3d1457e9c40ad79ae78ded15c7c2ff286d79d /src/test/java/com/seaofnodes/simple/SccpTest.java | |
| parent | 8309071562b63f77a15425ab2146e05dbcb5acfd (diff) | |
| download | Simple-linear-chapter24a.tar.gz Simple-linear-chapter24a.zip | |
Chapter 24a: SCCP Within a Functionlinear-chapter24a
Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com>
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Hadházy Tamás <helsgithub15@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/SccpTest.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/SccpTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/com/seaofnodes/simple/SccpTest.java b/src/test/java/com/seaofnodes/simple/SccpTest.java new file mode 100644 index 00000000..afa0ec58 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/SccpTest.java @@ -0,0 +1,35 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.TypeInteger; +import org.junit.Test; +import static org.junit.Assert.*; + +public class SccpTest { + @Test public void testLoopFixedPoint() { + var code = new CodeGen("int x=1; while(arg) { x=2-x; arg--; } return x;").parse().iter(); + assertFalse(code.link(code._main).ret().expr()._type.isConstant()); + code.opto(); + assertSame(TypeInteger.TRUE,code.link(code._main).ret().expr()._type); + code.driver(CodeGen.Phase.LocalSched); + assertEquals("1",Eval2.eval(code,4)); + } + + @Test public void testConservativeCalls() { + var code = new CodeGen("val f={ int x -> x+1; }; return f(1)+f(2);").parse().iter().opto(); + int[] parms = {0}; + code._start.walk(n -> { + if( n instanceof ParmNode p && "x".equals(p._label) ) { + parms[0]++; + assertSame(TypeInteger.BOT,p._type); + assertTrue(p.fun().in(1) instanceof StartNode); + } + if( n instanceof CallEndNode cend ) assertEquals(1,cend.nIns()); + return null; + }); + assertEquals(1,parms[0]); + code.driver(CodeGen.Phase.LocalSched); + assertEquals("5",Eval2.eval(code,0)); + } +} |
