]> git.sur5r.net Git - cc65/blobdiff - src/cc65/locals.c
Cosmetic changes
[cc65] / src / cc65 / locals.c
index 0824884438663c03859b9425e5c93ec2b3227a02..414e72342a03b2187a8f78c1f1038b3e8958272a 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -84,7 +84,7 @@ void InitRegVars (void)
      * will usually waste some space but we don't need to dynamically
      * grow the array.
      */
-    RegSyms = xmalloc (MaxRegSpace * sizeof (RegSyms[0]));
+    RegSyms = (const SymEntry**) xmalloc (MaxRegSpace * sizeof (RegSyms[0]));
     RegOffs = MaxRegSpace;
 }
 
@@ -152,7 +152,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
     if (IsTypeFunc (Decl.Type)) {
        /* Function prototypes are always external */
        if ((SC & SC_EXTERN) == 0) {
-                   Warning (WARN_FUNC_MUST_BE_EXTERN);
+                   Warning ("Function must be extern");
        }
                SC |= SC_FUNC | SC_EXTERN;
 
@@ -178,16 +178,13 @@ static void ParseOneDecl (const DeclSpec* Spec)
 
                /* Change SC in case it was register */
                SC = (SC & ~SC_REGISTER) | SC_AUTO;
-               if (curtok == TOK_ASSIGN) {
+               if (CurTok.Tok == TOK_ASSIGN) {
 
                    struct expent lval;
 
                    /* Allocate previously reserved local space */
                    AllocLocalSpace (CurrentFunc);
 
-                   /* Switch to the code segment. */
-                   g_usecode ();
-
                    /* Skip the '=' */
                    NextToken ();
 
@@ -229,20 +226,17 @@ static void ParseOneDecl (const DeclSpec* Spec)
                g_usebss ();
 
                /* Define the variable label */
-               SymData = GetLabel ();
-               g_defloclabel (SymData);
+               SymData = GetLocalLabel ();
+               g_defdatalabel (SymData);
 
                /* Reserve space for the data */
                g_res (Size);
 
                /* Allow assignments */
-               if (curtok == TOK_ASSIGN) {
+               if (CurTok.Tok == TOK_ASSIGN) {
 
                    struct expent lval;
 
-                   /* Switch to the code segment. */
-                   g_usecode ();
-
                    /* Skip the '=' */
                    NextToken ();
 
@@ -269,7 +263,7 @@ static void ParseOneDecl (const DeclSpec* Spec)
        } else if ((SC & SC_STATIC) == SC_STATIC) {
 
            /* Static data */
-           if (curtok == TOK_ASSIGN) {
+           if (CurTok.Tok == TOK_ASSIGN) {
 
                /* Initialization ahead, switch to data segment */
                if (IsQualConst (Decl.Type)) {
@@ -279,8 +273,8 @@ static void ParseOneDecl (const DeclSpec* Spec)
                }
 
                /* Define the variable label */
-               SymData = GetLabel ();
-               g_defloclabel (SymData);
+               SymData = GetLocalLabel ();
+               g_defdatalabel (SymData);
 
                /* Skip the '=' */
                NextToken ();
@@ -297,8 +291,8 @@ static void ParseOneDecl (const DeclSpec* Spec)
                g_usebss ();
 
                /* Define the variable label */
-               SymData = GetLabel ();
-               g_defloclabel (SymData);
+               SymData = GetLocalLabel ();
+               g_defdatalabel (SymData);
 
                /* Reserve space for the data */
                g_res (Size);
@@ -322,6 +316,9 @@ static void ParseOneDecl (const DeclSpec* Spec)
 void DeclareLocals (void)
 /* Declare local variables and types. */
 {
+    /* Remember the current stack pointer */
+    int InitialStack = oursp;
+
     /* Loop until we don't find any more variables */
     while (1) {
 
@@ -338,7 +335,7 @@ void DeclareLocals (void)
        }
 
        /* Accept type only declarations */
-       if (curtok == TOK_SEMI) {
+       if (CurTok.Tok == TOK_SEMI) {
            /* Type declaration only */
            CheckEmptyDecl (&Spec);
            NextToken ();
@@ -352,7 +349,7 @@ void DeclareLocals (void)
            ParseOneDecl (&Spec);
 
            /* Check if there is more */
-           if (curtok == TOK_COMMA) {
+           if (CurTok.Tok == TOK_COMMA) {
                /* More to come */
                NextToken ();
            } else {
@@ -368,8 +365,12 @@ void DeclareLocals (void)
     /* Be sure to allocate any reserved space for locals */
     AllocLocalSpace (CurrentFunc);
 
-    /* In case we switched away from code segment, switch back now */
-    g_usecode ();
+    /* 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) {
+               g_cstackcheck ();
+    }
 }