summaryrefslogtreecommitdiff
path: root/chapter-interprocedural-sccp/src/test/java/com/seaofnodes/simple/SccpTest.java
blob: cad1b7deca20406fa1aa0e1bc1961e4e56064f6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 testCallArgumentFlow() {
        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]++;
                TypeInteger t = (TypeInteger)p._type;
                assertEquals(1,t._min);
                assertEquals(2,t._max);
                assertFalse(p.fun().in(1) instanceof StartNode);
            }
            return null;
        });
        assertEquals(1,parms[0]);
        code.driver(CodeGen.Phase.LocalSched);
        assertEquals("5",Eval2.eval(code,0));
    }
}