From 3755e4a863da973a7de60fa1abd6dde5d4379aef Mon Sep 17 00:00:00 2001 From: acqn Date: Wed, 24 Mar 2021 14:35:44 +0800 Subject: [PATCH] Replaced checking for __fastcall__ aginst AutoCDecl etc. with IsFastcallFunc(). --- src/cc65/codeinfo.c | 9 +++------ src/cc65/datatype.c | 21 ++++++++++++++++++--- src/cc65/datatype.h | 9 ++++++++- src/cc65/expr.c | 14 ++++---------- src/cc65/function.c | 5 +---- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index 90d4f4d68..d81f46001 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -493,17 +493,14 @@ fncls_t GetFuncInfo (const char* Name, unsigned int* Use, unsigned int* Chg) ** registers. */ *Use = REG_EAXY; - } else if ((D->ParamCount > 0 || - (D->Flags & FD_EMPTY) != 0) && - (AutoCDecl ? - IsQualFastcall (E->Type) : - !IsQualCDecl (E->Type))) { + } else if ((D->ParamCount > 0 || (D->Flags & FD_EMPTY) != 0) && + IsFastcallFunc (E->Type)) { /* Will use registers depending on the last param. If the last ** param has incomplete type, or if the function has not been ** prototyped yet, just assume __EAX__. */ if (D->LastParam != 0) { - switch (SizeOf(D->LastParam->Type)) { + switch (SizeOf (D->LastParam->Type)) { case 1u: *Use = REG_A; break; diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 6e42057dc..d29a0d807 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -1085,11 +1085,26 @@ int HasUnknownSize (const Type* T) int IsVariadicFunc (const Type* T) /* Return true if this is a function type or pointer to function type with -** variable parameter list +** variable parameter list. +** Check fails if the type is not a function or a pointer to function. */ { - FuncDesc* F = GetFuncDesc (T); - return (F->Flags & FD_VARIADIC) != 0; + return (GetFuncDesc (T)->Flags & FD_VARIADIC) != 0; +} + + + +int IsFastcallFunc (const Type* T) +/* Return true if this is a function type or pointer to function type by +** __fastcall__ calling convention. +** Check fails if the type is not a function or a pointer to function. +*/ +{ + if (UnqualifiedType (T->C) == T_PTR) { + /* Pointer to function */ + ++T; + } + return !IsVariadicFunc (T) && (AutoCDecl ? IsQualFastcall (T) : !IsQualCDecl (T)); } diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 5c3e71da5..ac6edeeb5 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -825,7 +825,14 @@ INLINE int IsQualCConv (const Type* T) int IsVariadicFunc (const Type* T) attribute ((const)); /* Return true if this is a function type or pointer to function type with -** variable parameter list +** variable parameter list. +** Check fails if the type is not a function or a pointer to function. +*/ + +int IsFastcallFunc (const Type* T) attribute ((const)); +/* Return true if this is a function type or pointer to function type by +** __fastcall__ calling convention. +** Check fails if the type is not a function or a pointer to function. */ FuncDesc* GetFuncDesc (const Type* T) attribute ((const)); diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 048819d50..9b95efda6 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -863,7 +863,7 @@ static void FunctionCall (ExprDesc* Expr) unsigned ParamSize; /* Number of parameter bytes */ CodeMark Mark; int PtrOffs = 0; /* Offset of function pointer on stack */ - int IsFastcall = 0; /* True if it's a fast-call function */ + int IsFastcall = 0; /* True if we are fast-calling the function */ int PtrOnStack = 0; /* True if a pointer copy is on stack */ Type* ReturnType; @@ -882,11 +882,8 @@ static void FunctionCall (ExprDesc* Expr) ** parameter count is zero. Handle K & R functions as though there are ** parameters. */ - IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && - (Func->ParamCount > 0 || (Func->Flags & FD_EMPTY)) && - (AutoCDecl ? - IsQualFastcall (Expr->Type + 1) : - !IsQualCDecl (Expr->Type + 1)); + IsFastcall = (Func->ParamCount > 0 || (Func->Flags & FD_EMPTY) != 0) && + IsFastcallFunc (Expr->Type + 1); /* Things may be difficult, depending on where the function pointer ** resides. If the function pointer is an expression of some sort @@ -931,10 +928,7 @@ static void FunctionCall (ExprDesc* Expr) } /* If we didn't inline the function, get fastcall info */ - IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && - (AutoCDecl ? - IsQualFastcall (Expr->Type) : - !IsQualCDecl (Expr->Type)); + IsFastcall = IsFastcallFunc (Expr->Type); } /* Parse the parameter list */ diff --git a/src/cc65/function.c b/src/cc65/function.c index 9269d4c62..cad1df629 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -558,10 +558,7 @@ void NewFunc (SymEntry* Func, FuncDesc* D) PushLiteralPool (Func); /* If this is a fastcall function, push the last parameter onto the stack */ - if ((D->Flags & FD_VARIADIC) == 0 && D->ParamCount > 0 && - (AutoCDecl ? - IsQualFastcall (Func->Type) : - !IsQualCDecl (Func->Type))) { + if (D->ParamCount > 0 && IsFastcallFunc (Func->Type)) { unsigned Flags; /* Generate the push */