Made __fastcall__ be the default calling convention for non-variadic functions.

This commit is contained in:
Greg King
2015-03-10 05:53:52 -04:00
parent 6230b6a813
commit a798b1d648
10 changed files with 72 additions and 73 deletions

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2001-2012, Ullrich von Bassewitz */
/* (C) 2001-2015, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@@ -386,33 +386,32 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg)
** Search for it in the list of builtin functions.
*/
if (Name[0] == '_') {
/* Search in the symbol table, skip the leading underscore */
SymEntry* E = FindGlobalSym (Name+1);
/* Did we find it in the top level table? */
/* Did we find it in the top-level table? */
if (E && IsTypeFunc (E->Type)) {
FuncDesc* D = E->V.F.Func;
/* A function may use the A or A/X registers if it is a fastcall
** function. If it is not a fastcall function but a variadic one,
** it will use the Y register (the parameter size is passed here).
** In all other cases, no registers are used. However, we assume
** that any function will destroy all registers.
/* A variadic function will use the Y register (the parameter list
** size is passed there). A fastcall function will use the A or A/X
** registers. In all other cases, no registers are used. However,
** we assume that any function will destroy all registers.
*/
if (IsQualFastcall (E->Type) && D->ParamCount > 0) {
/* Will use registers depending on the last param */
unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type);
if (LastParamSize == 1) {
*Use = REG_A;
} else if (LastParamSize == 2) {
*Use = REG_AX;
} else {
*Use = REG_EAX;
}
} else if ((D->Flags & FD_VARIADIC) != 0) {
if ((D->Flags & FD_VARIADIC) != 0) {
*Use = REG_Y;
} else if (!IsQualCDecl (E->Type) && D->ParamCount > 0) {
/* Will use registers depending on the last param. */
switch (CheckedSizeOf (D->LastParam->Type)) {
case 1u:
*Use = REG_A;
break;
case 2u:
*Use = REG_AX;
break;
default:
*Use = REG_EAX;
}
} else {
/* Will not use any registers */
*Use = REG_NONE;

View File

@@ -1,6 +1,7 @@
/* expr.c
**
** Ullrich von Bassewitz, 21.06.1998
** 1998-06-21, Ullrich von Bassewitz
** 2015-03-10, Greg King
*/
@@ -471,8 +472,8 @@ static void FunctionCall (ExprDesc* Expr)
IsFuncPtr = IsTypeFuncPtr (Expr->Type);
if (IsFuncPtr) {
/* Check wether it's a fastcall function that has parameters */
IsFastcall = IsQualFastcall (Expr->Type + 1) && (Func->ParamCount > 0);
/* Check whether it's a fastcall function that has parameters */
IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type + 1) && (Func->ParamCount > 0);
/* Things may be difficult, depending on where the function pointer
** resides. If the function pointer is an expression of some sort
@@ -517,7 +518,7 @@ static void FunctionCall (ExprDesc* Expr)
}
/* If we didn't inline the function, get fastcall info */
IsFastcall = IsQualFastcall (Expr->Type);
IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type);
}
/* Parse the parameter list */

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2000-2012, Ullrich von Bassewitz */
/* (C) 2000-2015, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@@ -460,6 +460,9 @@ void NewFunc (SymEntry* Func)
*/
if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
g_importmainargs ();
/* The start-up code doesn't fast-call main(). */
Func->Type->C |= T_QUAL_CDECL;
}
/* Determine if this is a main function in a C99 environment that
@@ -478,13 +481,9 @@ void NewFunc (SymEntry* Func)
PushLiteralPool (Func);
/* If this is a fastcall function, push the last parameter onto the stack */
if (IsQualFastcall (Func->Type) && D->ParamCount > 0) {
if ((D->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Func->Type) && D->ParamCount > 0) {
unsigned Flags;
/* Fastcall functions may never have an ellipsis or the compiler is buggy */
CHECK ((D->Flags & FD_VARIADIC) == 0);
/* Generate the push */
if (IsTypeFunc (D->LastParam->Type)) {
/* Pointer to function */