Move evaluation of the argument for .BANK into the linker. It is otherwise too

restricted, since no imported symbols may be used.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5746 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2012-06-30 17:18:03 +00:00
parent 3e95d3048f
commit 43ea0e3df9
10 changed files with 66 additions and 165 deletions

View File

@@ -243,7 +243,7 @@ static ExprNode* Bank (ExprNode* Operand)
/* Return the bank of the given segmented expression */
{
/* Generate the bank expression */
ExprNode* Expr = NewExprNode (EXPR_BANKRAW);
ExprNode* Expr = NewExprNode (EXPR_BANK);
Expr->Left = Operand;
/* Return the result */
@@ -1833,76 +1833,6 @@ ExprNode* CloneExpr (ExprNode* Expr)
ExprNode* FinalizeExpr (ExprNode* Expr, const Collection* LineInfos)
/* Finalize an expression tree before it is written to the file. This will
* replace EXPR_BANKRAW nodes by EXPR_BANK nodes, and replace constant
* expressions by their result. The LineInfos are used when diagnosing errors.
* Beware: The expression tree may get replaced in future versions, so don't
* use Expr after calling this function.
*/
{
ExprDesc ED;
/* Check the type code */
switch (EXPR_NODETYPE (Expr->Op)) {
case EXPR_LEAFNODE:
/* Nothing to do for leaf nodes */
break;
case EXPR_BINARYNODE:
Expr->Left = FinalizeExpr (Expr->Left, LineInfos);
Expr->Right = FinalizeExpr (Expr->Right, LineInfos);
/* FALLTHROUGH */
case EXPR_UNARYNODE:
Expr->Left = FinalizeExpr (Expr->Left, LineInfos);
/* Special handling for BANKRAW */
if (Expr->Op == EXPR_BANKRAW) {
/* Study the expression */
ED_Init (&ED);
StudyExpr (Expr->Left, &ED);
/* The expression must be ok and must have exactly one segment
* reference.
*/
if (ED.Flags & ED_TOO_COMPLEX) {
LIError (LineInfos,
"Cannot evaluate expression");
} else if (ED.SecCount == 0) {
LIError (LineInfos,
".BANK expects a segment reference");
} else if (ED.SecCount > 1 || ED.SecRef[0].Count > 1) {
LIError (LineInfos,
"Too many segment references in argument to .BANK");
} else {
Segment* S;
FreeExpr (Expr->Left);
Expr->Op = EXPR_BANK;
Expr->Left = 0;
Expr->V.SecNum = ED.SecRef[0].Ref;
/* Mark the segment */
S = CollAt (&SegmentList, Expr->V.SecNum);
S->Flags |= SEG_FLAG_BANKREF;
}
/* Cleanup */
ED_Done (&ED);
}
break;
}
/* Return the (partial) tree */
return Expr;
}
void WriteExpr (ExprNode* Expr)
/* Write the given expression to the object file */
{
@@ -1940,11 +1870,6 @@ void WriteExpr (ExprNode* Expr)
WriteExpr (ULabResolve (Expr->V.IVal));
break;
case EXPR_BANK:
ObjWrite8 (EXPR_BANK);
ObjWriteVar (Expr->V.SecNum);
break;
default:
/* Not a leaf node */
ObjWrite8 (Expr->Op);

View File

@@ -147,14 +147,6 @@ ExprNode* CloneExpr (ExprNode* Expr);
* nodes, it will not resolve them.
*/
ExprNode* FinalizeExpr (ExprNode* Expr, const Collection* LineInfos);
/* Finalize an expression tree before it is written to the file. This will
* replace EXPR_BANKRAW nodes by EXPR_BANK nodes, and replace constant
* expressions by their result. The LineInfos are used when diagnosing errors.
* Beware: The expression tree may get replaced in future versions, so don't
* use Expr after calling this function.
*/
void WriteExpr (ExprNode* Expr);
/* Write the given expression to the object file */

View File

@@ -409,9 +409,6 @@ void SegDone (void)
} else {
/* Finalize the expression */
F->V.Expr = FinalizeExpr (F->V.Expr, &F->LI);
/* Simplify the expression */
/* ### F->V.Expr = SimplifyExpr (F->V.Expr, &ED); */

View File

@@ -1097,21 +1097,6 @@ static void StudyBoolNot (ExprNode* Expr, ExprDesc* D)
static void StudyBank (ExprNode* Expr, ExprDesc* D)
/* Study an EXPR_BANK expression node */
{
/* Get the section reference */
ED_SecRef* SecRef = ED_GetSecRef (D, Expr->V.SecNum);
/* Update the data and the address size */
++SecRef->Count;
/* The expression is always linker evaluated, so invalidate it */
ED_Invalidate (D);
}
static void StudyBankRaw (ExprNode* Expr, ExprDesc* D)
/* Study an EXPR_BANKRAW expression node */
{
/* Study the expression extracting section references */
StudyExprInternal (Expr->Left, D);
@@ -1296,10 +1281,6 @@ static void StudyExprInternal (ExprNode* Expr, ExprDesc* D)
StudyULabel (Expr, D);
break;
case EXPR_BANK:
StudyBank (Expr, D);
break;
case EXPR_PLUS:
StudyPlus (Expr, D);
break;
@@ -1400,8 +1381,8 @@ static void StudyExprInternal (ExprNode* Expr, ExprDesc* D)
StudyBoolNot (Expr, D);
break;
case EXPR_BANKRAW:
StudyBankRaw (Expr, D);
case EXPR_BANK:
StudyBank (Expr, D);
break;
case EXPR_BYTE0: