/* 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)) {
Internal ("Invalid location in ExprLoad: 0x%04X", ED_GetLoc (Expr));
}
+ /* Expression was tested */
+ ED_TestDone (Expr);
+
} else {
/* An rvalue */
if (ED_IsLocExpr (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);
}
}
}
/* 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)) {
}
/* Assume that each one of the stores will invalidate CC */
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (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;
RemoveCode (Mark);
}
ED_MakeConstAbs (Expr, Size, type_size_t);
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (Expr);
break;
default:
Expr->Type = type_int;
/* Condition codes are set */
- Expr->Test |= E_CC;
+ ED_TestDone (Expr);
}
}
}
/* Condition codes not set */
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (Expr);
}
}
/* Result is constant, condition codes not set */
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (Expr);
} else {
/* Result is a rvalue in the primary register */
ED_MakeRValExpr (Expr);
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (Expr);
}
/* Result is a rvalue in the primary register */
ED_MakeRValExpr (Expr);
- Expr->Test &= ~E_CC;
+ ED_MarkAsUntested (Expr);
}
}
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 */
/* 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);
/* 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 (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 */
/* 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);
/* 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 */
/* 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 ();
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
Expr->Type = 0;
Expr->Val = 0;
Expr->Flags = 0;
- Expr->Test = 0;
Expr->Name = 0;
return Expr;
}
Expr->Type = Type;
Expr->Val = Value;
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
- Expr->Test = 0;
Expr->Name = 0;
return Expr;
}
Expr->Type = type_int;
Expr->Val = Value;
Expr->Flags = E_LOC_ABS | E_RTYPE_RVAL;
- Expr->Test = 0;
Expr->Name = 0;
return 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;
}
{
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;
}
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 = ',';
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);
}
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;
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 */
/*****************************************************************************/
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)
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);
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 */