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:
cuz
2000-07-27 21:08:52 +00:00
parent ef579c4015
commit 77e8bffa81
9 changed files with 180 additions and 78 deletions

View File

@@ -68,7 +68,11 @@ void AddCodeHint (const char* Hint)
void AddEmptyLine (void) void AddEmptyLine (void)
/* Add an empty line for formatting purposes */ /* 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);
} }

View File

@@ -40,6 +40,9 @@
#include <stdio.h> #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 */ /* Add a new line of code to the output */
void AddCodeHint (const char* Hint); void AddCodeHint (const char* Hint);
@@ -84,3 +87,4 @@ void WriteOutput (FILE* F);

View File

@@ -40,6 +40,9 @@
#include <stdarg.h> #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 */ /* 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. */ /* Create a new line, insert it after L and return it. */
void FreeCodeLine (Line* L); void FreeCodeLine (Line* L);

View File

@@ -1546,7 +1546,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
AddCodeLine ("\tinc\t%s", lbuf); AddCodeLine ("\tinc\t%s", lbuf);
AddCodeLine ("\tlda\t%s", lbuf); AddCodeLine ("\tlda\t%s", lbuf);
} else { } else {
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t%s", lbuf); AddCodeLine ("\tadc\t%s", lbuf);
AddCodeLine ("\tsta\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) { if (val == 1) {
label = GetLabel (); label = GetLabel ();
AddCodeLine ("\tinc\t%s", lbuf); AddCodeLine ("\tinc\t%s", lbuf);
AddCodeLine ("\tbne\tL%04X", label); AddCodeLine ("\tbne\tL%04X", (int)label);
AddCodeLine ("\tinc\t%s+1", lbuf); AddCodeLine ("\tinc\t%s+1", lbuf);
g_defloclabel (label); g_defloclabel (label);
AddCodeLine ("\tlda\t%s", lbuf); /* Hmmm... */ AddCodeLine ("\tlda\t%s", lbuf); /* Hmmm... */
AddCodeLine ("\tldx\t%s+1", lbuf); AddCodeLine ("\tldx\t%s+1", lbuf);
} else { } else {
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t%s", lbuf); AddCodeLine ("\tadc\t%s", lbuf);
AddCodeLine ("\tsta\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf);
if (val < 0x100) { if (val < 0x100) {
label = GetLabel (); label = GetLabel ();
AddCodeLine ("\tbcc\tL%04X", label); AddCodeLine ("\tbcc\tL%04X", (int)label);
AddCodeLine ("\tinc\t%s+1", lbuf); AddCodeLine ("\tinc\t%s+1", lbuf);
g_defloclabel (label); g_defloclabel (label);
AddCodeLine ("\tldx\t%s+1", lbuf); AddCodeLine ("\tldx\t%s+1", lbuf);
} else { } else {
AddCodeLine ("\tlda\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tlda\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tadc\t%s+1", lbuf); AddCodeLine ("\tadc\t%s+1", lbuf);
AddCodeLine ("\tsta\t%s+1", lbuf); AddCodeLine ("\tsta\t%s+1", lbuf);
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
@@ -1615,7 +1615,7 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs,
if (val == 1) { if (val == 1) {
AddCodeLine ("\tjsr\tladdeq1"); AddCodeLine ("\tjsr\tladdeq1");
} else { } else {
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tjsr\tladdeqa"); AddCodeLine ("\tjsr\tladdeqa");
} }
} else { } else {
@@ -1654,7 +1654,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
if (flags & CF_CONST) { if (flags & CF_CONST) {
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tadc\t(sp,x)"); AddCodeLine ("\tadc\t(sp,x)");
AddCodeLine ("\tsta\t(sp,x)"); AddCodeLine ("\tsta\t(sp,x)");
} else { } else {
@@ -1667,7 +1667,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val)
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
if (flags & CF_CONST) { if (flags & CF_CONST) {
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tadc\t(sp),y"); AddCodeLine ("\tadc\t(sp),y");
AddCodeLine ("\tsta\t(sp),y"); AddCodeLine ("\tsta\t(sp),y");
} else { } else {
@@ -1733,14 +1733,14 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
AddCodeLine ("\tstx\tptr1+1"); AddCodeLine ("\tstx\tptr1+1");
if (offs == 0) { if (offs == 0) {
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t(ptr1,x)"); AddCodeLine ("\tadc\t(ptr1,x)");
AddCodeLine ("\tsta\t(ptr1,x)"); AddCodeLine ("\tsta\t(ptr1,x)");
} else { } else {
AddCodeLine ("\tldy\t#$%02X", offs); AddCodeLine ("\tldy\t#$%02X", offs);
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t(ptr1),y"); AddCodeLine ("\tadc\t(ptr1),y");
AddCodeLine ("\tsta\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 ("\tsta\tptr1");
AddCodeLine ("\tstx\tptr1+1"); AddCodeLine ("\tstx\tptr1+1");
AddCodeLine ("\tldy\t#$%02X", offs); AddCodeLine ("\tldy\t#$%02X", offs);
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t(ptr1),y"); AddCodeLine ("\tadc\t(ptr1),y");
AddCodeLine ("\tsta\t(ptr1),y"); AddCodeLine ("\tsta\t(ptr1),y");
AddCodeLine ("\tpha"); AddCodeLine ("\tpha");
AddCodeLine ("\tiny"); AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tlda\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tadc\t(ptr1),y"); AddCodeLine ("\tadc\t(ptr1),y");
AddCodeLine ("\tsta\t(ptr1),y"); AddCodeLine ("\tsta\t(ptr1),y");
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
@@ -1803,7 +1803,7 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
} else { } else {
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
AddCodeLine ("\tlda\t%s", lbuf); AddCodeLine ("\tlda\t%s", lbuf);
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (int)(val & 0xFF));
AddCodeLine ("\tsta\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf);
} }
} else { } else {
@@ -1826,17 +1826,17 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
if (flags & CF_CONST) { if (flags & CF_CONST) {
AddCodeLine ("\tlda\t%s", lbuf); AddCodeLine ("\tlda\t%s", lbuf);
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
AddCodeLine ("\tsta\t%s", lbuf); AddCodeLine ("\tsta\t%s", lbuf);
if (val < 0x100) { if (val < 0x100) {
label = GetLabel (); label = GetLabel ();
AddCodeLine ("\tbcs\tL%04X", label); AddCodeLine ("\tbcs\tL%04X", (unsigned)label);
AddCodeLine ("\tdec\t%s+1", lbuf); AddCodeLine ("\tdec\t%s+1", lbuf);
g_defloclabel (label); g_defloclabel (label);
AddCodeLine ("\tldx\t%s+1", lbuf); AddCodeLine ("\tldx\t%s+1", lbuf);
} else { } else {
AddCodeLine ("\tlda\t%s+1", lbuf); 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 ("\tsta\t%s+1", lbuf);
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
AddCodeLine ("\tlda\t%s", lbuf); AddCodeLine ("\tlda\t%s", lbuf);
@@ -1864,7 +1864,7 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs,
if (val == 1) { if (val == 1) {
AddCodeLine ("\tjsr\tlsubeq1"); AddCodeLine ("\tjsr\tlsubeq1");
} else { } else {
AddCodeLine ("\tlda\t#$%02X", val & 0xFF); AddCodeLine ("\tlda\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tlsubeqa"); AddCodeLine ("\tjsr\tlsubeqa");
} }
} else { } else {
@@ -1904,7 +1904,7 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val)
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
if (flags & CF_CONST) { if (flags & CF_CONST) {
AddCodeLine ("\tlda\t(sp),y"); AddCodeLine ("\tlda\t(sp),y");
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
} else { } else {
AddCodeLine ("\tsta\ttmp1"); AddCodeLine ("\tsta\ttmp1");
AddCodeLine ("\tlda\t(sp),y"); AddCodeLine ("\tlda\t(sp),y");
@@ -1970,14 +1970,14 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
AddCodeLine ("\tlda\t(ptr1,x)"); AddCodeLine ("\tlda\t(ptr1,x)");
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
AddCodeLine ("\tsta\t(ptr1,x)"); AddCodeLine ("\tsta\t(ptr1,x)");
} else { } else {
AddCodeLine ("\tldy\t#$%02X", offs); AddCodeLine ("\tldy\t#$%02X", offs);
AddCodeLine ("\tldx\t#$00"); AddCodeLine ("\tldx\t#$00");
AddCodeLine ("\tlda\t(ptr1),y"); AddCodeLine ("\tlda\t(ptr1),y");
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
AddCodeLine ("\tsta\t(ptr1),y"); AddCodeLine ("\tsta\t(ptr1),y");
} }
break; break;
@@ -1990,12 +1990,12 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
AddCodeLine ("\tldy\t#$%02X", offs); AddCodeLine ("\tldy\t#$%02X", offs);
AddCodeLine ("\tlda\t(ptr1),y"); AddCodeLine ("\tlda\t(ptr1),y");
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
AddCodeLine ("\tsta\t(ptr1),y"); AddCodeLine ("\tsta\t(ptr1),y");
AddCodeLine ("\tpha"); AddCodeLine ("\tpha");
AddCodeLine ("\tiny"); AddCodeLine ("\tiny");
AddCodeLine ("\tlda\t(ptr1),y"); 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 ("\tsta\t(ptr1),y");
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
AddCodeLine ("\tpla"); AddCodeLine ("\tpla");
@@ -2143,15 +2143,15 @@ void g_cmp (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
break; break;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case CF_INT: case CF_INT:
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
break; break;
case CF_LONG: case CF_LONG:
@@ -2415,11 +2415,13 @@ void g_case (unsigned flags, unsigned label, unsigned long val)
case CF_CHAR: case CF_CHAR:
case CF_INT: 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; break;
case CF_LONG: case CF_LONG:
AddCodeLine ("\t.dword\t$%08X", val); AddCodeLine ("\t.dword\t$%08lX", val);
AddCodeLine ("\t.word\tL%04X", label & 0xFFFF); AddCodeLine ("\t.word\tL%04X", label & 0xFFFF);
break; break;
@@ -2690,7 +2692,7 @@ void g_or (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
if ((val & 0xFF) != 0xFF) { if ((val & 0xFF) != 0xFF) {
AddCodeLine ("\tora\t#$%02X", val & 0xFF); AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
} }
return; return;
} }
@@ -2698,14 +2700,14 @@ void g_or (unsigned flags, unsigned long val)
case CF_INT: case CF_INT:
if (val <= 0xFF) { if (val <= 0xFF) {
AddCodeLine ("\tora\t#$%02X", val & 0xFF); AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
return; return;
} }
break; break;
case CF_LONG: case CF_LONG:
if (val <= 0xFF) { if (val <= 0xFF) {
AddCodeLine ("\tora\t#$%02X", val & 0xFF); AddCodeLine ("\tora\t#$%02X", (unsigned char)val);
return; return;
} }
break; break;
@@ -2748,7 +2750,7 @@ void g_xor (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
if ((val & 0xFF) != 0) { if ((val & 0xFF) != 0) {
AddCodeLine ("\teor\t#$%02X", val & 0xFF); AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
} }
return; return;
} }
@@ -2757,13 +2759,13 @@ void g_xor (unsigned flags, unsigned long val)
case CF_INT: case CF_INT:
if (val <= 0xFF) { if (val <= 0xFF) {
if (val != 0) { if (val != 0) {
AddCodeLine ("\teor\t#$%02X", val); AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
} }
return; return;
} else if ((val & 0xFF) == 0) { } else if ((val & 0xFF) == 0) {
AddCodeLine ("\tpha"); AddCodeLine ("\tpha");
AddCodeLine ("\ttxa"); AddCodeLine ("\ttxa");
AddCodeLine ("\teor\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\teor\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
AddCodeLine ("\tpla"); AddCodeLine ("\tpla");
return; return;
@@ -2773,7 +2775,7 @@ void g_xor (unsigned flags, unsigned long val)
case CF_LONG: case CF_LONG:
if (val <= 0xFF) { if (val <= 0xFF) {
if (val != 0) { if (val != 0) {
AddCodeLine ("\teor\t#$%02X", val & 0xFF); AddCodeLine ("\teor\t#$%02X", (unsigned char)val);
} }
return; return;
} }
@@ -2815,7 +2817,7 @@ void g_and (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tand\t#$%02X", val & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
return; return;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@@ -2826,23 +2828,23 @@ void g_and (unsigned flags, unsigned long val)
if (val == 0) { if (val == 0) {
ldaconst (0); ldaconst (0);
} else if (val != 0xFF) { } else if (val != 0xFF) {
AddCodeLine ("\tand\t#$%02X", val & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
} }
} else if ((val & 0xFF00) == 0xFF00) { } else if ((val & 0xFF00) == 0xFF00) {
AddCodeLine ("\tand\t#$%02X", val & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
} else if ((val & 0x00FF) == 0x0000) { } else if ((val & 0x00FF) == 0x0000) {
AddCodeLine ("\ttxa"); AddCodeLine ("\ttxa");
AddCodeLine ("\tand\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
ldaconst (0); ldaconst (0);
} else { } else {
AddCodeLine ("\ttay"); AddCodeLine ("\ttay");
AddCodeLine ("\ttxa"); AddCodeLine ("\ttxa");
AddCodeLine ("\tand\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\ttax"); AddCodeLine ("\ttax");
AddCodeLine ("\ttya"); AddCodeLine ("\ttya");
if ((val & 0x00FF) != 0x00FF) { 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+1");
AddCodeLine ("\tstx\tsreg"); AddCodeLine ("\tstx\tsreg");
if ((val & 0xFF) != 0xFF) { if ((val & 0xFF) != 0xFF) {
AddCodeLine ("\tand\t#$%02X", val & 0xFF); AddCodeLine ("\tand\t#$%02X", (unsigned char)val);
} }
return; return;
} else if (val == 0xFF00) { } else if (val == 0xFF00) {
@@ -3124,7 +3126,7 @@ void g_inc (unsigned flags, unsigned long val)
} }
} else { } else {
AddCodeLine ("\tclc"); AddCodeLine ("\tclc");
AddCodeLine ("\tadc\t#$%02X", val & 0xFF); AddCodeLine ("\tadc\t#$%02X", (unsigned char)val);
} }
break; break;
} }
@@ -3140,7 +3142,7 @@ void g_inc (unsigned flags, unsigned long val)
} else if (FavourSize) { } else if (FavourSize) {
/* Use jsr calls */ /* Use jsr calls */
if (val <= 8) { if (val <= 8) {
AddCodeLine ("\tjsr\tincax%u", val); AddCodeLine ("\tjsr\tincax%lu", val);
} else if (val <= 255) { } else if (val <= 255) {
ldyconst (val); ldyconst (val);
AddCodeLine ("\tjsr\tincaxy"); AddCodeLine ("\tjsr\tincaxy");
@@ -3212,7 +3214,7 @@ void g_dec (unsigned flags, unsigned long val)
} }
} else { } else {
AddCodeLine ("\tsec"); AddCodeLine ("\tsec");
AddCodeLine ("\tsbc\t#$%02X", val & 0xFF); AddCodeLine ("\tsbc\t#$%02X", (unsigned char)val);
} }
break; break;
} }
@@ -3273,16 +3275,16 @@ void g_eq (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tbooleq"); AddCodeLine ("\tjsr\tbooleq");
return; return;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case CF_INT: case CF_INT:
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tbooleq"); AddCodeLine ("\tjsr\tbooleq");
return; return;
@@ -3326,16 +3328,16 @@ void g_ne (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tboolne"); AddCodeLine ("\tjsr\tboolne");
return; return;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case CF_INT: case CF_INT:
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tboolne"); AddCodeLine ("\tjsr\tboolne");
return; return;
@@ -3384,7 +3386,7 @@ void g_lt (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tjsr\tboolult"); AddCodeLine ("\tjsr\tboolult");
} else { } else {
@@ -3405,9 +3407,9 @@ void g_lt (unsigned flags, unsigned long val)
} }
/* Direct code only for unsigned data types */ /* Direct code only for unsigned data types */
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tboolult"); AddCodeLine ("\tjsr\tboolult");
return; return;
} }
@@ -3454,7 +3456,7 @@ void g_le (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tjsr\tboolule"); AddCodeLine ("\tjsr\tboolule");
} else { } else {
@@ -3466,9 +3468,9 @@ void g_le (unsigned flags, unsigned long val)
case CF_INT: case CF_INT:
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tboolule"); AddCodeLine ("\tjsr\tboolule");
return; return;
} }
@@ -3515,7 +3517,7 @@ void g_gt (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
/* If we have a compare > 0, we will replace it by /* If we have a compare > 0, we will replace it by
* != 0 here, since both are identical but the latter * != 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 ("\tora\ttmp1");
AddCodeLine ("\tjsr\tboolne"); AddCodeLine ("\tjsr\tboolne");
} else { } else {
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tboolugt"); AddCodeLine ("\tjsr\tboolugt");
} }
return; return;
@@ -3599,7 +3601,7 @@ void g_ge (unsigned flags, unsigned long val)
case CF_CHAR: case CF_CHAR:
if (flags & CF_FORCECHAR) { if (flags & CF_FORCECHAR) {
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tjsr\tbooluge"); AddCodeLine ("\tjsr\tbooluge");
} else { } else {
@@ -3611,9 +3613,9 @@ void g_ge (unsigned flags, unsigned long val)
case CF_INT: case CF_INT:
if (flags & CF_UNSIGNED) { if (flags & CF_UNSIGNED) {
AddCodeLine ("\tcpx\t#$%02X", (val >> 8) & 0xFF); AddCodeLine ("\tcpx\t#$%02X", (unsigned char)(val >> 8));
AddCodeLine ("\tbne\t*+4"); AddCodeLine ("\tbne\t*+4");
AddCodeLine ("\tcmp\t#$%02X", val & 0xFF); AddCodeLine ("\tcmp\t#$%02X", (unsigned char)val);
AddCodeLine ("\tjsr\tbooluge"); AddCodeLine ("\tjsr\tbooluge");
return; return;
} }
@@ -3640,7 +3642,7 @@ void g_ge (unsigned flags, unsigned long val)
/*****************************************************************************/ /*****************************************************************************/
/* Allocating static storage */ /* Allocating static storage */
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -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 */ /* Data types */
#define T_END 0x0000 #define T_END 0x0000
#define T_CHAR 0x0011 #define T_CHAR 0x0011

View File

@@ -282,7 +282,7 @@ static void ParseTypeSpec (DeclSpec* D, int Default)
SymEntry* Entry; SymEntry* Entry;
type StructType; type StructType;
/* Assume have an explicit type */ /* Assume we have an explicit type */
D->Flags &= ~DS_DEF_TYPE; D->Flags &= ~DS_DEF_TYPE;
/* Skip const or volatile modifiers if needed */ /* Skip const or volatile modifiers if needed */

View File

@@ -182,6 +182,9 @@ static void ParseOneDecl (const DeclSpec* Spec)
/* Allocate previously reserved local space */ /* Allocate previously reserved local space */
AllocLocalSpace (CurrentFunc); AllocLocalSpace (CurrentFunc);
/* Switch to the code segment. */
g_usecode ();
/* Skip the '=' */ /* Skip the '=' */
NextToken (); NextToken ();

View File

@@ -5,7 +5,7 @@
# Default for the compiler lib search path as compiler define # Default for the compiler lib search path as compiler define
CDEFS=-DCC65_INC=\"/usr/lib/cc65/include/\" CDEFS=-DCC65_INC=\"/usr/lib/cc65/include/\"
CFLAGS = -O2 -g -Wall $(CDEFS) CFLAGS = -O2 -g -Wall -I../common $(CDEFS)
CC=gcc CC=gcc
LDFLAGS= LDFLAGS=

View File

@@ -38,8 +38,11 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "../common/xmalloc.h" /* common */
#include "attrib.h"
#include "xmalloc.h"
/* cc65 */
#include "asmlabel.h" #include "asmlabel.h"
#include "asmline.h" #include "asmline.h"
#include "check.h" #include "check.h"
@@ -126,7 +129,7 @@ static const struct {
{ "\tcpx\t", 0, REG_X, REG_NONE }, { "\tcpx\t", 0, REG_X, REG_NONE },
{ "\tcpy\t", 0, REG_Y, REG_NONE }, { "\tcpy\t", 0, REG_Y, REG_NONE },
{ "\tdea", 1, REG_A, 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 }, { "\tdec\t", 0, REG_NONE, REG_NONE },
{ "\tdex", 1, REG_X, REG_NONE }, { "\tdex", 1, REG_X, REG_NONE },
{ "\tdey", 1, REG_Y, 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); static unsigned RVUInt1 (Line* L, LineColl* LC, unsigned Used, unsigned Unused);
/* Subfunction for RegValUsed. Will be called recursively in case of branches. */ /* 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 */
/*****************************************************************************/ /*****************************************************************************/