mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-31 19:31:55 +00:00
Added a pointer test
This commit is contained in:
parent
120eba90a5
commit
5f1cf097a4
@ -156,7 +156,7 @@ public class Compiler {
|
||||
new Pass3ZeroPageCoalesce(program, log).allocate();
|
||||
new Pass3AssertNoCpuClobber(program, log).check();
|
||||
|
||||
//new Pass4CustomRegisters(program).allocate();
|
||||
//new Pass3CustomRegisters(program).allocate();
|
||||
//new Pass3AssertNoCpuClobber(program, log).check();
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dk.camelot64.kickc.asm.parser;
|
||||
package dk.camelot64.kickc.asm;
|
||||
|
||||
import dk.camelot64.kickc.asm.*;
|
||||
import dk.camelot64.kickc.asm.parser.AsmClobber;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
@ -0,0 +1,3 @@
|
||||
lda #{coby2}
|
||||
ldx {zpby1}
|
||||
sta {cowo1},x
|
@ -0,0 +1,4 @@
|
||||
inc {zpptrby1}
|
||||
bne !+
|
||||
inc {zpptrby1}+1
|
||||
!:
|
@ -28,7 +28,7 @@ public class Pass3AssertNoCpuClobber {
|
||||
return log;
|
||||
}
|
||||
|
||||
/** Uplift one variable */
|
||||
/** Check that no statement clobbers a CPU register used by an alive variable */
|
||||
public void check() {
|
||||
LiveRangeVariables liveRangeVariables = program.getScope().getLiveRangeVariables();
|
||||
RegisterAllocation allocation = program.getScope().getAllocation();
|
||||
|
@ -5,12 +5,12 @@ import dk.camelot64.kickc.icl.*;
|
||||
/**
|
||||
* Register Allocation for variables
|
||||
*/
|
||||
public class Pass4CustomRegisters {
|
||||
public class Pass3CustomRegisters {
|
||||
|
||||
|
||||
private Program program;
|
||||
|
||||
public Pass4CustomRegisters(Program program) {
|
||||
public Pass3CustomRegisters(Program program) {
|
||||
this.program = program;
|
||||
}
|
||||
|
@ -50,8 +50,10 @@ public class Pass3RegisterUplifting {
|
||||
}
|
||||
}
|
||||
// Found max variable!
|
||||
log.append("Uplifting of variable " + maxVar + " to A");
|
||||
allocation.allocate(maxVar.getRef(), new RegisterAllocation.RegisterAByte());
|
||||
if(maxVar!=null) {
|
||||
log.append("Uplifting of variable " + maxVar + " to A");
|
||||
allocation.allocate(maxVar.getRef(), new RegisterAllocation.RegisterAByte());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.CompileLog;
|
||||
import dk.camelot64.kickc.asm.*;
|
||||
import dk.camelot64.kickc.asm.parser.AsmProgramStaticRegisterValues;
|
||||
import dk.camelot64.kickc.asm.AsmProgramStaticRegisterValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -67,6 +67,11 @@ public class TestCompilationOutput extends TestCase {
|
||||
tester.testFile("fibmem");
|
||||
}
|
||||
|
||||
public void testPtrTest() throws IOException, URISyntaxException {
|
||||
TestCompilationOutput tester = new TestCompilationOutput();
|
||||
tester.testFile("ptrtest");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void testFile(String fileName) throws IOException, URISyntaxException {
|
||||
|
75
src/main/java/dk/camelot64/kickc/test/ptrtest.kc
Normal file
75
src/main/java/dk/camelot64/kickc/test/ptrtest.kc
Normal file
@ -0,0 +1,75 @@
|
||||
// Test all types of pointers
|
||||
|
||||
main();
|
||||
|
||||
void main() {
|
||||
lvalue();
|
||||
rvalue();
|
||||
rvaluevar();
|
||||
lvaluevar();
|
||||
}
|
||||
|
||||
void lvalue() {
|
||||
|
||||
// A constant pointer
|
||||
byte[1024] SCREEN = $0400;
|
||||
|
||||
// LValue constant pointer dereference
|
||||
*SCREEN = 1;
|
||||
|
||||
// LValue constant array constant indexing
|
||||
SCREEN[1] = 2;
|
||||
|
||||
// LValue constant array variable indexing
|
||||
byte i=2;
|
||||
while(i<10) {
|
||||
SCREEN[i++] = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void rvalue() {
|
||||
|
||||
// A constant pointer
|
||||
byte[1024] SCREEN = $0400;
|
||||
|
||||
// RValue constant pointer
|
||||
byte b = *SCREEN;
|
||||
|
||||
// RValue constant array pointer constant index
|
||||
b = SCREEN[1];
|
||||
|
||||
// RValue constant array variable index
|
||||
byte i=2;
|
||||
while(i<10) {
|
||||
b = SCREEN[i++];
|
||||
}
|
||||
}
|
||||
|
||||
void lvaluevar() {
|
||||
byte *screen = $0400;
|
||||
|
||||
// LValue Variable pointer dereference
|
||||
byte b=4;
|
||||
byte i=2;
|
||||
while(i<10) {
|
||||
*screen = b;
|
||||
screen++;
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void rvaluevar() {
|
||||
byte *screen = $0400;
|
||||
|
||||
// RValue Variable pointer dereference
|
||||
byte b;
|
||||
byte i=2;
|
||||
while(i<10) {
|
||||
b = *screen;
|
||||
screen++;
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
104
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm
Normal file
104
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm
Normal file
@ -0,0 +1,104 @@
|
||||
BBEGIN:
|
||||
jsr main
|
||||
BEND:
|
||||
main:
|
||||
jsr lvalue
|
||||
main__B1:
|
||||
jsr rvalue
|
||||
main__B2:
|
||||
jsr rvaluevar
|
||||
main__B3:
|
||||
jsr lvaluevar
|
||||
main__Breturn:
|
||||
rts
|
||||
lvaluevar:
|
||||
lvaluevar__B1_from_lvaluevar:
|
||||
lda #<1024
|
||||
sta 3
|
||||
lda #>1024
|
||||
sta 3+1
|
||||
lda #2
|
||||
sta 2
|
||||
lvaluevar__B1:
|
||||
lda 2
|
||||
cmp #10
|
||||
bcc lvaluevar__B2
|
||||
lvaluevar__Breturn:
|
||||
rts
|
||||
lvaluevar__B2:
|
||||
ldy #0
|
||||
lda #4
|
||||
sta (3),y
|
||||
inc 3
|
||||
bne !+
|
||||
inc 3+1
|
||||
!:
|
||||
inc 2
|
||||
lvaluevar__B1_from_B2:
|
||||
jmp lvaluevar__B1
|
||||
rvaluevar:
|
||||
rvaluevar__B1_from_rvaluevar:
|
||||
lda #<1024
|
||||
sta 6
|
||||
lda #>1024
|
||||
sta 6+1
|
||||
lda #2
|
||||
sta 5
|
||||
rvaluevar__B1:
|
||||
lda 5
|
||||
cmp #10
|
||||
bcc rvaluevar__B2
|
||||
rvaluevar__Breturn:
|
||||
rts
|
||||
rvaluevar__B2:
|
||||
ldy #0
|
||||
lda (6),y
|
||||
sta 10
|
||||
inc 6
|
||||
bne !+
|
||||
inc 6+1
|
||||
!:
|
||||
inc 5
|
||||
rvaluevar__B1_from_B2:
|
||||
jmp rvaluevar__B1
|
||||
rvalue:
|
||||
lda 1024
|
||||
lda 1025
|
||||
sta 12
|
||||
rvalue__B1_from_rvalue:
|
||||
lda #2
|
||||
sta 8
|
||||
rvalue__B1:
|
||||
lda 8
|
||||
cmp #10
|
||||
bcc rvalue__B2
|
||||
rvalue__Breturn:
|
||||
rts
|
||||
rvalue__B2:
|
||||
ldx 8
|
||||
lda 1024,x
|
||||
sta 8
|
||||
inc 8
|
||||
rvalue__B1_from_B2:
|
||||
jmp rvalue__B1
|
||||
lvalue:
|
||||
lda #1
|
||||
sta 1024
|
||||
lda #2
|
||||
sta 1025
|
||||
lvalue__B1_from_lvalue:
|
||||
lda #2
|
||||
sta 9
|
||||
lvalue__B1:
|
||||
lda 9
|
||||
cmp #10
|
||||
bcc lvalue__B2
|
||||
lvalue__Breturn:
|
||||
rts
|
||||
lvalue__B2:
|
||||
lda #3
|
||||
ldx 9
|
||||
sta 1024,x
|
||||
inc 9
|
||||
lvalue__B1_from_B2:
|
||||
jmp lvalue__B1
|
79
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.cfg
Normal file
79
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.cfg
Normal file
@ -0,0 +1,79 @@
|
||||
@BEGIN: from
|
||||
[0] call main param-assignment [ ]
|
||||
to:@END
|
||||
@END: from @BEGIN
|
||||
main: from @BEGIN
|
||||
[1] call lvalue param-assignment [ ]
|
||||
to:main::@1
|
||||
main::@1: from main
|
||||
[2] call rvalue param-assignment [ ]
|
||||
to:main::@2
|
||||
main::@2: from main::@1
|
||||
[3] call rvaluevar param-assignment [ ]
|
||||
to:main::@3
|
||||
main::@3: from main::@2
|
||||
[4] call lvaluevar param-assignment [ ]
|
||||
to:main::@return
|
||||
main::@return: from main::@3
|
||||
[5] return [ ]
|
||||
to:@RETURN
|
||||
lvaluevar: from main::@3
|
||||
to:lvaluevar::@1
|
||||
lvaluevar::@1: from lvaluevar lvaluevar::@2
|
||||
[6] (byte*) lvaluevar::screen#2 ← phi( lvaluevar/(word) 1024 lvaluevar::@2/(byte*) lvaluevar::screen#1 ) [ lvaluevar::i#2 lvaluevar::screen#2 ]
|
||||
[6] (byte) lvaluevar::i#2 ← phi( lvaluevar/(byte) 2 lvaluevar::@2/(byte) lvaluevar::i#1 ) [ lvaluevar::i#2 lvaluevar::screen#2 ]
|
||||
[7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ]
|
||||
to:lvaluevar::@return
|
||||
lvaluevar::@return: from lvaluevar::@1
|
||||
[8] return [ ]
|
||||
to:@RETURN
|
||||
lvaluevar::@2: from lvaluevar::@1
|
||||
[9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ]
|
||||
[10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ]
|
||||
[11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ]
|
||||
to:lvaluevar::@1
|
||||
rvaluevar: from main::@2
|
||||
to:rvaluevar::@1
|
||||
rvaluevar::@1: from rvaluevar rvaluevar::@2
|
||||
[12] (byte*) rvaluevar::screen#2 ← phi( rvaluevar/(word) 1024 rvaluevar::@2/(byte*) rvaluevar::screen#1 ) [ rvaluevar::i#2 rvaluevar::screen#2 ]
|
||||
[12] (byte) rvaluevar::i#2 ← phi( rvaluevar/(byte) 2 rvaluevar::@2/(byte) rvaluevar::i#1 ) [ rvaluevar::i#2 rvaluevar::screen#2 ]
|
||||
[13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ]
|
||||
to:rvaluevar::@return
|
||||
rvaluevar::@return: from rvaluevar::@1
|
||||
[14] return [ ]
|
||||
to:@RETURN
|
||||
rvaluevar::@2: from rvaluevar::@1
|
||||
[15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ]
|
||||
[16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ]
|
||||
[17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ]
|
||||
to:rvaluevar::@1
|
||||
rvalue: from main::@1
|
||||
[18] (byte) rvalue::b#0 ← * (word) 1024 [ ]
|
||||
[19] (byte) rvalue::b#1 ← * (word) 1025 [ ]
|
||||
to:rvalue::@1
|
||||
rvalue::@1: from rvalue rvalue::@2
|
||||
[20] (byte) rvalue::i#2 ← phi( rvalue/(byte) 2 rvalue::@2/(byte) rvalue::i#1 ) [ rvalue::i#2 ]
|
||||
[21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ]
|
||||
to:rvalue::@return
|
||||
rvalue::@return: from rvalue::@1
|
||||
[22] return [ ]
|
||||
to:@RETURN
|
||||
rvalue::@2: from rvalue::@1
|
||||
[23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ]
|
||||
[24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ]
|
||||
to:rvalue::@1
|
||||
lvalue: from main
|
||||
[25] *((word) 1024) ← (byte) 1 [ ]
|
||||
[26] *((word) 1025) ← (byte) 2 [ ]
|
||||
to:lvalue::@1
|
||||
lvalue::@1: from lvalue lvalue::@2
|
||||
[27] (byte) lvalue::i#2 ← phi( lvalue/(byte) 2 lvalue::@2/(byte) lvalue::i#1 ) [ lvalue::i#2 ]
|
||||
[28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ]
|
||||
to:lvalue::@return
|
||||
lvalue::@return: from lvalue::@1
|
||||
[29] return [ ]
|
||||
to:@RETURN
|
||||
lvalue::@2: from lvalue::@1
|
||||
[30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ]
|
||||
[31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ]
|
||||
to:lvalue::@1
|
2443
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log
Normal file
2443
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log
Normal file
File diff suppressed because it is too large
Load Diff
53
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.sym
Normal file
53
src/main/java/dk/camelot64/kickc/test/ref/ptrtest.sym
Normal file
@ -0,0 +1,53 @@
|
||||
(label) @BEGIN
|
||||
(label) @END
|
||||
(void()) lvalue()
|
||||
(label) lvalue::@1
|
||||
(label) lvalue::@2
|
||||
(label) lvalue::@return
|
||||
(byte[1024]) lvalue::SCREEN
|
||||
(byte) lvalue::i
|
||||
(byte) lvalue::i#1 zp byte:9 22.0
|
||||
(byte) lvalue::i#2 zp byte:9 14.666666666666666
|
||||
(void()) lvaluevar()
|
||||
(label) lvaluevar::@1
|
||||
(label) lvaluevar::@2
|
||||
(label) lvaluevar::@return
|
||||
(byte) lvaluevar::b
|
||||
(byte) lvaluevar::i
|
||||
(byte) lvaluevar::i#1 zp byte:2 22.0
|
||||
(byte) lvaluevar::i#2 zp byte:2 8.25
|
||||
(byte*) lvaluevar::screen
|
||||
(byte*) lvaluevar::screen#1 zp ptr byte:3 11.0
|
||||
(byte*) lvaluevar::screen#2 zp ptr byte:3 11.0
|
||||
(void()) main()
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(void()) rvalue()
|
||||
(label) rvalue::@1
|
||||
(label) rvalue::@2
|
||||
(label) rvalue::@return
|
||||
(byte[1024]) rvalue::SCREEN
|
||||
(byte) rvalue::b
|
||||
(byte) rvalue::b#0 reg byte a Infinity
|
||||
(byte) rvalue::b#1 zp byte:12 Infinity
|
||||
(byte) rvalue::b#2 zp byte:8 Infinity
|
||||
(byte) rvalue::i
|
||||
(byte) rvalue::i#1 zp byte:8 22.0
|
||||
(byte) rvalue::i#2 zp byte:8 14.666666666666666
|
||||
(void()) rvaluevar()
|
||||
(label) rvaluevar::@1
|
||||
(label) rvaluevar::@2
|
||||
(label) rvaluevar::@return
|
||||
(byte) rvaluevar::b
|
||||
(byte) rvaluevar::b#0 zp byte:10 Infinity
|
||||
(byte) rvaluevar::i
|
||||
(byte) rvaluevar::i#1 zp byte:5 22.0
|
||||
(byte) rvaluevar::i#2 zp byte:5 8.25
|
||||
(byte*) rvaluevar::screen
|
||||
(byte*) rvaluevar::screen#1 zp ptr byte:6 11.0
|
||||
(byte*) rvaluevar::screen#2 zp ptr byte:6 11.0
|
||||
|
||||
zp byte:2 [ lvaluevar::i#2 lvaluevar::i#1 rvaluevar::i#2 rvaluevar::i#1 rvalue::i#2 rvalue::i#1 rvalue::b#2 lvalue::i#2 lvalue::i#1 rvaluevar::b#0 rvalue::b#0 rvalue::b#1 ]
|
||||
zp ptr byte:3 [ lvaluevar::screen#2 lvaluevar::screen#1 rvaluevar::screen#2 rvaluevar::screen#1 ]
|
Loading…
x
Reference in New Issue
Block a user