diff options
| author | Cliff Click <cliffc@acm.org> | 2025-03-18 15:13:43 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-03-18 15:13:43 -0700 |
| commit | 0328057dc9e5a7b4bcee4b9fe9260c91a59d5b5e (patch) | |
| tree | 04a5789018f2b360477147ff59617fe47520f7ec /chapter21/src/test | |
| parent | fbe1e0a84e154b17e09055b184f33cdb08a0138c (diff) | |
| download | Simple-0328057dc9e5a7b4bcee4b9fe9260c91a59d5b5e.tar.gz Simple-0328057dc9e5a7b4bcee4b9fe9260c91a59d5b5e.zip | |
Update Chapter21Test.java
Diffstat (limited to 'chapter21/src/test')
| -rw-r--r-- | chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index ad1f39b2..f652fa97 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -2,8 +2,9 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; import com.seaofnodes.simple.print.ASMPrinter; -import org.junit.Assert; -import org.junit.Ignore; +import java.nio.file.Files; +import java.io.IOException; +import java.nio.file.Path; import org.junit.Test; import static com.seaofnodes.simple.Main.PORTS; import static org.junit.Assert.*; @@ -42,10 +43,7 @@ public class Chapter21Test { testCPU(src,"arm" , "SystemV",0,"return (ori,arg);"); } - @Test - public void testNewtonFloat() { - String src = -""" + public static final String newton = """ // Newtons approximation to the square root val sqrt = { flt x -> flt guess = x; @@ -58,45 +56,45 @@ val sqrt = { flt x -> flt farg = arg; return sqrt(farg) + sqrt(farg+2.0); """; - testCPU(src,"x86_64_v2", "SystemV",25,null); - testCPU(src,"riscv" , "SystemV",17,null); - testCPU(src,"arm" , "SystemV",18,null); + + @Test + public void testNewtonFloat() { + testCPU(newton,"x86_64_v2", "SystemV",25,null); + testCPU(newton,"riscv" , "SystemV",17,null); + testCPU(newton,"arm" , "SystemV",18,null); } @Test public void testArray1() { - String src = - """ - int[] !ary = new int[arg]; - // Fill [0,1,2,3,4,...] - for( int i=0; i<ary#; i++ ) - ary[i] = i; - // Fill [0,1,3,6,10,...] - for( int i=0; i<ary#-1; i++ ) - ary[i+1] += ary[i]; - return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 - """; + String src = """ +int[] !ary = new int[arg]; +// Fill [0,1,2,3,4,...] +for( int i=0; i<ary#; i++ ) + ary[i] = i; +// Fill [0,1,3,6,10,...] +for( int i=0; i<ary#-1; i++ ) + ary[i+1] += ary[i]; +return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 +"""; testCPU(src,"x86_64_v2", "SystemV",3,"return .[];"); testCPU(src,"riscv" , "SystemV",1,"return (add,.[],(mul,.[],1000));"); testCPU(src,"arm" , "SystemV",1,"return (add,.[],(mul,.[],1000));"); } + + // Read test case from disk @Test - public void testExport() { - CodeGen code = new CodeGen( - """ -// Newtons approximation to the square root -val sqrt = { flt x -> - flt guess = x; - while( 1 ) { - flt next = (x/guess + guess)/2; - if( next == guess ) return guess; - guess = next; + public void testPersons() throws IOException { + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/Person.smp")); + testCPU(src,"x86_64_v2", "Win64" ,3,null); + testCPU(src,"riscv" , "SystemV",1,null); + testCPU(src,"arm" , "SystemV",1,null); } -}; -flt farg = arg; -return sqrt(farg) + sqrt(farg+2.0); - """); + + + @Test + public void testExport() { + CodeGen code = new CodeGen(newton); code.parse().opto().typeCheck().instSelect(PORTS, "x86_64_v2", "SystemV").GCM().localSched().regAlloc().encode().exportELF(); } } |
