/* */
/* */
/* */
-/* (C) 2000-2003 Ullrich von Bassewitz */
+/* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
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);
}
}
/* */
/* */
/* */
-/* (C) 1998-2003 Ullrich von Bassewitz */
+/* (C) 1998-2004 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
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;
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;
}
/* 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 */
/* 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 */
}
/* 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);
/* */
/* */
/* */
-/* (C) 2000-2003 Ullrich von Bassewitz */
+/* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
*/
{
/* 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);
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 ();
}
/* */
/* */
/* */
-/* (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 */
/* */
/* */
+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 */
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 */
/* */
/* */
/* */
-/* (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 */
/* */
/* */
+/* 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 */
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 */
/* */
/* */
/* */
-/* (C) 2000-2003 Ullrich von Bassewitz */
+/* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
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) {
/* 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 ();
}
}
/* */
/* */
/* */
-/* (C) 2000-2003 Ullrich von Bassewitz */
+/* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
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);
}
const char* Arg attribute ((unused)))
/* Handle the --register-vars option */
{
- EnableRegVars = 1;
+ IS_Set (&EnableRegVars, 1);
}
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);
}
CodeSizeFactor = 200;
break;
case 'r':
- EnableRegVars = 1;
+ IS_Set (&EnableRegVars, 1);
break;
case 's':
- InlineStdFuncs = 1;
+ IS_Set (&InlineStdFuncs, 1);
break;
}
}
/* */
/* */
/* */
-/* (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 */
/* */
/* */
PR_CODESEG,
PR_DATASEG,
PR_REGVARADDR,
+ PR_REGVARS,
PR_RODATASEG,
PR_SIGNEDCHARS,
PR_STATICLOCALS,
{ "codeseg", PR_CODESEG },
{ "dataseg", PR_DATASEG },
{ "regvaraddr", PR_REGVARADDR },
+ { "regvars", PR_REGVARS },
{ "rodataseg", PR_RODATASEG },
{ "signedchars", PR_SIGNEDCHARS },
{ "staticlocals", PR_STATICLOCALS },
-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);
}
}
break;
case PR_REGVARADDR:
- FlagPragma (&B, &AllowRegVarAddr);
+ FlagPragma (&B, &AllowRegVarAddr);
+ break;
+
+ case PR_REGVARS:
+ FlagPragma (&B, &EnableRegVars);
break;
case PR_RODATASEG:
break;
case PR_SIGNEDCHARS:
- FlagPragma (&B, &SignedChars);
+ FlagPragma (&B, &SignedChars);
break;
case PR_STATICLOCALS: