Merge pull request #158 from Movax12/definedmacro
Added .DEFINEDMACRO psuedo function
This commit is contained in:
@@ -2316,21 +2316,25 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
|
|
||||||
<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p>
|
<sect1><tt>.DEFINEDMACRO</tt><label id=".DEFINEDMACRO"><p>
|
||||||
|
|
||||||
Builtin function. The function expects an identifier as argument in braces.
|
Builtin function. The function expects an identifier as argument in braces.
|
||||||
The argument is evaluated, and the function yields "true" if the identifier
|
The argument is evaluated, and the function yields "true" if the identifier
|
||||||
is defined as an instruction mnemonic that is recognized by the assembler.
|
has already been defined as the name of a macro. Otherwise the function yields
|
||||||
Example:
|
false. Example:
|
||||||
|
|
||||||
<tscreen><verb>
|
<tscreen><verb>
|
||||||
.if .not .ismnemonic(ina)
|
.macro add foo
|
||||||
.macro ina
|
clc
|
||||||
|
adc foo
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.if .definedmacro(add)
|
||||||
|
add #$01
|
||||||
|
.else
|
||||||
clc
|
clc
|
||||||
adc #$01
|
adc #$01
|
||||||
.endmacro
|
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
</verb></tscreen>
|
</verb></tscreen>
|
||||||
|
|
||||||
|
|
||||||
@@ -3158,6 +3162,23 @@ Here's a list of all control commands and a description, what they do:
|
|||||||
the feature in more detail.
|
the feature in more detail.
|
||||||
|
|
||||||
|
|
||||||
|
<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p>
|
||||||
|
|
||||||
|
Builtin function. The function expects an identifier as argument in braces.
|
||||||
|
The argument is evaluated, and the function yields "true" if the identifier
|
||||||
|
is defined as an instruction mnemonic that is recognized by the assembler.
|
||||||
|
Example:
|
||||||
|
|
||||||
|
<tscreen><verb>
|
||||||
|
.if .not .ismnemonic(ina)
|
||||||
|
.macro ina
|
||||||
|
clc
|
||||||
|
adc #$01
|
||||||
|
.endmacro
|
||||||
|
.endif
|
||||||
|
</verb></tscreen>
|
||||||
|
|
||||||
|
|
||||||
<sect1><tt>.LINECONT</tt><label id=".LINECONT"><p>
|
<sect1><tt>.LINECONT</tt><label id=".LINECONT"><p>
|
||||||
|
|
||||||
Switch on or off line continuations using the backslash character
|
Switch on or off line continuations using the backslash character
|
||||||
|
|||||||
@@ -418,30 +418,22 @@ static ExprNode* FuncDefined (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static ExprNode* FuncIsMnemonic (void)
|
static ExprNode* FuncDefinedMacro (void)
|
||||||
/* Handle the .ISMNEMONIC, .ISMNEM builtin function */
|
/* Handle the .DEFINEDMACRO builtin function */
|
||||||
{
|
{
|
||||||
int Instr = -1;
|
Macro* Mac = 0;
|
||||||
|
|
||||||
/* Check for a macro or an instruction depending on UbiquitousIdents */
|
/* Check if the identifier is a macro */
|
||||||
|
|
||||||
if (CurTok.Tok == TOK_IDENT) {
|
if (CurTok.Tok == TOK_IDENT) {
|
||||||
if (UbiquitousIdents) {
|
Mac = FindMacro (&CurTok.SVal);
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Error ("Identifier expected.");
|
Error ("Identifier expected.");
|
||||||
}
|
}
|
||||||
/* Skip the name */
|
/* Skip the name */
|
||||||
NextTok ();
|
NextTok ();
|
||||||
|
|
||||||
return GenLiteralExpr (Instr > 0);
|
return GenLiteralExpr (Mac != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -462,6 +454,36 @@ static ExprNode* FuncHiWord (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static ExprNode* FuncIsMnemonic (void)
|
||||||
|
/* Handle the .ISMNEMONIC, .ISMNEM builtin function */
|
||||||
|
{
|
||||||
|
int Instr = -1;
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Error ("Identifier expected.");
|
||||||
|
}
|
||||||
|
/* Skip the name */
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
|
return GenLiteralExpr (Instr > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ExprNode* FuncLoByte (void)
|
ExprNode* FuncLoByte (void)
|
||||||
/* Handle the .LOBYTE builtin function */
|
/* Handle the .LOBYTE builtin function */
|
||||||
{
|
{
|
||||||
@@ -1094,8 +1116,8 @@ static ExprNode* Factor (void)
|
|||||||
N = Function (FuncDefined);
|
N = Function (FuncDefined);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_ISMNEMONIC:
|
case TOK_DEFINEDMACRO:
|
||||||
N = Function (FuncIsMnemonic);
|
N = Function (FuncDefinedMacro);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_HIBYTE:
|
case TOK_HIBYTE:
|
||||||
@@ -1106,6 +1128,10 @@ static ExprNode* Factor (void)
|
|||||||
N = Function (FuncHiWord);
|
N = Function (FuncHiWord);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_ISMNEMONIC:
|
||||||
|
N = Function (FuncIsMnemonic);
|
||||||
|
break;
|
||||||
|
|
||||||
case TOK_LOBYTE:
|
case TOK_LOBYTE:
|
||||||
N = Function (FuncLoByte);
|
N = Function (FuncLoByte);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -83,3 +83,4 @@ unsigned char CComments = 0; /* Allow C like comments */
|
|||||||
unsigned char ForceRange = 0; /* Force values into expected range */
|
unsigned char ForceRange = 0; /* Force values into expected range */
|
||||||
unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */
|
unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */
|
||||||
unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */
|
unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */
|
||||||
|
|
||||||
|
|||||||
@@ -1989,6 +1989,7 @@ static CtrlDesc CtrlCmdTab [] = {
|
|||||||
{ ccNone, DoDebugInfo },
|
{ ccNone, DoDebugInfo },
|
||||||
{ ccNone, DoDefine },
|
{ ccNone, DoDefine },
|
||||||
{ ccNone, DoUnexpected }, /* .DEFINED */
|
{ ccNone, DoUnexpected }, /* .DEFINED */
|
||||||
|
{ ccNone, DoUnexpected }, /* .DEFINEDMACRO */
|
||||||
{ ccNone, DoDelMac },
|
{ ccNone, DoDelMac },
|
||||||
{ ccNone, DoDestructor },
|
{ ccNone, DoDestructor },
|
||||||
{ ccNone, DoDWord },
|
{ ccNone, DoDWord },
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ struct DotKeyword {
|
|||||||
{ ".DEF", TOK_DEFINED },
|
{ ".DEF", TOK_DEFINED },
|
||||||
{ ".DEFINE", TOK_DEFINE },
|
{ ".DEFINE", TOK_DEFINE },
|
||||||
{ ".DEFINED", TOK_DEFINED },
|
{ ".DEFINED", TOK_DEFINED },
|
||||||
|
{ ".DEFINEDMACRO", TOK_DEFINEDMACRO },
|
||||||
{ ".DELMAC", TOK_DELMAC },
|
{ ".DELMAC", TOK_DELMAC },
|
||||||
{ ".DELMACRO", TOK_DELMAC },
|
{ ".DELMACRO", TOK_DELMAC },
|
||||||
{ ".DESTRUCTOR", TOK_DESTRUCTOR },
|
{ ".DESTRUCTOR", TOK_DESTRUCTOR },
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ typedef enum token_t {
|
|||||||
TOK_DEBUGINFO,
|
TOK_DEBUGINFO,
|
||||||
TOK_DEFINE,
|
TOK_DEFINE,
|
||||||
TOK_DEFINED,
|
TOK_DEFINED,
|
||||||
|
TOK_DEFINEDMACRO,
|
||||||
TOK_DELMAC,
|
TOK_DELMAC,
|
||||||
TOK_DESTRUCTOR,
|
TOK_DESTRUCTOR,
|
||||||
TOK_DWORD,
|
TOK_DWORD,
|
||||||
|
|||||||
Reference in New Issue
Block a user