mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-07 06:30:04 +00:00
341 lines
12 KiB
Plaintext
341 lines
12 KiB
Plaintext
Fixing struct type size struct Person to 16
|
|
Fixing struct type size struct Person to 16
|
|
Fixing struct type SIZE_OF struct Person to 16
|
|
Fixing struct type SIZE_OF struct Person to 16
|
|
Fixing pointer increment (struct Person*) main::person ← ++ (struct Person*) main::person
|
|
Replacing struct member reference *((struct Person*) main::person).name with member unwinding reference (byte*~) main::$0
|
|
Replacing struct member reference *((struct Person*) main::person).name with member unwinding reference (byte*~) main::$1
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
to:@1
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
(struct Person*) main::person#0 ← (const struct Person*) persons
|
|
(byte*~) main::$0 ← (byte*)(struct Person*) main::person#0 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
*((const byte*) main::SCREEN + (number) 0) ← *((byte*~) main::$0 + (number) 2)
|
|
(struct Person*) main::person#1 ← (struct Person*) main::person#0 + (const byte) SIZEOF_STRUCT_PERSON
|
|
(byte*~) main::$1 ← (byte*)(struct Person*) main::person#1 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
*((const byte*) main::SCREEN + (number) 1) ← *((byte*~) main::$1 + (number) 2)
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
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
|
|
(const byte) OFFSET_STRUCT_PERSON_NAME = (byte) 1
|
|
(word) Person::age
|
|
(byte) Person::id
|
|
(const byte*) Person::name[(number) $d] = { fill( $d, 0) }
|
|
(const byte) SIZEOF_STRUCT_PERSON = (byte) $10
|
|
(void()) main()
|
|
(byte*~) main::$0
|
|
(byte*~) main::$1
|
|
(label) main::@return
|
|
(const byte*) main::SCREEN = (byte*)(number) $400
|
|
(struct Person*) main::person
|
|
(struct Person*) main::person#0
|
|
(struct Person*) main::person#1
|
|
(const struct Person*) persons[(number) 2] = { { id: (byte) 7, name: (string) "jesper", age: (word) $141 }, { id: (byte) 9, name: (string) "henry", age: (word) $7b } }
|
|
|
|
Adding number conversion cast (unumber) 2 in *((const byte*) main::SCREEN + (number) 0) ← *((byte*~) main::$0 + (number) 2)
|
|
Adding number conversion cast (unumber) 0 in *((const byte*) main::SCREEN + (number) 0) ← *((byte*~) main::$0 + (unumber)(number) 2)
|
|
Adding number conversion cast (unumber) 2 in *((const byte*) main::SCREEN + (number) 1) ← *((byte*~) main::$1 + (number) 2)
|
|
Adding number conversion cast (unumber) 1 in *((const byte*) main::SCREEN + (number) 1) ← *((byte*~) main::$1 + (unumber)(number) 2)
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
Simplifying constant integer cast 2
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 2
|
|
Simplifying constant integer cast 1
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 2
|
|
Finalized unsigned number type (byte) 0
|
|
Finalized unsigned number type (byte) 2
|
|
Finalized unsigned number type (byte) 1
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Constant (const struct Person*) main::person#0 = persons
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Constant value identified (byte*)main::person#0 in [1] (byte*~) main::$0 ← (byte*)(const struct Person*) main::person#0 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Successful SSA optimization Pass2ConstantValues
|
|
Simplifying expression containing zero main::SCREEN in [2] *((const byte*) main::SCREEN + (byte) 0) ← *((byte*~) main::$0 + (byte) 2)
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Constant right-side identified [0] (byte*~) main::$0 ← (byte*)(const struct Person*) main::person#0 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Constant right-side identified [2] (struct Person*) main::person#1 ← (const struct Person*) main::person#0 + (const byte) SIZEOF_STRUCT_PERSON
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant (const byte*) main::$0 = (byte*)main::person#0+OFFSET_STRUCT_PERSON_NAME
|
|
Constant (const struct Person*) main::person#1 = main::person#0+SIZEOF_STRUCT_PERSON
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Constant value identified (byte*)main::person#1 in [3] (byte*~) main::$1 ← (byte*)(const struct Person*) main::person#1 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Successful SSA optimization Pass2ConstantValues
|
|
Constant right-side identified [1] (byte*~) main::$1 ← (byte*)(const struct Person*) main::person#1 + (const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant (const byte*) main::$1 = (byte*)main::person#1+OFFSET_STRUCT_PERSON_NAME
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Inlining constant with different constant siblings (const struct Person*) main::person#0
|
|
Constant inlined main::$1 = (byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Constant inlined main::person#0 = (const struct Person*) persons
|
|
Constant inlined main::$0 = (byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Consolidated array index constant in *((byte*)persons+OFFSET_STRUCT_PERSON_NAME+2)
|
|
Consolidated array index constant in *((byte*)main::person#1+OFFSET_STRUCT_PERSON_NAME+2)
|
|
Consolidated array index constant in *(main::SCREEN+1)
|
|
Successful SSA optimization Pass2ConstantAdditionElimination
|
|
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 0 initial phi equivalence classes
|
|
Coalesced down to 0 phi equivalence classes
|
|
Culled Empty Block (label) @2
|
|
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()
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
[4] *((const byte*) main::SCREEN) ← *((byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2)
|
|
[5] *((const byte*) main::SCREEN+(byte) 1) ← *((byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2)
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
[6] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(word) Person::age
|
|
(byte) Person::id
|
|
(void()) main()
|
|
(struct Person*) main::person
|
|
|
|
Initial phi equivalence classes
|
|
Complete equivalence classes
|
|
|
|
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 = $10
|
|
.const OFFSET_STRUCT_PERSON_NAME = 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 person = persons+SIZEOF_STRUCT_PERSON
|
|
// [4] *((const byte*) main::SCREEN) ← *((byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda persons+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN
|
|
// [5] *((const byte*) main::SCREEN+(byte) 1) ← *((byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda person+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN+1
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [6] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 7
|
|
.text "jesper"
|
|
.byte 0
|
|
.fill 6, 0
|
|
.word $141
|
|
.byte 9
|
|
.text "henry"
|
|
.byte 0
|
|
.fill 7, 0
|
|
.word $7b
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [4] *((const byte*) main::SCREEN) ← *((byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) [ ] ( main:2 [ ] ) always clobbers reg byte a
|
|
Statement [5] *((const byte*) main::SCREEN+(byte) 1) ← *((byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) [ ] ( main:2 [ ] ) always clobbers reg byte a
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [Person]
|
|
Uplift Scope [main]
|
|
Uplift Scope []
|
|
|
|
Uplifting [Person] best 37 combination
|
|
Uplifting [main] best 37 combination
|
|
Uplifting [] best 37 combination
|
|
|
|
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 = $10
|
|
.const OFFSET_STRUCT_PERSON_NAME = 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 person = persons+SIZEOF_STRUCT_PERSON
|
|
// [4] *((const byte*) main::SCREEN) ← *((byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda persons+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN
|
|
// [5] *((const byte*) main::SCREEN+(byte) 1) ← *((byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda person+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN+1
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [6] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 7
|
|
.text "jesper"
|
|
.byte 0
|
|
.fill 6, 0
|
|
.word $141
|
|
.byte 9
|
|
.text "henry"
|
|
.byte 0
|
|
.fill 7, 0
|
|
.word $7b
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Replacing label __bbegin with __b1
|
|
Removing instruction __bbegin:
|
|
Removing instruction __b1_from___bbegin:
|
|
Removing instruction __bend_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bend:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Updating BasicUpstart to call main directly
|
|
Removing instruction jsr main
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
Removing instruction __b1:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
(label) @1
|
|
(label) @begin
|
|
(label) @end
|
|
(const byte) OFFSET_STRUCT_PERSON_NAME = (byte) 1
|
|
(word) Person::age
|
|
(byte) Person::id
|
|
(const byte*) Person::name[(number) $d] = { fill( $d, 0) }
|
|
(const byte) SIZEOF_STRUCT_PERSON = (byte) $10
|
|
(void()) main()
|
|
(label) main::@return
|
|
(const byte*) main::SCREEN = (byte*) 1024
|
|
(struct Person*) main::person
|
|
(const struct Person*) main::person#1 person = (const struct Person*) persons+(const byte) SIZEOF_STRUCT_PERSON
|
|
(const struct Person*) persons[(number) 2] = { { id: (byte) 7, name: (string) "jesper", age: (word) $141 }, { id: (byte) 9, name: (string) "henry", age: (word) $7b } }
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 22
|
|
|
|
// 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 = $10
|
|
.const OFFSET_STRUCT_PERSON_NAME = 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 person = persons+SIZEOF_STRUCT_PERSON
|
|
// SCREEN[0] = person->name[2]
|
|
// [4] *((const byte*) main::SCREEN) ← *((byte*)(const struct Person*) persons+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda persons+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN
|
|
// SCREEN[1] = person->name[2]
|
|
// [5] *((const byte*) main::SCREEN+(byte) 1) ← *((byte*)(const struct Person*) main::person#1+(const byte) OFFSET_STRUCT_PERSON_NAME+(byte) 2) -- _deref_pbuc1=_deref_pbuc2
|
|
lda person+OFFSET_STRUCT_PERSON_NAME+2
|
|
sta SCREEN+1
|
|
// main::@return
|
|
// }
|
|
// [6] return
|
|
rts
|
|
}
|
|
// File Data
|
|
persons: .byte 7
|
|
.text "jesper"
|
|
.byte 0
|
|
.fill 6, 0
|
|
.word $141
|
|
.byte 9
|
|
.text "henry"
|
|
.byte 0
|
|
.fill 7, 0
|
|
.word $7b
|
|
|