From 39c4f0d6b4d1a24bf76b8d5d3d048b7cb244e3f8 Mon Sep 17 00:00:00 2001 From: Jesper Gravgaard Date: Wed, 22 May 2019 15:29:47 +0200 Subject: [PATCH] Fixed identification of identical Phi RValues that are constant pointers to symbols. --- src/main/fragment/_deref_pptc1=pbuz1.asm | 4 ++ .../model/values/ConstantSymbolPointer.java | 16 ++++++++ src/test/ref/hex2dec-ptrptr.asm | 38 ++++--------------- src/test/ref/pointer-pointer-3.asm | 19 ++-------- src/test/ref/ptrptr-optimize-2.asm | 28 ++++---------- 5 files changed, 38 insertions(+), 67 deletions(-) create mode 100644 src/main/fragment/_deref_pptc1=pbuz1.asm diff --git a/src/main/fragment/_deref_pptc1=pbuz1.asm b/src/main/fragment/_deref_pptc1=pbuz1.asm new file mode 100644 index 000000000..0e0382e79 --- /dev/null +++ b/src/main/fragment/_deref_pptc1=pbuz1.asm @@ -0,0 +1,4 @@ +lda {z1} +sta {c1} +lda {z1}+1 +sta {c1}+1 \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/model/values/ConstantSymbolPointer.java b/src/main/java/dk/camelot64/kickc/model/values/ConstantSymbolPointer.java index 4474cb416..4f7c079a9 100644 --- a/src/main/java/dk/camelot64/kickc/model/values/ConstantSymbolPointer.java +++ b/src/main/java/dk/camelot64/kickc/model/values/ConstantSymbolPointer.java @@ -6,6 +6,8 @@ import dk.camelot64.kickc.model.symbols.Symbol; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypePointer; +import java.util.Objects; + /** A pointer to a symbol (variable or procedure) */ public class ConstantSymbolPointer implements ConstantValue { @@ -44,4 +46,18 @@ public class ConstantSymbolPointer implements ConstantValue { public String toString() { return toString(null); } + + @Override + public boolean equals(Object o) { + if(this == o) return true; + if(o == null || getClass() != o.getClass()) return false; + ConstantSymbolPointer that = (ConstantSymbolPointer) o; + return Objects.equals(toSymbol, that.toSymbol); + } + + @Override + public int hashCode() { + + return Objects.hash(toSymbol); + } } diff --git a/src/test/ref/hex2dec-ptrptr.asm b/src/test/ref/hex2dec-ptrptr.asm index 3c58ffe2c..af42a6775 100644 --- a/src/test/ref/hex2dec-ptrptr.asm +++ b/src/test/ref/hex2dec-ptrptr.asm @@ -60,39 +60,19 @@ utoa16w: { lsr lsr lsr - tay - lda #dst - sta utoa16n.dst+1 ldx #0 jsr utoa16n lda value+1 and #$f - tay - lda #dst - sta utoa16n.dst+1 jsr utoa16n lda value lsr lsr lsr lsr - tay - lda #dst - sta utoa16n.dst+1 jsr utoa16n lda value and #$f - tay - lda #dst - sta utoa16n.dst+1 ldx #1 jsr utoa16n lda #0 @@ -101,26 +81,22 @@ utoa16w: { rts } // Hexadecimal utoa() for a single nybble -// utoa16n(byte register(Y) nybble, word** zeropage(6) dst, byte register(X) started) +// utoa16n(byte register(A) nybble, byte register(X) started) utoa16n: { - .label dst = 6 - cpy #0 + cmp #0 beq b1 ldx #1 b1: cpx #0 beq breturn + tay lda DIGITS,y - ldy dst - sty !++1 ldy #0 + sta (utoa16w.dst),y + inc utoa16w.dst + bne !+ + inc utoa16w.dst+1 !: - sta ($ff),y - ldy #0 - lda (dst),y - clc - adc #1 - sta (dst),y breturn: rts } diff --git a/src/test/ref/pointer-pointer-3.asm b/src/test/ref/pointer-pointer-3.asm index 8d95438d3..079d897cf 100644 --- a/src/test/ref/pointer-pointer-3.asm +++ b/src/test/ref/pointer-pointer-3.asm @@ -4,7 +4,7 @@ .pc = $80d "Program" .label screen1 = $400 .label screen2 = $400+$28 - .label screen = 6 + .label screen = 4 bbegin: lda #<$400 sta screen @@ -13,10 +13,6 @@ bbegin: jsr main rts main: { - lda #screen - sta setscreen.screen+1 lda #screen1 @@ -25,10 +21,6 @@ main: { lda #'a' ldy #0 sta (screen),y - lda #screen - sta setscreen.screen+1 lda #screen2 @@ -39,15 +31,12 @@ main: { sta (screen),y rts } -// setscreen(byte** zeropage(4) screen, byte* zeropage(2) val) +// setscreen(byte* zeropage(2) val) setscreen: { .label val = 2 - .label screen = 4 - ldy #0 lda val - sta (screen),y - iny + sta screen lda val+1 - sta (screen),y + sta screen+1 rts } diff --git a/src/test/ref/ptrptr-optimize-2.asm b/src/test/ref/ptrptr-optimize-2.asm index 0105bd47d..afc340a19 100644 --- a/src/test/ref/ptrptr-optimize-2.asm +++ b/src/test/ref/ptrptr-optimize-2.asm @@ -9,33 +9,19 @@ main: { sta screen lda #>$400 sta screen+1 - lda #screen - sta sub.dst+1 - ldx #'a' + lda #'a' jsr sub - lda #screen - sta sub.dst+1 - ldx #'b' + lda #'b' jsr sub rts } -// sub(byte register(X) ch, byte** zeropage(2) dst) +// sub(byte register(A) ch) sub: { - .label dst = 2 - txa - ldy dst - sty !++1 ldy #0 + sta (main.screen),y + inc main.screen + bne !+ + inc main.screen+1 !: - sta ($ff),y - ldy #0 - lda (dst),y - clc - adc #1 - sta (dst),y rts }