1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-24 11:31:31 +00:00

Utility functions about compare conditions.

This commit is contained in:
acqn 2020-01-23 06:39:37 +08:00 committed by Oliver Schmidt
parent 64ef562fa7
commit 57117fa687
3 changed files with 73 additions and 6 deletions

View File

@ -64,6 +64,13 @@ static const char CmpSuffixTab [][4] = {
"eq", "ne", "gt", "ge", "lt", "le", "ugt", "uge", "ult", "ule"
};
/* Table with the bool transformers */
static const char BoolTransformerTab [][8] = {
"booleq", "boolne",
"boolgt", "boolge", "boollt", "boolle",
"boolugt", "booluge", "boolult", "boolule"
};
/* Table listing the function names and code info values for known internally
** used functions. This table should get auto-generated in the future.
*/
@ -840,3 +847,55 @@ cmp_t FindTosCmpCond (const char* Name)
return CMP_INV;
}
}
const char* GetBoolTransformer (cmp_t Cond)
/* Get the bool transformer corresponding to the given compare condition */
{
if (Cond > CMP_INV && Cond < CMP_END) {
return BoolTransformerTab[Cond];
}
/* Not found */
return 0;
}
cmp_t GetNegatedCond (cmp_t Cond)
/* Get the logically opposite compare condition */
{
switch (Cond) {
case CMP_EQ: return CMP_NE;
case CMP_NE: return CMP_EQ;
case CMP_GT: return CMP_LE;
case CMP_GE: return CMP_LT;
case CMP_LT: return CMP_GE;
case CMP_LE: return CMP_GT;
case CMP_UGT: return CMP_ULE;
case CMP_UGE: return CMP_ULT;
case CMP_ULT: return CMP_UGE;
case CMP_ULE: return CMP_UGT;
default: return CMP_INV;
}
}
cmp_t GetRevertedCond (cmp_t Cond)
/* Get the compare condition in reverted order of operands */
{
switch (Cond) {
case CMP_EQ: return CMP_EQ;
case CMP_NE: return CMP_NE;
case CMP_GT: return CMP_LT;
case CMP_GE: return CMP_LE;
case CMP_LT: return CMP_GT;
case CMP_LE: return CMP_GE;
case CMP_UGT: return CMP_ULT;
case CMP_UGE: return CMP_ULE;
case CMP_ULT: return CMP_UGT;
case CMP_ULE: return CMP_UGE;
default: return CMP_INV;
}
}

View File

@ -115,7 +115,10 @@ typedef enum {
CMP_UGT,
CMP_UGE,
CMP_ULT,
CMP_ULE
CMP_ULE,
/* End of the enumeration */
CMP_END
} cmp_t;
@ -185,6 +188,15 @@ cmp_t FindTosCmpCond (const char* Name);
** Return the condition code or CMP_INV on failure.
*/
const char* GetBoolTransformer (cmp_t Cond);
/* Get the bool transformer corresponding to the given compare condition */
cmp_t GetNegatedCond (cmp_t Cond);
/* Get the logically opposite compare condition */
cmp_t GetRevertedCond (cmp_t Cond);
/* Get the compare condition in reverted order of operands */
/* End of codeinfo.h */

View File

@ -448,11 +448,7 @@ unsigned OptCmp3 (CodeSeg* S)
Delete = 1;
break;
case CMP_UGT:
case CMP_UGE:
case CMP_ULT:
case CMP_ULE:
case CMP_INV:
default:
/* Leave it alone */
break;
}