]> git.sur5r.net Git - cc65/blobdiff - src/ca65/expr.c
Added pseudo function .DEFINEDINSTR
[cc65] / src / ca65 / expr.c
index 8b87d0860d488ec803564d8a28df59deafb2a889..969028f10075e495662145f5edffc8789b4f9ac2 100644 (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;