]> git.sur5r.net Git - cc65/commitdiff
String literals can be handled as static data in most cases
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 31 May 2004 19:51:13 +0000 (19:51 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 31 May 2004 19:51:13 +0000 (19:51 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3062 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/expr.c

index d0ff65a3a2ce0b68573efce0e2ff5a2d3b8b94e1..51aee06627127b741cbfbdd37eb1d0b32f214f66 100644 (file)
@@ -203,7 +203,8 @@ void DefineData (ExprDesc* Expr)
             break;
 
         case E_LOC_STATIC:
-            /* Static variable */
+        case E_LOC_LITERAL:
+            /* Static variable or literal in the literal pool */
             g_defdata (CF_STATIC, Expr->Name, Expr->Val);
             break;
 
@@ -217,11 +218,6 @@ void DefineData (ExprDesc* Expr)
             g_defdata (CF_REGVAR, Expr->Name, Expr->Val);
             break;
 
-        case E_LOC_LITERAL:
-            /* Literal in the literal pool */
-            g_defdata (CF_STATIC, LiteralPoolLabel, Expr->Val);
-            break;
-
                default:
            Internal ("Unknown constant type: 0x%04X", ED_GetLoc (Expr));
     }
@@ -245,7 +241,8 @@ static void LoadConstant (unsigned Flags, ExprDesc* Expr)
                    break;
 
                case E_LOC_STATIC:
-                   /* Static symbol, load address */
+               case E_LOC_LITERAL:
+                   /* Static symbol or literal, load address */
                    g_getimmed ((Flags | CF_STATIC) & ~CF_CONST, Expr->Name, Expr->Val);
                    break;
 
@@ -262,11 +259,6 @@ static void LoadConstant (unsigned Flags, ExprDesc* Expr)
                    g_leasp (Expr->Val);
            break;
 
-               case E_LOC_LITERAL:
-           /* Literal string */
-           g_getimmed (CF_STATIC, LiteralPoolLabel, Expr->Val);
-                   break;
-
                default:
            Internal ("Unknown constant type: %04X", Expr->Flags);
     }
@@ -409,7 +401,8 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
                 break;
 
             case E_LOC_STATIC:
-                /* Static variable */
+            case E_LOC_LITERAL:
+                /* Static variable or literal in the literal pool */
                 g_getstatic (Flags | CF_STATIC, Expr->Name, Expr->Val);
                 break;
 
@@ -435,11 +428,6 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
                 g_getind (Flags, Expr->Val);
                 break;
 
-            case E_LOC_LITERAL:
-                /* Literal in the literal pool */
-                g_getstatic (Flags | CF_STATIC, LiteralPoolLabel, Expr->Val);
-                break;
-
             default:
                 Internal ("Invalid location in ExprLoad: 0x%04X", ED_GetLoc (Expr));
         }
@@ -929,9 +917,10 @@ static void Primary (ExprDesc* E)
 
         case TOK_SCONST:
             /* String literal */
-            E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
-            E->Val = CurTok.IVal;
             E->Type  = GetCharArrayType (GetLiteralPoolOffs () - CurTok.IVal);
+            E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL;
+            E->Val   = CurTok.IVal;
+            E->Name  = LiteralPoolLabel;
             NextToken ();
             break;
 
@@ -1390,7 +1379,8 @@ void Store (ExprDesc* Expr, const type* StoreType)
             break;
 
         case E_LOC_STATIC:
-            /* Static variable */
+        case E_LOC_LITERAL:
+            /* Static variable or literal in the literal pool */
             g_putstatic (Flags | CF_STATIC, Expr->Name, Expr->Val);
             break;
 
@@ -1414,11 +1404,6 @@ void Store (ExprDesc* Expr, const type* StoreType)
             g_putind (Flags, Expr->Val);
             break;
 
-        case E_LOC_LITERAL:
-            /* Literal in the literal pool */
-            g_putstatic (Flags | CF_STATIC, LiteralPoolLabel, Expr->Val);
-            break;
-
         default:
             Internal ("Invalid location in Store(): 0x%04X", ED_GetLoc (Expr));
     }
@@ -1465,7 +1450,8 @@ static void PreInc (ExprDesc* Expr)
             break;
 
         case E_LOC_STATIC:
-            /* Static variable */
+        case E_LOC_LITERAL:
+            /* Static variable or literal in the literal pool */
             g_addeqstatic (Flags | CF_STATIC, Expr->Name, Expr->Val, Val);
             break;
 
@@ -1489,11 +1475,6 @@ static void PreInc (ExprDesc* Expr)
             g_addeqind (Flags, Expr->Val, Val);
             break;
 
-        case E_LOC_LITERAL:
-            /* Literal in the literal pool */
-            g_addeqstatic (Flags | CF_STATIC, LiteralPoolLabel, Expr->Val, Val);
-            break;
-
         default:
             Internal ("Invalid location in PreInc(): 0x%04X", ED_GetLoc (Expr));
     }
@@ -1540,7 +1521,8 @@ static void PreDec (ExprDesc* Expr)
             break;
 
         case E_LOC_STATIC:
-            /* Static variable */
+        case E_LOC_LITERAL:
+            /* Static variable or literal in the literal pool */
             g_subeqstatic (Flags | CF_STATIC, Expr->Name, Expr->Val, Val);
             break;
 
@@ -1564,11 +1546,6 @@ static void PreDec (ExprDesc* Expr)
             g_subeqind (Flags, Expr->Val, Val);
             break;
 
-        case E_LOC_LITERAL:
-            /* Literal in the literal pool */
-            g_subeqstatic (Flags | CF_STATIC, LiteralPoolLabel, Expr->Val, Val);
-            break;
-
         default:
             Internal ("Invalid location in PreDec(): 0x%04X", ED_GetLoc (Expr));
     }
@@ -3009,7 +2986,8 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
             break;
 
         case E_LOC_STATIC:
-            /* Static variable */
+        case E_LOC_LITERAL:
+            /* Static variable or literal in the literal pool */
             lflags |= CF_STATIC;
             if (Gen->Tok == TOK_PLUS_ASSIGN) {
                 g_addeqstatic (lflags, Expr->Name, Expr->Val, Expr2.Val);
@@ -3037,16 +3015,6 @@ static void addsubeq (const GenDesc* Gen, ExprDesc *Expr)
             }
             break;
 
-        case E_LOC_LITERAL:
-            /* Literal in the literal pool */
-            lflags |= CF_STATIC;
-            if (Gen->Tok == TOK_PLUS_ASSIGN) {
-                g_addeqstatic (lflags, LiteralPoolLabel, Expr->Val, Expr2.Val);
-            } else {
-                g_subeqstatic (lflags, LiteralPoolLabel, Expr->Val, Expr2.Val);
-            }
-            break;
-
         default:
             Internal ("Invalid location in Store(): 0x%04X", ED_GetLoc (Expr));
     }