2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* condasm.c */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Conditional assembly support for ca65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2011-01-16 14:51:13 +00:00
|
|
|
/* (C) 2000-2011, Ullrich von Bassewitz */
|
2010-07-26 17:28:34 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-28 20:55:12 +00:00
|
|
|
/* ca65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "expr.h"
|
2000-11-28 20:55:12 +00:00
|
|
|
#include "instr.h"
|
2011-01-29 18:43:36 +00:00
|
|
|
#include "lineinfo.h"
|
2000-06-03 11:15:11 +00:00
|
|
|
#include "nexttok.h"
|
2003-11-06 11:22:31 +00:00
|
|
|
#include "symbol.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "symtab.h"
|
|
|
|
#include "condasm.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Maximum count of nested .ifs */
|
2013-05-09 11:56:54 +00:00
|
|
|
#define MAX_IFS 256
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Set of bitmapped flags for the if descriptor */
|
|
|
|
enum {
|
2013-05-09 11:56:54 +00:00
|
|
|
ifNone = 0x0000, /* No flag */
|
|
|
|
ifCond = 0x0001, /* IF condition was true */
|
2011-06-09 11:23:37 +00:00
|
|
|
ifParentCond= 0x0002, /* IF condition of parent */
|
2013-05-09 11:56:54 +00:00
|
|
|
ifElse = 0x0004, /* We had a .ELSE branch */
|
|
|
|
ifNeedTerm = 0x0008, /* Need .ENDIF termination */
|
2000-05-28 13:40:48 +00:00
|
|
|
};
|
|
|
|
|
2011-06-05 14:28:56 +00:00
|
|
|
/* The overall .IF condition */
|
|
|
|
int IfCond = 1;
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* struct IfDesc */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* One .IF descriptor */
|
2001-09-07 21:42:40 +00:00
|
|
|
typedef struct IfDesc IfDesc;
|
2002-08-11 14:49:42 +00:00
|
|
|
struct IfDesc {
|
2013-05-09 11:56:54 +00:00
|
|
|
unsigned Flags; /* Bitmapped flags, see above */
|
2011-01-29 18:43:36 +00:00
|
|
|
Collection LineInfos; /* File position of the .IF */
|
2013-05-09 11:56:54 +00:00
|
|
|
const char* Name; /* Name of the directive */
|
2000-05-28 13:40:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The .IF stack */
|
|
|
|
static IfDesc IfStack [MAX_IFS];
|
|
|
|
static unsigned IfCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static IfDesc* GetCurrentIf (void)
|
|
|
|
/* Return the current .IF descriptor */
|
|
|
|
{
|
|
|
|
if (IfCount == 0) {
|
2013-05-09 11:56:54 +00:00
|
|
|
return 0;
|
2000-05-28 13:40:48 +00:00
|
|
|
} else {
|
2011-06-05 14:28:56 +00:00
|
|
|
return &IfStack[IfCount-1];
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-09 11:23:37 +00:00
|
|
|
static int GetOverallIfCond (void)
|
|
|
|
/* Get the overall condition based on all conditions on the stack. */
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2011-06-09 11:23:37 +00:00
|
|
|
/* Since the last entry contains the overall condition of the parent, we
|
2014-06-30 09:10:35 +00:00
|
|
|
** must check it in combination of the current condition. If there is no
|
|
|
|
** last entry, the overall condition is true.
|
|
|
|
*/
|
2011-06-09 11:23:37 +00:00
|
|
|
return (IfCount == 0) ||
|
|
|
|
((IfStack[IfCount-1].Flags & (ifCond | ifParentCond)) == (ifCond | ifParentCond));
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-05 14:28:56 +00:00
|
|
|
static void CalcOverallIfCond (void)
|
2014-06-30 09:10:35 +00:00
|
|
|
/* Calculate the overall condition, based on all conditions on the stack. */
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2011-06-09 11:23:37 +00:00
|
|
|
IfCond = GetOverallIfCond ();
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void SetIfCond (IfDesc* ID, int C)
|
|
|
|
/* Set the .IF condition */
|
|
|
|
{
|
|
|
|
if (C) {
|
2013-05-09 11:56:54 +00:00
|
|
|
ID->Flags |= ifCond;
|
2000-05-28 13:40:48 +00:00
|
|
|
} else {
|
2013-05-09 11:56:54 +00:00
|
|
|
ID->Flags &= ~ifCond;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-05 14:28:56 +00:00
|
|
|
static void ElseClause (IfDesc* ID, const char* Directive)
|
|
|
|
/* Enter an .ELSE clause */
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2011-06-05 14:28:56 +00:00
|
|
|
/* Check if we have an open .IF - otherwise .ELSE is not allowed */
|
|
|
|
if (ID == 0) {
|
|
|
|
Error ("Unexpected %s", Directive);
|
|
|
|
return;
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-05 14:28:56 +00:00
|
|
|
/* Check for a duplicate else, then remember that we had one */
|
|
|
|
if (ID->Flags & ifElse) {
|
|
|
|
/* We already had a .ELSE ! */
|
|
|
|
Error ("Duplicate .ELSE");
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
ID->Flags |= ifElse;
|
|
|
|
|
|
|
|
/* Condition is inverted now */
|
|
|
|
ID->Flags ^= ifCond;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-09 11:23:37 +00:00
|
|
|
static IfDesc* AllocIf (const char* Directive, int NeedTerm)
|
|
|
|
/* Alloc a new element from the .IF stack */
|
|
|
|
{
|
|
|
|
IfDesc* ID;
|
|
|
|
|
|
|
|
/* Check for stack overflow */
|
|
|
|
if (IfCount >= MAX_IFS) {
|
2013-05-09 11:56:54 +00:00
|
|
|
Fatal ("Too many nested .IFs");
|
2011-06-09 11:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the next element */
|
|
|
|
ID = &IfStack[IfCount];
|
|
|
|
|
|
|
|
/* Initialize elements */
|
|
|
|
ID->Flags = NeedTerm? ifNeedTerm : ifNone;
|
|
|
|
if (GetOverallIfCond ()) {
|
|
|
|
/* The parents .IF condition is true */
|
|
|
|
ID->Flags |= ifParentCond;
|
|
|
|
}
|
|
|
|
ID->LineInfos = EmptyCollection;
|
2011-08-18 14:36:38 +00:00
|
|
|
GetFullLineInfo (&ID->LineInfos);
|
2011-06-09 11:23:37 +00:00
|
|
|
ID->Name = Directive;
|
|
|
|
|
|
|
|
/* One more slot allocated */
|
|
|
|
++IfCount;
|
|
|
|
|
|
|
|
/* Return the result */
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void FreeIf (void)
|
|
|
|
/* Free all .IF descriptors until we reach one with the NeedTerm bit set */
|
|
|
|
{
|
|
|
|
int Done;
|
|
|
|
do {
|
2013-05-09 11:56:54 +00:00
|
|
|
IfDesc* ID = GetCurrentIf();
|
|
|
|
if (ID == 0) {
|
|
|
|
Error (" Unexpected .ENDIF");
|
|
|
|
Done = 1;
|
|
|
|
} else {
|
|
|
|
Done = (ID->Flags & ifNeedTerm) != 0;
|
2011-08-18 14:36:38 +00:00
|
|
|
ReleaseFullLineInfo (&ID->LineInfos);
|
2011-08-02 16:16:37 +00:00
|
|
|
DoneCollection (&ID->LineInfos);
|
2011-06-09 11:23:37 +00:00
|
|
|
--IfCount;
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2011-06-09 11:23:37 +00:00
|
|
|
} while (!Done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DoConditionals (void)
|
|
|
|
/* Catch all for conditional directives */
|
|
|
|
{
|
|
|
|
IfDesc* D;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
switch (CurTok.Tok) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_ELSE:
|
|
|
|
D = GetCurrentIf ();
|
2011-06-05 14:28:56 +00:00
|
|
|
|
|
|
|
/* Allow an .ELSE */
|
|
|
|
ElseClause (D, ".ELSE");
|
|
|
|
|
|
|
|
/* Remember the data for the .ELSE */
|
2011-06-09 11:27:33 +00:00
|
|
|
if (D) {
|
2011-08-18 14:36:38 +00:00
|
|
|
ReleaseFullLineInfo (&D->LineInfos);
|
|
|
|
GetFullLineInfo (&D->LineInfos);
|
2011-06-09 11:27:33 +00:00
|
|
|
D->Name = ".ELSE";
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
|
|
|
|
/* Calculate the new overall condition */
|
|
|
|
CalcOverallIfCond ();
|
|
|
|
|
|
|
|
/* Skip .ELSE */
|
2013-05-09 11:56:54 +00:00
|
|
|
NextTok ();
|
|
|
|
ExpectSep ();
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_ELSEIF:
|
|
|
|
D = GetCurrentIf ();
|
2011-06-05 14:28:56 +00:00
|
|
|
/* Handle as if there was an .ELSE first */
|
|
|
|
ElseClause (D, ".ELSEIF");
|
|
|
|
|
2011-06-07 17:16:18 +00:00
|
|
|
/* Calculate the new overall if condition */
|
|
|
|
CalcOverallIfCond ();
|
|
|
|
|
2011-06-05 14:28:56 +00:00
|
|
|
/* Allocate and prepare a new descriptor */
|
|
|
|
D = AllocIf (".ELSEIF", 0);
|
|
|
|
NextTok ();
|
|
|
|
|
|
|
|
/* Ignore the new condition if we are inside a false .ELSE
|
2014-06-30 09:10:35 +00:00
|
|
|
** branch. This way we won't get any errors about undefined
|
|
|
|
** symbols or similar...
|
|
|
|
*/
|
2011-06-07 17:16:18 +00:00
|
|
|
if (IfCond) {
|
2011-06-05 14:28:56 +00:00
|
|
|
SetIfCond (D, ConstExpression ());
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the new overall condition */
|
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
2011-06-05 14:28:56 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_ENDIF:
|
|
|
|
/* We're done with this .IF.. - remove the descriptor(s) */
|
|
|
|
FreeIf ();
|
2011-06-05 14:28:56 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Be sure not to read the next token until the .IF stack
|
2014-06-30 09:10:35 +00:00
|
|
|
** has been cleanup up, since we may be at end of file.
|
|
|
|
*/
|
2013-05-09 11:56:54 +00:00
|
|
|
NextTok ();
|
|
|
|
ExpectSep ();
|
2011-06-05 14:28:56 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Get the new overall condition */
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_IF:
|
|
|
|
D = AllocIf (".IF", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
2011-06-05 14:28:56 +00:00
|
|
|
SetIfCond (D, ConstExpression ());
|
|
|
|
ExpectSep ();
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_IFBLANK:
|
|
|
|
D = AllocIf (".IFBLANK", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
2011-01-16 16:05:43 +00:00
|
|
|
if (TokIsSep (CurTok.Tok)) {
|
2002-09-14 21:05:12 +00:00
|
|
|
SetIfCond (D, 1);
|
|
|
|
} else {
|
2013-05-09 11:56:54 +00:00
|
|
|
SetIfCond (D, 0);
|
2002-09-14 21:05:12 +00:00
|
|
|
SkipUntilSep ();
|
|
|
|
}
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFCONST:
|
|
|
|
D = AllocIf (".IFCONST", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
ExprNode* Expr = Expression();
|
|
|
|
SetIfCond (D, IsConstExpr (Expr, 0));
|
|
|
|
FreeExpr (Expr);
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFDEF:
|
|
|
|
D = AllocIf (".IFDEF", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
|
|
|
|
SetIfCond (D, Sym != 0 && SymIsDef (Sym));
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_IFNBLANK:
|
|
|
|
D = AllocIf (".IFNBLANK", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
2011-01-16 16:05:43 +00:00
|
|
|
if (TokIsSep (CurTok.Tok)) {
|
2002-09-14 20:56:37 +00:00
|
|
|
SetIfCond (D, 0);
|
|
|
|
} else {
|
2013-05-09 11:56:54 +00:00
|
|
|
SetIfCond (D, 1);
|
2002-09-14 20:56:37 +00:00
|
|
|
SkipUntilSep ();
|
|
|
|
}
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFNCONST:
|
|
|
|
D = AllocIf (".IFNCONST", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
ExprNode* Expr = Expression();
|
|
|
|
SetIfCond (D, !IsConstExpr (Expr, 0));
|
|
|
|
FreeExpr (Expr);
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFNDEF:
|
|
|
|
D = AllocIf (".IFNDEF", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
|
|
|
|
SetIfCond (D, Sym == 0 || !SymIsDef (Sym));
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFNREF:
|
|
|
|
D = AllocIf (".IFNREF", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
|
|
|
|
SetIfCond (D, Sym == 0 || !SymIsRef (Sym));
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFP02:
|
|
|
|
D = AllocIf (".IFP02", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SetIfCond (D, GetCPU() == CPU_6502);
|
|
|
|
}
|
|
|
|
ExpectSep ();
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
2016-09-07 17:21:24 +00:00
|
|
|
case TOK_IFP4510:
|
|
|
|
D = AllocIf (".IFP4510", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SetIfCond (D, GetCPU() == CPU_4510);
|
|
|
|
}
|
|
|
|
ExpectSep ();
|
|
|
|
CalcOverallIfCond ();
|
|
|
|
break;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
case TOK_IFP816:
|
|
|
|
D = AllocIf (".IFP816", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SetIfCond (D, GetCPU() == CPU_65816);
|
|
|
|
}
|
|
|
|
ExpectSep ();
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFPC02:
|
|
|
|
D = AllocIf (".IFPC02", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SetIfCond (D, GetCPU() == CPU_65C02);
|
|
|
|
}
|
|
|
|
ExpectSep ();
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFPSC02:
|
|
|
|
D = AllocIf (".IFPSC02", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SetIfCond (D, GetCPU() == CPU_65SC02);
|
|
|
|
}
|
|
|
|
ExpectSep ();
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_IFREF:
|
|
|
|
D = AllocIf (".IFREF", 1);
|
|
|
|
NextTok ();
|
|
|
|
if (IfCond) {
|
|
|
|
SymEntry* Sym = ParseAnySymName (SYM_FIND_EXISTING);
|
|
|
|
SetIfCond (D, Sym != 0 && SymIsRef (Sym));
|
|
|
|
ExpectSep ();
|
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
CalcOverallIfCond ();
|
2013-05-09 11:56:54 +00:00
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
default:
|
|
|
|
/* Skip tokens */
|
|
|
|
NextTok ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-01-16 16:05:43 +00:00
|
|
|
} while (IfCond == 0 && CurTok.Tok != TOK_EOF);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-17 18:49:50 +00:00
|
|
|
int CheckConditionals (void)
|
|
|
|
/* Check if the current token is one that starts a conditional directive, and
|
2014-06-30 09:10:35 +00:00
|
|
|
** call DoConditionals if so. Return true if a conditional directive was found,
|
|
|
|
** return false otherwise.
|
|
|
|
*/
|
2003-11-17 18:49:50 +00:00
|
|
|
{
|
2011-01-16 16:05:43 +00:00
|
|
|
switch (CurTok.Tok) {
|
2003-11-17 18:49:50 +00:00
|
|
|
case TOK_ELSE:
|
|
|
|
case TOK_ELSEIF:
|
|
|
|
case TOK_ENDIF:
|
|
|
|
case TOK_IF:
|
|
|
|
case TOK_IFBLANK:
|
|
|
|
case TOK_IFCONST:
|
|
|
|
case TOK_IFDEF:
|
|
|
|
case TOK_IFNBLANK:
|
|
|
|
case TOK_IFNCONST:
|
|
|
|
case TOK_IFNDEF:
|
|
|
|
case TOK_IFNREF:
|
|
|
|
case TOK_IFP02:
|
2016-09-07 17:21:24 +00:00
|
|
|
case TOK_IFP4510:
|
2003-11-17 18:49:50 +00:00
|
|
|
case TOK_IFP816:
|
|
|
|
case TOK_IFPC02:
|
|
|
|
case TOK_IFPSC02:
|
|
|
|
case TOK_IFREF:
|
|
|
|
DoConditionals ();
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
void CheckOpenIfs (void)
|
|
|
|
/* Called from the scanner before closing an input file. Will check for any
|
2014-06-30 09:10:35 +00:00
|
|
|
** open .ifs in this file.
|
|
|
|
*/
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2011-01-29 18:43:36 +00:00
|
|
|
const LineInfo* LI;
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
while (1) {
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Get the current file number and check if the topmost entry on the
|
2014-06-30 09:10:35 +00:00
|
|
|
** .IF stack was inserted with this file number
|
|
|
|
*/
|
2013-05-09 11:56:54 +00:00
|
|
|
IfDesc* D = GetCurrentIf ();
|
|
|
|
if (D == 0) {
|
|
|
|
/* There are no open .IFs */
|
|
|
|
break;
|
|
|
|
}
|
2000-06-03 11:15:11 +00:00
|
|
|
|
2011-01-29 18:43:36 +00:00
|
|
|
LI = CollConstAt (&D->LineInfos, 0);
|
2013-05-09 11:56:54 +00:00
|
|
|
if (GetSourcePos (LI)->Name != CurTok.Pos.Name) {
|
|
|
|
/* The .if is from another file, bail out */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start of .if is in the file we're about to leave */
|
|
|
|
LIError (&D->LineInfos, "Conditional assembly branch was never closed");
|
|
|
|
FreeIf ();
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
|
|
|
|
/* Calculate the new overall .IF condition */
|
|
|
|
CalcOverallIfCond ();
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-03 11:15:11 +00:00
|
|
|
unsigned GetIfStack (void)
|
|
|
|
/* Get the current .IF stack pointer */
|
|
|
|
{
|
|
|
|
return IfCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CleanupIfStack (unsigned SP)
|
|
|
|
/* Cleanup the .IF stack, remove anything above the given stack pointer */
|
|
|
|
{
|
|
|
|
while (IfCount > SP) {
|
2013-05-09 11:56:54 +00:00
|
|
|
FreeIf ();
|
2000-06-03 11:15:11 +00:00
|
|
|
}
|
2011-06-05 14:28:56 +00:00
|
|
|
|
|
|
|
/* Calculate the new overall .IF condition */
|
|
|
|
CalcOverallIfCond ();
|
2000-06-03 11:15:11 +00:00
|
|
|
}
|