2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* locals.c */
|
|
|
|
/* */
|
|
|
|
/* Local variable handling for the cc65 C compiler */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2002-03-10 20:44:58 +00:00
|
|
|
/* (C) 2000-2002 Ullrich von Bassewitz */
|
2001-03-26 21:57:07 +00:00
|
|
|
/* Wacholderweg 14 */
|
|
|
|
/* D-70597 Stuttgart */
|
2001-05-03 17:34:54 +00:00
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 19:26:13 +00:00
|
|
|
/* common */
|
|
|
|
#include "xmalloc.h"
|
2000-10-10 20:39:04 +00:00
|
|
|
#include "xsprintf.h"
|
|
|
|
|
2000-09-14 19:26:13 +00:00
|
|
|
/* cc65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "anonname.h"
|
|
|
|
#include "asmlabel.h"
|
|
|
|
#include "codegen.h"
|
|
|
|
#include "declare.h"
|
2000-06-22 11:28:39 +00:00
|
|
|
#include "error.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "expr.h"
|
2000-06-12 18:31:40 +00:00
|
|
|
#include "function.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "locals.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Register variable management */
|
|
|
|
unsigned MaxRegSpace = 6; /* Maximum space available */
|
2000-06-08 21:11:48 +00:00
|
|
|
static unsigned RegOffs = 0; /* Offset into register space */
|
2000-05-28 13:40:48 +00:00
|
|
|
static const SymEntry** RegSyms = 0; /* The register variables */
|
|
|
|
static unsigned RegSymCount = 0; /* Number of register variables */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitRegVars (void)
|
|
|
|
/* Initialize register variable control data */
|
|
|
|
{
|
|
|
|
/* If the register space is zero, bail out */
|
|
|
|
if (MaxRegSpace == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The maximum number of register variables is equal to the register
|
|
|
|
* variable space available. So allocate one pointer per byte. This
|
|
|
|
* will usually waste some space but we don't need to dynamically
|
|
|
|
* grow the array.
|
|
|
|
*/
|
2001-03-23 19:17:04 +00:00
|
|
|
RegSyms = (const SymEntry**) xmalloc (MaxRegSpace * sizeof (RegSyms[0]));
|
2000-05-28 13:40:48 +00:00
|
|
|
RegOffs = MaxRegSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DoneRegVars (void)
|
|
|
|
/* Free the register variables */
|
|
|
|
{
|
|
|
|
xfree (RegSyms);
|
|
|
|
RegSyms = 0;
|
|
|
|
RegOffs = MaxRegSpace;
|
|
|
|
RegSymCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int AllocRegVar (const SymEntry* Sym, const type* tarray)
|
|
|
|
/* Allocate a register variable with the given amount of storage. If the
|
|
|
|
* allocation was successful, return the offset of the register variable in
|
|
|
|
* the register bank (zero page storage). If there is no register space left,
|
|
|
|
* return -1.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Maybe register variables are disabled... */
|
|
|
|
if (EnableRegVars) {
|
|
|
|
|
|
|
|
/* Get the size of the variable */
|
2002-03-10 20:44:58 +00:00
|
|
|
unsigned Size = CheckedSizeOf (tarray);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Do we have space left? */
|
|
|
|
if (RegOffs >= Size) {
|
|
|
|
|
|
|
|
/* Space left. We allocate the variables from high to low addresses,
|
|
|
|
* so the adressing is compatible with the saved values on stack.
|
|
|
|
* This allows shorter code when saving/restoring the variables.
|
|
|
|
*/
|
|
|
|
RegOffs -= Size;
|
|
|
|
RegSyms [RegSymCount++] = Sym;
|
|
|
|
return RegOffs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No space left or no allocation */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
static void ParseOneDecl (const DeclSpec* Spec)
|
|
|
|
/* Parse one variable declaration */
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2000-06-22 11:28:39 +00:00
|
|
|
int Size; /* Size of an auto variable */
|
|
|
|
int SC; /* Storage class for symbol */
|
|
|
|
int SymData = 0; /* Symbol data (offset, label name, ...) */
|
|
|
|
unsigned flags = 0; /* Code generator flags */
|
|
|
|
Declaration Decl; /* Declaration data structure */
|
|
|
|
|
|
|
|
/* Remember the storage class for the new symbol */
|
|
|
|
SC = Spec->StorageClass;
|
|
|
|
|
|
|
|
/* Read the declaration */
|
|
|
|
ParseDecl (Spec, &Decl, DM_NEED_IDENT);
|
|
|
|
|
|
|
|
/* Set the correct storage class for functions */
|
2000-08-01 18:45:08 +00:00
|
|
|
if (IsTypeFunc (Decl.Type)) {
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Function prototypes are always external */
|
|
|
|
if ((SC & SC_EXTERN) == 0) {
|
2000-10-15 19:52:01 +00:00
|
|
|
Warning ("Function must be extern");
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
2000-06-22 11:28:39 +00:00
|
|
|
SC |= SC_FUNC | SC_EXTERN;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* If we don't have a name, this was flagged as an error earlier.
|
|
|
|
* To avoid problems later, use an anonymous name here.
|
|
|
|
*/
|
|
|
|
if (Decl.Ident[0] == '\0') {
|
|
|
|
AnonName (Decl.Ident, "param");
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Handle anything that needs storage (no functions, no typdefs) */
|
|
|
|
if ((SC & SC_FUNC) != SC_FUNC && (SC & SC_TYPEDEF) != SC_TYPEDEF) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Get the size of the variable */
|
|
|
|
Size = SizeOf (Decl.Type);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-07 20:59:43 +00:00
|
|
|
/* */
|
2000-06-22 11:28:39 +00:00
|
|
|
if (SC & (SC_AUTO | SC_REGISTER)) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Auto variable */
|
|
|
|
if (StaticLocals == 0) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Change SC in case it was register */
|
|
|
|
SC = (SC & ~SC_REGISTER) | SC_AUTO;
|
2001-05-22 09:32:24 +00:00
|
|
|
if (CurTok.Tok == TOK_ASSIGN) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-07-17 21:24:19 +00:00
|
|
|
ExprDesc lval;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Allocate previously reserved local space */
|
2002-06-12 12:12:04 +00:00
|
|
|
F_AllocLocalSpace (CurrentFunc);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Skip the '=' */
|
|
|
|
NextToken ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Setup the type flags for the assignment */
|
|
|
|
flags = Size == 1? CF_FORCECHAR : CF_NONE;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Get the expression into the primary */
|
2002-03-10 14:34:20 +00:00
|
|
|
if (evalexpr (flags, hie1, &lval) == 0) {
|
|
|
|
/* Constant expression. Adjust the types */
|
|
|
|
assignadjust (Decl.Type, &lval);
|
|
|
|
flags |= CF_CONST;
|
|
|
|
} else {
|
|
|
|
/* Expression is not constant and in the primary */
|
|
|
|
assignadjust (Decl.Type, &lval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push the value */
|
|
|
|
g_push (flags | TypeOf (Decl.Type), lval.ConstVal);
|
|
|
|
|
|
|
|
/* Mark the variable as referenced */
|
|
|
|
SC |= SC_REF;
|
|
|
|
|
|
|
|
/* Variable is located at the current SP */
|
|
|
|
SymData = oursp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Non-initialized local variable. Just keep track of
|
|
|
|
* the space needed.
|
|
|
|
*/
|
2002-06-12 12:12:04 +00:00
|
|
|
SymData = F_ReserveLocalSpace (CurrentFunc, Size);
|
2002-03-10 14:34:20 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
} else {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Static local variables. */
|
|
|
|
SC = (SC & ~(SC_REGISTER | SC_AUTO)) | SC_STATIC;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Put them into the BSS */
|
|
|
|
g_usebss ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Define the variable label */
|
|
|
|
SymData = GetLocalLabel ();
|
|
|
|
g_defdatalabel (SymData);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Reserve space for the data */
|
|
|
|
g_res (Size);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Allow assignments */
|
|
|
|
if (CurTok.Tok == TOK_ASSIGN) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
ExprDesc lval;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Skip the '=' */
|
|
|
|
NextToken ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Setup the type flags for the assignment */
|
|
|
|
flags = Size == 1? CF_FORCECHAR : CF_NONE;
|
2001-09-21 13:48:55 +00:00
|
|
|
|
|
|
|
/* Get the expression into the primary */
|
2002-03-10 14:34:20 +00:00
|
|
|
if (evalexpr (flags, hie1, &lval) == 0) {
|
|
|
|
/* Constant expression. Adjust the types */
|
|
|
|
assignadjust (Decl.Type, &lval);
|
|
|
|
flags |= CF_CONST;
|
|
|
|
/* Load it into the primary */
|
|
|
|
exprhs (flags, 0, &lval);
|
|
|
|
} else {
|
|
|
|
/* Expression is not constant and in the primary */
|
|
|
|
assignadjust (Decl.Type, &lval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the value into the variable */
|
|
|
|
g_putstatic (flags | TypeOf (Decl.Type), SymData, 0);
|
|
|
|
|
|
|
|
/* Mark the variable as referenced */
|
|
|
|
SC |= SC_REF;
|
|
|
|
}
|
2000-06-22 11:28:39 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
} else if ((SC & SC_STATIC) == SC_STATIC) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Static data */
|
2001-05-22 09:32:24 +00:00
|
|
|
if (CurTok.Tok == TOK_ASSIGN) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Initialization ahead, switch to data segment */
|
2002-03-10 14:34:20 +00:00
|
|
|
if (IsQualConst (Decl.Type)) {
|
|
|
|
g_userodata ();
|
|
|
|
} else {
|
|
|
|
g_usedata ();
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Define the variable label */
|
2001-04-19 06:49:08 +00:00
|
|
|
SymData = GetLocalLabel ();
|
2001-05-03 20:16:41 +00:00
|
|
|
g_defdatalabel (SymData);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Skip the '=' */
|
|
|
|
NextToken ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Allow initialization of static vars */
|
|
|
|
ParseInit (Decl.Type);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* If the previous size has been unknown, it must be known now */
|
|
|
|
if (Size == 0) {
|
|
|
|
Size = SizeOf (Decl.Type);
|
|
|
|
}
|
|
|
|
|
2000-08-01 19:05:24 +00:00
|
|
|
/* Mark the variable as referenced */
|
2002-03-10 14:34:20 +00:00
|
|
|
SC |= SC_REF;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
} else {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Uninitialized data, use BSS segment */
|
|
|
|
g_usebss ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Define the variable label */
|
|
|
|
SymData = GetLocalLabel ();
|
|
|
|
g_defdatalabel (SymData);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Reserve space for the data */
|
|
|
|
g_res (Size);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-03-10 14:34:20 +00:00
|
|
|
/* Cannot allocate a variable of zero size */
|
|
|
|
if (Size == 0) {
|
|
|
|
Error ("Variable `%s' has unknown size", Decl.Ident);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-22 11:28:39 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* If the symbol is not marked as external, it will be defined */
|
|
|
|
if ((SC & SC_EXTERN) == 0) {
|
2002-03-10 14:34:20 +00:00
|
|
|
SC |= SC_DEF;
|
2000-06-22 11:28:39 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Add the symbol to the symbol table */
|
|
|
|
AddLocalSym (Decl.Ident, Decl.Type, SC, SymData);
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
void DeclareLocals (void)
|
|
|
|
/* Declare local variables and types. */
|
|
|
|
{
|
2001-03-19 23:01:35 +00:00
|
|
|
/* Remember the current stack pointer */
|
|
|
|
int InitialStack = oursp;
|
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Loop until we don't find any more variables */
|
|
|
|
while (1) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Check variable declarations. We need to distinguish between a
|
2002-03-10 14:34:20 +00:00
|
|
|
* default int type and the end of variable declarations. So we
|
2000-06-22 11:28:39 +00:00
|
|
|
* will do the following: If there is no explicit storage class
|
|
|
|
* specifier *and* no explicit type given, it is assume that we
|
|
|
|
* have reached the end of declarations.
|
|
|
|
*/
|
|
|
|
DeclSpec Spec;
|
|
|
|
ParseDeclSpec (&Spec, SC_AUTO, T_INT);
|
|
|
|
if ((Spec.Flags & DS_DEF_STORAGE) != 0 && (Spec.Flags & DS_DEF_TYPE) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Accept type only declarations */
|
2001-05-22 09:32:24 +00:00
|
|
|
if (CurTok.Tok == TOK_SEMI) {
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Type declaration only */
|
|
|
|
CheckEmptyDecl (&Spec);
|
|
|
|
NextToken ();
|
|
|
|
continue;
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Parse a comma separated variable list */
|
|
|
|
while (1) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Parse one declaration */
|
|
|
|
ParseOneDecl (&Spec);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Check if there is more */
|
2001-05-22 09:32:24 +00:00
|
|
|
if (CurTok.Tok == TOK_COMMA) {
|
2000-06-22 11:28:39 +00:00
|
|
|
/* More to come */
|
|
|
|
NextToken ();
|
|
|
|
} else {
|
|
|
|
/* Done */
|
2000-05-28 13:40:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 11:28:39 +00:00
|
|
|
|
|
|
|
/* A semicolon must follow */
|
|
|
|
ConsumeSemi ();
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 11:28:39 +00:00
|
|
|
/* Be sure to allocate any reserved space for locals */
|
2002-06-12 12:12:04 +00:00
|
|
|
F_AllocLocalSpace (CurrentFunc);
|
2000-06-22 11:28:39 +00:00
|
|
|
|
2001-03-19 23:01:35 +00:00
|
|
|
/* In case we've allocated local variables in this block, emit a call to
|
|
|
|
* the stack checking routine if stack checks are enabled.
|
|
|
|
*/
|
|
|
|
if (CheckStack && InitialStack != oursp) {
|
2001-03-20 22:34:08 +00:00
|
|
|
g_cstackcheck ();
|
2001-03-19 23:01:35 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RestoreRegVars (int HaveResult)
|
|
|
|
/* Restore the register variables for the local function if there are any.
|
|
|
|
* The parameter tells us if there is a return value in ax, in that case,
|
|
|
|
* the accumulator must be saved across the restore.
|
|
|
|
*/
|
|
|
|
{
|
2000-06-08 21:11:48 +00:00
|
|
|
unsigned I, J;
|
|
|
|
int Bytes, Offs;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* If we don't have register variables in this function, bail out early */
|
|
|
|
if (RegSymCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the accumulator if needed */
|
2002-06-12 12:12:04 +00:00
|
|
|
if (!F_HasVoidReturn (CurrentFunc) && HaveResult) {
|
2000-05-28 13:40:48 +00:00
|
|
|
g_save (CF_CHAR | CF_FORCECHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk through all variables. If there are several variables in a row
|
|
|
|
* (that is, with increasing stack offset), restore them in one chunk.
|
|
|
|
*/
|
|
|
|
I = 0;
|
|
|
|
while (I < RegSymCount) {
|
|
|
|
|
|
|
|
/* Check for more than one variable */
|
|
|
|
const SymEntry* Sym = RegSyms[I];
|
|
|
|
Offs = Sym->V.Offs;
|
2002-03-10 20:44:58 +00:00
|
|
|
Bytes = CheckedSizeOf (Sym->Type);
|
2000-05-28 13:40:48 +00:00
|
|
|
J = I+1;
|
|
|
|
|
|
|
|
while (J < RegSymCount) {
|
|
|
|
|
|
|
|
/* Get the next symbol */
|
|
|
|
const SymEntry* NextSym = RegSyms [J];
|
|
|
|
|
|
|
|
/* Get the size */
|
2002-03-10 20:44:58 +00:00
|
|
|
int Size = CheckedSizeOf (NextSym->Type);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Adjacent variable? */
|
|
|
|
if (NextSym->V.Offs + Size != Offs) {
|
|
|
|
/* No */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjacent variable */
|
|
|
|
Bytes += Size;
|
|
|
|
Offs -= Size;
|
|
|
|
Sym = NextSym;
|
|
|
|
++J;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the memory range */
|
|
|
|
g_restore_regvars (Offs, Sym->V.Offs, Bytes);
|
|
|
|
|
|
|
|
/* Next round */
|
|
|
|
I = J;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the accumulator if needed */
|
2002-06-12 12:12:04 +00:00
|
|
|
if (!F_HasVoidReturn (CurrentFunc) && HaveResult) {
|
2000-05-28 13:40:48 +00:00
|
|
|
g_restore (CF_CHAR | CF_FORCECHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-12 18:31:40 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|