diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 980d3ba0b..bd4be5c6d 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -2318,26 +2318,13 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor@1] +__b1_from___bbegin: + jmp __b1 + // @1 +__b1: + // [2] call main + jsr main + // [3] phi from @1 to @end [phi:@1->@end] +__bend_from___b1: + jmp __bend + // @end +__bend: + // main +main: { + // [4] *((const nomodify byte*) BORDERCOL) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta BORDERCOL + // [5] *((const nomodify byte*) BGCOL) ← (byte) 6 -- _deref_pbuc1=vbuc2 + lda #6 + sta BGCOL + jmp __breturn + // main::@return + __breturn: + // [6] return + rts +} + // File Data + // Commodore 64 processor port + COLORS: .fill SIZEOF_STRUCT_SCREEN_COLORS, 0 + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [4] *((const nomodify byte*) BORDERCOL) ← (byte) 0 [ ] ( main:2 [ ] { } ) always clobbers reg byte a +Statement [5] *((const nomodify byte*) BGCOL) ← (byte) 6 [ ] ( main:2 [ ] { } ) always clobbers reg byte a +Potential registers mem[5] [ COLORS ] : mem[5] , + +REGISTER UPLIFT SCOPES +Uplift Scope [SCREEN_COLORS] +Uplift Scope [main] +Uplift Scope [] 0: mem[5] [ COLORS ] + +Uplifting [SCREEN_COLORS] best 33 combination +Uplifting [main] best 33 combination +Uplifting [] best 33 combination mem[5] [ COLORS ] + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Support for pointer to struct member + // Upstart +.pc = $801 "Basic" +:BasicUpstart(__bbegin) +.pc = $80d "Program" + // Global Constants & labels + .const OFFSET_STRUCT_SCREEN_COLORS_BG0 = 1 + .const SIZEOF_STRUCT_SCREEN_COLORS = 5 + // The border color + .label BORDERCOL = COLORS + // The background color + .label BGCOL = COLORS+OFFSET_STRUCT_SCREEN_COLORS_BG0 + // @begin +__bbegin: + // [1] phi from @begin to @1 [phi:@begin->@1] +__b1_from___bbegin: + jmp __b1 + // @1 +__b1: + // [2] call main + jsr main + // [3] phi from @1 to @end [phi:@1->@end] +__bend_from___b1: + jmp __bend + // @end +__bend: + // main +main: { + // [4] *((const nomodify byte*) BORDERCOL) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta BORDERCOL + // [5] *((const nomodify byte*) BGCOL) ← (byte) 6 -- _deref_pbuc1=vbuc2 + lda #6 + sta BGCOL + jmp __breturn + // main::@return + __breturn: + // [6] return + rts +} + // File Data + // Commodore 64 processor port + COLORS: .fill SIZEOF_STRUCT_SCREEN_COLORS, 0 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __b1 +Removing instruction jmp __bend +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __b1_from___bbegin: +Removing instruction __b1: +Removing instruction __bend_from___b1: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction __bend: +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination +Updating BasicUpstart to call main directly +Removing instruction jsr main +Succesful ASM optimization Pass5SkipBegin +Removing instruction __bbegin: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(label) @1 +(label) @begin +(label) @end +(const nomodify byte*) BGCOL = (byte*)&(struct SCREEN_COLORS) COLORS+(const byte) OFFSET_STRUCT_SCREEN_COLORS_BG0 +(const nomodify byte*) BORDERCOL = (byte*)&(struct SCREEN_COLORS) COLORS +(struct SCREEN_COLORS) COLORS loadstore mem[5] = {} +(const byte) OFFSET_STRUCT_SCREEN_COLORS_BG0 = (byte) 1 +(byte) SCREEN_COLORS::BG0 +(byte) SCREEN_COLORS::BG1 +(byte) SCREEN_COLORS::BG2 +(byte) SCREEN_COLORS::BG3 +(byte) SCREEN_COLORS::BORDER +(const byte) SIZEOF_STRUCT_SCREEN_COLORS = (byte) 5 +(void()) main() +(label) main::@return + +mem[5] [ COLORS ] + + +FINAL ASSEMBLER +Score: 18 + + // File Comments +// Support for pointer to struct member + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .const OFFSET_STRUCT_SCREEN_COLORS_BG0 = 1 + .const SIZEOF_STRUCT_SCREEN_COLORS = 5 + // The border color + .label BORDERCOL = COLORS + // The background color + .label BGCOL = COLORS+OFFSET_STRUCT_SCREEN_COLORS_BG0 + // @begin + // [1] phi from @begin to @1 [phi:@begin->@1] + // @1 + // [2] call main + // [3] phi from @1 to @end [phi:@1->@end] + // @end + // main +main: { + // *BORDERCOL = 0 + // [4] *((const nomodify byte*) BORDERCOL) ← (byte) 0 -- _deref_pbuc1=vbuc2 + lda #0 + sta BORDERCOL + // *BGCOL = 6 + // [5] *((const nomodify byte*) BGCOL) ← (byte) 6 -- _deref_pbuc1=vbuc2 + lda #6 + sta BGCOL + // main::@return + // } + // [6] return + rts +} + // File Data + // Commodore 64 processor port + COLORS: .fill SIZEOF_STRUCT_SCREEN_COLORS, 0 + diff --git a/src/test/ref/struct-pointer-to-member-2.sym b/src/test/ref/struct-pointer-to-member-2.sym new file mode 100644 index 000000000..e93b7f9fa --- /dev/null +++ b/src/test/ref/struct-pointer-to-member-2.sym @@ -0,0 +1,17 @@ +(label) @1 +(label) @begin +(label) @end +(const nomodify byte*) BGCOL = (byte*)&(struct SCREEN_COLORS) COLORS+(const byte) OFFSET_STRUCT_SCREEN_COLORS_BG0 +(const nomodify byte*) BORDERCOL = (byte*)&(struct SCREEN_COLORS) COLORS +(struct SCREEN_COLORS) COLORS loadstore mem[5] = {} +(const byte) OFFSET_STRUCT_SCREEN_COLORS_BG0 = (byte) 1 +(byte) SCREEN_COLORS::BG0 +(byte) SCREEN_COLORS::BG1 +(byte) SCREEN_COLORS::BG2 +(byte) SCREEN_COLORS::BG3 +(byte) SCREEN_COLORS::BORDER +(const byte) SIZEOF_STRUCT_SCREEN_COLORS = (byte) 5 +(void()) main() +(label) main::@return + +mem[5] [ COLORS ]