1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-23 08:32:39 +00:00

Added test for macro-based struct addressing vs. const-pointer based.

This commit is contained in:
jespergravgaard 2020-10-19 23:59:26 +02:00
parent 482811f2c8
commit 599aaf4d67
6 changed files with 219 additions and 0 deletions

View File

@ -44,6 +44,11 @@ public class TestPrograms {
public TestPrograms() {
}
@Test
public void testChipsetTest() throws IOException, URISyntaxException {
compileAndCompare("chipset-test.c");
}
@Test
public void testConstRefNotLiteralProblem() throws IOException, URISyntaxException {
compileAndCompare("constref-not-literal-problem.c");

View File

@ -0,0 +1,28 @@
// Test ATARI chipset variations
// Pointer to struct versus MAcro pointer to struct
// CC65 macro pointer to struct
struct __pia {
unsigned char porta; /* port A data r/w */
unsigned char portb; /* port B data r/w */
unsigned char pactl; /* port A control */
unsigned char pbctl; /* port B control */
};
struct ATARI_PIA {
unsigned char PORTA; /* port A data r/w */
unsigned char PORTB; /* port B data r/w */
unsigned char PACTL; /* port A control */
unsigned char PBCTL; /* port B control */
};
#define PIA1 (*(struct __pia*)0xD300)
struct ATARI_PIA * const PIA2 = 0xD300;
void main() {
PIA1.porta = 7;
PIA2->PORTA = 7;
}

View File

@ -0,0 +1,15 @@
// Test ATARI chipset variations
// Pointer to struct versus MAcro pointer to struct
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label PIA2 = $d300
main: {
// PIA1.porta = 7
lda #7
sta $d300
// PIA2->PORTA = 7
sta PIA2
// }
rts
}

View File

@ -0,0 +1,9 @@
void main()
main: scope:[main] from
[0] *((byte*)(struct __pia*) 54016) = 7
[1] *((byte*)PIA2) = 7
to:main::@return
main::@return: scope:[main] from main
[2] return
to:@return

View File

@ -0,0 +1,159 @@
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start
*((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = 7
*((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7
to:main::@return
main::@return: scope:[main] from main
return
to:@return
void __start()
__start: scope:[__start] from
call main
to:__start::@1
__start::@1: scope:[__start] from __start
to:__start::@return
__start::@return: scope:[__start] from __start::@1
return
to:@return
SYMBOL TABLE SSA
const byte OFFSET_STRUCT_ATARI_PIA_PORTA = 0
const byte OFFSET_STRUCT___PIA_PORTA = 0
const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*)$d300
void __start()
void main()
Adding number conversion cast (unumber) 7 in *((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = 7
Adding number conversion cast (unumber) 7 in *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((byte*)(struct __pia*)$d300+OFFSET_STRUCT___PIA_PORTA) = (unumber)7
Inlining cast *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = (unumber)7
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (struct ATARI_PIA*) 54016
Simplifying constant integer cast 7
Simplifying constant pointer cast (struct __pia*) 54016
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type 7
Finalized unsigned number type 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero (byte*)(struct __pia*) 54016 in [0] *((byte*)(struct __pia*) 54016+OFFSET_STRUCT___PIA_PORTA) = 7
Simplifying expression containing zero (byte*)PIA2 in [1] *((byte*)PIA2+OFFSET_STRUCT_ATARI_PIA_PORTA) = 7
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant OFFSET_STRUCT___PIA_PORTA
Eliminating unused constant OFFSET_STRUCT_ATARI_PIA_PORTA
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
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] *((byte*)(struct __pia*) 54016) = 7
[1] *((byte*)PIA2) = 7
to:main::@return
main::@return: scope:[main] from main
[2] return
to:@return
VARIABLE REGISTER WEIGHTS
void main()
Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *((byte*)(struct __pia*) 54016) = 7 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [1] *((byte*)PIA2) = 7 [ ] ( [ ] { } ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [__pia]
Uplift Scope [ATARI_PIA]
Uplift Scope [main]
Uplift Scope []
Uplifting [__pia] best 21 combination
Uplifting [ATARI_PIA] best 21 combination
Uplifting [main] best 21 combination
Uplifting [] best 21 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test ATARI chipset variations
// Pointer to struct versus MAcro pointer to struct
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label PIA2 = $d300
// main
main: {
// [0] *((byte*)(struct __pia*) 54016) = 7 -- _deref_pbuc1=vbuc2
lda #7
sta $d300
// [1] *((byte*)PIA2) = 7 -- _deref_pbuc1=vbuc2
lda #7
sta PIA2
jmp __breturn
// main::@return
__breturn:
// [2] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #7
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*) 54016
void main()
FINAL ASSEMBLER
Score: 16
// File Comments
// Test ATARI chipset variations
// Pointer to struct versus MAcro pointer to struct
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label PIA2 = $d300
// main
main: {
// PIA1.porta = 7
// [0] *((byte*)(struct __pia*) 54016) = 7 -- _deref_pbuc1=vbuc2
lda #7
sta $d300
// PIA2->PORTA = 7
// [1] *((byte*)PIA2) = 7 -- _deref_pbuc1=vbuc2
sta PIA2
// main::@return
// }
// [2] return
rts
}
// File Data

View File

@ -0,0 +1,3 @@
const nomodify struct ATARI_PIA* PIA2 = (struct ATARI_PIA*) 54016
void main()