From b466f2f5cc3cdd6883cad30b5c3b9052f296b748 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 30 Jan 2018 22:23:07 +0100 Subject: [PATCH] Added test provoking a register clobber error. --- .../camelot64/kickc/passes/Pass4AssertNoCpuClobber.java | 2 +- src/test/java/dk/camelot64/kickc/test/TestPrograms.java | 5 +++++ .../java/dk/camelot64/kickc/test/kc/register-clobber.kc | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/register-clobber.kc diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4AssertNoCpuClobber.java b/src/main/java/dk/camelot64/kickc/passes/Pass4AssertNoCpuClobber.java index 0e81f846c..d1f943de4 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4AssertNoCpuClobber.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4AssertNoCpuClobber.java @@ -41,7 +41,7 @@ public class Pass4AssertNoCpuClobber extends Pass2Base { */ public void check() { if(hasClobberProblem(true)) { - throw new RuntimeException("CLOBBER ERROR! See log for more info."); + throw new CompileError("CLOBBER ERROR! See log for more info."); } } diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 723feda5d..6cea982ab 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -507,6 +507,11 @@ public class TestPrograms { assertError("illegal-alignment", "Cannot align variable"); } + @Test + public void testRegisterClobber() throws IOException, URISyntaxException { + assertError("register-clobber", "CLOBBER ERROR"); + } + private void assertError(String kcFile, String expectError) throws IOException, URISyntaxException { try { compileAndCompare(kcFile); diff --git a/src/test/java/dk/camelot64/kickc/test/kc/register-clobber.kc b/src/test/java/dk/camelot64/kickc/test/kc/register-clobber.kc new file mode 100644 index 000000000..97a3451e1 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/register-clobber.kc @@ -0,0 +1,8 @@ +void main() { + byte* SCREEN = $0400; + for( register(X) byte x: 0..100 ) { + for( register(X) byte y: 0..100 ) { + SCREEN[x] = y; + } + } +}