Added builtin .min() and .max() pseudo functions to the assembler.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4583 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2010-02-11 18:54:08 +00:00
parent c72cf88723
commit 61b69316c5
10 changed files with 188 additions and 34 deletions

View File

@@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2009, Ullrich von Bassewitz */
/* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@@ -535,6 +535,64 @@ static ExprNode* FuncMatch (void)
static ExprNode* FuncMax (void)
/* Handle the .MAX function */
{
ExprNode* Left;
ExprNode* Right;
ExprNode* Expr;
long LeftVal, RightVal;
/* Two arguments to the pseudo function */
Left = Expression ();
ConsumeComma ();
Right = Expression ();
/* Check if we can evaluate the value immediately */
if (IsEasyConst (Left, &LeftVal) && IsEasyConst (Right, &RightVal)) {
FreeExpr (Left);
FreeExpr (Right);
Expr = GenLiteralExpr ((LeftVal > RightVal)? LeftVal : RightVal);
} else {
/* Make an expression node */
Expr = NewExprNode (EXPR_MAX);
Expr->Left = Left;
Expr->Right = Right;
}
return Expr;
}
static ExprNode* FuncMin (void)
/* Handle the .MIN function */
{
ExprNode* Left;
ExprNode* Right;
ExprNode* Expr;
long LeftVal, RightVal;
/* Two arguments to the pseudo function */
Left = Expression ();
ConsumeComma ();
Right = Expression ();
/* Check if we can evaluate the value immediately */
if (IsEasyConst (Left, &LeftVal) && IsEasyConst (Right, &RightVal)) {
FreeExpr (Left);
FreeExpr (Right);
Expr = GenLiteralExpr ((LeftVal < RightVal)? LeftVal : RightVal);
} else {
/* Make an expression node */
Expr = NewExprNode (EXPR_MIN);
Expr->Left = Left;
Expr->Right = Right;
}
return Expr;
}
static ExprNode* FuncReferenced (void)
/* Handle the .REFERENCED builtin function */
{
@@ -919,6 +977,14 @@ static ExprNode* Factor (void)
N = Function (FuncMatch);
break;
case TOK_MAX:
N = Function (FuncMax);
break;
case TOK_MIN:
N = Function (FuncMin);
break;
case TOK_REFERENCED:
N = Function (FuncReferenced);
break;