From 7c1bed30f2ea2e6ced122c8cc8bf7d513cdebe45 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 29 Sep 2020 02:07:09 +0200 Subject: [PATCH] Fixed ATASCII newline encoding. Closes #526 --- src/test/kc/encoding-atascii.c | 1 + src/test/ref/encoding-atascii.asm | 5 +++- src/test/ref/encoding-atascii.cfg | 4 ++- src/test/ref/encoding-atascii.log | 41 +++++++++++++++++++++++-------- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/test/kc/encoding-atascii.c b/src/test/kc/encoding-atascii.c index faf9b916b..fb56b047c 100644 --- a/src/test/kc/encoding-atascii.c +++ b/src/test/kc/encoding-atascii.c @@ -7,4 +7,5 @@ char * SCREEN = 0x0400; void main() { SCREEN[0] = TEXT[13]; + SCREEN[1] = '\n'; } \ No newline at end of file diff --git a/src/test/ref/encoding-atascii.asm b/src/test/ref/encoding-atascii.asm index dabef2982..e6e82b0ff 100644 --- a/src/test/ref/encoding-atascii.asm +++ b/src/test/ref/encoding-atascii.asm @@ -7,9 +7,12 @@ main: { // SCREEN[0] = TEXT[13] lda TEXT+$d sta SCREEN + // SCREEN[1] = '\n' + .encoding "ascii" + lda #'\$9b' + sta SCREEN+1 // } 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 index 18b72cd52..a4d7f4766 100644 --- a/src/test/ref/encoding-atascii.cfg +++ b/src/test/ref/encoding-atascii.cfg @@ -2,7 +2,9 @@ (void()) main() main: scope:[main] from [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) + [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' +'at to:main::@return main::@return: scope:[main] from main - [1] return + [2] return to:@return diff --git a/src/test/ref/encoding-atascii.log b/src/test/ref/encoding-atascii.log index d3031aa83..f5d89d8f2 100644 --- a/src/test/ref/encoding-atascii.log +++ b/src/test/ref/encoding-atascii.log @@ -5,6 +5,8 @@ CONTROL FLOW GRAPH SSA (void()) main() main: scope:[main] from __start::@1 *((const byte*) SCREEN + (number) 0) ← *((const byte*) TEXT + (number) $d) + *((const byte*) SCREEN + (number) 1) ← (byte) ' +'at to:main::@return main::@return: scope:[main] from main return @@ -38,13 +40,17 @@ SYMBOL TABLE SSA 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) +Adding number conversion cast (unumber) 1 in *((const byte*) SCREEN + (number) 1) ← (byte) ' +'at Successful SSA optimization PassNAddNumberTypeConversions Simplifying constant pointer cast (byte*) 1024 Simplifying constant integer cast $d Simplifying constant integer cast 0 +Simplifying constant integer cast 1 Successful SSA optimization PassNCastSimplification Finalized unsigned number type (byte) $d Finalized unsigned number type (byte) 0 +Finalized unsigned number type (byte) 1 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 @@ -56,6 +62,7 @@ Removing unused procedure block __start::@2 Removing unused procedure block __start::@return Successful SSA optimization PassNEliminateEmptyStart Consolidated array index constant in *(TEXT+$d) +Consolidated array index constant in *(SCREEN+1) Successful SSA optimization Pass2ConstantAdditionElimination CALL GRAPH @@ -67,9 +74,11 @@ FINAL CONTROL FLOW GRAPH (void()) main() main: scope:[main] from [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) + [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' +'at to:main::@return main::@return: scope:[main] from main - [1] return + [2] return to:@return @@ -94,26 +103,31 @@ main: { // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 lda TEXT+$d sta SCREEN + // [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' 'at -- _deref_pbuc1=vbuc2 + .encoding "ascii" + lda #'\$9b' + sta SCREEN+1 jmp __breturn // main::@return __breturn: - // [1] return + // [2] 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 +Statement [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' +'at [ ] ( [ ] { } ) always clobbers reg byte a REGISTER UPLIFT SCOPES Uplift Scope [main] Uplift Scope [] -Uplifting [main] best 17 combination -Uplifting [] best 17 combination +Uplifting [main] best 23 combination +Uplifting [] best 23 combination ASSEMBLER BEFORE OPTIMIZATION // File Comments @@ -129,14 +143,17 @@ main: { // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 lda TEXT+$d sta SCREEN + // [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' 'at -- _deref_pbuc1=vbuc2 + .encoding "ascii" + lda #'\$9b' + sta SCREEN+1 jmp __breturn // main::@return __breturn: - // [1] return + // [2] return rts } // File Data -.encoding "ascii" TEXT: .text @"hello, world!\$9b" .byte 0 @@ -156,7 +173,7 @@ FINAL SYMBOL TABLE FINAL ASSEMBLER -Score: 14 +Score: 20 // File Comments // Tests ATASCII encoding @@ -172,13 +189,17 @@ main: { // [0] *((const byte*) SCREEN) ← *((const byte*) TEXT+(byte) $d) -- _deref_pbuc1=_deref_pbuc2 lda TEXT+$d sta SCREEN + // SCREEN[1] = '\n' + // [1] *((const byte*) SCREEN+(byte) 1) ← (byte) ' 'at -- _deref_pbuc1=vbuc2 + .encoding "ascii" + lda #'\$9b' + sta SCREEN+1 // main::@return // } - // [1] return + // [2] return rts } // File Data -.encoding "ascii" TEXT: .text @"hello, world!\$9b" .byte 0