1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-17 05:31:45 +00:00

Minor fixes and improvements.

This commit is contained in:
acqn 2020-07-21 13:09:41 +08:00 committed by Oliver Schmidt
parent 65081aebed
commit 18bd76bb90
4 changed files with 30 additions and 18 deletions

View File

@ -523,7 +523,7 @@ static void WrappedCallPragma (StrBuf* B)
Entry = FindSym(Name); Entry = FindSym(Name);
/* Check if the name is valid */ /* Check if the name is valid */
if (Entry && Entry->Flags & SC_FUNC) { if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) {
PushWrappedCall(Entry, (unsigned char) Val); PushWrappedCall(Entry, (unsigned char) Val);
Entry->Flags |= SC_REF; Entry->Flags |= SC_REF;

View File

@ -104,16 +104,21 @@ void FreeSymEntry (SymEntry* E)
void DumpSymEntry (FILE* F, const SymEntry* E) void DumpSymEntry (FILE* F, const SymEntry* E)
/* Dump the given symbol table entry to the file in readable form */ /* Dump the given symbol table entry to the file in readable form */
{ {
static const struct { typedef const struct {
const char* Name; const char* Name;
unsigned Val; unsigned Val;
} Flags [] = { } SCFlagTable;
/* Beware: Order is important! */
static SCFlagTable ESUTypes[] = {
{ "SC_TYPEDEF", SC_TYPEDEF }, { "SC_TYPEDEF", SC_TYPEDEF },
{ "SC_BITFIELD", SC_BITFIELD },
{ "SC_STRUCTFIELD", SC_STRUCTFIELD },
{ "SC_UNION", SC_UNION }, { "SC_UNION", SC_UNION },
{ "SC_STRUCT", SC_STRUCT }, { "SC_STRUCT", SC_STRUCT },
};
static SCFlagTable Flags[] = {
/* Beware: Order is important! */
{ "SC_BITFIELD", SC_BITFIELD },
{ "SC_STRUCTFIELD", SC_STRUCTFIELD },
{ "SC_AUTO", SC_AUTO }, { "SC_AUTO", SC_AUTO },
{ "SC_REGISTER", SC_REGISTER }, { "SC_REGISTER", SC_REGISTER },
{ "SC_STATIC", SC_STATIC }, { "SC_STATIC", SC_STATIC },
@ -124,6 +129,7 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
{ "SC_PARAM", SC_PARAM }, { "SC_PARAM", SC_PARAM },
{ "SC_FUNC", SC_FUNC }, { "SC_FUNC", SC_FUNC },
{ "SC_STORAGE", SC_STORAGE }, { "SC_STORAGE", SC_STORAGE },
{ "SC_DECL", SC_DECL },
{ "SC_DEF", SC_DEF }, { "SC_DEF", SC_DEF },
{ "SC_REF", SC_REF }, { "SC_REF", SC_REF },
{ "SC_ZEROPAGE", SC_ZEROPAGE }, { "SC_ZEROPAGE", SC_ZEROPAGE },
@ -143,6 +149,14 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
/* Print the flags */ /* Print the flags */
SymFlags = E->Flags; SymFlags = E->Flags;
fprintf (F, " Flags:"); fprintf (F, " Flags:");
if ((SymFlags & SC_ESUTYPEMASK) != 0) {
for (I = 0; I < sizeof (ESUTypes) / sizeof (ESUTypes[0]); ++I) {
if ((SymFlags & SC_ESUTYPEMASK) == ESUTypes[I].Val) {
SymFlags &= ~SC_ESUTYPEMASK;
fprintf (F, " %s", ESUTypes[I].Name);
}
}
}
for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) { for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
if ((SymFlags & Flags[I].Val) == Flags[I].Val) { if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
SymFlags &= ~Flags[I].Val; SymFlags &= ~Flags[I].Val;

View File

@ -74,24 +74,22 @@ struct CodeEntry;
#define SC_UNION 0x0002U /* Union */ #define SC_UNION 0x0002U /* Union */
#define SC_TYPEDEF 0x0004U /* A typedef */ #define SC_TYPEDEF 0x0004U /* A typedef */
#define SC_ESUTYPEMASK 0x0007U /* Mask for above types */ #define SC_ESUTYPEMASK 0x0007U /* Mask for above types */
#define SC_ENUM 0x0008U /* An enum */ #define SC_ENUM 0x0008U /* An enumerator */
#define SC_BITFIELD 0x0010U /* A bit-field inside a struct or union */ #define SC_BITFIELD 0x0010U /* A bit-field inside a struct or union */
#define SC_TYPEMASK 0x001FU /* Mask for above types */ #define SC_TYPEMASK 0x001FU /* Mask for above types */
#define SC_CONST 0x0020U /* A numeric constant with a type */ #define SC_FUNC 0x0020U /* A function */
#define SC_LABEL 0x0040U /* A goto code label */ #define SC_LABEL 0x0040U /* A goto code label */
#define SC_PARAM 0x0080U /* A function parameter */ #define SC_CONST 0x0080U /* A numeric constant with a type */
#define SC_FUNC 0x0100U /* A function */ #define SC_PARAM 0x0100U /* A function parameter */
#define SC_DEFTYPE 0x0200U /* Parameter has default type (=int, old style) */ #define SC_DEFTYPE 0x0200U /* Parameter has default type (=int, old style) */
#define SC_STRUCTFIELD 0x0400U /* Struct or union field */ #define SC_STRUCTFIELD 0x0400U /* Struct or union field */
#define SC_DECL 0x0800U /* Symbol is declared in global scope */ #define SC_ZEROPAGE 0x0800U /* Symbol marked as zeropage */
#define SC_DEF 0x1000U /* Symbol is defined */ #define SC_DEF 0x1000U /* Symbol is defined */
#define SC_REF 0x2000U /* Symbol is referenced */ #define SC_REF 0x2000U /* Symbol is referenced */
#define SC_DECL 0x4000U /* Symbol is declared in global scope */
#define SC_ZEROPAGE 0x4000U /* Symbol marked as zeropage */
#define SC_STORAGE 0x8000U /* Symbol with associated storage */ #define SC_STORAGE 0x8000U /* Symbol with associated storage */
#define SC_AUTO 0x010000U /* Auto variable */ #define SC_AUTO 0x010000U /* Auto variable */
@ -217,10 +215,10 @@ INLINE int SymIsBitField (const SymEntry* Sym)
INLINE int SymIsTypeDef (const SymEntry* Sym) INLINE int SymIsTypeDef (const SymEntry* Sym)
/* Return true if the given entry is a typedef entry */ /* Return true if the given entry is a typedef entry */
{ {
return ((Sym->Flags & SC_TYPEDEF) == SC_TYPEDEF); return ((Sym->Flags & SC_TYPEMASK) == SC_TYPEDEF);
} }
#else #else
# define SymIsTypeDef(Sym) (((Sym)->Flags & SC_TYPEDEF) == SC_TYPEDEF) # define SymIsTypeDef(Sym) (((Sym)->Flags & SC_TYPEMASK) == SC_TYPEDEF)
#endif #endif
#if defined(HAVE_INLINE) #if defined(HAVE_INLINE)
@ -251,7 +249,7 @@ INLINE int SymIsRegVar (const SymEntry* Sym)
return ((Sym->Flags & (SC_REGISTER|SC_TYPEMASK)) == SC_REGISTER); return ((Sym->Flags & (SC_REGISTER|SC_TYPEMASK)) == SC_REGISTER);
} }
#else #else
# define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_ESUTYPEMASK)) == SC_REGISTER) # define SymIsRegVar(Sym) (((Sym)->Flags & (SC_REGISTER|SC_TYPEMASK)) == SC_REGISTER)
#endif #endif
int SymIsOutputFunc (const SymEntry* Sym); int SymIsOutputFunc (const SymEntry* Sym);

View File

@ -821,7 +821,7 @@ SymEntry* AddLocalSym (const char* Name, const Type* T, unsigned Flags, int Offs
/* Set the symbol attributes */ /* Set the symbol attributes */
Entry->Type = TypeDup (T); Entry->Type = TypeDup (T);
if ((Flags & SC_AUTO) == SC_AUTO || (Flags & SC_TYPEDEF) == SC_TYPEDEF) { if ((Flags & SC_AUTO) == SC_AUTO || (Flags & SC_TYPEMASK) == SC_TYPEDEF) {
Entry->V.Offs = Offs; Entry->V.Offs = Offs;
} else if ((Flags & SC_REGISTER) == SC_REGISTER) { } else if ((Flags & SC_REGISTER) == SC_REGISTER) {
Entry->V.R.RegOffs = Offs; Entry->V.R.RegOffs = Offs;