diff options
| author | Cliff Click <cliffc@acm.org> | 2026-09-11 12:31:25 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-09-11 12:31:25 -0700 |
| commit | 413353dc37fead68507856fca500fa59423dca69 (patch) | |
| tree | f830ec1a8acef94fc92a78e8686f7f955e2711e1 /chapter25/src/test/java/com/seaofnodes | |
| parent | 6813c5ca6c3d87dc78995bd44668593c3b9e0883 (diff) | |
| download | Simple-413353dc37fead68507856fca500fa59423dca69.tar.gz Simple-413353dc37fead68507856fca500fa59423dca69.zip | |
Optional reset Types so Fuzzer can work.
FunNodes never GVN.
Diffstat (limited to 'chapter25/src/test/java/com/seaofnodes')
6 files changed, 29 insertions, 27 deletions
diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java b/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java index b21734b4..494f503d 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java @@ -18,6 +18,16 @@ import static org.junit.Assert.*; public class Chapter25Test { + @IGnore + @Test + public void testJig() { + String src = "struct _Oan {}; return --arg; arg=++arg;"; + CodeGen code = new CodeGen(src).driver(CodeGen.Phase.TypeCheck); + assertEquals("1",Eval2.eval(code,0)); + } + + + private static final String SYS_BLDDIR = "build/objs/lib_"+TestC.CPU_ABI; private static final File SYS_FILE = new File(SYS_BLDDIR+"/sys.o"); @@ -25,7 +35,7 @@ public class Chapter25Test { public void testForwardConstructor() { CodeGen code = new CodeGen("src/test/java/com/seaofnodes/simple/test_smp/forward_ctor", "build/objs/forward_ctor_parse",null, - "m",null,123L,TypeInteger.BOT); + "m",null,123L,true,TypeInteger.BOT); code.driver(CodeGen.Phase.TypeCheck); } @@ -62,7 +72,6 @@ public class Chapter25Test { assertEquals("1",Eval2.eval(code,0)); } - @Test @Ignore public void testModule0() throws IOException { String MODDIR = "src/test/java/com/seaofnodes/simple/test0"; @@ -77,7 +86,7 @@ public class Chapter25Test { // Since A refers to B also: // Compile MODDIR/A/B.smp into MODDIR/A/B.o CodeGen code1 = new CodeGen(MODDIR, BLDDIR,null, - "A",null,123L,TypeInteger.BOT); + "A",null,123L,true,TypeInteger.BOT); code1.driver(CodeGen.Phase.Export,TestC.CPU_PORT,TestC.CALL_CONVENTION); // Verify produces A.o, A/B.o @@ -94,7 +103,7 @@ public class Chapter25Test { // Compile again A, expecting both A.o and A/B.o to be up-to-date and not compiled CodeGen code2 = new CodeGen(MODDIR, BLDDIR, null, - "A",null,123L,TypeInteger.BOT); + "A",null,123L,true,TypeInteger.BOT); code2.driver(CodeGen.Phase.Export,TestC.CPU_PORT,TestC.CALL_CONVENTION); assertTrue( a_file.exists() ); @@ -108,7 +117,7 @@ public class Chapter25Test { // Touch A.smp and recompile. A/B.o should not recompile. new File(MODDIR+"/A.smp").setLastModified(System.currentTimeMillis()); CodeGen code3 = new CodeGen(MODDIR, BLDDIR,null, - "A",null,123L,TypeInteger.BOT); + "A",null,123L,true,TypeInteger.BOT); code3.driver(CodeGen.Phase.Export,TestC.CPU_PORT,TestC.CALL_CONVENTION); long a_msec3 = a_file.lastModified(); @@ -124,7 +133,7 @@ public class Chapter25Test { // Modify B.smp and recompile A/B.o; it should recompile and A.o should not. writeB(MODDIR,7); CodeGen code4 = new CodeGen(MODDIR, BLDDIR,null, - "A/B",null,123L,TypeInteger.BOT); + "A/B",null,123L,true,TypeInteger.BOT); code4.driver(CodeGen.Phase.Export,TestC.CPU_PORT,TestC.CALL_CONVENTION); long a_msec4 = a_file.lastModified(); @@ -139,7 +148,7 @@ public class Chapter25Test { // Recompile A.o, it should recompile despite not being touched because // it depends on A/B.o which recompiled in the prior step. CodeGen code5 = new CodeGen(MODDIR, BLDDIR,null, - "A",null,123L,TypeInteger.BOT); + "A",null,123L,true,TypeInteger.BOT); code5.driver(CodeGen.Phase.Export,TestC.CPU_PORT,TestC.CALL_CONVENTION); long a_msec5 = a_file.lastModified(); @@ -221,7 +230,7 @@ public class Chapter25Test { String expected = "Hello, World!\n"; String prog = "return sys.io.p_noInline(\""+expected+"\") - "+expected.length()+";"; CodeGen code = new CodeGen(null,"build/objs",new Ary<>(new String[]{SYS_BLDDIR}), - base,prog,123L,TypeInteger.BOT); + base,prog,123L,true,TypeInteger.BOT); code.driver(TestC.CPU_PORT,TestC.CALL_CONVENTION,false,true); String obj = "build/objs/"+base+".o"; diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Simple.java b/chapter25/src/test/java/com/seaofnodes/simple/Simple.java index a5d104e7..91f690eb 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/Simple.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/Simple.java @@ -223,7 +223,7 @@ Options: // Compilation pipeline Ary<String> externPaths = libPaths.isEmpty() ? null : new Ary<>(libPaths.toArray(new String[0])); - CodeGen code = new CodeGen(modPath.toString(), outPath.toString(), externPaths, srcName, src, 456, TypeInteger.BOT ); + CodeGen code = new CodeGen(modPath.toString(), outPath.toString(), externPaths, srcName, src, 456, true, TypeInteger.BOT ); code.driver(Phase.LastPhase,cpu,abi, false, emit_main || do_run || do_eval, dump); if( do_codegen && print_asm ) diff --git a/chapter25/src/test/java/com/seaofnodes/simple/TestC.java b/chapter25/src/test/java/com/seaofnodes/simple/TestC.java index bd8a52cc..b43d117f 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/TestC.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/TestC.java @@ -118,7 +118,7 @@ public abstract class TestC { String obj = pathBase+".o"; String exe = pathBase+(OS.startsWith("Windows") ? ".exe" : ""); // Compile simple, emit ELF - CodeGen code = new CodeGen(null,"build/objs",externPaths,base,src,126L,TypeInteger.BOT); + CodeGen code = new CodeGen(null,"build/objs",externPaths,base,src,126L,true,TypeInteger.BOT); code.driver( CPU_PORT, simple_conv, false, cfile==null ); linkExe(obj, c_conv, cfile, linkObjs(externPaths), exe); diff --git a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java index c1ffa6c1..37fa03a6 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java @@ -82,10 +82,10 @@ public class Fuzzer { private static void runCheck(String script, boolean valid) { CodeGen code1; try { - code1 = FuzzerUtils.parse(script, 123); + code1 = FuzzerUtils.parse(script, 123, true); } catch (RuntimeException e1) { try { - FuzzerUtils.parse(script, 456); + FuzzerUtils.parse(script, 456, true); } catch (RuntimeException e2) { if (FuzzerUtils.isExceptionFromSameCause(e1, e2)) { if (!valid || e1.getClass() == Parser.ParseException.class) return; @@ -95,7 +95,7 @@ public class Fuzzer { } throw e1; } - CodeGen code2 = FuzzerUtils.parse(script, 456); + CodeGen code2 = FuzzerUtils.parse(script, 456, false); checkGraphs(code1, code2, 0); checkGraphs(code1, code2, 1); checkGraphs(code1, code2, 10); diff --git a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java index 9175e380..7b3917f4 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/FuzzerUtils.java @@ -94,13 +94,13 @@ class FuzzerUtils { /** * Parse script with peepholes enabled or disabled */ - public static CodeGen parse(String script, long workListSeed) { + public static CodeGen parse(String script, long workListSeed, boolean resetTypes ) { var err = System.err; var out = System.out; try { System.setErr(NULL_PRINT_STREAM); System.setOut(NULL_PRINT_STREAM); - var code = new CodeGen(script, workListSeed); + var code = new CodeGen(script, workListSeed, resetTypes); return code.driver(CodeGen.Phase.LocalSched); } finally { System.setErr(err); diff --git a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java index dde5a1dc..7ecde7c0 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java @@ -83,18 +83,11 @@ public class ScriptGenerator { } } - private static final List<TypeInt> INTTYPES = new ArrayList<>(); - static { - for( var e : Parser.TYPES.entrySet() ) { - if( e.getValue() instanceof TypeInteger ) { - INTTYPES.add(new TypeInt(e.getKey())); - } - } - } - - private static final Type TYPE_INT = INTTYPES.stream().filter(t->t.name.equals("int")).findAny().get(); - private static final Type TYPE_BOOL = INTTYPES.stream().filter(t->t.name.equals("bool")).findAny().get(); + private static final TypeInt TYPE_INT = new TypeInt("int"); + private static final TypeInt TYPE_BOOL = new TypeInt("bool"); + private static final TypeInt TYPE_U8 = new TypeInt("u8"); + private static final List<TypeInt> INTTYPES = new ArrayList<>(){{add(TYPE_INT); add(TYPE_BOOL); add(TYPE_U8); }}; private static class Variable { final String name; @@ -935,4 +928,4 @@ public class ScriptGenerator { else sb.append(v.name); } -}
\ No newline at end of file +} |
