From d23b5773312cc9dc2d3b38620ea66aa272786153 Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 16 Jul 2020 01:07:53 +0800 Subject: [PATCH] More compiler flags on address types to match the location types of expressions. --- src/cc65/codegen.c | 4 ++-- src/cc65/codegen.h | 39 +++++++++++++++++++++------------------ src/cc65/expr.c | 20 ++++++++++---------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 7af329b91..20bfdf434 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -1349,7 +1349,7 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs) rtype = CF_LONG; } else if (ltype != CF_LONG && (lhs & CF_CONST) == 0 && rtype == CF_LONG) { /* We must promote the lhs to long */ - if (lhs & CF_REG) { + if (lhs & CF_PRIMARY) { g_reglong (lhs); } else { g_toslong (lhs); @@ -2338,7 +2338,7 @@ void g_call (unsigned Flags, const char* Label, unsigned ArgSize) void g_callind (unsigned Flags, unsigned ArgSize, int Offs) /* Call subroutine indirect */ { - if ((Flags & CF_LOCAL) == 0) { + if ((Flags & CF_STACK) == 0) { /* Address is in a/x */ if ((Flags & CF_FIXARGC) == 0) { /* Pass arg count */ diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index af539df8b..c63fc5398 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -62,35 +62,38 @@ #define CF_NONE 0x0000 /* No special flags */ /* Values for the actual type */ -#define CF_CHAR 0x0003 /* Operation on characters */ -#define CF_INT 0x0001 /* Operation on ints */ +#define CF_CHAR 0x0007 /* Operation on characters */ +#define CF_INT 0x0003 /* Operation on ints */ +#define CF_SHORT CF_INT /* Alias */ #define CF_PTR CF_INT /* Alias for readability */ -#define CF_LONG 0x0000 /* Operation on longs */ -#define CF_FLOAT 0x0004 /* Operation on a float */ +#define CF_LONG 0x0001 /* Operation on longs */ +#define CF_FLOAT 0x0010 /* Operation on a float */ /* Signedness */ #define CF_UNSIGNED 0x0008 /* Value is unsigned */ /* Masks for retrieving type information */ -#define CF_TYPEMASK 0x0007 /* Type information */ -#define CF_STYPEMASK 0x000F /* Includes signedness */ +#define CF_TYPEMASK 0x0017 /* Type information */ +#define CF_STYPEMASK 0x001F /* Includes signedness */ -#define CF_NOKEEP 0x0010 /* Value may get destroyed when storing */ -#define CF_CONST 0x0020 /* Constant value available */ -#define CF_CONSTADDR 0x0040 /* Constant address value available */ +#define CF_CONST 0x0040 /* Constant value available */ #define CF_TEST 0x0080 /* Test value */ #define CF_FIXARGC 0x0100 /* Function has fixed arg count */ #define CF_FORCECHAR 0x0200 /* Handle chars as chars, not ints */ +#define CF_NOKEEP 0x0400 /* Value may get destroyed when storing */ -/* Type of static address */ -#define CF_ADDRMASK 0xFC00 /* Type of address */ -#define CF_IMM 0x0000 /* Value is pure rvalue and has no address */ -#define CF_REG 0x0400 /* Value is in primary register */ -#define CF_STATIC 0x0800 /* Static local */ -#define CF_EXTERNAL 0x1000 /* Static external */ -#define CF_ABSOLUTE 0x2000 /* Numeric absolute address */ -#define CF_LOCAL 0x4000 /* Auto variable */ -#define CF_REGVAR 0x8000 /* Register variable */ +/* Type of address */ +#define CF_ADDRMASK 0xF000 /* Bit mask of address type */ +#define CF_IMM 0x0000 /* Value is pure rvalue and has no storage */ +#define CF_ABSOLUTE 0x1000 /* Numeric absolute address */ +#define CF_EXTERNAL 0x2000 /* External */ +#define CF_REGVAR 0x4000 /* Register variable */ +#define CF_LITERAL 0x7000 /* Literal */ +#define CF_PRIMARY 0x8000 /* Value is in primary register */ +#define CF_EXPR 0x9000 /* Value is addressed by primary register */ +#define CF_STATIC 0xA000 /* Local static */ +#define CF_CODE 0xB000 /* C code label location */ +#define CF_STACK 0xC000 /* Function-local auto on stack */ diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 38a52e744..d3b5255d8 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -88,10 +88,10 @@ static unsigned GlobalModeFlags (const ExprDesc* Expr) case E_LOC_GLOBAL: return CF_EXTERNAL; case E_LOC_STATIC: return CF_STATIC; case E_LOC_REGISTER: return CF_REGVAR; - case E_LOC_STACK: return CF_NONE; - case E_LOC_PRIMARY: return CF_NONE; - case E_LOC_EXPR: return CF_NONE; - case E_LOC_LITERAL: return CF_STATIC; /* Same as static */ + case E_LOC_STACK: return CF_STACK; + case E_LOC_PRIMARY: return CF_PRIMARY; + case E_LOC_EXPR: return CF_EXPR; + case E_LOC_LITERAL: return CF_LITERAL; default: Internal ("GlobalModeFlags: Invalid location flags value: 0x%04X", Expr->Flags); /* NOTREACHED */ @@ -189,7 +189,7 @@ static unsigned typeadjust (ExprDesc* lhs, ExprDesc* rhs, int NoPush) } if (NoPush) { /* Value is in primary register*/ - ltype |= CF_REG; + ltype |= CF_PRIMARY; } rtype = TypeOf (rhst); if (ED_IsLocNone (rhs)) { @@ -587,7 +587,7 @@ static void FunctionCall (ExprDesc* Expr) ** Since fastcall functions may never be variadic, we can use the ** index register for this purpose. */ - g_callind (CF_LOCAL, ParamSize, PtrOffs); + g_callind (CF_STACK, ParamSize, PtrOffs); } /* If we have a pointer on stack, remove it */ @@ -2068,7 +2068,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */ if ((Gen->Flags & GEN_NOPUSH) == 0) { g_push (ltype, 0); } else { - ltype |= CF_REG; /* Value is in register */ + ltype |= CF_PRIMARY; /* Value is in register */ } /* Determine the type of the operation result. */ @@ -2100,7 +2100,7 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */ } if ((Gen->Flags & GEN_NOPUSH) != 0) { RemoveCode (&Mark2); - ltype |= CF_REG; /* Value is in register */ + ltype |= CF_PRIMARY; /* Value is in register */ } } @@ -2276,7 +2276,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ flags |= CF_CONST; if ((Gen->Flags & GEN_NOPUSH) != 0) { RemoveCode (&Mark2); - ltype |= CF_REG; /* Value is in register */ + ltype |= CF_PRIMARY; /* Value is in register */ } } @@ -2550,7 +2550,7 @@ static void parseadd (ExprDesc* Expr) flags |= CF_CONST; } else { /* Constant address label */ - flags |= GlobalModeFlags (Expr) | CF_CONSTADDR; + flags |= GlobalModeFlags (Expr); } /* Check for pointer arithmetic */