1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-28 01:29:44 +00:00

Added test for __ssa / __notssa. Made literal char ConstantEnumerable.

This commit is contained in:
jespergravgaard 2019-10-20 14:06:54 +02:00
parent 077f40b0d7
commit bacd900a9b
9 changed files with 1388 additions and 4 deletions

View File

@ -99,7 +99,7 @@ public class AsmFragmentInstanceSpec {
if(constantLiteral instanceof ConstantInteger) {
constIntValue = ((ConstantInteger) constantLiteral).getValue();
} else if(constantLiteral instanceof ConstantChar) {
constIntValue = ((ConstantChar) constantLiteral).getIntValue();
constIntValue = ((ConstantChar) constantLiteral).getInteger();
}
if(constIntValue != null) {
List<SymbolTypeIntegerFixed> types = getVariationTypes(constIntValue);

View File

@ -22,7 +22,7 @@ public class OperatorCastByte extends OperatorCast {
} else if(value instanceof ConstantPointer) {
return new ConstantInteger(0xff & ((ConstantPointer) value).getLocation(), SymbolType.BYTE);
} else if(value instanceof ConstantChar) {
return new ConstantInteger(((ConstantChar) value).getIntValue(), SymbolType.BYTE);
return new ConstantInteger(((ConstantChar) value).getInteger(), SymbolType.BYTE);
}
throw new CompileError("Calculation not implemented " + getOperator() + " " + value );
}

View File

@ -10,7 +10,7 @@ import kickass.nonasm.c64.CharToPetsciiConverter;
/**
* SSA form constant char value (a byte)
*/
public class ConstantChar implements ConstantLiteral<Character> {
public class ConstantChar implements ConstantEnumerable<Character> {
/** The character. */
private Character value;
@ -41,7 +41,8 @@ public class ConstantChar implements ConstantLiteral<Character> {
* Get the integer value of the character
* @return The integer value (taking encoding into account)
*/
public Long getIntValue() {
@Override
public Long getInteger() {
Byte constCharIntValue = null;
if(ConstantString.Encoding.SCREENCODE_MIXED.equals(encoding)) {
constCharIntValue = CharToPetsciiConverter.charToScreenCode_mixed.get(value);

View File

@ -37,6 +37,11 @@ public class TestPrograms {
public TestPrograms() {
}
@Test
public void testDeclaredSsaVar8() throws IOException, URISyntaxException {
compileAndCompare("declared-ssa-var-0");
}
@Test
public void testDeclaredMemoryVar8() throws IOException, URISyntaxException {
compileAndCompare("declared-memory-var-8");

View File

@ -0,0 +1,37 @@
// Tests declaring variables as __ssa / __notssa
char __ssa idx_ssa_g;
char __notssa idx_nssa_g;
const char* SCREEN1 = 0x0400;
const char* SCREEN2 = 0x0400+40;
const char* SCREEN3 = 0x0400+80;
const char* SCREEN4 = 0x0400+120;
void main() {
char __ssa idx_ssa_l;
char __notssa idx_nssa_l;
SCREEN1[idx_ssa_g++] = 'C';
for( char i: 'M'..'L')
SCREEN1[idx_ssa_g++] = i;
SCREEN1[idx_ssa_g++] = '!';
SCREEN2[idx_nssa_g++] = 'C';
for( char i: 'M'..'L')
SCREEN2[idx_nssa_g++] = i;
SCREEN2[idx_nssa_g++] = '!';
SCREEN3[idx_ssa_l++] = 'C';
for( char i: 'M'..'L')
SCREEN3[idx_ssa_l++] = i;
SCREEN3[idx_ssa_l++] = '!';
SCREEN4[idx_nssa_l++] = 'C';
for( char i: 'M'..'L')
SCREEN4[idx_nssa_l++] = i;
SCREEN4[idx_nssa_l++] = '!';
}

View File

@ -0,0 +1,80 @@
// Tests declaring variables as __ssa / __notssa
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
.label SCREEN1 = $400
.label SCREEN2 = $400+$28
.label SCREEN3 = $400+$50
.label SCREEN4 = $400+$78
.label idx_nssa_g = 2
__bbegin:
lda #0
sta.z idx_nssa_g
jsr main
rts
main: {
.label idx_nssa_l = 3
lda #0
sta.z idx_nssa_l
lda #'C'
sta SCREEN1
ldy #1
ldx #'M'
__b1:
txa
sta SCREEN1,y
iny
dex
cpx #'L'-1
bne __b1
lda #'!'
sta SCREEN1,y
lda #'C'
ldy.z idx_nssa_g
sta SCREEN2,y
inc.z idx_nssa_g
lda #'M'
__b3:
ldy.z idx_nssa_g
sta SCREEN2,y
inc.z idx_nssa_g
sec
sbc #1
cmp #'L'-1
bne __b3
lda #'!'
ldy.z idx_nssa_g
sta SCREEN2,y
inc.z idx_nssa_g
lda #'C'
sta SCREEN3
ldy #1
ldx #'M'
__b5:
txa
sta SCREEN3,y
iny
dex
cpx #'L'-1
bne __b5
lda #'!'
sta SCREEN3,y
lda #'C'
ldy.z idx_nssa_l
sta SCREEN4,y
inc.z idx_nssa_l
lda #'M'
__b7:
ldy.z idx_nssa_l
sta SCREEN4,y
inc.z idx_nssa_l
sec
sbc #1
cmp #'L'-1
bne __b7
lda #'!'
ldy.z idx_nssa_l
sta SCREEN4,y
inc.z idx_nssa_l
rts
}

View File

@ -0,0 +1,67 @@
@begin: scope:[] from
[0] (byte) idx_nssa_g ← (byte) 0
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] (byte) main::idx_nssa_l ← (byte) 0
[5] *((const byte*) SCREEN1) ← (byte) 'C'
to:main::@1
main::@1: scope:[main] from main main::@1
[6] (byte) idx_ssa_g#7 ← phi( main/(byte) 1 main::@1/(byte) idx_ssa_g#2 )
[6] (byte) main::i#2 ← phi( main/(byte) 'M' main::@1/(byte) main::i#1 )
[7] *((const byte*) SCREEN1 + (byte) idx_ssa_g#7) ← (byte) main::i#2
[8] (byte) idx_ssa_g#2 ← ++ (byte) idx_ssa_g#7
[9] (byte) main::i#1 ← -- (byte) main::i#2
[10] if((byte) main::i#1!=(byte) 'L'-(byte) 1) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
[11] *((const byte*) SCREEN1 + (byte) idx_ssa_g#2) ← (byte) '!'
[12] *((const byte*) SCREEN2 + (byte) idx_nssa_g) ← (byte) 'C'
[13] (byte) idx_nssa_g ← ++ (byte) idx_nssa_g
to:main::@3
main::@3: scope:[main] from main::@2 main::@3
[14] (byte) main::i1#2 ← phi( main::@2/(byte) 'M' main::@3/(byte) main::i1#1 )
[15] *((const byte*) SCREEN2 + (byte) idx_nssa_g) ← (byte) main::i1#2
[16] (byte) idx_nssa_g ← ++ (byte) idx_nssa_g
[17] (byte) main::i1#1 ← -- (byte) main::i1#2
[18] if((byte) main::i1#1!=(byte) 'L'-(byte) 1) goto main::@3
to:main::@4
main::@4: scope:[main] from main::@3
[19] *((const byte*) SCREEN2 + (byte) idx_nssa_g) ← (byte) '!'
[20] (byte) idx_nssa_g ← ++ (byte) idx_nssa_g
[21] *((const byte*) SCREEN3) ← (byte) 'C'
to:main::@5
main::@5: scope:[main] from main::@4 main::@5
[22] (byte) main::idx_ssa_l#5 ← phi( main::@4/(byte) 1 main::@5/(byte) main::idx_ssa_l#2 )
[22] (byte) main::i2#2 ← phi( main::@4/(byte) 'M' main::@5/(byte) main::i2#1 )
[23] *((const byte*) SCREEN3 + (byte) main::idx_ssa_l#5) ← (byte) main::i2#2
[24] (byte) main::idx_ssa_l#2 ← ++ (byte) main::idx_ssa_l#5
[25] (byte) main::i2#1 ← -- (byte) main::i2#2
[26] if((byte) main::i2#1!=(byte) 'L'-(byte) 1) goto main::@5
to:main::@6
main::@6: scope:[main] from main::@5
[27] *((const byte*) SCREEN3 + (byte) main::idx_ssa_l#2) ← (byte) '!'
[28] *((const byte*) SCREEN4 + (byte) main::idx_nssa_l) ← (byte) 'C'
[29] (byte) main::idx_nssa_l ← ++ (byte) main::idx_nssa_l
to:main::@7
main::@7: scope:[main] from main::@6 main::@7
[30] (byte) main::i3#2 ← phi( main::@6/(byte) 'M' main::@7/(byte) main::i3#1 )
[31] *((const byte*) SCREEN4 + (byte) main::idx_nssa_l) ← (byte) main::i3#2
[32] (byte) main::idx_nssa_l ← ++ (byte) main::idx_nssa_l
[33] (byte) main::i3#1 ← -- (byte) main::i3#2
[34] if((byte) main::i3#1!=(byte) 'L'-(byte) 1) goto main::@7
to:main::@8
main::@8: scope:[main] from main::@7
[35] *((const byte*) SCREEN4 + (byte) main::idx_nssa_l) ← (byte) '!'
[36] (byte) main::idx_nssa_l ← ++ (byte) main::idx_nssa_l
to:main::@return
main::@return: scope:[main] from main::@8
[37] return
to:@return

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN1 = (byte*) 1024
(const byte*) SCREEN2 = (byte*)(number) $400+(number) $28
(const byte*) SCREEN3 = (byte*)(number) $400+(number) $50
(const byte*) SCREEN4 = (byte*)(number) $400+(number) $78
(byte) idx_nssa_g notregister zp[1]:2 3.1333333333333333
(byte) idx_ssa_g
(byte) idx_ssa_g#2 reg byte y 8.0
(byte) idx_ssa_g#7 reg byte y 16.5
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@8
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 11.0
(byte) main::i1
(byte) main::i1#1 reg byte a 16.5
(byte) main::i1#2 reg byte a 11.0
(byte) main::i2
(byte) main::i2#1 reg byte x 16.5
(byte) main::i2#2 reg byte x 11.0
(byte) main::i3
(byte) main::i3#1 reg byte a 16.5
(byte) main::i3#2 reg byte a 11.0
(byte) main::idx_nssa_l notregister zp[1]:3 1.6206896551724135
(byte) main::idx_ssa_l
(byte) main::idx_ssa_l#2 reg byte y 8.0
(byte) main::idx_ssa_l#5 reg byte y 16.5
reg byte x [ main::i#2 main::i#1 ]
reg byte y [ idx_ssa_g#7 idx_ssa_g#2 ]
reg byte a [ main::i1#2 main::i1#1 ]
reg byte x [ main::i2#2 main::i2#1 ]
reg byte y [ main::idx_ssa_l#5 main::idx_ssa_l#2 ]
reg byte a [ main::i3#2 main::i3#1 ]
zp[1]:2 [ idx_nssa_g ]
zp[1]:3 [ main::idx_nssa_l ]