mirror of
https://github.com/cc65/cc65.git
synced 2025-04-06 20:37:16 +00:00
Made several options that can be changed by #pragmas stackable.
Added new #pragma regvars. git-svn-id: svn://svn.cc65.org/cc65/trunk@2902 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
7492c924e3
commit
d0ea9f34b6
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||
/* Römerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -291,16 +291,19 @@ void Compile (const char* FileName)
|
||||
DefineNumericMacro ("__STRICT_ANSI__", 1);
|
||||
}
|
||||
|
||||
/* Optimization macros */
|
||||
/* Optimization macros. Since no source code has been parsed for now, the
|
||||
* IS_Get functions access the values in effect now, regardless of any
|
||||
* changes using #pragma later.
|
||||
*/
|
||||
if (Optimize) {
|
||||
DefineNumericMacro ("__OPT__", 1);
|
||||
if (FavourSize == 0) {
|
||||
DefineNumericMacro ("__OPT_i__", 1);
|
||||
}
|
||||
if (EnableRegVars) {
|
||||
if (IS_Get (&EnableRegVars)) {
|
||||
DefineNumericMacro ("__OPT_r__", 1);
|
||||
}
|
||||
if (InlineStdFuncs) {
|
||||
if (IS_Get (&InlineStdFuncs)) {
|
||||
DefineNumericMacro ("__OPT_s__", 1);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -138,7 +138,7 @@ void TypeFree (type* T)
|
||||
int SignExtendChar (int C)
|
||||
/* Do correct sign extension of a character */
|
||||
{
|
||||
if (SignedChars && (C & 0x80) != 0) {
|
||||
if (IS_Get (&SignedChars) && (C & 0x80) != 0) {
|
||||
return C | ~0xFF;
|
||||
} else {
|
||||
return C & 0xFF;
|
||||
@ -150,7 +150,7 @@ int SignExtendChar (int C)
|
||||
type GetDefaultChar (void)
|
||||
/* Return the default char type (signed/unsigned) depending on the settings */
|
||||
{
|
||||
return SignedChars? T_SCHAR : T_UCHAR;
|
||||
return IS_Get (&SignedChars)? T_SCHAR : T_UCHAR;
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +211,7 @@ void DefineData (ExprDesc* Expr)
|
||||
/* Register variable. Taking the address is usually not
|
||||
* allowed.
|
||||
*/
|
||||
if (!AllowRegVarAddr) {
|
||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||
Error ("Cannot take the address of a register variable");
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
@ -252,7 +252,7 @@ static void LoadConstant (unsigned Flags, ExprDesc* Expr)
|
||||
/* Register variable. Taking the address is usually not
|
||||
* allowed.
|
||||
*/
|
||||
if (!AllowRegVarAddr) {
|
||||
if (IS_Get (&AllowRegVarAddr) == 0) {
|
||||
Error ("Cannot take the address of a register variable");
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
@ -681,7 +681,7 @@ static void FunctionCall (int k, ExprDesc* lval)
|
||||
}
|
||||
|
||||
/* Check for known standard functions and inline them if requested */
|
||||
} else if (InlineStdFuncs && IsStdFunc ((const char*) lval->Name)) {
|
||||
} else if (IS_Get (&InlineStdFuncs) && IsStdFunc ((const char*) lval->Name)) {
|
||||
|
||||
/* Inline this function */
|
||||
HandleStdFunc (Func, lval);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||
/* Römerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -229,7 +229,7 @@ int F_AllocRegVar (Function* F, const type* Type)
|
||||
*/
|
||||
{
|
||||
/* Allow register variables only on top level and if enabled */
|
||||
if (EnableRegVars && GetLexicalLevel () == LEX_LEVEL_FUNCTION) {
|
||||
if (IS_Get (&EnableRegVars) && GetLexicalLevel () == LEX_LEVEL_FUNCTION) {
|
||||
|
||||
/* Get the size of the variable */
|
||||
unsigned Size = CheckedSizeOf (Type);
|
||||
@ -403,7 +403,7 @@ void NewFunc (SymEntry* Func)
|
||||
g_enter (TypeOf (Func->Type), F_GetParamSize (CurrentFunc));
|
||||
|
||||
/* If stack checking code is requested, emit a call to the helper routine */
|
||||
if (CheckStack) {
|
||||
if (IS_Get (&CheckStack)) {
|
||||
g_stackcheck ();
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
@ -43,6 +43,9 @@
|
||||
|
||||
|
||||
|
||||
unsigned char AddSource = 0; /* Add source lines as comments */
|
||||
unsigned char DebugInfo = 0; /* Add debug info to the obj */
|
||||
unsigned char CreateDep = 0; /* Create a dependency file */
|
||||
unsigned char ANSI = 0; /* Strict ANSI flag */
|
||||
unsigned char WriteableStrings = 0; /* Literal strings are r/w */
|
||||
unsigned char NoWarn = 0; /* Suppress warnings */
|
||||
@ -50,17 +53,16 @@ unsigned char Optimize = 0; /* Optimize flag */
|
||||
unsigned long OptDisable = 0; /* Optimizer passes to disable */
|
||||
unsigned char FavourSize = 1; /* Favour size over speed */
|
||||
unsigned CodeSizeFactor = 100; /* Size factor for generated code */
|
||||
unsigned char InlineStdFuncs = 0; /* Inline some known functions */
|
||||
unsigned char EnableRegVars = 0; /* Enable register variables */
|
||||
unsigned RegisterSpace = 6; /* Space available for register vars */
|
||||
unsigned char AllowRegVarAddr = 0; /* Allow taking addresses of register vars */
|
||||
unsigned char RegVarsToCallStack= 0; /* Save reg variables on call stack */
|
||||
unsigned char StaticLocals = 0; /* Make local variables static */
|
||||
unsigned char SignedChars = 0; /* Make characters signed by default */
|
||||
unsigned char AddSource = 0; /* Add source lines as comments */
|
||||
unsigned char DebugInfo = 0; /* Add debug info to the obj */
|
||||
unsigned char CreateDep = 0; /* Create a dependency file */
|
||||
unsigned char CheckStack = 0; /* Generate stack overflow checks */
|
||||
|
||||
/* Stackable options */
|
||||
IntStack InlineStdFuncs = INTSTACK(0); /* Inline some known functions */
|
||||
IntStack EnableRegVars = INTSTACK(0); /* Enable register variables */
|
||||
IntStack AllowRegVarAddr = INTSTACK(0); /* Allow taking addresses of register vars */
|
||||
IntStack RegVarsToCallStack = INTSTACK(0); /* Save reg variables on call stack */
|
||||
IntStack StaticLocals = INTSTACK(0); /* Make local variables static */
|
||||
IntStack SignedChars = INTSTACK(0); /* Make characters signed by default */
|
||||
IntStack CheckStack = INTSTACK(0); /* Generate stack overflow checks */
|
||||
|
||||
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
@ -38,12 +38,20 @@
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "intstack.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
extern unsigned char AddSource; /* Add source lines as comments */
|
||||
extern unsigned char DebugInfo; /* Add debug info to the obj */
|
||||
extern unsigned char CreateDep; /* Create a dependency file */
|
||||
extern unsigned char ANSI; /* Strict ANSI flag */
|
||||
extern unsigned char WriteableStrings; /* Literal strings are r/w */
|
||||
extern unsigned char NoWarn; /* Suppress warnings */
|
||||
@ -51,17 +59,16 @@ extern unsigned char Optimize; /* Optimize flag */
|
||||
extern unsigned long OptDisable; /* Optimizer passes to disable */
|
||||
extern unsigned char FavourSize; /* Favour size over speed */
|
||||
extern unsigned CodeSizeFactor; /* Size factor for generated code */
|
||||
extern unsigned char InlineStdFuncs; /* Inline some known functions */
|
||||
extern unsigned char EnableRegVars; /* Enable register variables */
|
||||
extern unsigned RegisterSpace; /* Space available for register vars */
|
||||
extern unsigned char AllowRegVarAddr; /* Allow taking addresses of register vars */
|
||||
extern unsigned char RegVarsToCallStack; /* Save reg variables on call stack */
|
||||
extern unsigned char StaticLocals; /* Make local variables static */
|
||||
extern unsigned char SignedChars; /* Make characters signed by default */
|
||||
extern unsigned char AddSource; /* Add source lines as comments */
|
||||
extern unsigned char DebugInfo; /* Add debug info to the obj */
|
||||
extern unsigned char CreateDep; /* Create a dependency file */
|
||||
extern unsigned char CheckStack; /* Generate stack overflow checks */
|
||||
|
||||
/* Stackable options */
|
||||
extern IntStack InlineStdFuncs; /* Inline some known functions */
|
||||
extern IntStack EnableRegVars; /* Enable register variables */
|
||||
extern IntStack AllowRegVarAddr; /* Allow taking addresses of register vars */
|
||||
extern IntStack RegVarsToCallStack; /* Save reg variables on call stack */
|
||||
extern IntStack StaticLocals; /* Make local variables static */
|
||||
extern IntStack SignedChars; /* Make characters signed by default */
|
||||
extern IntStack CheckStack; /* Generate stack overflow checks */
|
||||
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||
/* Römerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -156,7 +156,7 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC)
|
||||
unsigned Size = SizeOf (Decl->Type);
|
||||
|
||||
/* Check if this is a variable on the stack or in static memory */
|
||||
if (StaticLocals == 0) {
|
||||
if (IS_Get (&StaticLocals) == 0) {
|
||||
|
||||
/* Check for an optional initialization */
|
||||
if (CurTok.Tok == TOK_ASSIGN) {
|
||||
@ -503,7 +503,7 @@ void DeclareLocals (void)
|
||||
/* 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) {
|
||||
if (IS_Get (&CheckStack) && InitialStack != oursp) {
|
||||
g_cstackcheck ();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2000-2003 Ullrich von Bassewitz */
|
||||
/* (C) 2000-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@ -346,10 +346,10 @@ static void OptBssName (const char* Opt attribute ((unused)), const char* Arg)
|
||||
|
||||
|
||||
static void OptCheckStack (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Handle the --check-stack option */
|
||||
{
|
||||
CheckStack = 1;
|
||||
IS_Set (&CheckStack, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -593,7 +593,7 @@ static void OptRegisterVars (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Handle the --register-vars option */
|
||||
{
|
||||
EnableRegVars = 1;
|
||||
IS_Set (&EnableRegVars, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -611,19 +611,19 @@ static void OptRodataName (const char* Opt attribute ((unused)), const char* Arg
|
||||
|
||||
|
||||
static void OptSignedChars (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Make default characters signed */
|
||||
{
|
||||
SignedChars = 1;
|
||||
IS_Set (&SignedChars, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptStaticLocals (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Place local variables in static storage */
|
||||
{
|
||||
StaticLocals = 1;
|
||||
IS_Set (&StaticLocals, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -798,10 +798,10 @@ int main (int argc, char* argv[])
|
||||
CodeSizeFactor = 200;
|
||||
break;
|
||||
case 'r':
|
||||
EnableRegVars = 1;
|
||||
IS_Set (&EnableRegVars, 1);
|
||||
break;
|
||||
case 's':
|
||||
InlineStdFuncs = 1;
|
||||
IS_Set (&InlineStdFuncs, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2002 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
||||
/* Römerstraße 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
@ -68,6 +68,7 @@ typedef enum {
|
||||
PR_CODESEG,
|
||||
PR_DATASEG,
|
||||
PR_REGVARADDR,
|
||||
PR_REGVARS,
|
||||
PR_RODATASEG,
|
||||
PR_SIGNEDCHARS,
|
||||
PR_STATICLOCALS,
|
||||
@ -86,6 +87,7 @@ static const struct Pragma {
|
||||
{ "codeseg", PR_CODESEG },
|
||||
{ "dataseg", PR_DATASEG },
|
||||
{ "regvaraddr", PR_REGVARADDR },
|
||||
{ "regvars", PR_REGVARS },
|
||||
{ "rodataseg", PR_RODATASEG },
|
||||
{ "signedchars", PR_SIGNEDCHARS },
|
||||
{ "staticlocals", PR_STATICLOCALS },
|
||||
@ -220,24 +222,64 @@ static void CharMapPragma (StrBuf* B)
|
||||
|
||||
|
||||
|
||||
static void FlagPragma (StrBuf* B, unsigned char* Flag)
|
||||
static void FlagPragma (StrBuf* B, IntStack* Stack)
|
||||
/* Handle a pragma that expects a boolean paramater */
|
||||
{
|
||||
ident Ident;
|
||||
long Val;
|
||||
int Push;
|
||||
|
||||
if (SB_GetSym (B, Ident)) {
|
||||
/* Try to read an identifier */
|
||||
int IsIdent = SB_GetSym (B, Ident);
|
||||
|
||||
/* Check if we have a first argument named "pop" */
|
||||
if (IsIdent && strcmp (Ident, "pop") == 0) {
|
||||
if (IS_GetCount (Stack) < 2) {
|
||||
Error ("Cannot pop, stack is empty");
|
||||
} else {
|
||||
(void) IS_Pop (Stack);
|
||||
}
|
||||
/* No other arguments allowed */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if we have a first argument named "push" */
|
||||
if (IsIdent && strcmp (Ident, "push") == 0) {
|
||||
Push = 1;
|
||||
SB_SkipWhite (B);
|
||||
if (SB_Get (B) != ',') {
|
||||
Error ("Comma expected");
|
||||
return;
|
||||
}
|
||||
SB_SkipWhite (B);
|
||||
IsIdent = SB_GetSym (B, Ident);
|
||||
} else {
|
||||
Push = 0;
|
||||
}
|
||||
|
||||
/* Boolean argument follows */
|
||||
if (IsIdent) {
|
||||
if (strcmp (Ident, "true") == 0 || strcmp (Ident, "on") == 0) {
|
||||
*Flag = 1;
|
||||
Val = 1;
|
||||
} else if (strcmp (Ident, "false") == 0 || strcmp (Ident, "off") == 0) {
|
||||
*Flag = 0;
|
||||
Val = 0;
|
||||
} else {
|
||||
Error ("Pragma argument must be one of `on', `off', `true' or `false'");
|
||||
}
|
||||
} else if (SB_GetNumber (B, &Val)) {
|
||||
*Flag = (Val != 0);
|
||||
} else {
|
||||
} else if (!SB_GetNumber (B, &Val)) {
|
||||
Error ("Invalid pragma argument");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set/push the new value */
|
||||
if (Push) {
|
||||
if (IS_IsFull (Stack)) {
|
||||
Error ("Cannot push: stack overflow");
|
||||
} else {
|
||||
IS_Push (Stack, Val);
|
||||
}
|
||||
} else {
|
||||
IS_Set (Stack, Val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +359,11 @@ static void ParsePragma (void)
|
||||
break;
|
||||
|
||||
case PR_REGVARADDR:
|
||||
FlagPragma (&B, &AllowRegVarAddr);
|
||||
FlagPragma (&B, &AllowRegVarAddr);
|
||||
break;
|
||||
|
||||
case PR_REGVARS:
|
||||
FlagPragma (&B, &EnableRegVars);
|
||||
break;
|
||||
|
||||
case PR_RODATASEG:
|
||||
@ -325,7 +371,7 @@ static void ParsePragma (void)
|
||||
break;
|
||||
|
||||
case PR_SIGNEDCHARS:
|
||||
FlagPragma (&B, &SignedChars);
|
||||
FlagPragma (&B, &SignedChars);
|
||||
break;
|
||||
|
||||
case PR_STATICLOCALS:
|
||||
|
Loading…
x
Reference in New Issue
Block a user