Move the test flags into the Flags bitset of struct ExprDesc

git-svn-id: svn://svn.cc65.org/cc65/trunk@3101 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2004-06-05 20:29:47 +00:00
parent aa39d98cbc
commit 5586527fcc
4 changed files with 104 additions and 59 deletions

View File

@@ -384,9 +384,8 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
/* Dereferenced lvalue */ /* Dereferenced lvalue */
Flags |= TypeOf (Expr->Type); Flags |= TypeOf (Expr->Type);
if (Expr->Test & E_FORCETEST) { if (ED_NeedsTest (Expr)) {
Flags |= CF_TEST; Flags |= CF_TEST;
Expr->Test &= ~E_FORCETEST;
} }
switch (ED_GetLoc (Expr)) { switch (ED_GetLoc (Expr)) {
@@ -433,6 +432,9 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
Internal ("Invalid location in ExprLoad: 0x%04X", ED_GetLoc (Expr)); Internal ("Invalid location in ExprLoad: 0x%04X", ED_GetLoc (Expr));
} }
/* Expression was tested */
ED_TestDone (Expr);
} else { } else {
/* An rvalue */ /* An rvalue */
if (ED_IsLocExpr (Expr)) { if (ED_IsLocExpr (Expr)) {
@@ -449,11 +451,11 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr)
} }
/* Are we testing this value? */ /* Are we testing this value? */
if (Expr->Test & E_FORCETEST) { if (ED_NeedsTest (Expr)) {
/* Yes, force a test */ /* Yes, force a test */
Flags |= TypeOf (Expr->Type); Flags |= TypeOf (Expr->Type);
g_test (Flags); g_test (Flags);
Expr->Test &= ~E_FORCETEST; ED_TestDone (Expr);
} }
} }
} }
@@ -1354,10 +1356,6 @@ void Store (ExprDesc* Expr, const type* StoreType)
/* Prepare the code generator flags */ /* Prepare the code generator flags */
Flags = TypeOf (StoreType); Flags = TypeOf (StoreType);
if (Expr->Test) {
/* Testing the value */
Flags |= CF_TEST;
}
/* Do the store depending on the location */ /* Do the store depending on the location */
switch (ED_GetLoc (Expr)) { switch (ED_GetLoc (Expr)) {
@@ -1403,7 +1401,7 @@ void Store (ExprDesc* Expr, const type* StoreType)
} }
/* Assume that each one of the stores will invalidate CC */ /* Assume that each one of the stores will invalidate CC */
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
} }
@@ -1670,7 +1668,7 @@ void hie10 (ExprDesc* Expr)
} else { } else {
g_bneg (TypeOf (Expr->Type)); g_bneg (TypeOf (Expr->Type));
ED_MakeRValExpr (Expr); ED_MakeRValExpr (Expr);
Expr->Test |= E_CC; /* bneg will set cc */ ED_TestDone (Expr); /* bneg will set cc */
} }
break; break;
@@ -1733,7 +1731,7 @@ void hie10 (ExprDesc* Expr)
RemoveCode (Mark); RemoveCode (Mark);
} }
ED_MakeConstAbs (Expr, Size, type_size_t); ED_MakeConstAbs (Expr, Size, type_size_t);
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
break; break;
default: default:
@@ -1983,7 +1981,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
Expr->Type = type_int; Expr->Type = type_int;
/* Condition codes are set */ /* Condition codes are set */
Expr->Test |= E_CC; ED_TestDone (Expr);
} }
} }
@@ -2225,7 +2223,7 @@ static void parseadd (ExprDesc* Expr)
} }
/* Condition codes not set */ /* Condition codes not set */
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
} }
@@ -2298,7 +2296,7 @@ static void parsesub (ExprDesc* Expr)
} }
/* Result is constant, condition codes not set */ /* Result is constant, condition codes not set */
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
} else { } else {
@@ -2341,7 +2339,7 @@ static void parsesub (ExprDesc* Expr)
/* Result is a rvalue in the primary register */ /* Result is a rvalue in the primary register */
ED_MakeRValExpr (Expr); ED_MakeRValExpr (Expr);
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
} }
@@ -2391,7 +2389,7 @@ static void parsesub (ExprDesc* Expr)
/* Result is a rvalue in the primary register */ /* Result is a rvalue in the primary register */
ED_MakeRValExpr (Expr); ED_MakeRValExpr (Expr);
Expr->Test &= ~E_CC; ED_MarkAsUntested (Expr);
} }
} }
@@ -2559,8 +2557,8 @@ static void hieAnd (ExprDesc* Expr, unsigned TrueLab, int* BoolOp)
lab = GetLocalLabel (); lab = GetLocalLabel ();
/* If the expr hasn't set condition codes, set the force-test flag */ /* If the expr hasn't set condition codes, set the force-test flag */
if ((Expr->Test & E_CC) == 0) { if (!ED_IsTested (Expr)) {
Expr->Test |= E_FORCETEST; ED_MarkForTest (Expr);
} }
/* Load the value */ /* Load the value */
@@ -2577,8 +2575,8 @@ static void hieAnd (ExprDesc* Expr, unsigned TrueLab, int* BoolOp)
/* Get rhs */ /* Get rhs */
hie2 (&Expr2); hie2 (&Expr2);
if ((Expr2.Test & E_CC) == 0) { if (!ED_IsTested (&Expr2)) {
Expr2.Test |= E_FORCETEST; ED_MarkForTest (&Expr2);
} }
ExprLoad (CF_FORCECHAR, &Expr2); ExprLoad (CF_FORCECHAR, &Expr2);
@@ -2596,7 +2594,7 @@ static void hieAnd (ExprDesc* Expr, unsigned TrueLab, int* BoolOp)
/* The result is an rvalue in primary */ /* The result is an rvalue in primary */
ED_MakeRValExpr (Expr); ED_MakeRValExpr (Expr);
Expr->Test |= E_CC; /* Condition codes are set */ ED_TestDone (Expr); /* Condition codes are set */
} }
} }
@@ -2621,8 +2619,8 @@ static void hieOr (ExprDesc *Expr)
if (CurTok.Tok == TOK_BOOL_OR) { if (CurTok.Tok == TOK_BOOL_OR) {
/* If the expr hasn't set condition codes, set the force-test flag */ /* If the expr hasn't set condition codes, set the force-test flag */
if ((Expr->Test & E_CC) == 0) { if (!ED_IsTested (Expr)) {
Expr->Test |= E_FORCETEST; ED_MarkForTest (Expr);
} }
/* Get first expr */ /* Get first expr */
@@ -2647,8 +2645,8 @@ static void hieOr (ExprDesc *Expr)
/* Get a subexpr */ /* Get a subexpr */
AndOp = 0; AndOp = 0;
hieAnd (&Expr2, TrueLab, &AndOp); hieAnd (&Expr2, TrueLab, &AndOp);
if ((Expr2.Test & E_CC) == 0) { if (!ED_IsTested (&Expr2)) {
Expr2.Test |= E_FORCETEST; ED_MarkForTest (&Expr2);
} }
ExprLoad (CF_FORCECHAR, &Expr2); ExprLoad (CF_FORCECHAR, &Expr2);
@@ -2659,7 +2657,7 @@ static void hieOr (ExprDesc *Expr)
/* The result is an rvalue in primary */ /* The result is an rvalue in primary */
ED_MakeRValExpr (Expr); ED_MakeRValExpr (Expr);
Expr->Test |= E_CC; /* Condition codes are set */ ED_TestDone (Expr); /* Condition codes are set */
} }
/* If we really had boolean ops, generate the end sequence */ /* If we really had boolean ops, generate the end sequence */
@@ -2697,9 +2695,9 @@ static void hieQuest (ExprDesc* Expr)
/* Check if it's a ternary expression */ /* Check if it's a ternary expression */
if (CurTok.Tok == TOK_QUEST) { if (CurTok.Tok == TOK_QUEST) {
NextToken (); NextToken ();
if ((Expr->Test & E_CC) == 0) { if (!ED_IsTested (Expr)) {
/* Condition codes not set, force a test */ /* Condition codes not set, request a test */
Expr->Test |= E_FORCETEST; ED_MarkForTest (Expr);
} }
ExprLoad (CF_NONE, Expr); ExprLoad (CF_NONE, Expr);
labf = GetLocalLabel (); labf = GetLocalLabel ();

View File

@@ -48,7 +48,7 @@
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
@@ -60,7 +60,6 @@ ExprDesc* ED_Init (ExprDesc* Expr)
Expr->Type = 0; Expr->Type = 0;
Expr->Val = 0; Expr->Val = 0;
Expr->Flags = 0; Expr->Flags = 0;
Expr->Test = 0;
Expr->Name = 0; Expr->Name = 0;
return Expr; return Expr;
} }
@@ -145,7 +144,6 @@ ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type)
Expr->Type = Type; Expr->Type = Type;
Expr->Val = Value; Expr->Val = Value;
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL; Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
Expr->Test = 0;
Expr->Name = 0; Expr->Name = 0;
return Expr; return Expr;
} }
@@ -159,7 +157,6 @@ ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value)
Expr->Type = type_int; Expr->Type = type_int;
Expr->Val = Value; Expr->Val = Value;
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL; Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
Expr->Test = 0;
Expr->Name = 0; Expr->Name = 0;
return Expr; return Expr;
} }
@@ -173,8 +170,8 @@ ExprDesc* ED_MakeRValExpr (ExprDesc* Expr)
{ {
Expr->Sym = 0; Expr->Sym = 0;
Expr->Val = 0; /* No offset */ Expr->Val = 0; /* No offset */
Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_RVAL); Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
Expr->Test = 0; Expr->Flags |= (E_LOC_EXPR | E_RTYPE_RVAL);
Expr->Name = 0; Expr->Name = 0;
return Expr; return Expr;
} }
@@ -188,8 +185,8 @@ ExprDesc* ED_MakeLValExpr (ExprDesc* Expr)
{ {
Expr->Sym = 0; Expr->Sym = 0;
Expr->Val = 0; /* No offset */ Expr->Val = 0; /* No offset */
Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_LVAL); Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET);
Expr->Test = 0; Expr->Flags |= (E_LOC_EXPR | E_RTYPE_LVAL);
Expr->Name = 0; Expr->Name = 0;
return Expr; return Expr;
} }
@@ -315,6 +312,16 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
Flags &= ~E_RTYPE_LVAL; Flags &= ~E_RTYPE_LVAL;
Sep = ','; Sep = ',';
} }
if (Flags & E_NEED_TEST) {
fprintf (F, "%cE_NEED_TEST", Sep);
Flags &= ~E_NEED_TEST;
Sep = ',';
}
if (Flags & E_CC_SET) {
fprintf (F, "%cE_CC_SET", Sep);
Flags &= ~E_CC_SET;
Sep = ',';
}
if (Flags) { if (Flags) {
fprintf (F, "%c,0x%04X", Sep, Flags); fprintf (F, "%c,0x%04X", Sep, Flags);
Sep = ','; Sep = ',';
@@ -322,16 +329,6 @@ void PrintExprDesc (FILE* F, ExprDesc* E)
if (Sep != '(') { if (Sep != '(') {
fputc (')', F); fputc (')', F);
} }
fputc ('\n', F);
fprintf (F, "\nTest: ");
if (E->Test & E_CC) {
fprintf (F, "E_CC ");
}
if (E->Test & E_FORCETEST) {
fprintf (F, "E_FORCETEST ");
}
fprintf (F, "\nName: 0x%08lX\n", E->Name); fprintf (F, "\nName: 0x%08lX\n", E->Name);
} }

View File

@@ -72,14 +72,14 @@ enum {
E_LOC_REGISTER | E_LOC_LITERAL, E_LOC_REGISTER | E_LOC_LITERAL,
/* Reference? */ /* Reference? */
E_MASK_RTYPE = 0x8000, E_MASK_RTYPE = 0x0100,
E_RTYPE_RVAL = 0x0000, E_RTYPE_RVAL = 0x0000,
E_RTYPE_LVAL = 0x8000 E_RTYPE_LVAL = 0x0100,
};
/* Defines for the test field of the expression descriptor */ /* Test */
#define E_CC 0x0001U /* Condition codes are set */ E_NEED_TEST = 0x0200, /* Expression needs a test to set cc */
#define E_FORCETEST 0x0002U /* Force test to set condition codes */ E_CC_SET = 0x0400 /* Condition codes are set */
};
/* Describe the result of an expression */ /* Describe the result of an expression */
typedef struct ExprDesc ExprDesc; typedef struct ExprDesc ExprDesc;
@@ -88,14 +88,13 @@ struct ExprDesc {
type* Type; /* Type array of expression */ type* Type; /* Type array of expression */
long Val; /* Value if expression constant */ long Val; /* Value if expression constant */
unsigned short Flags; unsigned short Flags;
unsigned short Test; /* */
unsigned long Name; /* Name or label number */ unsigned long Name; /* Name or label number */
}; };
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
@@ -210,7 +209,7 @@ INLINE void ED_MakeLVal (ExprDesc* Expr)
Expr->Flags |= E_RTYPE_LVAL; Expr->Flags |= E_RTYPE_LVAL;
} }
#else #else
# define ED_MakeLVal(Expr) do { (Expr)->Flags |= E_RTYPE_LVAL; } while (0) # define ED_MakeLVal(Expr) do { (Expr)->Flags |= E_RTYPE_LVAL; } while (0)
#endif #endif
#if defined(HAVE_INLINE) #if defined(HAVE_INLINE)
@@ -220,7 +219,58 @@ INLINE void ED_MakeRVal (ExprDesc* Expr)
Expr->Flags &= ~E_RTYPE_LVAL; Expr->Flags &= ~E_RTYPE_LVAL;
} }
#else #else
# define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0) # define ED_MakeRVal(Expr) do { (Expr)->Flags &= ~E_RTYPE_LVAL; } while (0)
#endif
#if defined(HAVE_INLINE)
INLINE void ED_MarkForTest (ExprDesc* Expr)
/* Mark the expression for a test. */
{
Expr->Flags |= E_NEED_TEST;
}
#else
# define ED_MarkForTest(Expr) do { (Expr)->Flags |= E_NEED_TEST; } while (0)
#endif
#if defined(HAVE_INLINE)
INLINE int ED_NeedsTest (const ExprDesc* Expr)
/* Check if the expression needs a test. */
{
return (Expr->Flags & E_NEED_TEST) != 0;
}
#else
# define ED_NeedsTest(Expr) (((Expr)->Flags & E_NEED_TEST) != 0)
#endif
#if defined(HAVE_INLINE)
INLINE void ED_TestDone (ExprDesc* Expr)
/* Mark the expression as tested and condition codes set. */
{
Expr->Flags = (Expr->Flags & ~E_NEED_TEST) | E_CC_SET;
}
#else
# define ED_TestDone(Expr) \
do { (Expr)->Flags = ((Expr)->Flags & ~E_NEED_TEST) | E_CC_SET; } while (0)
#endif
#if defined(HAVE_INLINE)
INLINE int ED_IsTested (const ExprDesc* Expr)
/* Check if the expression has set the condition codes. */
{
return (Expr->Flags & E_CC_SET) != 0;
}
#else
# define ED_IsTested(Expr) (((Expr)->Flags & E_CC_SET) != 0)
#endif
#if defined(HAVE_INLINE)
INLINE void ED_MarkAsUntested (ExprDesc* Expr)
/* Mark the expression as not tested (condition codes not set). */
{
Expr->Flags &= ~E_CC_SET;
}
#else
# define ED_MarkAsUntested(Expr) do { (Expr)->Flags &= ~E_CC_SET; } while (0)
#endif #endif
const char* ED_GetLabelName (const ExprDesc* Expr, long Offs); const char* ED_GetLabelName (const ExprDesc* Expr, long Offs);

View File

@@ -79,8 +79,8 @@ unsigned Test (unsigned Label, int Invert)
Result = TESTEXPR_UNKNOWN; Result = TESTEXPR_UNKNOWN;
/* If the expr hasn't set condition codes, set the force-test flag */ /* If the expr hasn't set condition codes, set the force-test flag */
if ((Expr.Test & E_CC) == 0) { if (!ED_IsTested (&Expr)) {
Expr.Test |= E_FORCETEST; ED_MarkForTest (&Expr);
} }
/* Load the value into the primary register */ /* Load the value into the primary register */