--- /dev/null
+/*****************************************************************************/
+/* */
+/* 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);
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* 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
+
+
+
+
+
/*****************************************************************************/
/* */
-/* error.c */
+/* error.c */
/* */
-/* Error handling for the ca65 macroassembler */
+/* Error handling for the ca65 macroassembler */
/* */
/* */
/* */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-
+
+/* ca65 */
+#include "filetab.h"
#include "nexttok.h"
#include "error.h"
"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´",
--- /dev/null
+/*****************************************************************************/
+/* */
+/* 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 ();
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* 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
+
+
+
+
+
/* ca65 */
#include "error.h"
+#include "filetab.h"
#include "global.h"
#include "objcode.h"
#include "listing.h"
/* 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"
*/
if (!HavePushedInput ()) {
InitListingLine ();
- }
+ }
if (Tok == TOK_COLON) {
/* An unnamed label */
LDFLAGS =
OBJS = condasm.o \
+ dbginfo.o \
ea.o \
error.o \
expr.o \
+ filetab.o \
fragment.o \
global.o \
incpath.o \
# All library OBJ files
OBJS = condasm.obj \
+ dbginfo.obj \
ea.obj \
error.obj \
expr.obj \
+ filetab.obj \
fragment.obj \
global.obj \
incpath.obj \
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
-#include "../common/segdefs.h"
+/* common */
+#include "segdefs.h"
+
+/* ca65 */
#include "expr.h"
/* End of objcode.h */
#endif
-
+
/* ca65 */
#include "condasm.h"
+#include "dbginfo.h"
#include "error.h"
#include "expr.h"
#include "global.h"
+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 */
{
{ ccNone, DoUnexpected }, /* .CONST */
{ ccNone, DoUnexpected }, /* .CPU */
{ ccNone, DoData },
+ { ccNone, DoDbg, },
{ ccNone, DoDByt },
{ ccNone, DoDebugInfo },
{ ccNone, DoDefine },
/* 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"
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 */
{ "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 },
-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) {
/* 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 */
IVal = 0;
do {
--IVal;
- NextChar ();
+ NextChar ();
} while (C == '-');
Tok = TOK_ULABEL;
break;
-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 */
{
TOK_CONST,
TOK_CPU,
TOK_DATA,
+ TOK_DBG,
TOK_DBYT,
TOK_DEBUGINFO,
TOK_DEFINE,
-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 */
* 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 */