mirror of
https://github.com/cc65/cc65.git
synced 2024-12-22 12:30:41 +00:00
Do not save any register variables when entering main(). Do not restore the C
stack when leaving main(). Both are unnecessary and just bloat the executable.
This commit is contained in:
parent
b688cfa0c0
commit
b5cc68d6e2
@ -507,9 +507,13 @@ void g_enter (unsigned flags, unsigned argsize)
|
||||
|
||||
|
||||
|
||||
void g_leave (void)
|
||||
void g_leave (int IsMainFunc)
|
||||
/* Function epilogue */
|
||||
{
|
||||
/* In the main function nothing has to be dropped because the program
|
||||
** is terminated anyway.
|
||||
*/
|
||||
if (!IsMainFunc) {
|
||||
/* How many bytes of locals do we have to drop? */
|
||||
unsigned ToDrop = (unsigned) -StackPtr;
|
||||
|
||||
@ -536,6 +540,7 @@ void g_leave (void)
|
||||
AddCodeLine ("jsr leave");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the final rts */
|
||||
AddCodeLine ("rts");
|
||||
|
@ -247,7 +247,7 @@ void g_scale (unsigned flags, long val);
|
||||
void g_enter (unsigned flags, unsigned argsize);
|
||||
/* Function prologue */
|
||||
|
||||
void g_leave (void);
|
||||
void g_leave (int IsMainFunc);
|
||||
/* Function epilogue */
|
||||
|
||||
|
||||
|
@ -646,11 +646,13 @@ void NewFunc (SymEntry* Func, FuncDesc* D)
|
||||
/* Output the function exit code label */
|
||||
g_defcodelabel (F_GetRetLab (CurrentFunc));
|
||||
|
||||
/* Restore the register variables */
|
||||
/* Restore the register variables (not necessary for main function) */
|
||||
if (!F_IsMainFunc (CurrentFunc)) {
|
||||
F_RestoreRegVars (CurrentFunc);
|
||||
}
|
||||
|
||||
/* Generate the exit code */
|
||||
g_leave ();
|
||||
g_leave (F_IsMainFunc (CurrentFunc));
|
||||
|
||||
/* Emit references to imports/exports */
|
||||
EmitExternals ();
|
||||
|
@ -111,22 +111,31 @@ static void ParseRegisterDecl (Declarator* Decl, int Reg)
|
||||
/* Get the size of the variable */
|
||||
unsigned Size = SizeOf (Decl->Type);
|
||||
|
||||
/* Save the current contents of the register variable on stack */
|
||||
F_AllocLocalSpace (CurrentFunc);
|
||||
g_save_regvars (Reg, Size);
|
||||
|
||||
/* Add the symbol to the symbol table. We do that now, because for register
|
||||
** variables the current stack pointer is implicitly used as location for
|
||||
** the save area.
|
||||
*/
|
||||
Sym = AddLocalSym (Decl->Ident, Decl->Type, Decl->StorageClass, Reg);
|
||||
|
||||
/* Check for an optional initialization */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
|
||||
/* Skip the '=' */
|
||||
NextToken ();
|
||||
|
||||
/* If the register variable is initialized, the initialization code may
|
||||
** access other already declared variables. This means that we have to
|
||||
** allocate them now.
|
||||
*/
|
||||
F_AllocLocalSpace (CurrentFunc);
|
||||
|
||||
/* Save the current contents of the register variable on stack. This is
|
||||
** not necessary for the main function.
|
||||
*/
|
||||
if (!F_IsMainFunc (CurrentFunc)) {
|
||||
g_save_regvars (Reg, Size);
|
||||
}
|
||||
|
||||
/* Add the symbol to the symbol table. We do that now, because for
|
||||
** register variables the current stack pointer is implicitly used
|
||||
** as location for the save area (unused in case of main()).
|
||||
*/
|
||||
Sym = AddLocalSym (Decl->Ident, Decl->Type, Decl->StorageClass, Reg);
|
||||
|
||||
/* Special handling for compound types */
|
||||
if (IsCompound) {
|
||||
|
||||
@ -173,6 +182,21 @@ static void ParseRegisterDecl (Declarator* Decl, int Reg)
|
||||
|
||||
/* Mark the variable as referenced */
|
||||
Sym->Flags |= SC_REF;
|
||||
} else {
|
||||
|
||||
/* Save the current contents of the register variable on stack. This is
|
||||
** not necessary for the main function.
|
||||
*/
|
||||
if (!F_IsMainFunc (CurrentFunc)) {
|
||||
F_AllocLocalSpace (CurrentFunc);
|
||||
g_save_regvars (Reg, Size);
|
||||
}
|
||||
|
||||
/* Add the symbol to the symbol table. We do that now, because for
|
||||
** register variables the current stack pointer is implicitly used
|
||||
** as location for the save area (unused in case of main()).
|
||||
*/
|
||||
Sym = AddLocalSym (Decl->Ident, Decl->Type, Decl->StorageClass, Reg);
|
||||
}
|
||||
|
||||
/* Cannot allocate a variable of unknown size */
|
||||
|
Loading…
Reference in New Issue
Block a user