1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-15 09:23:47 +00:00

Moved KC test files into separate folder

This commit is contained in:
jespergravgaard 2018-01-06 16:36:39 +01:00
parent 40153fc6d6
commit 2603740d15
189 changed files with 93 additions and 670 deletions

View File

@ -227,7 +227,7 @@ public class AsmFragmentTemplateSynthesizer {
for(AsmFragmentClobber bestClobber : bestClobbers) {
AsmFragmentTemplate bestTemplate = bestTemplates.get(bestClobber);
double bestCycles = bestTemplate.getCycles();
if(candidateClobber.isSubset(bestClobber) && candidateCycles < bestCycles) {
if(candidateClobber.isSubset(bestClobber) && candidateCycles <= bestCycles) {
// The candidate is better - remove the current template
bestTemplates.remove(bestClobber);
}

View File

@ -0,0 +1,2 @@
sty $ff
ldx $ff

View File

@ -0,0 +1,2 @@
stx $ff
ldy $ff

View File

@ -1,90 +0,0 @@
ASMish - Assembler Like Language that is Optimizable for 6502
Design Goals:
- Ability to generate optimized 6502 assembler code.
- Very close to assembler allowing direct translation.
- Optimizing register allocation (registers, zeropage, stack, memory, self-modifying code)
- Optimizing parameter parsing to sub routines (via register, stack, zeropage, memory, modifying routine, fetching from caller, sw stack, ...)
- Optimizing by inlining sub soutines
- MAYBE: Optimizing by knowledge of runtime usage (#calls, actual value space of variables/parameters, ...)
- MAYBE: Optimize by swapping or modifying operations. (moving code out of loops or subroutines, precalculating constants)
- MAYBE/TODO: Graph of statements/operations - specifying what *must* be executed in sequence. All else can be swapped around freely during optimization.
- Existing Method: Single Static Assignment Form - Compiler Optimization
Language Features
- Variables
- Subroutines (non-recursive)
- Operations (mov, add, sub, ...)
- Adressing modes (variable, indirect, indirect sum, lo/hi-variable)
literals
--------
12 - decimal
$12 - hexadecimal - ASM-style
$d020 - hexadecimal word - ASM-style
0x12 - hexadecimal - C-style
%010101 - binary - ASM-style
8/16-bit variable declarations (local/global)
---------------------------------------------
byte a // 8 bit variable usable for operations or memory access (zeropage).
word b // 16bit variable usable for operations or for accessing memory.
del b // delete b (only local variables)
TODO: should delete be explicit or implicit?
operations
----------
mov a, b // b = a
add a, b // b += a
sub a, b // b -= a
inc a // a++
dec a // a--
and a, b // b &= a
or a, b // b |= a
xor a, b // b ^= a
not a // a ~= a
rol a // a<<
ror a // a>>
mul2 a // a *= 2 - short for rol a / a<<
div2 a // a /= 2 - short for ror a / a>>
TODO: w/wo carry for 8/16-bit add/sub/rol/ror/inc/...
memory-access (indirect adressing)
-------------
mov a, [b] // Indirect on b. b can be byte or word. bytes point to zeropage.
mov a, [b+c] // Indirect on b+c.
lo/hi-access og 16bit variables (lo/hi-adressing)
-------------------------------
mov a, <b // moves a to low part of b. a must be a byte, b must be a word.
mov <a, >b // moves low part of a to high part of b. a must be a word, b must be a word.
subroutine declaration with return
----------------------
sub byte fill(word a, word b, byte c) {
...
ret d
}
subroutine call with/without return value
---------------
mov d, call fill(a, b, c) // d = fill(a,b,c) - with return
call fill(a, b, c) // fill(a,b,c) - without return
TODO: Conditionals / comparisions
TODO: Branching
TODO: Looping
TODO: Jumping
TODO: Tables in memory
TODO: Strings
TODO: Annotations that guide / show register allocations
TODO: Stack operations
MAYBE: Recursive sub routines

View File

@ -24,7 +24,7 @@ public class TestPrograms {
String testPath;
public TestPrograms() throws IOException {
testPath = "src/test/java/dk/camelot64/kickc/test/";
testPath = "src/test/java/dk/camelot64/kickc/test/kc";
helper = new ReferenceHelper("dk/camelot64/kickc/test/ref/");
}
@ -32,7 +32,7 @@ public class TestPrograms {
public static void tearDown() throws Exception {
CompileLog log = new CompileLog();
log.setSysOut(true);
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, true, true);
}
@Test

View File

@ -1,123 +0,0 @@
byte n1 = 0;
byte n2 = 1;
byte i = 0;
byte fib = 0;
while(i<=10) {
fib = n1 + n2;
n1 = n2;
n2 = fib;
i = i + 1;
}
PROGRAM
(byte) n1 ← (byte) 0
(byte) n2 ← (byte) 1
(byte) i ← (byte) 0
(byte) fib ← (byte) 0
(label) @1:
(boolean*) $0 ← (byte) i <= (byte) 10
if((boolean*) $0) goto @2
goto @3
(label) @2:
(byte*) $1 ← (byte) n1 + (byte) n2
(byte) fib ← (byte*) $1
(byte) n1 ← (byte) n2
(byte) n2 ← (byte) fib
(byte*) $2 ← (byte) i + (byte) 1
(byte) i ← (byte*) $2
goto @1
(label) @3:
CONTROL FLOW GRAPH
@BEGIN:
to:@1
@1: from @BEGIN @2
(byte) n2#2 ← phi( @BEGIN/(byte) 1 @2/(byte) n2#1 )
(byte) n1#2 ← phi( @BEGIN/(byte) 0 @2/(byte) n1#1 )
(byte) i#3 ← phi( @BEGIN/(byte) 0 @2/(byte) i#1 )
(boolean*) $0 ← (byte) i#3 <= (byte) 10
if((boolean*) $0) goto @2
to:@END
@2: from @1
(byte) n2#1 ← (byte) n1#2 + (byte) n2#2
(byte) n1#1 ← (byte) n2#2
(byte) i#1 ← (byte) i#3 + (byte) 1
to:@1
@END: from @1
ASSEMBLER
BBEGIN:
jmp B1_from_BBEGIN
B1_from_BBEGIN:
// (byte) n2#2 = (byte) 1 // zpby1=coby1
lda #1
sta 7
// (byte) n1#2 = (byte) 0 // zpby1=coby1
lda #0
sta 6
// (byte) i#3 = (byte) 0 // zpby1=coby1
lda #0
sta 8
jmp B1
B1_from_B2:
// (byte) n2#2 = (byte) n2#1 // zpby1=zpby2
lda 4
sta 7
// (byte) n1#2 = (byte) n1#1 // zpby1=zpby2
lda 3
sta 6
// (byte) i#3 = (byte) i#1 // zpby1=zpby2
lda 5
sta 8
jmp B1
B1:
// (boolean*) $0 ← (byte) i#3 <= (byte) 10 // zpbo1=zpby1<=coby1
lda 8
cmp #10
bcc !t+
beq !t+
!f: lda #0
jmp !d+
!t: lda #$ff
!d: sta 2
// if((boolean*) $0) goto @2 // zpbo1?la1
lda 2
bne B2
jmp BEND
B2:
// (byte) n2#1 ← (byte) n1#2 + (byte) n2#2 // zpby1=zpby2+zpby3
lda 6
clc
adc 7
sta 4
// (byte) n1#1 ← (byte) n2#2 // zpby1=zpby2
lda 7
sta 3
// (byte) i#1 ← (byte) i#3 + (byte) 1 // zpby1=zpby2+coby1
lda 8
clc
adc #1
sta 5
jmp B1_from_B2
BEND:
OPTIMAL ASSEMBLER
BBEGIN:
B1_from_BBEGIN:
ldy #0
sty $2
iny
tya
ldx #12
clc
B2:
adc $2
sty $2
tay
dex
B1:
bne B2
BEND:
sta $3
inc $d020
jmp BEND

View File

@ -1,111 +0,0 @@
@1: from @BEGIN @5 b#3 a#7 $2 b#4 $4 b#2 b#8 a#1
(word) b#3 ← phi( @BEGIN/(byte) 0 @5/(word) b#8 ) L . . . . . R +
(byte) a#7 ← phi( @BEGIN/(byte) 0 @5/(byte) a#1 ) + L . . . . . R
(boolean*) $2 ← (byte) a#7 < (byte) 10 + R L . . . . .
if((boolean*) $2) goto @2 + + R . . . . .
to: @END . . . . . . . .
@2: from @1 ----------------------------------------------------------------------------
(word) b#4 ← (word) b#3 + (byte) a#7 R R . L . . . .
(boolean*) $4 ← (word) b#4 > (byte) 10 . + . R L . . .
if((boolean*) $4) goto @4 . + . + R . . .
to:@5 . . . + . . . .
@4: from @2 ----------------------------------------------------------------------------
(word) b#2 ← (word) b#4 - (byte) 10 . + . R . L . .
to:@5 . + . . . + . .
@5: from @4 @2 -------------------------------------------------------------------------
(word) b#8 ← phi( @2/(word) b#4 @4/(word) b#2 ) . + . R . R L .
(byte) a#1 ← (byte) a#7 + (byte) 1 . R . . . . + L
to:@1
@BEGIN:
@1_from_@0:
ldx #0 //X=a
lda #0 //A=b
@1: // A=b, X=a
cpx #10 // $2 (C)
bcs @END
@2: // A=b, X=a
stx $2 // tmp
adc $2 // tmp
cmp #11 // $4 (C)
bcc @5
@4: // A=b, X=a
sec
sbc #10
@5: // A=b, X=a
inx // a
jmp @1
@END:
@BEGIN:
@1_from_@0:
lda #0
sta $2 // b
sta $3 // a
@1:
lda $3 // a
cmp #10 // $2 (C)
bcs @END
@2:
adc $2 // b
sta $2 // b
lda #10 // (b#4 > 10) -> (10 < b#4)
cmp $2 // $4 (C)
bcs @5
@4:
lda $2 // b
sec
sbc #10
sta $2 // b
@5:
inc $3 // a
jmp @1
@END:
@BEGIN:
@1_from_@0:
lda #0
sta $2 // b#3
lda #0
sta $3 // a#7
jmp @1
@1_from_@5:
lda $5 // b#8
sta $2 // b#3
lda $6 // a#1
sta $3 // a#7
@1:
lda $3 // a#7
cmp #10 // $2 (C)
bcc @2
jmp @END
@2:
lda $2 // b#3
clc
adc $3 // a#7
sta $4 // b#4
lda #10 // (b#4 > 10) -> (10 < b#4)
cmp $4 // $4 (C)
bcc @4
jmp @5_from_@2
@4:
lda $4 // b#4
sec
sbc #10
sta $7 // b#2
jmp @5_from_@4
@5_from_@2:
lda $4 // b#4
sta $5 // b#8
jmp @5
@5_from_@4:
lda $7 // b#2
sta $5 // b#8
@5:
lda $3 // a#7
clc
adc 1
sta $6 // a#1
jmp @1_from_@5
@END:

View File

@ -1,141 +0,0 @@
byte i = 5;
a = inc(3);
a = inc(a);
a = a + i;
byte inc(byte a) {
i = i + 1;
return a + i;
}
// Not committed to a specific parameter transfer style (non SSA)
@BEGIN:
(byte) i := 5
(byte) a := call inc 3
(byte) a := call inc a
(byte) a := a + i
to: @END
byte inc(byte a):
(byte) i := i + 1
(byte§) $1 := INC.a + i
return (byte) $1
to: @RETURN
// Variable/Register parameter/return transfer (non SSA)
@BEGIN:
(byte) i := 5
(byte) inc.a := 3
(byte) a := call inc
to: @1
@1:
(byte) inc.a := a
(byte) a := call inc
to: @2
@2:
(byte§) a := a + i
to: @END
inc: (byte) inc((byte) a)
(byte) i := i + 1
(byte§) $1 := inc.a + i
(byte)return $1
to: @RETURN
// Variable/Register parameter/return transfer (SSA)
@BEGIN:
(byte) i#0 := 5
(byte) inc.a#0 := 3
call inc
(byte) a#0 := inc.return#0
(byte) i#3 := inc.i#1
to: @1
@1:
(byte) i#2 = phi( @BEGIN/i#3)
(byte§) a#1 := phi(@BEGIN/a#0)
(byte) inc.a#1 := a#1
call inc
(byte) a#1 := inc.return#0
(byte) i#4 := inc.i#1
to @2
@2:
(byte) i#1 = phi( @1/i#4)
(byte) a#2 = phi( @1/a#1)
(byte§) $2 := a#2 + i#1
(byte§) a#2 := $2
to: @END
inc: (byte) inc((byte) a) from @BEGIN @1
(byte) inc.a#2 = phi( @BEGIN/inc.a#0 @1/inc.a#1)
(byte) inc.i#0 = phi( @BEGIN/i#0 @1/i#2)
(byte) inc.i#1 := inc.i#0 + 1;
(byte§) $1 := inc.a#2 + inc.i#1;
(byte) inc.return#0 := $1
(byte) return inc.return#0
to: @RETURN
// Variable/Register parameter/return transfer (SSA) optimized
@BEGIN:
call inc
to: @1
@1:
call inc
to @2
@2:
(byte§) a#2 := inc.return#0 + inc.i#1
to: @END
inc: (byte) inc((byte) a) from @BEGIN @1
(byte) inc.a#2 = phi( @BEGIN/3 @1/inc.return#0)
(byte) inc.i#0 = phi( @BEGIN/5 @1/inc.i#1)
(byte) inc.i#1 := inc.i#0 + 1;
(byte) inc.return#0 := inc.a#2 + inc.i#1
to: @RETURN
// Inline call (non SSA)
@BEGIN:
(byte) i := 5
to: inc@1
inc@1:
(byte) inc.a := 3
(byte) i := i + 1
(byte§) $2 := inc.a + i
(byte) a := (byte) $2
to: inc@2
inc@2:
(byte) inc.a := a
(byte) i := i + 1
(byte§) $3 := inc.a + i
(byte) a := (byte) $3
to: @1
@1:
(byte) a := a + i;
to: @END
// Inline call (SSA)
@BEGIN:
(byte) i#0 := 5
to: inc@1
inc@1: from @BEGIN
(byte) i#5 := phi(@BEGIN/i#0)
(byte) inc.a#0 := 3
(byte) i#1 := i#5 + 1
(byte§) $2 := inc.a#0 + i#1
(byte) a#0 := (byte) $2
to: inc@2
inc@2: from inc@1
(byte) i#4 := phi(inc@2/i#1)
(byte) a#4 := phi(inc@1/a#0)
(byte) inc.a#1 := a#4
(byte) i#2 := i#4 + 1
(byte§) $3 := inc.a#1 + i#2
(byte) a#1 := (byte) $3
to: @1
@1: from inc@2
(byte) i#3 := phi(inc@2/i#2)
(byte) a#3 := phi(inc@2/a#1)
(byte) a#2 := a#3 + i#3;
to: @END
// Inline call (SSA) - optimized
@BEGIN:
(byte) i#3 := 7
(byte) a#2 := 23;
to: @END

View File

@ -1,116 +0,0 @@
byte a = 12;
byte s = sum(5,a);
byte a = a+s;
byte s2 = sum(s, a);
byte sum(byte b1, byte b2) {
return b1+b2;
}
CONTROL FLOW GRAPH:
// Not committed to a specific parameter transfer style (non SSA)
@BEGIN
(byte) a := 12
(byte) s := call SUM 5 a
(byte§) $2 := a + s
(byte§) a := $2
(byte) s2 := call SUM s a
to: @END
SUM:
param (byte) b1
param (byte) b2
(byte*) $1 := b1 + b2
return (byte) $1
to:
// Not committed to a specific parameter transfer style (SSA)
@BEGIN
(byte) a#0 := 12
(byte) s#0 := call SUM 5 a#0
(byte§) $2 := a#0 + s#0
(byte§) a#1 := $2
(byte) s2#0 := call SUM s#0 a#1
to: @END
SUM:
param (byte) b1#0
param (byte) b2#0
(byte*) $1 := b1#0 + b2#0
return (byte) $1
to: @RETURN
// Variable based parameter & return transfer (non SSA)
@BEGIN:
(byte) a := 12
(byte) SUM.b2 := a
(byte) SUM.b1 := 5
(byte) SUM.return = call SUM
to @1
@1: from @BEGIN
(byte) s := SUM.return
(byte*) $2 := a + s
(byte*) a := a + s
(byte) SUM.b2 := a
(byte) SUM.b1 := s
(byte) SUM.return := call SUM
to: @2
@2: from @1
(byte) s2 := SUM.return
to: @END
SUM: from: @BEGIN, @1
(byte§) $1 := SUM.b1 + SUM.b2
(byte) SUM.return := $1
return SUM.return
to: @RETURN
// Variable based parameter transfer & return (SSA)
@BEGIN:
(byte) a#0 := 12
(byte) SUM.b2#0 := a#0
(byte) SUM.b1#0 := 5
call SUM
(byte) SUM.return#0 = SUM.return#4
to @1
@1: from @BEGIN
(byte) SUM.return#1 = phi( @BEGIN/SUM.return#0)
(byte) a#1 = phi( @BEGIN/a#0)
(byte) s#0 := SUM.return#1
(byte*) $2 := a#1 + s#0
(byte*) a#2 := $2
(byte) SUM.b2#1 := a#2
(byte) SUM.b1#1 := s#0
call SUM
(byte) SUM.return#2 := SUM.return#4
to: @2
@2: from @1
(byte) SUM.return#3 = phi( @1/SUM.return#2)
(byte) s2#0 := SUM.return#3
to: @END
SUM: from: @BEGIN, @1
(byte) SUM.b1#2 := phi(@BEGIN/SUM.b1#0 @1/SUM.b1#1)
(byte) SUM.b2#2 := phi(@BEGIN/SUM.b2#0 @1/SUM.b2#1)
(byte§) $1 := SUM.b1#2 + SUM.b2#2
(byte) SUM.return#4 := $1
return SUM.return#4
to: @RETURN
// Variable based parameter transfer & return (SSA) - after optimizing
@BEGIN:
(byte) call SUM
to @1
@1: from @BEGIN
(byte) SUM.b2#1 := a#0 + SUM.return#4
(byte) call SUM
to: @2
@2: from @1
(byte) s2#0 := SUM.return#4
to: @END
SUM: from: @BEGIN, @1
(byte) SUM.b1#2 := phi(@BEGIN/5 @1/SUM.return#4)
(byte) SUM.b2#2 := phi(@BEGIN/12 @1/SUM.b2#1)
(byte§) $1 := SUM.b1#2 + SUM.b2#2
(byte) SUM.return#4 := $1
to: @RETURN

Some files were not shown because too many files have changed in this diff Show More