mirror of
https://github.com/fadden/6502bench.git
synced 2024-12-27 10:32:31 +00:00
Improve Common expression generation
Removed unnecessary parenthesis from Common-style expressions, which are used by 64tass and ACME.
This commit is contained in:
parent
7d1d7f9c56
commit
4d06bb24eb
@ -705,8 +705,6 @@ namespace SourceGen {
|
||||
// just use the byte-select operators, for wider ops we get only as fancy as we
|
||||
// need to be.
|
||||
|
||||
int adjustment, symbolValue;
|
||||
|
||||
// Start by remapping the label, if necessary. The remapped label may have a
|
||||
// local-variable prefix character.
|
||||
string symLabel = sym.Label;
|
||||
@ -727,6 +725,7 @@ namespace SourceGen {
|
||||
if (operandLen == 1) {
|
||||
// Use the byte-selection operator to get the right piece. In 64tass the
|
||||
// selection operator has a very low precedence, similar to Merlin 32.
|
||||
int symbolValue;
|
||||
string selOp;
|
||||
if (dfd.SymbolRef.ValuePart == WeakSymbolRef.Part.Bank) {
|
||||
symbolValue = (sym.Value >> 16) & 0xff;
|
||||
@ -757,16 +756,18 @@ namespace SourceGen {
|
||||
sb.Append(symLabel);
|
||||
sb.Append(')');
|
||||
} else {
|
||||
// no adjustment required
|
||||
// no adjustment required, or no byte-selection
|
||||
sb.Append(selOp);
|
||||
sb.Append(symLabel);
|
||||
}
|
||||
int adjustment = operandValue - symbolValue;
|
||||
sb.Append(formatter.FormatAdjustment(adjustment));
|
||||
} else if (operandLen <= 4) {
|
||||
// Operands and values should be 8/16/24 bit unsigned quantities. 32-bit
|
||||
// support is really there so you can have a 24-bit pointer in a 32-bit hole.
|
||||
// Might need to adjust this if 32-bit signed quantities become interesting.
|
||||
uint mask = 0xffffffff >> ((4 - operandLen) * 8);
|
||||
int rightShift;
|
||||
int rightShift, symbolValue;
|
||||
if (dfd.SymbolRef.ValuePart == WeakSymbolRef.Part.Bank) {
|
||||
symbolValue = (sym.Value >> 16);
|
||||
rightShift = 16;
|
||||
@ -777,6 +778,7 @@ namespace SourceGen {
|
||||
symbolValue = sym.Value;
|
||||
rightShift = 0;
|
||||
}
|
||||
bool hasShift = (rightShift != 0);
|
||||
|
||||
if ((flags & FormatNumericOpFlags.IsPcRel) != 0) {
|
||||
// PC-relative operands are funny, because an 8- or 16-bit value is always
|
||||
@ -809,45 +811,53 @@ namespace SourceGen {
|
||||
}
|
||||
|
||||
operandValue = (int)(operandValue & mask);
|
||||
int adjustment = operandValue - symbolValue;
|
||||
|
||||
// Generate one of:
|
||||
// label [+ adj]
|
||||
// (label >> rightShift) [+ adj]
|
||||
// (label & mask) [+ adj]
|
||||
// ((label >> rightShift) & mask) [+ adj]
|
||||
// Possibilities:
|
||||
// label
|
||||
// label + adj
|
||||
// label >> rightShift
|
||||
// (label >> rightShift) + adj
|
||||
// label & mask
|
||||
// (label & mask) + adj
|
||||
// (label >> rightShift) & mask
|
||||
// ((label >> rightShift) & mask) + adj
|
||||
|
||||
if (rightShift != 0 || needMask) {
|
||||
if ((flags & FormatNumericOpFlags.HasHashPrefix) == 0) {
|
||||
sb.Append("0+");
|
||||
}
|
||||
if (rightShift != 0 && needMask) {
|
||||
sb.Append("((");
|
||||
} else {
|
||||
sb.Append("(");
|
||||
}
|
||||
}
|
||||
sb.Append(symLabel);
|
||||
|
||||
if (rightShift != 0) {
|
||||
sb.Append(" >> ");
|
||||
sb.Append(rightShift.ToString());
|
||||
sb.Append(')');
|
||||
}
|
||||
|
||||
if (needMask) {
|
||||
if (rightShift != 0) {
|
||||
sb.Insert(0, '(');
|
||||
sb.Append(')');
|
||||
}
|
||||
|
||||
sb.Append(" & ");
|
||||
sb.Append(formatter.FormatHexValue((int)mask, 2));
|
||||
sb.Append(')');
|
||||
}
|
||||
|
||||
if (adjustment != 0) {
|
||||
if (needMask || rightShift != 0) {
|
||||
sb.Insert(0, '(');
|
||||
sb.Append(')');
|
||||
}
|
||||
|
||||
sb.Append(formatter.FormatAdjustment(adjustment));
|
||||
}
|
||||
|
||||
// Starting with a '(' makes it look like an indirect operand, so we need
|
||||
// to prefix the expression with a no-op addition.
|
||||
if (sb[0] == '(' && (flags & FormatNumericOpFlags.HasHashPrefix) == 0) {
|
||||
sb.Insert(0, "0+");
|
||||
}
|
||||
} else {
|
||||
Debug.Assert(false, "bad numeric len");
|
||||
sb.Append("?????");
|
||||
symbolValue = 0;
|
||||
}
|
||||
|
||||
adjustment = operandValue - symbolValue;
|
||||
|
||||
sb.Append(formatter.FormatAdjustment(adjustment));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -862,7 +872,7 @@ namespace SourceGen {
|
||||
// and divide.) This means that, if we want to mask off the low 16 bits and add one
|
||||
// to a label, we can write "start & $ffff + 1" rather than "(start & $ffff) + 1".
|
||||
//
|
||||
// This is particularly convenient for PEA, since "PEA (start & $ffff)" looks like
|
||||
// This is particularly convenient for PEA, since "PEA (start & $ffff) + 1" looks like
|
||||
// we're trying to use a (non-existent) indirect form of PEA. We can write things
|
||||
// in a simpler way.
|
||||
|
||||
|
@ -40,23 +40,23 @@ start lda #zip
|
||||
.byte >start
|
||||
.word zip
|
||||
.word absl
|
||||
.word 0+(absl >> 8)
|
||||
.word absl >> 8
|
||||
.word absl-$1000
|
||||
.word 0+(absl >> 8)-16
|
||||
.word absh
|
||||
.word 0+(absh >> 8)
|
||||
.word absh >> 8
|
||||
.word absh-$f000
|
||||
.word 0+(absh >> 8)+16
|
||||
.word start
|
||||
.word 0+(start >> 8)
|
||||
.word start >> 8
|
||||
.word start+1
|
||||
.word 0+(start >> 8)
|
||||
.word start >> 8
|
||||
.byte $fe,$ed
|
||||
.long zip
|
||||
.long absh
|
||||
.long 0+(absh >> 8)
|
||||
.long absh >> 8
|
||||
.long start
|
||||
.long 0+(start >> 8)
|
||||
.long start >> 8
|
||||
|
||||
_L23A3 jmp _L1000_1
|
||||
|
||||
|
@ -39,23 +39,23 @@ start lda #zip
|
||||
!byte >start
|
||||
!word zip
|
||||
!word absl
|
||||
!word 0+(absl >> 8)
|
||||
!word absl >> 8
|
||||
!word absl-$1000
|
||||
!word 0+(absl >> 8)-16
|
||||
!word absh
|
||||
!word 0+(absh >> 8)
|
||||
!word absh >> 8
|
||||
!word absh-$f000
|
||||
!word 0+(absh >> 8)+16
|
||||
!word start
|
||||
!word 0+(start >> 8)
|
||||
!word start >> 8
|
||||
!word start+1
|
||||
!word 0+(start >> 8)
|
||||
!word start >> 8
|
||||
!byte $fe,$ed
|
||||
!24 zip
|
||||
!24 absh
|
||||
!24 0+(absh >> 8)
|
||||
!24 absh >> 8
|
||||
!24 start
|
||||
!24 0+(start >> 8)
|
||||
!24 start >> 8
|
||||
|
||||
@L23A3 jmp @L1000_1
|
||||
|
||||
|
@ -34,15 +34,15 @@ start clc
|
||||
lda #>start
|
||||
lda #`start
|
||||
pea $feed
|
||||
pea 0+(start & $ffff)
|
||||
pea start & $ffff
|
||||
pea $0001
|
||||
pea $3456
|
||||
pea $0012
|
||||
pea absh
|
||||
pea 0+(start & $ffff)
|
||||
pea 0+(start >> 16)
|
||||
pea 0+(biggie & $ffff)
|
||||
pea 0+(biggie >> 16)
|
||||
pea start & $ffff
|
||||
pea start >> 16
|
||||
pea biggie & $ffff
|
||||
pea biggie >> 16
|
||||
lda zip+1
|
||||
lda @wzip+1
|
||||
lda @lzip+1
|
||||
@ -65,21 +65,21 @@ start clc
|
||||
lda #zip+16
|
||||
lda #zip+64
|
||||
lda #absl
|
||||
lda #(absl >> 8)
|
||||
lda #absl >> 8
|
||||
lda #absl-$1000
|
||||
lda #(absl >> 8)-16
|
||||
lda #(absl >> 16)
|
||||
lda #absl >> 16
|
||||
lda #absh
|
||||
lda #(absh >> 8)
|
||||
lda #absh >> 8
|
||||
lda #absh-$f000
|
||||
lda #(absh >> 8)+16
|
||||
lda #(absh >> 16)+1
|
||||
lda #(start & $ffff)
|
||||
lda #(start >> 8)
|
||||
lda #(start >> 16)
|
||||
lda #(biggie & $ffff)
|
||||
lda #(biggie >> 8)
|
||||
lda #(biggie >> 16)
|
||||
lda #start & $ffff
|
||||
lda #start >> 8
|
||||
lda #start >> 16
|
||||
lda #biggie & $ffff
|
||||
lda #biggie >> 8
|
||||
lda #biggie >> 16
|
||||
bra _skipdata
|
||||
|
||||
.byte zip
|
||||
@ -90,32 +90,32 @@ start clc
|
||||
.byte `start
|
||||
.word zip
|
||||
.word absl
|
||||
.word 0+(absl >> 8)
|
||||
.word absl >> 8
|
||||
.word absl-$1000
|
||||
.word 0+(absl >> 8)-16
|
||||
.word absh
|
||||
.word 0+(absh >> 8)
|
||||
.word absh >> 8
|
||||
.word absh-$f000
|
||||
.word 0+(absh >> 8)+16
|
||||
.word 0+(start & $ffff)
|
||||
.word 0+(start >> 8)
|
||||
.word 0+(start >> 16)
|
||||
.word start & $ffff
|
||||
.word start >> 8
|
||||
.word start >> 16
|
||||
.word 0+(start & $ffff)+1
|
||||
.word 0+(start >> 8)
|
||||
.word 0+(start >> 16)
|
||||
.word start >> 8
|
||||
.word start >> 16
|
||||
.byte $fe,$ed
|
||||
.long zip
|
||||
.long absh
|
||||
.long 0+(absh >> 8)
|
||||
.long absh >> 8
|
||||
.long start
|
||||
.long 0+(start >> 8)
|
||||
.long 0+(start >> 16)
|
||||
.long start >> 8
|
||||
.long start >> 16
|
||||
.dword zip
|
||||
.dword absh
|
||||
.dword 0+(absh >> 8)
|
||||
.dword absh >> 8
|
||||
.dword start-1
|
||||
.dword 0+(start >> 8)
|
||||
.dword 0+(start >> 16)
|
||||
.dword start >> 8
|
||||
.dword start >> 16
|
||||
|
||||
_skipdata lda #(biggie >> 16)-1
|
||||
mvn #`biggie,#(`biggie)-17
|
||||
@ -207,7 +207,7 @@ _L118E lda #<thirty2+2
|
||||
.xl
|
||||
lda #(thirty2 & $ffff)+3
|
||||
lda #((thirty2 >> 8) & $ffff)+4
|
||||
lda #(thirty2 >> 16)
|
||||
lda #thirty2 >> 16
|
||||
rts
|
||||
|
||||
.here
|
||||
|
@ -17,14 +17,14 @@ lodat .byte $00
|
||||
.logical $440000
|
||||
L440000 cmp L440000
|
||||
L440004 lda L440000
|
||||
lda @w0+(L440000 & $ffff)
|
||||
lda @wL440000 & $ffff
|
||||
lda zero
|
||||
bmi L440004
|
||||
per high44
|
||||
bne high44
|
||||
brl L44FFC0
|
||||
|
||||
dat44 .word 0+(dat44 & $ffff)
|
||||
dat44 .word dat44 & $ffff
|
||||
.long dat44
|
||||
|
||||
.here
|
||||
@ -39,8 +39,8 @@ _L44FFCB jml _L2000
|
||||
.here
|
||||
.logical $2000
|
||||
_L2000 bit _L2000
|
||||
pea 0+(dat44 & $ffff)
|
||||
pea 0+(dat44 >> 16)
|
||||
pea dat44 & $ffff
|
||||
pea dat44 >> 16
|
||||
bne skip
|
||||
jml [lodat]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user