Don't search twice for a macro.
git-svn-id: svn://svn.cc65.org/cc65/trunk@5075 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
49cdfcf5b0
commit
241afdc738
4 changed files with 47 additions and 34 deletions
|
@ -95,7 +95,6 @@ struct IdDesc {
|
||||||
|
|
||||||
|
|
||||||
/* Struct that describes a macro definition */
|
/* Struct that describes a macro definition */
|
||||||
typedef struct Macro Macro;
|
|
||||||
struct Macro {
|
struct Macro {
|
||||||
HashNode Node; /* Hash list node */
|
HashNode Node; /* Hash list node */
|
||||||
Macro* List; /* List of all macros */
|
Macro* List; /* List of all macros */
|
||||||
|
@ -936,14 +935,13 @@ static void StartExpDefine (MacExp* E)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MacExpandStart (void)
|
void MacExpandStart (Macro* M)
|
||||||
/* Start expanding the macro in SVal */
|
/* Start expanding a macro */
|
||||||
{
|
{
|
||||||
MacExp* E;
|
MacExp* E;
|
||||||
|
|
||||||
/* Search for the macro */
|
/* Check the argument */
|
||||||
Macro* M = HT_FindEntry (&MacroTab, &CurTok.SVal);
|
PRECONDITION (M && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));
|
||||||
CHECK (M != 0 && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));
|
|
||||||
|
|
||||||
/* We cannot expand an incomplete macro */
|
/* We cannot expand an incomplete macro */
|
||||||
if (M->Incomplete) {
|
if (M->Incomplete) {
|
||||||
|
@ -984,16 +982,21 @@ void MacAbort (void)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int IsMacro (const StrBuf* Name)
|
Macro* FindMacro (const StrBuf* Name)
|
||||||
/* Return true if the given name is the name of a macro */
|
/* Try to find the macro with the given name and return it. If no macro with
|
||||||
|
* this name was found, return NULL.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
return (HT_Find (&MacroTab, Name) != 0);
|
Macro* M = HT_FindEntry (&MacroTab, Name);
|
||||||
|
return (M != 0 && M->Style == MAC_STYLE_CLASSIC)? M : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int IsDefine (const StrBuf* Name)
|
Macro* FindDefine (const StrBuf* Name)
|
||||||
/* Return true if the given name is the name of a define style macro */
|
/* Try to find the define style macro with the given name and return it. If no
|
||||||
|
* such macro was found, return NULL.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
Macro* M;
|
Macro* M;
|
||||||
|
|
||||||
|
@ -1004,7 +1007,7 @@ int IsDefine (const StrBuf* Name)
|
||||||
|
|
||||||
/* Check if we have such a macro */
|
/* Check if we have such a macro */
|
||||||
M = HT_FindEntry (&MacroTab, Name);
|
M = HT_FindEntry (&MacroTab, Name);
|
||||||
return (M != 0 && M->Style == MAC_STYLE_DEFINE);
|
return (M != 0 && M->Style == MAC_STYLE_DEFINE)? M : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,10 @@ struct StrBuf;
|
||||||
#define MAC_STYLE_CLASSIC 0
|
#define MAC_STYLE_CLASSIC 0
|
||||||
#define MAC_STYLE_DEFINE 1
|
#define MAC_STYLE_DEFINE 1
|
||||||
|
|
||||||
|
/* Macro as an opaque data type */
|
||||||
|
struct Macro;
|
||||||
|
typedef struct Macro Macro;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -74,17 +78,21 @@ void MacUndef (const StrBuf* Name, unsigned char Style);
|
||||||
* treated as if the macro didn't exist.
|
* treated as if the macro didn't exist.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void MacExpandStart (void);
|
void MacExpandStart (Macro* M);
|
||||||
/* Start expanding the macro in SVal */
|
/* Start expanding a macro */
|
||||||
|
|
||||||
void MacAbort (void);
|
void MacAbort (void);
|
||||||
/* Abort the current macro expansion */
|
/* Abort the current macro expansion */
|
||||||
|
|
||||||
int IsMacro (const StrBuf* Name);
|
Macro* FindMacro (const StrBuf* Name);
|
||||||
/* Return true if the given name is the name of a macro */
|
/* Try to find the macro with the given name and return it. If no macro with
|
||||||
|
* this name was found, return NULL.
|
||||||
|
*/
|
||||||
|
|
||||||
int IsDefine (const StrBuf* Name);
|
Macro* FindDefine (const StrBuf* Name);
|
||||||
/* Return true if the given name is the name of a define style macro */
|
/* Try to find the define style macro with the given name and return it. If no
|
||||||
|
* such macro was found, return NULL.
|
||||||
|
*/
|
||||||
|
|
||||||
int InMacExpansion (void);
|
int InMacExpansion (void);
|
||||||
/* Return true if we're currently expanding a macro */
|
/* Return true if we're currently expanding a macro */
|
||||||
|
|
|
@ -596,7 +596,7 @@ static void OneLine (void)
|
||||||
Segment* Seg = 0;
|
Segment* Seg = 0;
|
||||||
unsigned long PC = 0;
|
unsigned long PC = 0;
|
||||||
SymEntry* Sym = 0;
|
SymEntry* Sym = 0;
|
||||||
int Macro = 0;
|
Macro* Mac = 0;
|
||||||
int Instr = -1;
|
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
|
||||||
|
@ -606,8 +606,8 @@ static void OneLine (void)
|
||||||
InitListingLine ();
|
InitListingLine ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Single colon means unnamed label */
|
||||||
if (CurTok.Tok == TOK_COLON) {
|
if (CurTok.Tok == TOK_COLON) {
|
||||||
/* An unnamed label */
|
|
||||||
ULabDef ();
|
ULabDef ();
|
||||||
NextTok ();
|
NextTok ();
|
||||||
}
|
}
|
||||||
|
@ -620,11 +620,11 @@ static void OneLine (void)
|
||||||
/* Macros and symbols cannot use instruction names */
|
/* Macros and symbols cannot use instruction names */
|
||||||
Instr = FindInstruction (&CurTok.SVal);
|
Instr = FindInstruction (&CurTok.SVal);
|
||||||
if (Instr < 0) {
|
if (Instr < 0) {
|
||||||
Macro = IsMacro (&CurTok.SVal);
|
Mac = FindMacro (&CurTok.SVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Macros and symbols may use the names of instructions */
|
/* Macros and symbols may use the names of instructions */
|
||||||
Macro = IsMacro (&CurTok.SVal);
|
Mac = FindMacro (&CurTok.SVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ static void OneLine (void)
|
||||||
*/
|
*/
|
||||||
if (CurTok.Tok == TOK_LOCAL_IDENT ||
|
if (CurTok.Tok == TOK_LOCAL_IDENT ||
|
||||||
CurTok.Tok == TOK_NAMESPACE ||
|
CurTok.Tok == TOK_NAMESPACE ||
|
||||||
(CurTok.Tok == TOK_IDENT && Instr < 0 && !Macro)) {
|
(CurTok.Tok == TOK_IDENT && Instr < 0 && Mac == 0)) {
|
||||||
|
|
||||||
/* Did we have whitespace before the ident? */
|
/* Did we have whitespace before the ident? */
|
||||||
int HadWS = CurTok.WS;
|
int HadWS = CurTok.WS;
|
||||||
|
@ -715,11 +715,11 @@ static void OneLine (void)
|
||||||
/* Macros and symbols cannot use instruction names */
|
/* Macros and symbols cannot use instruction names */
|
||||||
Instr = FindInstruction (&CurTok.SVal);
|
Instr = FindInstruction (&CurTok.SVal);
|
||||||
if (Instr < 0) {
|
if (Instr < 0) {
|
||||||
Macro = IsMacro (&CurTok.SVal);
|
Mac = FindMacro (&CurTok.SVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Macros and symbols may use the names of instructions */
|
/* Macros and symbols may use the names of instructions */
|
||||||
Macro = IsMacro (&CurTok.SVal);
|
Mac = FindMacro (&CurTok.SVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -729,9 +729,9 @@ static void OneLine (void)
|
||||||
if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
|
if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
|
||||||
/* A control command */
|
/* A control command */
|
||||||
HandlePseudo ();
|
HandlePseudo ();
|
||||||
} else if (Macro) {
|
} else if (Mac != 0) {
|
||||||
/* A macro expansion */
|
/* A macro expansion */
|
||||||
MacExpandStart ();
|
MacExpandStart (Mac);
|
||||||
} else if (Instr >= 0 ||
|
} else if (Instr >= 0 ||
|
||||||
(UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
|
(UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
|
||||||
/* A mnemonic - assemble one instruction */
|
/* A mnemonic - assemble one instruction */
|
||||||
|
|
|
@ -818,6 +818,8 @@ static int Sweet16Reg (const StrBuf* Id)
|
||||||
void NextRawTok (void)
|
void NextRawTok (void)
|
||||||
/* Read the next raw token from the input stream */
|
/* Read the next raw token from the input stream */
|
||||||
{
|
{
|
||||||
|
Macro* M;
|
||||||
|
|
||||||
/* If we've a forced end of assembly, don't read further */
|
/* If we've a forced end of assembly, don't read further */
|
||||||
if (ForcedEnd) {
|
if (ForcedEnd) {
|
||||||
CurTok.Tok = TOK_EOF;
|
CurTok.Tok = TOK_EOF;
|
||||||
|
@ -827,9 +829,9 @@ void NextRawTok (void)
|
||||||
Restart:
|
Restart:
|
||||||
/* Check if we have tokens from another input source */
|
/* Check if we have tokens from another input source */
|
||||||
if (InputFromStack ()) {
|
if (InputFromStack ()) {
|
||||||
if (CurTok.Tok == TOK_IDENT && IsDefine (&CurTok.SVal)) {
|
if (CurTok.Tok == TOK_IDENT && (M = FindDefine (&CurTok.SVal)) != 0) {
|
||||||
/* This is a define style macro - expand it */
|
/* This is a define style macro - expand it */
|
||||||
MacExpandStart ();
|
MacExpandStart (M);
|
||||||
goto Restart;
|
goto Restart;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -1001,9 +1003,9 @@ Again:
|
||||||
/* An identifier with a dot. Check if it's a define style
|
/* An identifier with a dot. Check if it's a define style
|
||||||
* macro.
|
* macro.
|
||||||
*/
|
*/
|
||||||
if (IsDefine (&CurTok.SVal)) {
|
if ((M = FindDefine (&CurTok.SVal)) != 0) {
|
||||||
/* This is a define style macro - expand it */
|
/* This is a define style macro - expand it */
|
||||||
MacExpandStart ();
|
MacExpandStart (M);
|
||||||
goto Restart;
|
goto Restart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1108,9 +1110,9 @@ Again:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for define style macro */
|
/* Check for define style macro */
|
||||||
if (IsDefine (&CurTok.SVal)) {
|
if ((M = FindDefine (&CurTok.SVal)) != 0) {
|
||||||
/* Macro - expand it */
|
/* Macro - expand it */
|
||||||
MacExpandStart ();
|
MacExpandStart (M);
|
||||||
goto Restart;
|
goto Restart;
|
||||||
} else {
|
} else {
|
||||||
/* An identifier */
|
/* An identifier */
|
||||||
|
|
Loading…
Add table
Reference in a new issue