1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-29 06:30:30 +00:00

Improved code generation, better tracking.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4108 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-09-01 10:07:02 +00:00
parent cdc3afa6ef
commit e9eb9eb77c
2 changed files with 78 additions and 67 deletions

View File

@ -557,6 +557,9 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
} else { } else {
Out->RegA = UNKNOWN_REGVAL; Out->RegA = UNKNOWN_REGVAL;
} }
} else if (CE_IsKnownImm (E, 0)) {
/* A and $00 does always give zero */
Out->RegA = 0;
} }
break; break;
@ -985,6 +988,9 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
/* A is now unknown */ /* A is now unknown */
Out->RegA = UNKNOWN_REGVAL; Out->RegA = UNKNOWN_REGVAL;
} }
} else if (CE_IsKnownImm (E, 0xFF)) {
/* ORA with 0xFF does always give 0xFF */
Out->RegA = 0xFF;
} }
break; break;

View File

@ -814,22 +814,22 @@ void g_getstatic (unsigned flags, unsigned long label, long offs)
void g_getlocal (unsigned flags, int offs) void g_getlocal (unsigned Flags, int Offs)
/* Fetch specified local object (local var). */ /* Fetch specified local object (local var). */
{ {
offs -= StackPtr; Offs -= StackPtr;
CheckLocalOffs (offs); switch (Flags & CF_TYPE) {
switch (flags & CF_TYPE) {
case CF_CHAR: case CF_CHAR:
if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) { CheckLocalOffs (Offs);
ldyconst (offs); if ((Flags & CF_FORCECHAR) || (Flags & CF_TEST)) {
ldyconst (Offs);
AddCodeLine ("lda (sp),y"); AddCodeLine ("lda (sp),y");
} else { } else {
ldyconst (offs); ldyconst (Offs);
AddCodeLine ("ldx #$00"); AddCodeLine ("ldx #$00");
AddCodeLine ("lda (sp),y"); AddCodeLine ("lda (sp),y");
if ((flags & CF_UNSIGNED) == 0) { if ((Flags & CF_UNSIGNED) == 0) {
unsigned L = GetLocalLabel(); unsigned L = GetLocalLabel();
AddCodeLine ("bpl %s", LocalLabelName (L)); AddCodeLine ("bpl %s", LocalLabelName (L));
AddCodeLine ("dex"); AddCodeLine ("dex");
@ -839,34 +839,39 @@ void g_getlocal (unsigned flags, int offs)
break; break;
case CF_INT: case CF_INT:
CheckLocalOffs (offs + 1); CheckLocalOffs (Offs + 1);
if (flags & CF_TEST) { AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+1));
ldyconst (offs + 1); if (Flags & CF_TEST) {
AddCodeLine ("lda (sp),y"); AddCodeLine ("lda (sp),y");
AddCodeLine ("dey"); AddCodeLine ("dey");
AddCodeLine ("ora (sp),y"); AddCodeLine ("ora (sp),y");
} else { } else if (IS_Get (&CodeSizeFactor) < 165) {
ldyconst (offs+1);
AddCodeLine ("jsr ldaxysp"); AddCodeLine ("jsr ldaxysp");
} else {
AddCodeLine ("lda (sp),y");
AddCodeLine ("tax");
AddCodeLine ("dey");
AddCodeLine ("lda (sp),y");
} }
break; break;
case CF_LONG: case CF_LONG:
ldyconst (offs+3); CheckLocalOffs (Offs + 3);
AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+3));
AddCodeLine ("jsr ldeaxysp"); AddCodeLine ("jsr ldeaxysp");
if (flags & CF_TEST) { if (Flags & CF_TEST) {
g_test (flags); g_test (Flags);
} }
break; break;
default: default:
typeerror (flags); typeerror (Flags);
} }
} }
void g_getind (unsigned flags, unsigned offs) void g_getind (unsigned Flags, unsigned Offs)
/* Fetch the specified object type indirect through the primary register /* Fetch the specified object type indirect through the primary register
* into the primary register * into the primary register
*/ */
@ -875,46 +880,46 @@ void g_getind (unsigned flags, unsigned offs)
* the primary. This way we get an easy addition and use the low byte * the primary. This way we get an easy addition and use the low byte
* as the offset * as the offset
*/ */
offs = MakeByteOffs (flags, offs); Offs = MakeByteOffs (Flags, Offs);
/* Handle the indirect fetch */ /* Handle the indirect fetch */
switch (flags & CF_TYPE) { switch (Flags & CF_TYPE) {
case CF_CHAR: case CF_CHAR:
/* Character sized */ /* Character sized */
if (flags & CF_UNSIGNED) { if (Flags & CF_UNSIGNED) {
ldyconst (offs); ldyconst (Offs);
AddCodeLine ("jsr ldauidx"); AddCodeLine ("jsr ldauidx");
} else { } else {
ldyconst (offs); ldyconst (Offs);
AddCodeLine ("jsr ldaidx"); AddCodeLine ("jsr ldaidx");
} }
break; break;
case CF_INT: case CF_INT:
if (flags & CF_TEST) { if (Flags & CF_TEST) {
ldyconst (offs); ldyconst (Offs);
AddCodeLine ("sta ptr1"); AddCodeLine ("sta ptr1");
AddCodeLine ("stx ptr1+1"); AddCodeLine ("stx ptr1+1");
AddCodeLine ("lda (ptr1),y"); AddCodeLine ("lda (ptr1),y");
AddCodeLine ("iny"); AddCodeLine ("iny");
AddCodeLine ("ora (ptr1),y"); AddCodeLine ("ora (ptr1),y");
} else { } else {
ldyconst (offs+1); ldyconst (Offs+1);
AddCodeLine ("jsr ldaxidx"); AddCodeLine ("jsr ldaxidx");
} }
break; break;
case CF_LONG: case CF_LONG:
ldyconst (offs+3); ldyconst (Offs+3);
AddCodeLine ("jsr ldeaxidx"); AddCodeLine ("jsr ldeaxidx");
if (flags & CF_TEST) { if (Flags & CF_TEST) {
g_test (flags); g_test (Flags);
} }
break; break;
default: default:
typeerror (flags); typeerror (Flags);
} }
} }