]> git.sur5r.net Git - cc65/commitdiff
Made several options that can be changed by #pragmas stackable.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Mar 2004 21:53:35 +0000 (21:53 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 7 Mar 2004 21:53:35 +0000 (21:53 +0000)
Added new #pragma regvars.

git-svn-id: svn://svn.cc65.org/cc65/trunk@2902 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/compile.c
src/cc65/datatype.c
src/cc65/expr.c
src/cc65/function.c
src/cc65/global.c
src/cc65/global.h
src/cc65/locals.c
src/cc65/main.c
src/cc65/pragma.c

index ca3175baa68846e62ed28e8233c442b479b2f808..7edd3ae1786df2d5ca7212a4329af3af498adfab 100644 (file)
@@ -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);
        }
     }
index e257d46aeecf90fd343758766eb73a7b9d5a3f3b..1c17c27960007cdb3ad02da11436b774d5b96b78 100644 (file)
@@ -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;
 }
 
 
index 845b4669687a4a90071480033df94284a83dec03..47abb50c4dafe0622b95290297e2a77a95ccd7a5 100644 (file)
@@ -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);
index c30e682a63eb17dd51ce5ade0a459844e5ed207b..6de9ba7b15f9a276bcf96b9fb9f53beb050ac30a 100644 (file)
@@ -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 ();
     }
 
index 51cddb51179f7687995a88a67fda5f88158735c4..abea777e8618b5943c05a52daa7fa8d9e24ef3f8 100644 (file)
@@ -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 */
 
 
 
index ff8f3bc914449830dced4364b4545b227a874e68..cc74c8df36423a514be06b8afd1972b630411b25 100644 (file)
@@ -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                                                 */
 /*                                                                           */
 /*                                                                           */
 
 
 
+/* 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 */
 
 
 
index 7b7af04792318f5eb99547dac35b4dfa0884e880..aa690daad9ee7e8a91cc38e67497ae88424b82e1 100644 (file)
@@ -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 ();
     }
 }
index 77e79cfc20db7c7eafa0530a320700b91806d09d..80ceaf7eb1c4ed29284158ebf951606e2a891663 100644 (file)
@@ -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;
                        }
                    }
index bf93bcd5b948633bf6ab54e28601abd749bd6fb3..ff0532b656c2a20c140361c30499f8710594cda2 100644 (file)
@@ -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: