diff --git a/src/main/java/dk/camelot64/kickc/model/values/StringEncoding.java b/src/main/java/dk/camelot64/kickc/model/values/StringEncoding.java index 67d3a2f36..155ee4372 100644 --- a/src/main/java/dk/camelot64/kickc/model/values/StringEncoding.java +++ b/src/main/java/dk/camelot64/kickc/model/values/StringEncoding.java @@ -14,7 +14,7 @@ public enum StringEncoding { SCREENCODE_MIXED("screencode_mixed", "screencode_mixed", "sm", CharToPetsciiConverter.charToScreenCode_mixed), SCREENCODE_UPPER("screencode_upper", "screencode_upper", "su", CharToPetsciiConverter.charToScreenCode_upper), ASCII("ascii", "ascii", "as", CharToPetsciiConverter.charToAscii), - ATASCII("atascii", "ascii", "at", CharToAtasciiConverter.charToAtascii), + ATASCII("atascii", null, "at", CharToAtasciiConverter.charToAtascii), SCREENCODE_ATARI("screencode_atari", null, "sa", CharToAtasciiConverter.charToScreenCodeAtari) ; diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 654ae6253..4e309d012 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -1395,6 +1395,11 @@ public class TestPrograms { compileAndCompare("examples/nmisamples/nmisamples.c"); } + @Test + public void testEncodingAtascii() throws IOException, URISyntaxException { + compileAndCompare("encoding-atascii.c"); + } + @Test public void testEncodingLiteralChar() throws IOException, URISyntaxException { compileAndCompare("encoding-literal-char.c"); diff --git a/src/test/kc/encoding-atascii.c b/src/test/kc/encoding-atascii.c new file mode 100644 index 000000000..faf9b916b --- /dev/null +++ b/src/test/kc/encoding-atascii.c @@ -0,0 +1,10 @@ +// Tests ATASCII encoding + +#pragma encoding(atascii) +char TEXT[] = "hello, world!\n"; + +char * SCREEN = 0x0400; + +void main() { + SCREEN[0] = TEXT[13]; +} \ No newline at end of file diff --git a/src/test/ref/encoding-atascii.asm b/src/test/ref/encoding-atascii.asm new file mode 100644 index 000000000..dabef2982 --- /dev/null +++ b/src/test/ref/encoding-atascii.asm @@ -0,0 +1,15 @@ +// Tests ATASCII encoding +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .label SCREEN = $400 +main: { + // SCREEN[0] = TEXT[13] + lda TEXT+$d + sta SCREEN + // } + rts +} +.encoding "ascii" + TEXT: .text @"hello, world!\$9b" + .byte 0 diff --git a/src/test/ref/encoding-atascii.cfg b/src/test/ref/encoding-atascii.cfg new file mode 100644 index 000000000..18b72cd52 --- /dev/null +++ b/src/test/ref/encoding-atascii.cfg @@ -0,0 +1,8 @@ + +(void()) main() +main: scope:[main] from + [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) + to:main::@return +main::@return: scope:[main] from main + [1] return + to:@return diff --git a/src/test/ref/encoding-atascii.log b/src/test/ref/encoding-atascii.log new file mode 100644 index 000000000..d3031aa83 --- /dev/null +++ b/src/test/ref/encoding-atascii.log @@ -0,0 +1,184 @@ +Inlined call call __init + +CONTROL FLOW GRAPH SSA + +(void()) main() +main: scope:[main] from __start::@1 + *((const byte*) SCREEN + (number) 0) ← *((const byte*) TEXT + (number) $d) + to:main::@return +main::@return: scope:[main] from main + return + to:@return + +(void()) __start() +__start: scope:[__start] from + to:__start::__init1 +__start::__init1: scope:[__start] from __start + to:__start::@1 +__start::@1: scope:[__start] from __start::__init1 + call main + to:__start::@2 +__start::@2: scope:[__start] from __start::@1 + to:__start::@return +__start::@return: scope:[__start] from __start::@2 + return + to:@return + +SYMBOL TABLE SSA +(const byte*) SCREEN = (byte*)(number) $400 +(const byte*) TEXT[] = (byte*) "hello, world! +"at +(void()) __start() +(label) __start::@1 +(label) __start::@2 +(label) __start::@return +(label) __start::__init1 +(void()) main() +(label) main::@return + +Adding number conversion cast (unumber) $d in *((const byte*) SCREEN + (number) 0) ← *((const byte*) TEXT + (number) $d) +Adding number conversion cast (unumber) 0 in *((const byte*) SCREEN + (number) 0) ← *((const byte*) TEXT + (unumber)(number) $d) +Successful SSA optimization PassNAddNumberTypeConversions +Simplifying constant pointer cast (byte*) 1024 +Simplifying constant integer cast $d +Simplifying constant integer cast 0 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (byte) $d +Finalized unsigned number type (byte) 0 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Simplifying expression containing zero SCREEN in [0] *((const byte*) SCREEN + (byte) 0) ← *((const byte*) TEXT + (byte) $d) +Successful SSA optimization PassNSimplifyExpressionWithZero +Removing unused procedure __start +Removing unused procedure block __start +Removing unused procedure block __start::__init1 +Removing unused procedure block __start::@1 +Removing unused procedure block __start::@2 +Removing unused procedure block __start::@return +Successful SSA optimization PassNEliminateEmptyStart +Consolidated array index constant in *(TEXT+$d) +Successful SSA optimization Pass2ConstantAdditionElimination +CALL GRAPH + +Created 0 initial phi equivalence classes +Coalesced down to 0 phi equivalence classes + +FINAL CONTROL FLOW GRAPH + +(void()) main() +main: scope:[main] from + [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) + to:main::@return +main::@return: scope:[main] from main + [1] return + to:@return + + +VARIABLE REGISTER WEIGHTS +(void()) main() + +Initial phi equivalence classes +Complete equivalence classes + +INITIAL ASM +Target platform is c64basic / MOS6502X + // File Comments +// Tests ATASCII encoding + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 + lda TEXT+$d + sta SCREEN + jmp __breturn + // main::@return + __breturn: + // [1] return + rts +} + // File Data +.encoding "ascii" + TEXT: .text @"hello, world!\$9b" + .byte 0 + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) [ ] ( [ ] { } ) always clobbers reg byte a + +REGISTER UPLIFT SCOPES +Uplift Scope [main] +Uplift Scope [] + +Uplifting [main] best 17 combination +Uplifting [] best 17 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Tests ATASCII encoding + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 + lda TEXT+$d + sta SCREEN + jmp __breturn + // main::@return + __breturn: + // [1] return + rts +} + // File Data +.encoding "ascii" + TEXT: .text @"hello, world!\$9b" + .byte 0 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(const byte*) SCREEN = (byte*) 1024 +(const byte*) TEXT[] = (byte*) "hello, world! +"at +(void()) main() +(label) main::@return + + + +FINAL ASSEMBLER +Score: 14 + + // File Comments +// Tests ATASCII encoding + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + // SCREEN[0] = TEXT[13] + // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 + lda TEXT+$d + sta SCREEN + // main::@return + // } + // [1] return + rts +} + // File Data +.encoding "ascii" + TEXT: .text @"hello, world!\$9b" + .byte 0 + diff --git a/src/test/ref/encoding-atascii.sym b/src/test/ref/encoding-atascii.sym new file mode 100644 index 000000000..23e1b54d6 --- /dev/null +++ b/src/test/ref/encoding-atascii.sym @@ -0,0 +1,6 @@ +(const byte*) SCREEN = (byte*) 1024 +(const byte*) TEXT[] = (byte*) "hello, world! +"at +(void()) main() +(label) main::@return +