/* Struct that describes a macro definition */
-typedef struct Macro Macro;
struct Macro {
HashNode Node; /* Hash list node */
Macro* List; /* List of all macros */
/* Check if we should abort this macro */
if (DoMacAbort) {
- /* Reset the flag */
+ /* Reset the flag */
DoMacAbort = 0;
/* Abort any open .IF statements in this macro expansion */
-void MacExpandStart (void)
-/* Start expanding the macro in SVal */
+void MacExpandStart (Macro* M)
+/* Start expanding a macro */
{
MacExp* E;
- /* Search for the macro */
- Macro* M = HT_FindEntry (&MacroTab, &CurTok.SVal);
- CHECK (M != 0 && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));
+ /* Check the argument */
+ PRECONDITION (M && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));
/* We cannot expand an incomplete macro */
if (M->Incomplete) {
-int IsMacro (const StrBuf* Name)
-/* Return true if the given name is the name of a macro */
+Macro* FindMacro (const StrBuf* Name)
+/* 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)
-/* Return true if the given name is the name of a define style macro */
+Macro* FindDefine (const StrBuf* Name)
+/* Try to find the define style macro with the given name and return it. If no
+ * such macro was found, return NULL.
+ */
{
Macro* M;
/* Check if we have such a macro */
M = HT_FindEntry (&MacroTab, Name);
- return (M != 0 && M->Style == MAC_STYLE_DEFINE);
+ return (M != 0 && M->Style == MAC_STYLE_DEFINE)? M : 0;
}
#define MAC_STYLE_CLASSIC 0
#define MAC_STYLE_DEFINE 1
+/* Macro as an opaque data type */
+struct Macro;
+typedef struct Macro Macro;
+
/*****************************************************************************/
* treated as if the macro didn't exist.
*/
-void MacExpandStart (void);
-/* Start expanding the macro in SVal */
+void MacExpandStart (Macro* M);
+/* Start expanding a macro */
void MacAbort (void);
/* Abort the current macro expansion */
-int IsMacro (const StrBuf* Name);
-/* Return true if the given name is the name of a macro */
+Macro* FindMacro (const StrBuf* Name);
+/* 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);
-/* Return true if the given name is the name of a define style macro */
+Macro* FindDefine (const StrBuf* Name);
+/* 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);
/* Return true if we're currently expanding a macro */
Segment* Seg = 0;
unsigned long PC = 0;
SymEntry* Sym = 0;
- int Macro = 0;
+ Macro* Mac = 0;
int Instr = -1;
/* Initialize the new listing line if we are actually reading from file
InitListingLine ();
}
+ /* Single colon means unnamed label */
if (CurTok.Tok == TOK_COLON) {
- /* An unnamed label */
ULabDef ();
NextTok ();
}
/* Macros and symbols cannot use instruction names */
Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) {
- Macro = IsMacro (&CurTok.SVal);
+ Mac = FindMacro (&CurTok.SVal);
}
} else {
/* Macros and symbols may use the names of instructions */
- Macro = IsMacro (&CurTok.SVal);
+ Mac = FindMacro (&CurTok.SVal);
}
}
*/
if (CurTok.Tok == TOK_LOCAL_IDENT ||
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? */
int HadWS = CurTok.WS;
/* Macros and symbols cannot use instruction names */
Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) {
- Macro = IsMacro (&CurTok.SVal);
+ Mac = FindMacro (&CurTok.SVal);
}
} else {
/* Macros and symbols may use the names of instructions */
- Macro = IsMacro (&CurTok.SVal);
+ Mac = FindMacro (&CurTok.SVal);
}
}
}
if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
/* A control command */
HandlePseudo ();
- } else if (Macro) {
+ } else if (Mac != 0) {
/* A macro expansion */
- MacExpandStart ();
+ MacExpandStart (Mac);
} else if (Instr >= 0 ||
(UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
/* A mnemonic - assemble one instruction */
void NextRawTok (void)
/* Read the next raw token from the input stream */
{
+ Macro* M;
+
/* If we've a forced end of assembly, don't read further */
if (ForcedEnd) {
CurTok.Tok = TOK_EOF;
Restart:
/* Check if we have tokens from another input source */
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 */
- MacExpandStart ();
+ MacExpandStart (M);
goto Restart;
}
return;
/* An identifier with a dot. Check if it's a define style
* macro.
*/
- if (IsDefine (&CurTok.SVal)) {
+ if ((M = FindDefine (&CurTok.SVal)) != 0) {
/* This is a define style macro - expand it */
- MacExpandStart ();
+ MacExpandStart (M);
goto Restart;
}
}
/* Check for define style macro */
- if (IsDefine (&CurTok.SVal)) {
+ if ((M = FindDefine (&CurTok.SVal)) != 0) {
/* Macro - expand it */
- MacExpandStart ();
+ MacExpandStart (M);
goto Restart;
} else {
/* An identifier */