mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-20 02:32:36 +00:00
899 lines
38 KiB
Plaintext
899 lines
38 KiB
Plaintext
Fixing struct type size struct Person to 5
|
|
Fixing struct type size struct Person to 5
|
|
Fixing struct type size struct Person to 5
|
|
Fixing pointer increment (struct Person*) main::person ← ++ (struct Person*) main::person
|
|
Rewriting struct pointer member access *((struct Person*) print_person::person).id
|
|
Rewriting struct pointer member access *((struct Person*) print_person::person).initials
|
|
Rewriting struct pointer member access *((struct Person*) print_person::person).initials
|
|
Rewriting struct pointer member access *((struct Person*) print_person::person).initials
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
(struct Person[]) persons ← { { (number) 1, (const string) $0 }, { (number) 8, (const string) $1 } }
|
|
to:@1
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @2
|
|
(byte) idx#18 ← phi( @2/(byte) idx#19 )
|
|
(struct Person*) main::person#0 ← (struct Person[]) persons
|
|
(struct Person*) print_person::person#0 ← (struct Person*) main::person#0
|
|
call print_person
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
(struct Person*) main::person#2 ← phi( main/(struct Person*) main::person#0 )
|
|
(byte) idx#12 ← phi( main/(byte) idx#10 )
|
|
(byte) idx#0 ← (byte) idx#12
|
|
(struct Person*) main::person#1 ← (struct Person*) main::person#2 + (const byte) SIZEOF_STRUCT_PERSON
|
|
(struct Person*) print_person::person#1 ← (struct Person*) main::person#1
|
|
call print_person
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
(byte) idx#13 ← phi( main::@1/(byte) idx#10 )
|
|
(byte) idx#1 ← (byte) idx#13
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@2
|
|
(byte) idx#14 ← phi( main::@2/(byte) idx#1 )
|
|
(byte) idx#2 ← (byte) idx#14
|
|
return
|
|
to:@return
|
|
@1: scope:[] from @begin
|
|
(byte*) SCREEN ← ((byte*)) (number) $400
|
|
(byte) idx#3 ← (number) 0
|
|
to:@2
|
|
|
|
(void()) print_person((struct Person*) print_person::person)
|
|
print_person: scope:[print_person] from main main::@1
|
|
(byte) idx#15 ← phi( main/(byte) idx#18 main::@1/(byte) idx#0 )
|
|
(struct Person*) print_person::person#2 ← phi( main/(struct Person*) print_person::person#0 main::@1/(struct Person*) print_person::person#1 )
|
|
(byte*) print_person::$1 ← (byte*)(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_ID
|
|
(byte~) print_person::$0 ← (byte) '0' + *((byte*) print_person::$1)
|
|
*((byte*) SCREEN + (byte) idx#15) ← (byte~) print_person::$0
|
|
(byte) idx#4 ← ++ (byte) idx#15
|
|
*((byte*) SCREEN + (byte) idx#4) ← (byte) ' '
|
|
(byte) idx#5 ← ++ (byte) idx#4
|
|
(byte[4]) print_person::$2 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
*((byte*) SCREEN + (byte) idx#5) ← *((byte[4]) print_person::$2 + (number) 0)
|
|
(byte) idx#6 ← ++ (byte) idx#5
|
|
(byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
*((byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (number) 1)
|
|
(byte) idx#7 ← ++ (byte) idx#6
|
|
(byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
*((byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (number) 2)
|
|
(byte) idx#8 ← ++ (byte) idx#7
|
|
*((byte*) SCREEN + (byte) idx#8) ← (byte) ' '
|
|
(byte) idx#9 ← ++ (byte) idx#8
|
|
to:print_person::@return
|
|
print_person::@return: scope:[print_person] from print_person
|
|
(byte) idx#16 ← phi( print_person/(byte) idx#9 )
|
|
(byte) idx#10 ← (byte) idx#16
|
|
return
|
|
to:@return
|
|
@2: scope:[] from @1
|
|
(byte) idx#19 ← phi( @1/(byte) idx#3 )
|
|
call main
|
|
to:@3
|
|
@3: scope:[] from @2
|
|
(byte) idx#17 ← phi( @2/(byte) idx#2 )
|
|
(byte) idx#11 ← (byte) idx#17
|
|
to:@end
|
|
@end: scope:[] from @3
|
|
|
|
SYMBOL TABLE SSA
|
|
(const string) $0 = (string) "jgr"
|
|
(const string) $1 = (string) "hbg"
|
|
(label) @1
|
|
(label) @2
|
|
(label) @3
|
|
(label) @begin
|
|
(label) @end
|
|
(const byte) OFFSET_STRUCT_PERSON_ID = (byte) 0
|
|
(const byte) OFFSET_STRUCT_PERSON_INITIALS = (byte) 1
|
|
(byte) Person::id
|
|
(byte[4]) Person::initials
|
|
(byte*) SCREEN
|
|
(const byte) SIZEOF_STRUCT_PERSON = (byte) 5
|
|
(byte) idx
|
|
(byte) idx#0
|
|
(byte) idx#1
|
|
(byte) idx#10
|
|
(byte) idx#11
|
|
(byte) idx#12
|
|
(byte) idx#13
|
|
(byte) idx#14
|
|
(byte) idx#15
|
|
(byte) idx#16
|
|
(byte) idx#17
|
|
(byte) idx#18
|
|
(byte) idx#19
|
|
(byte) idx#2
|
|
(byte) idx#3
|
|
(byte) idx#4
|
|
(byte) idx#5
|
|
(byte) idx#6
|
|
(byte) idx#7
|
|
(byte) idx#8
|
|
(byte) idx#9
|
|
(void()) main()
|
|
(label) main::@1
|
|
(label) main::@2
|
|
(label) main::@return
|
|
(struct Person*) main::person
|
|
(struct Person*) main::person#0
|
|
(struct Person*) main::person#1
|
|
(struct Person*) main::person#2
|
|
(struct Person[]) persons
|
|
(void()) print_person((struct Person*) print_person::person)
|
|
(byte~) print_person::$0
|
|
(byte*) print_person::$1
|
|
(byte[4]) print_person::$2
|
|
(byte[4]) print_person::$3
|
|
(byte[4]) print_person::$4
|
|
(label) print_person::@return
|
|
(struct Person*) print_person::person
|
|
(struct Person*) print_person::person#0
|
|
(struct Person*) print_person::person#1
|
|
(struct Person*) print_person::person#2
|
|
|
|
Adding number conversion cast (unumber) 0 in (byte) idx#3 ← (number) 0
|
|
Adding number conversion cast (unumber) 0 in *((byte*) SCREEN + (byte) idx#5) ← *((byte[4]) print_person::$2 + (number) 0)
|
|
Adding number conversion cast (unumber) 1 in *((byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (number) 1)
|
|
Adding number conversion cast (unumber) 2 in *((byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (number) 2)
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Added casts to value list in (struct Person[]) persons ← (struct Person[]){ (struct Person){ (byte)(number) 1, (const string) $0 }, (struct Person){ (byte)(number) 8, (const string) $1 } }
|
|
Successful SSA optimization PassNAddInitializerValueListTypeCasts
|
|
Inlining cast (byte*) SCREEN ← (byte*)(number) $400
|
|
Inlining cast (byte) idx#3 ← (unumber)(number) 0
|
|
Successful SSA optimization Pass2InlineCast
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 8
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 2
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 0
|
|
Finalized unsigned number type (byte) 0
|
|
Finalized unsigned number type (byte) 1
|
|
Finalized unsigned number type (byte) 2
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias (struct Person*) main::person#0 = (struct Person*) main::person#2
|
|
Alias (byte) idx#0 = (byte) idx#12
|
|
Alias (byte) idx#1 = (byte) idx#13 (byte) idx#14 (byte) idx#2
|
|
Alias (byte) idx#10 = (byte) idx#16 (byte) idx#9
|
|
Alias (byte) idx#19 = (byte) idx#3
|
|
Alias (byte) idx#11 = (byte) idx#17
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values (byte) idx#18 (byte) idx#19
|
|
Identical Phi Values (byte) idx#0 (byte) idx#10
|
|
Identical Phi Values (byte) idx#1 (byte) idx#10
|
|
Identical Phi Values (byte) idx#11 (byte) idx#1
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Identified constant from value list (struct Person) { id: (byte) 1, initials: (const string) $0 }
|
|
Identified constant from value list (struct Person) { id: (byte) 8, initials: (const string) $1 }
|
|
Successful SSA optimization Pass2ConstantInitializerValueLists
|
|
Identified constant from value list (struct Person[]) { { id: (byte) 1, initials: (const string) $0 }, { id: (byte) 8, initials: (const string) $1 } }
|
|
Successful SSA optimization Pass2ConstantInitializerValueLists
|
|
Constant (const struct Person[]) persons = { { id: 1, initials: $0 }, { id: 8, initials: $1 } }
|
|
Constant (const byte*) SCREEN = (byte*) 1024
|
|
Constant (const byte) idx#19 = 0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Constant (const struct Person*) main::person#0 = persons
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Constant (const struct Person*) print_person::person#0 = main::person#0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Converting *(pointer+n) to pointer[n] [19] (byte~) print_person::$0 ← (byte) '0' + *((byte*) print_person::$1) -- *((byte*)print_person::person#2 + OFFSET_STRUCT_PERSON_ID)
|
|
Successful SSA optimization Pass2InlineDerefIdx
|
|
Simplifying expression containing zero (byte*)print_person::person#2 in [18] (byte*) print_person::$1 ← (byte*)(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_ID
|
|
Simplifying expression containing zero (byte*)print_person::person#2 in [19] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_ID)
|
|
Simplifying expression containing zero print_person::$2 in [25] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4]) print_person::$2 + (byte) 0)
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Eliminating unused variable (byte*) print_person::$1 and assignment [6] (byte*) print_person::$1 ← (byte*)(struct Person*) print_person::person#2
|
|
Eliminating unused constant (const byte) OFFSET_STRUCT_PERSON_ID
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
Constant right-side identified [1] (struct Person*) main::person#1 ← (const struct Person*) main::person#0 + (const byte) SIZEOF_STRUCT_PERSON
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant (const struct Person*) main::person#1 = main::person#0+SIZEOF_STRUCT_PERSON
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Constant (const struct Person*) print_person::person#1 = main::person#1
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Converting *(pointer+n) to pointer[n] [12] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4]) print_person::$2) -- *((byte[4])print_person::person#2 + OFFSET_STRUCT_PERSON_INITIALS)
|
|
Successful SSA optimization Pass2InlineDerefIdx
|
|
Eliminating unused variable (byte[4]) print_person::$2 and assignment [9] (byte[4]) print_person::$2 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
Inlining constant with different constant siblings (const struct Person*) main::person#0
|
|
Inlining constant with var siblings (const struct Person*) print_person::person#0
|
|
Inlining constant with var siblings (const struct Person*) print_person::person#1
|
|
Inlining constant with var siblings (const byte) idx#19
|
|
Constant inlined idx#19 = (byte) 0
|
|
Constant inlined print_person::person#0 = (const struct Person[]) persons
|
|
Constant inlined main::person#0 = (const struct Person[]) persons
|
|
Constant inlined print_person::person#1 = (const struct Person*) main::person#1
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Constant array inlined into struct $0 = (string) "jgr"
|
|
Constant array inlined into struct $1 = (string) "hbg"
|
|
Successful SSA optimization Pass2ArrayInStructInlining
|
|
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 @3
|
|
Adding NOP phi() at start of @end
|
|
Adding NOP phi() at start of main
|
|
Adding NOP phi() at start of main::@2
|
|
CALL GRAPH
|
|
Calls in [] to main:3
|
|
Calls in [main] to print_person:7 print_person:9
|
|
|
|
Created 2 initial phi equivalence classes
|
|
Coalesced [8] idx#20 ← idx#10
|
|
Coalesced down to 2 phi equivalence classes
|
|
Culled Empty Block (label) @1
|
|
Culled Empty Block (label) @3
|
|
Culled Empty Block (label) main::@2
|
|
Renumbering block @2 to @1
|
|
Adding NOP phi() at start of @begin
|
|
Adding NOP phi() at start of @1
|
|
Adding NOP phi() at start of @end
|
|
Adding NOP phi() at start of main
|
|
Adding NOP phi() at start of main::@1
|
|
|
|
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()
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
[4] phi()
|
|
[5] call print_person
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
[6] phi()
|
|
[7] call print_person
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[8] return
|
|
to:@return
|
|
|
|
(void()) print_person((struct Person*) print_person::person)
|
|
print_person: scope:[print_person] from main main::@1
|
|
[9] (byte) idx#15 ← phi( main/(byte) 0 main::@1/(byte) idx#10 )
|
|
[9] (struct Person*) print_person::person#2 ← phi( main/(const struct Person[]) persons main::@1/(const struct Person*) main::person#1 )
|
|
[10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2)
|
|
[11] *((const byte*) SCREEN + (byte) idx#15) ← (byte~) print_person::$0
|
|
[12] (byte) idx#4 ← ++ (byte) idx#15
|
|
[13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' '
|
|
[14] (byte) idx#5 ← ++ (byte) idx#4
|
|
[15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS)
|
|
[16] (byte) idx#6 ← ++ (byte) idx#5
|
|
[17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
[18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1)
|
|
[19] (byte) idx#7 ← ++ (byte) idx#6
|
|
[20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS
|
|
[21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2)
|
|
[22] (byte) idx#8 ← ++ (byte) idx#7
|
|
[23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' '
|
|
[24] (byte) idx#10 ← ++ (byte) idx#8
|
|
to:print_person::@return
|
|
print_person::@return: scope:[print_person] from print_person
|
|
[25] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(byte) Person::id
|
|
(byte[4]) Person::initials
|
|
(byte) idx
|
|
(byte) idx#10 1.0
|
|
(byte) idx#15 2.0
|
|
(byte) idx#4 3.0
|
|
(byte) idx#5 3.0
|
|
(byte) idx#6 2.0
|
|
(byte) idx#7 2.0
|
|
(byte) idx#8 3.0
|
|
(void()) main()
|
|
(struct Person*) main::person
|
|
(void()) print_person((struct Person*) print_person::person)
|
|
(byte~) print_person::$0 4.0
|
|
(byte[4]) print_person::$3 4.0
|
|
(byte[4]) print_person::$4 4.0
|
|
(struct Person*) print_person::person
|
|
(struct Person*) print_person::person#2
|
|
|
|
Initial phi equivalence classes
|
|
[ print_person::person#2 ]
|
|
[ idx#15 idx#10 ]
|
|
Added variable print_person::$0 to zero page equivalence class [ print_person::$0 ]
|
|
Added variable idx#4 to zero page equivalence class [ idx#4 ]
|
|
Added variable idx#5 to zero page equivalence class [ idx#5 ]
|
|
Added variable idx#6 to zero page equivalence class [ idx#6 ]
|
|
Added variable print_person::$3 to zero page equivalence class [ print_person::$3 ]
|
|
Added variable idx#7 to zero page equivalence class [ idx#7 ]
|
|
Added variable print_person::$4 to zero page equivalence class [ print_person::$4 ]
|
|
Added variable idx#8 to zero page equivalence class [ idx#8 ]
|
|
Complete equivalence classes
|
|
[ print_person::person#2 ]
|
|
[ idx#15 idx#10 ]
|
|
[ print_person::$0 ]
|
|
[ idx#4 ]
|
|
[ idx#5 ]
|
|
[ idx#6 ]
|
|
[ print_person::$3 ]
|
|
[ idx#7 ]
|
|
[ print_person::$4 ]
|
|
[ idx#8 ]
|
|
Allocated zp ZP_WORD:2 [ print_person::person#2 ]
|
|
Allocated zp ZP_BYTE:4 [ idx#15 idx#10 ]
|
|
Allocated zp ZP_BYTE:5 [ print_person::$0 ]
|
|
Allocated zp ZP_BYTE:6 [ idx#4 ]
|
|
Allocated zp ZP_BYTE:7 [ idx#5 ]
|
|
Allocated zp ZP_BYTE:8 [ idx#6 ]
|
|
Allocated zp ZP_WORD:9 [ print_person::$3 ]
|
|
Allocated zp ZP_BYTE:11 [ idx#7 ]
|
|
Allocated zp ZP_WORD:12 [ print_person::$4 ]
|
|
Allocated zp ZP_BYTE:14 [ idx#8 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Example of a struct containing an array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(__bbegin)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_STRUCT_PERSON = 5
|
|
.const OFFSET_STRUCT_PERSON_INITIALS = 1
|
|
.label SCREEN = $400
|
|
.label idx = 6
|
|
.label idx_5 = 7
|
|
.label idx_6 = 8
|
|
.label idx_7 = $b
|
|
.label idx_8 = $e
|
|
.label idx_10 = 4
|
|
.label idx_15 = 4
|
|
// @begin
|
|
__bbegin:
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
__b1_from___bbegin:
|
|
jmp __b1
|
|
// @1
|
|
__b1:
|
|
// [2] call main
|
|
// [4] phi from @1 to main [phi:@1->main]
|
|
main_from___b1:
|
|
jsr main
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
__bend_from___b1:
|
|
jmp __bend
|
|
// @end
|
|
__bend:
|
|
// main
|
|
main: {
|
|
.label person = persons+SIZEOF_STRUCT_PERSON
|
|
// [5] call print_person
|
|
// [9] phi from main to print_person [phi:main->print_person]
|
|
print_person_from_main:
|
|
// [9] phi (byte) idx#15 = (byte) 0 [phi:main->print_person#0] -- vbuz1=vbuc1
|
|
lda #0
|
|
sta.z idx_15
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person[]) persons [phi:main->print_person#1] -- pssz1=pssc1
|
|
lda #<persons
|
|
sta.z print_person.person
|
|
lda #>persons
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call print_person
|
|
// [9] phi from main::@1 to print_person [phi:main::@1->print_person]
|
|
print_person_from___b1:
|
|
// [9] phi (byte) idx#15 = (byte) idx#10 [phi:main::@1->print_person#0] -- register_copy
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person*) main::person#1 [phi:main::@1->print_person#1] -- pssz1=pssc1
|
|
lda #<person
|
|
sta.z print_person.person
|
|
lda #>person
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [8] return
|
|
rts
|
|
}
|
|
// print_person
|
|
// print_person(struct Person* zeropage(2) person)
|
|
print_person: {
|
|
.label __0 = 5
|
|
.label __3 = 9
|
|
.label __4 = $c
|
|
.label person = 2
|
|
// [10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2) -- vbuz1=vbuc1_plus__deref_pbuz2
|
|
lda #'0'
|
|
clc
|
|
ldy #0
|
|
adc (person),y
|
|
sta.z __0
|
|
// [11] *((const byte*) SCREEN + (byte) idx#15) ← (byte~) print_person::$0 -- pbuc1_derefidx_vbuz1=vbuz2
|
|
lda.z __0
|
|
ldy.z idx_15
|
|
sta SCREEN,y
|
|
// [12] (byte) idx#4 ← ++ (byte) idx#15 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx_15
|
|
iny
|
|
sty.z idx
|
|
// [13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' ' -- pbuc1_derefidx_vbuz1=vbuc2
|
|
lda #' '
|
|
ldy.z idx
|
|
sta SCREEN,y
|
|
// [14] (byte) idx#5 ← ++ (byte) idx#4 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx
|
|
iny
|
|
sty.z idx_5
|
|
// [15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS) -- pbuc1_derefidx_vbuz1=pbuz2_derefidx_vbuc2
|
|
ldx.z idx_5
|
|
ldy #OFFSET_STRUCT_PERSON_INITIALS
|
|
lda (person),y
|
|
sta SCREEN,x
|
|
// [16] (byte) idx#6 ← ++ (byte) idx#5 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx_5
|
|
iny
|
|
sty.z idx_6
|
|
// [17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz2_plus_vbuc1
|
|
lda #OFFSET_STRUCT_PERSON_INITIALS
|
|
clc
|
|
adc.z person
|
|
sta.z __3
|
|
lda #0
|
|
adc.z person+1
|
|
sta.z __3+1
|
|
// [18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1) -- pbuc1_derefidx_vbuz1=pbuz2_derefidx_vbuc2
|
|
ldx.z idx_6
|
|
ldy #1
|
|
lda (__3),y
|
|
sta SCREEN,x
|
|
// [19] (byte) idx#7 ← ++ (byte) idx#6 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx_6
|
|
iny
|
|
sty.z idx_7
|
|
// [20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz2_plus_vbuc1
|
|
lda #OFFSET_STRUCT_PERSON_INITIALS
|
|
clc
|
|
adc.z person
|
|
sta.z __4
|
|
lda #0
|
|
adc.z person+1
|
|
sta.z __4+1
|
|
// [21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2) -- pbuc1_derefidx_vbuz1=pbuz2_derefidx_vbuc2
|
|
ldx.z idx_7
|
|
ldy #2
|
|
lda (__4),y
|
|
sta SCREEN,x
|
|
// [22] (byte) idx#8 ← ++ (byte) idx#7 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx_7
|
|
iny
|
|
sty.z idx_8
|
|
// [23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' ' -- pbuc1_derefidx_vbuz1=vbuc2
|
|
lda #' '
|
|
ldy.z idx_8
|
|
sta SCREEN,y
|
|
// [24] (byte) idx#10 ← ++ (byte) idx#8 -- vbuz1=_inc_vbuz2
|
|
ldy.z idx_8
|
|
iny
|
|
sty.z idx_10
|
|
jmp __breturn
|
|
// print_person::@return
|
|
__breturn:
|
|
// [25] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 1
|
|
.text "jgr"
|
|
.byte 0, 8
|
|
.text "hbg"
|
|
.byte 0
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2) [ print_person::person#2 idx#15 print_person::$0 ] ( main:2::print_person:5 [ print_person::person#2 idx#15 print_person::$0 ] main:2::print_person:7 [ print_person::person#2 idx#15 print_person::$0 ] ) always clobbers reg byte a reg byte y
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:4 [ idx#15 idx#10 ]
|
|
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:4 [ idx#15 idx#10 ]
|
|
Statement [13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' ' [ print_person::person#2 idx#4 ] ( main:2::print_person:5 [ print_person::person#2 idx#4 ] main:2::print_person:7 [ print_person::person#2 idx#4 ] ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:6 [ idx#4 ]
|
|
Statement [15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS) [ print_person::person#2 idx#5 ] ( main:2::print_person:5 [ print_person::person#2 idx#5 ] main:2::print_person:7 [ print_person::person#2 idx#5 ] ) always clobbers reg byte a reg byte y
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:7 [ idx#5 ]
|
|
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:7 [ idx#5 ]
|
|
Statement [17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS [ print_person::person#2 idx#6 print_person::$3 ] ( main:2::print_person:5 [ print_person::person#2 idx#6 print_person::$3 ] main:2::print_person:7 [ print_person::person#2 idx#6 print_person::$3 ] ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:8 [ idx#6 ]
|
|
Statement [18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1) [ print_person::person#2 idx#6 ] ( main:2::print_person:5 [ print_person::person#2 idx#6 ] main:2::print_person:7 [ print_person::person#2 idx#6 ] ) always clobbers reg byte a reg byte y
|
|
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:8 [ idx#6 ]
|
|
Statement [20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS [ idx#7 print_person::$4 ] ( main:2::print_person:5 [ idx#7 print_person::$4 ] main:2::print_person:7 [ idx#7 print_person::$4 ] ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:11 [ idx#7 ]
|
|
Statement [21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2) [ idx#7 ] ( main:2::print_person:5 [ idx#7 ] main:2::print_person:7 [ idx#7 ] ) always clobbers reg byte a reg byte y
|
|
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:11 [ idx#7 ]
|
|
Statement [23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' ' [ idx#8 ] ( main:2::print_person:5 [ idx#8 ] main:2::print_person:7 [ idx#8 ] ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:14 [ idx#8 ]
|
|
Statement [10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2) [ print_person::person#2 idx#15 print_person::$0 ] ( main:2::print_person:5 [ print_person::person#2 idx#15 print_person::$0 ] main:2::print_person:7 [ print_person::person#2 idx#15 print_person::$0 ] ) always clobbers reg byte a reg byte y
|
|
Statement [13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' ' [ print_person::person#2 idx#4 ] ( main:2::print_person:5 [ print_person::person#2 idx#4 ] main:2::print_person:7 [ print_person::person#2 idx#4 ] ) always clobbers reg byte a
|
|
Statement [15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS) [ print_person::person#2 idx#5 ] ( main:2::print_person:5 [ print_person::person#2 idx#5 ] main:2::print_person:7 [ print_person::person#2 idx#5 ] ) always clobbers reg byte a reg byte y
|
|
Statement [17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS [ print_person::person#2 idx#6 print_person::$3 ] ( main:2::print_person:5 [ print_person::person#2 idx#6 print_person::$3 ] main:2::print_person:7 [ print_person::person#2 idx#6 print_person::$3 ] ) always clobbers reg byte a
|
|
Statement [18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1) [ print_person::person#2 idx#6 ] ( main:2::print_person:5 [ print_person::person#2 idx#6 ] main:2::print_person:7 [ print_person::person#2 idx#6 ] ) always clobbers reg byte a reg byte y
|
|
Statement [20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS [ idx#7 print_person::$4 ] ( main:2::print_person:5 [ idx#7 print_person::$4 ] main:2::print_person:7 [ idx#7 print_person::$4 ] ) always clobbers reg byte a
|
|
Statement [21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2) [ idx#7 ] ( main:2::print_person:5 [ idx#7 ] main:2::print_person:7 [ idx#7 ] ) always clobbers reg byte a reg byte y
|
|
Statement [23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' ' [ idx#8 ] ( main:2::print_person:5 [ idx#8 ] main:2::print_person:7 [ idx#8 ] ) always clobbers reg byte a
|
|
Potential registers zp ZP_WORD:2 [ print_person::person#2 ] : zp ZP_WORD:2 ,
|
|
Potential registers zp ZP_BYTE:4 [ idx#15 idx#10 ] : zp ZP_BYTE:4 , reg byte x ,
|
|
Potential registers zp ZP_BYTE:5 [ print_person::$0 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp ZP_BYTE:6 [ idx#4 ] : zp ZP_BYTE:6 , reg byte x , reg byte y ,
|
|
Potential registers zp ZP_BYTE:7 [ idx#5 ] : zp ZP_BYTE:7 , reg byte x ,
|
|
Potential registers zp ZP_BYTE:8 [ idx#6 ] : zp ZP_BYTE:8 , reg byte x ,
|
|
Potential registers zp ZP_WORD:9 [ print_person::$3 ] : zp ZP_WORD:9 ,
|
|
Potential registers zp ZP_BYTE:11 [ idx#7 ] : zp ZP_BYTE:11 , reg byte x ,
|
|
Potential registers zp ZP_WORD:12 [ print_person::$4 ] : zp ZP_WORD:12 ,
|
|
Potential registers zp ZP_BYTE:14 [ idx#8 ] : zp ZP_BYTE:14 , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [] 3: zp ZP_BYTE:4 [ idx#15 idx#10 ] 3: zp ZP_BYTE:6 [ idx#4 ] 3: zp ZP_BYTE:7 [ idx#5 ] 3: zp ZP_BYTE:14 [ idx#8 ] 2: zp ZP_BYTE:8 [ idx#6 ] 2: zp ZP_BYTE:11 [ idx#7 ]
|
|
Uplift Scope [print_person] 4: zp ZP_BYTE:5 [ print_person::$0 ] 4: zp ZP_WORD:9 [ print_person::$3 ] 4: zp ZP_WORD:12 [ print_person::$4 ] 0: zp ZP_WORD:2 [ print_person::person#2 ]
|
|
Uplift Scope [Person]
|
|
Uplift Scope [main]
|
|
|
|
Uplifting [] best 196 combination reg byte x [ idx#15 idx#10 ] reg byte x [ idx#4 ] reg byte x [ idx#5 ] reg byte x [ idx#8 ] reg byte x [ idx#6 ] zp ZP_BYTE:11 [ idx#7 ]
|
|
Limited combination testing to 100 combinations of 144 possible.
|
|
Uplifting [print_person] best 190 combination reg byte a [ print_person::$0 ] zp ZP_WORD:9 [ print_person::$3 ] zp ZP_WORD:12 [ print_person::$4 ] zp ZP_WORD:2 [ print_person::person#2 ]
|
|
Uplifting [Person] best 190 combination
|
|
Uplifting [main] best 190 combination
|
|
Attempting to uplift remaining variables inzp ZP_BYTE:11 [ idx#7 ]
|
|
Uplifting [] best 181 combination reg byte x [ idx#7 ]
|
|
Coalescing zero page register [ zp ZP_WORD:2 [ print_person::person#2 ] ] with [ zp ZP_WORD:12 [ print_person::$4 ] ] - score: 1
|
|
Allocated (was zp ZP_WORD:9) zp ZP_WORD:4 [ print_person::$3 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Example of a struct containing an array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(__bbegin)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_STRUCT_PERSON = 5
|
|
.const OFFSET_STRUCT_PERSON_INITIALS = 1
|
|
.label SCREEN = $400
|
|
// @begin
|
|
__bbegin:
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
__b1_from___bbegin:
|
|
jmp __b1
|
|
// @1
|
|
__b1:
|
|
// [2] call main
|
|
// [4] phi from @1 to main [phi:@1->main]
|
|
main_from___b1:
|
|
jsr main
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
__bend_from___b1:
|
|
jmp __bend
|
|
// @end
|
|
__bend:
|
|
// main
|
|
main: {
|
|
.label person = persons+SIZEOF_STRUCT_PERSON
|
|
// [5] call print_person
|
|
// [9] phi from main to print_person [phi:main->print_person]
|
|
print_person_from_main:
|
|
// [9] phi (byte) idx#15 = (byte) 0 [phi:main->print_person#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person[]) persons [phi:main->print_person#1] -- pssz1=pssc1
|
|
lda #<persons
|
|
sta.z print_person.person
|
|
lda #>persons
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call print_person
|
|
// [9] phi from main::@1 to print_person [phi:main::@1->print_person]
|
|
print_person_from___b1:
|
|
// [9] phi (byte) idx#15 = (byte) idx#10 [phi:main::@1->print_person#0] -- register_copy
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person*) main::person#1 [phi:main::@1->print_person#1] -- pssz1=pssc1
|
|
lda #<person
|
|
sta.z print_person.person
|
|
lda #>person
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [8] return
|
|
rts
|
|
}
|
|
// print_person
|
|
// print_person(struct Person* zeropage(2) person)
|
|
print_person: {
|
|
.label __3 = 4
|
|
.label __4 = 2
|
|
.label person = 2
|
|
// [10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2) -- vbuaa=vbuc1_plus__deref_pbuz1
|
|
lda #'0'
|
|
clc
|
|
ldy #0
|
|
adc (person),y
|
|
// [11] *((const byte*) SCREEN + (byte) idx#15) ← (byte~) print_person::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
|
sta SCREEN,x
|
|
// [12] (byte) idx#4 ← ++ (byte) idx#15 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
|
|
lda #' '
|
|
sta SCREEN,x
|
|
// [14] (byte) idx#5 ← ++ (byte) idx#4 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #OFFSET_STRUCT_PERSON_INITIALS
|
|
lda (person),y
|
|
sta SCREEN,x
|
|
// [16] (byte) idx#6 ← ++ (byte) idx#5 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz2_plus_vbuc1
|
|
lda #OFFSET_STRUCT_PERSON_INITIALS
|
|
clc
|
|
adc.z person
|
|
sta.z __3
|
|
lda #0
|
|
adc.z person+1
|
|
sta.z __3+1
|
|
// [18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #1
|
|
lda (__3),y
|
|
sta SCREEN,x
|
|
// [19] (byte) idx#7 ← ++ (byte) idx#6 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz1_plus_vbuc1
|
|
lda #OFFSET_STRUCT_PERSON_INITIALS
|
|
clc
|
|
adc.z __4
|
|
sta.z __4
|
|
bcc !+
|
|
inc.z __4+1
|
|
!:
|
|
// [21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #2
|
|
lda (__4),y
|
|
sta SCREEN,x
|
|
// [22] (byte) idx#8 ← ++ (byte) idx#7 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
|
|
lda #' '
|
|
sta SCREEN,x
|
|
// [24] (byte) idx#10 ← ++ (byte) idx#8 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
jmp __breturn
|
|
// print_person::@return
|
|
__breturn:
|
|
// [25] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 1
|
|
.text "jgr"
|
|
.byte 0, 8
|
|
.text "hbg"
|
|
.byte 0
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Replacing instruction lda #OFFSET_STRUCT_PERSON_INITIALS with TYA
|
|
Replacing label __bbegin with __b1
|
|
Removing instruction __bbegin:
|
|
Removing instruction __b1_from___bbegin:
|
|
Removing instruction main_from___b1:
|
|
Removing instruction __bend_from___b1:
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction print_person_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bend:
|
|
Removing instruction print_person_from_main:
|
|
Removing instruction __b1:
|
|
Removing instruction __breturn:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Updating BasicUpstart to call main directly
|
|
Removing instruction jsr main
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
Removing instruction __b1:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
(label) @1
|
|
(label) @begin
|
|
(label) @end
|
|
(const byte) OFFSET_STRUCT_PERSON_INITIALS OFFSET_STRUCT_PERSON_INITIALS = (byte) 1
|
|
(byte) Person::id
|
|
(byte[4]) Person::initials
|
|
(const byte*) SCREEN SCREEN = (byte*) 1024
|
|
(const byte) SIZEOF_STRUCT_PERSON SIZEOF_STRUCT_PERSON = (byte) 5
|
|
(byte) idx
|
|
(byte) idx#10 reg byte x 1.0
|
|
(byte) idx#15 reg byte x 2.0
|
|
(byte) idx#4 reg byte x 3.0
|
|
(byte) idx#5 reg byte x 3.0
|
|
(byte) idx#6 reg byte x 2.0
|
|
(byte) idx#7 reg byte x 2.0
|
|
(byte) idx#8 reg byte x 3.0
|
|
(void()) main()
|
|
(label) main::@1
|
|
(label) main::@return
|
|
(struct Person*) main::person
|
|
(const struct Person*) main::person#1 person = (const struct Person[]) persons+(const byte) SIZEOF_STRUCT_PERSON
|
|
(const struct Person[]) persons persons = { { id: (byte) 1, initials: (string) "jgr" }, { id: (byte) 8, initials: (string) "hbg" } }
|
|
(void()) print_person((struct Person*) print_person::person)
|
|
(byte~) print_person::$0 reg byte a 4.0
|
|
(byte[4]) print_person::$3 $3 zp ZP_WORD:4 4.0
|
|
(byte[4]) print_person::$4 $4 zp ZP_WORD:2 4.0
|
|
(label) print_person::@return
|
|
(struct Person*) print_person::person
|
|
(struct Person*) print_person::person#2 person zp ZP_WORD:2
|
|
|
|
zp ZP_WORD:2 [ print_person::person#2 print_person::$4 ]
|
|
reg byte x [ idx#15 idx#10 ]
|
|
reg byte a [ print_person::$0 ]
|
|
reg byte x [ idx#4 ]
|
|
reg byte x [ idx#5 ]
|
|
reg byte x [ idx#6 ]
|
|
zp ZP_WORD:4 [ print_person::$3 ]
|
|
reg byte x [ idx#7 ]
|
|
reg byte x [ idx#8 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 159
|
|
|
|
// File Comments
|
|
// Example of a struct containing an array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_STRUCT_PERSON = 5
|
|
.const OFFSET_STRUCT_PERSON_INITIALS = 1
|
|
.label SCREEN = $400
|
|
// @begin
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
// @1
|
|
// [2] call main
|
|
// [4] phi from @1 to main [phi:@1->main]
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
// @end
|
|
// main
|
|
main: {
|
|
.label person = persons+SIZEOF_STRUCT_PERSON
|
|
// print_person(person)
|
|
// [5] call print_person
|
|
// [9] phi from main to print_person [phi:main->print_person]
|
|
// [9] phi (byte) idx#15 = (byte) 0 [phi:main->print_person#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person[]) persons [phi:main->print_person#1] -- pssz1=pssc1
|
|
lda #<persons
|
|
sta.z print_person.person
|
|
lda #>persons
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
// main::@1
|
|
// print_person(person)
|
|
// [7] call print_person
|
|
// [9] phi from main::@1 to print_person [phi:main::@1->print_person]
|
|
// [9] phi (byte) idx#15 = (byte) idx#10 [phi:main::@1->print_person#0] -- register_copy
|
|
// [9] phi (struct Person*) print_person::person#2 = (const struct Person*) main::person#1 [phi:main::@1->print_person#1] -- pssz1=pssc1
|
|
lda #<person
|
|
sta.z print_person.person
|
|
lda #>person
|
|
sta.z print_person.person+1
|
|
jsr print_person
|
|
// main::@return
|
|
// }
|
|
// [8] return
|
|
rts
|
|
}
|
|
// print_person
|
|
// print_person(struct Person* zeropage(2) person)
|
|
print_person: {
|
|
.label __3 = 4
|
|
.label __4 = 2
|
|
.label person = 2
|
|
// '0'+person->id
|
|
// [10] (byte~) print_person::$0 ← (byte) '0' + *((byte*)(struct Person*) print_person::person#2) -- vbuaa=vbuc1_plus__deref_pbuz1
|
|
lda #'0'
|
|
clc
|
|
ldy #0
|
|
adc (person),y
|
|
// SCREEN[idx++] = '0'+person->id
|
|
// [11] *((const byte*) SCREEN + (byte) idx#15) ← (byte~) print_person::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = '0'+person->id;
|
|
// [12] (byte) idx#4 ← ++ (byte) idx#15 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// SCREEN[idx++] = ' '
|
|
// [13] *((const byte*) SCREEN + (byte) idx#4) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
|
|
lda #' '
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = ' ';
|
|
// [14] (byte) idx#5 ← ++ (byte) idx#4 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// SCREEN[idx++] = person->initials[0]
|
|
// [15] *((const byte*) SCREEN + (byte) idx#5) ← *((byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #OFFSET_STRUCT_PERSON_INITIALS
|
|
lda (person),y
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = person->initials[0];
|
|
// [16] (byte) idx#6 ← ++ (byte) idx#5 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// SCREEN[idx++] = person->initials[1]
|
|
// [17] (byte[4]) print_person::$3 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz2_plus_vbuc1
|
|
tya
|
|
clc
|
|
adc.z person
|
|
sta.z __3
|
|
lda #0
|
|
adc.z person+1
|
|
sta.z __3+1
|
|
// [18] *((const byte*) SCREEN + (byte) idx#6) ← *((byte[4]) print_person::$3 + (byte) 1) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #1
|
|
lda (__3),y
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = person->initials[1];
|
|
// [19] (byte) idx#7 ← ++ (byte) idx#6 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// SCREEN[idx++] = person->initials[2]
|
|
// [20] (byte[4]) print_person::$4 ← (byte[4])(struct Person*) print_person::person#2 + (const byte) OFFSET_STRUCT_PERSON_INITIALS -- pbuz1=pbuz1_plus_vbuc1
|
|
lda #OFFSET_STRUCT_PERSON_INITIALS
|
|
clc
|
|
adc.z __4
|
|
sta.z __4
|
|
bcc !+
|
|
inc.z __4+1
|
|
!:
|
|
// [21] *((const byte*) SCREEN + (byte) idx#7) ← *((byte[4]) print_person::$4 + (byte) 2) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
|
|
ldy #2
|
|
lda (__4),y
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = person->initials[2];
|
|
// [22] (byte) idx#8 ← ++ (byte) idx#7 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// SCREEN[idx++] = ' '
|
|
// [23] *((const byte*) SCREEN + (byte) idx#8) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
|
|
lda #' '
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = ' ';
|
|
// [24] (byte) idx#10 ← ++ (byte) idx#8 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// print_person::@return
|
|
// }
|
|
// [25] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 1
|
|
.text "jgr"
|
|
.byte 0, 8
|
|
.text "hbg"
|
|
.byte 0
|
|
|