From c9b90692080a21fd4e78e5cd1871c35935d5d997 Mon Sep 17 00:00:00 2001 From: uz Date: Tue, 9 Nov 2010 20:34:08 +0000 Subject: [PATCH] Better handling of imports in the ExprNode structure. git-svn-id: svn://svn.cc65.org/cc65/trunk@4841 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/exprdefs.h | 7 ++++--- src/ld65/expr.c | 24 +++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/common/exprdefs.h b/src/common/exprdefs.h index d9a3970c0..db85a5934 100644 --- a/src/common/exprdefs.h +++ b/src/common/exprdefs.h @@ -109,11 +109,12 @@ struct ExprNode { union { long IVal; /* If this is a int value */ struct SymEntry* Sym; /* If this is a symbol */ - unsigned SegNum; /* If this is a segment */ - struct Import* Imp; /* If this is an import */ + unsigned SecNum; /* If this is a section and Obj != 0 */ + unsigned ImpNum; /* If this is an import and Obj != 0 */ + struct Import* Imp; /* If this is an import and Obj == 0 */ struct MemoryArea* Mem; /* If this is a memory area */ struct Segment* Seg; /* If this is a segment */ - struct Section* Sec; /* If section and Obj is NULL */ + struct Section* Sec; /* If this is a section and Obj == 0 */ } V; }; diff --git a/src/ld65/expr.c b/src/ld65/expr.c index a5b7a3c5c..6dc43db72 100644 --- a/src/ld65/expr.c +++ b/src/ld65/expr.c @@ -136,7 +136,7 @@ int IsConstExpr (ExprNode* Root) case EXPR_MEMAREA: /* A memory area is const if it is not relocatable and placed */ - return !Root->V.Mem->Relocatable && + return !Root->V.Mem->Relocatable && (Root->V.Mem->Flags & MF_PLACED); default: @@ -196,8 +196,16 @@ Import* GetExprImport (ExprNode* Expr) /* Check that this is really a symbol */ PRECONDITION (Expr->Op == EXPR_SYMBOL); - /* Return the import */ - return Expr->V.Imp; + /* If we have an object file, get the import from it, otherwise + * (internally generated expressions), get the import from the + * import pointer. + */ + if (Expr->Obj) { + /* Return the export */ + return CollAt (&Expr->Obj->Imports, Expr->V.ImpNum); + } else { + return Expr->V.Imp; + } } @@ -226,7 +234,7 @@ Section* GetExprSection (ExprNode* Expr) */ if (Expr->Obj) { /* Return the export */ - return CollAt (&Expr->Obj->Sections, Expr->V.SegNum); + return CollAt (&Expr->Obj->Sections, Expr->V.SecNum); } else { return Expr->V.Sec; } @@ -467,7 +475,6 @@ ExprNode* ReadExpr (FILE* F, ObjData* O) /* Read an expression from the given file */ { ExprNode* Expr; - unsigned ImpNum; /* Read the node tag and handle NULL nodes */ unsigned char Op = Read8 (F); @@ -488,13 +495,12 @@ ExprNode* ReadExpr (FILE* F, ObjData* O) case EXPR_SYMBOL: /* Read the import number */ - ImpNum = ReadVar (F); - Expr->V.Imp = CollAt (&O->Imports, ImpNum); + Expr->V.ImpNum = ReadVar (F); break; case EXPR_SECTION: /* Read the segment number */ - Expr->V.SegNum = Read8 (F); + Expr->V.SecNum = Read8 (F); break; default: @@ -541,7 +547,7 @@ int EqualExpr (ExprNode* E1, ExprNode* E2) case EXPR_SYMBOL: /* Import must be identical */ - return (E1->V.Imp == E2->V.Imp); + return (GetExprImport (E1) == GetExprImport (E2)); case EXPR_SECTION: /* Section must be identical */ -- 2.39.5