mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-23 08:32:39 +00:00
Added test example of sub-optimal ASM generated for sub-structs member access of a struct through a pointer. #226
This commit is contained in:
parent
889cc1219f
commit
aefa5c9f49
@ -322,6 +322,11 @@ public class TestPrograms {
|
||||
compileAndCompare("textbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStructPtr15() throws IOException, URISyntaxException {
|
||||
compileAndCompare("struct-ptr-15");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStructPtr14() throws IOException, URISyntaxException {
|
||||
compileAndCompare("struct-ptr-14");
|
||||
|
34
src/test/kc/struct-ptr-15.kc
Normal file
34
src/test/kc/struct-ptr-15.kc
Normal file
@ -0,0 +1,34 @@
|
||||
// Minimal struct - using pointers to nested structs
|
||||
|
||||
struct Point {
|
||||
byte x;
|
||||
byte y;
|
||||
};
|
||||
|
||||
struct Circle {
|
||||
byte radius;
|
||||
struct Point center;
|
||||
};
|
||||
|
||||
struct Circle[2] circles;
|
||||
|
||||
void main() {
|
||||
circles[0].center.x = 2;
|
||||
circles[0].center.y = 3;
|
||||
circles[0].radius = 5;
|
||||
circles[1].center.x = 8;
|
||||
circles[1].center.y = 9;
|
||||
circles[1].radius = 15;
|
||||
|
||||
const byte* SCREEN = 0x0400;
|
||||
byte idx =0;
|
||||
struct Circle* ptr = circles;
|
||||
for(byte i:0..1) {
|
||||
byte x = ptr->center.x;
|
||||
byte y = ptr->center.y;
|
||||
SCREEN[idx++] = x;
|
||||
SCREEN[idx++] = y;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
}
|
68
src/test/ref/struct-ptr-15.asm
Normal file
68
src/test/ref/struct-ptr-15.asm
Normal file
@ -0,0 +1,68 @@
|
||||
// Minimal struct - using pointers to nested structs
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.const SIZEOF_STRUCT_CIRCLE = 3
|
||||
.const OFFSET_STRUCT_CIRCLE_CENTER = 1
|
||||
.const OFFSET_STRUCT_POINT_Y = 1
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _16 = 3
|
||||
.label ptr = 3
|
||||
.label x = 5
|
||||
.label y = 6
|
||||
.label idx = 2
|
||||
lda #2
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
lda #3
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y
|
||||
lda #5
|
||||
sta circles
|
||||
lda #8
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+1*SIZEOF_STRUCT_CIRCLE
|
||||
lda #9
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y+1*SIZEOF_STRUCT_CIRCLE
|
||||
lda #$f
|
||||
sta circles+1*SIZEOF_STRUCT_CIRCLE
|
||||
lda #0
|
||||
sta idx
|
||||
tax
|
||||
b1:
|
||||
txa
|
||||
asl
|
||||
stx $ff
|
||||
clc
|
||||
adc $ff
|
||||
clc
|
||||
adc #<circles
|
||||
sta ptr
|
||||
lda #>circles
|
||||
adc #0
|
||||
sta ptr+1
|
||||
ldy #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
lda (ptr),y
|
||||
sta x
|
||||
tya
|
||||
clc
|
||||
adc _16
|
||||
sta _16
|
||||
bcc !+
|
||||
inc _16+1
|
||||
!:
|
||||
ldy #OFFSET_STRUCT_POINT_Y
|
||||
lda (_16),y
|
||||
sta y
|
||||
lda x
|
||||
ldy idx
|
||||
sta SCREEN,y
|
||||
iny
|
||||
lda y
|
||||
sta SCREEN,y
|
||||
iny
|
||||
sty idx
|
||||
inx
|
||||
cpx #2
|
||||
bne b1
|
||||
rts
|
||||
}
|
||||
circles: .fill 3*2, 0
|
36
src/test/ref/struct-ptr-15.cfg
Normal file
36
src/test/ref/struct-ptr-15.cfg
Normal file
@ -0,0 +1,36 @@
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2
|
||||
[5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3
|
||||
[6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5
|
||||
[7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8
|
||||
[8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9
|
||||
[9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[10] (byte) main::idx#3 ← phi( main/(byte) 0 main::@1/(byte) main::idx#2 )
|
||||
[10] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
|
||||
[11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1
|
||||
[12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2
|
||||
[13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2
|
||||
[14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER)
|
||||
[15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
[16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y)
|
||||
[17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0
|
||||
[18] (byte) main::idx#1 ← ++ (byte) main::idx#3
|
||||
[19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0
|
||||
[20] (byte) main::idx#2 ← ++ (byte) main::idx#1
|
||||
[21] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[22] if((byte) main::i#1!=(byte) 2) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[23] return
|
||||
to:@return
|
965
src/test/ref/struct-ptr-15.log
Normal file
965
src/test/ref/struct-ptr-15.log
Normal file
@ -0,0 +1,965 @@
|
||||
Fixing pointer addition (struct Circle*~) main::$0 ← (struct Circle[2]) circles + (byte) main::i
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 0)
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 0)
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 0)
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 1)
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 1)
|
||||
Fixing pointer array-indexing *((struct Circle[2]) circles + (number) 1)
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$3).center
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$4).center
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$5).radius
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$6).center
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$7).center
|
||||
Rewriting struct pointer member access *((struct Circle[2]) circles + (number~) main::$8).radius
|
||||
Rewriting struct pointer member access *((struct Circle*) main::ptr).center
|
||||
Rewriting struct pointer member access *((struct Circle*) main::ptr).center
|
||||
Rewriting struct pointer member access *((struct Point*) main::$9 + (number~) main::$3).x
|
||||
Rewriting struct pointer member access *((struct Point*) main::$10 + (number~) main::$4).y
|
||||
Rewriting struct pointer member access *((struct Point*) main::$12 + (number~) main::$6).x
|
||||
Rewriting struct pointer member access *((struct Point*) main::$13 + (number~) main::$7).y
|
||||
Rewriting struct pointer member access *((struct Point*) main::$15).x
|
||||
Rewriting struct pointer member access *((struct Point*) main::$16).y
|
||||
Culled Empty Block (label) main::@2
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
(struct Circle[2]) circles#0 ← { fill( 2, 0) }
|
||||
to:@1
|
||||
main: scope:[main] from @1
|
||||
(number~) main::$3 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(struct Point*) main::$9 ← (struct Point*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$17 ← (byte*)(struct Point*) main::$9 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
*((byte*) main::$17 + (number~) main::$3) ← (number) 2
|
||||
(number~) main::$4 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(struct Point*) main::$10 ← (struct Point*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$18 ← (byte*)(struct Point*) main::$10 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
*((byte*) main::$18 + (number~) main::$4) ← (number) 3
|
||||
(number~) main::$5 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(byte*) main::$11 ← (byte*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
*((byte*) main::$11 + (number~) main::$5) ← (number) 5
|
||||
(number~) main::$6 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(struct Point*) main::$12 ← (struct Point*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$19 ← (byte*)(struct Point*) main::$12 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
*((byte*) main::$19 + (number~) main::$6) ← (number) 8
|
||||
(number~) main::$7 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(struct Point*) main::$13 ← (struct Point*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$20 ← (byte*)(struct Point*) main::$13 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
*((byte*) main::$20 + (number~) main::$7) ← (number) 9
|
||||
(number~) main::$8 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(byte*) main::$14 ← (byte*)(struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
*((byte*) main::$14 + (number~) main::$8) ← (number) $f
|
||||
(byte*) main::SCREEN#0 ← ((byte*)) (number) $400
|
||||
(byte) main::idx#0 ← (number) 0
|
||||
(byte) main::i#0 ← (byte) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
(byte) main::idx#3 ← phi( main/(byte) main::idx#0 main::@1/(byte) main::idx#2 )
|
||||
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
|
||||
(byte~) main::$2 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
(struct Circle*~) main::$0 ← (struct Circle[2]) circles#0 + (byte~) main::$2
|
||||
(struct Circle*) main::ptr#0 ← (struct Circle*~) main::$0
|
||||
(struct Point*) main::$15 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$21 ← (byte*)(struct Point*) main::$15 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
(byte) main::x#0 ← *((byte*) main::$21)
|
||||
(struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
(byte*) main::$22 ← (byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
(byte) main::y#0 ← *((byte*) main::$22)
|
||||
*((byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0
|
||||
(byte) main::idx#1 ← ++ (byte) main::idx#3
|
||||
*((byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0
|
||||
(byte) main::idx#2 ← ++ (byte) main::idx#1
|
||||
(byte) main::i#1 ← (byte) main::i#2 + rangenext(0,1)
|
||||
(bool~) main::$1 ← (byte) main::i#1 != rangelast(0,1)
|
||||
if((bool~) main::$1) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
return
|
||||
to:@return
|
||||
@1: scope:[] from @begin
|
||||
call main
|
||||
to:@2
|
||||
@2: scope:[] from @1
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @1
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(struct Point) Circle::center
|
||||
(byte) Circle::radius
|
||||
(const byte) OFFSET_STRUCT_CIRCLE_CENTER = (byte) 1
|
||||
(const byte) OFFSET_STRUCT_CIRCLE_RADIUS = (byte) 0
|
||||
(const byte) OFFSET_STRUCT_POINT_X = (byte) 0
|
||||
(const byte) OFFSET_STRUCT_POINT_Y = (byte) 1
|
||||
(byte) Point::x
|
||||
(byte) Point::y
|
||||
(const byte) SIZEOF_STRUCT_CIRCLE = (byte) 3
|
||||
(struct Circle[2]) circles
|
||||
(struct Circle[2]) circles#0
|
||||
(void()) main()
|
||||
(struct Circle*~) main::$0
|
||||
(bool~) main::$1
|
||||
(struct Point*) main::$10
|
||||
(byte*) main::$11
|
||||
(struct Point*) main::$12
|
||||
(struct Point*) main::$13
|
||||
(byte*) main::$14
|
||||
(struct Point*) main::$15
|
||||
(struct Point*) main::$16
|
||||
(byte*) main::$17
|
||||
(byte*) main::$18
|
||||
(byte*) main::$19
|
||||
(byte~) main::$2
|
||||
(byte*) main::$20
|
||||
(byte*) main::$21
|
||||
(byte*) main::$22
|
||||
(number~) main::$3
|
||||
(number~) main::$4
|
||||
(number~) main::$5
|
||||
(number~) main::$6
|
||||
(number~) main::$7
|
||||
(number~) main::$8
|
||||
(struct Point*) main::$9
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(byte*) main::SCREEN#0
|
||||
(byte) main::i
|
||||
(byte) main::i#0
|
||||
(byte) main::i#1
|
||||
(byte) main::i#2
|
||||
(byte) main::idx
|
||||
(byte) main::idx#0
|
||||
(byte) main::idx#1
|
||||
(byte) main::idx#2
|
||||
(byte) main::idx#3
|
||||
(struct Circle*) main::ptr
|
||||
(struct Circle*) main::ptr#0
|
||||
(byte) main::x
|
||||
(byte) main::x#0
|
||||
(byte) main::y
|
||||
(byte) main::y#0
|
||||
|
||||
Adding number conversion cast (unumber) 0 in (number~) main::$3 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$3 in (number~) main::$3 ← (unumber)(number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) 2 in *((byte*) main::$17 + (unumber~) main::$3) ← (number) 2
|
||||
Adding number conversion cast (unumber) 0 in (number~) main::$4 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (unumber)(number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) 3 in *((byte*) main::$18 + (unumber~) main::$4) ← (number) 3
|
||||
Adding number conversion cast (unumber) 0 in (number~) main::$5 ← (number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$5 in (number~) main::$5 ← (unumber)(number) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) 5 in *((byte*) main::$11 + (unumber~) main::$5) ← (number) 5
|
||||
Adding number conversion cast (unumber) 1 in (number~) main::$6 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$6 in (number~) main::$6 ← (unumber)(number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) 8 in *((byte*) main::$19 + (unumber~) main::$6) ← (number) 8
|
||||
Adding number conversion cast (unumber) 1 in (number~) main::$7 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$7 in (number~) main::$7 ← (unumber)(number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) 9 in *((byte*) main::$20 + (unumber~) main::$7) ← (number) 9
|
||||
Adding number conversion cast (unumber) 1 in (number~) main::$8 ← (number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) main::$8 in (number~) main::$8 ← (unumber)(number) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Adding number conversion cast (unumber) $f in *((byte*) main::$14 + (unumber~) main::$8) ← (number) $f
|
||||
Adding number conversion cast (unumber) 0 in (byte) main::idx#0 ← (number) 0
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Inlining cast *((byte*) main::$17 + (unumber~) main::$3) ← (unumber)(number) 2
|
||||
Inlining cast *((byte*) main::$18 + (unumber~) main::$4) ← (unumber)(number) 3
|
||||
Inlining cast *((byte*) main::$11 + (unumber~) main::$5) ← (unumber)(number) 5
|
||||
Inlining cast *((byte*) main::$19 + (unumber~) main::$6) ← (unumber)(number) 8
|
||||
Inlining cast *((byte*) main::$20 + (unumber~) main::$7) ← (unumber)(number) 9
|
||||
Inlining cast *((byte*) main::$14 + (unumber~) main::$8) ← (unumber)(number) $f
|
||||
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400
|
||||
Inlining cast (byte) main::idx#0 ← (unumber)(number) 0
|
||||
Successful SSA optimization Pass2InlineCast
|
||||
Simplifying constant integer cast 0
|
||||
Simplifying constant integer cast 2
|
||||
Simplifying constant integer cast 0
|
||||
Simplifying constant integer cast 3
|
||||
Simplifying constant integer cast 0
|
||||
Simplifying constant integer cast 5
|
||||
Simplifying constant integer cast 1
|
||||
Simplifying constant integer cast 8
|
||||
Simplifying constant integer cast 1
|
||||
Simplifying constant integer cast 9
|
||||
Simplifying constant integer cast 1
|
||||
Simplifying constant integer cast $f
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Simplifying constant integer cast 0
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 0
|
||||
Finalized unsigned number type (byte) 2
|
||||
Finalized unsigned number type (byte) 0
|
||||
Finalized unsigned number type (byte) 3
|
||||
Finalized unsigned number type (byte) 0
|
||||
Finalized unsigned number type (byte) 5
|
||||
Finalized unsigned number type (byte) 1
|
||||
Finalized unsigned number type (byte) 8
|
||||
Finalized unsigned number type (byte) 1
|
||||
Finalized unsigned number type (byte) 9
|
||||
Finalized unsigned number type (byte) 1
|
||||
Finalized unsigned number type (byte) $f
|
||||
Finalized unsigned number type (byte) 0
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Inferred type updated to byte in (unumber~) main::$3 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inferred type updated to byte in (unumber~) main::$4 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inferred type updated to byte in (unumber~) main::$5 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inferred type updated to byte in (unumber~) main::$6 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inferred type updated to byte in (unumber~) main::$7 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inferred type updated to byte in (unumber~) main::$8 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Alias (struct Circle*) main::ptr#0 = (struct Circle*~) main::$0
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Simple Condition (bool~) main::$1 [42] if((byte) main::i#1!=rangelast(0,1)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant right-side identified [0] (struct Circle[2]) circles#0 ← { fill( 2, 0) }
|
||||
Constant right-side identified [1] (byte~) main::$3 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant right-side identified [5] (byte~) main::$4 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant right-side identified [9] (byte~) main::$5 ← (byte) 0 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant right-side identified [12] (byte~) main::$6 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant right-side identified [16] (byte~) main::$7 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant right-side identified [20] (byte~) main::$8 ← (byte) 1 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Successful SSA optimization Pass2ConstantRValueConsolidation
|
||||
Constant (const struct Circle[2]) circles#0 = { fill( 2, 0) }
|
||||
Constant (const byte) main::$3 = 0*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte) main::$4 = 0*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte) main::$5 = 0*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte) main::$6 = 1*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte) main::$7 = 1*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte) main::$8 = 1*SIZEOF_STRUCT_CIRCLE
|
||||
Constant (const byte*) main::SCREEN#0 = (byte*) 1024
|
||||
Constant (const byte) main::idx#0 = 0
|
||||
Constant (const byte) main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant value identified (struct Point*)circles#0 in [2] (struct Point*) main::$9 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant value identified (struct Point*)circles#0 in [6] (struct Point*) main::$10 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant value identified (byte*)circles#0 in [10] (byte*) main::$11 ← (byte*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
Constant value identified (struct Point*)circles#0 in [13] (struct Point*) main::$12 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant value identified (struct Point*)circles#0 in [17] (struct Point*) main::$13 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant value identified (byte*)circles#0 in [21] (byte*) main::$14 ← (byte*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
Successful SSA optimization Pass2ConstantValues
|
||||
Resolved ranged next value [40] main::i#1 ← ++ main::i#2 to ++
|
||||
Resolved ranged comparison value [42] if(main::i#1!=rangelast(0,1)) goto main::@1 to (number) 2
|
||||
Converting *(pointer+n) to pointer[n] [32] (byte) main::x#0 ← *((byte*) main::$21) -- *((byte*)main::$15 + OFFSET_STRUCT_POINT_X)
|
||||
Converting *(pointer+n) to pointer[n] [35] (byte) main::y#0 ← *((byte*) main::$22) -- *((byte*)main::$16 + OFFSET_STRUCT_POINT_Y)
|
||||
Successful SSA optimization Pass2InlineDerefIdx
|
||||
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_STRUCT_CIRCLE in
|
||||
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_STRUCT_CIRCLE in
|
||||
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_STRUCT_CIRCLE in
|
||||
Successful SSA optimization PassNSimplifyConstantZero
|
||||
Simplifying expression containing zero (byte*)main::$9 in [3] (byte*) main::$17 ← (byte*)(struct Point*) main::$9 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
Simplifying expression containing zero main::$17 in [4] *((byte*) main::$17 + (const byte) main::$3) ← (byte) 2
|
||||
Simplifying expression containing zero main::$18 in [8] *((byte*) main::$18 + (const byte) main::$4) ← (byte) 3
|
||||
Simplifying expression containing zero (byte*)circles#0 in [10] (byte*) main::$11 ← (byte*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
Simplifying expression containing zero main::$11 in [11] *((byte*) main::$11 + (const byte) main::$5) ← (byte) 5
|
||||
Simplifying expression containing zero (byte*)main::$12 in [14] (byte*) main::$19 ← (byte*)(struct Point*) main::$12 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
Simplifying expression containing zero (byte*)circles#0 in [21] (byte*) main::$14 ← (byte*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
Simplifying expression containing zero (byte*)main::$15 in [31] (byte*) main::$21 ← (byte*)(struct Point*) main::$15 + (const byte) OFFSET_STRUCT_POINT_X
|
||||
Simplifying expression containing zero (byte*)main::$15 in [32] (byte) main::x#0 ← *((byte*)(struct Point*) main::$15 + (const byte) OFFSET_STRUCT_POINT_X)
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Eliminating unused variable (byte*) main::$21 and assignment [20] (byte*) main::$21 ← (byte*)(struct Point*) main::$15
|
||||
Eliminating unused variable (byte*) main::$22 and assignment [23] (byte*) main::$22 ← (byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
Eliminating unused constant (const byte) main::$3
|
||||
Eliminating unused constant (const byte) main::$4
|
||||
Eliminating unused constant (const byte) main::$5
|
||||
Eliminating unused constant (const byte) OFFSET_STRUCT_CIRCLE_RADIUS
|
||||
Eliminating unused constant (const byte) OFFSET_STRUCT_POINT_X
|
||||
Successful SSA optimization PassNEliminateUnusedVars
|
||||
Adding number conversion cast (unumber) 2 in if((byte) main::i#1!=(number) 2) goto main::@1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Simplifying constant integer cast 2
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 2
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Constant right-side identified [0] (struct Point*) main::$9 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant right-side identified [3] (struct Point*) main::$10 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant right-side identified [8] (struct Point*) main::$12 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant right-side identified [11] (struct Point*) main::$13 ← (struct Point*)(const struct Circle[2]) circles#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Successful SSA optimization Pass2ConstantRValueConsolidation
|
||||
Constant (const struct Point*) main::$9 = (struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant (const struct Point*) main::$10 = (struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant (const byte*) main::$11 = (byte*)circles#0
|
||||
Constant (const struct Point*) main::$12 = (struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant (const struct Point*) main::$13 = (struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant (const byte*) main::$14 = (byte*)circles#0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Constant value identified (byte*)main::$9 in [1] (byte*) main::$17 ← (byte*)(const struct Point*) main::$9
|
||||
Constant value identified (byte*)main::$10 in [4] (byte*) main::$18 ← (byte*)(const struct Point*) main::$10 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
Constant value identified (byte*)main::$12 in [9] (byte*) main::$19 ← (byte*)(const struct Point*) main::$12
|
||||
Constant value identified (byte*)main::$13 in [12] (byte*) main::$20 ← (byte*)(const struct Point*) main::$13 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
Successful SSA optimization Pass2ConstantValues
|
||||
Converting *(pointer+n) to pointer[n] [5] *((byte*) main::$18) ← (byte) 3 -- *((byte*)main::$10 + OFFSET_STRUCT_POINT_Y)
|
||||
Converting *(pointer+n) to pointer[n] [20] (byte) main::x#0 ← *((byte*)(struct Point*) main::$15) -- *((byte*)(struct Point*)main::ptr#0 + OFFSET_STRUCT_CIRCLE_CENTER)
|
||||
Successful SSA optimization Pass2InlineDerefIdx
|
||||
Eliminating unused variable (byte*) main::$18 and assignment [2] (byte*) main::$18 ← (byte*)(const struct Point*) main::$10 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
Eliminating unused variable (struct Point*) main::$15 and assignment [13] (struct Point*) main::$15 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Successful SSA optimization PassNEliminateUnusedVars
|
||||
Constant right-side identified [6] (byte*) main::$20 ← (byte*)(const struct Point*) main::$13 + (const byte) OFFSET_STRUCT_POINT_Y
|
||||
Successful SSA optimization Pass2ConstantRValueConsolidation
|
||||
Constant (const byte*) main::$17 = (byte*)main::$9
|
||||
Constant (const byte*) main::$19 = (byte*)main::$12
|
||||
Constant (const byte*) main::$20 = (byte*)main::$13+OFFSET_STRUCT_POINT_Y
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Rewriting multiplication to use shift and addition[7] (byte~) main::$2 ← (byte) main::i#2 * (const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Inlining constant with var siblings (const byte) main::idx#0
|
||||
Inlining constant with var siblings (const byte) main::i#0
|
||||
Constant inlined main::$12 = (struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::$13 = (struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::$14 = (byte*)(const struct Circle[2]) circles#0
|
||||
Constant inlined main::$20 = (byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y
|
||||
Constant inlined main::$10 = (struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::$11 = (byte*)(const struct Circle[2]) circles#0
|
||||
Constant inlined main::idx#0 = (byte) 0
|
||||
Constant inlined main::$17 = (byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::$19 = (byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::i#0 = (byte) 0
|
||||
Constant inlined main::$6 = (byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant inlined main::$9 = (struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
Constant inlined main::$7 = (byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Constant inlined main::$8 = (byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Consolidated array index constant in *((byte*)(struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y)
|
||||
Consolidated array index constant in *((byte*)(struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER+1*SIZEOF_STRUCT_CIRCLE)
|
||||
Consolidated array index constant in *((byte*)(struct Point*)circles#0+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y+1*SIZEOF_STRUCT_CIRCLE)
|
||||
Consolidated array index constant in *((byte*)circles#0+1*SIZEOF_STRUCT_CIRCLE)
|
||||
Successful SSA optimization Pass2ConstantAdditionElimination
|
||||
Alias (byte~) main::$2 = (byte) main::$24
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Added new block during phi lifting main::@3(between main::@1 and main::@1)
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @2
|
||||
Adding NOP phi() at start of @end
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
|
||||
Created 2 initial phi equivalence classes
|
||||
Coalesced [25] main::i#3 ← main::i#1
|
||||
Coalesced [26] main::idx#4 ← main::idx#2
|
||||
Coalesced down to 2 phi equivalence classes
|
||||
Culled Empty Block (label) @2
|
||||
Culled Empty Block (label) main::@3
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
@begin: scope:[] from
|
||||
[0] phi()
|
||||
to:@1
|
||||
@1: scope:[] from @begin
|
||||
[1] phi()
|
||||
[2] call main
|
||||
to:@end
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2
|
||||
[5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3
|
||||
[6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5
|
||||
[7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8
|
||||
[8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9
|
||||
[9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@1
|
||||
[10] (byte) main::idx#3 ← phi( main/(byte) 0 main::@1/(byte) main::idx#2 )
|
||||
[10] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
|
||||
[11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1
|
||||
[12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2
|
||||
[13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2
|
||||
[14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER)
|
||||
[15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER
|
||||
[16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y)
|
||||
[17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0
|
||||
[18] (byte) main::idx#1 ← ++ (byte) main::idx#3
|
||||
[19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0
|
||||
[20] (byte) main::idx#2 ← ++ (byte) main::idx#1
|
||||
[21] (byte) main::i#1 ← ++ (byte) main::i#2
|
||||
[22] if((byte) main::i#1!=(byte) 2) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[23] return
|
||||
to:@return
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(struct Point) Circle::center
|
||||
(byte) Circle::radius
|
||||
(byte) Point::x
|
||||
(byte) Point::y
|
||||
(struct Circle[2]) circles
|
||||
(void()) main()
|
||||
(struct Point*) main::$16 11.0
|
||||
(byte~) main::$2 22.0
|
||||
(byte) main::$23 22.0
|
||||
(byte*) main::SCREEN
|
||||
(byte) main::i
|
||||
(byte) main::i#1 16.5
|
||||
(byte) main::i#2 4.0
|
||||
(byte) main::idx
|
||||
(byte) main::idx#1 16.5
|
||||
(byte) main::idx#2 7.333333333333333
|
||||
(byte) main::idx#3 4.125
|
||||
(struct Circle*) main::ptr
|
||||
(struct Circle*) main::ptr#0 5.5
|
||||
(byte) main::x
|
||||
(byte) main::x#0 7.333333333333333
|
||||
(byte) main::y
|
||||
(byte) main::y#0 7.333333333333333
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ main::idx#3 main::idx#2 ]
|
||||
Added variable main::$23 to zero page equivalence class [ main::$23 ]
|
||||
Added variable main::$2 to zero page equivalence class [ main::$2 ]
|
||||
Added variable main::ptr#0 to zero page equivalence class [ main::ptr#0 ]
|
||||
Added variable main::x#0 to zero page equivalence class [ main::x#0 ]
|
||||
Added variable main::$16 to zero page equivalence class [ main::$16 ]
|
||||
Added variable main::y#0 to zero page equivalence class [ main::y#0 ]
|
||||
Added variable main::idx#1 to zero page equivalence class [ main::idx#1 ]
|
||||
Complete equivalence classes
|
||||
[ main::i#2 main::i#1 ]
|
||||
[ main::idx#3 main::idx#2 ]
|
||||
[ main::$23 ]
|
||||
[ main::$2 ]
|
||||
[ main::ptr#0 ]
|
||||
[ main::x#0 ]
|
||||
[ main::$16 ]
|
||||
[ main::y#0 ]
|
||||
[ main::idx#1 ]
|
||||
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
||||
Allocated zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ]
|
||||
Allocated zp ZP_BYTE:4 [ main::$23 ]
|
||||
Allocated zp ZP_BYTE:5 [ main::$2 ]
|
||||
Allocated zp ZP_WORD:6 [ main::ptr#0 ]
|
||||
Allocated zp ZP_BYTE:8 [ main::x#0 ]
|
||||
Allocated zp ZP_WORD:9 [ main::$16 ]
|
||||
Allocated zp ZP_BYTE:11 [ main::y#0 ]
|
||||
Allocated zp ZP_BYTE:12 [ main::idx#1 ]
|
||||
|
||||
INITIAL ASM
|
||||
// File Comments
|
||||
// Minimal struct - using pointers to nested structs
|
||||
// Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.const SIZEOF_STRUCT_CIRCLE = 3
|
||||
.const OFFSET_STRUCT_CIRCLE_CENTER = 1
|
||||
.const OFFSET_STRUCT_POINT_Y = 1
|
||||
// @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: {
|
||||
.label SCREEN = $400
|
||||
.label _2 = 5
|
||||
.label _16 = 9
|
||||
.label ptr = 6
|
||||
.label x = 8
|
||||
.label y = $b
|
||||
.label idx = $c
|
||||
.label idx_2 = 3
|
||||
.label i = 2
|
||||
.label idx_3 = 3
|
||||
.label _23 = 4
|
||||
// [4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2 -- _deref_pbuc1=vbuc2
|
||||
lda #2
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
// [5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3 -- _deref_pbuc1=vbuc2
|
||||
lda #3
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y
|
||||
// [6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5 -- _deref_pbuc1=vbuc2
|
||||
lda #5
|
||||
sta circles
|
||||
// [7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8 -- _deref_pbuc1=vbuc2
|
||||
lda #8
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9 -- _deref_pbuc1=vbuc2
|
||||
lda #9
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f -- _deref_pbuc1=vbuc2
|
||||
lda #$f
|
||||
sta circles+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [10] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
// [10] phi (byte) main::idx#3 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta idx_3
|
||||
// [10] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta i
|
||||
jmp b1
|
||||
// [10] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
// [10] phi (byte) main::idx#3 = (byte) main::idx#2 [phi:main::@1->main::@1#0] -- register_copy
|
||||
// [10] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy
|
||||
jmp b1
|
||||
// main::@1
|
||||
b1:
|
||||
// [11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1
|
||||
lda i
|
||||
asl
|
||||
sta _23
|
||||
// [12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2 -- vbuz1=vbuz2_plus_vbuz3
|
||||
lda _23
|
||||
clc
|
||||
adc i
|
||||
sta _2
|
||||
// [13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2 -- pssz1=pssc1_plus_vbuz2
|
||||
lda _2
|
||||
clc
|
||||
adc #<circles
|
||||
sta ptr
|
||||
lda #>circles
|
||||
adc #0
|
||||
sta ptr+1
|
||||
// [14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
lda (ptr),y
|
||||
sta x
|
||||
// [15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER -- pssz1=pssz2_plus_vbuc1
|
||||
lda #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
clc
|
||||
adc ptr
|
||||
sta _16
|
||||
lda #0
|
||||
adc ptr+1
|
||||
sta _16+1
|
||||
// [16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_POINT_Y
|
||||
lda (_16),y
|
||||
sta y
|
||||
// [17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda x
|
||||
ldy idx_3
|
||||
sta SCREEN,y
|
||||
// [18] (byte) main::idx#1 ← ++ (byte) main::idx#3 -- vbuz1=_inc_vbuz2
|
||||
ldy idx_3
|
||||
iny
|
||||
sty idx
|
||||
// [19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda y
|
||||
ldy idx
|
||||
sta SCREEN,y
|
||||
// [20] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuz2
|
||||
ldy idx
|
||||
iny
|
||||
sty idx_2
|
||||
// [21] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
||||
inc i
|
||||
// [22] if((byte) main::i#1!=(byte) 2) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda #2
|
||||
cmp i
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
// main::@return
|
||||
breturn:
|
||||
// [23] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
circles: .fill 3*2, 0
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::idx#3 main::$23 ] ( main:2 [ main::i#2 main::idx#3 main::$23 ] ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ]
|
||||
Statement [12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2 [ main::i#2 main::idx#3 main::$2 ] ( main:2 [ main::i#2 main::idx#3 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2 [ main::i#2 main::idx#3 main::ptr#0 ] ( main:2 [ main::i#2 main::idx#3 main::ptr#0 ] ) always clobbers reg byte a
|
||||
Statement [14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER) [ main::i#2 main::idx#3 main::ptr#0 main::x#0 ] ( main:2 [ main::i#2 main::idx#3 main::ptr#0 main::x#0 ] ) always clobbers reg byte a reg byte y
|
||||
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
||||
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ]
|
||||
Statement [15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER [ main::i#2 main::idx#3 main::x#0 main::$16 ] ( main:2 [ main::i#2 main::idx#3 main::x#0 main::$16 ] ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:8 [ main::x#0 ]
|
||||
Statement [16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y) [ main::i#2 main::idx#3 main::x#0 main::y#0 ] ( main:2 [ main::i#2 main::idx#3 main::x#0 main::y#0 ] ) always clobbers reg byte a reg byte y
|
||||
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:8 [ main::x#0 ]
|
||||
Statement [17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0 [ main::i#2 main::idx#3 main::y#0 ] ( main:2 [ main::i#2 main::idx#3 main::y#0 ] ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:11 [ main::y#0 ]
|
||||
Statement [19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0 [ main::i#2 main::idx#1 ] ( main:2 [ main::i#2 main::idx#1 ] ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:12 [ main::idx#1 ]
|
||||
Statement [4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9 [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f [ ] ( main:2 [ ] ) always clobbers reg byte a
|
||||
Statement [11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::idx#3 main::$23 ] ( main:2 [ main::i#2 main::idx#3 main::$23 ] ) always clobbers reg byte a
|
||||
Statement [12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2 [ main::i#2 main::idx#3 main::$2 ] ( main:2 [ main::i#2 main::idx#3 main::$2 ] ) always clobbers reg byte a
|
||||
Statement [13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2 [ main::i#2 main::idx#3 main::ptr#0 ] ( main:2 [ main::i#2 main::idx#3 main::ptr#0 ] ) always clobbers reg byte a
|
||||
Statement [14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER) [ main::i#2 main::idx#3 main::ptr#0 main::x#0 ] ( main:2 [ main::i#2 main::idx#3 main::ptr#0 main::x#0 ] ) always clobbers reg byte a reg byte y
|
||||
Statement [15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER [ main::i#2 main::idx#3 main::x#0 main::$16 ] ( main:2 [ main::i#2 main::idx#3 main::x#0 main::$16 ] ) always clobbers reg byte a
|
||||
Statement [16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y) [ main::i#2 main::idx#3 main::x#0 main::y#0 ] ( main:2 [ main::i#2 main::idx#3 main::x#0 main::y#0 ] ) always clobbers reg byte a reg byte y
|
||||
Statement [17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0 [ main::i#2 main::idx#3 main::y#0 ] ( main:2 [ main::i#2 main::idx#3 main::y#0 ] ) always clobbers reg byte a
|
||||
Statement [19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0 [ main::i#2 main::idx#1 ] ( main:2 [ main::i#2 main::idx#1 ] ) always clobbers reg byte a
|
||||
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x ,
|
||||
Potential registers zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ] : zp ZP_BYTE:3 , reg byte x ,
|
||||
Potential registers zp ZP_BYTE:4 [ main::$23 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:5 [ main::$2 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_WORD:6 [ main::ptr#0 ] : zp ZP_WORD:6 ,
|
||||
Potential registers zp ZP_BYTE:8 [ main::x#0 ] : zp ZP_BYTE:8 , reg byte x ,
|
||||
Potential registers zp ZP_WORD:9 [ main::$16 ] : zp ZP_WORD:9 ,
|
||||
Potential registers zp ZP_BYTE:11 [ main::y#0 ] : zp ZP_BYTE:11 , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:12 [ main::idx#1 ] : zp ZP_BYTE:12 , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 22: zp ZP_BYTE:4 [ main::$23 ] 22: zp ZP_BYTE:5 [ main::$2 ] 20.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 16.5: zp ZP_BYTE:12 [ main::idx#1 ] 11.46: zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ] 11: zp ZP_WORD:9 [ main::$16 ] 7.33: zp ZP_BYTE:8 [ main::x#0 ] 7.33: zp ZP_BYTE:11 [ main::y#0 ] 5.5: zp ZP_WORD:6 [ main::ptr#0 ]
|
||||
Uplift Scope [Point]
|
||||
Uplift Scope [Circle]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 1219 combination reg byte a [ main::$23 ] reg byte a [ main::$2 ] reg byte x [ main::i#2 main::i#1 ] reg byte y [ main::idx#1 ] zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ] zp ZP_WORD:9 [ main::$16 ] zp ZP_BYTE:8 [ main::x#0 ] zp ZP_BYTE:11 [ main::y#0 ] zp ZP_WORD:6 [ main::ptr#0 ]
|
||||
Limited combination testing to 100 combinations of 1152 possible.
|
||||
Uplifting [Point] best 1219 combination
|
||||
Uplifting [Circle] best 1219 combination
|
||||
Uplifting [] best 1219 combination
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:3 [ main::idx#3 main::idx#2 ]
|
||||
Uplifting [main] best 1219 combination zp ZP_BYTE:3 [ main::idx#3 main::idx#2 ]
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:8 [ main::x#0 ]
|
||||
Uplifting [main] best 1219 combination zp ZP_BYTE:8 [ main::x#0 ]
|
||||
Attempting to uplift remaining variables inzp ZP_BYTE:11 [ main::y#0 ]
|
||||
Uplifting [main] best 1219 combination zp ZP_BYTE:11 [ main::y#0 ]
|
||||
Coalescing zero page register with common assignment [ zp ZP_WORD:6 [ main::ptr#0 ] ] with [ zp ZP_WORD:9 [ main::$16 ] ] - score: 1
|
||||
Allocated (was zp ZP_BYTE:3) zp ZP_BYTE:2 [ main::idx#3 main::idx#2 ]
|
||||
Allocated (was zp ZP_WORD:6) zp ZP_WORD:3 [ main::ptr#0 main::$16 ]
|
||||
Allocated (was zp ZP_BYTE:8) zp ZP_BYTE:5 [ main::x#0 ]
|
||||
Allocated (was zp ZP_BYTE:11) zp ZP_BYTE:6 [ main::y#0 ]
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Minimal struct - using pointers to nested structs
|
||||
// Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.const SIZEOF_STRUCT_CIRCLE = 3
|
||||
.const OFFSET_STRUCT_CIRCLE_CENTER = 1
|
||||
.const OFFSET_STRUCT_POINT_Y = 1
|
||||
// @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: {
|
||||
.label SCREEN = $400
|
||||
.label _16 = 3
|
||||
.label ptr = 3
|
||||
.label x = 5
|
||||
.label y = 6
|
||||
.label idx = 2
|
||||
// [4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2 -- _deref_pbuc1=vbuc2
|
||||
lda #2
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
// [5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3 -- _deref_pbuc1=vbuc2
|
||||
lda #3
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y
|
||||
// [6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5 -- _deref_pbuc1=vbuc2
|
||||
lda #5
|
||||
sta circles
|
||||
// [7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8 -- _deref_pbuc1=vbuc2
|
||||
lda #8
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9 -- _deref_pbuc1=vbuc2
|
||||
lda #9
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f -- _deref_pbuc1=vbuc2
|
||||
lda #$f
|
||||
sta circles+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [10] phi from main to main::@1 [phi:main->main::@1]
|
||||
b1_from_main:
|
||||
// [10] phi (byte) main::idx#3 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta idx
|
||||
// [10] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp b1
|
||||
// [10] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
b1_from_b1:
|
||||
// [10] phi (byte) main::idx#3 = (byte) main::idx#2 [phi:main::@1->main::@1#0] -- register_copy
|
||||
// [10] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy
|
||||
jmp b1
|
||||
// main::@1
|
||||
b1:
|
||||
// [11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
// [12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2 -- vbuaa=vbuaa_plus_vbuxx
|
||||
stx $ff
|
||||
clc
|
||||
adc $ff
|
||||
// [13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2 -- pssz1=pssc1_plus_vbuaa
|
||||
clc
|
||||
adc #<circles
|
||||
sta ptr
|
||||
lda #>circles
|
||||
adc #0
|
||||
sta ptr+1
|
||||
// [14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
lda (ptr),y
|
||||
sta x
|
||||
// [15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER -- pssz1=pssz1_plus_vbuc1
|
||||
lda #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
clc
|
||||
adc _16
|
||||
sta _16
|
||||
bcc !+
|
||||
inc _16+1
|
||||
!:
|
||||
// [16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_POINT_Y
|
||||
lda (_16),y
|
||||
sta y
|
||||
// [17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda x
|
||||
ldy idx
|
||||
sta SCREEN,y
|
||||
// [18] (byte) main::idx#1 ← ++ (byte) main::idx#3 -- vbuyy=_inc_vbuz1
|
||||
ldy idx
|
||||
iny
|
||||
// [19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0 -- pbuc1_derefidx_vbuyy=vbuz1
|
||||
lda y
|
||||
sta SCREEN,y
|
||||
// [20] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuyy
|
||||
iny
|
||||
sty idx
|
||||
// [21] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [22] if((byte) main::i#1!=(byte) 2) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #2
|
||||
bne b1_from_b1
|
||||
jmp breturn
|
||||
// main::@return
|
||||
breturn:
|
||||
// [23] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
circles: .fill 3*2, 0
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp bend
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing instruction ldx #0 with TAX
|
||||
Replacing instruction lda #OFFSET_STRUCT_CIRCLE_CENTER with TYA
|
||||
Removing instruction ldy idx
|
||||
Succesful ASM optimization Pass5UnnecesaryLoadElimination
|
||||
Replacing label b1_from_b1 with b1
|
||||
Removing instruction b1_from_bbegin:
|
||||
Removing instruction b1:
|
||||
Removing instruction bend_from_b1:
|
||||
Removing instruction b1_from_b1:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction bend:
|
||||
Removing instruction b1_from_main:
|
||||
Removing instruction breturn:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Updating BasicUpstart to call main directly
|
||||
Removing instruction jsr main
|
||||
Succesful ASM optimization Pass5SkipBegin
|
||||
Removing instruction jmp b1
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction bbegin:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(struct Point) Circle::center
|
||||
(byte) Circle::radius
|
||||
(const byte) OFFSET_STRUCT_CIRCLE_CENTER OFFSET_STRUCT_CIRCLE_CENTER = (byte) 1
|
||||
(const byte) OFFSET_STRUCT_POINT_Y OFFSET_STRUCT_POINT_Y = (byte) 1
|
||||
(byte) Point::x
|
||||
(byte) Point::y
|
||||
(const byte) SIZEOF_STRUCT_CIRCLE SIZEOF_STRUCT_CIRCLE = (byte) 3
|
||||
(struct Circle[2]) circles
|
||||
(const struct Circle[2]) circles#0 circles = { fill( 2, 0) }
|
||||
(void()) main()
|
||||
(struct Point*) main::$16 $16 zp ZP_WORD:3 11.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte) main::$23 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 4.0
|
||||
(byte) main::idx
|
||||
(byte) main::idx#1 reg byte y 16.5
|
||||
(byte) main::idx#2 idx zp ZP_BYTE:2 7.333333333333333
|
||||
(byte) main::idx#3 idx zp ZP_BYTE:2 4.125
|
||||
(struct Circle*) main::ptr
|
||||
(struct Circle*) main::ptr#0 ptr zp ZP_WORD:3 5.5
|
||||
(byte) main::x
|
||||
(byte) main::x#0 x zp ZP_BYTE:5 7.333333333333333
|
||||
(byte) main::y
|
||||
(byte) main::y#0 y zp ZP_BYTE:6 7.333333333333333
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
zp ZP_BYTE:2 [ main::idx#3 main::idx#2 ]
|
||||
reg byte a [ main::$23 ]
|
||||
reg byte a [ main::$2 ]
|
||||
zp ZP_WORD:3 [ main::ptr#0 main::$16 ]
|
||||
zp ZP_BYTE:5 [ main::x#0 ]
|
||||
zp ZP_BYTE:6 [ main::y#0 ]
|
||||
reg byte y [ main::idx#1 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 1082
|
||||
|
||||
// File Comments
|
||||
// Minimal struct - using pointers to nested structs
|
||||
// Basic Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.const SIZEOF_STRUCT_CIRCLE = 3
|
||||
.const OFFSET_STRUCT_CIRCLE_CENTER = 1
|
||||
.const OFFSET_STRUCT_POINT_Y = 1
|
||||
// @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: {
|
||||
.label SCREEN = $400
|
||||
.label _16 = 3
|
||||
.label ptr = 3
|
||||
.label x = 5
|
||||
.label y = 6
|
||||
.label idx = 2
|
||||
// circles[0].center.x = 2
|
||||
// [4] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER) ← (byte) 2 -- _deref_pbuc1=vbuc2
|
||||
lda #2
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER
|
||||
// circles[0].center.y = 3
|
||||
// [5] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y) ← (byte) 3 -- _deref_pbuc1=vbuc2
|
||||
lda #3
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y
|
||||
// circles[0].radius = 5
|
||||
// [6] *((byte*)(const struct Circle[2]) circles#0) ← (byte) 5 -- _deref_pbuc1=vbuc2
|
||||
lda #5
|
||||
sta circles
|
||||
// circles[1].center.x = 8
|
||||
// [7] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 8 -- _deref_pbuc1=vbuc2
|
||||
lda #8
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+1*SIZEOF_STRUCT_CIRCLE
|
||||
// circles[1].center.y = 9
|
||||
// [8] *((byte*)(struct Point*)(const struct Circle[2]) circles#0+(const byte) OFFSET_STRUCT_CIRCLE_CENTER+(const byte) OFFSET_STRUCT_POINT_Y+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) 9 -- _deref_pbuc1=vbuc2
|
||||
lda #9
|
||||
sta circles+OFFSET_STRUCT_CIRCLE_CENTER+OFFSET_STRUCT_POINT_Y+1*SIZEOF_STRUCT_CIRCLE
|
||||
// circles[1].radius = 15
|
||||
// [9] *((byte*)(const struct Circle[2]) circles#0+(byte) 1*(const byte) SIZEOF_STRUCT_CIRCLE) ← (byte) $f -- _deref_pbuc1=vbuc2
|
||||
lda #$f
|
||||
sta circles+1*SIZEOF_STRUCT_CIRCLE
|
||||
// [10] phi from main to main::@1 [phi:main->main::@1]
|
||||
// [10] phi (byte) main::idx#3 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta idx
|
||||
// [10] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
|
||||
tax
|
||||
// [10] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
|
||||
// [10] phi (byte) main::idx#3 = (byte) main::idx#2 [phi:main::@1->main::@1#0] -- register_copy
|
||||
// [10] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy
|
||||
// main::@1
|
||||
b1:
|
||||
// circles+i
|
||||
// [11] (byte) main::$23 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
|
||||
txa
|
||||
asl
|
||||
// [12] (byte~) main::$2 ← (byte) main::$23 + (byte) main::i#2 -- vbuaa=vbuaa_plus_vbuxx
|
||||
stx $ff
|
||||
clc
|
||||
adc $ff
|
||||
// ptr = circles+i
|
||||
// [13] (struct Circle*) main::ptr#0 ← (const struct Circle[2]) circles#0 + (byte~) main::$2 -- pssz1=pssc1_plus_vbuaa
|
||||
clc
|
||||
adc #<circles
|
||||
sta ptr
|
||||
lda #>circles
|
||||
adc #0
|
||||
sta ptr+1
|
||||
// x = ptr->center.x
|
||||
// [14] (byte) main::x#0 ← *((byte*)(struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_CIRCLE_CENTER
|
||||
lda (ptr),y
|
||||
sta x
|
||||
// y = ptr->center.y
|
||||
// [15] (struct Point*) main::$16 ← (struct Point*)(struct Circle*) main::ptr#0 + (const byte) OFFSET_STRUCT_CIRCLE_CENTER -- pssz1=pssz1_plus_vbuc1
|
||||
tya
|
||||
clc
|
||||
adc _16
|
||||
sta _16
|
||||
bcc !+
|
||||
inc _16+1
|
||||
!:
|
||||
// [16] (byte) main::y#0 ← *((byte*)(struct Point*) main::$16 + (const byte) OFFSET_STRUCT_POINT_Y) -- vbuz1=pbuz2_derefidx_vbuc1
|
||||
ldy #OFFSET_STRUCT_POINT_Y
|
||||
lda (_16),y
|
||||
sta y
|
||||
// SCREEN[idx++] = x
|
||||
// [17] *((const byte*) main::SCREEN#0 + (byte) main::idx#3) ← (byte) main::x#0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda x
|
||||
ldy idx
|
||||
sta SCREEN,y
|
||||
// SCREEN[idx++] = x;
|
||||
// [18] (byte) main::idx#1 ← ++ (byte) main::idx#3 -- vbuyy=_inc_vbuz1
|
||||
iny
|
||||
// SCREEN[idx++] = y
|
||||
// [19] *((const byte*) main::SCREEN#0 + (byte) main::idx#1) ← (byte) main::y#0 -- pbuc1_derefidx_vbuyy=vbuz1
|
||||
lda y
|
||||
sta SCREEN,y
|
||||
// SCREEN[idx++] = y;
|
||||
// [20] (byte) main::idx#2 ← ++ (byte) main::idx#1 -- vbuz1=_inc_vbuyy
|
||||
iny
|
||||
sty idx
|
||||
// for(byte i:0..1)
|
||||
// [21] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [22] if((byte) main::i#1!=(byte) 2) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #2
|
||||
bne b1
|
||||
// main::@return
|
||||
// }
|
||||
// [23] return
|
||||
rts
|
||||
}
|
||||
// File Data
|
||||
circles: .fill 3*2, 0
|
||||
|
42
src/test/ref/struct-ptr-15.sym
Normal file
42
src/test/ref/struct-ptr-15.sym
Normal file
@ -0,0 +1,42 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(struct Point) Circle::center
|
||||
(byte) Circle::radius
|
||||
(const byte) OFFSET_STRUCT_CIRCLE_CENTER OFFSET_STRUCT_CIRCLE_CENTER = (byte) 1
|
||||
(const byte) OFFSET_STRUCT_POINT_Y OFFSET_STRUCT_POINT_Y = (byte) 1
|
||||
(byte) Point::x
|
||||
(byte) Point::y
|
||||
(const byte) SIZEOF_STRUCT_CIRCLE SIZEOF_STRUCT_CIRCLE = (byte) 3
|
||||
(struct Circle[2]) circles
|
||||
(const struct Circle[2]) circles#0 circles = { fill( 2, 0) }
|
||||
(void()) main()
|
||||
(struct Point*) main::$16 $16 zp ZP_WORD:3 11.0
|
||||
(byte~) main::$2 reg byte a 22.0
|
||||
(byte) main::$23 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 16.5
|
||||
(byte) main::i#2 reg byte x 4.0
|
||||
(byte) main::idx
|
||||
(byte) main::idx#1 reg byte y 16.5
|
||||
(byte) main::idx#2 idx zp ZP_BYTE:2 7.333333333333333
|
||||
(byte) main::idx#3 idx zp ZP_BYTE:2 4.125
|
||||
(struct Circle*) main::ptr
|
||||
(struct Circle*) main::ptr#0 ptr zp ZP_WORD:3 5.5
|
||||
(byte) main::x
|
||||
(byte) main::x#0 x zp ZP_BYTE:5 7.333333333333333
|
||||
(byte) main::y
|
||||
(byte) main::y#0 y zp ZP_BYTE:6 7.333333333333333
|
||||
|
||||
reg byte x [ main::i#2 main::i#1 ]
|
||||
zp ZP_BYTE:2 [ main::idx#3 main::idx#2 ]
|
||||
reg byte a [ main::$23 ]
|
||||
reg byte a [ main::$2 ]
|
||||
zp ZP_WORD:3 [ main::ptr#0 main::$16 ]
|
||||
zp ZP_BYTE:5 [ main::x#0 ]
|
||||
zp ZP_BYTE:6 [ main::y#0 ]
|
||||
reg byte y [ main::idx#1 ]
|
Loading…
Reference in New Issue
Block a user