mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Replace address mode detection for expressions
git-svn-id: svn://svn.cc65.org/cc65/trunk@2670 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
353b7e66a1
commit
c5ad7d9af1
@ -1815,11 +1815,14 @@ int IsConstExpr (ExprNode* Expr, long* Val)
|
||||
|
||||
|
||||
|
||||
static void CheckByteExpr (const ExprNode* N, int* IsByte)
|
||||
/* Internal routine that is recursively called to check if there is a zeropage
|
||||
* symbol in the expression tree.
|
||||
static void CheckAddrSize (const ExprNode* N, unsigned char* AddrSize)
|
||||
/* Internal routine that is recursively called to check for the address size
|
||||
* of the expression tree.
|
||||
*/
|
||||
{
|
||||
unsigned char A;
|
||||
unsigned char Left, Right;
|
||||
|
||||
if (N) {
|
||||
switch (N->Op & EXPR_TYPEMASK) {
|
||||
|
||||
@ -1828,16 +1831,24 @@ static void CheckByteExpr (const ExprNode* N, int* IsByte)
|
||||
|
||||
case EXPR_SYMBOL:
|
||||
if (SymIsZP (N->V.Sym)) {
|
||||
*IsByte = 1;
|
||||
if (*AddrSize < ADDR_SIZE_ZP) {
|
||||
*AddrSize = ADDR_SIZE_ZP;
|
||||
}
|
||||
} else if (SymHasExpr (N->V.Sym)) {
|
||||
/* Check if this expression is a byte expression */
|
||||
CheckByteExpr (GetSymExpr (N->V.Sym), IsByte);
|
||||
CheckAddrSize (GetSymExpr (N->V.Sym), AddrSize);
|
||||
} else {
|
||||
/* Undefined symbol, use absolute */
|
||||
if (*AddrSize < ADDR_SIZE_ABS) {
|
||||
*AddrSize = ADDR_SIZE_ABS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_SECTION:
|
||||
if (GetSegAddrSize (N->V.SegNum) == ADDR_SIZE_ZP) {
|
||||
*IsByte = 1;
|
||||
A = GetSegAddrSize (N->V.SegNum);
|
||||
if (A > *AddrSize) {
|
||||
*AddrSize = A;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1845,12 +1856,42 @@ static void CheckByteExpr (const ExprNode* N, int* IsByte)
|
||||
break;
|
||||
|
||||
case EXPR_UNARYNODE:
|
||||
CheckByteExpr (N->Left, IsByte);
|
||||
switch (N->Op) {
|
||||
|
||||
case EXPR_BYTE0:
|
||||
case EXPR_BYTE1:
|
||||
case EXPR_BYTE2:
|
||||
case EXPR_BYTE3:
|
||||
/* No need to look at the expression */
|
||||
*AddrSize = ADDR_SIZE_ZP;
|
||||
break;
|
||||
|
||||
case EXPR_WORD0:
|
||||
case EXPR_WORD1:
|
||||
case EXPR_FORCEWORD:
|
||||
/* No need to look at the expression */
|
||||
*AddrSize = ADDR_SIZE_ABS;
|
||||
break;
|
||||
|
||||
case EXPR_FORCEFAR:
|
||||
/* No need to look at the expression */
|
||||
*AddrSize = ADDR_SIZE_FAR;
|
||||
break;
|
||||
|
||||
default:
|
||||
CheckAddrSize (N->Left, AddrSize);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPR_BINARYNODE:
|
||||
CheckByteExpr (N->Left, IsByte);
|
||||
CheckByteExpr (N->Right, IsByte);
|
||||
Left = Right = ADDR_SIZE_DEFAULT;
|
||||
CheckAddrSize (N->Left, &Left);
|
||||
CheckAddrSize (N->Right, &Right);
|
||||
A = (Left > Right)? Left : Right;
|
||||
if (A > *AddrSize) {
|
||||
*AddrSize = A;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1864,26 +1905,15 @@ static void CheckByteExpr (const ExprNode* N, int* IsByte)
|
||||
int IsByteExpr (ExprNode* Root)
|
||||
/* Return true if this is a byte expression */
|
||||
{
|
||||
int IsByte;
|
||||
long Val;
|
||||
|
||||
if (IsConstExpr (Root, &Val)) {
|
||||
IsByte = IsByteRange (Val);
|
||||
} else if (Root->Op == EXPR_BYTE0 || Root->Op == EXPR_BYTE1 ||
|
||||
Root->Op == EXPR_BYTE2 || Root->Op == EXPR_BYTE3) {
|
||||
/* Symbol forced to have byte range */
|
||||
IsByte = 1;
|
||||
return IsByteRange (Val);
|
||||
} else {
|
||||
/* We have undefined symbols in the expression. Assume that the
|
||||
* expression is a byte expression if there is at least one symbol
|
||||
* declared as zeropage in it. Being wrong here is not a very big
|
||||
* problem since the linker knows about all symbols and detects
|
||||
* error like mixing absolute and zeropage labels.
|
||||
*/
|
||||
IsByte = 0;
|
||||
CheckByteExpr (Root, &IsByte);
|
||||
unsigned char AddrSize = ADDR_SIZE_DEFAULT;
|
||||
CheckAddrSize (Root, &AddrSize);
|
||||
return (AddrSize == ADDR_SIZE_ZP);
|
||||
}
|
||||
return IsByte;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user