From f948ce0571feaa19ffea371391b24f6d1505a42c Mon Sep 17 00:00:00 2001 From: Sven Van de Velde Date: Wed, 16 Nov 2022 17:41:25 +0100 Subject: [PATCH] far call test cases. --- .../kickc/test/TestProgramsFast.java | 45 +++++++++++++++++++ .../procedure-callingconvention-phi-far-0.vs | 5 --- ...procedure-callingconvention-stack-far-1.c} | 0 .../procedure-callingconvention-stack-far-2.c | 19 ++++++++ .../procedure-callingconvention-stack-far-3.c | 15 +++++++ .../procedure-callingconvention-stack-far-4.c | 43 ++++++++++++++++++ .../procedure-callingconvention-stack-far-5.c | 35 +++++++++++++++ .../procedure-callingconvention-stack-far-6.c | 18 ++++++++ 8 files changed, 175 insertions(+), 5 deletions(-) delete mode 100644 src/test/kc/$workspacedir/target/procedure-callingconvention-phi-far-0.vs rename src/test/kc/{procedure-callingconvention-phi-far-1.c => procedure-callingconvention-stack-far-1.c} (100%) create mode 100644 src/test/kc/procedure-callingconvention-stack-far-2.c create mode 100644 src/test/kc/procedure-callingconvention-stack-far-3.c create mode 100644 src/test/kc/procedure-callingconvention-stack-far-4.c create mode 100644 src/test/kc/procedure-callingconvention-stack-far-5.c create mode 100644 src/test/kc/procedure-callingconvention-stack-far-6.c diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index c6cb04fe1..7ef17a7d0 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -1495,6 +1495,51 @@ public class TestProgramsFast extends TestPrograms { compileAndCompare("declared-memory-var-0.c"); } + @Test + public void testProcedureCallingConventionStackFar13() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-13.c"); + } + + @Test + public void testProcedureCallingConventionStackFar6() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-6.c"); + } + + @Test + public void testProcedureCallingConventionStackFar5() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-5.c"); + } + + @Test + public void testProcedureCallingConventionStackFar4() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-4.c"); + } + + @Test + public void testProcedureCallingConventionStackFar3() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-3.c"); + } + + @Test + public void testProcedureCallingConventionStackFar2() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-2.c"); + } + + @Test + public void testProcedureCallingConventionStackFar1() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-1.c"); + } + + @Test + public void testProcedureCallingConventionStackFar0() throws IOException { + compileAndCompare("procedure-callingconvention-stack-far-0.c"); + } + + @Test + public void testProcedureCallingConventionPhiFar0() throws IOException { + compileAndCompare("procedure-callingconvention-phi-far-0.c"); + } + @Test public void testProcedureCallingConventionStack13() throws IOException { compileAndCompare("procedure-callingconvention-stack-13.c"); diff --git a/src/test/kc/$workspacedir/target/procedure-callingconvention-phi-far-0.vs b/src/test/kc/$workspacedir/target/procedure-callingconvention-phi-far-0.vs deleted file mode 100644 index 243aa53b5..000000000 --- a/src/test/kc/$workspacedir/target/procedure-callingconvention-phi-far-0.vs +++ /dev/null @@ -1,5 +0,0 @@ -al C:400 .SCREEN -al C:80b .upstartEnd -al C:80d .main -al C:819 .plus -al C:37 .return diff --git a/src/test/kc/procedure-callingconvention-phi-far-1.c b/src/test/kc/procedure-callingconvention-stack-far-1.c similarity index 100% rename from src/test/kc/procedure-callingconvention-phi-far-1.c rename to src/test/kc/procedure-callingconvention-stack-far-1.c diff --git a/src/test/kc/procedure-callingconvention-stack-far-2.c b/src/test/kc/procedure-callingconvention-stack-far-2.c new file mode 100644 index 000000000..bdcb7c1df --- /dev/null +++ b/src/test/kc/procedure-callingconvention-stack-far-2.c @@ -0,0 +1,19 @@ +// Test a procedure with calling convention stack +// A slightly more complex call + +char* const SCREEN = (char*)0x0400; + +char i = 0; + +void main(void) { + for(char a:0..1) { + char v = a+1; + char w = plus('0', v); + SCREEN[i] = w+a; + } +} + +char __far(1) __stackcall plus(char a, char b) { + i++; + return a+b; +} \ No newline at end of file diff --git a/src/test/kc/procedure-callingconvention-stack-far-3.c b/src/test/kc/procedure-callingconvention-stack-far-3.c new file mode 100644 index 000000000..9586a90fd --- /dev/null +++ b/src/test/kc/procedure-callingconvention-stack-far-3.c @@ -0,0 +1,15 @@ +// Test a procedure with calling convention stack +// Recursive fibonacci + +char* const SCREEN = (char*)0x0400; + +void main(void) { + *SCREEN = fib(5); +} + +char __far(1) __stackcall fib(char n) { + if (n == 0 || n == 1) + return n; + else + return (fib(n-1) + fib(n-2)); +} \ No newline at end of file diff --git a/src/test/kc/procedure-callingconvention-stack-far-4.c b/src/test/kc/procedure-callingconvention-stack-far-4.c new file mode 100644 index 000000000..0fd8e1aa9 --- /dev/null +++ b/src/test/kc/procedure-callingconvention-stack-far-4.c @@ -0,0 +1,43 @@ +// Test a procedure with calling convention stack +// Illustrates live range problem with function variable printother::i and global variable val + +#pragma calling(__stackcall) + +char* const SCREEN = (char*)0x0400; + +char val = 0; + +void main(void) { + for(char i:0..5) { + pval(); + printother(); + ival(); + } +} + +void __far(1) pval() { + printval(); +} + +void __far(2) ival() { + incval(); +} + +void __far(3) printval() { + SCREEN[0] = val; +} + +void __far(4) incval() { + val++; +} + +void __far(5) printother() { + for(char i:0..5) { + (SCREEN+40)[i]++; + } +} + + + + + diff --git a/src/test/kc/procedure-callingconvention-stack-far-5.c b/src/test/kc/procedure-callingconvention-stack-far-5.c new file mode 100644 index 000000000..c006ecd6f --- /dev/null +++ b/src/test/kc/procedure-callingconvention-stack-far-5.c @@ -0,0 +1,35 @@ +// Test a procedure with calling convention stack +// Returning and passing struct values + +#pragma calling(__stackcall) +#pragma struct_model(classic) + +char* const SCREEN = (char*)0x0400; +char idx = 0; + +struct Point { + char x; + char y; +}; + +void main(void) { + for(char i=0;i<5;i++) { + struct Point p = get(i); + print(p); + } +} + +struct Point __far(1) get(char i) { + struct Point p = { i, i/2 }; + return p; +} + +void __far(2) print(struct Point p) { + SCREEN[idx++] = p.x; + SCREEN[idx++] = p.y; +} + + + + + diff --git a/src/test/kc/procedure-callingconvention-stack-far-6.c b/src/test/kc/procedure-callingconvention-stack-far-6.c new file mode 100644 index 000000000..925beedec --- /dev/null +++ b/src/test/kc/procedure-callingconvention-stack-far-6.c @@ -0,0 +1,18 @@ +// Test a procedure with calling convention stack +// Recursion that works (no local variables) + +char* const SCREEN = (char*)0x0400; + +void main(void) { + *SCREEN = pow2(6); +} + +char __stackcall __far(1) pow2(char n) { + if (n == 0) + return 1; + else { + char c = pow2(n-1); + return c+c; + } + +} \ No newline at end of file