]> git.sur5r.net Git - cc65/commitdiff
Increased the file count to 16 bits when written to the object file.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Aug 2000 21:36:45 +0000 (21:36 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Aug 2000 21:36:45 +0000 (21:36 +0000)
Moved the input file table to a separate module and added an AddFile()
function to add files to this table.
Removed the 8 bit limit for the file number in several places (the file
number is still 8 bits in the file position structure).
Added a pseudo instruction .dbg that will be used to add debug info from
high level code to the assembler source.
Added a subkey "file" to the .dbg command that allows to add a file to the
file table that is later written to the object file.

git-svn-id: svn://svn.cc65.org/cc65/trunk@258 b7a2c559-68d2-44c3-8de9-860c34a00d81

13 files changed:
src/ca65/dbginfo.c [new file with mode: 0644]
src/ca65/dbginfo.h [new file with mode: 0644]
src/ca65/error.c
src/ca65/filetab.c [new file with mode: 0644]
src/ca65/filetab.h [new file with mode: 0644]
src/ca65/listing.c
src/ca65/main.c
src/ca65/make/gcc.mak
src/ca65/make/watcom.mak
src/ca65/objcode.h
src/ca65/pseudo.c
src/ca65/scanner.c
src/ca65/scanner.h

diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c
new file mode 100644 (file)
index 0000000..ef1cd97
--- /dev/null
@@ -0,0 +1,83 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                dbginfo.c                                 */
+/*                                                                           */
+/*                        Handle the .dbg commands                          */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* ca65 */
+#include "error.h"
+#include "expr.h"
+#include "filetab.h"
+#include "nexttok.h"
+#include "dbginfo.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+void DbgInfoFile (void)
+/* Parse and handle FILE subcommand of the .dbg pseudo instruction */
+{
+    char Name [sizeof (SVal)];
+    unsigned long Size;
+    unsigned long MTime;
+
+    /* Name */
+    if (Tok != TOK_STRCON) {
+               ErrorSkip (ERR_STRCON_EXPECTED);
+               return;
+    }
+    strcpy (Name, SVal);
+    NextTok ();
+
+    /* Comma expected */
+    ConsumeComma ();
+
+    /* Size */
+    Size = ConstExpression ();
+
+    /* Comma expected */
+    ConsumeComma ();
+
+    /* MTime */
+    MTime = ConstExpression ();
+
+    /* Insert the file into the table */
+    AddFile (Name, Size, MTime);
+}
+
+
+
diff --git a/src/ca65/dbginfo.h b/src/ca65/dbginfo.h
new file mode 100644 (file)
index 0000000..7d236e1
--- /dev/null
@@ -0,0 +1,59 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                dbginfo.h                                 */
+/*                                                                           */
+/*                        Handle the .dbg commands                          */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef DBGINFO_H
+#define        DBGINFO_H
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+void DbgInfoFile (void);
+/* Parse and handle the .REPEAT statement */
+
+
+
+/* End of dbginfo.h */
+
+#endif
+
+
+
+
+              
index 93ffa121a2809735599d063a02ddcbcef9aa24ad..2337c668b23cba7b69be40b46e02ee67ea579596 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 error.c                                  */
+/*                                 error.c                                  */
 /*                                                                           */
-/*               Error handling for the ca65 macroassembler                 */
+/*               Error handling for the ca65 macroassembler                 */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -36,7 +36,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
-
+                   
+/* ca65 */
+#include "filetab.h"
 #include "nexttok.h"
 #include "error.h"
 
@@ -180,7 +182,7 @@ void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
                "Conditional assembly branch was never closed",
        "Lexical level was not terminated correctly",
        "Segment attribute mismatch",
-       "CPU not supported",
+       "CPU not supported",
        "Counter underflow",
        "Undefined label",
        "Open `%s´",
diff --git a/src/ca65/filetab.c b/src/ca65/filetab.c
new file mode 100644 (file)
index 0000000..c65c833
--- /dev/null
@@ -0,0 +1,136 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                filetab.h                                 */
+/*                                                                           */
+/*                        Input file table for ca65                         */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "check.h"
+#include "xmalloc.h"
+
+/* ca65 */
+#include "error.h"
+#include "objfile.h"
+#include "filetab.h"
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* List of input files */
+static struct {
+    unsigned long  MTime;              /* Time of last modification */
+    unsigned long  Size;               /* Size of file */
+    const char*           Name;                /* Name of file */
+} Files [MAX_INPUT_FILES];
+static unsigned    FileCount = 0;
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+const char* GetFileName (unsigned Name)
+/* Get the name of a file where the name index is known */
+{
+    PRECONDITION (Name <= FileCount);
+    if (Name == 0) {
+       /* Name was defined outside any file scope, use the name of the first
+        * file instead. Errors are then reported with a file position of
+        * line zero in the first file.
+        */
+       if (FileCount == 0) {
+           /* No files defined until now */
+                   return "(outside file scope)";
+       } else {
+           return Files [0].Name;
+       }
+    } else {
+        return Files [Name-1].Name;
+    }
+}
+
+
+
+unsigned AddFile (const char* Name, unsigned long Size, unsigned long MTime)
+/* Add a new file to the list of input files. Return the index of the file in
+ * the table.
+ */
+{
+    /* Check for a table overflow */
+    if (FileCount >= MAX_INPUT_FILES) {
+       /* Table overflow */
+       Fatal (FAT_MAX_INPUT_FILES);
+    }
+
+    /* Add the file to the table */
+    Files [FileCount].Name  = xstrdup (Name);
+    Files [FileCount].Size  = Size;
+    Files [FileCount].MTime = MTime;
+
+    /* One more file */
+    return ++FileCount;
+}
+
+
+
+void WriteFiles (void)
+/* Write the list of input files to the object file */
+{
+    unsigned I;
+
+    /* Tell the obj file module that we're about to start the file list */
+    ObjStartFiles ();
+
+    /* Write the file count */
+    ObjWrite16 (FileCount);
+
+    /* Write the file data */
+    for (I = 0; I < FileCount; ++I) {
+       ObjWrite32 (Files [I].MTime);
+       ObjWrite32 (Files [I].Size);
+       ObjWriteStr (Files [I].Name);
+    }
+
+    /* Done writing files */
+    ObjEndFiles ();
+}
+
+
+
diff --git a/src/ca65/filetab.h b/src/ca65/filetab.h
new file mode 100644 (file)
index 0000000..aa331f8
--- /dev/null
@@ -0,0 +1,68 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                filetab.h                                 */
+/*                                                                           */
+/*                        Input file table for ca65                         */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef FILETAB_H
+#define        FILETAB_H
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+const char* GetFileName (unsigned Name);
+/* Get the name of a file where the name index is known */
+
+unsigned AddFile (const char* Name, unsigned long Size, unsigned long MTime);
+/* Add a new file to the list of input files. Return the index of the file in
+ * the table.
+ */
+
+void WriteFiles (void);
+/* Write the list of input files to the object file */
+
+
+
+
+/* End of filetab.h */
+
+#endif
+
+
+
+
+
index 94edfd2c98adddcf44a1edb505ddb0a336152e9f..e132b24c3982f369a3743174b2349d07d9d151e9 100644 (file)
@@ -46,6 +46,7 @@
 
 /* ca65 */
 #include "error.h"
+#include "filetab.h"
 #include "global.h"
 #include "objcode.h"
 #include "listing.h"
index 9f947f649119d05cec06b381c512253a95cb7178..08f701ccf1e7d127278e4c2786cbd5e9e48f1c92 100644 (file)
 /* common */
 #include "cmdline.h"
 #include "version.h"
-         
+
 /* ca65 */
 #include "error.h"
 #include "expr.h"
+#include "filetab.h"
 #include "global.h"
 #include "incpath.h"
 #include "instr.h"
@@ -307,7 +308,7 @@ static void OneLine (void)
      */
     if (!HavePushedInput ()) {
        InitListingLine ();
-    }    
+    }
 
     if (Tok == TOK_COLON) {
        /* An unnamed label */
index 07f63be933084587439ad592dc10bf00f70b2193..6407780dc7b580ee7d3cf5041d3b02389a25a15a 100644 (file)
@@ -10,9 +10,11 @@ CC   = gcc
 LDFLAGS        =
 
 OBJS =  condasm.o      \
+       dbginfo.o       \
        ea.o            \
         error.o                \
         expr.o         \
+       filetab.o       \
        fragment.o      \
         global.o               \
        incpath.o       \
index 623b6156655940d687f174eb29aa2fc0224adddb..220bb3500354572a402ab8f94ae27aedd51bea97 100644 (file)
@@ -68,9 +68,11 @@ CCCFG        = $(CCCFG) -i=..\common
 # All library OBJ files
 
 OBJS =         condasm.obj     \
+       dbginfo.obj     \
        ea.obj          \
        error.obj       \
        expr.obj        \
+       filetab.obj     \
        fragment.obj    \
        global.obj      \
        incpath.obj     \
@@ -112,9 +114,11 @@ DEBUG ALL
 OPTION QUIET
 NAME $<
 FILE condasm.obj
+FILE dbginfo.obj
 FILE ea.obj
 FILE error.obj
-FILE expr.obj
+FILE expr.obj  
+FILE filetab.obj
 FILE fragment.obj
 FILE global.obj
 FILE incpath.obj
index b4b0d489811aaebff164fdce43c15941863c8018..83c7720c9ca4775187f6ec8c31d29bcc662f7464 100644 (file)
 
 
 
-#include "../common/segdefs.h"
+/* common */
+#include "segdefs.h"
+
+/* ca65 */
 #include "expr.h"
 
 
@@ -163,6 +166,6 @@ void EmitFill (unsigned long Count);
 /* End of objcode.h */
 
 #endif
-               
+
 
 
index 8604ca75f5ebbac5e50231e48f74eef40f86b061..94a5c3e4c7600679cd523fdb49a4e8bf5161d46a 100644 (file)
@@ -45,6 +45,7 @@
 
 /* ca65 */
 #include "condasm.h"
+#include "dbginfo.h"
 #include "error.h"
 #include "expr.h"
 #include "global.h"
@@ -347,6 +348,42 @@ static void DoData (void)
 
 
 
+static void DoDbg (void)
+/* Add debug information from high level code */
+{
+    static const char* Keys[] = {
+               "FILE",
+       "LINE",
+       "SYM",
+    };
+    int Key;
+
+
+    /* We expect a subkey */
+    if (Tok != TOK_IDENT) {
+       ErrorSkip (ERR_IDENT_EXPECTED);
+       return;
+    }
+
+    /* Map the following keyword to a number */
+    Key = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
+
+    /* Skip the subkey */
+    NextTok ();
+           
+    /* Parameters are separated by a comma */
+    ConsumeComma ();
+
+    /* Check the key and dispatch to a handler */
+    switch (Key) {
+       case 0:     DbgInfoFile ();             break;
+       case 1:
+       default:    ErrorSkip (ERR_SYNTAX);     break;
+    }
+}
+
+
+
 static void DoDByt (void)
 /* Output double bytes */
 {
@@ -1113,6 +1150,7 @@ static CtrlDesc CtrlCmdTab [] = {
     { ccNone,          DoUnexpected    },      /* .CONST */
     { ccNone,          DoUnexpected    },      /* .CPU */
     { ccNone,          DoData          },
+    { ccNone,          DoDbg,          },
     { ccNone,          DoDByt          },
     { ccNone,          DoDebugInfo     },
     { ccNone,          DoDefine        },
index fbebe0277b88b4a1ff915d8c9bb43faf044b97f3..850bf03093e12e4877d8788a9ccc17d3fa785fa6 100644 (file)
 /* ca65 */
 #include "condasm.h"
 #include "error.h"
+#include "filetab.h"
 #include "global.h"
 #include "incpath.h"
 #include "instr.h"
 #include "istack.h"
 #include "listing.h"
 #include "macro.h"
-#include "objfile.h"
 #include "toklist.h"
 #include "scanner.h"
 
@@ -101,14 +101,6 @@ struct InputData_ {
     InputData*     Next;               /* Linked list of input data */
 };
 
-/* List of input files */
-static struct {
-    unsigned long  MTime;              /* Time of last modification */
-    unsigned long  Size;               /* Size of file */
-    const char*           Name;                /* Name of file */
-} Files [MAX_INPUT_FILES];
-static unsigned    FileCount = 0;
-
 /* Current input variables */
 static InputFile* IFile                = 0;    /* Current input file */
 static InputData* IData                = 0;    /* Current input memory data */
@@ -139,10 +131,11 @@ struct DotKeyword {
     { "BYTE",          TOK_BYTE        },
     { "CASE",                  TOK_CASE        },
     { "CODE",          TOK_CODE        },
-    { "CONCAT",                TOK_CONCAT      },
+    { "CONCAT",                TOK_CONCAT      },
     { "CONST",                 TOK_CONST       },
-    { "CPU",           TOK_CPU         },
-    { "DATA",                  TOK_DATA        },
+    { "CPU",           TOK_CPU         },
+    { "DATA",                  TOK_DATA        },
+    { "DBG",           TOK_DBG         },
     { "DBYT",                  TOK_DBYT        },
     { "DEBUGINFO",     TOK_DEBUGINFO   },
     { "DEF",                   TOK_DEFINED     },
@@ -311,39 +304,12 @@ static int IsIdStart (int C)
 
 
 
-const char* GetFileName (unsigned char Name)
-/* Get the name of a file where the name index is known */
-{
-    PRECONDITION (Name <= FileCount);
-    if (Name == 0) {
-       /* Name was defined outside any file scope, use the name of the first
-        * file instead. Errors are then reported with a file position of
-        * line zero in the first file.
-        */
-       if (FileCount == 0) {
-           /* No files defined until now */
-                   return "(outside file scope)";
-       } else {
-           return Files [0].Name;
-       }
-    } else {
-        return Files [Name-1].Name;
-    }
-}
-
-
-
 void NewInputFile (const char* Name)
 /* Open a new input file */
 {
     InputFile* I;
     FILE* F;
 
-    /* Check for nested include overflow */
-    if (FileCount >= MAX_INPUT_FILES) {
-       Fatal (FAT_MAX_INPUT_FILES);
-    }
-
     /* First try to open the file */
     F = fopen (Name, "r");
     if (F == 0) {
@@ -372,29 +338,30 @@ void NewInputFile (const char* Name)
     /* check again if we do now have an open file */
     if (F != 0) {
 
+       unsigned FileIdx;
+
        /* Stat the file and remember the values */
        struct stat Buf;
        if (fstat (fileno (F), &Buf) != 0) {
            Fatal (FAT_CANNOT_STAT_INPUT, Name, strerror (errno));
        }
-       Files [FileCount].MTime = Buf.st_mtime;
-       Files [FileCount].Size  = Buf.st_size;
-       Files [FileCount].Name  = xstrdup (Name);
-       ++FileCount;
+
+       /* Add the file to the input file table and remember the index */
+       FileIdx = AddFile (Name, Buf.st_size, Buf.st_mtime);
 
        /* Create a new state variable and initialize it */
-       I           = xmalloc (sizeof (*I));
+       I           = xmalloc (sizeof (*I));
        I->F        = F;
        I->Pos.Line = 0;
        I->Pos.Col  = 0;
-       I->Pos.Name = FileCount;
+       I->Pos.Name = FileIdx;
        I->Tok      = Tok;
-       I->C        = C;
+       I->C        = C;
        I->Line[0]  = '\0';
 
        /* Use the new file */
        I->Next     = IFile;
-       IFile       = I;
+       IFile       = I;
        ++ICount;
 
        /* Prime the pump */
@@ -899,7 +866,7 @@ CharAgain:
                    IVal = 0;
                    do {
                        --IVal;
-                       NextChar ();
+                       NextChar ();
                    } while (C == '-');
                    Tok = TOK_ULABEL;
                    break;
@@ -1128,30 +1095,6 @@ int GetSubKey (const char** Keys, unsigned Count)
 
 
 
-void WriteFiles (void)
-/* Write the list of input files to the object file */
-{
-    unsigned I;
-
-    /* Tell the obj file module that we're about to start the file list */
-    ObjStartFiles ();
-
-    /* Write the file count */
-    ObjWrite8 (FileCount);
-
-    /* Write the file data */
-    for (I = 0; I < FileCount; ++I) {
-       ObjWrite32 (Files [I].MTime);
-       ObjWrite32 (Files [I].Size);
-       ObjWriteStr (Files [I].Name);
-    }
-
-    /* Done writing files */
-    ObjEndFiles ();
-}
-
-
-
 void InitScanner (const char* InFile)
 /* Initialize the scanner, open the given input file */
 {
index 1c4073b01f049f8f94000fab79ad85ae27259f21..b2707d5111fc693a0d476c5a17ce0b124766b026 100644 (file)
@@ -124,6 +124,7 @@ enum Token {
     TOK_CONST,
     TOK_CPU,
     TOK_DATA,
+    TOK_DBG,
     TOK_DBYT,
     TOK_DEBUGINFO,
     TOK_DEFINE,
@@ -226,9 +227,6 @@ extern int          ForcedEnd;              /* Force end of assembly */
 
 
 
-const char* GetFileName (unsigned char Name);
-/* Get the name of a file where the name index is known */
-
 void NewInputFile (const char* Name);
 /* Open a new input file */
 
@@ -257,9 +255,6 @@ int GetSubKey (const char** Keys, unsigned Count);
  * or -1 if the keyword was not found.
  */
 
-void WriteFiles (void);
-/* Write the list of input files to the object file */
-
 void InitScanner (const char* InFile);
 /* Initialize the scanner, open the given input file */