mirror of
https://github.com/cc65/cc65.git
synced 2025-01-30 12:33:15 +00:00
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
This commit is contained in:
parent
0eba6f615f
commit
c3d510a9bc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user