1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-21 17:24:39 +00:00

Last of fragment renaming completed (zpptrby1/zpptrsby1 => pbuz1/pbsz1)

This commit is contained in:
jespergravgaard 2017-12-13 00:29:47 +01:00
parent 49b8545232
commit 177be17dd9
301 changed files with 3424 additions and 3448 deletions

View File

@ -93,9 +93,6 @@ public class AsmFragmentManager {
mapZ.put("vbuz3", "vbuz2");
mapZ.put("z2", "z1");
mapZ.put("z3", "z2");
Map<String, String> mapZpptrby = new LinkedHashMap<>();
mapZpptrby.put("zpptrby2", "zpptrby1");
mapZpptrby.put("zpptrby3", "zpptrby2");
Map<String, String> mapConst = new LinkedHashMap<>();
mapConst.put("vwuc2", "vwuc1");
mapConst.put("vwuc3", "vwuc2");
@ -103,17 +100,6 @@ public class AsmFragmentManager {
mapConst.put("vbuc3", "vbuc2");
mapConst.put("c2", "c1");
mapConst.put("c3", "c2");
Map<String, String> mapZpptrToWord = new LinkedHashMap<>();
mapZpptrToWord.put("zpptrby1", "zpwo1");
mapZpptrToWord.put("zpptrby2", "zpwo2");
mapZpptrToWord.put("zpptrby3", "zpwo3");
Map<String, String> mapZpptrToWord2 = new LinkedHashMap<>();
mapZpptrToWord2.put("zpwo1", "zpwo2");
mapZpptrToWord2.put("zpptrby1", "zpwo1");
Map<String, String> mapZpptrToWord3 = new LinkedHashMap<>();
mapZpptrToWord3.put("zpwo1", "zpwo3");
mapZpptrToWord3.put("zpptrby1", "zpwo1");
mapZpptrToWord3.put("zpptrby2", "zpwo2");
Map<String, String> mapSbyToBy = new LinkedHashMap<>();
mapSbyToBy.put("vbsz1", "vbuz1");
mapSbyToBy.put("vbsz2", "vbuz2");
@ -138,15 +124,17 @@ public class AsmFragmentManager {
synths.add(new FragmentSynthesis("vbuz1=(.*)", ".*=.*vb.z1.*", null, "vbuaa=$1", "sta {vbuz1}\n", mapZ));
synths.add(new FragmentSynthesis("vbsz1=(.*)", ".*=.*vb.z1.*", null, "vbsaa=$1", "sta {vbsz1}\n", mapZ));
synths.add(new FragmentSynthesis("_deref_vwuc1=(.*)", null, null, "vbuaa=$1", "sta {c1}\n", mapConst));
synths.add(new FragmentSynthesis("_deref_zpptrby1=(.*)", ".*=.*zpptrby1.*", null, "vbuaa=$1", "ldy #0\n" + "sta ({zpptrby1}),y\n", mapZpptrby));
synths.add(new FragmentSynthesis("_deref_pbuz1=(.*)", ".*=.*z1.*", null, "vbuaa=$1", "ldy #0\n" + "sta ({pbuz1}),y\n", mapZ));
synths.add(new FragmentSynthesis("vwuc1_derefidx_vbuz1=(.*)", null, null, "vbuaa=$1", "ldx {vbuz1}\n"+"sta {c1},x\n", mapZ));
synths.add(new FragmentSynthesis("(.*)=vbuxx(.*)", ".*=.*vb.aa.*", "txa\n", "$1=vbuaa$2", null, null));
synths.add(new FragmentSynthesis("(.*)=vbuyy(.*)", ".*=.*vb.aa.*", "tya\n", "$1=vbuaa$2", null, null));
synths.add(new FragmentSynthesis("(.*)=vbuz1(.*)", ".*=.*vb.aa.*|vbuz1=.*", "lda {vbuz1}\n", "$1=vbuaa$2", null, mapZ));
synths.add(new FragmentSynthesis("(.*)=vbsz1(.*)", ".*=.*vb.aa.*|vbsz1=.*", "lda {vbsz1}\n", "$1=vbuaa$2", null, mapZ));
synths.add(new FragmentSynthesis("(.*)=vbuz2", ".*=.*vb.aa.*|...z2=.*", "lda {vbuz2}\n", "$1=vbuaa", null, null));
synths.add(new FragmentSynthesis("(.*)=vbsz2", ".*=.*vb.aa.*|...z2=.*", "lda {vbsz2}\n", "$1=vbuaa", null, null));
synths.add(new FragmentSynthesis("(.*)=_deref_vwuc1(.*)", ".*=.*vb.aa.*", "lda {c1}\n", "$1=vbuaa$2", null, mapConst));
synths.add(new FragmentSynthesis("(.*)=_deref_zpptrby1(.*)", ".*=.*vb.aa.*|.*=.*vb.yy.*", "ldy #0\n" + "lda ({zpptrby1}),y\n", "$1=vbuaa$2", null, mapZpptrby));
synths.add(new FragmentSynthesis("(.*)=_deref_pb(.)z1(.*)", ".*z1.*=.*|.*=.*vb.aa.*|.*=.*vb.yy.*", "ldy #0\n" + "lda ({z1}),y\n", "$1=vb$2aa$3", null, mapZ));
synths.add(new FragmentSynthesis("(.*)=(.*)_vbuxx", ".*=vb.[ax][ax].*vb.xx|.*derefidx_vb.xx", "txa\n", "$1=$2_vbuaa", null, null));
synths.add(new FragmentSynthesis("(.*)=(.*)_vbsxx", ".*=vb.[ax][ax].*vb.xx|.*derefidx_vb.xx", "txa\n", "$1=$2_vbsaa", null, null));
@ -154,6 +142,7 @@ public class AsmFragmentManager {
synths.add(new FragmentSynthesis("(.*)=(.*)_vbsyy", ".*=[ay]s?by.*vb.yy|.*derefidx_vb.yy", "tya\n", "$1=$2_vbsaa", null, null));
synths.add(new FragmentSynthesis("(.*)=(.*)_vbuz1", ".*=.*vb.aa.*|.*vb.z1.*_vb.z1", "lda {vbuz1}\n", "$1=$2_vbuaa", null, mapZ));
synths.add(new FragmentSynthesis("(.*)=(.*)_vbsz1", ".*=.*vb.aa.*|.*vb.z1.*_vb.z1", "lda {vbsz1}\n", "$1=$2_vbsaa", null, mapZ));
synths.add(new FragmentSynthesis("(.*)=(.*)_vbuz2", ".*=.*vb.aa.*|.*vb.z2.*_vb.z2", "lda {vbuz2}\n", "$1=$2_vbuaa", null, null));
synths.add(new FragmentSynthesis("vbuz1=vbuz1(.*)", ".*=.*vb.aa.*", "lda {vbuz1}\n", "vbuaa=vbuaa$1", "sta {vbuz1}\n", mapZ));
synths.add(new FragmentSynthesis("vbsz1=vbsz1(.*)", ".*=.*vb.aa.*", "lda {vbsz1}\n", "vbsaa=vbsaa$1", "sta {vbsz1}\n", mapZ));
@ -166,7 +155,7 @@ public class AsmFragmentManager {
synths.add(new FragmentSynthesis("vbuz1_(lt|gt|le|ge|eq|neq)_(.*)", ".*vb.aa.*", "lda {vbuz1}\n", "vbuaa_$1_$2", null, mapZ));
synths.add(new FragmentSynthesis("vbsz1_(lt|gt|le|ge|eq|neq)_(.*)", ".*vb.aa.*", "lda {vbsz1}\n", "vbsaa_$1_$2", null, mapZ));
synths.add(new FragmentSynthesis("_deref_vwuc1_(lt|gt|le|ge|eq|neq)_(.*)", ".*vb.aa.*", "lda {c1}\n", "vbuaa_$1_$2", null, mapConst));
synths.add(new FragmentSynthesis("_deref_zpptrby1_(lt|gt|le|ge|eq|neq)_(.*)", ".*=.*vb.aa.*|.*=.*vb.yy.*", "ldy #0\n" + "lda ({zpptrby1}),y\n", "vbuaa_$1_$2", null, mapZpptrby));
synths.add(new FragmentSynthesis("_deref_pb(.)z1_(lt|gt|le|ge|eq|neq)_(.*)", ".*vb.aa.*|.*vb.yy.*|.*z1.*z1.*", "ldy #0\n" + "lda ({z1}),y\n", "vb$1aa_$2_$3", null, mapZ));
synths.add(new FragmentSynthesis("(.*)_ge_(vb.aa)_then_(.*)", ".*vb.aa.*_ge.*", null, "$2_lt_$1_then_$3", null, null));
synths.add(new FragmentSynthesis("(.*)_ge_(vb.xx)_then_(.*)", ".*vb.[ax][ax].*_ge.*", null, "$2_lt_$1_then_$3", null, null));
synths.add(new FragmentSynthesis("(.*)_ge_(vb.yy)_then_(.*)", ".*vb.[axy][axy].*_ge.*", null, "$2_lt_$1_then_$3", null, null));
@ -186,10 +175,8 @@ public class AsmFragmentManager {
synths.add(new FragmentSynthesis("(.*)_eq_(vb.xx)_then_(.*)", ".*vb.[ax][ax].*_eq.*", null, "$2_eq_$1_then_$3", null, null));
synths.add(new FragmentSynthesis("(.*)_eq_(vb.yy)_then_(.*)", ".*vb.[axy][axy].*_eq.*", null, "$2_eq_$1_then_$3", null, null));
synths.add(new FragmentSynthesis("zpptrby1=(vbuc.|vwuc.)_(sethi|setlo|plus|minus)_(.*)", ".*zpwo.*|.*=zpptr.*", null, "zpwo1=$1_$2_$3", null, mapZpptrToWord));
synths.add(new FragmentSynthesis("zpptrby1=zpptrby([12])_(sethi|setlo|plus|minus)_(.*)", ".*zpwo.*", null, "zpwo1=zpwo$1_$2_$3", null, mapZpptrToWord));
synths.add(new FragmentSynthesis("zpptrby1=zpptrby1_(sethi|setlo|plus|minus)_zpwo1", null, null, "zpptrby1=zpptrby1_$1_zpwo1", null, mapZpptrToWord2));
synths.add(new FragmentSynthesis("zpptrby1=zpptrby2_(sethi|setlo|plus|minus)_zpwo1", null, null, "zpptrby1=zpptrby2_$1_zpwo1", null, mapZpptrToWord3));
synths.add(new FragmentSynthesis("p..z1=(.*)_(sethi|setlo|plus|minus)_(.*)", null, null, "vwuz1=$1_$2_$3", null, null));
synths.add(new FragmentSynthesis("(.*)=p..z(.)_(sethi|setlo|plus|minus)_(.*)", null, null, "$1=vwuz$2_$3_$4", null, null));
synths.add(new FragmentSynthesis("(vbsz.|vbsaa|vbsxx|vbsyy)_(eq|neq)_(vbsz.|csoby.|vbsaa|vbsxx|vbsyy)_then_(.*)", null, null, "$1_$2_$3_then_$4", null, mapSbyToBy));
synths.add(new FragmentSynthesis("(vbsz.|vbsaa|vbsxx|vbsyy)=(vbsz.|vbsc.|vbsaa|vbsxx|vbsyy)", null, null, "$1=$2", null, mapSbyToBy));

View File

@ -186,10 +186,7 @@ public class AsmFragmentSignature {
* Zero page register name indexing.
*/
private int nextZpByteIdx = 1;
private int nextZpSByteIdx = 1;
private int nextZpWordIdx = 1;
private int nextZpBoolIdx = 1;
private int nextZpPtrIdx = 1;
private int nextConstByteIdx = 1;
private int nextLabelIdx = 1;
@ -278,17 +275,14 @@ public class AsmFragmentSignature {
return name;
}
} else if (Registers.RegisterType.ZP_WORD.equals(register.getType())) {
String name = "zpwo" + nextZpWordIdx++;
SymbolType varType = ((Variable) value).getType();
String name = getTypePrefix(varType) + getRegisterName(register);
bindings.put(name, value);
return name;
} else if (Registers.RegisterType.ZP_BOOL.equals(register.getType())) {
String name = "zpbo" + nextZpBoolIdx++;
bindings.put(name, value);
return name;
} else if (Registers.RegisterType.ZP_PTR_BYTE.equals(register.getType())) {
String name = "zpptrby" + nextZpPtrIdx++;
bindings.put(name, value);
return name;
} else if (Registers.RegisterType.REG_ALU.equals(register.getType())) {
throw new AsmFragment.AluNotApplicableException();
}
@ -340,6 +334,19 @@ public class AsmFragmentSignature {
return "vbu";
} else if (SymbolType.isSByte(type)) {
return "vbs";
} else if (SymbolType.isWord(type)) {
return "vwu";
} else if (type instanceof SymbolTypePointer ) {
SymbolType elementType = ((SymbolTypePointer) type).getElementType();
if (SymbolType.isByte(elementType)) {
return "pbu";
} else if (SymbolType.isSByte(elementType)) {
return "pbs";
} else if (SymbolType.isWord(elementType)) {
return "pwu";
} else {
throw new RuntimeException("Not implemented "+type);
}
} else {
throw new RuntimeException("Not implemented "+type);
}
@ -353,7 +360,9 @@ public class AsmFragmentSignature {
*/
private String getRegisterName(Registers.Register register) {
if(Registers.RegisterType.ZP_BYTE.equals(register.getType())) {
return "z"+ getRegisterZpNameIdx((Registers.RegisterZp) register);
return "z" + getRegisterZpNameIdx((Registers.RegisterZp) register);
} else if (Registers.RegisterType.ZP_WORD.equals(register.getType())) {
return "z" + getRegisterZpNameIdx((Registers.RegisterZp) register);
} else {
throw new RuntimeException("Not implemented "+register.getType());
}
@ -366,14 +375,13 @@ public class AsmFragmentSignature {
* @return The index. Either reused ot allocated from {@link #nextZpByteIdx}
*/
private String getRegisterZpNameIdx(Registers.RegisterZp register) {
Registers.RegisterZp registerZp = register;
for (String boundName : bindings.keySet()) {
Value boundValue = bindings.get(boundName);
if(boundValue instanceof Variable) {
Registers.Register boundRegister = ((Variable) boundValue).getAllocation();
if(boundRegister!=null && boundRegister.isZp()) {
Registers.RegisterZp boundRegisterZp = (Registers.RegisterZp) boundRegister;
if(registerZp.getZp()==boundRegisterZp.getZp()) {
if(register.getZp()==boundRegisterZp.getZp()) {
// Found other register with same ZP address!
return boundName.substring(boundName.length()-1);
}

View File

@ -0,0 +1,2 @@
ldy #0
sta ({z1}),y

View File

@ -0,0 +1,3 @@
ldy #0
lda #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
txa
ldy #0
sta ({z1}),y

View File

@ -0,0 +1,3 @@
tya
ldy #0
sta ({z1}),y

View File

@ -0,0 +1,3 @@
ldy #0
lda {z2}
sta ({z1}),y

View File

@ -1,2 +0,0 @@
ldy #0
sta ({zpptrby1}),y

View File

@ -1,3 +0,0 @@
ldy #0
lda #{c1}
sta ({zpptrby1}),y

View File

@ -1,3 +0,0 @@
txa
ldy #0
sta ({zpptrby1}),y

View File

@ -1,3 +0,0 @@
tya
ldy #0
sta ({zpptrby1}),y

View File

@ -1,3 +0,0 @@
ldy #0
lda {z1}
sta ({zpptrby1}),y

View File

@ -0,0 +1,4 @@
inc {z1}
bne !+
inc {z1}+1
!:

View File

@ -0,0 +1,7 @@
lda {z2}
clc
adc #1
sta {z1}
lda {z2}+1
adc #0
sta {z1}+1

View File

@ -0,0 +1,4 @@
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z1}
sec
sbc #{c1}
sta {z1}
bcs !+
dec {z1}+1
!:

View File

@ -0,0 +1,4 @@
inc {z1}
bne !+
inc {z1}+1
!:

View File

@ -0,0 +1,6 @@
lda {z1}
asl
sta {z1}
lda {z1}+1
rol
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z1}
clc
adc {z2}
sta {z1}
lda {z1}+1
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z1}
clc
adc #{c1}
sta {z1}
bcc !+
inc {z1}+1
!:

View File

@ -0,0 +1,8 @@
lda {z1}
clc
adc #<{c1}
sta {z1}
lda {z1}+1
adc #>{c1}
sta {z1}+1

View File

@ -0,0 +1,4 @@
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1

View File

@ -0,0 +1,4 @@
lda {z2}
sta {z1}
lda {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z2}
clc
adc #1
sta {z1}
lda {z2}+1
adc #0
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z2}
clc
adc {z3}
sta {z1}
lda {z2}+1
adc {z3}+1
sta {z1}+1

View File

@ -0,0 +1,6 @@
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda #{c1}
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
txa
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
tya
clc
adc {z2}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z2}
clc
adc {z3}
sta {z1}
lda #0
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda {z2}
clc
adc #<{c1}
sta {z1}
lda {z2}+1
adc #>{c1}
sta {z1}+1

View File

@ -0,0 +1,4 @@
lda #{c1}
sta {z1}
lda #0
sta {z1}+1

View File

@ -0,0 +1,4 @@
lda #<{c1}
sta {z1}
lda #>{c1}
sta {z1}+1

View File

@ -1,7 +1,7 @@
txa
clc
adc #<{c1}
sta {zpptrby1}
sta {z1}
lda #0
adc #>{c1}
sta {zpptrby1}+1
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda #<{c1}
clc
adc {z2}
sta {z1}
lda #>{c1}
adc #0
sta {z1}+1

View File

@ -0,0 +1,7 @@
lda #<{c1}
clc
adc {z2}
sta {z1}
lda #>{c1}
adc {z2}+1
sta {z1}+1

View File

@ -0,0 +1,2 @@
tay
sta ({z1}),y

View File

@ -0,0 +1,3 @@
tay
lda #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
tay
lda {z2}
sta ({z1}),y

View File

@ -0,0 +1,2 @@
ldy #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
txa
ldy #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
tya
ldy #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
lda {z2}
ldy #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
stx $ff
ldy $ff
sta ({z1}),y

View File

@ -0,0 +1,4 @@
txa
tay
lda #{c1}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
txa
tay
sta ({z1}),y

View File

@ -0,0 +1,4 @@
txa
tay
lda {z2}
sta ({z1}),y

View File

@ -0,0 +1 @@
sta ({z1}),y

View File

@ -0,0 +1,2 @@
lda #{c1}
sta ({z1}),y

View File

@ -0,0 +1,2 @@
txa
sta ({z1}),y

View File

@ -0,0 +1,2 @@
tya
sta ({z1}),y

View File

@ -0,0 +1,2 @@
lda {z2}
sta ({z1}),y

View File

@ -0,0 +1,2 @@
ldy {z2}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
lda #{c1}
ldy {z2}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
ldy {z2}
txa
sta ({z1}),y

View File

@ -0,0 +1,3 @@
tya
ldy {z2}
sta ({z1}),y

View File

@ -0,0 +1,3 @@
lda {z2}
tay
sta ({z1}),y

View File

@ -0,0 +1,3 @@
lda {z3}
ldy {z2}
sta ({z1}),y

View File

@ -0,0 +1,8 @@
lda {z1}+1
cmp {z2}+1
bcc {la1}
bne !+
lda {z1}
cmp {z2}
bcc {la1}
!:

View File

@ -1,8 +1,8 @@
lda {zpptrby1}+1
lda {z1}+1
cmp #>{c1}
bcc {la1}
bne !+
lda {zpptrby1}
lda {z1}
cmp #<{c1}
bcc {la1}
!:

View File

@ -1,6 +1,6 @@
lda {zpptrby1}+1
lda {z1}+1
cmp #>{c1}
bne {la1}
lda {zpptrby1}
lda {z1}
cmp #<{c1}
bne {la1}

View File

@ -0,0 +1 @@
lda {z1}

View File

@ -0,0 +1,2 @@
ldy #0
lda ({z1}),y

View File

@ -1,2 +0,0 @@
ldy #0
lda ({zpptrby1}),y

View File

@ -0,0 +1 @@
lda {z1}+1

View File

@ -0,0 +1 @@
lda {z1}+1

View File

@ -0,0 +1 @@
lda {z1}

View File

@ -0,0 +1 @@
lda {z1}

View File

@ -0,0 +1,2 @@
tay
lda ({z1}),y

View File

@ -0,0 +1,2 @@
ldy #{c1}
lda ({z1}),y

View File

@ -0,0 +1,3 @@
stx $ff
ldy $ff
lda ({z1}),y

View File

@ -0,0 +1 @@
lda ({z1}),y

View File

@ -0,0 +1,2 @@
ldy {z2}
lda ({z1}),y

View File

@ -0,0 +1,2 @@
ldy #0
ora ({z1}),y

View File

@ -1,2 +0,0 @@
ldy #0
ora ({zpptrby1}),y

View File

@ -0,0 +1 @@
ora >{z1}

View File

@ -0,0 +1 @@
ora <{z1}

View File

@ -1,2 +0,0 @@
tay
lda ({zpptrby1}),y

View File

@ -1,2 +0,0 @@
ldy #{c1}
lda ({zpptrby1}),y

View File

@ -1,3 +0,0 @@
stx $ff
ldy $ff
lda ({zpptrby1}),y

View File

@ -1,2 +0,0 @@
ldy {z1}
lda ({zpptrby1}),y

View File

@ -0,0 +1,3 @@
ldy #0
lda ({z1}),y
tax

View File

@ -1,3 +0,0 @@
ldy #0
lda ({zpptrby1}),y
tax

View File

@ -0,0 +1,3 @@
ldy {z3}
lda ({z2}),y
sta {z1}

View File

@ -1,3 +0,0 @@
ldy {z2}
lda ({zpptrby1}),y
sta {z1}

View File

@ -1,9 +1,9 @@
lda #<{c1}
clc
adc {zpwo1}
adc {z1}
sta !+ +1
lda #>{c1}
adc {zpwo1}+1
adc {z1}+1
sta !+ +2
lda #{c2}
!: sta {c1}

View File

@ -0,0 +1,4 @@
inc {z1}
bne !+
inc {z1}+1
!:

Some files were not shown because too many files have changed in this diff Show More