]> git.sur5r.net Git - cc65/commitdiff
Added pseudo function .DEFINEDINSTR
authorJT <jeremiah.turner@gmail.com>
Tue, 12 May 2015 23:28:57 +0000 (19:28 -0400)
committerJT <jeremiah.turner@gmail.com>
Tue, 12 May 2015 23:28:57 +0000 (19:28 -0400)
src/ca65/expr.c
src/ca65/feature.c
src/ca65/feature.h
src/ca65/global.c
src/ca65/global.h
src/ca65/pseudo.c
src/ca65/scanner.c
src/ca65/token.h

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;
index 3462d5501c30848cf3d29d3f9c2cd45938c87fe5..2a29b5e8f151797e113417e42b17ae746fa6354a 100644 (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;
     }
 
index 3a520a54a3e2ff5eee997eb6214035b7f41490e9..d5d4d9d237386f98329f92d6152fe89c0062a926 100644 (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
index 77ed66e7f5306d4fa4d1cb2c9f0ca9fb1d7105ee..a1f29bc3876920aab96d1c5026924d252e4b1f97 100644 (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 */
index fb254f835342f13a07379c36ab0555395c4c66ec..4939f8edf9d7b528dbd0ff6f62cca9308a662f90 100644 (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 */
 
 
 
index 2e8a473a5e745321d62ed591f0fff0ecbe72e118..d99bd29a425b7118d069907f94734761d6b4230e 100644 (file)
@@ -1989,6 +1989,7 @@ static CtrlDesc CtrlCmdTab [] = {
     { ccNone,           DoDebugInfo     },
     { ccNone,           DoDefine        },
     { ccNone,           DoUnexpected    },      /* .DEFINED */
+    { ccNone,           DoUnexpected    },      /* .DEFINEDINSTR */
     { ccNone,           DoDelMac        },
     { ccNone,           DoDestructor    },
     { ccNone,           DoDWord         },
index db747cf70712726a8dd4ab34b979ba4beb3895e8..801790fa0634630ce1db5e00ab2b6072a174192c 100644 (file)
@@ -132,163 +132,164 @@ struct DotKeyword {
     const char* Key;                    /* MUST be first field */
     token_t     Tok;
 } DotKeywords [] = {
-    { ".A16",           TOK_A16         },
-    { ".A8",            TOK_A8          },
-    { ".ADDR",          TOK_ADDR        },
-    { ".ADDRSIZE",      TOK_ADDRSIZE    },
-    { ".ALIGN",         TOK_ALIGN       },
-    { ".AND",           TOK_BOOLAND     },
-    { ".ASCIIZ",        TOK_ASCIIZ      },
-    { ".ASSERT",        TOK_ASSERT      },
-    { ".AUTOIMPORT",    TOK_AUTOIMPORT  },
-    { ".BANK",          TOK_BANK        },
-    { ".BANKBYTE",      TOK_BANKBYTE    },
-    { ".BANKBYTES",     TOK_BANKBYTES   },
-    { ".BITAND",        TOK_AND         },
-    { ".BITNOT",        TOK_NOT         },
-    { ".BITOR",         TOK_OR          },
-    { ".BITXOR",        TOK_XOR         },
-    { ".BLANK",         TOK_BLANK       },
-    { ".BSS",           TOK_BSS         },
-    { ".BYT",           TOK_BYTE        },
-    { ".BYTE",          TOK_BYTE        },
-    { ".CASE",          TOK_CASE        },
-    { ".CHARMAP",       TOK_CHARMAP     },
-    { ".CODE",          TOK_CODE        },
-    { ".CONCAT",        TOK_CONCAT      },
-    { ".CONDES",        TOK_CONDES      },
-    { ".CONST",         TOK_CONST       },
-    { ".CONSTRUCTOR",   TOK_CONSTRUCTOR },
-    { ".CPU",           TOK_CPU         },
-    { ".DATA",          TOK_DATA        },
-    { ".DBG",           TOK_DBG         },
-    { ".DBYT",          TOK_DBYT        },
-    { ".DEBUGINFO",     TOK_DEBUGINFO   },
-    { ".DEF",           TOK_DEFINED     },
-    { ".DEFINE",        TOK_DEFINE      },
-    { ".DEFINED",       TOK_DEFINED     },
-    { ".DELMAC",        TOK_DELMAC      },
-    { ".DELMACRO",      TOK_DELMAC      },
-    { ".DESTRUCTOR",    TOK_DESTRUCTOR  },
-    { ".DWORD",         TOK_DWORD       },
-    { ".ELSE",          TOK_ELSE        },
-    { ".ELSEIF",        TOK_ELSEIF      },
-    { ".END",           TOK_END         },
-    { ".ENDENUM",       TOK_ENDENUM     },
-    { ".ENDIF",         TOK_ENDIF       },
-    { ".ENDMAC",        TOK_ENDMACRO    },
-    { ".ENDMACRO",      TOK_ENDMACRO    },
-    { ".ENDPROC",       TOK_ENDPROC     },
-    { ".ENDREP",        TOK_ENDREP      },
-    { ".ENDREPEAT",     TOK_ENDREP      },
-    { ".ENDSCOPE",      TOK_ENDSCOPE    },
-    { ".ENDSTRUCT",     TOK_ENDSTRUCT   },
-    { ".ENDUNION",      TOK_ENDUNION    },
-    { ".ENUM",          TOK_ENUM        },
-    { ".ERROR",         TOK_ERROR       },
-    { ".EXITMAC",       TOK_EXITMACRO   },
-    { ".EXITMACRO",     TOK_EXITMACRO   },
-    { ".EXPORT",        TOK_EXPORT      },
-    { ".EXPORTZP",      TOK_EXPORTZP    },
-    { ".FARADDR",       TOK_FARADDR     },
-    { ".FATAL",         TOK_FATAL       },
-    { ".FEATURE",       TOK_FEATURE     },
-    { ".FILEOPT",       TOK_FILEOPT     },
-    { ".FOPT",          TOK_FILEOPT     },
-    { ".FORCEIMPORT",   TOK_FORCEIMPORT },
-    { ".FORCEWORD",     TOK_FORCEWORD   },
-    { ".GLOBAL",        TOK_GLOBAL      },
-    { ".GLOBALZP",      TOK_GLOBALZP    },
-    { ".HIBYTE",        TOK_HIBYTE      },
-    { ".HIBYTES",       TOK_HIBYTES     },
-    { ".HIWORD",        TOK_HIWORD      },
-    { ".I16",           TOK_I16         },
-    { ".I8",            TOK_I8          },
-    { ".IDENT",         TOK_MAKEIDENT   },
-    { ".IF",            TOK_IF          },
-    { ".IFBLANK",       TOK_IFBLANK     },
-    { ".IFCONST",       TOK_IFCONST     },
-    { ".IFDEF",         TOK_IFDEF       },
-    { ".IFNBLANK",      TOK_IFNBLANK    },
-    { ".IFNCONST",      TOK_IFNCONST    },
-    { ".IFNDEF",        TOK_IFNDEF      },
-    { ".IFNREF",        TOK_IFNREF      },
-    { ".IFP02",         TOK_IFP02       },
-    { ".IFP816",        TOK_IFP816      },
-    { ".IFPC02",        TOK_IFPC02      },
-    { ".IFPSC02",       TOK_IFPSC02     },
-    { ".IFREF",         TOK_IFREF       },
-    { ".IMPORT",        TOK_IMPORT      },
-    { ".IMPORTZP",      TOK_IMPORTZP    },
-    { ".INCBIN",        TOK_INCBIN      },
-    { ".INCLUDE",       TOK_INCLUDE     },
-    { ".INTERRUPTOR",   TOK_INTERRUPTOR },
-    { ".LEFT",          TOK_LEFT        },
-    { ".LINECONT",      TOK_LINECONT    },
-    { ".LIST",          TOK_LIST        },
-    { ".LISTBYTES",     TOK_LISTBYTES   },
-    { ".LOBYTE",        TOK_LOBYTE      },
-    { ".LOBYTES",       TOK_LOBYTES     },
-    { ".LOCAL",         TOK_LOCAL       },
-    { ".LOCALCHAR",     TOK_LOCALCHAR   },
-    { ".LOWORD",        TOK_LOWORD      },
-    { ".MAC",           TOK_MACRO       },
-    { ".MACPACK",       TOK_MACPACK     },
-    { ".MACRO",         TOK_MACRO       },
-    { ".MATCH",         TOK_MATCH       },
-    { ".MAX",           TOK_MAX         },
-    { ".MID",           TOK_MID         },
-    { ".MIN",           TOK_MIN         },
-    { ".MOD",           TOK_MOD         },
-    { ".NOT",           TOK_BOOLNOT     },
-    { ".NULL",          TOK_NULL        },
-    { ".OR",            TOK_BOOLOR      },
-    { ".ORG",           TOK_ORG         },
-    { ".OUT",           TOK_OUT         },
-    { ".P02",           TOK_P02         },
-    { ".P816",          TOK_P816        },
-    { ".PAGELEN",       TOK_PAGELENGTH  },
-    { ".PAGELENGTH",    TOK_PAGELENGTH  },
-    { ".PARAMCOUNT",    TOK_PARAMCOUNT  },
-    { ".PC02",          TOK_PC02        },
-    { ".POPCPU",        TOK_POPCPU      },
-    { ".POPSEG",        TOK_POPSEG      },
-    { ".PROC",          TOK_PROC        },
-    { ".PSC02",         TOK_PSC02       },
-    { ".PUSHCPU",       TOK_PUSHCPU     },
-    { ".PUSHSEG",       TOK_PUSHSEG     },
-    { ".REF",           TOK_REFERENCED  },
-    { ".REFERENCED",    TOK_REFERENCED  },
-    { ".RELOC",         TOK_RELOC       },
-    { ".REPEAT",        TOK_REPEAT      },
-    { ".RES",           TOK_RES         },
-    { ".RIGHT",         TOK_RIGHT       },
-    { ".RODATA",        TOK_RODATA      },
-    { ".SCOPE",         TOK_SCOPE       },
-    { ".SEGMENT",       TOK_SEGMENT     },
-    { ".SET",           TOK_SET         },
-    { ".SETCPU",        TOK_SETCPU      },
-    { ".SHL",           TOK_SHL         },
-    { ".SHR",           TOK_SHR         },
-    { ".SIZEOF",        TOK_SIZEOF      },
-    { ".SMART",         TOK_SMART       },
-    { ".SPRINTF",       TOK_SPRINTF     },
-    { ".STRAT",         TOK_STRAT       },
-    { ".STRING",        TOK_STRING      },
-    { ".STRLEN",        TOK_STRLEN      },
-    { ".STRUCT",        TOK_STRUCT      },
-    { ".TAG",           TOK_TAG         },
-    { ".TCOUNT",        TOK_TCOUNT      },
-    { ".TIME",          TOK_TIME        },
-    { ".UNDEF",         TOK_UNDEF       },
-    { ".UNDEFINE",      TOK_UNDEF       },
-    { ".UNION",         TOK_UNION       },
-    { ".VERSION",       TOK_VERSION     },
-    { ".WARNING",       TOK_WARNING     },
-    { ".WORD",          TOK_WORD        },
-    { ".XMATCH",        TOK_XMATCH      },
-    { ".XOR",           TOK_BOOLXOR     },
-    { ".ZEROPAGE",      TOK_ZEROPAGE    },
+    { ".A16",           TOK_A16          },
+    { ".A8",            TOK_A8           },
+    { ".ADDR",          TOK_ADDR         },
+    { ".ADDRSIZE",      TOK_ADDRSIZE     },
+    { ".ALIGN",         TOK_ALIGN        },
+    { ".AND",           TOK_BOOLAND      },
+    { ".ASCIIZ",        TOK_ASCIIZ       },
+    { ".ASSERT",        TOK_ASSERT       },
+    { ".AUTOIMPORT",    TOK_AUTOIMPORT   },
+    { ".BANK",          TOK_BANK         },
+    { ".BANKBYTE",      TOK_BANKBYTE     },
+    { ".BANKBYTES",     TOK_BANKBYTES    },
+    { ".BITAND",        TOK_AND          },
+    { ".BITNOT",        TOK_NOT          },
+    { ".BITOR",         TOK_OR           },
+    { ".BITXOR",        TOK_XOR          },
+    { ".BLANK",         TOK_BLANK        },
+    { ".BSS",           TOK_BSS          },
+    { ".BYT",           TOK_BYTE         },
+    { ".BYTE",          TOK_BYTE         },
+    { ".CASE",          TOK_CASE         },
+    { ".CHARMAP",       TOK_CHARMAP      },
+    { ".CODE",          TOK_CODE         },
+    { ".CONCAT",        TOK_CONCAT       },
+    { ".CONDES",        TOK_CONDES       },
+    { ".CONST",         TOK_CONST        },
+    { ".CONSTRUCTOR",   TOK_CONSTRUCTOR  },
+    { ".CPU",           TOK_CPU          },
+    { ".DATA",          TOK_DATA         },
+    { ".DBG",           TOK_DBG          },
+    { ".DBYT",          TOK_DBYT         },
+    { ".DEBUGINFO",     TOK_DEBUGINFO    },
+    { ".DEF",           TOK_DEFINED      },
+    { ".DEFINE",        TOK_DEFINE       },
+    { ".DEFINED",       TOK_DEFINED      },
+    { ".DEFINEDINSTR",  TOK_DEFINEDINSTR },
+    { ".DELMAC",        TOK_DELMAC       },
+    { ".DELMACRO",      TOK_DELMAC       },
+    { ".DESTRUCTOR",    TOK_DESTRUCTOR   },
+    { ".DWORD",         TOK_DWORD        },
+    { ".ELSE",          TOK_ELSE         },
+    { ".ELSEIF",        TOK_ELSEIF       },
+    { ".END",           TOK_END          },
+    { ".ENDENUM",       TOK_ENDENUM      },
+    { ".ENDIF",         TOK_ENDIF        },
+    { ".ENDMAC",        TOK_ENDMACRO     },
+    { ".ENDMACRO",      TOK_ENDMACRO     },
+    { ".ENDPROC",       TOK_ENDPROC      },
+    { ".ENDREP",        TOK_ENDREP       },
+    { ".ENDREPEAT",     TOK_ENDREP       },
+    { ".ENDSCOPE",      TOK_ENDSCOPE     },
+    { ".ENDSTRUCT",     TOK_ENDSTRUCT    },
+    { ".ENDUNION",      TOK_ENDUNION     },
+    { ".ENUM",          TOK_ENUM         },
+    { ".ERROR",         TOK_ERROR        },
+    { ".EXITMAC",       TOK_EXITMACRO    },
+    { ".EXITMACRO",     TOK_EXITMACRO    },
+    { ".EXPORT",        TOK_EXPORT       },
+    { ".EXPORTZP",      TOK_EXPORTZP     },
+    { ".FARADDR",       TOK_FARADDR      },
+    { ".FATAL",         TOK_FATAL        },
+    { ".FEATURE",       TOK_FEATURE      },
+    { ".FILEOPT",       TOK_FILEOPT      },
+    { ".FOPT",          TOK_FILEOPT      },
+    { ".FORCEIMPORT",   TOK_FORCEIMPORT  },
+    { ".FORCEWORD",     TOK_FORCEWORD    },
+    { ".GLOBAL",        TOK_GLOBAL       },
+    { ".GLOBALZP",      TOK_GLOBALZP     },
+    { ".HIBYTE",        TOK_HIBYTE       },
+    { ".HIBYTES",       TOK_HIBYTES      },
+    { ".HIWORD",        TOK_HIWORD       },
+    { ".I16",           TOK_I16          },
+    { ".I8",            TOK_I8           },
+    { ".IDENT",         TOK_MAKEIDENT    },
+    { ".IF",            TOK_IF           },
+    { ".IFBLANK",       TOK_IFBLANK      },
+    { ".IFCONST",       TOK_IFCONST      },
+    { ".IFDEF",         TOK_IFDEF        },
+    { ".IFNBLANK",      TOK_IFNBLANK     },
+    { ".IFNCONST",      TOK_IFNCONST     },
+    { ".IFNDEF",        TOK_IFNDEF       },
+    { ".IFNREF",        TOK_IFNREF       },
+    { ".IFP02",         TOK_IFP02        },
+    { ".IFP816",        TOK_IFP816       },
+    { ".IFPC02",        TOK_IFPC02       },
+    { ".IFPSC02",       TOK_IFPSC02      },
+    { ".IFREF",         TOK_IFREF        },
+    { ".IMPORT",        TOK_IMPORT       },
+    { ".IMPORTZP",      TOK_IMPORTZP     },
+    { ".INCBIN",        TOK_INCBIN       },
+    { ".INCLUDE",       TOK_INCLUDE      },
+    { ".INTERRUPTOR",   TOK_INTERRUPTOR  },
+    { ".LEFT",          TOK_LEFT         },
+    { ".LINECONT",      TOK_LINECONT     },
+    { ".LIST",          TOK_LIST         },
+    { ".LISTBYTES",     TOK_LISTBYTES    },
+    { ".LOBYTE",        TOK_LOBYTE       },
+    { ".LOBYTES",       TOK_LOBYTES      },
+    { ".LOCAL",         TOK_LOCAL        },
+    { ".LOCALCHAR",     TOK_LOCALCHAR    },
+    { ".LOWORD",        TOK_LOWORD       },
+    { ".MAC",           TOK_MACRO        },
+    { ".MACPACK",       TOK_MACPACK      },
+    { ".MACRO",         TOK_MACRO        },
+    { ".MATCH",         TOK_MATCH        },
+    { ".MAX",           TOK_MAX          },
+    { ".MID",           TOK_MID          },
+    { ".MIN",           TOK_MIN          },
+    { ".MOD",           TOK_MOD          },
+    { ".NOT",           TOK_BOOLNOT      },
+    { ".NULL",          TOK_NULL         },
+    { ".OR",            TOK_BOOLOR       },
+    { ".ORG",           TOK_ORG          },
+    { ".OUT",           TOK_OUT          },
+    { ".P02",           TOK_P02          },
+    { ".P816",          TOK_P816         },
+    { ".PAGELEN",       TOK_PAGELENGTH   },
+    { ".PAGELENGTH",    TOK_PAGELENGTH   },
+    { ".PARAMCOUNT",    TOK_PARAMCOUNT   },
+    { ".PC02",          TOK_PC02         },
+    { ".POPCPU",        TOK_POPCPU       },
+    { ".POPSEG",        TOK_POPSEG       },
+    { ".PROC",          TOK_PROC         },
+    { ".PSC02",         TOK_PSC02        },
+    { ".PUSHCPU",       TOK_PUSHCPU      },
+    { ".PUSHSEG",       TOK_PUSHSEG      },
+    { ".REF",           TOK_REFERENCED   },
+    { ".REFERENCED",    TOK_REFERENCED   },
+    { ".RELOC",         TOK_RELOC        },
+    { ".REPEAT",        TOK_REPEAT       },
+    { ".RES",           TOK_RES          },
+    { ".RIGHT",         TOK_RIGHT        },
+    { ".RODATA",        TOK_RODATA       },
+    { ".SCOPE",         TOK_SCOPE        },
+    { ".SEGMENT",       TOK_SEGMENT      },
+    { ".SET",           TOK_SET          },
+    { ".SETCPU",        TOK_SETCPU       },
+    { ".SHL",           TOK_SHL          },
+    { ".SHR",           TOK_SHR          },
+    { ".SIZEOF",        TOK_SIZEOF       },
+    { ".SMART",         TOK_SMART        },
+    { ".SPRINTF",       TOK_SPRINTF      },
+    { ".STRAT",         TOK_STRAT        },
+    { ".STRING",        TOK_STRING       },
+    { ".STRLEN",        TOK_STRLEN       },
+    { ".STRUCT",        TOK_STRUCT       },
+    { ".TAG",           TOK_TAG          },
+    { ".TCOUNT",        TOK_TCOUNT       },
+    { ".TIME",          TOK_TIME         },
+    { ".UNDEF",         TOK_UNDEF        },
+    { ".UNDEFINE",      TOK_UNDEF        },
+    { ".UNION",         TOK_UNION        },
+    { ".VERSION",       TOK_VERSION      },
+    { ".WARNING",       TOK_WARNING      },
+    { ".WORD",          TOK_WORD         },
+    { ".XMATCH",        TOK_XMATCH       },
+    { ".XOR",           TOK_BOOLXOR      },
+    { ".ZEROPAGE",      TOK_ZEROPAGE     },
 };
 
 
@@ -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;
         }
index 7aaba34c3315ba4a64db6d06f0f8d87a4ca104a5..102fde8067260a4e3bd1412a3e019aca89885e53 100644 (file)
@@ -148,6 +148,7 @@ typedef enum token_t {
     TOK_DEBUGINFO,
     TOK_DEFINE,
     TOK_DEFINED,
+    TOK_DEFINEDINSTR,
     TOK_DELMAC,
     TOK_DESTRUCTOR,
     TOK_DWORD,