]> git.sur5r.net Git - cc65/blobdiff - src/cc65/symentry.c
Change the OptStackOps function so that it adjusts the instruction pointer
[cc65] / src / cc65 / symentry.c
index 03223fc97ac57d0402b793dcb617ae200866e8c3..e42c8bbaa52a45be4bcd537515a2f0deb1212045 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
-#include "../common/xmalloc.h"
+#include <string.h>
 
+/* common */
+#include "xmalloc.h"
+
+/* cc65 */
+#include "anonname.h"
+#include "declare.h"
+#include "error.h"
 #include "symentry.h"
 
 
@@ -62,6 +69,8 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags)
     E->Owner   = 0;
     E->Flags   = Flags;
     E->Type    = 0;
+    E->Attr     = 0;
+    E->AsmName  = 0;
     memcpy (E->Name, Name, Len+1);
 
     /* Return the new entry */
@@ -74,6 +83,7 @@ void FreeSymEntry (SymEntry* E)
 /* Free a symbol entry */
 {
     TypeFree (E->Type);
+    xfree (E->AsmName);
     xfree (E);
 }
 
@@ -83,25 +93,27 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
 /* Dump the given symbol table entry to the file in readable form */
 {
     static const struct {
-       const char*         Name;
-       unsigned            Val;
+       const char*         Name;
+       unsigned            Val;
     } Flags [] = {
        /* Beware: Order is important! */
-       { "SC_TYPEDEF",     SC_TYPEDEF  },
-       { "SC_SFLD",        SC_SFLD     },
-       { "SC_STRUCT",      SC_STRUCT   },
-       { "SC_AUTO",        SC_AUTO     },
-       { "SC_REGISTER",    SC_REGISTER },
-       { "SC_STATIC",      SC_STATIC   },
-       { "SC_EXTERN",      SC_EXTERN   },
-       { "SC_ENUM",        SC_ENUM     },
-       { "SC_LABEL",       SC_LABEL    },
-       { "SC_PARAM",       SC_PARAM    },
-       { "SC_FUNC",        SC_FUNC     },
-       { "SC_STORAGE",     SC_STORAGE  },
-       { "SC_DEF",         SC_DEF      },
-       { "SC_REF",         SC_REF      },
-       { "SC_ZEROPAGE",    SC_ZEROPAGE },
+       { "SC_TYPEDEF",     SC_TYPEDEF          },
+        { "SC_BITFIELD",    SC_BITFIELD         },
+               { "SC_STRUCTFIELD", SC_STRUCTFIELD      },
+       { "SC_STRUCT",      SC_STRUCT           },
+       { "SC_AUTO",        SC_AUTO             },
+       { "SC_REGISTER",    SC_REGISTER         },
+       { "SC_STATIC",      SC_STATIC           },
+       { "SC_EXTERN",      SC_EXTERN           },
+       { "SC_ENUM",        SC_ENUM             },
+       { "SC_CONST",       SC_CONST            },
+       { "SC_LABEL",       SC_LABEL            },
+       { "SC_PARAM",       SC_PARAM            },
+       { "SC_FUNC",        SC_FUNC             },
+       { "SC_STORAGE",     SC_STORAGE          },
+       { "SC_DEF",         SC_DEF              },
+       { "SC_REF",         SC_REF              },
+       { "SC_ZEROPAGE",    SC_ZEROPAGE         },
     };
 
     unsigned I;
@@ -110,6 +122,11 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
     /* Print the name */
     fprintf (F, "%s:\n", E->Name);
 
+    /* Print the assembler name if we have one */
+    if (E->AsmName) {
+        fprintf (F, "    AsmName: %s\n", E->AsmName);
+    }
+
     /* Print the flags */
     SymFlags = E->Flags;
     fprintf (F, "    Flags: ");
@@ -129,27 +146,104 @@ void DumpSymEntry (FILE* F, const SymEntry* E)
     if (E->Type) {
        PrintType (F, E->Type);
     } else {
-       fprintf (F, "(none)\n");
+       fprintf (F, "(none)");
+    }
+    fprintf (F, "\n");
+}
+
+
+
+int SymIsOutputFunc (const SymEntry* Sym)
+/* Return true if this is a function that must be output */
+{
+    /* Symbol must be a function which is defined and either extern or
+     * static and referenced.
+     */
+    return IsTypeFunc (Sym->Type)               &&
+           SymIsDef (Sym)                       &&
+           (Sym->Flags & (SC_REF | SC_EXTERN));
+}                                               
+
+
+
+const DeclAttr* SymGetAttr (const SymEntry* Sym, DeclAttrType AttrType)
+/* Return an attribute for this symbol or NULL if the attribute does not exist */
+{
+    /* Beware: We may not even have a collection */
+    if (Sym->Attr) {
+        unsigned I;
+        for (I = 0; I < CollCount (Sym->Attr); ++I) {
+
+            /* Get the next attribute */
+            const DeclAttr* A = CollConstAt (Sym->Attr, I);
+
+            /* If this is the one we're searching for, return it */
+            if (A->AttrType == AttrType) {
+                return A;
+            }
+        }
+    }
+
+    /* Not found */
+    return 0;
+}
+
+
+
+void SymUseAttr (SymEntry* Sym, struct Declaration* D)
+/* Use the attributes from the declaration for this symbol */
+{
+    /* We cannot specify attributes twice */
+    if ((Sym->Flags & SC_HAVEATTR) != 0) {
+        if (D->Attributes != 0) {
+            Error ("Attributes must be specified in the first declaration");
+        }
+        return;
     }
+
+    /* Move the attributes */
+    Sym->Attr = D->Attributes;
+    D->Attributes = 0;
+    Sym->Flags |= SC_HAVEATTR;
 }
 
 
 
-int IsTypeDef (const SymEntry* E)
-/* Return true if the given entry is a typedef entry */
+void CvtRegVarToAuto (SymEntry* Sym)
+/* Convert a register variable to an auto variable */
 {
-    return ((E->Flags & SC_TYPEDEF) == SC_TYPEDEF);
+    /* Change the storage class */
+    Sym->Flags = (Sym->Flags & ~(SC_REGISTER | SC_STATIC | SC_EXTERN)) | SC_AUTO;
+
+    /* Transfer the stack offset from register save area to actual offset */
+    Sym->V.Offs = Sym->V.R.SaveOffs;
 }
 
 
 
-void ChangeSymType (SymEntry* Entry, type* Type)
+void ChangeSymType (SymEntry* Entry, Type* T)
 /* Change the type of the given symbol */
 {
     TypeFree (Entry->Type);
-    Entry->Type = TypeDup (Type);
+    Entry->Type = TypeDup (T);
+}
+
+
+
+void ChangeAsmName (SymEntry* Entry, const char* NewAsmName)
+/* Change the assembler name of the symbol */
+{
+    xfree (Entry->AsmName);
+    Entry->AsmName = xstrdup (NewAsmName);
 }
 
 
 
+int HasAnonName (const SymEntry* Entry)
+/* Return true if the symbol entry has an anonymous name */
+{
+    return IsAnonName (Entry->Name);
+}
+
+