]> git.sur5r.net Git - cc65/blobdiff - src/cc65/pragma.c
So far the built-in inlining of several known standard function was always (!) enable...
[cc65] / src / cc65 / pragma.c
index 01e4ea3cf0d85a02b77d713e647fed2fb1d6708b..707546e1dd98e91e1c1214c5240e20c280107a06 100644 (file)
@@ -64,6 +64,7 @@
 typedef enum {
     PRAGMA_ILLEGAL = -1,
     PRAGMA_ALIGN,
+    PRAGMA_ALLOW_EAGER_INLINE,
     PRAGMA_BSS_NAME,
     PRAGMA_BSSSEG,                                      /* obsolete */
     PRAGMA_CHARMAP,
@@ -74,6 +75,7 @@ typedef enum {
     PRAGMA_CODESIZE,
     PRAGMA_DATA_NAME,
     PRAGMA_DATASEG,                                     /* obsolete */
+    PRAGMA_INLINE_STDFUNCS,
     PRAGMA_LOCAL_STRINGS,
     PRAGMA_OPTIMIZE,
     PRAGMA_REGVARADDR,
@@ -96,31 +98,33 @@ static const struct Pragma {
     const char* Key;            /* Keyword */
     pragma_t    Tok;            /* Token */
 } Pragmas[PRAGMA_COUNT] = {
-    { "align",                  PRAGMA_ALIGN            },
-    { "bss-name",               PRAGMA_BSS_NAME         },
-    { "bssseg",                 PRAGMA_BSSSEG           },      /* obsolete */
-    { "charmap",                PRAGMA_CHARMAP          },
-    { "check-stack",            PRAGMA_CHECK_STACK      },
-    { "checkstack",             PRAGMA_CHECKSTACK       },      /* obsolete */
-    { "code-name",              PRAGMA_CODE_NAME        },
-    { "codeseg",                PRAGMA_CODESEG          },      /* obsolete */
-    { "codesize",               PRAGMA_CODESIZE         },
-    { "data-name",              PRAGMA_DATA_NAME        },
-    { "dataseg",                PRAGMA_DATASEG          },      /* obsolete */
-    { "local-strings",          PRAGMA_LOCAL_STRINGS    },
-    { "optimize",               PRAGMA_OPTIMIZE         },
-    { "register-vars",          PRAGMA_REGISTER_VARS    },
-    { "regvaraddr",             PRAGMA_REGVARADDR       },
-    { "regvars",                PRAGMA_REGVARS          },      /* obsolete */
-    { "rodata-name",            PRAGMA_RODATA_NAME      },
-    { "rodataseg",              PRAGMA_RODATASEG        },      /* obsolete */
-    { "signed-chars",           PRAGMA_SIGNED_CHARS     },
-    { "signedchars",            PRAGMA_SIGNEDCHARS      },      /* obsolete */
-    { "static-locals",          PRAGMA_STATIC_LOCALS    },
-    { "staticlocals",           PRAGMA_STATICLOCALS     },      /* obsolete */
-    { "warn",                   PRAGMA_WARN             },
-    { "writable-strings",       PRAGMA_WRITABLE_STRINGS },
-    { "zpsym",                  PRAGMA_ZPSYM            },
+    { "align",                  PRAGMA_ALIGN              },
+    { "allow-eager-inline",     PRAGMA_ALLOW_EAGER_INLINE },
+    { "bss-name",               PRAGMA_BSS_NAME           },
+    { "bssseg",                 PRAGMA_BSSSEG             },      /* obsolete */
+    { "charmap",                PRAGMA_CHARMAP            },
+    { "check-stack",            PRAGMA_CHECK_STACK        },
+    { "checkstack",             PRAGMA_CHECKSTACK         },      /* obsolete */
+    { "code-name",              PRAGMA_CODE_NAME          },
+    { "codeseg",                PRAGMA_CODESEG            },      /* obsolete */
+    { "codesize",               PRAGMA_CODESIZE           },
+    { "data-name",              PRAGMA_DATA_NAME          },
+    { "dataseg",                PRAGMA_DATASEG            },      /* obsolete */
+    { "inline-stdfuncs",        PRAGMA_INLINE_STDFUNCS    },
+    { "local-strings",          PRAGMA_LOCAL_STRINGS      },
+    { "optimize",               PRAGMA_OPTIMIZE           },
+    { "register-vars",          PRAGMA_REGISTER_VARS      },
+    { "regvaraddr",             PRAGMA_REGVARADDR         },
+    { "regvars",                PRAGMA_REGVARS            },      /* obsolete */
+    { "rodata-name",            PRAGMA_RODATA_NAME        },
+    { "rodataseg",              PRAGMA_RODATASEG          },      /* obsolete */
+    { "signed-chars",           PRAGMA_SIGNED_CHARS       },
+    { "signedchars",            PRAGMA_SIGNEDCHARS        },      /* obsolete */
+    { "static-locals",          PRAGMA_STATIC_LOCALS      },
+    { "staticlocals",           PRAGMA_STATICLOCALS       },      /* obsolete */
+    { "warn",                   PRAGMA_WARN               },
+    { "writable-strings",       PRAGMA_WRITABLE_STRINGS   },
+    { "zpsym",                  PRAGMA_ZPSYM              },
 };
 
 /* Result of ParsePushPop */
@@ -141,8 +145,8 @@ typedef enum {
 
 static void PragmaErrorSkip (void)
 /* Called in case of an error, skips tokens until the closing paren or a
- * semicolon is reached.
- */
+** semicolon is reached.
+*/
 {
     static const token_t TokenList[] = { TOK_RPAREN, TOK_SEMI };
     SkipTokens (TokenList, sizeof(TokenList) / sizeof(TokenList[0]));
@@ -160,8 +164,8 @@ static int CmpKey (const void* Key, const void* Elem)
 
 static pragma_t FindPragma (const StrBuf* Key)
 /* Find a pragma and return the token. Return PRAGMA_ILLEGAL if the keyword is
- * not a valid pragma.
- */
+** not a valid pragma.
+*/
 {
     struct Pragma* P;
     P = bsearch (SB_GetConstBuf (Key), Pragmas, PRAGMA_COUNT, sizeof (Pragmas[0]), CmpKey);
@@ -172,8 +176,8 @@ static pragma_t FindPragma (const StrBuf* Key)
 
 static int GetComma (StrBuf* B)
 /* Expects and skips a comma in B. Prints an error and returns zero if no
- * comma is found. Return a value <> 0 otherwise.
- */
+** comma is found. Return a value <> 0 otherwise.
+*/
 {
     SB_SkipWhite (B);
     if (SB_Get (B) != ',') {
@@ -188,8 +192,8 @@ static int GetComma (StrBuf* B)
 
 static int GetString (StrBuf* B, StrBuf* S)
 /* Expects and skips a string in B. Prints an error and returns zero if no
- * string is found. Returns a value <> 0 otherwise.
- */
+** string is found. Returns a value <> 0 otherwise.
+*/
 {
     if (!SB_GetString (B, S)) {
         Error ("String literal expected");
@@ -202,8 +206,8 @@ static int GetString (StrBuf* B, StrBuf* S)
 
 static int GetNumber (StrBuf* B, long* Val)
 /* Expects and skips a number in B. Prints an eror and returns zero if no
- * number is found. Returns a value <> 0 otherwise.
- */
+** number is found. Returns a value <> 0 otherwise.
+*/
 {
     if (!SB_GetNumber (B, Val)) {
         Error ("Constant integer expected");
@@ -216,9 +220,9 @@ static int GetNumber (StrBuf* B, long* Val)
 
 static IntStack* GetWarning (StrBuf* B)
 /* Get a warning name from the string buffer. Returns a pointer to the intstack
- * that holds the state of the warning, and NULL in case of errors. The
- * function will output error messages in case of problems.
- */
+** that holds the state of the warning, and NULL in case of errors. The
+** function will output error messages in case of problems.
+*/
 {
     IntStack* S = 0;
     StrBuf W = AUTO_STRBUF_INITIALIZER;
@@ -262,8 +266,8 @@ static int HasStr (StrBuf* B, const char* E)
 
 static PushPopResult ParsePushPop (StrBuf* B)
 /* Check for and parse the "push" and "pop" keywords. In case of "push", a
- * following comma is expected and skipped.
- */
+** following comma is expected and skipped.
+*/
 {
     StrBuf Ident      = AUTO_STRBUF_INITIALIZER;
     PushPopResult Res = PP_NONE;
@@ -330,8 +334,8 @@ static void PushInt (IntStack* S, long Val)
 
 static int BoolKeyword (StrBuf* Ident)
 /* Check if the identifier in Ident is a keyword for a boolean value. Currently
- * accepted are true/false/on/off.
- */
+** accepted are true/false/on/off.
+*/
 {
     if (SB_CompareStr (Ident, "true") == 0) {
         return 1;
@@ -452,13 +456,8 @@ static void CharMapPragma (StrBuf* B)
     if (!GetNumber (B, &Index)) {
         return;
     }
-    if (Index < 1 || Index > 255) {
-        if (Index == 0) {
-            /* For groepaz */
-            Error ("Remapping 0 is not allowed");
-        } else {
-            Error ("Character index out of range");
-        }
+    if (Index < 0 || Index > 255) {
+        Error ("Character index out of range");
         return;
     }
 
@@ -471,16 +470,23 @@ static void CharMapPragma (StrBuf* B)
     if (!GetNumber (B, &C)) {
         return;
     }
-    if (C < 1 || C > 255) {
-        if (C == 0) {
-            /* For groepaz */
-            Error ("Remapping 0 is not allowed");
-        } else {
-            Error ("Character code out of range");
-        }
+    if (C < 0 || C > 255) {
+        Error ("Character code out of range");
         return;
     }
 
+    /* Warn about remapping character code 0x00
+    ** (except when remapping it back to itself).
+    */
+    if (Index + C != 0 && IS_Get (&WarnRemapZero)) {
+        if (Index == 0) {
+            Warning ("Remapping from 0 is dangerous with string functions");
+        }
+        else if (C == 0) {
+            Warning ("Remapping to 0 can make string functions stop unexpectedly");
+        }
+    }
+
     /* Remap the character */
     TgtTranslateSet ((unsigned) Index, (unsigned char) C);
 }
@@ -676,8 +682,8 @@ static void ParsePragma (void)
     /* Do we know this pragma? */
     if (Pragma == PRAGMA_ILLEGAL) {
         /* According to the ANSI standard, we're not allowed to generate errors
-         * for unknown pragmas, but warn about them if enabled (the default).
-         */
+        ** for unknown pragmas, but warn about them if enabled (the default).
+        */
         if (IS_Get (&WarnUnknownPragma)) {
             Warning ("Unknown pragma `%s'", SB_GetConstBuf (&Ident));
         }
@@ -701,6 +707,10 @@ static void ParsePragma (void)
             IntPragma (&B, &DataAlignment, 1, 4096);
             break;
 
+        case PRAGMA_ALLOW_EAGER_INLINE:
+            FlagPragma (&B, &EagerlyInlineFuncs);
+            break;
+
         case PRAGMA_BSSSEG:
             Warning ("#pragma bssseg is obsolete, please use #pragma bss-name instead");
             /* FALLTHROUGH */
@@ -737,6 +747,10 @@ static void ParsePragma (void)
             SegNamePragma (&B, SEG_DATA);
             break;
 
+        case PRAGMA_INLINE_STDFUNCS:
+            FlagPragma (&B, &InlineStdFuncs);
+            break;
+
         case PRAGMA_LOCAL_STRINGS:
             FlagPragma (&B, &LocalStrings);
             break;
@@ -838,8 +852,8 @@ void DoPragma (void)
         Error ("String literal expected");
 
         /* Try some smart error recovery: Skip tokens until we reach the
-         * enclosing paren, or a semicolon.
-         */
+        ** enclosing paren, or a semicolon.
+        */
         PragmaErrorSkip ();
 
     } else {