From: cuz Date: Fri, 23 Mar 2001 10:16:50 +0000 (+0000) Subject: Make __fixargs__ an actual symbol table entry. Add a new pseudo variable X-Git-Tag: V2.12.0~2916 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=594a941ee94d1cd7369256ac6ffa9ebf26e33a64;p=cc65 Make __fixargs__ an actual symbol table entry. Add a new pseudo variable __argsize__. git-svn-id: svn://svn.cc65.org/cc65/trunk@646 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/expr.c b/src/cc65/expr.c index dc05dcfee..5ff685b97 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -772,7 +772,8 @@ static int primary (struct expent* lval) } /* Check for legal symbol types */ - if ((Sym->Flags & SC_ENUM) == SC_ENUM) { + if ((Sym->Flags & SC_CONST) == SC_CONST) { + /* Enum or some other numeric constant */ lval->e_flags = E_MCONST; lval->e_const = Sym->V.EnumVal; return 0; diff --git a/src/cc65/function.c b/src/cc65/function.c index 9ec1f52ab..c0b913ab4 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -219,6 +219,20 @@ void NewFunc (SymEntry* Func) /* Reenter the lexical level */ ReenterFunctionLevel (D); + /* Declare two special functions symbols: __fixargs__ and __argsize__. + * The latter is different depending on the type of the function (variadic + * or not). + */ + AddLocalSym ("__fixargs__", type_uint, SC_DEF | SC_CONST, D->ParamSize); + if (D->Flags & FD_ELLIPSIS) { + /* Variadic function. The variable must be const. */ + static const type T [] = { T_UCHAR | T_QUAL_CONST, T_END }; + AddLocalSym ("__argsize__", T, SC_DEF | SC_REF | SC_AUTO, 0); + } else { + /* Non variadic */ + AddLocalSym ("__argsize__", type_uchar, SC_DEF | SC_CONST, D->ParamSize); + } + /* Function body now defined */ Func->Flags |= SC_DEF; @@ -235,12 +249,16 @@ void NewFunc (SymEntry* Func) g_defgloblabel (Func->Name); /* If this is a fastcall function, push the last parameter onto the stack */ - if (IsFastCallFunc (Func->Type) && D->ParamCount > 0 && (D->Flags & FD_ELLIPSIS) == 0) { + if (IsFastCallFunc (Func->Type) && D->ParamCount > 0) { + SymEntry* LastParam; unsigned Flags; + /* Fastcall functions may never have an ellipsis or the compiler is buggy */ + CHECK ((D->Flags & FD_ELLIPSIS) == 0); + /* Get a pointer to the last parameter entry */ - SymEntry* LastParam = D->SymTab->SymTail; + LastParam = D->SymTab->SymTail; /* Generate the push */ if (IsTypeFunc (LastParam->Type)) { diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index e8939052c..58df8f76d 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -507,11 +507,6 @@ void NextToken (void) nxtval = GetCurrentLine(); nxttype = type_int; return; - } else if (strcmp (token, "__fixargs__") == 0) { - nxttok = TOK_ICONST; - nxtval = GetParamSize (CurrentFunc); - nxttype = type_uint; - return; } else if (strcmp (token, "__func__") == 0) { /* __func__ is only defined in functions */ if (CurrentFunc) { diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index 35ed800b4..59f34e4ab 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -34,10 +34,10 @@ #include - + /* common */ #include "xmalloc.h" - + /* cc65 */ #include "symentry.h" @@ -47,7 +47,7 @@ /* Code */ /*****************************************************************************/ - + SymEntry* NewSymEntry (const char* Name, unsigned Flags) /* Create a new symbol table with the given name */ @@ -99,6 +99,7 @@ void DumpSymEntry (FILE* F, const SymEntry* E) { "SC_STATIC", SC_STATIC }, { "SC_EXTERN", SC_EXTERN }, { "SC_ENUM", SC_ENUM }, + { "SC_CONST", SC_CONST }, { "SC_LABEL", SC_LABEL }, { "SC_PARAM", SC_PARAM }, { "SC_FUNC", SC_FUNC }, diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index 82f9458b9..610a06ee3 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -56,21 +56,22 @@ #define SC_STATIC 0x0004U #define SC_EXTERN 0x0008U -#define SC_ENUM 0x0010U /* An enum (numeric constant) */ -#define SC_LABEL 0x0020U /* A goto label */ -#define SC_PARAM 0x0040U /* This is a function parameter */ -#define SC_FUNC 0x0080U /* Function entry */ - -#define SC_STORAGE 0x0100U /* Symbol with associated storage */ -#define SC_DEFAULT 0x0200U /* Flag: default storage class was used */ - -#define SC_DEF 0x0400U /* Symbol is defined */ -#define SC_REF 0x0800U /* Symbol is referenced */ - -#define SC_TYPE 0x1000U /* This is a type, struct, typedef, etc. */ -#define SC_STRUCT 0x1001U /* Struct or union */ -#define SC_SFLD 0x1002U /* Struct or union field */ -#define SC_TYPEDEF 0x1003U /* A typedef */ +#define SC_ENUM 0x0030U /* An enum (numeric constant) */ +#define SC_CONST 0x0020U /* A numeric constant with a type */ +#define SC_LABEL 0x0040U /* A goto label */ +#define SC_PARAM 0x0080U /* This is a function parameter */ +#define SC_FUNC 0x0100U /* Function entry */ + +#define SC_STORAGE 0x0400U /* Symbol with associated storage */ +#define SC_DEFAULT 0x0800U /* Flag: default storage class was used */ + +#define SC_DEF 0x1000U /* Symbol is defined */ +#define SC_REF 0x2000U /* Symbol is referenced */ + +#define SC_TYPE 0x4000U /* This is a type, struct, typedef, etc. */ +#define SC_STRUCT 0x4001U /* Struct or union */ +#define SC_SFLD 0x4002U /* Struct or union field */ +#define SC_TYPEDEF 0x4003U /* A typedef */ #define SC_ZEROPAGE 0x8000U /* Symbol marked as zeropage */ diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 3bab90d7c..9228e5628 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -631,7 +631,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags) -SymEntry* AddLocalSym (const char* Name, type* Type, unsigned Flags, int Offs) +SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int Offs) /* Add a local symbol and return the symbol entry */ { /* Do we have an entry with this name already? */ @@ -661,7 +661,7 @@ SymEntry* AddLocalSym (const char* Name, type* Type, unsigned Flags, int Offs) -SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags) +SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) /* Add an external or global symbol to the symbol table and return the entry */ { /* Functions must be inserted in the global symbol table */ @@ -729,7 +729,7 @@ SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags) /* Create a new entry */ Entry = NewSymEntry (Name, Flags); - /* Set the symbol attributes */ + /* Set the symbol attributes */ Entry->Type = TypeDup (Type); /* Add the entry to the symbol table */ diff --git a/src/cc65/symtab.h b/src/cc65/symtab.h index 2e8c2a0e5..2628ecd5e 100644 --- a/src/cc65/symtab.h +++ b/src/cc65/symtab.h @@ -143,10 +143,10 @@ SymEntry* AddEnumSym (const char* Name, int Val); SymEntry* AddLabelSym (const char* Name, unsigned Flags); /* Add a goto label to the symbol table */ -SymEntry* AddLocalSym (const char* Name, type* Type, unsigned Flags, int Offs); +SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int Offs); /* Add a local symbol and return the symbol entry */ -SymEntry* AddGlobalSym (const char* Name, type* Type, unsigned Flags); +SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags); /* Add an external or global symbol to the symbol table and return the entry */