Merge branch 'master' into master

This commit is contained in:
WayneParham
2021-05-16 10:02:37 -05:00
committed by GitHub
33 changed files with 519 additions and 307 deletions

View File

@@ -184,7 +184,7 @@ INLINE CodeLabel* CE_GetLabel (CodeEntry* E, unsigned Index)
INLINE void CE_ReplaceLabel (CodeEntry* E, CodeLabel* L, unsigned Index)
/* Replace the code label at the specified index with L */
{
return CollReplace (&E->Labels, L, Index);
CollReplace (&E->Labels, L, Index);
}
#else
# define CE_ReplaceLabel(E, L, Index) CollReplace (&(E)->Labels, (L), (Index))

View File

@@ -1447,7 +1447,7 @@ void AdjustEntryIndices (Collection* Indices, int Index, int Change)
} else if (Index <= *IndexPtr) {
/* Has been removed */
*IndexPtr = -1;
//CollDelete (Indices, I);
/*CollDelete (Indices, I);*/
--I;
}
}

View File

@@ -156,9 +156,8 @@ static void Parse (void)
**
** This means that "extern int i;" will not get storage allocated.
*/
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
(Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF &&
(Decl.StorageClass & SC_FICTITIOUS) != SC_FICTITIOUS) {
if ((Decl.StorageClass & SC_FUNC) != SC_FUNC &&
(Decl.StorageClass & SC_TYPEMASK) != SC_TYPEDEF) {
if ((Spec.Flags & DS_DEF_STORAGE) != 0 ||
(Decl.StorageClass & (SC_EXTERN|SC_STATIC)) == SC_STATIC ||
((Decl.StorageClass & SC_EXTERN) != 0 &&

View File

@@ -1242,7 +1242,7 @@ const Type* GetBaseElementType (const Type* T)
SymEntry* GetESUSymEntry (const Type* T)
struct SymEntry* GetESUSymEntry (const Type* T)
/* Return a SymEntry pointer from an enum/struct/union type */
{
/* Only enums, structs or unions have a SymEntry attribute */
@@ -1254,7 +1254,7 @@ SymEntry* GetESUSymEntry (const Type* T)
void SetESUSymEntry (Type* T, SymEntry* S)
void SetESUSymEntry (Type* T, struct SymEntry* S)
/* Set the SymEntry pointer for an enum/struct/union type */
{
/* Only enums, structs or unions have a SymEntry attribute */

View File

@@ -45,6 +45,9 @@
#include "inline.h"
#include "mmodel.h"
/* cc65 */
#include "funcdesc.h"
/*****************************************************************************/
@@ -53,8 +56,8 @@
typedef struct FuncDesc FuncDesc;
typedef struct SymEntry SymEntry;
struct StrBuf;
struct SymEntry;
@@ -162,12 +165,12 @@ typedef unsigned long TypeCode;
/* Type entry */
typedef struct Type Type;
struct Type {
TypeCode C; /* Code for this entry */
TypeCode C; /* Code for this entry */
union {
FuncDesc* F; /* Function description pointer */
SymEntry* S; /* Enum/struct/union tag symbol entry pointer */
long L; /* Numeric attribute value */
unsigned long U; /* Dito, unsigned */
struct FuncDesc* F; /* Function description pointer */
struct SymEntry* S; /* Enum/struct/union tag symbol entry pointer */
long L; /* Numeric attribute value */
unsigned long U; /* Dito, unsigned */
} A; /* Type attribute if necessary */
};
@@ -221,11 +224,6 @@ extern const Type type_c_char_p[];
extern const Type type_void_p[];
extern const Type type_c_void_p[];
/* Forward for the SymEntry struct */
struct SymEntry;
/* Forward for the StrBuf struct */
struct StrBuf;
/*****************************************************************************/
@@ -849,7 +847,7 @@ int IsVariadicFunc (const Type* T) attribute ((const));
*/
int IsFastcallFunc (const Type* T) attribute ((const));
/* Return true if this is a function type or pointer to function type by
/* Return true if this is a function type or pointer to function type with
** __fastcall__ calling convention.
** Check fails if the type is not a function or a pointer to function.
*/

View File

@@ -1738,7 +1738,7 @@ static FuncDesc* ParseFuncDecl (void)
{
SymEntry* Sym;
SymEntry* WrappedCall;
unsigned char WrappedCallData;
unsigned int WrappedCallData;
/* Create a new function descriptor */
FuncDesc* F = NewFuncDesc ();
@@ -2080,7 +2080,7 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
if (PrevErrorCount != ErrorCount) {
/* Make the declaration fictitious if is is not parsed correctly */
D->StorageClass |= SC_DECL | SC_FICTITIOUS;
D->StorageClass |= SC_FICTITIOUS;
if (Mode == DM_NEED_IDENT && D->Ident[0] == '\0') {
/* Use a fictitious name for the identifier if it is missing */

View File

@@ -129,7 +129,7 @@ void Fatal (const char* Format, ...)
LineNum = GetCurrentLine ();
}
fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
fprintf (stderr, "%s:%u: Fatal: ", FileName, LineNum);
va_start (ap, Format);
vfprintf (stderr, Format, ap);
@@ -159,7 +159,7 @@ void Internal (const char* Format, ...)
LineNum = GetCurrentLine ();
}
fprintf (stderr, "%s(%u): Internal compiler error:\n",
fprintf (stderr, "%s:%u: Internal compiler error:\n",
FileName, LineNum);
va_start (ap, Format);
@@ -186,7 +186,7 @@ void Internal (const char* Format, ...)
static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
/* Print an error message - internal function*/
{
fprintf (stderr, "%s(%u): Error: ", Filename, LineNo);
fprintf (stderr, "%s:%u: Error: ", Filename, LineNo);
vfprintf (stderr, Msg, ap);
fprintf (stderr, "\n");
@@ -250,7 +250,7 @@ static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg,
} else if (IS_Get (&WarnEnable)) {
fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
fprintf (stderr, "%s:%u: Warning: ", Filename, LineNo);
vfprintf (stderr, Msg, ap);
fprintf (stderr, "\n");

View File

@@ -997,9 +997,16 @@ static void FunctionCall (ExprDesc* Expr)
char tmp[64];
StrBuf S = AUTO_STRBUF_INITIALIZER;
/* Store the WrappedCall data in tmp4 */
sprintf(tmp, "ldy #%u", Func->WrappedCallData);
SB_AppendStr (&S, tmp);
if (Func->WrappedCallData == WRAPPED_CALL_USE_BANK) {
/* Store the bank attribute in tmp4 */
SB_AppendStr (&S, "ldy #<.bank(_");
SB_AppendStr (&S, (const char*) Expr->Name);
SB_AppendChar (&S, ')');
} else {
/* Store the WrappedCall data in tmp4 */
sprintf(tmp, "ldy #%u", Func->WrappedCallData);
SB_AppendStr (&S, tmp);
}
g_asmcode (&S);
SB_Clear(&S);
@@ -1294,6 +1301,7 @@ static void Primary (ExprDesc* E)
/* Statement block */
NextToken ();
Error ("Expression expected");
E->Flags |= E_EVAL_MAYBE_UNUSED;
hie0 (E);
if (CurTok.Tok == TOK_RCURLY) {
NextToken ();
@@ -1325,6 +1333,7 @@ static void Primary (ExprDesc* E)
}
} else {
Error ("Expression expected");
E->Flags |= E_EVAL_MAYBE_UNUSED;
NextToken ();
}
}

View File

@@ -54,14 +54,14 @@ FuncDesc* NewFuncDesc (void)
FuncDesc* F = (FuncDesc*) xmalloc (sizeof (FuncDesc));
/* Nullify the fields */
F->Flags = 0;
F->SymTab = 0;
F->TagTab = 0;
F->ParamCount = 0;
F->ParamSize = 0;
F->LastParam = 0;
F->FuncDef = 0;
F->WrappedCall = 0;
F->Flags = 0;
F->SymTab = 0;
F->TagTab = 0;
F->ParamCount = 0;
F->ParamSize = 0;
F->LastParam = 0;
F->FuncDef = 0;
F->WrappedCall = 0;
F->WrappedCallData = 0;
/* Return the new struct */

View File

@@ -45,33 +45,33 @@
/* Masks for the Flags field in FuncDesc */
#define FD_NONE 0x0000U /* No flags */
#define FD_EMPTY 0x0001U /* Function with empty param list */
#define FD_VOID_PARAM 0x0002U /* Function with a void param list */
#define FD_VARIADIC 0x0004U /* Function with variable param list */
#define FD_NONE 0x0000U /* No flags */
#define FD_EMPTY 0x0001U /* Function with empty param list */
#define FD_VOID_PARAM 0x0002U /* Function with a void param list */
#define FD_VARIADIC 0x0004U /* Function with variable param list */
#define FD_INCOMPLETE_PARAM 0x0008U /* Function with param of unknown size */
#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */
#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */
#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */
#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */
#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */
#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */
#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */
#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */
/* Bits that must be ignored when comparing funcs */
#define FD_IGNORE (FD_INCOMPLETE_PARAM | FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER)
#define WRAPPED_CALL_USE_BANK 0x0100U /* WrappedCall uses .bank() */
/* Function descriptor */
typedef struct FuncDesc FuncDesc;
struct FuncDesc {
unsigned Flags; /* Bitmapped flags FD_... */
struct SymTable* SymTab; /* Symbol table */
struct SymTable* TagTab; /* Symbol table for structs/enums */
unsigned ParamCount; /* Number of parameters */
unsigned ParamSize; /* Size of the parameters */
struct SymEntry* LastParam; /* Pointer to last parameter */
struct FuncDesc* FuncDef; /* Descriptor used in definition */
struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */
unsigned char WrappedCallData;/* The WrappedCall's user data */
unsigned Flags; /* Bitmapped flags FD_... */
struct SymTable* SymTab; /* Symbol table */
struct SymTable* TagTab; /* Symbol table for structs/enums */
unsigned ParamCount; /* Number of parameters */
unsigned ParamSize; /* Size of the parameters */
struct SymEntry* LastParam; /* Pointer to last parameter */
struct FuncDesc* FuncDef; /* Descriptor used in definition */
struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */
unsigned int WrappedCallData; /* The WrappedCall's user data */
};

View File

@@ -476,8 +476,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
}
/* If the symbol is not marked as external, it will be defined now */
if ((Decl.StorageClass & SC_FICTITIOUS) == 0 &&
(Decl.StorageClass & SC_DECL) == 0 &&
if ((Decl.StorageClass & SC_DECL) == 0 &&
(Decl.StorageClass & SC_EXTERN) == 0) {
Decl.StorageClass |= SC_DEF;
}

View File

@@ -531,16 +531,19 @@ static void WrappedCallPragma (StrBuf* B)
/* Skip the following comma */
if (!GetComma (B)) {
/* Error already flagged by GetComma */
Error ("Value or the word 'bank' required for wrapped-call identifier");
goto ExitPoint;
}
/* Next must be either a numeric value, or "bank" */
if (HasStr (B, "bank")) {
Val = WRAPPED_CALL_USE_BANK;
} else if (!GetNumber (B, &Val)) {
Error ("Value required for wrapped-call identifier");
goto ExitPoint;
}
if (!GetNumber (B, &Val)) {
Error ("Value required for wrapped-call identifier");
goto ExitPoint;
}
if (Val < 0 || Val > 255) {
if (!(Val == WRAPPED_CALL_USE_BANK) && (Val < 0 || Val > 255)) {
Error ("Identifier must be between 0-255");
goto ExitPoint;
}
@@ -552,7 +555,7 @@ static void WrappedCallPragma (StrBuf* B)
/* Check if the name is valid */
if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) {
PushWrappedCall(Entry, (unsigned char) Val);
PushWrappedCall(Entry, (unsigned int) Val);
Entry->Flags |= SC_REF;
GetFuncDesc (Entry->Type)->Flags |= FD_CALL_WRAPPER;
@@ -781,7 +784,7 @@ static void IntPragma (StrBuf* B, IntStack* Stack, long Low, long High)
static void MakeMessage (const char* Message)
{
fprintf (stderr, "%s(%u): Note: %s\n", GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Message);
fprintf (stderr, "%s:%u: Note: %s\n", GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Message);
}

View File

@@ -1396,7 +1396,7 @@ void Preprocess (void)
Done:
if (Verbosity > 1 && SB_NotEmpty (Line)) {
printf ("%s(%u): %.*s\n", GetCurrentFile (), GetCurrentLine (),
printf ("%s:%u: %.*s\n", GetCurrentFile (), GetCurrentLine (),
(int) SB_GetLen (Line), SB_GetConstBuf (Line));
}
}

View File

@@ -64,7 +64,7 @@ static IntPtrStack WrappedCalls;
void PushWrappedCall (void *Ptr, unsigned char Val)
void PushWrappedCall (void *Ptr, unsigned int Val)
/* Push the current WrappedCall */
{
if (IPS_IsFull (&WrappedCalls)) {
@@ -88,7 +88,7 @@ void PopWrappedCall (void)
void GetWrappedCall (void **Ptr, unsigned char *Val)
void GetWrappedCall (void **Ptr, unsigned int *Val)
/* Get the current WrappedCall */
{
if (IPS_GetCount (&WrappedCalls) < 1) {
@@ -97,6 +97,6 @@ void GetWrappedCall (void **Ptr, unsigned char *Val)
} else {
long Temp;
IPS_Get (&WrappedCalls, &Temp, Ptr);
*Val = (unsigned char) Temp;
*Val = (unsigned int) Temp;
}
}

View File

@@ -50,13 +50,13 @@
void PushWrappedCall (void *Ptr, unsigned char Val);
void PushWrappedCall (void *Ptr, unsigned int Val);
/* Push the current WrappedCall */
void PopWrappedCall (void);
/* Pop the current WrappedCall */
void GetWrappedCall (void **Ptr, unsigned char *Val);
void GetWrappedCall (void **Ptr, unsigned int *Val);
/* Get the current WrappedCall, if any */