1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-27 09:31:18 +00:00

working on type qualifiers

This commit is contained in:
jespergravgaard 2021-04-24 08:05:16 +02:00
parent 8b2186e634
commit 37ad98913f
25 changed files with 9235 additions and 20303 deletions

1
.idea/vcs.xml generated
View File

@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/src/test/kc/complex/push" vcs="Git" />
</component>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -1,72 +1,24 @@
//KICKC FRAGMENT CACHE 108dd16dc1 108dd18d7f
//FRAGMENT _deref_pbuc1=vbuc2
lda #{c2}
sta {c1}
//FRAGMENT _deref_pbuc1=_deref_pbuc1_bor_vbuc2
lda #{c2}
ora {c1}
sta {c1}
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}
//FRAGMENT pbuz1=pbuc1
lda #<{c1}
sta {z1}
lda #>{c1}
sta {z1}+1
//FRAGMENT pbuz1_lt_pbuc1_then_la1
lda {z1}+1
cmp #>{c1}
bcc {la1}
bne !+
lda {z1}
cmp #<{c1}
bcc {la1}
!:
//FRAGMENT _deref_pbuc1=_deref_pbuc2
lda {c2}
sta {c1}
//FRAGMENT vbuz1=_lo_pbuz2
lda {z2}
sta {z1}
//FRAGMENT _deref_pbuz1=vbuz2
lda {z2}
ldy #0
sta ({z1}),y
//FRAGMENT pbuz1=_inc_pbuz1
inw {z1}
//FRAGMENT _deref_pbuz1=vbuc1
lda #{c1}
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=_lo_pbuz1
lda {z1}
//FRAGMENT vbuxx=_lo_pbuz1
ldx {z1}
//FRAGMENT _deref_pbuz1=vbuaa
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuxx
txa
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuyy
tya
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuzz
tza
ldy #0
sta ({z1}),y
//FRAGMENT vbuyy=_lo_pbuz1
ldy {z1}
//FRAGMENT vbuzz=_lo_pbuz1
ldz {z1}
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}
//FRAGMENT isr_hardware_all_entry
pha @clob_a
phx @clob_x
phy @clob_y
phz @clob_z
//FRAGMENT _deref_pbuc1=_deref_pbuc1_bor_vbuc2
lda #{c2}
ora {c1}
sta {c1}
//FRAGMENT _deref_pbuc1=vbuc2
lda #{c2}
sta {c1}
//FRAGMENT vbuz1=_inc_vbuz1
inc {z1}
//FRAGMENT vbuz1=vbuz2
@ -93,6 +45,8 @@ dec {z1}
ldy #0
lda ({z2}),y
sta {z1}
//FRAGMENT pbuz1=_inc_pbuz1
inw {z1}
//FRAGMENT vbuz1_neq_0_then_la1
lda {z1}
bne {la1}
@ -190,6 +144,10 @@ bne {la1}
lda {z1}
cmp #<{c1}
bne {la1}
//FRAGMENT _deref_pbuz1=vbuc1
lda #{c1}
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=vbuz1
lda {z1}
//FRAGMENT vbuxx=vbuz1
@ -1187,217 +1145,11 @@ inc
stx {c1}
//FRAGMENT _deref_pbuc1=vbuzz
stz {c1}
//FRAGMENT vbuz1=_deref_pbuc1_plus_1
lda {c1}
inc
sta {z1}
//FRAGMENT vwuz1=_word_vbuz2
lda {z2}
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_2
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vwuz3
lda {z2}
clc
adc {z3}
sta {z1}
lda {z2}+1
adc {z3}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_4
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz2
clc
lda {z2}
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1=pbuz2
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1
//FRAGMENT 0_neq_vbuz1_then_la1
lda {z1}
bne {la1}
//FRAGMENT pbuz1_derefidx_vbuz2=vbuz3
lda {z3}
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuc1
lda #{c1}
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1=pbuz1_plus_vbuc1
lda #{c1}
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT pvoz1=pvoc1
lda #<{c1}
sta {z1}
lda #>{c1}
sta {z1}+1
//FRAGMENT pbuz1=pbuz1_minus_vbuc1
sec
lda {z1}
sbc #{c1}
sta {z1}
lda {z1}+1
sbc #0
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_vwuc1
clc
lda {z2}
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1_neq_pbuz2_then_la1
lda {z1}+1
cmp {z2}+1
bne {la1}
lda {z1}
cmp {z2}
bne {la1}
//FRAGMENT _deref_pbuz1=_deref_pbuz2
ldy #0
lda ({z2}),y
ldy #0
sta ({z1}),y
//FRAGMENT pbuz1=pbuz2_plus_vbuc1
lda #{c1}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vbuaa=_deref_pbuc1_plus_1
lda {c1}
inc
//FRAGMENT vbuxx=_deref_pbuc1_plus_1
ldx {c1}
inx
//FRAGMENT vbuz1=vbuxx
stx {z1}
//FRAGMENT vwuz1=_word_vbuxx
txa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuyy
tya
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuzz
tza
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT 0_neq_vbuaa_then_la1
cmp #0
bne {la1}
//FRAGMENT vbuz1=vbuaa
sta {z1}
//FRAGMENT pbuz1_derefidx_vbuz2=vbuaa
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuxx
txa
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuyy
tya
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuzz
tza
ldz {z2}
sta ({z1}),z
//FRAGMENT 0_neq_vbuxx_then_la1
cpx #0
bne {la1}
//FRAGMENT vbuaa=vbuxx
txa
//FRAGMENT 0_neq_vbuyy_then_la1
cpy #0
bne {la1}
//FRAGMENT vbuaa=vbuyy
tya
//FRAGMENT 0_neq_vbuzz_then_la1
cpz #0
bne {la1}
//FRAGMENT vbuaa=vbuzz
tza
//FRAGMENT vbuz1=vbuyy
sty {z1}
//FRAGMENT vbuz1=vbuzz
tza
sta {z1}
//FRAGMENT vbuxx=vbuaa
tax
//FRAGMENT vbuyy=_deref_pbuc1_plus_1
ldy {c1}
iny
//FRAGMENT vbuxx=vbuyy
tya
tax
//FRAGMENT vbuzz=_deref_pbuc1_plus_1
lda {c1}
inc
taz
//FRAGMENT vbuxx=vbuzz
tza
tax
//FRAGMENT vwuz1=vwuz2_plus_vwuz1
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz1
clc
lda {z1}
adc #<{c1}
sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT vwuz1=vwuz1_rol_4
asw {z1}
asw {z1}
asw {z1}
asw {z1}
//FRAGMENT vwuz1=vwuc1
lda #<{c1}
sta {z1}
@ -1408,6 +1160,9 @@ lda #<{c1}
sta {z1}
lda #>{c1}
sta {z1}+1
//FRAGMENT _deref_pbuc1=_deref_pbuc2
lda {c2}
sta {c1}
//FRAGMENT pbuz1=pbuz1_plus_vwuc1
clc
lda {z1}
@ -1416,10 +1171,23 @@ sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1=pbuz1_plus_vbuc1
lda #{c1}
clc
adc {z1}
sta {z1}
bcc !+
inc {z1}+1
!:
//FRAGMENT pbuz1_derefidx_vbuz2=pbuz3_derefidx_vbuz2
ldy {z2}
lda ({z3}),y
sta ({z1}),y
//FRAGMENT vwuz1=_word_vbuz2
lda {z2}
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT pwuz1=pwuz1_plus_vbuc1
lda #{c1}
clc
@ -1493,6 +1261,21 @@ sta ({z1}),y
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuxx
txa
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuyy
tya
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vwuz1=_word_vbuzz
tza
sta {z1}
lda #0
sta {z1}+1
//FRAGMENT vbuz1=vbuaa_rol_1
asl
sta {z1}
@ -1661,6 +1444,8 @@ inc {c1},x
lda {z1}
//FRAGMENT vbuxx=_lo_vwuz1
ldx {z1}
//FRAGMENT vbuz1=vbuaa
sta {z1}
//FRAGMENT vbuaa=_hi_vwuz1
lda {z1}+1
//FRAGMENT vbuxx=_hi_vwuz1
@ -1700,10 +1485,17 @@ ora {z2}
sta {z1}
//FRAGMENT vbuz1=vbuxx_bor_vbuxx
stx {z1}
//FRAGMENT vbuz1=vbuxx
stx {z1}
//FRAGMENT vbuyy=_lo_vwuz1
ldy {z1}
//FRAGMENT vbuz1=vbuyy
sty {z1}
//FRAGMENT vbuzz=_lo_vwuz1
ldz {z1}
//FRAGMENT vbuz1=vbuzz
tza
sta {z1}
//FRAGMENT vbuyy=_hi_vwuz1
ldy {z1}+1
//FRAGMENT vbuzz=_hi_vwuz1
@ -2541,6 +2333,8 @@ tza
tax
tya
sta {c1},x
//FRAGMENT vbuxx=vbuaa
tax
//FRAGMENT vbuyy=vbuaa
tay
//FRAGMENT vbuzz=vbuaa
@ -2609,3 +2403,209 @@ sta {z1}+3
NO_SYNTHESIS
//FRAGMENT vduz1=vwsc1
NO_SYNTHESIS
//FRAGMENT pbuz1_lt_pbuc1_then_la1
lda {z1}+1
cmp #>{c1}
bcc {la1}
bne !+
lda {z1}
cmp #<{c1}
bcc {la1}
!:
//FRAGMENT vbuz1=_lo_pbuz2
lda {z2}
sta {z1}
//FRAGMENT _deref_pbuz1=vbuz2
lda {z2}
ldy #0
sta ({z1}),y
//FRAGMENT vbuaa=_lo_pbuz1
lda {z1}
//FRAGMENT vbuxx=_lo_pbuz1
ldx {z1}
//FRAGMENT _deref_pbuz1=vbuaa
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuxx
txa
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuyy
tya
ldy #0
sta ({z1}),y
//FRAGMENT _deref_pbuz1=vbuzz
tza
ldy #0
sta ({z1}),y
//FRAGMENT vbuyy=_lo_pbuz1
ldy {z1}
//FRAGMENT vbuzz=_lo_pbuz1
ldz {z1}
//FRAGMENT vbuz1=_deref_pbuc1_plus_1
lda {c1}
inc
sta {z1}
//FRAGMENT vwuz1=vwuz2_rol_2
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT vwuz1=vwuz2_plus_vwuz3
lda {z2}
clc
adc {z3}
sta {z1}
lda {z2}+1
adc {z3}+1
sta {z1}+1
//FRAGMENT vwuz1=vwuz2_rol_4
lda {z2}
asl
sta {z1}
lda {z2}+1
rol
sta {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
asl {z1}
rol {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz2
clc
lda {z2}
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1=pbuz2
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1
//FRAGMENT 0_neq_vbuz1_then_la1
lda {z1}
bne {la1}
//FRAGMENT pbuz1_derefidx_vbuz2=vbuz3
lda {z3}
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuc1
lda #{c1}
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1=pbuz1_minus_vbuc1
sec
lda {z1}
sbc #{c1}
sta {z1}
lda {z1}+1
sbc #0
sta {z1}+1
//FRAGMENT pbuz1=pbuz2_plus_vwuc1
clc
lda {z2}
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT pbuz1_neq_pbuz2_then_la1
lda {z1}+1
cmp {z2}+1
bne {la1}
lda {z1}
cmp {z2}
bne {la1}
//FRAGMENT _deref_pbuz1=_deref_pbuz2
ldy #0
lda ({z2}),y
ldy #0
sta ({z1}),y
//FRAGMENT pbuz1=pbuz2_plus_vbuc1
lda #{c1}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1
//FRAGMENT vbuaa=_deref_pbuc1_plus_1
lda {c1}
inc
//FRAGMENT vbuxx=_deref_pbuc1_plus_1
ldx {c1}
inx
//FRAGMENT 0_neq_vbuaa_then_la1
cmp #0
bne {la1}
//FRAGMENT pbuz1_derefidx_vbuz2=vbuaa
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuxx
txa
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuyy
tya
ldz {z2}
sta ({z1}),z
//FRAGMENT pbuz1_derefidx_vbuz2=vbuzz
tza
ldz {z2}
sta ({z1}),z
//FRAGMENT 0_neq_vbuxx_then_la1
cpx #0
bne {la1}
//FRAGMENT vbuaa=vbuxx
txa
//FRAGMENT 0_neq_vbuyy_then_la1
cpy #0
bne {la1}
//FRAGMENT vbuaa=vbuyy
tya
//FRAGMENT 0_neq_vbuzz_then_la1
cpz #0
bne {la1}
//FRAGMENT vbuaa=vbuzz
tza
//FRAGMENT vbuyy=_deref_pbuc1_plus_1
ldy {c1}
iny
//FRAGMENT vbuxx=vbuyy
tya
tax
//FRAGMENT vbuzz=_deref_pbuc1_plus_1
lda {c1}
inc
taz
//FRAGMENT vbuxx=vbuzz
tza
tax
//FRAGMENT vwuz1=vwuz2_plus_vwuz1
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1
//FRAGMENT pbuz1=pbuc1_plus_vwuz1
clc
lda {z1}
adc #<{c1}
sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1
//FRAGMENT vwuz1=vwuz1_rol_4
asw {z1}
asw {z1}
asw {z1}
asw {z1}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -54,13 +54,20 @@ public class VariableBuilder {
* @return The variable
*/
public Variable build() {
Variable variable = new Variable(varName, getKind(), type, scope, getMemoryArea(), dataSegment, null);
// Todo: move to type parsing!
SymbolType typeQualified = type.getQualified(this.isVolatile(), this.isNoModify());
Variable variable = new Variable(varName, getKind(), typeQualified, scope, getMemoryArea(), dataSegment, null);
// Todo: remove!
variable.setNoModify(this.isNoModify());
variable.setVolatile(this.isVolatile());
variable.setExport(this.isExport());
variable.setPermanent(this.isPermanent());
variable.setToNoModify(this.isToNoModify());
variable.setToVolatile(this.isToVolatile());
variable.setExport(this.isExport());
variable.setPermanent(this.isPermanent());
variable.setOptimize(this.isOptimize());
variable.setRegister(this.getRegister());
if(variable.getRegister() instanceof Registers.RegisterMainMem) {

View File

@ -193,11 +193,14 @@ public class Variable implements Symbol {
version.setMemoryAlignment(phiMaster.getMemoryAlignment());
version.setMemoryAddress(phiMaster.getMemoryAddress());
version.setOptimize(phiMaster.isOptimize());
version.setNoModify(phiMaster.isNoModify());
version.setRegister(phiMaster.getRegister());
// TODO: remove
version.setVolatile(phiMaster.isVolatile());
version.setNoModify(phiMaster.isNoModify());
version.setToNoModify(phiMaster.isToNoModify());
version.setToVolatile(phiMaster.isToVolatile());
version.setRegister(phiMaster.getRegister());
version.setPermanent(phiMaster.isPermanent());
version.setExport(phiMaster.isExport());
version.setComments(phiMaster.getComments());
@ -239,11 +242,13 @@ public class Variable implements Symbol {
constVar.setMemoryAlignment(variable.getMemoryAlignment());
constVar.setMemoryAddress(variable.getMemoryAddress());
constVar.setOptimize(variable.isOptimize());
constVar.setNoModify(variable.isNoModify());
constVar.setRegister(variable.getRegister());
// Todo: remove
constVar.setVolatile(variable.isVolatile());
constVar.setNoModify(variable.isNoModify());
constVar.setToNoModify(variable.isToNoModify());
constVar.setToVolatile(variable.isToVolatile());
constVar.setPermanent(variable.isPermanent());
constVar.setExport(variable.isExport());
constVar.setComments(variable.getComments());
@ -262,11 +267,14 @@ public class Variable implements Symbol {
copy.setMemoryAlignment(original.getMemoryAlignment());
copy.setMemoryAddress(original.getMemoryAddress());
copy.setOptimize(original.isOptimize());
copy.setNoModify(original.isNoModify());
copy.setPermanent(original.isPermanent());
// Todo: remove
copy.setVolatile(original.isVolatile());
copy.setNoModify(original.isNoModify());
copy.setToNoModify(original.isToNoModify());
copy.setToVolatile(original.isToVolatile());
copy.setExport(original.isExport());
copy.setRegister(original.getRegister());
copy.setComments(original.getComments());
@ -288,18 +296,24 @@ public class Variable implements Symbol {
if(isParameter && memberDefinition.isArray()) {
// Array struct members are converted to pointers when unwound (use same kind as the struct variable)
SymbolTypePointer arrayType = (SymbolTypePointer) memberDefinition.getType();
memberVariable = new Variable(name, structVar.getKind(), new SymbolTypePointer(arrayType.getElementType()), structVar.getScope(), memoryArea, structVar.getDataSegment(), null);
SymbolType typeQualified = new SymbolTypePointer(arrayType.getElementType()).getQualified(structVar.isVolatile, structVar.isNoModify());
memberVariable = new Variable(name, structVar.getKind(), typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), null);
} else if(memberDefinition.isKindConstant()) {
// Constant members are unwound as constants
memberVariable = new Variable(name, Kind.CONSTANT, memberDefinition.getType(), structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile, structVar.isNoModify());
memberVariable = new Variable(name, Kind.CONSTANT, typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
} else {
// For others the kind is preserved from the member definition
memberVariable = new Variable(name, structVar.getKind(), memberDefinition.getType(), structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile, structVar.isNoModify());
memberVariable = new Variable(name, structVar.getKind(),typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
}
// Todo: fix struct member qualifiers - and remove!
memberVariable.setVolatile(structVar.isVolatile());
memberVariable.setNoModify(structVar.isNoModify());
memberVariable.setToNoModify(structVar.isToNoModify());
memberVariable.setToVolatile(structVar.isToVolatile());
memberVariable.setExport(structVar.isExport());
memberVariable.setPermanent(structVar.isPermanent());
return memberVariable;

View File

@ -11,6 +11,14 @@ public interface SymbolType extends Serializable {
/** Specifies that the variable is not allowed to be modified (const keyword). The compiler should try to detect modifications and generate compile-time errors if they occur.*/
boolean isNomodify();
/** Get the type with different type qualifiers.
*
* @param isVolatile Should the type be marked as volatile
* @param isNomodify Should the type be marked as nomodify (keyword const)
* @return The type with different qualifiers
*/
SymbolType getQualified(boolean isVolatile, boolean isNomodify);
/** Unsigned byte (8 bits)). */
SymbolTypeIntegerFixed BYTE = new SymbolTypeIntegerFixed("byte", 0, 255, false, 8, false, false);
/** Signed byte (8 bits). */

View File

@ -4,12 +4,11 @@ package dk.camelot64.kickc.model.types;
public class SymbolTypeBlockScope implements SymbolType {
public SymbolTypeBlockScope() {
}
@Override
public String getTypeName() {
return "BLOCK";
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return this;
}
@Override
@ -22,6 +21,11 @@ public class SymbolTypeBlockScope implements SymbolType {
return false;
}
@Override
public String getTypeName() {
return "BLOCK";
}
@Override
public int getSizeBytes() {
return -1;

View File

@ -8,7 +8,7 @@ import java.util.Objects;
public class SymbolTypeEnum implements SymbolType {
/** Name of the enum type. */
private String name;
private String enumName;
/** The enum definition. */
private EnumDefinition definition;
@ -18,11 +18,16 @@ public class SymbolTypeEnum implements SymbolType {
public SymbolTypeEnum(EnumDefinition definition, boolean isVolatile, boolean isNomodify) {
this.definition = definition;
this.name = definition.getLocalName();
this.enumName = definition.getLocalName();
this.isVolatile = isVolatile;
this.isNomodify = isNomodify;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return new SymbolTypeEnum(this.definition, isVolatile, isNomodify);
}
@Override
public boolean isVolatile() {
return isVolatile;
@ -35,7 +40,15 @@ public class SymbolTypeEnum implements SymbolType {
@Override
public String getTypeName() {
return "enum " + name;
String name = "";
/*
if(isVolatile)
name += "volatile ";
if(isNomodify)
name += "const ";
*/
name += "enum " + this.enumName;
return name;
}
@Override
@ -57,12 +70,12 @@ public class SymbolTypeEnum implements SymbolType {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
SymbolTypeEnum that = (SymbolTypeEnum) o;
return Objects.equals(name, that.name);
return Objects.equals(enumName, that.enumName);
}
@Override
public int hashCode() {
return Objects.hash(name);
return Objects.hash(enumName);
}
}

View File

@ -11,6 +11,11 @@ public class SymbolTypeIntegerAuto implements SymbolTypeInteger {
this.typeName = typeName;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return this;
}
@Override
public boolean isVolatile() {
return false;

View File

@ -7,16 +7,19 @@ import java.util.Objects;
/** Integer type with a fixed size (byte, signed byte, word, ...). */
public class SymbolTypeIntegerFixed implements SymbolTypeInteger {
private final String typeName;
/** The basename of the the type (without any qualifiers). */
private final String typeBaseName;
private final long minValue;
private final long maxValue;
private final boolean signed;
private final int bits;
private final boolean isVolatile;
private final boolean isNomodify;
SymbolTypeIntegerFixed(String typeName, long minValue, long maxValue, boolean signed, int bits, boolean isVolatile, boolean isNomodify) {
this.typeName = typeName;
SymbolTypeIntegerFixed(String typeBaseName, long minValue, long maxValue, boolean signed, int bits, boolean isVolatile, boolean isNomodify) {
this.typeBaseName = typeBaseName;
this.minValue = minValue;
this.maxValue = maxValue;
this.signed = signed;
@ -25,10 +28,15 @@ public class SymbolTypeIntegerFixed implements SymbolTypeInteger {
this.isNomodify = isNomodify;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return new SymbolTypeIntegerFixed(this.typeBaseName, this.minValue, this.maxValue, this.signed, this.bits, isVolatile, isNomodify);
}
/**
* Get all fixed size integer types.
* Get all (unqualified) fixed size integer types.
*
* @return All fixed size integer types
* @return All (unqualified) fixed size integer types
*/
public static Collection<SymbolTypeIntegerFixed> getIntegerFixedTypes() {
ArrayList<SymbolTypeIntegerFixed> types = new ArrayList<>();
@ -88,7 +96,15 @@ public class SymbolTypeIntegerFixed implements SymbolTypeInteger {
@Override
public String getTypeName() {
return typeName;
String name = "";
/*
if(isVolatile)
name += "volatile ";
if(isNomodify)
name += "const ";
*/
name += typeBaseName;
return name;
}
public long getMinValue() {
@ -122,11 +138,11 @@ public class SymbolTypeIntegerFixed implements SymbolTypeInteger {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
SymbolTypeIntegerFixed that = (SymbolTypeIntegerFixed) o;
return Objects.equals(typeName, that.typeName);
return Objects.equals(typeBaseName, that.typeBaseName);
}
@Override
public int hashCode() {
return Objects.hash(typeName);
return Objects.hash(typeBaseName);
}
}

View File

@ -3,18 +3,23 @@ package dk.camelot64.kickc.model.types;
/** Basic named (string, char, ...) Symbol Types */
public class SymbolTypeNamed implements SymbolType {
private String typeName;
private String typeBaseName;
private int sizeBytes;
private final boolean isVolatile;
private final boolean isNomodify;
SymbolTypeNamed(String typeName, int sizeBytes, boolean isVolatile, boolean isNomodify) {
this.typeName = typeName;
SymbolTypeNamed(String typeBaseName, int sizeBytes, boolean isVolatile, boolean isNomodify) {
this.typeBaseName = typeBaseName;
this.sizeBytes = sizeBytes;
this.isVolatile = isVolatile;
this.isNomodify = isNomodify;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return new SymbolTypeNamed(this.typeBaseName, this.sizeBytes, isVolatile, isNomodify);
}
@Override
public boolean isVolatile() {
return isVolatile;
@ -26,7 +31,15 @@ public class SymbolTypeNamed implements SymbolType {
}
public String getTypeName() {
return typeName;
String name = "";
/*
if(isVolatile)
name += "volatile ";
if(isNomodify)
name += "const ";
*/
name += typeBaseName;
return name;
}
@Override
@ -45,12 +58,12 @@ public class SymbolTypeNamed implements SymbolType {
SymbolTypeNamed that = (SymbolTypeNamed) o;
return typeName != null ? typeName.equals(that.typeName) : that.typeName == null;
return typeBaseName != null ? typeBaseName.equals(that.typeBaseName) : that.typeBaseName == null;
}
@Override
public int hashCode() {
return typeName != null ? typeName.hashCode() : 0;
return typeBaseName != null ? typeBaseName.hashCode() : 0;
}
@Override

View File

@ -18,7 +18,6 @@ public class SymbolTypePointer implements SymbolType {
private final boolean isVolatile;
private final boolean isNomodify;
public SymbolTypePointer(SymbolType elementType, ArraySpec arraySpec, boolean isVolatile, boolean isNomodify) {
this.elementType = elementType;
this.arraySpec = arraySpec;
@ -30,14 +29,19 @@ public class SymbolTypePointer implements SymbolType {
this(elementType, null, false, false);
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return new SymbolTypePointer(this.elementType, this.arraySpec, isVolatile, isNomodify);
}
@Override
public boolean isVolatile() {
return false;
return isVolatile;
}
@Override
public boolean isNomodify() {
return false;
return isNomodify;
}
public SymbolType getElementType() {
@ -54,7 +58,14 @@ public class SymbolTypePointer implements SymbolType {
@Override
public String getTypeName() {
return elementType.getTypeName() + "*";
String name = elementType.getTypeName() + "*";
/*
if(isVolatile)
name += " volatile";
if(isNomodify)
name += " const";
*/
return name;
}
@Override

View File

@ -11,6 +11,11 @@ public class SymbolTypeProcedure implements SymbolType {
this.returnType = returnType;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return this;
}
@Override
public boolean isVolatile() {
return false;

View File

@ -4,7 +4,11 @@ package dk.camelot64.kickc.model.types;
public class SymbolTypeProgram implements SymbolType {
public SymbolTypeProgram() {
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return this;
}
@Override

View File

@ -13,7 +13,7 @@ import java.util.Objects;
public class SymbolTypeStruct implements SymbolType {
/** Name of the struct type. */
private String name;
private String structName;
/** Size of the struct in bytes. */
private int sizeBytes;
@ -21,13 +21,25 @@ public class SymbolTypeStruct implements SymbolType {
private final boolean isVolatile;
private final boolean isNomodify;
public SymbolTypeStruct(String structName, int sizeBytes, boolean isVolatile, boolean isNomodify) {
this.structName = structName;
this.sizeBytes = sizeBytes;
this.isVolatile = isVolatile;
this.isNomodify = isNomodify;
}
public SymbolTypeStruct(StructDefinition structDefinition, boolean isVolatile, boolean isNomodify) {
this.name = structDefinition.getLocalName();
this.structName = structDefinition.getLocalName();
this.sizeBytes = calculateSizeBytes(structDefinition, null);
this.isVolatile = isVolatile;
this.isNomodify = isNomodify;
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return new SymbolTypeStruct(this.structName, this.sizeBytes, isVolatile, isNomodify);
}
@Override
public boolean isVolatile() {
return isVolatile;
@ -40,15 +52,23 @@ public class SymbolTypeStruct implements SymbolType {
@Override
public String getTypeName() {
return "struct " + name;
}
public String getStructTypeName() {
String name = "";
/*
if(isVolatile)
name += "volatile ";
if(isNomodify)
name += "const ";
*/
name += "struct " + this.structName;
return name;
}
public String getStructTypeName() {
return structName;
}
public StructDefinition getStructDefinition(ProgramScope programScope) {
return programScope.getLocalStructDefinition(name);
return programScope.getLocalStructDefinition(structName);
}
@Override
@ -98,12 +118,12 @@ public class SymbolTypeStruct implements SymbolType {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
SymbolTypeStruct that = (SymbolTypeStruct) o;
return Objects.equals(name, that.name);
return Objects.equals(structName, that.structName);
}
@Override
public int hashCode() {
return Objects.hash(name, sizeBytes);
return Objects.hash(structName, sizeBytes);
}
@Override

View File

@ -4,7 +4,11 @@ package dk.camelot64.kickc.model.types;
public class SymbolTypeTypeDefScope implements SymbolType {
public SymbolTypeTypeDefScope() {
}
@Override
public SymbolType getQualified(boolean isVolatile, boolean isNomodify) {
return this;
}
@Override

View File

@ -794,9 +794,11 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
}
/** The declared type of a variable. Combines SymbolType, type directives (const, volatile) and ArraySpec. It holds advanced type information like <p><code>char volatile * const * [42]</code> */
// TODO: Remove when const/volatile are put into type
static class VariableDeclType {
/** The type. */
SymbolType type;
// TODO: Remove when const/volatile are put into type
/** Const / Volatile Directives if applied to the type */
List<Directive> typeDirectives;
/** If the type is SymbolTypePointer this holds the declaration type of the elements. */
@ -851,8 +853,20 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
void setDeclDirectives(List<Directive> directives) {
this.declDirectives = new ArrayList<>();
for(Directive directive : directives) {
if(directive instanceof Directive.Const || directive instanceof Directive.Volatile) {
if(directive instanceof Directive.Volatile) {
// Type directive
SymbolType type = this.declType.getType();
SymbolType typeQualified = type.getQualified(true, type.isNomodify());
this.declType.setType(typeQualified);
// TODO: Remove when const/volatile are put into type
if(!this.declType.getTypeDirectives().contains(directive))
this.declType.getTypeDirectives().add(directive);
} else if(directive instanceof Directive.Const) {
// Type directive
SymbolType type = this.declType.getType();
SymbolType typeQualified = type.getQualified(type.isVolatile(), true);
this.declType.setType(typeQualified);
// TODO: Remove when const/volatile are put into type
if(!this.declType.getTypeDirectives().contains(directive))
this.declType.getTypeDirectives().add(directive);
} else {
@ -868,9 +882,11 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
// Add all general directives
dirs.addAll(declDirectives);
// Add type-directives
// TODO: Remove when const/volatile are put into type
final VariableDeclType effectiveDeclType = getEffectiveDeclType();
dirs.addAll(effectiveDeclType.getTypeDirectives());
// Convert element directives
// TODO: Remove when const/volatile are put into type
final VariableDeclType elementDeclType = effectiveDeclType.getElementDeclType();
if(elementDeclType != null) {
for(Directive elementTypeDirective : elementDeclType.getTypeDirectives()) {
@ -881,6 +897,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
}
}
// Produce error on any deeper directives
// TODO: Remove when const/volatile are put into type
VariableDeclType deepDeclType = elementDeclType.getElementDeclType();
while(deepDeclType != null) {
if(!deepDeclType.getTypeDirectives().isEmpty()) {
@ -2039,6 +2056,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
type = elementType;
declType = elementDeclType;
}
// TODO: Remove when const/volatile are put into type
if(typeDefVariable.isNoModify())
varDecl.getDeclType().getTypeDirectives().add(new Directive.Const());
if(typeDefVariable.isVolatile())

View File

@ -7,6 +7,7 @@ import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.symbols.Symbol;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
import dk.camelot64.kickc.model.values.ConstantSymbolPointer;
import dk.camelot64.kickc.model.values.RValue;
@ -60,11 +61,17 @@ public class Pass1AddressOfHandling extends Pass2SsaOptimization {
private void updateAddressOfVariable(Variable variable, String stmtStr) {
if(variable.getType() instanceof SymbolTypeStruct) {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: remove
variable.setVolatile(true);
getLog().append("Setting struct to load/store in variable affected by address-of " + stmtStr);
//getLog().append("Setting struct to load/store in variable affected by address-of: " + variable.toString() + " in " + stmtStr);
} else {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: remove
variable.setVolatile(true);
getLog().append("Setting inferred volatile on symbol affected by address-of " + stmtStr);
//getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);

View File

@ -4,6 +4,7 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.iterator.ProgramValue;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeStruct;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
import dk.camelot64.kickc.model.values.Value;
@ -39,9 +40,13 @@ public class Pass1AsmUsesHandling extends Pass2SsaOptimization {
private void updateAddressOfVariable(Variable variable, String stmtStr) {
if(variable.getType() instanceof SymbolTypeStruct) {
variable.setKind(Variable.Kind.LOAD_STORE);
// TODO: Add volatile??
getLog().append("Setting struct to load/store in variable affected by address-of: " + variable.toString() + " in " + stmtStr);
} else {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: Remove
variable.setVolatile(true);
getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);
}

View File

@ -8,6 +8,10 @@ import dk.camelot64.kickc.asm.AsmProgram;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.TargetPlatform;
import dk.camelot64.kickc.model.symbols.Symbol;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.parser.CTargetPlatformParser;
import kickass.KickAssembler65CE02;
import kickass.nonasm.c64.CharToPetsciiConverter;
@ -5094,6 +5098,25 @@ public class TestPrograms {
defines.put("__KICKC__", "1");
defines.putAll(program.getTargetPlatform().getDefines());
compiler.compile(files, defines);
// TODO: Delete when const/volatile is confirmed to work on SymbolType
for(Symbol symbol : program.getScope().getAllSymbols(true)) {
if(symbol instanceof Variable) {
Variable var = (Variable) symbol;
SymbolType varType = var.getType();
assertEquals(var.isVolatile(), varType.isVolatile(), "Variable volatile "+var.toString());
assertEquals(var.isNoModify(), varType.isNomodify(), "Variable nomodify "+var.toString());
boolean isToVolatile = false;
boolean isToNomodify = false;
if(varType instanceof SymbolTypePointer) {
isToVolatile = ((SymbolTypePointer) varType).getElementType().isVolatile();
isToNomodify = ((SymbolTypePointer) varType).getElementType().isNomodify();
}
assertEquals(var.isToVolatile(), isToVolatile, "Variable to volatile "+var.toString());
assertEquals(var.isToNoModify(), isToNomodify, "Variable to nomodify "+var.toString());
}
}
compileAsm(fileName, program);
boolean success = true;
ReferenceHelper helper = new ReferenceHelperFolder(refPath);

View File

@ -2,7 +2,7 @@
#include "lib.h"
const char* SCREEN = 0x0400;
char* const SCREEN = 0x0400;
void main() {

View File

@ -65,8 +65,6 @@ void main() {
SEI();
// Map memory to BANK 0 : 0x00XXXX - giving access to I/O
memoryRemap(0x00,0,0);
// Fast CPU, M65 IO
POKE(0,65);
// Disable Kernal & Basic
*PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK;
*PROCPORT = PROCPORT_RAM_IO;
@ -124,10 +122,13 @@ void main() {
VICIV->CHARPTR_HILO = 0;
graphics_render = GRAPHICS1;
}
VICIV->BORDER_COLOR = BLUE;
// Clear the graphics
memset_dma(graphics_render, 0x00, 40*25*8);
VICIV->BORDER_COLOR = PURPLE;
// Render some dots
render_dots();
VICIV->BORDER_COLOR = BLACK;
//Play SID
(*musicPlay)();
@ -212,7 +213,7 @@ unsigned int SINX2[SINX2_SIZE+256] = kickasm {{
void graphics_mode(void) {
// 16-bit text mode
VICIV->CONTROLC = VICIV_CHR16;
VICIV->CONTROLC = VICIV_CHR16|VICIV_VFAST;
// H320, fast CPU
VICIV->CONTROLB = VICIV_FAST;
// 320x200 per char, 16 pixels wide per char