From: cuz Date: Sun, 10 Aug 2003 17:05:18 +0000 (+0000) Subject: Fixed a bug that caused problems locating the last parameter of a function X-Git-Tag: V2.12.0~1465 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=73dfa23c987d8a7f1154801b85c171f9e01dcd58;p=cc65 Fixed a bug that caused problems locating the last parameter of a function git-svn-id: svn://svn.cc65.org/cc65/trunk@2259 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index cf04baf9c..ed4fae03b 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -287,8 +287,7 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg) 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) { diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 73f7e27ea..93760bc82 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -806,11 +806,18 @@ static FuncDesc* ParseFuncDecl (const DeclSpec* Spec) 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)) { diff --git a/src/cc65/expr.c b/src/cc65/expr.c index b10c568b4..b71d2d670 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -583,8 +583,7 @@ static unsigned FunctionParamList (FuncDesc* Func) 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; } diff --git a/src/cc65/funcdesc.c b/src/cc65/funcdesc.c index cccff02c2..cfba7fec8 100644 --- a/src/cc65/funcdesc.c +++ b/src/cc65/funcdesc.c @@ -35,7 +35,7 @@ /* common */ #include "xmalloc.h" - + /* cc65 */ #include "funcdesc.h" @@ -59,6 +59,7 @@ FuncDesc* NewFuncDesc (void) F->TagTab = 0; F->ParamCount = 0; F->ParamSize = 0; + F->LastParam = 0; /* Return the new struct */ return F; diff --git a/src/cc65/funcdesc.h b/src/cc65/funcdesc.h index afdda89d9..973e1c2c8 100644 --- a/src/cc65/funcdesc.h +++ b/src/cc65/funcdesc.h @@ -67,6 +67,7 @@ struct FuncDesc { 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 */ }; diff --git a/src/cc65/function.c b/src/cc65/function.c index c4f30ca49..fb274d8f9 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -334,7 +334,6 @@ void NewFunc (SymEntry* Func) /* Parse argument declarations and function body. */ { int HadReturn; - SymEntry* LastParam; SymEntry* Param; /* Get the function descriptor from the function entry */ @@ -346,9 +345,6 @@ void NewFunc (SymEntry* Func) /* 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). @@ -394,11 +390,11 @@ void NewFunc (SymEntry* Func) 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); }