1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-20 15:29:10 +00:00

far call test cases.

This commit is contained in:
Sven Van de Velde 2022-11-16 17:41:25 +01:00 committed by Flight_Control
parent 4a4d6f72d0
commit f948ce0571
8 changed files with 175 additions and 5 deletions

View File

@ -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");

View File

@ -1,5 +0,0 @@
al C:400 .SCREEN
al C:80b .upstartEnd
al C:80d .main
al C:819 .plus
al C:37 .return

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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]++;
}
}

View File

@ -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;
}

View File

@ -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;
}
}