diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java index 23014f73c..77a667553 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1UnwindStructValues.java @@ -76,12 +76,14 @@ public class Pass1UnwindStructValues extends Pass1Base { getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> { if(programValue.get() instanceof StructMemberRef) { StructMemberRef structMemberRef = (StructMemberRef) programValue.get(); - StructUnwinding.StructMemberUnwinding memberVariables = getStructMemberUnwinding(structMemberRef.getStruct(), currentStmt, stmtIt, currentBlock); - if(memberVariables != null && memberVariables != POSTPONE_UNWINDING) { - VariableRef structMemberVariable = (VariableRef) memberVariables.getMemberUnwinding(structMemberRef.getMemberName()); - getLog().append("Replacing struct member reference " + structMemberRef.toString(getProgram()) + " with member unwinding reference " + structMemberVariable.toString(getProgram())); - programValue.set(structMemberVariable); - modified.set(true); + if(structMemberRef.getStruct() instanceof VariableRef) { + StructUnwinding.StructMemberUnwinding memberVariables = getStructMemberUnwinding(structMemberRef.getStruct(), currentStmt, stmtIt, currentBlock); + if(memberVariables != null && memberVariables != POSTPONE_UNWINDING) { + LValue structMemberVariable = memberVariables.getMemberUnwinding(structMemberRef.getMemberName()); + getLog().append("Replacing struct member reference " + structMemberRef.toString(getProgram()) + " with member unwinding reference " + structMemberVariable.toString(getProgram())); + programValue.set(structMemberVariable); + modified.set(true); + } } } }); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java b/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java index 0a4528000..f326a7841 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java @@ -84,7 +84,11 @@ public class Pass5FixLongBranches extends Pass5AsmOptimization { try { asmRes = KickAssembler.main2(new String[]{asmFile.getAbsolutePath(), "-o", asmPrgFile.getAbsolutePath()}); } catch(Throwable e) { - throw new CompileError("Error! KickAssembler failed, while trying to fix long branch. " + e); + if(e instanceof AssertionError && e.getMessage().contains("Invalid number of bytes in memblock!")) { + throw new CompileError("Error! KickAssembler failed due to assertion. Please run java without -ea / -enableassertions.", e); + } else { + throw new CompileError("Error! KickAssembler failed, while trying to fix long branch. " + e); + } } finally { System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); } diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 8063c28a8..d97eb6d24 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -75,45 +75,6 @@ public class TestPrograms { compileAndCompare("sieve"); } - @Test - public void testProblemPointerInsideStructSizeofRewriting() throws IOException, URISyntaxException { - compileAndCompare("problem-pointer-inside-struct-sizeof-rewriting"); - } - - @Test - public void testProblemStructPointerParam() throws IOException, URISyntaxException { - compileAndCompare("problem-struct-pointer-param"); - } - - @Test - public void testProblemArrayStructParam() throws IOException, URISyntaxException { - compileAndCompare("problem-array-struct-param"); - } - - @Test - public void testProblemStructReturnToPointer() throws IOException, URISyntaxException { - compileAndCompare("problem-struct-return-to-pointer"); - } - - @Test - public void testProblemStructReturnPointerDeref() throws IOException, URISyntaxException { - compileAndCompare("problem-struct-return-pointer-deref"); - } - - /* - @Test - public void testProblemArrayStructInit() throws IOException, URISyntaxException { - compileAndCompare("problem-array-struct-init"); - } - */ - - /* - @Test - public void testProblemInlineStructReturn() throws IOException, URISyntaxException { - compileAndCompare("problem-inline-struct-return", log().verboseCreateSsa()); - } - */ - @Test public void testTrueTypeSplines() throws IOException, URISyntaxException { compileAndCompare("complex/splines/truetype-splines"); @@ -372,6 +333,40 @@ public class TestPrograms { compileAndCompare("textbox"); } + /* + @Test + public void testProblemArrayStructInit() throws IOException, URISyntaxException { + compileAndCompare("problem-array-struct-init"); + } + */ + + /* + @Test + public void testProblemInlineStructReturn() throws IOException, URISyntaxException { + compileAndCompare("problem-inline-struct-return", log().verboseCreateSsa()); + } + */ + + @Test + public void testStructPtr19() throws IOException, URISyntaxException { + compileAndCompare("struct-ptr-19"); + } + + @Test + public void testStructPtr18() throws IOException, URISyntaxException { + compileAndCompare("struct-ptr-18"); + } + + @Test + public void testStructPtr17() throws IOException, URISyntaxException { + compileAndCompare("struct-ptr-17"); + } + + @Test + public void testStructPtr16() throws IOException, URISyntaxException { + compileAndCompare("struct-ptr-16"); + } + @Test public void testStructPtr15() throws IOException, URISyntaxException { compileAndCompare("struct-ptr-15"); @@ -487,6 +482,11 @@ public class TestPrograms { assertError("struct-err-0", "Unknown struct type"); } + @Test + public void testStruct10() throws IOException, URISyntaxException { + compileAndCompare("struct-10"); + } + @Test public void testStruct9() throws IOException, URISyntaxException { compileAndCompare("struct-9"); diff --git a/src/test/kc/problem-pointer-inside-struct-sizeof-rewriting.kc b/src/test/kc/struct-10.kc similarity index 100% rename from src/test/kc/problem-pointer-inside-struct-sizeof-rewriting.kc rename to src/test/kc/struct-10.kc diff --git a/src/test/kc/problem-struct-return-pointer-deref.kc b/src/test/kc/struct-ptr-16.kc similarity index 100% rename from src/test/kc/problem-struct-return-pointer-deref.kc rename to src/test/kc/struct-ptr-16.kc diff --git a/src/test/kc/problem-struct-return-to-pointer.kc b/src/test/kc/struct-ptr-17.kc similarity index 100% rename from src/test/kc/problem-struct-return-to-pointer.kc rename to src/test/kc/struct-ptr-17.kc diff --git a/src/test/kc/problem-array-struct-param.kc b/src/test/kc/struct-ptr-18.kc similarity index 100% rename from src/test/kc/problem-array-struct-param.kc rename to src/test/kc/struct-ptr-18.kc diff --git a/src/test/kc/problem-struct-pointer-param.kc b/src/test/kc/struct-ptr-19.kc similarity index 100% rename from src/test/kc/problem-struct-pointer-param.kc rename to src/test/kc/struct-ptr-19.kc diff --git a/src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.asm b/src/test/ref/struct-10.asm similarity index 100% rename from src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.asm rename to src/test/ref/struct-10.asm diff --git a/src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.cfg b/src/test/ref/struct-10.cfg similarity index 100% rename from src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.cfg rename to src/test/ref/struct-10.cfg diff --git a/src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.log b/src/test/ref/struct-10.log similarity index 100% rename from src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.log rename to src/test/ref/struct-10.log diff --git a/src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.sym b/src/test/ref/struct-10.sym similarity index 100% rename from src/test/ref/problem-pointer-inside-struct-sizeof-rewriting.sym rename to src/test/ref/struct-10.sym diff --git a/src/test/ref/problem-struct-return-pointer-deref.asm b/src/test/ref/struct-ptr-16.asm similarity index 100% rename from src/test/ref/problem-struct-return-pointer-deref.asm rename to src/test/ref/struct-ptr-16.asm diff --git a/src/test/ref/problem-struct-return-pointer-deref.cfg b/src/test/ref/struct-ptr-16.cfg similarity index 100% rename from src/test/ref/problem-struct-return-pointer-deref.cfg rename to src/test/ref/struct-ptr-16.cfg diff --git a/src/test/ref/problem-struct-return-pointer-deref.log b/src/test/ref/struct-ptr-16.log similarity index 100% rename from src/test/ref/problem-struct-return-pointer-deref.log rename to src/test/ref/struct-ptr-16.log diff --git a/src/test/ref/problem-struct-return-pointer-deref.sym b/src/test/ref/struct-ptr-16.sym similarity index 100% rename from src/test/ref/problem-struct-return-pointer-deref.sym rename to src/test/ref/struct-ptr-16.sym diff --git a/src/test/ref/problem-struct-return-to-pointer.asm b/src/test/ref/struct-ptr-17.asm similarity index 100% rename from src/test/ref/problem-struct-return-to-pointer.asm rename to src/test/ref/struct-ptr-17.asm diff --git a/src/test/ref/problem-struct-return-to-pointer.cfg b/src/test/ref/struct-ptr-17.cfg similarity index 100% rename from src/test/ref/problem-struct-return-to-pointer.cfg rename to src/test/ref/struct-ptr-17.cfg diff --git a/src/test/ref/problem-struct-return-to-pointer.log b/src/test/ref/struct-ptr-17.log similarity index 100% rename from src/test/ref/problem-struct-return-to-pointer.log rename to src/test/ref/struct-ptr-17.log diff --git a/src/test/ref/problem-struct-return-to-pointer.sym b/src/test/ref/struct-ptr-17.sym similarity index 100% rename from src/test/ref/problem-struct-return-to-pointer.sym rename to src/test/ref/struct-ptr-17.sym diff --git a/src/test/ref/problem-array-struct-param.asm b/src/test/ref/struct-ptr-18.asm similarity index 100% rename from src/test/ref/problem-array-struct-param.asm rename to src/test/ref/struct-ptr-18.asm diff --git a/src/test/ref/problem-array-struct-param.cfg b/src/test/ref/struct-ptr-18.cfg similarity index 100% rename from src/test/ref/problem-array-struct-param.cfg rename to src/test/ref/struct-ptr-18.cfg diff --git a/src/test/ref/problem-array-struct-param.log b/src/test/ref/struct-ptr-18.log similarity index 100% rename from src/test/ref/problem-array-struct-param.log rename to src/test/ref/struct-ptr-18.log diff --git a/src/test/ref/problem-array-struct-param.sym b/src/test/ref/struct-ptr-18.sym similarity index 100% rename from src/test/ref/problem-array-struct-param.sym rename to src/test/ref/struct-ptr-18.sym diff --git a/src/test/ref/problem-struct-pointer-param.asm b/src/test/ref/struct-ptr-19.asm similarity index 100% rename from src/test/ref/problem-struct-pointer-param.asm rename to src/test/ref/struct-ptr-19.asm diff --git a/src/test/ref/problem-struct-pointer-param.cfg b/src/test/ref/struct-ptr-19.cfg similarity index 100% rename from src/test/ref/problem-struct-pointer-param.cfg rename to src/test/ref/struct-ptr-19.cfg diff --git a/src/test/ref/problem-struct-pointer-param.log b/src/test/ref/struct-ptr-19.log similarity index 100% rename from src/test/ref/problem-struct-pointer-param.log rename to src/test/ref/struct-ptr-19.log diff --git a/src/test/ref/problem-struct-pointer-param.sym b/src/test/ref/struct-ptr-19.sym similarity index 100% rename from src/test/ref/problem-struct-pointer-param.sym rename to src/test/ref/struct-ptr-19.sym