1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-27 19:50:10 +00:00

Added missing fragment. Added test for literal string pointer cast to word. #298

This commit is contained in:
Jesper Gravgaard 2019-08-27 14:54:49 +02:00
parent a1fc0ace62
commit b6d917a264
8 changed files with 396 additions and 0 deletions

View File

@ -0,0 +1,7 @@
sec
lda #{c1}
sbc {z2}
sta {z1}
lda #0
sbc #0
sta {z1}+1

View File

@ -1378,6 +1378,19 @@ public class TestPrograms {
}
*/
@Test
public void testLiteralWordPointer0() throws IOException, URISyntaxException {
compileAndCompare("literal-word-pointer-0");
}
// TODO: Fix casting literal char* to word https://gitlab.com/camelot/kickc/issues/298
/*
@Test
public void testLiteralWordPointer1() throws IOException, URISyntaxException {
compileAndCompare("literal-word-pointer-1");
}
*/
@Test
public void testLiteralStrings() throws IOException, URISyntaxException {
compileAndCompare("literal-strings");

View File

@ -0,0 +1,9 @@
// Tests assigning a literal word pointer
void main() {
print("qwe");
}
void print(char* str) {
*(char**)0x80 = (char*)str;
}

View File

@ -0,0 +1,9 @@
// Tests assigning a literal word pointer
void main() {
print("qwe");
}
void print(char* str) {
*(word*)0x80 = (word)str;
}

View File

@ -0,0 +1,17 @@
// Tests assigning a literal word pointer
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
main: {
jsr print
rts
str: .text "qwe"
.byte 0
}
print: {
lda #<main.str
sta $80
lda #>main.str
sta $80+1
rts
}

View File

@ -0,0 +1,22 @@
@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] phi()
[5] call print
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
print: scope:[print] from main
[7] *((byte**) 128) ← (const string) main::str
to:print::@return
print::@return: scope:[print] from print
[8] return
to:@return

View File

@ -0,0 +1,309 @@
Culled Empty Block (label) @1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@2
main: scope:[main] from @2
(byte*) print::str#0 ← (const string) main::str
call print
to:main::@1
main::@1: scope:[main] from main
to:main::@return
main::@return: scope:[main] from main::@1
return
to:@return
print: scope:[print] from main
(byte*) print::str#1 ← phi( main/(byte*) print::str#0 )
(byte**~) print::$0 ← ((byte**)) (number) $80
(byte*~) print::$1 ← ((byte*)) (byte*) print::str#1
*((byte**~) print::$0) ← (byte*~) print::$1
to:print::@return
print::@return: scope:[print] from print
return
to:@return
@2: scope:[] from @begin
call main
to:@3
@3: scope:[] from @2
to:@end
@end: scope:[] from @3
SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@return
(const string) main::str = (string) "qwe"
(void()) print((byte*) print::str)
(byte**~) print::$0
(byte*~) print::$1
(label) print::@return
(byte*) print::str
(byte*) print::str#0
(byte*) print::str#1
Inlining cast (byte**~) print::$0 ← (byte**)(number) $80
Inlining cast (byte*~) print::$1 ← (byte*)(byte*) print::str#1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte**) 128
Simplifying constant integer cast (byte*) print::str#1
Successful SSA optimization PassNCastSimplification
Alias (byte*) print::str#1 = (byte*~) print::$1
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) print::str#1 (byte*) print::str#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant (const byte*) print::str#0 = main::str
Constant (const byte**) print::$0 = (byte**) 128
Successful SSA optimization Pass2ConstantIdentification
Constant inlined print::str#0 = (const string) main::str
Constant inlined print::$0 = (byte**) 128
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
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::@1
CALL GRAPH
Calls in [] to main:2
Calls in [main] to print:6
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@1
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
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] phi()
[5] call print
to:main::@return
main::@return: scope:[main] from main
[6] return
to:@return
print: scope:[print] from main
[7] *((byte**) 128) ← (const string) main::str
to:print::@return
print::@return: scope:[print] from print
[8] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(void()) print((byte*) print::str)
(byte*) print::str
Initial phi equivalence classes
Complete equivalence classes
INITIAL ASM
Target platform is c64basic
// File Comments
// Tests assigning a literal word pointer
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// @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: {
// [5] call print
jsr print
jmp breturn
// main::@return
breturn:
// [6] return
rts
str: .text "qwe"
.byte 0
}
// print
print: {
// [7] *((byte**) 128) ← (const string) main::str -- _deref_pptc1=pbuc2
lda #<main.str
sta $80
lda #>main.str
sta $80+1
jmp breturn
// print::@return
breturn:
// [8] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] *((byte**) 128) ← (const string) main::str [ ] ( main:2::print:5 [ ] ) always clobbers reg byte a
REGISTER UPLIFT SCOPES
Uplift Scope [main]
Uplift Scope [print]
Uplift Scope []
Uplifting [main] best 48 combination
Uplifting [print] best 48 combination
Uplifting [] best 48 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Tests assigning a literal word pointer
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// @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: {
// [5] call print
jsr print
jmp breturn
// main::@return
breturn:
// [6] return
rts
str: .text "qwe"
.byte 0
}
// print
print: {
// [7] *((byte**) 128) ← (const string) main::str -- _deref_pptc1=pbuc2
lda #<main.str
sta $80
lda #>main.str
sta $80+1
jmp breturn
// print::@return
breturn:
// [8] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@return
(const string) main::str str = (string) "qwe"
(void()) print((byte*) print::str)
(label) print::@return
(byte*) print::str
FINAL ASSEMBLER
Score: 30
// File Comments
// Tests assigning a literal word pointer
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
// @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: {
// print("qwe")
// [5] call print
jsr print
// main::@return
// }
// [6] return
rts
str: .text "qwe"
.byte 0
}
// print
print: {
// *(char**)0x80 = (char*)str
// [7] *((byte**) 128) ← (const string) main::str -- _deref_pptc1=pbuc2
lda #<main.str
sta $80
lda #>main.str
sta $80+1
// print::@return
// }
// [8] return
rts
}
// File Data

View File

@ -0,0 +1,10 @@
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@return
(const string) main::str str = (string) "qwe"
(void()) print((byte*) print::str)
(label) print::@return
(byte*) print::str