From 5586527fccfcffe65d4ef9eba666f8c3b0d3b3cc Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 5 Jun 2004 20:29:47 +0000 Subject: [PATCH] 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 --- src/cc65/expr.c | 56 +++++++++++++++++------------------- src/cc65/exprdesc.c | 33 ++++++++++----------- src/cc65/exprdesc.h | 70 ++++++++++++++++++++++++++++++++++++++------- src/cc65/testexpr.c | 4 +-- 4 files changed, 104 insertions(+), 59 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 0057e272c..c6fb1092a 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -384,9 +384,8 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr) /* Dereferenced lvalue */ Flags |= TypeOf (Expr->Type); - if (Expr->Test & E_FORCETEST) { + if (ED_NeedsTest (Expr)) { Flags |= CF_TEST; - Expr->Test &= ~E_FORCETEST; } switch (ED_GetLoc (Expr)) { @@ -433,6 +432,9 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr) Internal ("Invalid location in ExprLoad: 0x%04X", ED_GetLoc (Expr)); } + /* Expression was tested */ + ED_TestDone (Expr); + } else { /* An rvalue */ if (ED_IsLocExpr (Expr)) { @@ -449,11 +451,11 @@ void ExprLoad (unsigned Flags, ExprDesc* Expr) } /* Are we testing this value? */ - if (Expr->Test & E_FORCETEST) { + if (ED_NeedsTest (Expr)) { /* Yes, force a test */ Flags |= TypeOf (Expr->Type); 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 */ Flags = TypeOf (StoreType); - if (Expr->Test) { - /* Testing the value */ - Flags |= CF_TEST; - } /* Do the store depending on the location */ 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 */ - Expr->Test &= ~E_CC; + ED_MarkAsUntested (Expr); } @@ -1670,7 +1668,7 @@ void hie10 (ExprDesc* Expr) } else { g_bneg (TypeOf (Expr->Type)); ED_MakeRValExpr (Expr); - Expr->Test |= E_CC; /* bneg will set cc */ + ED_TestDone (Expr); /* bneg will set cc */ } break; @@ -1733,7 +1731,7 @@ void hie10 (ExprDesc* Expr) RemoveCode (Mark); } ED_MakeConstAbs (Expr, Size, type_size_t); - Expr->Test &= ~E_CC; + ED_MarkAsUntested (Expr); break; default: @@ -1983,7 +1981,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ Expr->Type = type_int; /* Condition codes are set */ - Expr->Test |= E_CC; + ED_TestDone (Expr); } } @@ -2225,7 +2223,7 @@ static void parseadd (ExprDesc* Expr) } /* 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 */ - Expr->Test &= ~E_CC; + ED_MarkAsUntested (Expr); } else { @@ -2341,7 +2339,7 @@ static void parsesub (ExprDesc* Expr) /* Result is a rvalue in the primary register */ 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 */ 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 (); /* If the expr hasn't set condition codes, set the force-test flag */ - if ((Expr->Test & E_CC) == 0) { - Expr->Test |= E_FORCETEST; + if (!ED_IsTested (Expr)) { + ED_MarkForTest (Expr); } /* Load the value */ @@ -2577,8 +2575,8 @@ static void hieAnd (ExprDesc* Expr, unsigned TrueLab, int* BoolOp) /* Get rhs */ hie2 (&Expr2); - if ((Expr2.Test & E_CC) == 0) { - Expr2.Test |= E_FORCETEST; + if (!ED_IsTested (&Expr2)) { + ED_MarkForTest (&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 */ 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 the expr hasn't set condition codes, set the force-test flag */ - if ((Expr->Test & E_CC) == 0) { - Expr->Test |= E_FORCETEST; + if (!ED_IsTested (Expr)) { + ED_MarkForTest (Expr); } /* Get first expr */ @@ -2647,8 +2645,8 @@ static void hieOr (ExprDesc *Expr) /* Get a subexpr */ AndOp = 0; hieAnd (&Expr2, TrueLab, &AndOp); - if ((Expr2.Test & E_CC) == 0) { - Expr2.Test |= E_FORCETEST; + if (!ED_IsTested (&Expr2)) { + ED_MarkForTest (&Expr2); } ExprLoad (CF_FORCECHAR, &Expr2); @@ -2659,7 +2657,7 @@ static void hieOr (ExprDesc *Expr) /* The result is an rvalue in primary */ 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 */ @@ -2697,9 +2695,9 @@ static void hieQuest (ExprDesc* Expr) /* Check if it's a ternary expression */ if (CurTok.Tok == TOK_QUEST) { NextToken (); - if ((Expr->Test & E_CC) == 0) { - /* Condition codes not set, force a test */ - Expr->Test |= E_FORCETEST; + if (!ED_IsTested (Expr)) { + /* Condition codes not set, request a test */ + ED_MarkForTest (Expr); } ExprLoad (CF_NONE, Expr); labf = GetLocalLabel (); diff --git a/src/cc65/exprdesc.c b/src/cc65/exprdesc.c index bb2571050..470c0e10e 100644 --- a/src/cc65/exprdesc.c +++ b/src/cc65/exprdesc.c @@ -48,7 +48,7 @@ /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -60,7 +60,6 @@ ExprDesc* ED_Init (ExprDesc* Expr) Expr->Type = 0; Expr->Val = 0; Expr->Flags = 0; - Expr->Test = 0; Expr->Name = 0; return Expr; } @@ -145,7 +144,6 @@ ExprDesc* ED_MakeConstAbs (ExprDesc* Expr, long Value, type* Type) Expr->Type = Type; Expr->Val = Value; Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL; - Expr->Test = 0; Expr->Name = 0; return Expr; } @@ -159,7 +157,6 @@ ExprDesc* ED_MakeConstAbsInt (ExprDesc* Expr, long Value) Expr->Type = type_int; Expr->Val = Value; Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL; - Expr->Test = 0; Expr->Name = 0; return Expr; } @@ -173,8 +170,8 @@ ExprDesc* ED_MakeRValExpr (ExprDesc* Expr) { Expr->Sym = 0; Expr->Val = 0; /* No offset */ - Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_RVAL); - Expr->Test = 0; + Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET); + Expr->Flags |= (E_LOC_EXPR | E_RTYPE_RVAL); Expr->Name = 0; return Expr; } @@ -188,8 +185,8 @@ ExprDesc* ED_MakeLValExpr (ExprDesc* Expr) { Expr->Sym = 0; Expr->Val = 0; /* No offset */ - Expr->Flags = (Expr->Flags & ~(E_MASK_LOC|E_MASK_RTYPE)) | (E_LOC_EXPR|E_RTYPE_LVAL); - Expr->Test = 0; + Expr->Flags &= ~(E_MASK_LOC | E_MASK_RTYPE | E_NEED_TEST | E_CC_SET); + Expr->Flags |= (E_LOC_EXPR | E_RTYPE_LVAL); Expr->Name = 0; return Expr; } @@ -315,6 +312,16 @@ void PrintExprDesc (FILE* F, ExprDesc* E) Flags &= ~E_RTYPE_LVAL; 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) { fprintf (F, "%c,0x%04X", Sep, Flags); Sep = ','; @@ -322,16 +329,6 @@ void PrintExprDesc (FILE* F, ExprDesc* E) if (Sep != '(') { 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); } diff --git a/src/cc65/exprdesc.h b/src/cc65/exprdesc.h index 99c0edbc9..06225ccb1 100644 --- a/src/cc65/exprdesc.h +++ b/src/cc65/exprdesc.h @@ -72,14 +72,14 @@ enum { E_LOC_REGISTER | E_LOC_LITERAL, /* Reference? */ - E_MASK_RTYPE = 0x8000, + E_MASK_RTYPE = 0x0100, E_RTYPE_RVAL = 0x0000, - E_RTYPE_LVAL = 0x8000 -}; + E_RTYPE_LVAL = 0x0100, -/* Defines for the test field of the expression descriptor */ -#define E_CC 0x0001U /* Condition codes are set */ -#define E_FORCETEST 0x0002U /* Force test to set condition codes */ + /* Test */ + E_NEED_TEST = 0x0200, /* Expression needs a test to set cc */ + E_CC_SET = 0x0400 /* Condition codes are set */ +}; /* Describe the result of an expression */ typedef struct ExprDesc ExprDesc; @@ -88,14 +88,13 @@ struct ExprDesc { type* Type; /* Type array of expression */ long Val; /* Value if expression constant */ unsigned short Flags; - unsigned short Test; /* */ unsigned long Name; /* Name or label number */ }; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ @@ -210,7 +209,7 @@ INLINE void ED_MakeLVal (ExprDesc* Expr) Expr->Flags |= E_RTYPE_LVAL; } #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 #if defined(HAVE_INLINE) @@ -220,7 +219,58 @@ INLINE void ED_MakeRVal (ExprDesc* Expr) Expr->Flags &= ~E_RTYPE_LVAL; } #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 const char* ED_GetLabelName (const ExprDesc* Expr, long Offs); diff --git a/src/cc65/testexpr.c b/src/cc65/testexpr.c index 6fb573b93..a9702c6b4 100644 --- a/src/cc65/testexpr.c +++ b/src/cc65/testexpr.c @@ -79,8 +79,8 @@ unsigned Test (unsigned Label, int Invert) Result = TESTEXPR_UNKNOWN; /* If the expr hasn't set condition codes, set the force-test flag */ - if ((Expr.Test & E_CC) == 0) { - Expr.Test |= E_FORCETEST; + if (!ED_IsTested (&Expr)) { + ED_MarkForTest (&Expr); } /* Load the value into the primary register */ -- 2.39.5