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
This commit is contained in:
cuz
2000-08-01 21:36:45 +00:00
parent 6b3b938945
commit 51543fddb0
13 changed files with 422 additions and 87 deletions

83
src/ca65/dbginfo.c Normal file
View File

@@ -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);
}

59
src/ca65/dbginfo.h Normal file
View File

@@ -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

View 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
/* ca65 */
#include "filetab.h"
#include "nexttok.h" #include "nexttok.h"
#include "error.h" #include "error.h"
@@ -180,7 +182,7 @@ void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
"Conditional assembly branch was never closed", "Conditional assembly branch was never closed",
"Lexical level was not terminated correctly", "Lexical level was not terminated correctly",
"Segment attribute mismatch", "Segment attribute mismatch",
"CPU not supported", "CPU not supported",
"Counter underflow", "Counter underflow",
"Undefined label", "Undefined label",
"Open `%s<>", "Open `%s<>",

136
src/ca65/filetab.c Normal file
View File

@@ -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 ();
}

68
src/ca65/filetab.h Normal file
View File

@@ -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

View File

@@ -46,6 +46,7 @@
/* ca65 */ /* ca65 */
#include "error.h" #include "error.h"
#include "filetab.h"
#include "global.h" #include "global.h"
#include "objcode.h" #include "objcode.h"
#include "listing.h" #include "listing.h"

View File

@@ -42,10 +42,11 @@
/* common */ /* common */
#include "cmdline.h" #include "cmdline.h"
#include "version.h" #include "version.h"
/* ca65 */ /* ca65 */
#include "error.h" #include "error.h"
#include "expr.h" #include "expr.h"
#include "filetab.h"
#include "global.h" #include "global.h"
#include "incpath.h" #include "incpath.h"
#include "instr.h" #include "instr.h"
@@ -307,7 +308,7 @@ static void OneLine (void)
*/ */
if (!HavePushedInput ()) { if (!HavePushedInput ()) {
InitListingLine (); InitListingLine ();
} }
if (Tok == TOK_COLON) { if (Tok == TOK_COLON) {
/* An unnamed label */ /* An unnamed label */

View File

@@ -10,9 +10,11 @@ CC = gcc
LDFLAGS = LDFLAGS =
OBJS = condasm.o \ OBJS = condasm.o \
dbginfo.o \
ea.o \ ea.o \
error.o \ error.o \
expr.o \ expr.o \
filetab.o \
fragment.o \ fragment.o \
global.o \ global.o \
incpath.o \ incpath.o \

View File

@@ -68,9 +68,11 @@ CCCFG = $(CCCFG) -i=..\common
# All library OBJ files # All library OBJ files
OBJS = condasm.obj \ OBJS = condasm.obj \
dbginfo.obj \
ea.obj \ ea.obj \
error.obj \ error.obj \
expr.obj \ expr.obj \
filetab.obj \
fragment.obj \ fragment.obj \
global.obj \ global.obj \
incpath.obj \ incpath.obj \
@@ -112,9 +114,11 @@ DEBUG ALL
OPTION QUIET OPTION QUIET
NAME $< NAME $<
FILE condasm.obj FILE condasm.obj
FILE dbginfo.obj
FILE ea.obj FILE ea.obj
FILE error.obj FILE error.obj
FILE expr.obj FILE expr.obj
FILE filetab.obj
FILE fragment.obj FILE fragment.obj
FILE global.obj FILE global.obj
FILE incpath.obj FILE incpath.obj

View File

@@ -38,7 +38,10 @@
#include "../common/segdefs.h" /* common */
#include "segdefs.h"
/* ca65 */
#include "expr.h" #include "expr.h"
@@ -163,6 +166,6 @@ void EmitFill (unsigned long Count);
/* End of objcode.h */ /* End of objcode.h */
#endif #endif

View File

@@ -45,6 +45,7 @@
/* ca65 */ /* ca65 */
#include "condasm.h" #include "condasm.h"
#include "dbginfo.h"
#include "error.h" #include "error.h"
#include "expr.h" #include "expr.h"
#include "global.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) static void DoDByt (void)
/* Output double bytes */ /* Output double bytes */
{ {
@@ -1113,6 +1150,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoUnexpected }, /* .CONST */ { ccNone, DoUnexpected }, /* .CONST */
{ ccNone, DoUnexpected }, /* .CPU */ { ccNone, DoUnexpected }, /* .CPU */
{ ccNone, DoData }, { ccNone, DoData },
{ ccNone, DoDbg, },
{ ccNone, DoDByt }, { ccNone, DoDByt },
{ ccNone, DoDebugInfo }, { ccNone, DoDebugInfo },
{ ccNone, DoDefine }, { ccNone, DoDefine },

View File

@@ -48,13 +48,13 @@
/* ca65 */ /* ca65 */
#include "condasm.h" #include "condasm.h"
#include "error.h" #include "error.h"
#include "filetab.h"
#include "global.h" #include "global.h"
#include "incpath.h" #include "incpath.h"
#include "instr.h" #include "instr.h"
#include "istack.h" #include "istack.h"
#include "listing.h" #include "listing.h"
#include "macro.h" #include "macro.h"
#include "objfile.h"
#include "toklist.h" #include "toklist.h"
#include "scanner.h" #include "scanner.h"
@@ -101,14 +101,6 @@ struct InputData_ {
InputData* Next; /* Linked list of input data */ 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 */ /* Current input variables */
static InputFile* IFile = 0; /* Current input file */ static InputFile* IFile = 0; /* Current input file */
static InputData* IData = 0; /* Current input memory data */ static InputData* IData = 0; /* Current input memory data */
@@ -139,10 +131,11 @@ struct DotKeyword {
{ "BYTE", TOK_BYTE }, { "BYTE", TOK_BYTE },
{ "CASE", TOK_CASE }, { "CASE", TOK_CASE },
{ "CODE", TOK_CODE }, { "CODE", TOK_CODE },
{ "CONCAT", TOK_CONCAT }, { "CONCAT", TOK_CONCAT },
{ "CONST", TOK_CONST }, { "CONST", TOK_CONST },
{ "CPU", TOK_CPU }, { "CPU", TOK_CPU },
{ "DATA", TOK_DATA }, { "DATA", TOK_DATA },
{ "DBG", TOK_DBG },
{ "DBYT", TOK_DBYT }, { "DBYT", TOK_DBYT },
{ "DEBUGINFO", TOK_DEBUGINFO }, { "DEBUGINFO", TOK_DEBUGINFO },
{ "DEF", TOK_DEFINED }, { "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) void NewInputFile (const char* Name)
/* Open a new input file */ /* Open a new input file */
{ {
InputFile* I; InputFile* I;
FILE* F; FILE* F;
/* Check for nested include overflow */
if (FileCount >= MAX_INPUT_FILES) {
Fatal (FAT_MAX_INPUT_FILES);
}
/* First try to open the file */ /* First try to open the file */
F = fopen (Name, "r"); F = fopen (Name, "r");
if (F == 0) { if (F == 0) {
@@ -372,29 +338,30 @@ void NewInputFile (const char* Name)
/* check again if we do now have an open file */ /* check again if we do now have an open file */
if (F != 0) { if (F != 0) {
unsigned FileIdx;
/* Stat the file and remember the values */ /* Stat the file and remember the values */
struct stat Buf; struct stat Buf;
if (fstat (fileno (F), &Buf) != 0) { if (fstat (fileno (F), &Buf) != 0) {
Fatal (FAT_CANNOT_STAT_INPUT, Name, strerror (errno)); Fatal (FAT_CANNOT_STAT_INPUT, Name, strerror (errno));
} }
Files [FileCount].MTime = Buf.st_mtime;
Files [FileCount].Size = Buf.st_size; /* Add the file to the input file table and remember the index */
Files [FileCount].Name = xstrdup (Name); FileIdx = AddFile (Name, Buf.st_size, Buf.st_mtime);
++FileCount;
/* Create a new state variable and initialize it */ /* Create a new state variable and initialize it */
I = xmalloc (sizeof (*I)); I = xmalloc (sizeof (*I));
I->F = F; I->F = F;
I->Pos.Line = 0; I->Pos.Line = 0;
I->Pos.Col = 0; I->Pos.Col = 0;
I->Pos.Name = FileCount; I->Pos.Name = FileIdx;
I->Tok = Tok; I->Tok = Tok;
I->C = C; I->C = C;
I->Line[0] = '\0'; I->Line[0] = '\0';
/* Use the new file */ /* Use the new file */
I->Next = IFile; I->Next = IFile;
IFile = I; IFile = I;
++ICount; ++ICount;
/* Prime the pump */ /* Prime the pump */
@@ -899,7 +866,7 @@ CharAgain:
IVal = 0; IVal = 0;
do { do {
--IVal; --IVal;
NextChar (); NextChar ();
} while (C == '-'); } while (C == '-');
Tok = TOK_ULABEL; Tok = TOK_ULABEL;
break; 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) void InitScanner (const char* InFile)
/* Initialize the scanner, open the given input file */ /* Initialize the scanner, open the given input file */
{ {

View File

@@ -124,6 +124,7 @@ enum Token {
TOK_CONST, TOK_CONST,
TOK_CPU, TOK_CPU,
TOK_DATA, TOK_DATA,
TOK_DBG,
TOK_DBYT, TOK_DBYT,
TOK_DEBUGINFO, TOK_DEBUGINFO,
TOK_DEFINE, 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); void NewInputFile (const char* Name);
/* Open a new input file */ /* Open a new input file */
@@ -257,9 +255,6 @@ int GetSubKey (const char** Keys, unsigned Count);
* or -1 if the keyword was not found. * 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); void InitScanner (const char* InFile);
/* Initialize the scanner, open the given input file */ /* Initialize the scanner, open the given input file */