From: cuz Date: Tue, 20 Apr 2004 12:49:36 +0000 (+0000) Subject: Add a new feature "ubiquitous_idents" that allows the use of instructions as X-Git-Tag: V2.12.0~845 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c3d510a9bc55017e64680488964e28bb26222e07;p=cc65 Add a new feature "ubiquitous_idents" that allows the use of instructions as identifiers and macro names. git-svn-id: svn://svn.cc65.org/cc65/trunk@2981 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/feature.c b/src/ca65/feature.c index 3983270ec..91b0ae092 100644 --- a/src/ca65/feature.c +++ b/src/ca65/feature.c @@ -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; } diff --git a/src/ca65/feature.h b/src/ca65/feature.h index df91e77f1..2b8ec5ad3 100644 --- a/src/ca65/feature.h +++ b/src/ca65/feature.h @@ -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 diff --git a/src/ca65/global.c b/src/ca65/global.c index f9d29bea9..e0196226a 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -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"; diff --git a/src/ca65/global.h b/src/ca65/global.h index f75d12335..472800062 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -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 */ diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 3b60297d0..282bbe687 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -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; } diff --git a/src/ca65/main.c b/src/ca65/main.c index dc77a2e92..d888e70a8 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -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) { diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 6c0e06d9c..62f7277b2 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -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); } diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index bcc76c37e..b9d38895f 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -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 */