mirror of
https://github.com/cc65/cc65.git
synced 2025-01-03 01:31:55 +00:00
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
This commit is contained in:
parent
9a34fdb41e
commit
73dfa23c98
@ -287,8 +287,7 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg)
|
|||||||
FuncDesc* D = E->V.F.Func;
|
FuncDesc* D = E->V.F.Func;
|
||||||
if ((D->Flags & FD_FASTCALL) != 0 && D->ParamCount > 0) {
|
if ((D->Flags & FD_FASTCALL) != 0 && D->ParamCount > 0) {
|
||||||
/* Will use registers depending on the last param */
|
/* Will use registers depending on the last param */
|
||||||
SymEntry* LastParam = D->SymTab->SymTail;
|
unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type);
|
||||||
unsigned LastParamSize = CheckedSizeOf (LastParam->Type);
|
|
||||||
if (LastParamSize == 1) {
|
if (LastParamSize == 1) {
|
||||||
*Use = REG_A;
|
*Use = REG_A;
|
||||||
} else if (LastParamSize == 2) {
|
} else if (LastParamSize == 2) {
|
||||||
|
@ -806,11 +806,18 @@ static FuncDesc* ParseFuncDecl (const DeclSpec* Spec)
|
|||||||
ParseOldStyleParamList (F);
|
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,
|
/* Assign offsets. If the function has a variable parameter list,
|
||||||
* there's one additional byte (the arg size).
|
* there's one additional byte (the arg size).
|
||||||
*/
|
*/
|
||||||
Offs = (F->Flags & FD_VARIADIC)? 1 : 0;
|
Offs = (F->Flags & FD_VARIADIC)? 1 : 0;
|
||||||
Sym = GetSymTab()->SymTail;
|
Sym = F->LastParam;
|
||||||
while (Sym) {
|
while (Sym) {
|
||||||
unsigned Size = CheckedSizeOf (Sym->Type);
|
unsigned Size = CheckedSizeOf (Sym->Type);
|
||||||
if (SymIsRegVar (Sym)) {
|
if (SymIsRegVar (Sym)) {
|
||||||
|
@ -583,8 +583,7 @@ static unsigned FunctionParamList (FuncDesc* Func)
|
|||||||
FrameSize = Func->ParamSize;
|
FrameSize = Func->ParamSize;
|
||||||
if (FrameParams > 0 && (Func->Flags & FD_FASTCALL) != 0) {
|
if (FrameParams > 0 && (Func->Flags & FD_FASTCALL) != 0) {
|
||||||
/* Last parameter is not pushed */
|
/* Last parameter is not pushed */
|
||||||
const SymEntry* LastParam = Func->SymTab->SymTail;
|
FrameSize -= CheckedSizeOf (Func->LastParam->Type);
|
||||||
FrameSize -= CheckedSizeOf (LastParam->Type);
|
|
||||||
--FrameParams;
|
--FrameParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "funcdesc.h"
|
#include "funcdesc.h"
|
||||||
|
|
||||||
@ -59,6 +59,7 @@ FuncDesc* NewFuncDesc (void)
|
|||||||
F->TagTab = 0;
|
F->TagTab = 0;
|
||||||
F->ParamCount = 0;
|
F->ParamCount = 0;
|
||||||
F->ParamSize = 0;
|
F->ParamSize = 0;
|
||||||
|
F->LastParam = 0;
|
||||||
|
|
||||||
/* Return the new struct */
|
/* Return the new struct */
|
||||||
return F;
|
return F;
|
||||||
|
@ -67,6 +67,7 @@ struct FuncDesc {
|
|||||||
struct SymTable* TagTab; /* Symbol table for structs/enums */
|
struct SymTable* TagTab; /* Symbol table for structs/enums */
|
||||||
unsigned ParamCount; /* Number of parameters */
|
unsigned ParamCount; /* Number of parameters */
|
||||||
unsigned ParamSize; /* Size of the parameters */
|
unsigned ParamSize; /* Size of the parameters */
|
||||||
|
struct SymEntry* LastParam; /* Pointer to last parameter */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,7 +334,6 @@ void NewFunc (SymEntry* Func)
|
|||||||
/* Parse argument declarations and function body. */
|
/* Parse argument declarations and function body. */
|
||||||
{
|
{
|
||||||
int HadReturn;
|
int HadReturn;
|
||||||
SymEntry* LastParam;
|
|
||||||
SymEntry* Param;
|
SymEntry* Param;
|
||||||
|
|
||||||
/* Get the function descriptor from the function entry */
|
/* Get the function descriptor from the function entry */
|
||||||
@ -346,9 +345,6 @@ void NewFunc (SymEntry* Func)
|
|||||||
/* Reenter the lexical level */
|
/* Reenter the lexical level */
|
||||||
ReenterFunctionLevel (D);
|
ReenterFunctionLevel (D);
|
||||||
|
|
||||||
/* Before adding more symbols, remember the last parameter for later */
|
|
||||||
LastParam = D->SymTab->SymTail;
|
|
||||||
|
|
||||||
/* Declare two special functions symbols: __fixargs__ and __argsize__.
|
/* Declare two special functions symbols: __fixargs__ and __argsize__.
|
||||||
* The latter is different depending on the type of the function (variadic
|
* The latter is different depending on the type of the function (variadic
|
||||||
* or not).
|
* or not).
|
||||||
@ -394,11 +390,11 @@ void NewFunc (SymEntry* Func)
|
|||||||
CHECK ((D->Flags & FD_VARIADIC) == 0);
|
CHECK ((D->Flags & FD_VARIADIC) == 0);
|
||||||
|
|
||||||
/* Generate the push */
|
/* Generate the push */
|
||||||
if (IsTypeFunc (LastParam->Type)) {
|
if (IsTypeFunc (D->LastParam->Type)) {
|
||||||
/* Pointer to function */
|
/* Pointer to function */
|
||||||
Flags = CF_PTR;
|
Flags = CF_PTR;
|
||||||
} else {
|
} else {
|
||||||
Flags = TypeOf (LastParam->Type) | CF_FORCECHAR;
|
Flags = TypeOf (D->LastParam->Type) | CF_FORCECHAR;
|
||||||
}
|
}
|
||||||
g_push (Flags, 0);
|
g_push (Flags, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user