1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-18 08:30:18 +00:00

Implemented sorter inside a multiplexer.

This commit is contained in:
jespergravgaard 2018-08-02 02:53:52 +02:00
parent c272b93872
commit 3658d9f68e
14 changed files with 3893 additions and 17 deletions

View File

@ -0,0 +1,3 @@
ldy {c2},x
cmp {c1},y
bcc {la1}

View File

@ -0,0 +1,3 @@
ldx {c2},y
cmp {c1},x
bcc {la1}

View File

@ -10,10 +10,7 @@ import dk.camelot64.kickc.model.symbols.Label;
import dk.camelot64.kickc.model.symbols.Scope;
import dk.camelot64.kickc.model.values.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Compiler Pass rewriting conditional jumps that use && or || operators
@ -91,13 +88,21 @@ public class Pass2ConditionalAndOrRewriting extends Pass2SsaOptimization {
Label newBlockLabel = currentScope.addLabelIntermediate();
ControlFlowBlock newBlock = new ControlFlowBlock(newBlockLabel.getRef(), currentScopeRef);
getGraph().addBlock(newBlock);
newBlock.getStatements().add(new StatementConditionalJump(conditionAssignment.getrValue2(), conditional.getDestination(), conditional.getSource()));
LabelRef destLabel = conditional.getDestination();
newBlock.getStatements().add(new StatementConditionalJump(conditionAssignment.getrValue2(), destLabel, conditional.getSource()));
newBlock.setDefaultSuccessor(block.getDefaultSuccessor());
newBlock.setConditionalSuccessor(conditional.getDestination());
newBlock.setConditionalSuccessor(destLabel);
// Rewrite the conditional to use only the first part of the && condition expression
conditional.setDestination(newBlockLabel.getRef());
block.setConditionalSuccessor(newBlockLabel.getRef());
conditional.setrValue2(conditionAssignment.getrValue1());
// Replace the phi labels inside the destination block with the new block
ControlFlowBlock destBlock = getGraph().getBlock(destLabel);
LinkedHashMap<LabelRef, LabelRef> replacements = new LinkedHashMap<>();
replacements.put(block.getLabel(), newBlockLabel.getRef());
replaceLabels(destBlock, replacements);
}
/**
@ -120,6 +125,19 @@ public class Pass2ConditionalAndOrRewriting extends Pass2SsaOptimization {
// Rewrite the conditional to use only the first part of the && condition expression
block.setDefaultSuccessor(newBlockLabel.getRef());
conditional.setrValue2(conditionAssignment.getrValue1());
// TODO: Fix phi-values inside the destination phi-blocks to reflect the new control flow! Use replaceLabels(block, replacement)
ControlFlowBlock conditionalDestBlock = getGraph().getBlock(conditional.getDestination());
if(conditionalDestBlock.hasPhiBlock()) {
throw new RuntimeException("TODO: Fix phi-values inside the conditional destination phi-block!");
}
ControlFlowBlock defaultDestBlock = getGraph().getBlock(newBlock.getDefaultSuccessor());
if(defaultDestBlock.hasPhiBlock()) {
throw new RuntimeException("TODO: Fix phi-values inside the default destination phi-block!");
}
}
/**

View File

@ -59,7 +59,7 @@ public abstract class Pass2SsaOptimization extends Pass1Base {
visitor.visitBlock(block);
}
/** Creates a visitor that can getReplacement labels. */
/** Creates a visitor that can replace labels. */
private ControlFlowGraphBaseVisitor<Void> getLabelReplaceVisitor(final Map<LabelRef, LabelRef> replacements) {
return new ControlFlowGraphBaseVisitor<Void>() {

View File

@ -33,7 +33,7 @@ public class Pass2UnaryNotSimplification extends Pass2SsaOptimization {
}
/**
* Examine all unary nots. If they are the only usage of a reversable unary not getReplacement the unary not with the reversed comparison - and eliminate the riginal variable.
* Examine all unary nots. If they are the only usage of a reversable unary not replace the unary not with the reversed comparison - and eliminate the riginal variable.
*
* @param assignments Assignments to examine
* @param usages All variable usages

View File

@ -63,7 +63,7 @@ public class Pass3PhiLifting {
}
StatementAssignment newAssignment = new StatementAssignment(newVar.getRef(), phiRValue.getrValue(), phiBlock.getSource());
if(lastPredecessorStatement instanceof StatementConditionalJump) {
// Use or Create a new block between the predecessor and this one - getReplacement labels where appropriate
// Use or Create a new block between the predecessor and this one - replace labels where appropriate
ControlFlowBlock newBlock;
LabelRef newBlockRef = newBlocks.get(predecessorRef);
if(newBlockRef == null) {

View File

@ -46,6 +46,11 @@ public class TestPrograms {
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
}
@Test
public void testMultiplexer() throws IOException, URISyntaxException {
compileAndCompare("multiplexer");
}
@Test
public void testForRangedWords() throws IOException, URISyntaxException {
compileAndCompare("forrangedwords");

View File

@ -0,0 +1,83 @@
// A flexible sprite multiplexer routine
import "print.kc"
// The number of sprites in the multiplexer
const byte PLEX_COUNT = 10;
// The x-positions of the multiplexer sprites ($000-$1ff)
word[PLEX_COUNT] PLEX_XPOS;
// The y-positions of the multiplexer sprites
byte[PLEX_COUNT] PLEX_YPOS = { $ff, $12, $11, $34, $2, $81, $77, $81, $ef, $11 };
// The sprite pointers for the multiplexed sprites
byte[PLEX_COUNT] PLEX_PTR;
// The address of the sprite pointers on the current screen (screen+$3e8).
byte* PLEX_SCREEN_PTR = $400+$3e8;
// Indexes of the plex-sprites sorted by sprite y-position. Each call to plexSort() will fix the sorting if changes to the Y-positions have ruined it.
byte[PLEX_COUNT] PLEX_SORTED_IDX;
// Set the address of the sprite pointers on the current screen (screen+$3e8)
inline void plexSetScreenPtr(byte* plexScreenPtr) {
PLEX_SCREEN_PTR = plexScreenPtr;
}
// Initialize the multiplexer data structures
void plexInit() {
for(byte i: 0..PLEX_COUNT-1) {
PLEX_SORTED_IDX[i] = i;
}
}
// Ensure that the indices in PLEX_SORTED_IDX is sorted based on the y-positions of the sprites
// Assumes that the positions are nearly sorted already (as each sprite just moves a bit)
// Uses an insertion sort
// 1. Moves a marker from the start to end of the array. Every time the marker moves forward all elements before the marker are sorted correctly.
// 2a. If the next element after the marker is larger that the current element
// the marker can be moved forwards (as the sorting is correct).
// 2b. If the next element after the marker is smaller than the current element:
// elements before the marker are shifted right one at a time until encountering one smaller than the current one.
// It is then inserted at the spot. Now the marker can move forward.
void plexSort() {
for(byte m: 0..PLEX_COUNT-2) {
byte nxt_idx = PLEX_SORTED_IDX[m+1];
byte nxt_y = PLEX_YPOS[nxt_idx];
byte cur_idx = PLEX_SORTED_IDX[m];
if(nxt_y<PLEX_YPOS[cur_idx]) {
// Shift values until we encounter a value smaller than nxt_y
byte s = m;
do {
PLEX_SORTED_IDX[s+1] = PLEX_SORTED_IDX[s];
s--;
} while((s!=$ff) && (nxt_y<PLEX_YPOS[PLEX_SORTED_IDX[s]]));
// store the mark at the found position
s++;
PLEX_SORTED_IDX[s] = nxt_idx;
}
}
}
void main() {
plexInit();
print_cls();
print_plex();
plexSort();
print_plex();
}
void print_plex() {
for( byte i: 0..PLEX_COUNT-1) {
print_byte(PLEX_YPOS[PLEX_SORTED_IDX[i]]);
print_char(' ');
}
print_ln();
}

View File

@ -38,8 +38,7 @@ word xsin_idx = 0;
void loop() {
while(true) {
// Wait for the raster to reach the bottom of the screen
while(*RASTER!=$ff) {
}
while(*RASTER!=$ff) {}
(*BORDERCOL)++;
signed word xpos = *(xsin+xsin_idx);
render_logo(xpos);
@ -105,5 +104,3 @@ void render_logo(signed word xpos) {
}
}
}

View File

@ -0,0 +1,163 @@
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.const PLEX_COUNT = $a
.label print_line_cursor = 2
.label print_char_cursor = 4
jsr main
main: {
jsr plexInit
jsr print_cls
lda #<$400
sta print_line_cursor
lda #>$400
sta print_line_cursor+1
lda #<$400
sta print_char_cursor
lda #>$400
sta print_char_cursor+1
jsr print_plex
jsr plexSort
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
sta print_char_cursor+1
jsr print_plex
rts
}
print_plex: {
ldx #0
b1:
lda PLEX_SORTED_IDX,x
tay
lda PLEX_YPOS,y
sta print_byte.b
jsr print_byte
lda #' '
jsr print_char
inx
cpx #PLEX_COUNT-1+1
bne b1
jsr print_ln
rts
}
print_ln: {
b1:
lda print_line_cursor
clc
adc #$28
sta print_line_cursor
bcc !+
inc print_line_cursor+1
!:
lda print_line_cursor+1
cmp print_char_cursor+1
bcc b1
bne !+
lda print_line_cursor
cmp print_char_cursor
bcc b1
!:
rts
}
print_char: {
ldy #0
sta (print_char_cursor),y
inc print_char_cursor
bne !+
inc print_char_cursor+1
!:
rts
}
print_byte: {
.label b = 6
lda b
lsr
lsr
lsr
lsr
tay
lda print_hextab,y
jsr print_char
lda #$f
and b
tay
lda print_hextab,y
jsr print_char
rts
}
plexSort: {
.label nxt_idx = 7
.label nxt_y = 8
.label m = 6
lda #0
sta m
b1:
ldy m
lda PLEX_SORTED_IDX+1,y
sta nxt_idx
tay
lda PLEX_YPOS,y
sta nxt_y
ldx m
ldy PLEX_SORTED_IDX,x
cmp PLEX_YPOS,y
bcs b2
b3:
lda PLEX_SORTED_IDX,x
sta PLEX_SORTED_IDX+1,x
dex
cpx #$ff
bne b7
b5:
inx
lda nxt_idx
sta PLEX_SORTED_IDX,x
b2:
inc m
lda m
cmp #PLEX_COUNT-2+1
bne b1
rts
b7:
lda nxt_y
ldy PLEX_SORTED_IDX,x
cmp PLEX_YPOS,y
bcc b3
jmp b5
}
print_cls: {
.label sc = 2
lda #<$400
sta sc
lda #>$400
sta sc+1
b1:
lda #' '
ldy #0
sta (sc),y
inc sc
bne !+
inc sc+1
!:
lda sc+1
cmp #>$400+$3e8
bne b1
lda sc
cmp #<$400+$3e8
bne b1
rts
}
plexInit: {
ldx #0
b1:
txa
sta PLEX_SORTED_IDX,x
inx
cpx #PLEX_COUNT-1+1
bne b1
rts
}
print_hextab: .text "0123456789abcdef"
PLEX_YPOS: .byte $ff, $12, $11, $34, 2, $81, $77, $81, $ef, $11
PLEX_SORTED_IDX: .fill PLEX_COUNT, 0

View File

@ -0,0 +1,147 @@
@begin: scope:[] from
[0] phi() [ ] ( )
to:@19
@19: scope:[] from @begin
[1] phi() [ ] ( )
[2] call main [ ] ( )
to:@end
@end: scope:[] from @19
[3] phi() [ ] ( )
main: scope:[main] from @19
[4] phi() [ ] ( main:2 [ ] )
[5] call plexInit [ ] ( main:2 [ ] )
to:main::@1
main::@1: scope:[main] from main
[6] phi() [ ] ( main:2 [ ] )
[7] call print_cls [ ] ( main:2 [ ] )
to:main::@2
main::@2: scope:[main] from main::@1
[8] phi() [ ] ( main:2 [ ] )
[9] call print_plex [ print_line_cursor#1 ] ( main:2 [ print_line_cursor#1 ] )
to:main::@3
main::@3: scope:[main] from main::@2
[10] phi() [ print_line_cursor#1 ] ( main:2 [ print_line_cursor#1 ] )
[11] call plexSort [ print_line_cursor#1 ] ( main:2 [ print_line_cursor#1 ] )
to:main::@4
main::@4: scope:[main] from main::@3
[12] (byte*~) print_char_cursor#47 ← (byte*) print_line_cursor#1 [ print_char_cursor#47 print_line_cursor#1 ] ( main:2 [ print_char_cursor#47 print_line_cursor#1 ] )
[13] call print_plex [ ] ( main:2 [ ] )
to:main::@return
main::@return: scope:[main] from main::@4
[14] return [ ] ( main:2 [ ] )
to:@return
print_plex: scope:[print_plex] from main::@2 main::@4
[15] (byte*) print_line_cursor#34 ← phi( main::@2/((byte*))(word/signed word/dword/signed dword) 1024 main::@4/(byte*) print_line_cursor#1 ) [ print_char_cursor#44 print_line_cursor#34 ] ( main:2::print_plex:9 [ print_char_cursor#44 print_line_cursor#34 ] main:2::print_plex:13 [ print_char_cursor#44 print_line_cursor#34 ] )
[15] (byte*) print_char_cursor#44 ← phi( main::@2/((byte*))(word/signed word/dword/signed dword) 1024 main::@4/(byte*~) print_char_cursor#47 ) [ print_char_cursor#44 print_line_cursor#34 ] ( main:2::print_plex:9 [ print_char_cursor#44 print_line_cursor#34 ] main:2::print_plex:13 [ print_char_cursor#44 print_line_cursor#34 ] )
to:print_plex::@1
print_plex::@1: scope:[print_plex] from print_plex print_plex::@4
[16] (byte*) print_char_cursor#40 ← phi( print_plex/(byte*) print_char_cursor#44 print_plex::@4/(byte*) print_char_cursor#25 ) [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] )
[16] (byte) print_plex::i#2 ← phi( print_plex/(byte/signed byte/word/signed word/dword/signed dword) 0 print_plex::@4/(byte) print_plex::i#1 ) [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 ] )
[17] (byte) print_byte::b#0 ← *((const byte[PLEX_COUNT#0]) PLEX_YPOS#0 + *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) print_plex::i#2)) [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 ] )
[18] call print_byte [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:print_plex::@3
print_plex::@3: scope:[print_plex] from print_plex::@1
[19] phi() [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
[20] call print_char [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:print_plex::@4
print_plex::@4: scope:[print_plex] from print_plex::@3
[21] (byte) print_plex::i#1 ← ++ (byte) print_plex::i#2 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] )
[22] if((byte) print_plex::i#1!=(const byte) PLEX_COUNT#0-(byte/signed byte/word/signed word/dword/signed dword) 1+(byte/signed byte/word/signed word/dword/signed dword) 1) goto print_plex::@1 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_plex::i#1 print_char_cursor#25 ] )
to:print_plex::@2
print_plex::@2: scope:[print_plex] from print_plex::@4
[23] phi() [ print_line_cursor#34 print_char_cursor#25 ] ( main:2::print_plex:9 [ print_line_cursor#34 print_char_cursor#25 ] main:2::print_plex:13 [ print_line_cursor#34 print_char_cursor#25 ] )
[24] call print_ln [ print_line_cursor#1 ] ( main:2::print_plex:9 [ print_line_cursor#1 ] main:2::print_plex:13 [ print_line_cursor#1 ] )
to:print_plex::@return
print_plex::@return: scope:[print_plex] from print_plex::@2
[25] return [ print_line_cursor#1 ] ( main:2::print_plex:9 [ print_line_cursor#1 ] main:2::print_plex:13 [ print_line_cursor#1 ] )
to:@return
print_ln: scope:[print_ln] from print_plex::@2
[26] phi() [ print_line_cursor#34 print_char_cursor#25 ] ( main:2::print_plex:9::print_ln:24 [ print_line_cursor#34 print_char_cursor#25 ] main:2::print_plex:13::print_ln:24 [ print_line_cursor#34 print_char_cursor#25 ] )
to:print_ln::@1
print_ln::@1: scope:[print_ln] from print_ln print_ln::@1
[27] (byte*) print_line_cursor#12 ← phi( print_ln/(byte*) print_line_cursor#34 print_ln::@1/(byte*) print_line_cursor#1 ) [ print_char_cursor#25 print_line_cursor#12 ] ( main:2::print_plex:9::print_ln:24 [ print_char_cursor#25 print_line_cursor#12 ] main:2::print_plex:13::print_ln:24 [ print_char_cursor#25 print_line_cursor#12 ] )
[28] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#12 + (byte/signed byte/word/signed word/dword/signed dword) 40 [ print_line_cursor#1 print_char_cursor#25 ] ( main:2::print_plex:9::print_ln:24 [ print_line_cursor#1 print_char_cursor#25 ] main:2::print_plex:13::print_ln:24 [ print_line_cursor#1 print_char_cursor#25 ] )
[29] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#25) goto print_ln::@1 [ print_line_cursor#1 print_char_cursor#25 ] ( main:2::print_plex:9::print_ln:24 [ print_line_cursor#1 print_char_cursor#25 ] main:2::print_plex:13::print_ln:24 [ print_line_cursor#1 print_char_cursor#25 ] )
to:print_ln::@return
print_ln::@return: scope:[print_ln] from print_ln::@1
[30] return [ print_line_cursor#1 ] ( main:2::print_plex:9::print_ln:24 [ print_line_cursor#1 ] main:2::print_plex:13::print_ln:24 [ print_line_cursor#1 ] )
to:@return
print_char: scope:[print_char] from print_byte print_byte::@1 print_plex::@3
[31] (byte*) print_char_cursor#24 ← phi( print_byte/(byte*) print_char_cursor#40 print_byte::@1/(byte*) print_char_cursor#25 print_plex::@3/(byte*) print_char_cursor#25 ) [ print_char::ch#3 print_char_cursor#24 ] ( main:2::print_plex:9::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] )
[31] (byte) print_char::ch#3 ← phi( print_byte/(byte) print_char::ch#0 print_byte::@1/(byte) print_char::ch#1 print_plex::@3/(byte) ' ' ) [ print_char::ch#3 print_char_cursor#24 ] ( main:2::print_plex:9::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char::ch#3 print_char_cursor#24 ] )
[32] *((byte*) print_char_cursor#24) ← (byte) print_char::ch#3 [ print_char_cursor#24 ] ( main:2::print_plex:9::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#24 ] main:2::print_plex:13::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#24 ] main:2::print_plex:9::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#24 ] main:2::print_plex:13::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#24 ] )
[33] (byte*) print_char_cursor#25 ← ++ (byte*) print_char_cursor#24 [ print_char_cursor#25 ] ( main:2::print_plex:9::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:9::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#25 ] main:2::print_plex:9::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:print_char::@return
print_char::@return: scope:[print_char] from print_char
[34] return [ print_char_cursor#25 ] ( main:2::print_plex:9::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_char:20 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:9::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18::print_char:37 [ print_line_cursor#34 print_plex::i#2 print_byte::b#0 print_char_cursor#25 ] main:2::print_plex:9::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18::print_char:40 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:@return
print_byte: scope:[print_byte] from print_plex::@1
[35] (byte~) print_byte::$0 ← (byte) print_byte::b#0 >> (byte/signed byte/word/signed word/dword/signed dword) 4 [ print_char_cursor#40 print_byte::b#0 print_byte::$0 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 print_byte::$0 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 print_byte::$0 ] )
[36] (byte) print_char::ch#0 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) [ print_char_cursor#40 print_byte::b#0 print_char::ch#0 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 print_char::ch#0 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#40 print_byte::b#0 print_char::ch#0 ] )
[37] call print_char [ print_char_cursor#25 print_byte::b#0 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_byte::b#0 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_byte::b#0 ] )
to:print_byte::@1
print_byte::@1: scope:[print_byte] from print_byte
[38] (byte~) print_byte::$2 ← (byte) print_byte::b#0 & (byte/signed byte/word/signed word/dword/signed dword) 15 [ print_char_cursor#25 print_byte::$2 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_byte::$2 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_byte::$2 ] )
[39] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) [ print_char_cursor#25 print_char::ch#1 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_char::ch#1 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 print_char::ch#1 ] )
[40] call print_char [ print_char_cursor#25 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:print_byte::@return
print_byte::@return: scope:[print_byte] from print_byte::@1
[41] return [ print_char_cursor#25 ] ( main:2::print_plex:9::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] main:2::print_plex:13::print_byte:18 [ print_line_cursor#34 print_plex::i#2 print_char_cursor#25 ] )
to:@return
plexSort: scope:[plexSort] from main::@3
[42] phi() [ ] ( main:2::plexSort:11 [ print_line_cursor#1 ] )
to:plexSort::@1
plexSort::@1: scope:[plexSort] from plexSort plexSort::@2
[43] (byte) plexSort::m#2 ← phi( plexSort/(byte/signed byte/word/signed word/dword/signed dword) 0 plexSort::@2/(byte) plexSort::m#1 ) [ plexSort::m#2 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 ] )
[44] (byte) plexSort::nxt_idx#0 ← *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0+(byte/signed byte/word/signed word/dword/signed dword) 1 + (byte) plexSort::m#2) [ plexSort::m#2 plexSort::nxt_idx#0 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 ] )
[45] (byte) plexSort::nxt_y#0 ← *((const byte[PLEX_COUNT#0]) PLEX_YPOS#0 + (byte) plexSort::nxt_idx#0) [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 ] )
[46] (byte) plexSort::cur_idx#0 ← *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) plexSort::m#2) [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::cur_idx#0 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::cur_idx#0 ] )
[47] if((byte) plexSort::nxt_y#0>=*((const byte[PLEX_COUNT#0]) PLEX_YPOS#0 + (byte) plexSort::cur_idx#0)) goto plexSort::@2 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 ] )
to:plexSort::@10
plexSort::@10: scope:[plexSort] from plexSort::@1
[48] (byte~) plexSort::s#6 ← (byte) plexSort::m#2 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#6 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#6 ] )
to:plexSort::@3
plexSort::@3: scope:[plexSort] from plexSort::@10 plexSort::@7
[49] (byte) plexSort::s#3 ← phi( plexSort::@7/(byte) plexSort::s#1 plexSort::@10/(byte~) plexSort::s#6 ) [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#3 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#3 ] )
[50] *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0+(byte/signed byte/word/signed word/dword/signed dword) 1 + (byte) plexSort::s#3) ← *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) plexSort::s#3) [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#3 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#3 ] )
[51] (byte) plexSort::s#1 ← -- (byte) plexSort::s#3 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] )
[52] if((byte) plexSort::s#1!=(byte/word/signed word/dword/signed dword) 255) goto plexSort::@7 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] )
to:plexSort::@5
plexSort::@5: scope:[plexSort] from plexSort::@3 plexSort::@7
[53] (byte) plexSort::s#2 ← ++ (byte) plexSort::s#1 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::s#2 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::s#2 ] )
[54] *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) plexSort::s#2) ← (byte) plexSort::nxt_idx#0 [ plexSort::m#2 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 ] )
to:plexSort::@2
plexSort::@2: scope:[plexSort] from plexSort::@1 plexSort::@5
[55] (byte) plexSort::m#1 ← ++ (byte) plexSort::m#2 [ plexSort::m#1 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#1 ] )
[56] if((byte) plexSort::m#1!=(const byte) PLEX_COUNT#0-(byte/signed byte/word/signed word/dword/signed dword) 2+(byte/signed byte/word/signed word/dword/signed dword) 1) goto plexSort::@1 [ plexSort::m#1 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#1 ] )
to:plexSort::@return
plexSort::@return: scope:[plexSort] from plexSort::@2
[57] return [ ] ( main:2::plexSort:11 [ print_line_cursor#1 ] )
to:@return
plexSort::@7: scope:[plexSort] from plexSort::@3
[58] if((byte) plexSort::nxt_y#0<*((const byte[PLEX_COUNT#0]) PLEX_YPOS#0 + *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) plexSort::s#1))) goto plexSort::@3 [ plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] ( main:2::plexSort:11 [ print_line_cursor#1 plexSort::m#2 plexSort::nxt_idx#0 plexSort::nxt_y#0 plexSort::s#1 ] )
to:plexSort::@5
print_cls: scope:[print_cls] from main::@1
[59] phi() [ ] ( main:2::print_cls:7 [ ] )
to:print_cls::@1
print_cls::@1: scope:[print_cls] from print_cls print_cls::@1
[60] (byte*) print_cls::sc#2 ← phi( print_cls/((byte*))(word/signed word/dword/signed dword) 1024 print_cls::@1/(byte*) print_cls::sc#1 ) [ print_cls::sc#2 ] ( main:2::print_cls:7 [ print_cls::sc#2 ] )
[61] *((byte*) print_cls::sc#2) ← (byte) ' ' [ print_cls::sc#2 ] ( main:2::print_cls:7 [ print_cls::sc#2 ] )
[62] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 [ print_cls::sc#1 ] ( main:2::print_cls:7 [ print_cls::sc#1 ] )
[63] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) 1024+(word/signed word/dword/signed dword) 1000) goto print_cls::@1 [ print_cls::sc#1 ] ( main:2::print_cls:7 [ print_cls::sc#1 ] )
to:print_cls::@return
print_cls::@return: scope:[print_cls] from print_cls::@1
[64] return [ ] ( main:2::print_cls:7 [ ] )
to:@return
plexInit: scope:[plexInit] from main
[65] phi() [ ] ( main:2::plexInit:5 [ ] )
to:plexInit::@1
plexInit::@1: scope:[plexInit] from plexInit plexInit::@1
[66] (byte) plexInit::i#2 ← phi( plexInit/(byte/signed byte/word/signed word/dword/signed dword) 0 plexInit::@1/(byte) plexInit::i#1 ) [ plexInit::i#2 ] ( main:2::plexInit:5 [ plexInit::i#2 ] )
[67] *((const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 + (byte) plexInit::i#2) ← (byte) plexInit::i#2 [ plexInit::i#2 ] ( main:2::plexInit:5 [ plexInit::i#2 ] )
[68] (byte) plexInit::i#1 ← ++ (byte) plexInit::i#2 [ plexInit::i#1 ] ( main:2::plexInit:5 [ plexInit::i#1 ] )
[69] if((byte) plexInit::i#1!=(const byte) PLEX_COUNT#0-(byte/signed byte/word/signed word/dword/signed dword) 1+(byte/signed byte/word/signed word/dword/signed dword) 1) goto plexInit::@1 [ plexInit::i#1 ] ( main:2::plexInit:5 [ plexInit::i#1 ] )
to:plexInit::@return
plexInit::@return: scope:[plexInit] from plexInit::@1
[70] return [ ] ( main:2::plexInit:5 [ ] )
to:@return

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
(label) @19
(label) @begin
(label) @end
(byte) PLEX_COUNT
(const byte) PLEX_COUNT#0 PLEX_COUNT = (byte/signed byte/word/signed word/dword/signed dword) 10
(byte[PLEX_COUNT#0]) PLEX_SORTED_IDX
(const byte[PLEX_COUNT#0]) PLEX_SORTED_IDX#0 PLEX_SORTED_IDX = { fill( PLEX_COUNT#0, 0) }
(byte[PLEX_COUNT#0]) PLEX_YPOS
(const byte[PLEX_COUNT#0]) PLEX_YPOS#0 PLEX_YPOS = { (byte/word/signed word/dword/signed dword) 255, (byte/signed byte/word/signed word/dword/signed dword) 18, (byte/signed byte/word/signed word/dword/signed dword) 17, (byte/signed byte/word/signed word/dword/signed dword) 52, (byte/signed byte/word/signed word/dword/signed dword) 2, (byte/word/signed word/dword/signed dword) 129, (byte/signed byte/word/signed word/dword/signed dword) 119, (byte/word/signed word/dword/signed dword) 129, (byte/word/signed word/dword/signed dword) 239, (byte/signed byte/word/signed word/dword/signed dword) 17 }
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(void()) plexInit()
(label) plexInit::@1
(label) plexInit::@return
(byte) plexInit::i
(byte) plexInit::i#1 reg byte x 16.5
(byte) plexInit::i#2 reg byte x 22.0
(void()) plexSort()
(label) plexSort::@1
(label) plexSort::@10
(label) plexSort::@2
(label) plexSort::@3
(label) plexSort::@5
(label) plexSort::@7
(label) plexSort::@return
(byte) plexSort::cur_idx
(byte) plexSort::cur_idx#0 reg byte y 22.0
(byte) plexSort::m
(byte) plexSort::m#1 m zp ZP_BYTE:6 16.5
(byte) plexSort::m#2 m zp ZP_BYTE:6 4.230769230769231
(byte) plexSort::nxt_idx
(byte) plexSort::nxt_idx#0 nxt_idx zp ZP_BYTE:7 3.0
(byte) plexSort::nxt_y
(byte) plexSort::nxt_y#0 nxt_y zp ZP_BYTE:8 13.666666666666666
(byte) plexSort::s
(byte) plexSort::s#1 reg byte x 138.33333333333334
(byte) plexSort::s#2 reg byte x 22.0
(byte) plexSort::s#3 reg byte x 207.5
(byte~) plexSort::s#6 reg byte x 22.0
(void()) print_byte((byte) print_byte::b)
(byte~) print_byte::$0 reg byte a 4.0
(byte~) print_byte::$2 reg byte a 4.0
(label) print_byte::@1
(label) print_byte::@return
(byte) print_byte::b
(byte) print_byte::b#0 b zp ZP_BYTE:6 3.75
(void()) print_char((byte) print_char::ch)
(label) print_char::@return
(byte) print_char::ch
(byte) print_char::ch#0 reg byte a 4.0
(byte) print_char::ch#1 reg byte a 4.0
(byte) print_char::ch#3 reg byte a 6.0
(byte*) print_char_cursor
(byte*) print_char_cursor#24 print_char_cursor zp ZP_WORD:4 9.5
(byte*) print_char_cursor#25 print_char_cursor zp ZP_WORD:4 2.1764705882352944
(byte*) print_char_cursor#40 print_char_cursor zp ZP_WORD:4 3.75
(byte*) print_char_cursor#44 print_char_cursor zp ZP_WORD:4 4.0
(byte*~) print_char_cursor#47 print_char_cursor zp ZP_WORD:4 4.0
(void()) print_cls()
(label) print_cls::@1
(label) print_cls::@return
(byte*) print_cls::sc
(byte*) print_cls::sc#1 sc zp ZP_WORD:2 16.5
(byte*) print_cls::sc#2 sc zp ZP_WORD:2 16.5
(byte[]) print_hextab
(const byte[]) print_hextab#0 print_hextab = (string) "0123456789abcdef"
(byte*) print_line_cursor
(byte*) print_line_cursor#1 print_line_cursor zp ZP_WORD:2 4.111111111111112
(byte*) print_line_cursor#12 print_line_cursor zp ZP_WORD:2 24.0
(byte*) print_line_cursor#34 print_line_cursor zp ZP_WORD:2 0.4
(void()) print_ln()
(label) print_ln::@1
(label) print_ln::@return
(void()) print_plex()
(label) print_plex::@1
(label) print_plex::@2
(label) print_plex::@3
(label) print_plex::@4
(label) print_plex::@return
(byte) print_plex::i
(byte) print_plex::i#1 reg byte x 16.5
(byte) print_plex::i#2 reg byte x 6.6000000000000005
(byte*) print_screen
reg byte x [ print_plex::i#2 print_plex::i#1 ]
zp ZP_WORD:2 [ print_line_cursor#12 print_line_cursor#34 print_line_cursor#1 print_cls::sc#2 print_cls::sc#1 ]
reg byte a [ print_char::ch#3 print_char::ch#0 print_char::ch#1 ]
zp ZP_WORD:4 [ print_char_cursor#24 print_char_cursor#40 print_char_cursor#44 print_char_cursor#47 print_char_cursor#25 ]
zp ZP_BYTE:6 [ plexSort::m#2 plexSort::m#1 print_byte::b#0 ]
reg byte x [ plexSort::s#3 plexSort::s#1 plexSort::s#6 ]
reg byte x [ plexInit::i#2 plexInit::i#1 ]
reg byte a [ print_byte::$0 ]
reg byte a [ print_byte::$2 ]
zp ZP_BYTE:7 [ plexSort::nxt_idx#0 ]
zp ZP_BYTE:8 [ plexSort::nxt_y#0 ]
reg byte y [ plexSort::cur_idx#0 ]
reg byte x [ plexSort::s#2 ]

View File

@ -39,8 +39,7 @@ word xsin_idx = 0;
void loop() {
while(true) {
// Wait for the raster to reach the bottom of the screen
while(*RASTER!=$ff) {
}
while(*RASTER!=$ff) {}
(*BORDERCOL)++;
signed word xpos = *(xsin+xsin_idx);
render_logo(xpos);
@ -107,8 +106,6 @@ void render_logo(signed word xpos) {
}
}
Importing c64.kc
PARSING src/test/java/dk/camelot64/kickc/test/kc/c64.kc
// Commodore 64 Registers and Constants