From: cuz Date: Tue, 1 Aug 2000 21:36:45 +0000 (+0000) Subject: Increased the file count to 16 bits when written to the object file. X-Git-Tag: V2.12.0~3260 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=51543fddb01cd8c15cc3f9d26157a76e4bb2f816;p=cc65 Increased the file count to 16 bits when written to the object file. 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 --- diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c new file mode 100644 index 000000000..ef1cd9752 --- /dev/null +++ b/src/ca65/dbginfo.c @@ -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 index 000000000..7d236e1c3 --- /dev/null +++ b/src/ca65/dbginfo.h @@ -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 + + + + + diff --git a/src/ca65/error.c b/src/ca65/error.c index 93ffa121a..2337c668b 100644 --- a/src/ca65/error.c +++ b/src/ca65/error.c @@ -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 #include #include - + +/* 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 index 000000000..c65c833ce --- /dev/null +++ b/src/ca65/filetab.c @@ -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 index 000000000..aa331f874 --- /dev/null +++ b/src/ca65/filetab.h @@ -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 + + + + + diff --git a/src/ca65/listing.c b/src/ca65/listing.c index 94edfd2c9..e132b24c3 100644 --- a/src/ca65/listing.c +++ b/src/ca65/listing.c @@ -46,6 +46,7 @@ /* ca65 */ #include "error.h" +#include "filetab.h" #include "global.h" #include "objcode.h" #include "listing.h" diff --git a/src/ca65/main.c b/src/ca65/main.c index 9f947f649..08f701ccf 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -42,10 +42,11 @@ /* 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 */ diff --git a/src/ca65/make/gcc.mak b/src/ca65/make/gcc.mak index 07f63be93..6407780dc 100644 --- a/src/ca65/make/gcc.mak +++ b/src/ca65/make/gcc.mak @@ -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 \ diff --git a/src/ca65/make/watcom.mak b/src/ca65/make/watcom.mak index 623b61566..220bb3500 100644 --- a/src/ca65/make/watcom.mak +++ b/src/ca65/make/watcom.mak @@ -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 diff --git a/src/ca65/objcode.h b/src/ca65/objcode.h index b4b0d4898..83c7720c9 100644 --- a/src/ca65/objcode.h +++ b/src/ca65/objcode.h @@ -38,7 +38,10 @@ -#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 - + diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 8604ca75f..94a5c3e4c 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -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 }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index fbebe0277..850bf0309 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -48,13 +48,13 @@ /* 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 */ { diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index 1c4073b01..b2707d511 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -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 */