mirror of
https://github.com/cc65/cc65.git
synced 2025-02-06 12:31:12 +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 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -58,6 +58,7 @@ static const char* FeatureKeys[FEAT_COUNT] = {
|
|||||||
"leading_dot_in_identifiers",
|
"leading_dot_in_identifiers",
|
||||||
"pc_assignment",
|
"pc_assignment",
|
||||||
"missing_char_term",
|
"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_LEADING_DOT_IN_IDENTIFIERS: LeadingDotInIdents= 1; break;
|
||||||
case FEAT_PC_ASSIGNMENT: PCAssignment = 1; break;
|
case FEAT_PC_ASSIGNMENT: PCAssignment = 1; break;
|
||||||
case FEAT_MISSING_CHAR_TERM: MissingCharTerm = 1; break;
|
case FEAT_MISSING_CHAR_TERM: MissingCharTerm = 1; break;
|
||||||
|
case FEAT_UBIQUITOUS_IDENTS: UbiquitousIdents = 1; break;
|
||||||
default: /* Keep gcc silent */ break;
|
default: /* Keep gcc silent */ break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ typedef enum {
|
|||||||
FEAT_LEADING_DOT_IN_IDENTIFIERS,
|
FEAT_LEADING_DOT_IN_IDENTIFIERS,
|
||||||
FEAT_PC_ASSIGNMENT,
|
FEAT_PC_ASSIGNMENT,
|
||||||
FEAT_MISSING_CHAR_TERM,
|
FEAT_MISSING_CHAR_TERM,
|
||||||
|
FEAT_UBIQUITOUS_IDENTS,
|
||||||
|
|
||||||
/* Special value: Number of features available */
|
/* Special value: Number of features available */
|
||||||
FEAT_COUNT
|
FEAT_COUNT
|
||||||
|
@ -75,6 +75,7 @@ unsigned char DollarInIdents = 0; /* Allow '$' in identifiers */
|
|||||||
unsigned char LeadingDotInIdents = 0; /* Allow '.' to start an identifier */
|
unsigned char LeadingDotInIdents = 0; /* Allow '.' to start an identifier */
|
||||||
unsigned char PCAssignment = 0; /* Allow "* = $XXX" or "$ = $XXX" */
|
unsigned char PCAssignment = 0; /* Allow "* = $XXX" or "$ = $XXX" */
|
||||||
unsigned char MissingCharTerm = 0; /* Allow lda #'a (no closing term) */
|
unsigned char MissingCharTerm = 0; /* Allow lda #'a (no closing term) */
|
||||||
|
unsigned char UbiquitousIdents = 0; /* Allow ubiquitous identifiers */
|
||||||
|
|
||||||
/* Misc stuff */
|
/* Misc stuff */
|
||||||
const char Copyright[] = "(C) Copyright 1998-2004 Ullrich von Bassewitz";
|
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 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* 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 LeadingDotInIdents; /* Allow '.' to start an identifier */
|
||||||
extern unsigned char PCAssignment; /* Allow "* = $XXX" or "$ = $XXX" */
|
extern unsigned char PCAssignment; /* Allow "* = $XXX" or "$ = $XXX" */
|
||||||
extern unsigned char MissingCharTerm; /* Allow lda #'a (no closing term) */
|
extern unsigned char MissingCharTerm; /* Allow lda #'a (no closing term) */
|
||||||
|
extern unsigned char UbiquitousIdents; /* Allow ubiquitous identifiers */
|
||||||
|
|
||||||
/* Misc stuff */
|
/* Misc stuff */
|
||||||
extern const char Copyright[]; /* Copyright string */
|
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 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -46,6 +46,7 @@
|
|||||||
#include "condasm.h"
|
#include "condasm.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "instr.h"
|
||||||
#include "istack.h"
|
#include "istack.h"
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
#include "pseudo.h"
|
#include "pseudo.h"
|
||||||
@ -333,6 +334,13 @@ void MacDef (unsigned Style)
|
|||||||
Error ("Identifier expected");
|
Error ("Identifier expected");
|
||||||
MacSkipDef (Style);
|
MacSkipDef (Style);
|
||||||
return;
|
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? */
|
/* Did we already define that macro? */
|
||||||
@ -381,7 +389,7 @@ void MacDef (unsigned Style)
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (strcmp (List->Id, SVal) == 0) {
|
if (strcmp (List->Id, SVal) == 0) {
|
||||||
Error ("Duplicate symbol `%s'", SVal);
|
Error ("Duplicate symbol `%s'", SVal);
|
||||||
}
|
}
|
||||||
if (List->Next == 0) {
|
if (List->Next == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@ -663,7 +671,7 @@ static void StartExpClassic (Macro* M)
|
|||||||
/* Check for maximum parameter count */
|
/* Check for maximum parameter count */
|
||||||
if (E->ParamCount >= M->ParamCount) {
|
if (E->ParamCount >= M->ParamCount) {
|
||||||
Error ("Too many macro parameters");
|
Error ("Too many macro parameters");
|
||||||
SkipUntilSep ();
|
SkipUntilSep ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,26 +375,44 @@ static void DoPCAssign (void)
|
|||||||
static void OneLine (void)
|
static void OneLine (void)
|
||||||
/* Assemble one line */
|
/* Assemble one line */
|
||||||
{
|
{
|
||||||
Segment* Seg = 0;
|
Segment* Seg = 0;
|
||||||
unsigned long PC = 0;
|
unsigned long PC = 0;
|
||||||
SymEntry* Sym = 0;
|
SymEntry* Sym = 0;
|
||||||
int Done = 0;
|
int Done = 0;
|
||||||
|
int Macro = 0;
|
||||||
|
int Instr = -1;
|
||||||
|
|
||||||
/* Initialize the new listing line if we are actually reading from file
|
/* Initialize the new listing line if we are actually reading from file
|
||||||
* and not from internally pushed input.
|
* and not from internally pushed input.
|
||||||
*/
|
*/
|
||||||
if (!HavePushedInput ()) {
|
if (!HavePushedInput ()) {
|
||||||
InitListingLine ();
|
InitListingLine ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Tok == TOK_COLON) {
|
if (Tok == TOK_COLON) {
|
||||||
/* An unnamed label */
|
/* An unnamed label */
|
||||||
ULabDef ();
|
ULabDef ();
|
||||||
NextTok ();
|
NextTok ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assemble the line */
|
/* If the first token on the line is an identifier, check for a macro or
|
||||||
if (Tok == TOK_LOCAL_IDENT || (Tok == TOK_IDENT && !IsMacro (SVal))) {
|
* 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? */
|
/* Did we have whitespace before the ident? */
|
||||||
int HadWS = WS;
|
int HadWS = WS;
|
||||||
@ -453,12 +471,13 @@ static void OneLine (void)
|
|||||||
if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) {
|
if (Tok >= TOK_FIRSTPSEUDO && Tok <= TOK_LASTPSEUDO) {
|
||||||
/* A control command */
|
/* A control command */
|
||||||
HandlePseudo ();
|
HandlePseudo ();
|
||||||
} else if (Tok == TOK_MNEMO) {
|
} else if (Macro) {
|
||||||
/* A mnemonic - assemble one instruction */
|
|
||||||
HandleInstruction (IVal);
|
|
||||||
} else if (Tok == TOK_IDENT && IsMacro (SVal)) {
|
|
||||||
/* A macro expansion */
|
/* A macro expansion */
|
||||||
MacExpandStart ();
|
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)) {
|
} else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
|
||||||
NextTok ();
|
NextTok ();
|
||||||
if (Tok != TOK_EQ) {
|
if (Tok != TOK_EQ) {
|
||||||
|
@ -617,7 +617,7 @@ static unsigned ReadStringConst (int StringTerm)
|
|||||||
|
|
||||||
/* Return the length of the string */
|
/* Return the length of the string */
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -844,13 +844,9 @@ Again:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for an opcode */
|
/* Check for define style macro */
|
||||||
IVal = FindInstruction (SVal);
|
if (IsDefine (SVal)) {
|
||||||
if (IVal >= 0) {
|
/* Macro - expand it */
|
||||||
/* This is a mnemonic */
|
|
||||||
Tok = TOK_MNEMO;
|
|
||||||
} else if (IsDefine (SVal)) {
|
|
||||||
/* This is a define style macro - expand it */
|
|
||||||
MacExpandStart ();
|
MacExpandStart ();
|
||||||
goto Restart;
|
goto Restart;
|
||||||
} else {
|
} else {
|
||||||
@ -1122,7 +1118,7 @@ int TokHasSVal (enum Token Tok)
|
|||||||
int TokHasIVal (enum Token Tok)
|
int TokHasIVal (enum Token Tok)
|
||||||
/* Return true if the given token has an attached IVal */
|
/* 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 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -57,7 +57,6 @@ enum Token {
|
|||||||
TOK_SEP, /* Separator (usually newline) */
|
TOK_SEP, /* Separator (usually newline) */
|
||||||
TOK_IDENT, /* An identifier */
|
TOK_IDENT, /* An identifier */
|
||||||
TOK_LOCAL_IDENT, /* A cheap local identifier */
|
TOK_LOCAL_IDENT, /* A cheap local identifier */
|
||||||
TOK_MNEMO, /* A mnemonic */
|
|
||||||
|
|
||||||
TOK_INTCON, /* Integer constant */
|
TOK_INTCON, /* Integer constant */
|
||||||
TOK_CHARCON, /* Character constant */
|
TOK_CHARCON, /* Character constant */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user