Merge branch 'master' into c_sp
This commit is contained in:
@@ -394,6 +394,16 @@ void DoConditionals (void)
|
||||
CalcOverallIfCond ();
|
||||
break;
|
||||
|
||||
case TOK_IFP02X:
|
||||
D = AllocIf (".IFP02X", 1);
|
||||
NextTok ();
|
||||
if (IfCond) {
|
||||
SetIfCond (D, GetCPU() == CPU_6502X);
|
||||
}
|
||||
ExpectSep ();
|
||||
CalcOverallIfCond ();
|
||||
break;
|
||||
|
||||
case TOK_IFP4510:
|
||||
D = AllocIf (".IFP4510", 1);
|
||||
NextTok ();
|
||||
@@ -485,6 +495,7 @@ int CheckConditionals (void)
|
||||
case TOK_IFNDEF:
|
||||
case TOK_IFNREF:
|
||||
case TOK_IFP02:
|
||||
case TOK_IFP02X:
|
||||
case TOK_IFP4510:
|
||||
case TOK_IFP816:
|
||||
case TOK_IFPC02:
|
||||
|
||||
@@ -1562,6 +1562,14 @@ static void DoP02 (void)
|
||||
|
||||
|
||||
|
||||
static void DoP02X (void)
|
||||
/* Switch to 6502 CPU */
|
||||
{
|
||||
SetCPU (CPU_6502X);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void DoPC02 (void)
|
||||
/* Switch to 65C02 CPU */
|
||||
{
|
||||
@@ -2057,70 +2065,72 @@ struct CtrlDesc {
|
||||
void (*Handler) (void); /* Command handler */
|
||||
};
|
||||
|
||||
/* NOTE: .AND, .BITAND, .BITNOT, .BITOR, .BITXOR, .MOD, .NOT, .OR, .SHL, .SHR
|
||||
and .XOR do NOT go into this table */
|
||||
#define PSEUDO_COUNT (sizeof (CtrlCmdTab) / sizeof (CtrlCmdTab [0]))
|
||||
static CtrlDesc CtrlCmdTab [] = {
|
||||
{ ccNone, DoA16 },
|
||||
{ ccNone, DoA8 },
|
||||
{ ccNone, DoA16 }, /* .A16 */
|
||||
{ ccNone, DoA8 }, /* .A8 */
|
||||
{ ccNone, DoAddr }, /* .ADDR */
|
||||
{ ccNone, DoUnexpected }, /* .ADDRSIZE */
|
||||
{ ccNone, DoAlign },
|
||||
{ ccNone, DoASCIIZ },
|
||||
{ ccNone, DoAlign }, /* .ALIGN */
|
||||
{ ccNone, DoASCIIZ }, /* .ASCIIZ */
|
||||
{ ccNone, DoUnexpected }, /* .ASIZE */
|
||||
{ ccNone, DoAssert },
|
||||
{ ccNone, DoAutoImport },
|
||||
{ ccNone, DoAssert }, /* .ASSERT */
|
||||
{ ccNone, DoAutoImport }, /* .AUTOIMPORT */
|
||||
{ ccNone, DoUnexpected }, /* .BANK */
|
||||
{ ccNone, DoUnexpected }, /* .BANKBYTE */
|
||||
{ ccNone, DoBankBytes },
|
||||
{ ccNone, DoBankBytes }, /* .BANKBYTES */
|
||||
{ ccNone, DoUnexpected }, /* .BLANK */
|
||||
{ ccNone, DoBss },
|
||||
{ ccNone, DoByte },
|
||||
{ ccNone, DoCase },
|
||||
{ ccNone, DoCharMap },
|
||||
{ ccNone, DoCode },
|
||||
{ ccNone, DoBss }, /* .BSS */
|
||||
{ ccNone, DoByte }, /* .BYT, .BYTE */
|
||||
{ ccNone, DoCase }, /* .CASE */
|
||||
{ ccNone, DoCharMap }, /* .CHARMAP */
|
||||
{ ccNone, DoCode }, /* .CODE */
|
||||
{ ccNone, DoUnexpected, }, /* .CONCAT */
|
||||
{ ccNone, DoConDes },
|
||||
{ ccNone, DoConDes }, /* .CONDES */
|
||||
{ ccNone, DoUnexpected }, /* .CONST */
|
||||
{ ccNone, DoConstructor },
|
||||
{ ccNone, DoConstructor }, /* .CONSTRUCTOR */
|
||||
{ ccNone, DoUnexpected }, /* .CPU */
|
||||
{ ccNone, DoData },
|
||||
{ ccNone, DoDbg, },
|
||||
{ ccNone, DoDByt },
|
||||
{ ccNone, DoDebugInfo },
|
||||
{ ccKeepToken, DoDefine },
|
||||
{ ccNone, DoData }, /* .DATA */
|
||||
{ ccNone, DoDbg, }, /* .DBG */
|
||||
{ ccNone, DoDByt }, /* .DBYT */
|
||||
{ ccNone, DoDebugInfo }, /* .DEBUGINFO */
|
||||
{ ccKeepToken, DoDefine }, /* .DEF, .DEFINE */
|
||||
{ ccNone, DoUnexpected }, /* .DEFINED */
|
||||
{ ccNone, DoUnexpected }, /* .DEFINEDMACRO */
|
||||
{ ccNone, DoDelMac },
|
||||
{ ccNone, DoDestructor },
|
||||
{ ccNone, DoDWord },
|
||||
{ ccNone, DoDelMac }, /* .DELMAC, .DELMACRO */
|
||||
{ ccNone, DoDestructor }, /* .DESTRUCTOR */
|
||||
{ ccNone, DoDWord }, /* .DWORD */
|
||||
{ ccKeepToken, DoConditionals }, /* .ELSE */
|
||||
{ ccKeepToken, DoConditionals }, /* .ELSEIF */
|
||||
{ ccKeepToken, DoEnd },
|
||||
{ ccKeepToken, DoEnd }, /* .END */
|
||||
{ ccNone, DoUnexpected }, /* .ENDENUM */
|
||||
{ ccKeepToken, DoConditionals }, /* .ENDIF */
|
||||
{ ccNone, DoUnexpected }, /* .ENDMACRO */
|
||||
{ ccNone, DoEndProc },
|
||||
{ ccNone, DoUnexpected }, /* .ENDREPEAT */
|
||||
{ ccNone, DoEndScope },
|
||||
{ ccNone, DoUnexpected }, /* .ENDMAC, .ENDMACRO */
|
||||
{ ccNone, DoEndProc }, /* .ENDPROC */
|
||||
{ ccNone, DoUnexpected }, /* .ENDREP, .ENDREPEAT */
|
||||
{ ccNone, DoEndScope }, /* .ENDSCOPE */
|
||||
{ ccNone, DoUnexpected }, /* .ENDSTRUCT */
|
||||
{ ccNone, DoUnexpected }, /* .ENDUNION */
|
||||
{ ccNone, DoEnum },
|
||||
{ ccNone, DoError },
|
||||
{ ccNone, DoExitMacro },
|
||||
{ ccNone, DoExport },
|
||||
{ ccNone, DoExportZP },
|
||||
{ ccNone, DoFarAddr },
|
||||
{ ccNone, DoFatal },
|
||||
{ ccNone, DoFeature },
|
||||
{ ccNone, DoFileOpt },
|
||||
{ ccNone, DoForceImport },
|
||||
{ ccNone, DoEnum }, /* .ENUM */
|
||||
{ ccNone, DoError }, /* .ERROR */
|
||||
{ ccNone, DoExitMacro }, /* .EXITMAC, .EXITMACRO */
|
||||
{ ccNone, DoExport }, /* .EXPORT */
|
||||
{ ccNone, DoExportZP }, /* .EXPORTZP */
|
||||
{ ccNone, DoFarAddr }, /* .FARADDR */
|
||||
{ ccNone, DoFatal }, /* .FATAL */
|
||||
{ ccNone, DoFeature }, /* .FEATURE */
|
||||
{ ccNone, DoFileOpt }, /* .FOPT, .FILEOPT */
|
||||
{ ccNone, DoForceImport }, /* .FORCEIMPORT */
|
||||
{ ccNone, DoUnexpected }, /* .FORCEWORD */
|
||||
{ ccNone, DoGlobal },
|
||||
{ ccNone, DoGlobalZP },
|
||||
{ ccNone, DoGlobal }, /* .GLOBAL */
|
||||
{ ccNone, DoGlobalZP }, /* .GLOBALZP */
|
||||
{ ccNone, DoUnexpected }, /* .HIBYTE */
|
||||
{ ccNone, DoHiBytes },
|
||||
{ ccNone, DoHiBytes }, /* .HIBYTES */
|
||||
{ ccNone, DoUnexpected }, /* .HIWORD */
|
||||
{ ccNone, DoI16 },
|
||||
{ ccNone, DoI8 },
|
||||
{ ccNone, DoI16 }, /* .I16 */
|
||||
{ ccNone, DoI8 }, /* .I8 */
|
||||
{ ccNone, DoUnexpected }, /* .IDENT */
|
||||
{ ccKeepToken, DoConditionals }, /* .IF */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFBLANK */
|
||||
@@ -2131,81 +2141,83 @@ static CtrlDesc CtrlCmdTab [] = {
|
||||
{ ccKeepToken, DoConditionals }, /* .IFNDEF */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFNREF */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFP02 */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFP02X */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFP4510 */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFP816 */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFPC02 */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFPDTV */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFPSC02 */
|
||||
{ ccKeepToken, DoConditionals }, /* .IFREF */
|
||||
{ ccNone, DoImport },
|
||||
{ ccNone, DoImportZP },
|
||||
{ ccNone, DoIncBin },
|
||||
{ ccNone, DoInclude },
|
||||
{ ccNone, DoInterruptor },
|
||||
{ ccNone, DoImport }, /* .IMPORT */
|
||||
{ ccNone, DoImportZP }, /* .IMPORTZP */
|
||||
{ ccNone, DoIncBin }, /* .INCBIN */
|
||||
{ ccNone, DoInclude }, /* .INCLUDE */
|
||||
{ ccNone, DoInterruptor }, /* .INTERRUPTPOR */
|
||||
{ ccNone, DoUnexpected }, /* .ISIZE */
|
||||
{ ccNone, DoUnexpected }, /* .ISMNEMONIC */
|
||||
{ ccNone, DoInvalid }, /* .LEFT */
|
||||
{ ccNone, DoLineCont },
|
||||
{ ccNone, DoList },
|
||||
{ ccNone, DoListBytes },
|
||||
{ ccNone, DoLiteral },
|
||||
{ ccNone, DoLineCont }, /* .LINECONT */
|
||||
{ ccNone, DoList }, /* .LIST */
|
||||
{ ccNone, DoListBytes }, /* .LISTBYTES */
|
||||
{ ccNone, DoLiteral }, /* .LITERAL */
|
||||
{ ccNone, DoUnexpected }, /* .LOBYTE */
|
||||
{ ccNone, DoLoBytes },
|
||||
{ ccNone, DoLoBytes }, /* .LOBYTES */
|
||||
{ ccNone, DoUnexpected }, /* .LOCAL */
|
||||
{ ccNone, DoLocalChar },
|
||||
{ ccNone, DoLocalChar }, /* .LOCALCHAR */
|
||||
{ ccNone, DoUnexpected }, /* .LOWORD */
|
||||
{ ccNone, DoMacPack },
|
||||
{ ccNone, DoMacro },
|
||||
{ ccNone, DoMacPack }, /* .MACPACK */
|
||||
{ ccNone, DoMacro }, /* .MAC, .MACRO */
|
||||
{ ccNone, DoUnexpected }, /* .MATCH */
|
||||
{ ccNone, DoUnexpected }, /* .MAX */
|
||||
{ ccNone, DoInvalid }, /* .MID */
|
||||
{ ccNone, DoUnexpected }, /* .MIN */
|
||||
{ ccNone, DoNull },
|
||||
{ ccNone, DoOrg },
|
||||
{ ccNone, DoOut },
|
||||
{ ccNone, DoP02 },
|
||||
{ ccNone, DoP4510 },
|
||||
{ ccNone, DoP816 },
|
||||
{ ccNone, DoPageLength },
|
||||
{ ccNone, DoNull }, /* .NULL */
|
||||
{ ccNone, DoOrg }, /* .ORG */
|
||||
{ ccNone, DoOut }, /* .OUT */
|
||||
{ ccNone, DoP02 }, /* .P02 */
|
||||
{ ccNone, DoP02X }, /* .P02X */
|
||||
{ ccNone, DoP4510 }, /* .P4510 */
|
||||
{ ccNone, DoP816 }, /* .P816 */
|
||||
{ ccNone, DoPageLength }, /* .PAGELEN, .PAGELENGTH */
|
||||
{ ccNone, DoUnexpected }, /* .PARAMCOUNT */
|
||||
{ ccNone, DoPC02 },
|
||||
{ ccNone, DoPDTV },
|
||||
{ ccNone, DoPopCharmap },
|
||||
{ ccNone, DoPopCPU },
|
||||
{ ccNone, DoPopSeg },
|
||||
{ ccNone, DoProc },
|
||||
{ ccNone, DoPSC02 },
|
||||
{ ccNone, DoPushCharmap },
|
||||
{ ccNone, DoPushCPU },
|
||||
{ ccNone, DoPushSeg },
|
||||
{ ccNone, DoUnexpected }, /* .REFERENCED */
|
||||
{ ccNone, DoReferTo }, /* .REFERTO */
|
||||
{ ccNone, DoReloc },
|
||||
{ ccNone, DoRepeat },
|
||||
{ ccNone, DoRes },
|
||||
{ ccNone, DoPC02 }, /* .PSC02 */
|
||||
{ ccNone, DoPDTV }, /* .PDTV */
|
||||
{ ccNone, DoPopCharmap }, /* .POPCHARMAP */
|
||||
{ ccNone, DoPopCPU }, /* .POPCPU */
|
||||
{ ccNone, DoPopSeg }, /* .POPSEG */
|
||||
{ ccNone, DoProc }, /* .PROC */
|
||||
{ ccNone, DoPSC02 }, /* .PSC02 */
|
||||
{ ccNone, DoPushCharmap }, /* .PUSHCHARMAP */
|
||||
{ ccNone, DoPushCPU }, /* .PUSHCPU */
|
||||
{ ccNone, DoPushSeg }, /* .PUSHSEG */
|
||||
{ ccNone, DoUnexpected }, /* .REF, .REFERENCED */
|
||||
{ ccNone, DoReferTo }, /* .REFTO, .REFERTO */
|
||||
{ ccNone, DoReloc }, /* .RELOC */
|
||||
{ ccNone, DoRepeat }, /* .REPEAT */
|
||||
{ ccNone, DoRes }, /* .RES */
|
||||
{ ccNone, DoInvalid }, /* .RIGHT */
|
||||
{ ccNone, DoROData },
|
||||
{ ccNone, DoScope },
|
||||
{ ccNone, DoSegment },
|
||||
{ ccNone, DoROData }, /* .RODATA */
|
||||
{ ccNone, DoScope }, /* .SCOPE */
|
||||
{ ccNone, DoSegment }, /* .SEGMENT */
|
||||
{ ccNone, DoUnexpected }, /* .SET */
|
||||
{ ccNone, DoSetCPU },
|
||||
{ ccNone, DoSetCPU }, /* .SETCPU */
|
||||
{ ccNone, DoUnexpected }, /* .SIZEOF */
|
||||
{ ccNone, DoSmart },
|
||||
{ ccNone, DoSmart }, /* .SMART */
|
||||
{ ccNone, DoUnexpected }, /* .SPRINTF */
|
||||
{ ccNone, DoUnexpected }, /* .STRAT */
|
||||
{ ccNone, DoUnexpected }, /* .STRING */
|
||||
{ ccNone, DoUnexpected }, /* .STRLEN */
|
||||
{ ccNone, DoStruct },
|
||||
{ ccNone, DoTag },
|
||||
{ ccNone, DoStruct }, /* .STRUCT */
|
||||
{ ccNone, DoTag }, /* .TAG */
|
||||
{ ccNone, DoUnexpected }, /* .TCOUNT */
|
||||
{ ccNone, DoUnexpected }, /* .TIME */
|
||||
{ ccKeepToken, DoUnDef },
|
||||
{ ccNone, DoUnion },
|
||||
{ ccKeepToken, DoUnDef }, /* .UNDEF, .UNDEFINE */
|
||||
{ ccNone, DoUnion }, /* .UNION */
|
||||
{ ccNone, DoUnexpected }, /* .VERSION */
|
||||
{ ccNone, DoWarning },
|
||||
{ ccNone, DoWord },
|
||||
{ ccNone, DoWarning }, /* .WARNING */
|
||||
{ ccNone, DoWord }, /* .WORD */
|
||||
{ ccNone, DoUnexpected }, /* .XMATCH */
|
||||
{ ccNone, DoZeropage },
|
||||
{ ccNone, DoZeropage }, /* .ZEROPAGE */
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -221,6 +221,7 @@ struct DotKeyword {
|
||||
{ ".IFNDEF", TOK_IFNDEF },
|
||||
{ ".IFNREF", TOK_IFNREF },
|
||||
{ ".IFP02", TOK_IFP02 },
|
||||
{ ".IFP02X", TOK_IFP02X },
|
||||
{ ".IFP4510", TOK_IFP4510 },
|
||||
{ ".IFP816", TOK_IFP816 },
|
||||
{ ".IFPC02", TOK_IFPC02 },
|
||||
@@ -259,6 +260,7 @@ struct DotKeyword {
|
||||
{ ".ORG", TOK_ORG },
|
||||
{ ".OUT", TOK_OUT },
|
||||
{ ".P02", TOK_P02 },
|
||||
{ ".P02X", TOK_P02X },
|
||||
{ ".P4510", TOK_P4510 },
|
||||
{ ".P816", TOK_P816 },
|
||||
{ ".PAGELEN", TOK_PAGELENGTH },
|
||||
|
||||
@@ -193,6 +193,7 @@ typedef enum token_t {
|
||||
TOK_IFNDEF,
|
||||
TOK_IFNREF,
|
||||
TOK_IFP02,
|
||||
TOK_IFP02X,
|
||||
TOK_IFP4510,
|
||||
TOK_IFP816,
|
||||
TOK_IFPC02,
|
||||
@@ -226,6 +227,7 @@ typedef enum token_t {
|
||||
TOK_ORG,
|
||||
TOK_OUT,
|
||||
TOK_P02,
|
||||
TOK_P02X,
|
||||
TOK_P4510,
|
||||
TOK_P816,
|
||||
TOK_PAGELENGTH,
|
||||
|
||||
@@ -496,6 +496,14 @@ void Compile (const char* FileName)
|
||||
while (PreprocessNextLine ())
|
||||
{ /* Nothing */ }
|
||||
|
||||
/* Output macros if requested by the user */
|
||||
if (DumpPredefMacros) {
|
||||
OutputPredefMacros ();
|
||||
}
|
||||
if (DumpUserMacros) {
|
||||
OutputUserMacros ();
|
||||
}
|
||||
|
||||
/* Close the output file */
|
||||
CloseOutputFile ();
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "debugflag.h"
|
||||
#include "print.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
@@ -183,11 +184,15 @@ static unsigned GetDiagnosticLineNum (void)
|
||||
|
||||
|
||||
|
||||
void Fatal (const char* Format, ...)
|
||||
void Fatal_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a message about a fatal error and die */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
fprintf (stderr, "%s:%u: Fatal: ", GetDiagnosticFileName (), GetDiagnosticLineNum ());
|
||||
|
||||
va_start (ap, Format);
|
||||
@@ -203,11 +208,15 @@ void Fatal (const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void Internal (const char* Format, ...)
|
||||
void Internal_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a message about an internal compiler error and die */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
fprintf (stderr, "%s:%u: Internal compiler error:\n",
|
||||
GetDiagnosticFileName (), GetDiagnosticLineNum ());
|
||||
|
||||
@@ -270,10 +279,15 @@ static void IntError (errcat_t EC, LineInfo* LI, const char* Msg, va_list ap)
|
||||
|
||||
|
||||
|
||||
void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
void LIError_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
/* Print an error message with the line info given explicitly */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntError (EC, LI, Format, ap);
|
||||
va_end (ap);
|
||||
@@ -281,10 +295,15 @@ void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void Error (const char* Format, ...)
|
||||
void Error_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print an error message */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntError (EC_PARSER, GetDiagnosticLI (), Format, ap);
|
||||
va_end (ap);
|
||||
@@ -292,10 +311,15 @@ void Error (const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void PPError (const char* Format, ...)
|
||||
void PPError_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print an error message. For use within the preprocessor */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntError (EC_PP, GetCurLineInfo (), Format, ap);
|
||||
va_end (ap);
|
||||
@@ -346,10 +370,15 @@ static void IntWarning (errcat_t EC, LineInfo* LI, const char* Msg, va_list ap)
|
||||
|
||||
|
||||
|
||||
void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
void LIWarning_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
/* Print a warning message with the line info given explicitly */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntWarning (EC, LI, Format, ap);
|
||||
va_end (ap);
|
||||
@@ -357,10 +386,15 @@ void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void Warning (const char* Format, ...)
|
||||
void Warning_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a warning message */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntWarning (EC_PARSER, GetDiagnosticLI (), Format, ap);
|
||||
va_end (ap);
|
||||
@@ -368,10 +402,15 @@ void Warning (const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void PPWarning (const char* Format, ...)
|
||||
void PPWarning_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a warning message. For use within the preprocessor */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntWarning (EC_PP, GetCurLineInfo (), Format, ap);
|
||||
va_end (ap);
|
||||
@@ -436,10 +475,15 @@ static void IntNote (const LineInfo* LI, const char* Msg, va_list ap)
|
||||
|
||||
|
||||
|
||||
void LINote (const LineInfo* LI, const char* Format, ...)
|
||||
void LINote_ (const char *file, int line, const LineInfo* LI, const char* Format, ...)
|
||||
/* Print a note message with the line info given explicitly */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntNote (LI, Format, ap);
|
||||
va_end (ap);
|
||||
@@ -447,10 +491,15 @@ void LINote (const LineInfo* LI, const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void Note (const char* Format, ...)
|
||||
void Note_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a note message */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntNote (GetDiagnosticLI (), Format, ap);
|
||||
va_end (ap);
|
||||
@@ -458,10 +507,15 @@ void Note (const char* Format, ...)
|
||||
|
||||
|
||||
|
||||
void PPNote (const char* Format, ...)
|
||||
void PPNote_ (const char *file, int line, const char* Format, ...)
|
||||
/* Print a note message. For use within the preprocessor */
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (Debug) {
|
||||
fprintf(stderr, "[%s:%d] ", file, line);
|
||||
}
|
||||
|
||||
va_start (ap, Format);
|
||||
IntNote (GetDiagnosticLI (), Format, ap);
|
||||
va_end (ap);
|
||||
|
||||
@@ -103,28 +103,36 @@ struct StrBuf;
|
||||
void PrintFileInclusionInfo (const LineInfo* LI);
|
||||
/* Print hierarchy of file inclusion */
|
||||
|
||||
void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
|
||||
void Fatal_ (const char *file, int line, const char* Format, ...) attribute ((noreturn, format (printf, 3, 4)));
|
||||
#define Fatal(...) Fatal_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a message about a fatal error and die */
|
||||
|
||||
void Internal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2)));
|
||||
void Internal_ (const char *file, int line, const char* Format, ...) attribute ((noreturn, format (printf, 3, 4)));
|
||||
#define Internal(...) Internal_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a message about an internal compiler error and die */
|
||||
|
||||
void Error (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void Error_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define Error(...) Error_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print an error message */
|
||||
|
||||
void LIError (errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
void LIError_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 5, 6)));
|
||||
#define LIError(...) LIError_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print an error message with the line info given explicitly */
|
||||
|
||||
void PPError (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void PPError_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define PPError(...) PPError_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print an error message. For use within the preprocessor */
|
||||
|
||||
void Warning (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void Warning_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define Warning(...) Warning_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a warning message */
|
||||
|
||||
void LIWarning (errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
void LIWarning_ (const char *file, int line, errcat_t EC, LineInfo* LI, const char* Format, ...) attribute ((format (printf, 5, 6)));
|
||||
#define LIWarning(...) LIWarning_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a warning message with the line info given explicitly */
|
||||
|
||||
void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void PPWarning_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define PPWarning(...) PPWarning_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a warning message. For use within the preprocessor */
|
||||
|
||||
void UnreachableCodeWarning (void);
|
||||
@@ -140,13 +148,16 @@ IntStack* FindWarning (const char* Name);
|
||||
void ListWarnings (FILE* F);
|
||||
/* Print a list of warning types/names to the given file */
|
||||
|
||||
void Note (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void Note_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define Note(...) Note_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a note message */
|
||||
|
||||
void LINote (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3)));
|
||||
void LINote_ (const char *file, int line, const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 4, 5)));
|
||||
#define LINote(...) LINote_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a note message with the line info given explicitly */
|
||||
|
||||
void PPNote (const char* Format, ...) attribute ((format (printf, 1, 2)));
|
||||
void PPNote_ (const char *file, int line, const char* Format, ...) attribute ((format (printf, 3, 4)));
|
||||
#define PPNote(...) PPNote_(__FILE__, __LINE__, __VA_ARGS__)
|
||||
/* Print a note message. For use within the preprocessor */
|
||||
|
||||
unsigned GetTotalErrors (void);
|
||||
|
||||
@@ -44,12 +44,14 @@
|
||||
|
||||
|
||||
unsigned char AddSource = 0; /* Add source lines as comments */
|
||||
unsigned char AllowNewComments = 0; /* Allow new style comments in C89 mode */
|
||||
unsigned char AutoCDecl = 0; /* Make functions default to __cdecl__ */
|
||||
unsigned char DebugInfo = 0; /* Add debug info to the obj */
|
||||
unsigned char DumpPredefMacros = 0; /* Output predefined macros */
|
||||
unsigned char DumpUserMacros = 0; /* Output user macros */
|
||||
unsigned char PreprocessOnly = 0; /* Just preprocess the input */
|
||||
unsigned char DebugOptOutput = 0; /* Output debug stuff */
|
||||
unsigned RegisterSpace = 6; /* Space available for register vars */
|
||||
unsigned AllowNewComments = 0; /* Allow new style comments in C89 mode */
|
||||
|
||||
/* Stackable options */
|
||||
IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */
|
||||
|
||||
@@ -52,12 +52,14 @@
|
||||
|
||||
/* Options */
|
||||
extern unsigned char AddSource; /* Add source lines as comments */
|
||||
extern unsigned char AllowNewComments; /* Allow new style comments in C89 mode */
|
||||
extern unsigned char AutoCDecl; /* Make functions default to __cdecl__ */
|
||||
extern unsigned char DebugInfo; /* Add debug info to the obj */
|
||||
extern unsigned char DumpPredefMacros; /* Output predefined macros */
|
||||
extern unsigned char DumpUserMacros; /* Output user macros */
|
||||
extern unsigned char PreprocessOnly; /* Just preprocess the input */
|
||||
extern unsigned char DebugOptOutput; /* Output debug stuff */
|
||||
extern unsigned RegisterSpace; /* Space available for register vars */
|
||||
extern unsigned AllowNewComments; /* Allow new style comments in C89 mode */
|
||||
|
||||
/* Stackable options */
|
||||
extern IntStack WritableStrings; /* Literal strings are r/w */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************/
|
||||
|
||||
/* */
|
||||
/* macrotab.h */
|
||||
/* */
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
/* cc65 */
|
||||
#include "error.h"
|
||||
#include "output.h"
|
||||
#include "preproc.h"
|
||||
#include "macrotab.h"
|
||||
|
||||
@@ -60,6 +61,70 @@ static Macro* MacroTab[MACRO_TAB_SIZE];
|
||||
/* The undefined macros list head */
|
||||
static Macro* UndefinedMacrosListHead;
|
||||
|
||||
/* Some defines for better readability when calling OutputMacros() */
|
||||
#define USER_MACROS 0
|
||||
#define PREDEF_MACROS 1
|
||||
#define NAME_ONLY 0
|
||||
#define FULL_DEFINITION 1
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* helpers */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
static void OutputMacro (const Macro* M, int Full)
|
||||
/* Output one macro. If Full is true, the replacement is also output. */
|
||||
{
|
||||
WriteOutput ("#define %s", M->Name);
|
||||
int ParamCount = M->ParamCount;
|
||||
if (M->ParamCount >= 0) {
|
||||
int I;
|
||||
if (M->Variadic) {
|
||||
CHECK (ParamCount > 0);
|
||||
--ParamCount;
|
||||
}
|
||||
WriteOutput ("(");
|
||||
for (I = 0; I < ParamCount; ++I) {
|
||||
const char* Name = CollConstAt (&M->Params, I);
|
||||
WriteOutput ("%s%s", (I == 0)? "" : ",", Name);
|
||||
}
|
||||
if (M->Variadic) {
|
||||
WriteOutput ("%s...", (ParamCount == 0)? "" : ",");
|
||||
}
|
||||
WriteOutput (")");
|
||||
}
|
||||
WriteOutput (" ");
|
||||
if (Full) {
|
||||
WriteOutput ("%.*s",
|
||||
SB_GetLen (&M->Replacement),
|
||||
SB_GetConstBuf (&M->Replacement));
|
||||
}
|
||||
WriteOutput ("\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OutputMacros (int Predefined, int Full)
|
||||
/* Output macros to the output file depending on the flags given. */
|
||||
{
|
||||
/* Note: The Full flag is currently not used by any callers but is left in
|
||||
** place for possible future changes.
|
||||
*/
|
||||
unsigned I;
|
||||
for (I = 0; I < MACRO_TAB_SIZE; ++I) {
|
||||
const Macro* M = MacroTab [I];
|
||||
while (M) {
|
||||
if ((Predefined != 0) == (M->Predefined != 0)) {
|
||||
OutputMacro (M, Full);
|
||||
}
|
||||
M = M->Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -68,7 +133,7 @@ static Macro* UndefinedMacrosListHead;
|
||||
|
||||
|
||||
|
||||
Macro* NewMacro (const char* Name)
|
||||
Macro* NewMacro (const char* Name, unsigned char Predefined)
|
||||
/* Allocate a macro structure with the given name. The structure is not
|
||||
** inserted into the macro table.
|
||||
*/
|
||||
@@ -84,6 +149,7 @@ Macro* NewMacro (const char* Name)
|
||||
M->ParamCount = -1; /* Flag: Not a function-like macro */
|
||||
InitCollection (&M->Params);
|
||||
SB_Init (&M->Replacement);
|
||||
M->Predefined = Predefined;
|
||||
M->Variadic = 0;
|
||||
memcpy (M->Name, Name, Len+1);
|
||||
|
||||
@@ -116,7 +182,7 @@ Macro* CloneMacro (const Macro* M)
|
||||
** Use FreeMacro for that.
|
||||
*/
|
||||
{
|
||||
Macro* New = NewMacro (M->Name);
|
||||
Macro* New = NewMacro (M->Name, M->Predefined);
|
||||
unsigned I;
|
||||
|
||||
for (I = 0; I < CollCount (&M->Params); ++I) {
|
||||
@@ -134,7 +200,7 @@ Macro* CloneMacro (const Macro* M)
|
||||
|
||||
|
||||
void DefineNumericMacro (const char* Name, long Val)
|
||||
/* Define a macro for a numeric constant */
|
||||
/* Define a predefined macro for a numeric constant */
|
||||
{
|
||||
char Buf[64];
|
||||
|
||||
@@ -148,10 +214,10 @@ void DefineNumericMacro (const char* Name, long Val)
|
||||
|
||||
|
||||
void DefineTextMacro (const char* Name, const char* Val)
|
||||
/* Define a macro for a textual constant */
|
||||
/* Define a predefined macro for a textual constant */
|
||||
{
|
||||
/* Create a new macro */
|
||||
Macro* M = NewMacro (Name);
|
||||
Macro* M = NewMacro (Name, 1);
|
||||
|
||||
/* Set the value as replacement text */
|
||||
SB_CopyStr (&M->Replacement, Val);
|
||||
@@ -350,3 +416,19 @@ void PrintMacroStats (FILE* F)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OutputPredefMacros (void)
|
||||
/* Output all predefined macros to the output file */
|
||||
{
|
||||
OutputMacros (PREDEF_MACROS, FULL_DEFINITION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OutputUserMacros (void)
|
||||
/* Output all user defined macros to the output file */
|
||||
{
|
||||
OutputMacros (USER_MACROS, FULL_DEFINITION);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ struct Macro {
|
||||
int ParamCount; /* Number of parameters, -1 = no parens */
|
||||
Collection Params; /* Parameter list (char*) */
|
||||
StrBuf Replacement; /* Replacement text */
|
||||
unsigned char Predefined; /* True if this is a predefined macro */
|
||||
unsigned char Variadic; /* C99 variadic macro */
|
||||
char Name[1]; /* Name, dynamically allocated */
|
||||
};
|
||||
@@ -70,7 +71,7 @@ struct Macro {
|
||||
|
||||
|
||||
|
||||
Macro* NewMacro (const char* Name);
|
||||
Macro* NewMacro (const char* Name, unsigned char Predefined);
|
||||
/* Allocate a macro structure with the given name. The structure is not
|
||||
** inserted into the macro table.
|
||||
*/
|
||||
@@ -87,10 +88,10 @@ Macro* CloneMacro (const Macro* M);
|
||||
*/
|
||||
|
||||
void DefineNumericMacro (const char* Name, long Val);
|
||||
/* Define a macro for a numeric constant */
|
||||
/* Define a predefined macro for a numeric constant */
|
||||
|
||||
void DefineTextMacro (const char* Name, const char* Val);
|
||||
/* Define a macro for a textual constant */
|
||||
/* Define a predefined macro for a textual constant */
|
||||
|
||||
void InsertMacro (Macro* M);
|
||||
/* Insert the given macro into the macro table. */
|
||||
@@ -132,6 +133,12 @@ int MacroCmp (const Macro* M1, const Macro* M2);
|
||||
void PrintMacroStats (FILE* F);
|
||||
/* Print macro statistics to the given text file. */
|
||||
|
||||
void OutputPredefMacros (void);
|
||||
/* Output all predefined macros to the output file */
|
||||
|
||||
void OutputUserMacros (void);
|
||||
/* Output all user defined macros to the output file */
|
||||
|
||||
|
||||
|
||||
/* End of macrotab.h */
|
||||
|
||||
@@ -93,6 +93,8 @@ static void Usage (void)
|
||||
" -V\t\t\t\tPrint the compiler version number\n"
|
||||
" -W [-+]warning[,...]\t\tControl warnings ('-' disables, '+' enables)\n"
|
||||
" -d\t\t\t\tDebug mode\n"
|
||||
" -dM\t\t\t\tOutput all user macros (needs -E)\n"
|
||||
" -dP\t\t\t\tOutput all predefined macros (needs -E)\n"
|
||||
" -g\t\t\t\tAdd debug info to object file\n"
|
||||
" -h\t\t\t\tHelp (this text)\n"
|
||||
" -j\t\t\t\tDefault characters are signed\n"
|
||||
@@ -1026,7 +1028,25 @@ int main (int argc, char* argv[])
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
OptDebug (Arg, 0);
|
||||
P = Arg + 2;
|
||||
if (*P == '\0') {
|
||||
OptDebug (Arg, 0);
|
||||
} else {
|
||||
while (*P) {
|
||||
switch (*P) {
|
||||
case 'M':
|
||||
DumpUserMacros = 1;
|
||||
break;
|
||||
case 'P':
|
||||
DumpPredefMacros = 1;
|
||||
break;
|
||||
default:
|
||||
UnknownOption (Arg);
|
||||
break;
|
||||
}
|
||||
++P;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
@@ -1138,6 +1158,11 @@ int main (int argc, char* argv[])
|
||||
AbEnd ("No input files");
|
||||
}
|
||||
|
||||
/* The options to output macros can only be used with -E */
|
||||
if ((DumpPredefMacros || DumpUserMacros) && !PreprocessOnly) {
|
||||
AbEnd ("Preprocessor macro output can only be used together with -E");
|
||||
}
|
||||
|
||||
/* Add the default include search paths. */
|
||||
FinishIncludePaths ();
|
||||
|
||||
|
||||
@@ -2575,7 +2575,7 @@ static void DoDefine (void)
|
||||
CheckForBadIdent (Ident, Std, 0);
|
||||
|
||||
/* Create a new macro definition */
|
||||
M = NewMacro (Ident);
|
||||
M = NewMacro (Ident, 0);
|
||||
|
||||
/* Check if this is a function-like macro */
|
||||
if (CurC == '(') {
|
||||
|
||||
@@ -169,7 +169,7 @@ char* MakeTmpFilename (const char *Directory, const char *Origin, const char* Ex
|
||||
Len += strlen (Origin) + (strlen (".2147483648") * 2) + strlen (Ext) + 1;
|
||||
Out = xmalloc (Len);
|
||||
|
||||
snprintf (Out, Len, "%s%s.%u%u%s", (Directory != NULL ? Directory : ""),
|
||||
snprintf (Out, Len, "%s%s.%u.%u%s", (Directory != NULL ? Directory : ""),
|
||||
FindName(Origin), getpid(), Counter, Ext);
|
||||
Counter++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user