]> git.sur5r.net Git - cc65/blobdiff - src/da65/attrtab.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / da65 / attrtab.c
index 90233e2bb8e8b65c49a1a22098659d86ceca30c3..07a47b72e7210d9da194a813e03a3b6a9843d219 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                attrtab.c                                 */
+/*                                 attrtab.c                                 */
 /*                                                                           */
-/*                      Disassembler attribute table                        */
+/*                       Disassembler attribute table                        */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2005 Ullrich von Bassewitz                                       */
+/* (C) 2000-2006 Ullrich von Bassewitz                                       */
 /*               Römerstrasse 52                                             */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 
 
 
-#include <stdio.h>
-#include <string.h>
-
-/* common */
-#include "xmalloc.h"
-#include "xsprintf.h"
-
 /* da65 */
-#include "code.h"
 #include "error.h"
-#include "global.h"
-#include "output.h"
 #include "attrtab.h"
 
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 
-/* Label + comment */
-typedef struct {
-    const char*        Name;
-    const char* Comment;
-} Label;
-
-/* A whole lot of Labels, so we don't have to allocate them separately */
-static Label* LabelHeap = 0;
-static unsigned LabelsLeft = 0;
-
 /* Attribute table */
-static unsigned char AttrTab [0x10000];
-
-/* Symbol table */
-static const Label* SymTab [0x10000];
+static unsigned short AttrTab[0x10000];
 
 
 
 /*****************************************************************************/
-/*                               struct Label                                */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
 
-Label* NewLabel (const char* Name, const char* Comment)
-/* Create a new Label structure, initialize and return it */
+void AddrCheck (unsigned Addr)
+/* Check if the given address has a valid range */
 {
-    Label* L;
-
-    /* Check if we have some free labels left */
-    if (LabelsLeft == 0) {
-        /* Allocate a new block of memory */
-        LabelsLeft = 200;
-        LabelHeap = xmalloc (LabelsLeft * sizeof (Label));
+    if (Addr >= 0x10000) {
+        Error ("Address out of range: %08X", Addr);
     }
-
-    /* Get a new one from the buffer */
-    L = LabelHeap++;
-    --LabelsLeft;
-
-    /* Initialize the new label */
-    L->Name = xstrdup (Name);
-    L->Comment = Comment? xstrdup (Comment) : 0;
-
-    /* Return the new label */
-    return L;
 }
 
 
 
-/*****************************************************************************/
-/*                                  Code                                    */
-/*****************************************************************************/
+int SegmentDefined (unsigned Start, unsigned End)
+/* Return true if the atSegment bit is set somewhere in the given range */
+{
+    while (Start <= End) {
+        if (AttrTab[Start++] & atSegment) {
+            return 1;
+        }
+    }
+    return 0;
+}
 
 
 
-static void AddrCheck (unsigned Addr)
-/* Check if the given address has a valid range */
+int HaveSegmentChange (unsigned Addr)
+/* Return true if the segment change attribute is set for the given address */
 {
-    if (Addr >= 0x10000) {
-       Error ("Address out of range: %08X", Addr);
-    }
+    /* Check the given address */
+    AddrCheck (Addr);
+
+    /* Return the attribute */
+    return (AttrTab[Addr] & atSegmentChange) != 0;
 }
 
 
@@ -125,21 +95,21 @@ unsigned GetGranularity (attr_t Style)
 /* Get the granularity for the given style */
 {
     switch (Style) {
-       case atDefault:  return 1;
-       case atCode:     return 1;
-       case atIllegal:  return 1;
-       case atByteTab:  return 1;
-       case atDByteTab: return 2;
-       case atWordTab:  return 2;
-       case atDWordTab: return 4;
-       case atAddrTab:  return 2;
-       case atRtsTab:   return 2;
-       case atTextTab:  return 1;
-
-       case atSkip:
-       default:
-           Internal ("GetGraularity called for style = %d", Style);
-           return 0;
+        case atDefault:  return 1;
+        case atCode:     return 1;
+        case atIllegal:  return 1;
+        case atByteTab:  return 1;
+        case atDByteTab: return 2;
+        case atWordTab:  return 2;
+        case atDWordTab: return 4;
+        case atAddrTab:  return 2;
+        case atRtsTab:   return 2;
+        case atTextTab:  return 1;
+
+        case atSkip:
+        default:
+            Internal ("GetGraularity called for style = %d", Style);
+            return 0;
     }
 }
 
@@ -150,7 +120,7 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr)
 {
     /* Do it easy here... */
     while (Start <= End) {
-       MarkAddr (Start++, Attr);
+        MarkAddr (Start++, Attr);
     }
 }
 
@@ -164,9 +134,9 @@ void MarkAddr (unsigned Addr, attr_t Attr)
 
     /* We must not have more than one style bit */
     if (Attr & atStyleMask) {
-       if (AttrTab[Addr] & atStyleMask) {
-           Error ("Duplicate style for address %04X", Addr);
-       }
+        if (AttrTab[Addr] & atStyleMask) {
+            Error ("Duplicate style for address %04X", Addr);
+        }
     }
 
     /* Set the style */
@@ -175,195 +145,19 @@ void MarkAddr (unsigned Addr, attr_t Attr)
 
 
 
-static const char* MakeLabelName (unsigned Addr)
-/* Make the default label name from the given address and return it in a
- * static buffer.
- */
-{
-    static char LabelBuf [32];
-    xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr);
-    return LabelBuf;
-}
-
-
-
-void AddLabel (unsigned Addr, attr_t Attr, const char* Name, const char* Comment)
-/* Add a label */
-{
-    /* Get an existing label attribute */
-    attr_t ExistingAttr = GetLabelAttr (Addr);
-
-    /* Must not have two symbols for one address */
-    if (ExistingAttr != atNoLabel) {
-       /* Allow redefinition if identical */
-               if (ExistingAttr == Attr && strcmp (SymTab[Addr]->Name, Name) == 0) {
-           return;
-       }
-       Error ("Duplicate label for address $%04X: %s/%s", Addr, SymTab[Addr]->Name, Name);
-    }
-
-    /* Create a new label */
-    SymTab[Addr] = NewLabel (Name, Comment);
-
-    /* Remember the attribute */
-    AttrTab[Addr] |= Attr;
-}
-
-
-
-void AddIntLabel (unsigned Addr)
-/* Add an internal label using the address to generate the name. */
-{
-    AddLabel (Addr, atIntLabel, MakeLabelName (Addr), 0);
-}
-
-
-
-void AddExtLabel (unsigned Addr, const char* Name, const char* Comment)
-/* Add an external label */
-{
-    AddLabel (Addr, atExtLabel, Name, Comment);
-}
-
-
-
-void AddDepLabel (unsigned Addr, attr_t Attr, const char* BaseName, unsigned Offs)
-/* Add a dependent label at the given address using "base name+Offs" as the new
- * name.
- */
-{
-    /* Allocate memory for the dependent label name */
-    unsigned NameLen = strlen (BaseName);
-    char*    DepName = xmalloc (NameLen + 7);  /* "+$ABCD" */
-
-    /* Create the new name in the buffer */
-    if (UseHexOffs) {
-       sprintf (DepName, "%s+$%02X", BaseName, Offs);
-    } else {
-       sprintf (DepName, "%s+%u", BaseName, Offs);
-    }
-
-    /* Define the labels */
-    AddLabel (Addr, Attr | atDepLabel, DepName, 0);
-
-    /* Free the name buffer */
-    xfree (DepName);
-}
-
-
-
-static void AddLabelRange (unsigned Addr, attr_t Attr,
-                           const char* Name, const char* Comment,
-                           unsigned Count)
-/* Add a label for a range. The first entry gets the label "Name" while the
- * others get "Name+offs".
- */
-{
-    /* Define the label */
-    AddLabel (Addr, Attr, Name, Comment);
-
-    /* Define dependent labels if necessary */
-    if (Count > 1) {
-       unsigned Offs;
-
-        /* Setup the format string */
-        const char* Format = UseHexOffs? "$%02X" : "%u";
-
-       /* Allocate memory for the dependent label names */
-       unsigned NameLen = strlen (Name);
-       char*    DepName = xmalloc (NameLen + 7);       /* "+$ABCD" */
-       char*    DepOffs = DepName + NameLen + 1;
-
-       /* Copy the original name into the buffer */
-       memcpy (DepName, Name, NameLen);
-       DepName[NameLen] = '+';
-
-       /* Define the labels */
-               for (Offs = 1; Offs < Count; ++Offs) {
-           sprintf (DepOffs, Format, Offs);
-           AddLabel (Addr + Offs, Attr | atDepLabel, DepName, 0);
-       }
-
-       /* Free the name buffer */
-       xfree (DepName);
-    }
-}
-
-
-
-void AddIntLabelRange (unsigned Addr, const char* Name, unsigned Count)
-/* Add an internal label for a range. The first entry gets the label "Name"
- * while the others get "Name+offs".
- */
-{
-    /* Define the label range */
-    AddLabelRange (Addr, atIntLabel, Name, 0, Count);
-}
-
-
-
-void AddExtLabelRange (unsigned Addr, const char* Name, const char* Comment, unsigned Count)
-/* Add an external label for a range. The first entry gets the label "Name"
- * while the others get "Name+offs".
- */
-{
-    /* Define the label range */
-    AddLabelRange (Addr, atExtLabel, Name, Comment, Count);
-}
-
-
-
-int HaveLabel (unsigned Addr)
-/* Check if there is a label for the given address */
-{
-    /* Check the given address */
-    AddrCheck (Addr);
-
-    /* Check for a label */
-    return (SymTab[Addr] != 0);
-}
-
-
-
-int MustDefLabel (unsigned Addr)
-/* Return true if we must define a label for this address, that is, if there
- * is a label at this address, and it is an external or internal label.
- */
-{
-    /* Get the label attribute */
-    attr_t A = GetLabelAttr (Addr);
-
-    /* Check for an internal or external label */
-    return (A == atExtLabel || A == atIntLabel);
-}
-
-
-
-const char* GetLabel (unsigned Addr)
-/* Return the label for an address */
+attr_t GetAttr (unsigned Addr)
+/* Return the attribute for the given address */
 {
     /* Check the given address */
     AddrCheck (Addr);
 
-    /* Return the label if any */
-    return SymTab[Addr]? SymTab[Addr]->Name : 0;
-}
-
-
-
-const char* GetComment (unsigned Addr)
-/* Return the comment for an address */
-{
-    /* Check the given address */
-    AddrCheck (Addr);
-
-    /* Return the label if any */
-    return SymTab[Addr]? SymTab[Addr]->Comment : 0;
+    /* Return the attribute */
+    return AttrTab[Addr];
 }
 
 
 
-unsigned char GetStyleAttr (unsigned Addr)
+attr_t GetStyleAttr (unsigned Addr)
 /* Return the style attribute for the given address */
 {
     /* Check the given address */
@@ -375,7 +169,7 @@ unsigned char GetStyleAttr (unsigned Addr)
 
 
 
-unsigned char GetLabelAttr (unsigned Addr)
+attr_t GetLabelAttr (unsigned Addr)
 /* Return the label attribute for the given address */
 {
     /* Check the given address */
@@ -387,40 +181,3 @@ unsigned char GetLabelAttr (unsigned Addr)
 
 
 
-void DefOutOfRangeLabels (void)
-/* Output any labels that are out of the loaded code range */
-{
-    unsigned long Addr;
-
-    SeparatorLine ();
-
-    /* Low range */
-    Addr = 0;
-    while (Addr < CodeStart) {
-       if (MustDefLabel (Addr)) {
-           DefineConst (SymTab[Addr]->Name, SymTab[Addr]->Comment, Addr);
-       }
-        ++Addr;
-    }
-
-    /* Skip areas in code range */
-    while (Addr <= CodeEnd) {
-        if ((AttrTab[Addr] & atStyleMask) == atSkip && MustDefLabel (Addr)) {
-           DefineConst (SymTab[Addr]->Name, SymTab[Addr]->Comment, Addr);
-        }
-        ++Addr;
-    }
-
-    /* High range */
-    while (Addr < 0x10000) {
-       if (MustDefLabel (Addr)) {
-           DefineConst (SymTab[Addr]->Name, SymTab[Addr]->Comment, Addr);
-       }
-        ++Addr;
-    }
-
-    SeparatorLine ();
-}
-
-
-