mirror of
https://github.com/cc65/cc65.git
synced 2025-01-16 13:31:16 +00:00
Fixed internal representation of calculated constant results.
Minor clean-up.
This commit is contained in:
parent
24985f1b33
commit
81d6321cd7
@ -251,6 +251,42 @@ static unsigned typeadjust (ExprDesc* lhs, ExprDesc* rhs, int NoPush)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void LimitExprValue (ExprDesc* Expr)
|
||||||
|
/* Limit the constant value of the expression to the range of its type */
|
||||||
|
{
|
||||||
|
switch (GetUnderlyingTypeCode (Expr->Type)) {
|
||||||
|
case T_INT:
|
||||||
|
case T_SHORT:
|
||||||
|
Expr->IVal = (int16_t)Expr->IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case T_UINT:
|
||||||
|
case T_USHORT:
|
||||||
|
case T_PTR:
|
||||||
|
case T_ARRAY:
|
||||||
|
Expr->IVal = (uint16_t)Expr->IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case T_LONG:
|
||||||
|
case T_ULONG:
|
||||||
|
/* No need to do anything */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case T_SCHAR:
|
||||||
|
Expr->IVal = (int8_t)Expr->IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case T_UCHAR:
|
||||||
|
Expr->IVal = (uint8_t)Expr->IVal;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Internal ("hie_internal: constant result type %s\n", GetFullTypeName (Expr->Type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const GenDesc* FindGen (token_t Tok, const GenDesc* Table)
|
static const GenDesc* FindGen (token_t Tok, const GenDesc* Table)
|
||||||
/* Find a token in a generator table */
|
/* Find a token in a generator table */
|
||||||
{
|
{
|
||||||
@ -2165,15 +2201,19 @@ static void UnaryOp (ExprDesc* Expr)
|
|||||||
ED_MakeConstAbsInt (Expr, 1);
|
ED_MakeConstAbsInt (Expr, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for a constant expression */
|
/* Check for a constant numeric expression */
|
||||||
if (ED_IsConstAbs (Expr)) {
|
if (ED_IsConstAbs (Expr)) {
|
||||||
/* Value is constant */
|
/* Value is numeric */
|
||||||
switch (Tok) {
|
switch (Tok) {
|
||||||
case TOK_MINUS: Expr->IVal = -Expr->IVal; break;
|
case TOK_MINUS: Expr->IVal = -Expr->IVal; break;
|
||||||
case TOK_PLUS: break;
|
case TOK_PLUS: break;
|
||||||
case TOK_COMP: Expr->IVal = ~Expr->IVal; break;
|
case TOK_COMP: Expr->IVal = ~Expr->IVal; break;
|
||||||
default: Internal ("Unexpected token: %d", Tok);
|
default: Internal ("Unexpected token: %d", Tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Limit the calculated value to the range of its type */
|
||||||
|
LimitExprValue (Expr);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Value is not constant */
|
/* Value is not constant */
|
||||||
LoadExpr (CF_NONE, Expr);
|
LoadExpr (CF_NONE, Expr);
|
||||||
@ -2224,7 +2264,7 @@ void hie10 (ExprDesc* Expr)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
BoolExpr (hie10, Expr);
|
BoolExpr (hie10, Expr);
|
||||||
if (ED_IsConstAbs (Expr)) {
|
if (ED_IsConstAbs (Expr)) {
|
||||||
/* Constant expression */
|
/* Constant numeric expression */
|
||||||
Expr->IVal = !Expr->IVal;
|
Expr->IVal = !Expr->IVal;
|
||||||
} else if (ED_IsAddrExpr (Expr)) {
|
} else if (ED_IsAddrExpr (Expr)) {
|
||||||
/* Address != NULL, so !Address == 0 */
|
/* Address != NULL, so !Address == 0 */
|
||||||
@ -2515,6 +2555,9 @@ static void hie_internal (const GenDesc* Ops, /* List of generators */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Limit the calculated value to the range of its type */
|
||||||
|
LimitExprValue (Expr);
|
||||||
|
|
||||||
} else if (lconst && (Gen->Flags & GEN_COMM) && !rconst) {
|
} else if (lconst && (Gen->Flags & GEN_COMM) && !rconst) {
|
||||||
/* If the LHS constant is an int that fits into an unsigned char, change the
|
/* If the LHS constant is an int that fits into an unsigned char, change the
|
||||||
** codegen type to unsigned char. If the RHS is also an unsigned char, then
|
** codegen type to unsigned char. If the RHS is also an unsigned char, then
|
||||||
@ -3048,6 +3091,9 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
/* Integer addition */
|
/* Integer addition */
|
||||||
Expr->IVal += Expr2.IVal;
|
Expr->IVal += Expr2.IVal;
|
||||||
typeadjust (Expr, &Expr2, 1);
|
typeadjust (Expr, &Expr2, 1);
|
||||||
|
|
||||||
|
/* Limit the calculated value to the range of its type */
|
||||||
|
LimitExprValue (Expr);
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
Error ("Invalid operands for binary operator '+'");
|
Error ("Invalid operands for binary operator '+'");
|
||||||
@ -3231,7 +3277,7 @@ static void parseadd (ExprDesc* Expr)
|
|||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Condition codes not set */
|
/* Condition code not set */
|
||||||
ED_MarkAsUntested (Expr);
|
ED_MarkAsUntested (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3315,14 +3361,14 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
/* Integer subtraction */
|
/* Integer subtraction */
|
||||||
typeadjust (Expr, &Expr2, 1);
|
typeadjust (Expr, &Expr2, 1);
|
||||||
Expr->IVal -= Expr2.IVal;
|
Expr->IVal -= Expr2.IVal;
|
||||||
|
|
||||||
|
/* Limit the calculated value to the range of its type */
|
||||||
|
LimitExprValue (Expr);
|
||||||
} else {
|
} else {
|
||||||
/* OOPS */
|
/* OOPS */
|
||||||
Error ("Invalid operands for binary operator '-'");
|
Error ("Invalid operands for binary operator '-'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Result is constant, condition codes not set */
|
|
||||||
ED_MarkAsUntested (Expr);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Left hand side is not constant, right hand side is.
|
/* Left hand side is not constant, right hand side is.
|
||||||
@ -3364,8 +3410,6 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Result is an rvalue in the primary register */
|
/* Result is an rvalue in the primary register */
|
||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
ED_MarkAsUntested (Expr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -3418,8 +3462,10 @@ static void parsesub (ExprDesc* Expr)
|
|||||||
|
|
||||||
/* Result is an rvalue in the primary register */
|
/* Result is an rvalue in the primary register */
|
||||||
ED_FinalizeRValLoad (Expr);
|
ED_FinalizeRValLoad (Expr);
|
||||||
ED_MarkAsUntested (Expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Condition code not set */
|
||||||
|
ED_MarkAsUntested (Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
/* Read a boolean expression */
|
/* Read a boolean expression */
|
||||||
BoolExpr (hie0, &Expr);
|
BoolExpr (hie0, &Expr);
|
||||||
|
|
||||||
/* Check for a constant expression */
|
/* Check for a constant numeric expression */
|
||||||
if (ED_IsConstAbs (&Expr)) {
|
if (ED_IsConstAbs (&Expr)) {
|
||||||
|
|
||||||
/* Append deferred inc/dec at sequence point */
|
/* Append deferred inc/dec at sequence point */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user