/* Struct that describes a macro definition */
/* Struct that describes a macro definition */
-typedef struct Macro Macro;
struct Macro {
HashNode Node; /* Hash list node */
Macro* List; /* List of all macros */
struct Macro {
HashNode Node; /* Hash list node */
Macro* List; /* List of all macros */
/* Check if we should abort this macro */
if (DoMacAbort) {
/* Check if we should abort this macro */
if (DoMacAbort) {
DoMacAbort = 0;
/* Abort any open .IF statements in this macro expansion */
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 */
- /* 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) {
/* 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.
+ */
/* Check if we have such a macro */
M = HT_FindEntry (&MacroTab, Name);
/* 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
#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.
*/
* 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 */
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 */
int InMacExpansion (void);
/* Return true if we're currently expanding a macro */
Segment* Seg = 0;
unsigned long PC = 0;
SymEntry* Sym = 0;
Segment* Seg = 0;
unsigned long PC = 0;
SymEntry* Sym = 0;
int Instr = -1;
/* Initialize the new listing line if we are actually reading from file
int Instr = -1;
/* Initialize the new listing line if we are actually reading from file
+ /* Single colon means unnamed label */
if (CurTok.Tok == TOK_COLON) {
if (CurTok.Tok == TOK_COLON) {
ULabDef ();
NextTok ();
}
ULabDef ();
NextTok ();
}
/* Macros and symbols cannot use instruction names */
Instr = FindInstruction (&CurTok.SVal);
if (Instr < 0) {
/* 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 */
}
} 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 ||
*/
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;
/* 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) {
/* 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 */
}
} 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 ();
if (CurTok.Tok >= TOK_FIRSTPSEUDO && CurTok.Tok <= TOK_LASTPSEUDO) {
/* A control command */
HandlePseudo ();
} else if (Instr >= 0 ||
(UbiquitousIdents && ((Instr = FindInstruction (&CurTok.SVal)) >= 0))) {
/* A mnemonic - assemble one instruction */
} 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 */
{
void NextRawTok (void)
/* Read the next raw token from the input stream */
{
/* If we've a forced end of assembly, don't read further */
if (ForcedEnd) {
CurTok.Tok = TOK_EOF;
/* 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 ()) {
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 */
/* This is a define style macro - expand it */
/* An identifier with a dot. Check if it's a define style
* macro.
*/
/* 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 */
/* This is a define style macro - expand it */
}
/* Check for define style macro */
}
/* Check for define style macro */
- if (IsDefine (&CurTok.SVal)) {
+ if ((M = FindDefine (&CurTok.SVal)) != 0) {
goto Restart;
} else {
/* An identifier */
goto Restart;
} else {
/* An identifier */