]> git.sur5r.net Git - cc65/blobdiff - src/common/addrsize.c
Added cc65_symbol_byscope.
[cc65] / src / common / addrsize.c
index 278f5745b2a392d7f8320e7125abfca3bcc10a19..82dc14d0073c73d6fd1cd56c58cb161c8c25702e 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 /* common */
 #include "addrsize.h"
+#include "strutil.h"
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                          Code                                    */
 /*****************************************************************************/
 
 
@@ -52,9 +53,45 @@ const char* AddrSizeToStr (unsigned char AddrSize)
         case ADDR_SIZE_ZP:              return "zeropage";
         case ADDR_SIZE_ABS:             return "absolute";
         case ADDR_SIZE_FAR:             return "far";
+        case ADDR_SIZE_LONG:            return "long";
         default:                        return "unknown";
     }
 }
 
 
 
+unsigned char AddrSizeFromStr (const char* Str)
+/* Return the address size for a given string. Returns ADDR_SIZE_INVALID if
+ * the string cannot be mapped to an address size.
+ */
+{
+    static const struct {
+        const char*     Name;
+        unsigned char   AddrSize;
+    } AddrSizeTable[] = {
+        { "abs",        ADDR_SIZE_ABS     },
+        { "absolute",   ADDR_SIZE_ABS     },
+        { "default",    ADDR_SIZE_DEFAULT },
+        { "direct",     ADDR_SIZE_ZP      },
+        { "dword",      ADDR_SIZE_LONG    },
+        { "far",        ADDR_SIZE_FAR     },
+        { "long",       ADDR_SIZE_LONG    },
+        { "near",       ADDR_SIZE_ABS     },
+        { "zeropage",   ADDR_SIZE_ZP      },
+        { "zp",         ADDR_SIZE_ZP      },
+    };
+    unsigned I;
+
+    for (I = 0; I < sizeof (AddrSizeTable) / sizeof (AddrSizeTable[0]); ++I) {
+        if (StrCaseCmp (Str, AddrSizeTable[I].Name) == 0) {
+            /* Found */
+            return AddrSizeTable[I].AddrSize;
+        }
+    }
+
+    /* Not found */
+    return ADDR_SIZE_INVALID;
+}
+
+
+