Add bounded expressions for immediate addressing and list the new feature in

the docs.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5406 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2012-01-18 19:50:34 +00:00
parent 0e4f581f71
commit 7ecb4c50b1
11 changed files with 185 additions and 40 deletions

View File

@@ -1705,6 +1705,44 @@ ExprNode* GenWordExpr (ExprNode* Expr)
ExprNode* GenFarAddrExpr (ExprNode* Expr)
/* Force the given expression into a far address and return the result. */
{
long Val;
/* Special handling for const expressions */
if (IsEasyConst (Expr, &Val)) {
FreeExpr (Expr);
Expr = GenLiteralExpr (Val & 0xFFFFFF);
} else {
ExprNode* Operand = Expr;
Expr = NewExprNode (EXPR_FARADDR);
Expr->Left = Operand;
}
return Expr;
}
ExprNode* GenDWordExpr (ExprNode* Expr)
/* Force the given expression into a dword and return the result. */
{
long Val;
/* Special handling for const expressions */
if (IsEasyConst (Expr, &Val)) {
FreeExpr (Expr);
Expr = GenLiteralExpr (Val & 0xFFFFFFFF);
} else {
ExprNode* Operand = Expr;
Expr = NewExprNode (EXPR_DWORD);
Expr->Left = Operand;
}
return Expr;
}
ExprNode* GenNE (ExprNode* Expr, long Val)
/* Generate an expression that compares Expr and Val for inequality */
{
@@ -1957,3 +1995,28 @@ void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize)
ExprNode* MakeBoundedExpr (ExprNode* Expr, unsigned Size)
/* Force the given expression into a specific size of ForceRange is true */
{
if (ForceRange) {
switch (Size) {
case 1: Expr = GenByteExpr (Expr); break;
case 2: Expr = GenWordExpr (Expr); break;
case 3: Expr = GenFarAddrExpr (Expr); break;
case 4: Expr = GenDWordExpr (Expr); break;
default: Internal ("Invalid size in BoundedExpr: %u", Size);
}
}
return Expr;
}
ExprNode* BoundedExpr (ExprNode* (*ExprFunc) (void), unsigned Size)
/* Parse an expression and force it within a given size if ForceRange is true */
{
return MakeBoundedExpr (ExprFunc (), Size);
}