1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-15 06:27:36 +00:00

Added pseudo function .DEFINEDINSTR

This commit is contained in:
JT
2015-05-12 19:28:57 -04:00
parent 1748bb1ab6
commit 5ed3a1a6dc
8 changed files with 204 additions and 157 deletions

View File

@@ -62,6 +62,7 @@
#include "symtab.h"
#include "toklist.h"
#include "ulabel.h"
#include "macro.h"
@@ -417,6 +418,33 @@ static ExprNode* FuncDefined (void)
static ExprNode* FuncDefinedInstr (void)
/* Handle the .DEFINEDINSTR builtin function */
{
int Instr = 0;
/* Check for a macro or an instruction depending on UbiquitousIdents */
if (CurTok.Tok == TOK_IDENT) {
if (UbiquitousIdents) {
/* Macros CAN be instructions, so check for them first */
if (FindMacro(&CurTok.SVal) == 0) {
Instr = FindInstruction (&CurTok.SVal);
}
} else {
/* Macros and symbols may NOT use the names of instructions, so just check for the instruction */
Instr = FindInstruction(&CurTok.SVal);
}
NextTok();
} else {
Error("Idenitifier expected.");
}
return GenLiteralExpr(Instr > 0);
}
ExprNode* FuncHiByte (void)
/* Handle the .HIBYTE builtin function */
{
@@ -1065,6 +1093,10 @@ static ExprNode* Factor (void)
N = Function (FuncDefined);
break;
case TOK_DEFINEDINSTR:
N = Function (FuncDefinedInstr);
break;
case TOK_HIBYTE:
N = Function (FuncHiByte);
break;

View File

@@ -64,6 +64,7 @@ static const char* FeatureKeys[FEAT_COUNT] = {
"force_range",
"underline_in_numbers",
"addrsize",
"definedinstr",
};
@@ -121,6 +122,7 @@ feature_t SetFeature (const StrBuf* Key)
case FEAT_FORCE_RANGE: ForceRange = 1; break;
case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break;
case FEAT_ADDRSIZE: AddrSize = 1; break;
case FEAT_DEFINEDINSTR: DefinedInstr = 1; break;
default: /* Keep gcc silent */ break;
}

View File

@@ -66,6 +66,7 @@ typedef enum {
FEAT_FORCE_RANGE,
FEAT_UNDERLINE_IN_NUMBERS,
FEAT_ADDRSIZE,
FEAT_DEFINEDINSTR,
/* Special value: Number of features available */
FEAT_COUNT

View File

@@ -83,3 +83,4 @@ unsigned char CComments = 0; /* Allow C like comments */
unsigned char ForceRange = 0; /* Force values into expected range */
unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */
unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */
unsigned char DefinedInstr = 0; /* Allow .DEFINEDINSTR function */

View File

@@ -85,6 +85,7 @@ extern unsigned char CComments; /* Allow C like comments */
extern unsigned char ForceRange; /* Force values into expected range */
extern unsigned char UnderlineInNumbers; /* Allow underlines in numbers */
extern unsigned char AddrSize; /* Allow .ADDRSIZE function */
extern unsigned char DefinedInstr; /* Allow .DEFINEDINSTR function */

View File

@@ -1989,6 +1989,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoDebugInfo },
{ ccNone, DoDefine },
{ ccNone, DoUnexpected }, /* .DEFINED */
{ ccNone, DoUnexpected }, /* .DEFINEDINSTR */
{ ccNone, DoDelMac },
{ ccNone, DoDestructor },
{ ccNone, DoDWord },

View File

@@ -167,6 +167,7 @@ struct DotKeyword {
{ ".DEF", TOK_DEFINED },
{ ".DEFINE", TOK_DEFINE },
{ ".DEFINED", TOK_DEFINED },
{ ".DEFINEDINSTR", TOK_DEFINEDINSTR },
{ ".DELMAC", TOK_DELMAC },
{ ".DELMACRO", TOK_DELMAC },
{ ".DESTRUCTOR", TOK_DESTRUCTOR },
@@ -736,6 +737,13 @@ static token_t FindDotKeyword (void)
}
break;
case TOK_DEFINEDINSTR:
/* Disallow .DEFINEDINSTR function by default */
if (DefinedInstr == 0) {
return TOK_NONE;
}
break;
default:
break;
}

View File

@@ -148,6 +148,7 @@ typedef enum token_t {
TOK_DEBUGINFO,
TOK_DEFINE,
TOK_DEFINED,
TOK_DEFINEDINSTR,
TOK_DELMAC,
TOK_DESTRUCTOR,
TOK_DWORD,