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:
@@ -46,6 +46,7 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "litpool.h"
|
#include "litpool.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "asmstmt.h"
|
#include "asmstmt.h"
|
||||||
|
|
||||||
|
|||||||
@@ -54,23 +54,13 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "segments.h"
|
#include "segments.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "textseg.h"
|
#include "textseg.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "codegen.h"
|
#include "codegen.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Data */
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Compiler relative stack pointer */
|
|
||||||
int StackPtr = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|||||||
@@ -85,9 +85,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Compiler relative stackpointer */
|
|
||||||
extern int StackPtr;
|
|
||||||
|
|
||||||
/* Forward */
|
/* Forward */
|
||||||
struct StrBuf;
|
struct StrBuf;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "macrotab.h"
|
#include "macrotab.h"
|
||||||
#include "preproc.h"
|
#include "preproc.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "stdfunc.h"
|
#include "stdfunc.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "typecmp.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. */
|
/* Call an expression function with checks. */
|
||||||
{
|
{
|
||||||
/* Remember the stack pointer */
|
/* Remember the stack pointer */
|
||||||
|
|||||||
@@ -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,
|
/* If the expression contains an address that was somehow evaluated,
|
||||||
* push this address on the stack. This is a helper function for all
|
* push this address on the stack. This is a helper function for all
|
||||||
* sorts of implicit or explicit assignment functions where the lvalue
|
* sorts of implicit or explicit assignment functions where the lvalue
|
||||||
|
|||||||
@@ -34,12 +34,14 @@
|
|||||||
|
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
|
#include "check.h"
|
||||||
#include "xsprintf.h"
|
#include "xsprintf.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
#include "datatype.h"
|
#include "datatype.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "symentry.h"
|
#include "symentry.h"
|
||||||
#include "exprdesc.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)
|
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type)
|
||||||
/* Make Expr an absolute const with the given value and type. */
|
/* Make Expr an absolute const with the given value and type. */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -229,6 +229,11 @@ const char* ED_GetLabelName (const ExprDesc* Expr, long Offs);
|
|||||||
* call to the function.
|
* 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);
|
ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type);
|
||||||
/* Make Expr an absolute const with the given value and type. */
|
/* Make Expr an absolute const with the given value and type. */
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#include "locals.h"
|
#include "locals.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "segments.h"
|
#include "segments.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "stmt.h"
|
#include "stmt.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "locals.h"
|
#include "locals.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "typeconv.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.
|
/* If the value is not const, load it into the primary.
|
||||||
* Otherwise pass the information to the code generator.
|
* Otherwise pass the information to the code generator.
|
||||||
*/
|
*/
|
||||||
if (ED_IsConstAbsInt (&Expr)) {
|
if (ED_IsConstAbsInt (&Expr)) {
|
||||||
Flags |= CF_CONST;
|
Flags |= CF_CONST;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ OBJS = anonname.o \
|
|||||||
scanner.o \
|
scanner.o \
|
||||||
scanstrbuf.o \
|
scanstrbuf.o \
|
||||||
segments.o \
|
segments.o \
|
||||||
|
stackptr.o \
|
||||||
stdfunc.o \
|
stdfunc.o \
|
||||||
stdnames.o \
|
stdnames.o \
|
||||||
stmt.o \
|
stmt.o \
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ OBJS = anonname.obj \
|
|||||||
scanner.obj \
|
scanner.obj \
|
||||||
scanstrbuf.obj \
|
scanstrbuf.obj \
|
||||||
segments.obj \
|
segments.obj \
|
||||||
|
stackptr.obj \
|
||||||
stdfunc.obj \
|
stdfunc.obj \
|
||||||
stdnames.obj \
|
stdnames.obj \
|
||||||
stmt.obj \
|
stmt.obj \
|
||||||
|
|||||||
57
src/cc65/stackptr.c
Normal file
57
src/cc65/stackptr.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* stackptr.c */
|
||||||
|
/* */
|
||||||
|
/* Manage the parameter stack pointer */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2004 Ullrich von Bassewitz */
|
||||||
|
/* R<>merstra<72>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
63
src/cc65/stackptr.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* stackptr.h */
|
||||||
|
/* */
|
||||||
|
/* Manage the parameter stack pointer */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2004 Ullrich von Bassewitz */
|
||||||
|
/* R<>merstra<72>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
@@ -55,6 +55,7 @@
|
|||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include "pragma.h"
|
#include "pragma.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "swstmt.h"
|
#include "swstmt.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "stmt.h"
|
#include "stmt.h"
|
||||||
@@ -516,7 +517,7 @@ int Statement (int* PendingToken)
|
|||||||
* NULL, the function will skip the token.
|
* NULL, the function will skip the token.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ExprDesc lval;
|
ExprDesc Expr;
|
||||||
int GotBreak;
|
int GotBreak;
|
||||||
|
|
||||||
/* Assume no pending token */
|
/* Assume no pending token */
|
||||||
@@ -590,7 +591,13 @@ int Statement (int* PendingToken)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Actual statement */
|
/* 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);
|
CheckSemi (PendingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstra<EFBFBD>e 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "stmt.h"
|
#include "stmt.h"
|
||||||
#include "swstmt.h"
|
#include "swstmt.h"
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "funcdesc.h"
|
#include "funcdesc.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "stackptr.h"
|
||||||
#include "symentry.h"
|
#include "symentry.h"
|
||||||
#include "typecmp.h"
|
#include "typecmp.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
@@ -672,7 +673,7 @@ SymEntry* AddLocalSym (const char* Name, const type* Type, unsigned Flags, int O
|
|||||||
Entry->V.Offs = Offs;
|
Entry->V.Offs = Offs;
|
||||||
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
|
} else if ((Flags & SC_REGISTER) == SC_REGISTER) {
|
||||||
Entry->V.R.RegOffs = Offs;
|
Entry->V.R.RegOffs = Offs;
|
||||||
Entry->V.R.SaveOffs = StackPtr; /* ### Cleaner! */
|
Entry->V.R.SaveOffs = StackPtr;
|
||||||
} else if ((Flags & SC_STATIC) == SC_STATIC) {
|
} else if ((Flags & SC_STATIC) == SC_STATIC) {
|
||||||
/* Generate the assembler name from the label number */
|
/* Generate the assembler name from the label number */
|
||||||
Entry->V.Label = Offs;
|
Entry->V.Label = Offs;
|
||||||
|
|||||||
Reference in New Issue
Block a user