1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-09 06:29:38 +00:00

Move the compiler stack pointer into its own module.

Improved the inlining of standard C functions. Added more standard functions
to inline.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3095 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2004-06-05 11:35:53 +00:00
parent a0c1b9fe38
commit 104ae3a54f
17 changed files with 985 additions and 100 deletions

View File

@ -46,6 +46,7 @@
#include "function.h"
#include "litpool.h"
#include "scanner.h"
#include "stackptr.h"
#include "symtab.h"
#include "asmstmt.h"

View File

@ -54,23 +54,13 @@
#include "error.h"
#include "global.h"
#include "segments.h"
#include "stackptr.h"
#include "textseg.h"
#include "util.h"
#include "codegen.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Compiler relative stack pointer */
int StackPtr = 0;
/*****************************************************************************/
/* Helpers */
/*****************************************************************************/

View File

@ -85,9 +85,6 @@
/* Compiler relative stackpointer */
extern int StackPtr;
/* Forward */
struct StrBuf;

View File

@ -28,6 +28,7 @@
#include "macrotab.h"
#include "preproc.h"
#include "scanner.h"
#include "stackptr.h"
#include "stdfunc.h"
#include "symtab.h"
#include "typecmp.h"
@ -97,7 +98,7 @@ static unsigned GlobalModeFlags (unsigned Flags)
static void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr)
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr)
/* Call an expression function with checks. */
{
/* Remember the stack pointer */

View File

@ -23,7 +23,10 @@
void PushAddr (const ExprDesc* Expr);
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc *Expr);
/* Call an expression function with checks. */
void PushAddr (const ExprDesc* Expr);
/* If the expression contains an address that was somehow evaluated,
* push this address on the stack. This is a helper function for all
* sorts of implicit or explicit assignment functions where the lvalue

View File

@ -34,12 +34,14 @@
/* common */
#include "check.h"
#include "xsprintf.h"
/* cc65 */
#include "asmlabel.h"
#include "datatype.h"
#include "error.h"
#include "stackptr.h"
#include "symentry.h"
#include "exprdesc.h"
@ -123,6 +125,19 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
int ED_GetStackOffs (const ExprDesc* Expr, int Offs)
/* Get the stack offset of an address on the stack in Expr taking into account
* an additional offset in Offs.
*/
{
PRECONDITION (ED_IsLocStack (Expr));
Offs += ((int) Expr->Val) - StackPtr;
CHECK (Offs >= 0); /* Cannot handle negative stack offsets */
return Offs;
}
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type)
/* Make Expr an absolute const with the given value and type. */
{

View File

@ -229,6 +229,11 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs);
* call to the function.
*/
int ED_GetStackOffs (const ExprDesc* Expr, int Offs);
/* Get the stack offset of an address on the stack in Expr taking into account
* an additional offset in Offs.
*/
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type);
/* Make Expr an absolute const with the given value and type. */

View File

@ -48,6 +48,7 @@
#include "locals.h"
#include "scanner.h"
#include "segments.h"
#include "stackptr.h"
#include "stmt.h"
#include "symtab.h"
#include "function.h"

View File

@ -47,6 +47,7 @@
#include "function.h"
#include "global.h"
#include "locals.h"
#include "stackptr.h"
#include "symtab.h"
#include "typeconv.h"
@ -214,7 +215,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
/* If the value is not const, load it into the primary.
* Otherwise pass the information to the code generator.
*/
*/
if (ED_IsConstAbsInt (&Expr)) {
Flags |= CF_CONST;
} else {

View File

@ -78,6 +78,7 @@ OBJS = anonname.o \
scanner.o \
scanstrbuf.o \
segments.o \
stackptr.o \
stdfunc.o \
stdnames.o \
stmt.o \

View File

@ -112,6 +112,7 @@ OBJS = anonname.obj \
scanner.obj \
scanstrbuf.obj \
segments.obj \
stackptr.obj \
stdfunc.obj \
stdnames.obj \
stmt.obj \

57
src/cc65/stackptr.c Normal file
View File

@ -0,0 +1,57 @@
/*****************************************************************************/
/* */
/* stackptr.c */
/* */
/* Manage the parameter stack pointer */
/* */
/* */
/* */
/* (C) 2004 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
/* cc65 */
#include "stackptr.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Compiler relative stackpointer */
int StackPtr = 0;
/*****************************************************************************/
/* Code */
/*****************************************************************************/

63
src/cc65/stackptr.h Normal file
View File

@ -0,0 +1,63 @@
/*****************************************************************************/
/* */
/* stackptr.h */
/* */
/* Manage the parameter stack pointer */
/* */
/* */
/* */
/* (C) 2004 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef STACKPTR_H
#define STACKPTR_H
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Compiler relative stackpointer */
extern int StackPtr;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
/* End of stackptr.h */
#endif

File diff suppressed because it is too large Load Diff

View File

@ -55,6 +55,7 @@
#include "loop.h"
#include "pragma.h"
#include "scanner.h"
#include "stackptr.h"
#include "swstmt.h"
#include "symtab.h"
#include "stmt.h"
@ -516,7 +517,7 @@ int Statement (int* PendingToken)
* NULL, the function will skip the token.
*/
{
ExprDesc lval;
ExprDesc Expr;
int GotBreak;
/* Assume no pending token */
@ -590,7 +591,13 @@ int Statement (int* PendingToken)
default:
/* Actual statement */
Expression0 (&lval);
ExprWithCheck (hie0, &Expr);
/* Load the result only if it is an lvalue and the type is
* marked as volatile. Otherwise the load is useless.
*/
if (ED_IsLVal (&Expr) && IsQualVolatile (Expr.Type)) {
ExprLoad (CF_NONE, &Expr);
}
CheckSemi (PendingToken);
}
}

View File

@ -7,8 +7,8 @@
/* */
/* */
/* (C) 1998-2004 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
@ -50,6 +50,7 @@
#include "global.h"
#include "loop.h"
#include "scanner.h"
#include "stackptr.h"
#include "stmt.h"
#include "swstmt.h"

View File

@ -53,6 +53,7 @@
#include "error.h"
#include "funcdesc.h"
#include "global.h"
#include "stackptr.h"
#include "symentry.h"
#include "typecmp.h"
#include "symtab.h"
@ -672,7 +673,7 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O
Entry->V.Offs = Offs;
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
Entry->V.R.RegOffs = Offs;
Entry->V.R.SaveOffs = StackPtr; /* ### Cleaner! */
Entry->V.R.SaveOffs = StackPtr;
} else if ((Flags & SC_STATIC) == SC_STATIC) {
/* Generate the assembler name from the label number */
Entry->V.Label = Offs;