]> git.sur5r.net Git - cc65/blobdiff - src/od65/dump.c
Improved code generation
[cc65] / src / od65 / dump.c
index d3f52a9e7a5a5618735bd8d05465927ca7c2534d..208c4bfbced706729d9211dc92495e43f471a528 100644 (file)
@@ -37,6 +37,7 @@
 #include <time.h>
 
 /* common */
+#include "addrsize.h"
 #include "cddefs.h"
 #include "coll.h"
 #include "exprdefs.h"
@@ -171,23 +172,17 @@ static const char* GetExportFlags (unsigned Flags, const unsigned char* ConDes)
     unsigned Count;
     unsigned I;
 
-    /* Adressing mode */
-    TypeDesc[0] = '\0';
-    switch (Flags & EXP_MASK_SIZE) {
-               case EXP_ABS:   strcat (TypeDesc, "EXP_ABS");           break;
-               case EXP_ZP:    strcat (TypeDesc, "EXP_ZP");            break;
-    }
-
     /* Type of expression */
+    TypeDesc[0] = '\0';
     switch (Flags & EXP_MASK_VAL) {
-               case EXP_CONST: strcat (TypeDesc, ",EXP_CONST");        break;
-               case EXP_EXPR:  strcat (TypeDesc, ",EXP_EXPR");         break;
+               case EXP_CONST: strcat (TypeDesc, "EXP_CONST"); break;
+               case EXP_EXPR:  strcat (TypeDesc, "EXP_EXPR");  break;
     }
 
     /* Constructor/destructor declarations */
     T = TypeDesc + strlen (TypeDesc);
     Count = GET_EXP_CONDES_COUNT (Flags);
-    if (Count > 0) {
+    if (Count > 0 && ConDes) {
        T += sprintf (T, ",EXP_CONDES=");
        for (I = 0; I < Count; ++I) {
            unsigned Type = CD_GET_TYPE (ConDes[I]);
@@ -379,9 +374,9 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
     for (I = 0; I < Count; ++I) {
 
        /* Read the data for one file */
+               const char*   Name  = GetString (&StrPool, ReadVar (F));
        unsigned long MTime = Read32 (F);
        unsigned long Size  = Read32 (F);
-       char*         Name  = ReadStr (F);
        unsigned      Len   = strlen (Name);
 
        /* Print the header */
@@ -391,9 +386,6 @@ void DumpObjFiles (FILE* F, unsigned long Offset)
        printf ("      Name:%*s\"%s\"\n", 24-Len, "", Name);
                printf ("      Size:%26lu\n", Size);
        printf ("      Modification time:%13lu  (%s)\n", MTime, TimeToStr (MTime));
-
-       /* Free the Name */
-       xfree (Name);
     }
 
     /* Destroy the string pool */
@@ -438,19 +430,9 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
        unsigned      Len       = strlen (Name);
        unsigned long Size      = Read32 (F);
        unsigned      Align     = (1U << Read8 (F));
-       unsigned char Type      = Read8 (F);
+               unsigned char AddrSize  = Read8 (F);
         unsigned long FragCount = ReadVar (F);
 
-       /* Get the description for the type */
-       const char* TypeDesc;
-       switch (Type) {
-           case SEGTYPE_DEFAULT:       TypeDesc = "SEGTYPE_DEFAULT";   break;
-           case SEGTYPE_ABS:           TypeDesc = "SEGTYPE_ABS";       break;
-           case SEGTYPE_ZP:            TypeDesc = "SEGTYPE_ZP";        break;
-           case SEGTYPE_FAR:           TypeDesc = "SEGTYPE_FAR";       break;
-           default:                    TypeDesc = "SEGTYPE_UNKNOWN";   break;
-       }
-
        /* Print the header */
        printf ("    Index:%27u\n", I);
 
@@ -458,7 +440,8 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
        printf ("      Name:%*s\"%s\"\n", 24-Len, "", Name);
                printf ("      Size:%26lu\n", Size);
        printf ("      Alignment:%21u\n", Align);
-       printf ("      Type:%22s0x%02X  (%s)\n", "", Type, TypeDesc);
+       printf ("      Address size:%14s0x%02X  (%s)\n", "", AddrSize,
+                AddrSizeToStr (AddrSize));
                printf ("      Fragment count:%16lu\n", FragCount);
 
         /* Seek to the end of the segment data (start of next) */
@@ -501,26 +484,18 @@ void DumpObjImports (FILE* F, unsigned long Offset)
     /* Read and print all imports */
     for (I = 0; I < Count; ++I) {
 
-       const char* TypeDesc;
-
                /* Read the data for one import */
-               unsigned char Type  = Read8 (F);
-               const char*   Name  = GetString (&StrPool, ReadVar (F));
-       unsigned      Len   = strlen (Name);
+               unsigned char AddrSize = Read8 (F);
+               const char*   Name     = GetString (&StrPool, ReadVar (F));
+       unsigned      Len      = strlen (Name);
        ReadFilePos (F, &Pos);
 
-       /* Get a description for the type */
-       switch (Type) {
-           case IMP_ZP:        TypeDesc = "IMP_ZP";            break;
-           case IMP_ABS:       TypeDesc = "IMP_ABS";           break;
-           default:            TypeDesc = "IMP_UNKNOWN";       break;
-       }
-
        /* Print the header */
        printf ("    Index:%27u\n", I);
 
        /* Print the data */
-               printf ("      Type:%22s0x%02X  (%s)\n", "", Type, TypeDesc);
+       printf ("      Address size:%14s0x%02X  (%s)\n", "", AddrSize,
+                AddrSizeToStr (AddrSize));
        printf ("      Name:%*s\"%s\"\n", 24-Len, "", Name);
     }
 
@@ -562,14 +537,14 @@ void DumpObjExports (FILE* F, unsigned long Offset)
 
        unsigned long   Value = 0;
        int             HaveValue;
-       unsigned char   Type;
        unsigned char   ConDes [CD_TYPE_COUNT];
                const char*     Name;
        unsigned        Len;
 
 
                /* Read the data for one export */
-               Type  = Read8 (F);
+               unsigned char Type = Read8 (F);
+        unsigned char AddrSize = Read8 (F);
        ReadData (F, ConDes, GET_EXP_CONDES_COUNT (Type));
                Name  = GetString (&StrPool, ReadVar (F));
        Len   = strlen (Name);
@@ -587,6 +562,8 @@ void DumpObjExports (FILE* F, unsigned long Offset)
 
        /* Print the data */
                printf ("      Type:%22s0x%02X  (%s)\n", "", Type, GetExportFlags (Type, ConDes));
+       printf ("      Address size:%14s0x%02X  (%s)\n", "", AddrSize,
+                AddrSizeToStr (AddrSize));
        printf ("      Name:%*s\"%s\"\n", 24-Len, "", Name);
        if (HaveValue) {
            printf ("      Value:%15s0x%08lX  (%lu)\n", "", Value, Value);
@@ -637,17 +614,13 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
     for (I = 0; I < Count; ++I) {
 
        unsigned long   Value = 0;
-       int             HaveValue;
-       unsigned char   Type;
-       unsigned char   ConDes [CD_TYPE_COUNT];
-               const char*     Name;
-       unsigned        Len;
+       int             HaveValue;
 
                /* Read the data for one symbol */
-               Type  = Read8 (F);
-       ReadData (F, ConDes, GET_EXP_CONDES_COUNT (Type));
-               Name  = GetString (&StrPool, ReadVar (F));
-       Len   = strlen (Name);
+               unsigned char Type     = Read8 (F);
+        unsigned char AddrSize = Read8 (F);
+               const char*   Name     = GetString (&StrPool, ReadVar (F));
+       unsigned      Len      = strlen (Name);
        if (IS_EXP_EXPR (Type)) {
            SkipExpr (F);
            HaveValue = 0;
@@ -661,7 +634,9 @@ void DumpObjDbgSyms (FILE* F, unsigned long Offset)
        printf ("    Index:%27u\n", I);
 
        /* Print the data */
-               printf ("      Type:%22s0x%02X  (%s)\n", "", Type, GetExportFlags (Type, ConDes));
+               printf ("      Type:%22s0x%02X  (%s)\n", "", Type, GetExportFlags (Type, 0));
+       printf ("      Address size:%14s0x%02X  (%s)\n", "", AddrSize,
+                AddrSizeToStr (AddrSize));
        printf ("      Name:%*s\"%s\"\n", 24-Len, "", Name);
        if (HaveValue) {
            printf ("      Value:%15s0x%08lX  (%lu)\n", "", Value, Value);