mirror of
https://github.com/cc65/cc65.git
synced 2024-12-24 11:31:31 +00:00
Added .dbg statement generation for the assembler
git-svn-id: svn://svn.cc65.org/cc65/trunk@744 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
afbf6d5fac
commit
bc8f4f3a1e
@ -143,32 +143,44 @@ void g_preamble (void)
|
|||||||
PushSegments (0);
|
PushSegments (0);
|
||||||
|
|
||||||
/* Identify the compiler version */
|
/* Identify the compiler version */
|
||||||
|
AddTextLine (";");
|
||||||
AddTextLine ("; File generated by cc65 v %u.%u.%u",
|
AddTextLine ("; File generated by cc65 v %u.%u.%u",
|
||||||
VER_MAJOR, VER_MINOR, VER_PATCH);
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
||||||
|
AddTextLine (";");
|
||||||
|
|
||||||
/* Insert some object file options */
|
/* Insert some object file options */
|
||||||
AddTextLine (".fopt\t\tcompiler,\"cc65 v %u.%u.%u\"",
|
AddTextLine ("\t.fopt\t\tcompiler,\"cc65 v %u.%u.%u\"",
|
||||||
VER_MAJOR, VER_MINOR, VER_PATCH);
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
||||||
|
|
||||||
/* If we're producing code for some other CPU, switch the command set */
|
/* If we're producing code for some other CPU, switch the command set */
|
||||||
if (CPU == CPU_65C02) {
|
if (CPU == CPU_65C02) {
|
||||||
AddTextLine (".pc02");
|
AddTextLine ("\t.pc02");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allow auto import for runtime library routines */
|
/* Allow auto import for runtime library routines */
|
||||||
AddTextLine (".autoimport\ton");
|
AddTextLine ("\t.autoimport\ton");
|
||||||
|
|
||||||
/* Switch the assembler into case sensitive mode */
|
/* Switch the assembler into case sensitive mode */
|
||||||
AddTextLine (".case\t\ton");
|
AddTextLine ("\t.case\t\ton");
|
||||||
|
|
||||||
/* Tell the assembler if we want to generate debug info */
|
/* Tell the assembler if we want to generate debug info */
|
||||||
AddTextLine (".debuginfo\t%s", (DebugInfo != 0)? "on" : "off");
|
AddTextLine ("\t.debuginfo\t%s", (DebugInfo != 0)? "on" : "off");
|
||||||
|
|
||||||
/* Import the stack pointer for direct auto variable access */
|
/* Import the stack pointer for direct auto variable access */
|
||||||
AddTextLine (".importzp\tsp, sreg, regsave, regbank, tmp1, ptr1");
|
AddTextLine ("\t.importzp\tsp, sreg, regsave, regbank, tmp1, ptr1");
|
||||||
|
|
||||||
/* Define long branch macros */
|
/* Define long branch macros */
|
||||||
AddTextLine (".macpack\tlongbranch");
|
AddTextLine ("\t.macpack\tlongbranch");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime)
|
||||||
|
/* If debug info is enabled, place a file info into the source */
|
||||||
|
{
|
||||||
|
if (DebugInfo) {
|
||||||
|
AddTextLine ("\t.dbg\t\tfile, \"%s\", %lu, %lu", Name, Size, MTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ extern int oursp;
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Pre- and postamble */
|
/* Files, pre- and postamble */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@ -95,6 +95,9 @@ extern int oursp;
|
|||||||
void g_preamble (void);
|
void g_preamble (void);
|
||||||
/* Generate the assembler code preamble */
|
/* Generate the assembler code preamble */
|
||||||
|
|
||||||
|
void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime);
|
||||||
|
/* If debug info is enabled, place a file info into the source */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -944,13 +944,23 @@ void OutputCodeSeg (const CodeSeg* S, FILE* F)
|
|||||||
/* Get the next entry */
|
/* Get the next entry */
|
||||||
const CodeEntry* E = CollConstAt (&S->Entries, I);
|
const CodeEntry* E = CollConstAt (&S->Entries, I);
|
||||||
/* Check if the line info has changed. If so, output the source line
|
/* Check if the line info has changed. If so, output the source line
|
||||||
* if the option is enabled.
|
* if the option is enabled and output debug line info if the debug
|
||||||
|
* option is enabled.
|
||||||
*/
|
*/
|
||||||
if (E->LI != LI) {
|
if (E->LI != LI) {
|
||||||
|
/* Line info has changed, remember the new line info */
|
||||||
LI = E->LI;
|
LI = E->LI;
|
||||||
|
|
||||||
|
/* Add the source line as a comment */
|
||||||
if (AddSource) {
|
if (AddSource) {
|
||||||
fprintf (F, ";\n; %s\n;\n", LI->Line);
|
fprintf (F, ";\n; %s\n;\n", LI->Line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add line debug info */
|
||||||
|
if (DebugInfo) {
|
||||||
|
fprintf (F, "\t.dbg\tline, \"%s\", %u\n",
|
||||||
|
GetInputName (LI), GetInputLine (LI));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Output the code */
|
/* Output the code */
|
||||||
OutputCodeEntry (E, F);
|
OutputCodeEntry (E, F);
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "incpath.h"
|
#include "incpath.h"
|
||||||
|
#include "input.h"
|
||||||
#include "litpool.h"
|
#include "litpool.h"
|
||||||
#include "macrotab.h"
|
#include "macrotab.h"
|
||||||
#include "pragma.h"
|
#include "pragma.h"
|
||||||
@ -250,7 +251,7 @@ static void Parse (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Compile (void)
|
void Compile (const char* FileName)
|
||||||
/* Top level compile routine. Will setup things and call the parser. */
|
/* Top level compile routine. Will setup things and call the parser. */
|
||||||
{
|
{
|
||||||
char* Path;
|
char* Path;
|
||||||
@ -300,6 +301,9 @@ void Compile (void)
|
|||||||
/* Generate the code generator preamble */
|
/* Generate the code generator preamble */
|
||||||
g_preamble ();
|
g_preamble ();
|
||||||
|
|
||||||
|
/* Open the input file */
|
||||||
|
OpenMainFile (FileName);
|
||||||
|
|
||||||
/* Ok, start the ball rolling... */
|
/* Ok, start the ball rolling... */
|
||||||
Parse ();
|
Parse ();
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Compile (void);
|
void Compile (const char* FileName);
|
||||||
/* Top level compile routine. Will setup things and call the parser. */
|
/* Top level compile routine. Will setup things and call the parser. */
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
@ -43,7 +45,8 @@
|
|||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmcode.h"
|
#include "asmcode.h"
|
||||||
|
#include "codegen.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "incpath.h"
|
#include "incpath.h"
|
||||||
#include "lineinfo.h"
|
#include "lineinfo.h"
|
||||||
@ -86,7 +89,53 @@ static Collection AFiles = STATIC_COLLECTION_INITIALIZER;
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* struct IFile */
|
/* Helper functions */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static long GetFileSize (FILE* F)
|
||||||
|
/* Calculate the size of the file F, return -1 on error. */
|
||||||
|
{
|
||||||
|
long Size;
|
||||||
|
long CurPos = ftell (F);
|
||||||
|
if (CurPos < 0) {
|
||||||
|
/* Error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fseek (F, 0, SEEK_END) != 0) {
|
||||||
|
/* Error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Size = ftell (F);
|
||||||
|
if (Size < 0) {
|
||||||
|
/* Error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fseek (F, CurPos, SEEK_SET) != 0) {
|
||||||
|
/* Error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static long GetFileTime (const char* Name)
|
||||||
|
/* Get the time of last modification for the given file. Return -1 on errors. */
|
||||||
|
{
|
||||||
|
struct stat Buf;
|
||||||
|
if (stat (Name, &Buf) != 0) {
|
||||||
|
/* Error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (long) Buf.st_mtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* struct IFile */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +152,8 @@ static IFile* NewIFile (const char* Name)
|
|||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
IF->Index = CollCount (&IFiles) + 1;
|
IF->Index = CollCount (&IFiles) + 1;
|
||||||
IF->Usage = 0;
|
IF->Usage = 0;
|
||||||
|
IF->Size = 0;
|
||||||
|
IF->MTime = 0;
|
||||||
memcpy (IF->Name, Name, Len+1);
|
memcpy (IF->Name, Name, Len+1);
|
||||||
|
|
||||||
/* Insert the new structure into the IFile collection */
|
/* Insert the new structure into the IFile collection */
|
||||||
@ -131,8 +182,31 @@ static AFile* NewAFile (IFile* IF, FILE* F)
|
|||||||
AF->F = F;
|
AF->F = F;
|
||||||
AF->Input = IF;
|
AF->Input = IF;
|
||||||
|
|
||||||
/* Increment the usage counter of the corresponding IFile */
|
/* Increment the usage counter of the corresponding IFile. If this
|
||||||
++IF->Usage;
|
* is the first use, set the file data and output debug info if
|
||||||
|
* requested.
|
||||||
|
*/
|
||||||
|
if (IF->Usage++ == 0) {
|
||||||
|
|
||||||
|
long Val;
|
||||||
|
|
||||||
|
/* Get the file size */
|
||||||
|
Val = GetFileSize (AF->F);
|
||||||
|
if (Val < 0) {
|
||||||
|
Fatal ("Cannot seek on `%s': %s", IF->Name, strerror (errno));
|
||||||
|
}
|
||||||
|
IF->Size = Val;
|
||||||
|
|
||||||
|
/* Get the file modification time */
|
||||||
|
Val = GetFileTime (IF->Name);
|
||||||
|
if (Val < 0) {
|
||||||
|
Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
|
||||||
|
}
|
||||||
|
IF->MTime = Val;
|
||||||
|
|
||||||
|
/* Set the debug data */
|
||||||
|
g_fileinfo (IF->Name, IF->Size, IF->MTime);
|
||||||
|
}
|
||||||
|
|
||||||
/* Insert the new structure into the AFile collection */
|
/* Insert the new structure into the AFile collection */
|
||||||
CollAppend (&AFiles, AF);
|
CollAppend (&AFiles, AF);
|
||||||
|
@ -63,9 +63,11 @@ extern char NextC;
|
|||||||
/* Struct that describes an input file */
|
/* Struct that describes an input file */
|
||||||
typedef struct IFile IFile;
|
typedef struct IFile IFile;
|
||||||
struct IFile {
|
struct IFile {
|
||||||
unsigned Index; /* File index */
|
unsigned Index; /* File index */
|
||||||
unsigned Usage; /* Usage counter */
|
unsigned Usage; /* Usage counter */
|
||||||
char Name[1]; /* Name of file (dynamically allocated) */
|
unsigned long Size; /* File size */
|
||||||
|
unsigned long MTime; /* Time of last modification */
|
||||||
|
char Name[1]; /* Name of file (dynamically allocated) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec);
|
|||||||
|
|
||||||
void ClearLine (void);
|
void ClearLine (void);
|
||||||
/* Clear the current input line */
|
/* Clear the current input line */
|
||||||
|
|
||||||
void InitLine (const char* Buf);
|
void InitLine (const char* Buf);
|
||||||
/* Initialize lptr from Buf and read CurC and NextC from the new input line */
|
/* Initialize lptr from Buf and read CurC and NextC from the new input line */
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "incpath.h"
|
#include "incpath.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "macrotab.h"
|
#include "macrotab.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "segments.h"
|
#include "segments.h"
|
||||||
@ -638,16 +638,13 @@ int main (int argc, char* argv[])
|
|||||||
AbEnd ("No input files");
|
AbEnd ("No input files");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the input file */
|
|
||||||
OpenMainFile (InputFile);
|
|
||||||
|
|
||||||
/* Create the output file name if it was not explicitly given */
|
/* Create the output file name if it was not explicitly given */
|
||||||
if (OutputFile == 0) {
|
if (OutputFile == 0) {
|
||||||
OutputFile = MakeFilename (InputFile, ".s");
|
OutputFile = MakeFilename (InputFile, ".s");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go! */
|
/* Go! */
|
||||||
Compile ();
|
Compile (InputFile);
|
||||||
|
|
||||||
/* Create the output file if we didn't had any errors */
|
/* Create the output file if we didn't had any errors */
|
||||||
if (ErrorCount == 0 || Debug) {
|
if (ErrorCount == 0 || Debug) {
|
||||||
|
Loading…
Reference in New Issue
Block a user