65C02 additions, saved a few bytes in the code generator

git-svn-id: svn://svn.cc65.org/cc65/trunk@80 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-06-14 16:58:52 +00:00
parent 409d12534b
commit 500233166a
2 changed files with 147 additions and 115 deletions

View File

@@ -790,8 +790,12 @@ void g_getlocal (unsigned flags, int offs)
case CF_CHAR: case CF_CHAR:
if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) { if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) {
if (CPU == CPU_65C02 && offs == 0) {
AddCodeLine ("\tlda\t(sp)");
} else {
ldyconst (offs); ldyconst (offs);
AddCodeLine ("\tlda\t(sp),y"); AddCodeLine ("\tlda\t(sp),y");
}
} else { } else {
if (offs == 0) { if (offs == 0) {
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
@@ -1004,8 +1008,12 @@ void g_putlocal (unsigned flags, int offs)
switch (flags & CF_TYPE) { switch (flags & CF_TYPE) {
case CF_CHAR: case CF_CHAR:
if (CPU == CPU_65C02 && offs == 0) {
AddCodeLine ("\tsta\t(sp)");
} else {
ldyconst (offs); ldyconst (offs);
AddCodeLine ("\tsta\t(sp),y"); AddCodeLine ("\tsta\t(sp),y");
}
break; break;
case CF_INT: case CF_INT:
@@ -3741,8 +3749,8 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
AddCodeLine ("\tiny"); AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t%s,y", lbuf); AddCodeLine ("\tlda\t%s,y", lbuf);
AddCodeLine ("\tbne\tL%04X", label); AddCodeLine ("\tbne\tL%04X", label);
AddCodeLine ("\ttax");
AddCodeLine ("\ttya"); AddCodeLine ("\ttya");
AddCodeLine ("\tldx\t#$00");
} else { } else {
@@ -3759,8 +3767,8 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
AddCodeLine ("\tiny"); AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t(ptr1),y"); AddCodeLine ("\tlda\t(ptr1),y");
AddCodeLine ("\tbne\tL%04X", label); AddCodeLine ("\tbne\tL%04X", label);
AddCodeLine ("\ttax");
AddCodeLine ("\ttya"); AddCodeLine ("\ttya");
AddCodeLine ("\tldx\t#$00");
} }
} }
} }

View File

@@ -1103,7 +1103,7 @@ static unsigned RVUInt2 (Line* L,
do { do {
/* Handle jumps to local labels (continue there) */ /* Handle jumps to local labels (continue there) */
if (LineMatch (L, "\tjmp\tL")) { if (LineMatch (L, "\tjmp\tL") || LineMatch (L, "\tbra\tL")) {
/* Get the target of the jump */ /* Get the target of the jump */
L = GetTargetLine (L->Line+5); L = GetTargetLine (L->Line+5);
} }
@@ -1124,7 +1124,7 @@ static unsigned RVUInt2 (Line* L,
goto ExitPoint; goto ExitPoint;
} }
} while (LineMatch (L, "\tjmp\tL")); } while (LineMatch (L, "\tjmp\tL") || LineMatch (L, "\tbra\tL"));
/* Special handling for branches */ /* Special handling for branches */
if (LineMatchX (L, ShortBranches) >= 0 || if (LineMatchX (L, ShortBranches) >= 0 ||
@@ -3867,6 +3867,10 @@ static Line* OptOneBlock (Line* L)
} else if (LineFullMatch (L, "\tjsr\tpushax")) { } else if (LineFullMatch (L, "\tjsr\tpushax")) {
/* We know about this function */ /* We know about this function */
Y = 1; Y = 1;
} else if (LineFullMatch (L, "\tjsr\tpushaysp")) {
/* We know about this function */
A = -1;
Y = 0;
} else if (LineFullMatch (L, "\tjsr\tpushc0")) { } else if (LineFullMatch (L, "\tjsr\tpushc0")) {
/* We know about this function */ /* We know about this function */
A = 0; A = 0;
@@ -4196,6 +4200,26 @@ static void OptJumps (void)
} }
L = NextCodeLine (L); L = NextCodeLine (L);
} }
/* Special treatment for jumps on the 65C02 */
if (CPU == CPU_65C02) {
Line* L = FirstCode;
while (L) {
if (LineMatch (L, "\tjmp\tL")) {
Line* Target = GetTargetLine (L->Line+5);
unsigned Distance = GetJumpDistance (L, Target);
if (Distance < 123) { /* Safety */
L->Line [1] = 'b'; /* Make a short branch */
L->Line [2] = 'r';
L->Line [3] = 'a';
L->Size = 2; /* Set new size */
}
}
L = NextCodeLine (L);
}
}
} }