mirror of
https://github.com/cc65/cc65.git
synced 2025-01-26 02:30:17 +00:00
Use gcc function attributes, fix several format related problems
git-svn-id: svn://svn.cc65.org/cc65/trunk@214 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ef579c4015
commit
77e8bffa81
@ -67,8 +67,12 @@ void AddCodeHint (const char* Hint)
|
||||
|
||||
void AddEmptyLine (void)
|
||||
/* Add an empty line for formatting purposes */
|
||||
{
|
||||
AddCodeLine ("");
|
||||
{
|
||||
/* Use a somewhat weird construct to avoid that gcc complains about
|
||||
* an empty format string.
|
||||
*/
|
||||
static const char EmptyLine[] = "";
|
||||
AddCodeLine (EmptyLine);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,6 +40,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -59,7 +62,7 @@ typedef struct Line_* CodeMark;
|
||||
|
||||
|
||||
|
||||
void AddCodeLine (const char* Format, ...);
|
||||
void AddCodeLine (const char* Format, ...) attribute ((format(printf,1,2)));
|
||||
/* Add a new line of code to the output */
|
||||
|
||||
void AddCodeHint (const char* Hint);
|
||||
@ -84,3 +87,4 @@ void WriteOutput (FILE* F);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -40,6 +40,9 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -72,10 +75,10 @@ extern Line* LastLine; /* Pointer to last line */
|
||||
|
||||
|
||||
|
||||
Line* NewCodeLine (const char* Format, va_list ap);
|
||||
Line* NewCodeLine (const char* Format, va_list ap) attribute((format(printf,1,0)));
|
||||
/* Create a new code line and return it */
|
||||
|
||||
Line* NewCodeLineAfter (Line* LineBefore, const char* Format, va_list ap);
|
||||
Line* NewCodeLineAfter (Line* LineBefore, const char* Format, va_list ap) attribute((format(printf,2,0)));
|
||||
/* Create a new line, insert it after L and return it. */
|
||||
|
||||
void FreeCodeLine (Line* L);
|
||||
|
@ -1546,7 +1546,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
AddCodeLine ("\tinc\t%s", lbuf);
|
||||
AddCodeLine ("\tlda\t%s", lbuf);
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t%s", lbuf);
|
||||
AddCodeLine ("\tsta\t%s", lbuf);
|
||||
@ -1570,24 +1570,24 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
if (val == 1) {
|
||||
label = GetLabel ();
|
||||
AddCodeLine ("\tinc\t%s", lbuf);
|
||||
AddCodeLine ("\tbne\tL%04X", label);
|
||||
AddCodeLine ("\tbne\tL%04X", (int)label);
|
||||
AddCodeLine ("\tinc\t%s+1", lbuf);
|
||||
g_defloclabel (label);
|
||||
AddCodeLine ("\tlda\t%s", lbuf); /* Hmmm... */
|
||||
AddCodeLine ("\tlda\t%s", lbuf); /* Hmmm... */
|
||||
AddCodeLine ("\tldx\t%s+1", lbuf);
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t%s", lbuf);
|
||||
AddCodeLine ("\tsta\t%s", lbuf);
|
||||
if (val < 0x100) {
|
||||
label = GetLabel ();
|
||||
AddCodeLine ("\tbcc\tL%04X", label);
|
||||
AddCodeLine ("\tbcc\tL%04X", (int)label);
|
||||
AddCodeLine ("\tinc\t%s+1", lbuf);
|
||||
g_defloclabel (label);
|
||||
AddCodeLine ("\tldx\t%s+1", lbuf);
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tadc\t%s+1", lbuf);
|
||||
AddCodeLine ("\tsta\t%s+1", lbuf);
|
||||
AddCodeLine ("\ttax");
|
||||
@ -1615,7 +1615,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
if (val == 1) {
|
||||
AddCodeLine ("\tjsr\tladdeq1");
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tjsr\tladdeqa");
|
||||
}
|
||||
} else {
|
||||
@ -1654,7 +1654,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tadc\t(sp,x)");
|
||||
AddCodeLine ("\tsta\t(sp,x)");
|
||||
} else {
|
||||
@ -1667,7 +1667,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tadc\t(sp),y");
|
||||
AddCodeLine ("\tsta\t(sp),y");
|
||||
} else {
|
||||
@ -1733,14 +1733,14 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
|
||||
AddCodeLine ("\tstx\tptr1+1");
|
||||
if (offs == 0) {
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t(ptr1,x)");
|
||||
AddCodeLine ("\tsta\t(ptr1,x)");
|
||||
} else {
|
||||
AddCodeLine ("\tldy\t#$%02X", offs);
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t(ptr1),y");
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
@ -1753,13 +1753,13 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
|
||||
AddCodeLine ("\tsta\tptr1");
|
||||
AddCodeLine ("\tstx\tptr1+1");
|
||||
AddCodeLine ("\tldy\t#$%02X", offs);
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t(ptr1),y");
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
AddCodeLine ("\tpha");
|
||||
AddCodeLine ("\tiny");
|
||||
AddCodeLine ("\tlda\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tadc\t(ptr1),y");
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
AddCodeLine ("\ttax");
|
||||
@ -1803,7 +1803,7 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
} else {
|
||||
AddCodeLine ("\tsec");
|
||||
AddCodeLine ("\tlda\t%s", lbuf);
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (int)(val & 0xFF));
|
||||
AddCodeLine ("\tsta\t%s", lbuf);
|
||||
}
|
||||
} else {
|
||||
@ -1826,17 +1826,17 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
AddCodeLine ("\tsec");
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("\tlda\t%s", lbuf);
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tsta\t%s", lbuf);
|
||||
if (val < 0x100) {
|
||||
label = GetLabel ();
|
||||
AddCodeLine ("\tbcs\tL%04X", label);
|
||||
AddCodeLine ("\tbcs\tL%04X", (unsigned)label);
|
||||
AddCodeLine ("\tdec\t%s+1", lbuf);
|
||||
g_defloclabel (label);
|
||||
AddCodeLine ("\tldx\t%s+1", lbuf);
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t%s+1", lbuf);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tsta\t%s+1", lbuf);
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\tlda\t%s", lbuf);
|
||||
@ -1864,7 +1864,7 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
|
||||
if (val == 1) {
|
||||
AddCodeLine ("\tjsr\tlsubeq1");
|
||||
} else {
|
||||
AddCodeLine ("\tlda\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tlda\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tlsubeqa");
|
||||
}
|
||||
} else {
|
||||
@ -1904,7 +1904,7 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val)
|
||||
AddCodeLine ("\tsec");
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
} else {
|
||||
AddCodeLine ("\tsta\ttmp1");
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
@ -1970,14 +1970,14 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
AddCodeLine ("\tlda\t(ptr1,x)");
|
||||
AddCodeLine ("\tsec");
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tsta\t(ptr1,x)");
|
||||
} else {
|
||||
AddCodeLine ("\tldy\t#$%02X", offs);
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
AddCodeLine ("\tlda\t(ptr1),y");
|
||||
AddCodeLine ("\tsec");
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
}
|
||||
break;
|
||||
@ -1990,12 +1990,12 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
|
||||
AddCodeLine ("\tldy\t#$%02X", offs);
|
||||
AddCodeLine ("\tlda\t(ptr1),y");
|
||||
AddCodeLine ("\tsec");
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
AddCodeLine ("\tpha");
|
||||
AddCodeLine ("\tiny");
|
||||
AddCodeLine ("\tlda\t(ptr1),y");
|
||||
AddCodeLine ("\tsbc\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tsta\t(ptr1),y");
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\tpla");
|
||||
@ -2143,15 +2143,15 @@ void g_cmp (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case CF_INT:
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
break;
|
||||
|
||||
case CF_LONG:
|
||||
@ -2415,11 +2415,13 @@ void g_case (unsigned flags, unsigned label, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
case CF_INT:
|
||||
AddCodeLine ("\t.word\t$%04X, L%04X", val & 0xFFFF, label & 0xFFFF);
|
||||
AddCodeLine ("\t.word\t$%04X, L%04X",
|
||||
(unsigned)(val & 0xFFFF),
|
||||
(unsigned)(label & 0xFFFF));
|
||||
break;
|
||||
|
||||
case CF_LONG:
|
||||
AddCodeLine ("\t.dword\t$%08X", val);
|
||||
AddCodeLine ("\t.dword\t$%08lX", val);
|
||||
AddCodeLine ("\t.word\tL%04X", label & 0xFFFF);
|
||||
break;
|
||||
|
||||
@ -2552,7 +2554,7 @@ void g_mul (unsigned flags, unsigned long val)
|
||||
}
|
||||
|
||||
/* If the right hand side is const, the lhs is not on stack but still
|
||||
* in the primary register.
|
||||
* in the primary register.
|
||||
*/
|
||||
if (flags & CF_CONST) {
|
||||
|
||||
@ -2690,7 +2692,7 @@ void g_or (unsigned flags, unsigned long val)
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
if ((val & 0xFF) != 0xFF) {
|
||||
AddCodeLine ("\tora\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2698,14 +2700,14 @@ void g_or (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_INT:
|
||||
if (val <= 0xFF) {
|
||||
AddCodeLine ("\tora\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case CF_LONG:
|
||||
if (val <= 0xFF) {
|
||||
AddCodeLine ("\tora\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -2748,7 +2750,7 @@ void g_xor (unsigned flags, unsigned long val)
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
if ((val & 0xFF) != 0) {
|
||||
AddCodeLine ("\teor\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2757,13 +2759,13 @@ void g_xor (unsigned flags, unsigned long val)
|
||||
case CF_INT:
|
||||
if (val <= 0xFF) {
|
||||
if (val != 0) {
|
||||
AddCodeLine ("\teor\t#$%02X", val);
|
||||
AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
return;
|
||||
} else if ((val & 0xFF) == 0) {
|
||||
AddCodeLine ("\tpha");
|
||||
AddCodeLine ("\ttxa");
|
||||
AddCodeLine ("\teor\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\teor\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\tpla");
|
||||
return;
|
||||
@ -2773,7 +2775,7 @@ void g_xor (unsigned flags, unsigned long val)
|
||||
case CF_LONG:
|
||||
if (val <= 0xFF) {
|
||||
if (val != 0) {
|
||||
AddCodeLine ("\teor\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2815,7 +2817,7 @@ void g_and (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tand\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
|
||||
return;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
@ -2826,23 +2828,23 @@ void g_and (unsigned flags, unsigned long val)
|
||||
if (val == 0) {
|
||||
ldaconst (0);
|
||||
} else if (val != 0xFF) {
|
||||
AddCodeLine ("\tand\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
} else if ((val & 0xFF00) == 0xFF00) {
|
||||
AddCodeLine ("\tand\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
|
||||
} else if ((val & 0x00FF) == 0x0000) {
|
||||
AddCodeLine ("\ttxa");
|
||||
AddCodeLine ("\tand\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\ttax");
|
||||
ldaconst (0);
|
||||
} else {
|
||||
AddCodeLine ("\ttay");
|
||||
AddCodeLine ("\ttxa");
|
||||
AddCodeLine ("\tand\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\ttya");
|
||||
if ((val & 0x00FF) != 0x00FF) {
|
||||
AddCodeLine ("\tand\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2854,7 +2856,7 @@ void g_and (unsigned flags, unsigned long val)
|
||||
AddCodeLine ("\tstx\tsreg+1");
|
||||
AddCodeLine ("\tstx\tsreg");
|
||||
if ((val & 0xFF) != 0xFF) {
|
||||
AddCodeLine ("\tand\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
return;
|
||||
} else if (val == 0xFF00) {
|
||||
@ -3124,7 +3126,7 @@ void g_inc (unsigned flags, unsigned long val)
|
||||
}
|
||||
} else {
|
||||
AddCodeLine ("\tclc");
|
||||
AddCodeLine ("\tadc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tadc\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3140,7 +3142,7 @@ void g_inc (unsigned flags, unsigned long val)
|
||||
} else if (FavourSize) {
|
||||
/* Use jsr calls */
|
||||
if (val <= 8) {
|
||||
AddCodeLine ("\tjsr\tincax%u", val);
|
||||
AddCodeLine ("\tjsr\tincax%lu", val);
|
||||
} else if (val <= 255) {
|
||||
ldyconst (val);
|
||||
AddCodeLine ("\tjsr\tincaxy");
|
||||
@ -3212,7 +3214,7 @@ void g_dec (unsigned flags, unsigned long val)
|
||||
}
|
||||
} else {
|
||||
AddCodeLine ("\tsec");
|
||||
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3273,16 +3275,16 @@ void g_eq (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tbooleq");
|
||||
return;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case CF_INT:
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tbooleq");
|
||||
return;
|
||||
|
||||
@ -3326,16 +3328,16 @@ void g_ne (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tboolne");
|
||||
return;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case CF_INT:
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tboolne");
|
||||
return;
|
||||
|
||||
@ -3384,7 +3386,7 @@ void g_lt (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tjsr\tboolult");
|
||||
} else {
|
||||
@ -3405,9 +3407,9 @@ void g_lt (unsigned flags, unsigned long val)
|
||||
}
|
||||
/* Direct code only for unsigned data types */
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tboolult");
|
||||
return;
|
||||
}
|
||||
@ -3454,7 +3456,7 @@ void g_le (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tjsr\tboolule");
|
||||
} else {
|
||||
@ -3466,9 +3468,9 @@ void g_le (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_INT:
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tboolule");
|
||||
return;
|
||||
}
|
||||
@ -3515,7 +3517,7 @@ void g_gt (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
if (flags & CF_UNSIGNED) {
|
||||
/* If we have a compare > 0, we will replace it by
|
||||
* != 0 here, since both are identical but the latter
|
||||
@ -3544,9 +3546,9 @@ void g_gt (unsigned flags, unsigned long val)
|
||||
AddCodeLine ("\tora\ttmp1");
|
||||
AddCodeLine ("\tjsr\tboolne");
|
||||
} else {
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tboolugt");
|
||||
}
|
||||
return;
|
||||
@ -3599,7 +3601,7 @@ void g_ge (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
if (flags & CF_FORCECHAR) {
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tjsr\tbooluge");
|
||||
} else {
|
||||
@ -3611,9 +3613,9 @@ void g_ge (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_INT:
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF);
|
||||
AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
|
||||
AddCodeLine ("\tbne\t*+4");
|
||||
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF);
|
||||
AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
|
||||
AddCodeLine ("\tjsr\tbooluge");
|
||||
return;
|
||||
}
|
||||
@ -3640,7 +3642,7 @@ void g_ge (unsigned flags, unsigned long val)
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Allocating static storage */
|
||||
/* Allocating static storage */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
@ -48,6 +48,80 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// Basic data types
|
||||
enum type_t {
|
||||
T_NONE = 0x0000,
|
||||
|
||||
// Basic types
|
||||
T_TYPE_NONE = 0x0000,
|
||||
T_TYPE_CHAR = 0x0001,
|
||||
T_TYPE_INT = 0x0002,
|
||||
T_TYPE_ENUM = 0x0003,
|
||||
T_TYPE_FLOAT = 0x0004,
|
||||
T_TYPE_DOUBLE = 0x0005,
|
||||
T_TYPE_VOID = 0x0006,
|
||||
T_TYPE_STRUCT = 0x0007,
|
||||
T_TYPE_UNION = 0x0008,
|
||||
T_TYPE_ARRAY = 0x0009,
|
||||
T_TYPE_PTR = 0x000A,
|
||||
T_TYPE_FUNC = 0x000B,
|
||||
T_MASK_TYPE = 0x001F,
|
||||
|
||||
// Type classes
|
||||
T_CLASS_NONE = 0x0000,
|
||||
T_CLASS_INT = 0x0020,
|
||||
T_CLASS_FLOAT = 0x0040,
|
||||
T_CLASS_PTR = 0x0060,
|
||||
T_CLASS_STRUCT = 0x0080,
|
||||
T_CLASS_FUNC = 0x00A0,
|
||||
T_MASK_CLASS = 0x00E0,
|
||||
|
||||
// Type signedness
|
||||
T_SIGN_NONE = 0x0000,
|
||||
T_SIGN_UNSIGNED = 0x0100,
|
||||
T_SIGN_SIGNED = 0x0200,
|
||||
T_MASK_SIGN = 0x0300,
|
||||
|
||||
// Type size modifiers
|
||||
T_SIZE_NONE = 0x0000,
|
||||
T_SIZE_SHORT = 0x0400,
|
||||
T_SIZE_LONG = 0x0800,
|
||||
T_SIZE_LONGLONG = 0x0C00,
|
||||
T_MASK_SIZE = 0x0C00,
|
||||
|
||||
// Type qualifiers
|
||||
T_QUAL_NONE = 0x0000,
|
||||
T_QUAL_CONST = 0x1000,
|
||||
T_QUAL_VOLATILE = 0x2000,
|
||||
T_MASK_QUAL = 0x3000,
|
||||
|
||||
// Types
|
||||
T_CHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
|
||||
T_SCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
|
||||
T_UCHAR = T_TYPE_CHAR | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
|
||||
T_SHORT = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_SHORT,
|
||||
T_USHORT = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_SHORT,
|
||||
T_INT = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
|
||||
T_UINT = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_NONE,
|
||||
T_LONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONG,
|
||||
T_ULONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONG,
|
||||
T_LONGLONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_LONGLONG,
|
||||
T_ULONGLONG = T_TYPE_INT | T_CLASS_INT | T_SIGN_UNSIGNED | T_SIZE_LONGLONG,
|
||||
T_ENUM = T_TYPE_ENUM | T_CLASS_INT | T_SIGN_SIGNED | T_SIZE_NONE,
|
||||
T_FLOAT = T_TYPE_FLOAT | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_DOUBLE = T_TYPE_DOUBLE | T_CLASS_FLOAT | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_VOID = T_TYPE_VOID | T_CLASS_NONE | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_STRUCT = T_TYPE_STRUCT | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_UNION = T_TYPE_UNION | T_CLASS_STRUCT | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_ARRAY = T_TYPE_ARRAY | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_PTR = T_TYPE_PTR | T_CLASS_PTR | T_SIGN_NONE | T_SIZE_NONE,
|
||||
T_FUNC = T_TYPE_FUNC | T_CLASS_FUNC | T_SIGN_NONE | T_SIZE_NONE,
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Data types */
|
||||
#define T_END 0x0000
|
||||
#define T_CHAR 0x0011
|
||||
@ -159,7 +233,7 @@ void* DecodePtr (const type* Type);
|
||||
|
||||
int HasEncode (const type* Type);
|
||||
/* Return true if the given type has encoded data */
|
||||
|
||||
|
||||
void CopyEncode (const type* Source, type* Target);
|
||||
/* Copy encoded data from Source to Target */
|
||||
|
||||
|
@ -282,7 +282,7 @@ static void ParseTypeSpec (DeclSpec* D, int Default)
|
||||
SymEntry* Entry;
|
||||
type StructType;
|
||||
|
||||
/* Assume have an explicit type */
|
||||
/* Assume we have an explicit type */
|
||||
D->Flags &= ~DS_DEF_TYPE;
|
||||
|
||||
/* Skip const or volatile modifiers if needed */
|
||||
|
@ -182,6 +182,9 @@ static void ParseOneDecl (const DeclSpec* Spec)
|
||||
/* Allocate previously reserved local space */
|
||||
AllocLocalSpace (CurrentFunc);
|
||||
|
||||
/* Switch to the code segment. */
|
||||
g_usecode ();
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
# Default for the compiler lib search path as compiler define
|
||||
CDEFS=-DCC65_INC=\"/usr/lib/cc65/include/\"
|
||||
CFLAGS = -O2 -g -Wall $(CDEFS)
|
||||
CFLAGS = -O2 -g -Wall -I../common $(CDEFS)
|
||||
CC=gcc
|
||||
LDFLAGS=
|
||||
|
||||
|
@ -38,8 +38,11 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../common/xmalloc.h"
|
||||
/* common */
|
||||
#include "attrib.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "asmlabel.h"
|
||||
#include "asmline.h"
|
||||
#include "check.h"
|
||||
@ -126,7 +129,7 @@ static const struct {
|
||||
{ "\tcpx\t", 0, REG_X, REG_NONE },
|
||||
{ "\tcpy\t", 0, REG_Y, REG_NONE },
|
||||
{ "\tdea", 1, REG_A, REG_NONE },
|
||||
{ "\tdec\ta", 1, REG_A, REG_NONE },
|
||||
{ "\tdec\ta", 1, REG_A, REG_NONE },
|
||||
{ "\tdec\t", 0, REG_NONE, REG_NONE },
|
||||
{ "\tdex", 1, REG_X, REG_NONE },
|
||||
{ "\tdey", 1, REG_Y, REG_NONE },
|
||||
@ -226,7 +229,7 @@ static const char* LongBranches [] = {
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Forwards */
|
||||
/* Forwards */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@ -243,10 +246,19 @@ static unsigned GetLabelNum (const char* L);
|
||||
static unsigned RVUInt1 (Line* L, LineColl* LC, unsigned Used, unsigned Unused);
|
||||
/* Subfunction for RegValUsed. Will be called recursively in case of branches. */
|
||||
|
||||
static Line* NewLineAfter (Line* LineBefore, const char* Format, ...) attribute ((format(printf,2,3)));
|
||||
/* Create a new line, insert it after L and return it. The new line is marked
|
||||
* as code line.
|
||||
*/
|
||||
|
||||
static Line* ReplaceLine (Line* L, const char* Format, ...)
|
||||
attribute ((format(printf,2,3)));
|
||||
/* Replace one line by another */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* List stuff */
|
||||
/* List stuff */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@ -2265,7 +2277,7 @@ static void OptPtrOps (void)
|
||||
Line* L = FirstCode;
|
||||
while (L) {
|
||||
|
||||
if (OptPtrOps1 (&L)) {
|
||||
if (OptPtrOps1 (&L)) {
|
||||
continue;
|
||||
} else if (OptPtrOps2 (&L)) {
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user