]> git.sur5r.net Git - cc65/commitdiff
Add a new feature "ubiquitous_idents" that allows the use of instructions as
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 20 Apr 2004 12:49:36 +0000 (12:49 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 20 Apr 2004 12:49:36 +0000 (12:49 +0000)
identifiers and macro names.

git-svn-id: svn://svn.cc65.org/cc65/trunk@2981 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/feature.c
src/ca65/feature.h
src/ca65/global.c
src/ca65/global.h
src/ca65/macro.c
src/ca65/main.c
src/ca65/scanner.c
src/ca65/scanner.h

index 3983270ecfde6f892fd2944ad84189f69ce8e81e..91b0ae09211a54df1cb8767c166a266e6befe6ca 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2003 Ullrich von Bassewitz                                       */
+/* (C) 2000-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -58,6 +58,7 @@ static const char* FeatureKeys[FEAT_COUNT] = {
     "leading_dot_in_identifiers",
     "pc_assignment",
     "missing_char_term",
+    "ubiquitous_idents",
 };
 
 
@@ -109,6 +110,7 @@ feature_t SetFeature (const char* Key)
                case FEAT_LEADING_DOT_IN_IDENTIFIERS: LeadingDotInIdents= 1;    break;
        case FEAT_PC_ASSIGNMENT:              PCAssignment      = 1;    break;
         case FEAT_MISSING_CHAR_TERM:          MissingCharTerm   = 1;    break;
+        case FEAT_UBIQUITOUS_IDENTS:          UbiquitousIdents  = 1;    break;
        default:                         /* Keep gcc silent */          break;
     }
 
index df91e77f133ea6ee3f7ebc695f6e8ae5231c097a..2b8ec5ad3e7fb08553c6e8d83d62a77299e2260c 100644 (file)
@@ -55,6 +55,7 @@ typedef enum {
     FEAT_LEADING_DOT_IN_IDENTIFIERS,
     FEAT_PC_ASSIGNMENT,
     FEAT_MISSING_CHAR_TERM,
+    FEAT_UBIQUITOUS_IDENTS,
 
     /* Special value: Number of features available */
     FEAT_COUNT
index f9d29bea95aa6692b7d652f1a7164d24538f9350..e0196226aa05553668ed14e6e1b5022d67ae4c0b 100644 (file)
@@ -75,6 +75,7 @@ unsigned char DollarInIdents     = 0;   /* Allow '$' in identifiers */
 unsigned char LeadingDotInIdents = 0;   /* Allow '.' to start an identifier */
 unsigned char PCAssignment       = 0;  /* Allow "* = $XXX" or "$ = $XXX" */
 unsigned char MissingCharTerm    = 0;   /* Allow lda #'a (no closing term) */
+unsigned char UbiquitousIdents   = 0;   /* Allow ubiquitous identifiers */
 
 /* Misc stuff */
 const char Copyright[]           = "(C) Copyright 1998-2004 Ullrich von Bassewitz";
index f75d12335982a9bb2c44f76cfced7dd72112806b..4728000620afcc5808105bf6559d985846235657 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -72,6 +72,7 @@ extern unsigned char          DollarInIdents;     /* Allow '$' in identifiers */
 extern unsigned char    LeadingDotInIdents; /* Allow '.' to start an identifier */
 extern unsigned char           PCAssignment;       /* Allow "* = $XXX" or "$ = $XXX" */
 extern unsigned char    MissingCharTerm;    /* Allow lda #'a (no closing term) */
+extern unsigned char    UbiquitousIdents;   /* Allow ubiquitous identifiers */
 
 /* Misc stuff */
 extern const char       Copyright[];        /* Copyright string */
index 3b60297d09175250035155613819878474434a2e..282bbe6871356fa7b40bf3fbaf117f4cea251d6e 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -46,6 +46,7 @@
 #include "condasm.h"
 #include "error.h"
 #include "global.h"
+#include "instr.h"
 #include "istack.h"
 #include "nexttok.h"
 #include "pseudo.h"
@@ -333,6 +334,13 @@ void MacDef (unsigned Style)
        Error ("Identifier expected");
        MacSkipDef (Style);
        return;
+    } else if (!UbiquitousIdents && FindInstruction (SVal) >= 0) {
+        /* The identifier is a name of a 6502 instruction, which is not
+         * allowed if not explicitly enabled.
+         */
+        Error ("Cannot use an instruction as macro name");
+        MacSkipDef (Style);
+        return;
     }
 
     /* Did we already define that macro? */
@@ -381,7 +389,7 @@ void MacDef (unsigned Style)
                while (1) {
                    if (strcmp (List->Id, SVal) == 0) {
                        Error ("Duplicate symbol `%s'", SVal);
-                   }                                 
+                   }
                    if (List->Next == 0) {
                        break;
                    } else {
@@ -663,7 +671,7 @@ static void StartExpClassic (Macro* M)
                /* Check for maximum parameter count */
        if (E->ParamCount >= M->ParamCount) {
            Error ("Too many macro parameters");
-           SkipUntilSep ();                    
+           SkipUntilSep ();
            break;
        }
 
index dc77a2e9211493c70e6945761376a8e1db153d43..d888e70a81646c3585853aed4dce96ebb6eab2f1 100644 (file)
@@ -375,26 +375,44 @@ static void DoPCAssign (void)
 static void OneLine (void)
 /* Assemble one line */
 {
-    Segment*      Seg  = 0;
-    unsigned long PC   = 0;
-    SymEntry*     Sym  = 0;
-    int           Done = 0;
+    Segment*      Seg   = 0;
+    unsigned long PC    = 0;
+    SymEntry*     Sym   = 0;
+    int           Done  = 0;
+    int           Macro = 0;
+    int           Instr = -1;
 
     /* Initialize the new listing line if we are actually reading from file
      * and not from internally pushed input.
      */
     if (!HavePushedInput ()) {
-       InitListingLine ();
+               InitListingLine ();
     }
 
     if (Tok == TOK_COLON) {
-       /* An unnamed label */
-       ULabDef ();
-       NextTok ();
+               /* An unnamed label */
+               ULabDef ();
+               NextTok ();
     }
 
-    /* Assemble the line */
-    if (Tok == TOK_LOCAL_IDENT || (Tok == TOK_IDENT && !IsMacro (SVal))) {
+    /* If the first token on the line is an identifier, check for a macro or
+     * an instruction.
+     */
+    if (Tok == TOK_IDENT) {
+        if (!UbiquitousIdents) {
+            /* Macros and symbols cannot use instruction names */
+            Instr = FindInstruction (SVal);
+            if (Instr < 0) {
+                Macro = IsMacro (SVal);
+            }
+        } else {
+            /* Macros and symbols may use the names of instructions */
+            Macro = IsMacro (SVal);
+        }
+    }
+
+    /* Handle an identifier */
+    if (Tok == TOK_LOCAL_IDENT || (Tok == TOK_IDENT && Instr < 0 && !Macro)) {
 
         /* Did we have whitespace before the ident? */
         int HadWS = WS;
@@ -453,12 +471,13 @@ static void OneLine (void)
        if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) {
            /* A control command */
            HandlePseudo ();
-       } else if (Tok == TOK_MNEMO) {
-           /* A mnemonic - assemble one instruction */
-           HandleInstruction (IVal);
-       } else if (Tok == TOK_IDENT && IsMacro (SVal)) {
+       } else if (Macro) {
            /* A macro expansion */
            MacExpandStart ();
+       } else if (Instr >= 0 ||
+                   (UbiquitousIdents && ((Instr = FindInstruction (SVal)) >= 0))) {
+           /* A mnemonic - assemble one instruction */
+           HandleInstruction (Instr);
        } else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
            NextTok ();
            if (Tok != TOK_EQ) {
index 6c0e06d9c0172902077ea2df92a6327aaa511591..62f7277b2d52e8fa05232278e8f12b6ebd0cb655 100644 (file)
@@ -617,7 +617,7 @@ static unsigned ReadStringConst (int StringTerm)
 
     /* Return the length of the string */
     return I;
-}               
+}
 
 
 
@@ -844,13 +844,9 @@ Again:
            }
        }
 
-       /* Search for an opcode */
-       IVal = FindInstruction (SVal);
-       if (IVal >= 0) {
-           /* This is a mnemonic */
-                   Tok = TOK_MNEMO;
-               } else if (IsDefine (SVal)) {
-           /* This is a define style macro - expand it */
+       /* Check for define style macro */
+               if (IsDefine (SVal)) {
+           /* Macro - expand it */
            MacExpandStart ();
            goto Restart;
        } else {
@@ -1122,7 +1118,7 @@ int TokHasSVal (enum Token Tok)
 int TokHasIVal (enum Token Tok)
 /* Return true if the given token has an attached IVal */
 {
-    return (Tok == TOK_INTCON || Tok == TOK_CHARCON || Tok == TOK_MNEMO);
+    return (Tok == TOK_INTCON || Tok == TOK_CHARCON);
 }
 
 
index bcc76c37e5483c3dbe2a6b4f58869a7ab030b1a3..b9d38895fa5e5345dcda5acf5e5daeae6d0e3da1 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/* (C) 1998-2004 Ullrich von Bassewitz                                       */
 /*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
@@ -57,7 +57,6 @@ enum Token {
     TOK_SEP,           /* Separator (usually newline) */
     TOK_IDENT,         /* An identifier */
     TOK_LOCAL_IDENT,    /* A cheap local identifier */
-    TOK_MNEMO,                 /* A mnemonic */
 
     TOK_INTCON,        /* Integer constant */
     TOK_CHARCON,       /* Character constant */