FuncDesc* D = E->V.F.Func;
if ((D->Flags & FD_FASTCALL) != 0 && D->ParamCount > 0) {
/* Will use registers depending on the last param */
- SymEntry* LastParam = D->SymTab->SymTail;
- unsigned LastParamSize = CheckedSizeOf (LastParam->Type);
+ unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type);
if (LastParamSize == 1) {
*Use = REG_A;
} else if (LastParamSize == 2) {
ParseOldStyleParamList (F);
}
+ /* Remember the last function parameter. We need it later for several
+ * purposes, for example when passing stuff to fastcall functions. Since
+ * more symbols are added to the table, it is easier if we remember it
+ * now, since it is currently the last entry in the symbol table.
+ */
+ F->LastParam = GetSymTab()->SymTail;
+
/* Assign offsets. If the function has a variable parameter list,
* there's one additional byte (the arg size).
*/
Offs = (F->Flags & FD_VARIADIC)? 1 : 0;
- Sym = GetSymTab()->SymTail;
+ Sym = F->LastParam;
while (Sym) {
unsigned Size = CheckedSizeOf (Sym->Type);
if (SymIsRegVar (Sym)) {
FrameSize = Func->ParamSize;
if (FrameParams > 0 && (Func->Flags & FD_FASTCALL) != 0) {
/* Last parameter is not pushed */
- const SymEntry* LastParam = Func->SymTab->SymTail;
- FrameSize -= CheckedSizeOf (LastParam->Type);
+ FrameSize -= CheckedSizeOf (Func->LastParam->Type);
--FrameParams;
}
/* common */
#include "xmalloc.h"
-
+
/* cc65 */
#include "funcdesc.h"
F->TagTab = 0;
F->ParamCount = 0;
F->ParamSize = 0;
+ F->LastParam = 0;
/* Return the new struct */
return F;
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 */
};
/* Parse argument declarations and function body. */
{
int HadReturn;
- SymEntry* LastParam;
SymEntry* Param;
/* Get the function descriptor from the function entry */
/* Reenter the lexical level */
ReenterFunctionLevel (D);
- /* Before adding more symbols, remember the last parameter for later */
- LastParam = D->SymTab->SymTail;
-
/* Declare two special functions symbols: __fixargs__ and __argsize__.
* The latter is different depending on the type of the function (variadic
* or not).
CHECK ((D->Flags & FD_VARIADIC) == 0);
/* Generate the push */
- if (IsTypeFunc (LastParam->Type)) {
+ if (IsTypeFunc (D->LastParam->Type)) {
/* Pointer to function */
Flags = CF_PTR;
} else {
- Flags = TypeOf (LastParam->Type) | CF_FORCECHAR;
+ Flags = TypeOf (D->LastParam->Type) | CF_FORCECHAR;
}
g_push (Flags, 0);
}