]> git.sur5r.net Git - cc65/blobdiff - src/ld65/bin.c
Ignore module.inc
[cc65] / src / ld65 / bin.c
index 48bc5d65b2fecfc170d3c9a98d2b93aa87255a50..017b5a15cf8139e8cdeef6d6d32c0264aa4a4ccf 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1999-2000 Ullrich von Bassewitz                                       */
+/* (C) 1999-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #include <errno.h>
 
 /* common */
+#include "print.h"
 #include "xmalloc.h"
 
 /* ld65 */
 #include "global.h"
 #include "error.h"
 #include "fileio.h"
+#include "lineinfo.h"
 #include "segments.h"
 #include "exports.h"
 #include "config.h"
@@ -98,17 +100,26 @@ void FreeBinDesc (BinDesc* D)
 
 
 static unsigned BinWriteExpr (ExprNode* E, int Signed, unsigned Size,
-                             unsigned long Offs, void* Data)
+                             unsigned long Offs attribute ((unused)),
+                             void* Data)
 /* Called from SegWrite for an expression. Evaluate the expression, check the
  * range and write the expression value to the file.
  */
-{            
+{
     /* There's a predefined function to handle constant expressions */
     return SegWriteConstExpr (((BinDesc*)Data)->F, E, Signed, Size);
 }
 
 
 
+static void PrintBoolVal (const char* Name, int B)
+/* Print a boolean value for debugging */
+{
+    printf ("      %s = %s\n", Name, B? "true" : "false");
+}
+
+
+
 static void BinWriteMem (BinDesc* D, Memory* M)
 /* Write the segments of one memory area to a file */
 {
@@ -125,15 +136,21 @@ static void BinWriteMem (BinDesc* D, Memory* M)
        SegDesc* S = N->Seg;
 
        /* Keep the user happy */
-       if (Verbose) {
-           printf ("    Writing `%s'\n", S->Name);
-       }
+               Print (stdout, 1, "    Writing `%s'\n", S->Name);
 
        /* Writes do only occur in the load area and not for BSS segments */
                DoWrite = (S->Flags & SF_BSS) == 0      &&      /* No BSS segment */
                   S->Load == M                 &&      /* LOAD segment */
                   S->Seg->Dumped == 0;                 /* Not already written */
 
+       /* Output the DoWrite flag for debugging */
+       if (Verbosity > 1) {
+                   PrintBoolVal ("bss", S->Flags & SF_BSS);
+           PrintBoolVal ("LoadArea", S->Load == M);
+                   PrintBoolVal ("Dumped", S->Seg->Dumped);
+           PrintBoolVal ("DoWrite", DoWrite);
+       }
+
        /* Check if we would need an alignment */
        if (S->Seg->Align > S->Align) {
            /* Segment itself requires larger alignment than configured
@@ -171,11 +188,16 @@ static void BinWriteMem (BinDesc* D, Memory* M)
         * if the memory area is the load area.
         */
                if (DoWrite) {
+           RelocLineInfo (S->Seg);
            SegWrite (D->F, S->Seg, BinWriteExpr, D);
        } else if (M->Flags & MF_FILL) {
            WriteMult (D->F, M->FillVal, S->Seg->Size);
        }
-       S->Seg->Dumped = 1;
+
+       /* If this was the load memory area, mark the segment as dumped */
+       if (S->Load == M) {
+           S->Seg->Dumped = 1;
+               }
 
        /* Calculate the new address */
        Addr += S->Seg->Size;
@@ -195,7 +217,7 @@ static void BinWriteMem (BinDesc* D, Memory* M)
 
 
 
-static int BinUnresolved (const char* Name, void* D)
+static int BinUnresolved (const char* Name attribute ((unused)), void* D)
 /* Called if an unresolved symbol is encountered */
 {
     /* Unresolved symbols are an error in binary format. Bump the counter
@@ -233,16 +255,12 @@ void BinWriteTarget (BinDesc* D, struct File* F)
     }
 
     /* Keep the user happy */
-    if (Verbose) {
-       printf ("Opened `%s'...\n", F->Name);
-    }
+    Print (stdout, 1, "Opened `%s'...\n", F->Name);
 
     /* Dump all memory areas */
     M = F->MemList;
     while (M) {
-       if (Verbose) {
-           printf ("  Dumping `%s'\n", M->Name);
-       }
+       Print (stdout, 1, "  Dumping `%s'\n", M->Name);
        BinWriteMem (D, M);
        M = M->FNext;
     }