]> git.sur5r.net Git - cc65/blobdiff - src/cc65/pragma.c
Fixed two compiler warnings.
[cc65] / src / cc65 / pragma.c
index 37ae1bbb140991cbab8a7c3741c3024e533d8f2a..08d62ae20c7a2cb73efe11c6be563f4b567b7bfd 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2009, Ullrich von Bassewitz                                      */
+/* (C) 1998-2011, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -63,6 +63,7 @@
 /* Tokens for the #pragmas */
 typedef enum {
     PRAGMA_ILLEGAL = -1,
+    PRAGMA_ALIGN,
     PRAGMA_BSS_NAME,
     PRAGMA_BSSSEG,                                      /* obsolete */
     PRAGMA_CHARMAP,
@@ -73,6 +74,7 @@ typedef enum {
     PRAGMA_CODESIZE,
     PRAGMA_DATA_NAME,
     PRAGMA_DATASEG,                                     /* obsolete */
+    PRAGMA_LOCAL_STRINGS,
     PRAGMA_OPTIMIZE,
     PRAGMA_REGVARADDR,
     PRAGMA_REGISTER_VARS,
@@ -94,6 +96,7 @@ 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          },
@@ -104,6 +107,7 @@ static const struct Pragma {
     { "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      },
@@ -264,6 +268,8 @@ static PushPopResult ParsePushPop (StrBuf* B)
     StrBuf Ident      = AUTO_STRBUF_INITIALIZER;
     PushPopResult Res = PP_NONE;
 
+    /* Remember the current string index, so we can go back in case of errors */
+    unsigned Index = SB_GetIndex (B);
 
     /* Try to read an identifier */
     if (SB_GetSym (B, &Ident, 0)) {
@@ -280,14 +286,14 @@ static PushPopResult ParsePushPop (StrBuf* B)
 
             /* Skip the following comma */
             if (!GetComma (B)) {
+                /* Error already flagged by GetComma */
                 Res = PP_ERROR;
             }
 
         } else {
 
-            /* Unknown keyword */
-            Error ("Invalid pragma arguments");
-            Res = PP_ERROR;
+            /* Unknown keyword, roll back */
+            SB_SetIndex (B, Index);
         }
     }
 
@@ -488,7 +494,7 @@ static void WarnPragma (StrBuf* B)
     int    Push;
 
     /* A warning name must follow */
-    IntStack* S =GetWarning (B);
+    IntStack* S = GetWarning (B);
     if (S == 0) {
         return;
     }
@@ -652,14 +658,7 @@ static void ParsePragma (void)
 
     /* Create a string buffer from the string literal */
     StrBuf B = AUTO_STRBUF_INITIALIZER;
-    GetLiteralStrBuf (&B, CurTok.IVal);
-
-    /* Reset the string pointer, effectivly clearing the string from the
-     * string table. Since we're working with one token lookahead, this
-     * will fail if the next token is also a string token, but that's a
-     * syntax error anyway, because we expect a right paren.
-     */
-    ResetLiteralPoolOffs (CurTok.IVal);
+    SB_Append (&B, GetLiteralStrBuf (CurTok.SVal));
 
     /* Skip the string token */
     NextToken ();
@@ -698,6 +697,10 @@ static void ParsePragma (void)
     /* Switch for the different pragmas */
     switch (Pragma) {
 
+        case PRAGMA_ALIGN:
+            IntPragma (&B, &DataAlignment, 1, 4096);
+            break;
+
        case PRAGMA_BSSSEG:
             Warning ("#pragma bssseg is obsolete, please use #pragma bss-name instead");
             /* FALLTHROUGH */
@@ -734,6 +737,10 @@ static void ParsePragma (void)
            SegNamePragma (&B, SEG_DATA);
            break;
 
+        case PRAGMA_LOCAL_STRINGS:
+            FlagPragma (&B, &LocalStrings);
+            break;
+
         case PRAGMA_OPTIMIZE:
             FlagPragma (&B, &Optimize);
             break;