mirror of
https://github.com/cc65/cc65.git
synced 2025-01-12 17:30:50 +00:00
Emit warnings for symbols that were used suboptimal because of forward
definitions. For example a zero page symbol that is used as absolute because it was undefined when encountered. git-svn-id: svn://svn.cc65.org/cc65/trunk@3724 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
44405a0bb5
commit
c13f40a9f1
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -1695,11 +1695,11 @@ void WriteExpr (ExprNode* Expr)
|
|||||||
|
|
||||||
case EXPR_LITERAL:
|
case EXPR_LITERAL:
|
||||||
ObjWrite8 (EXPR_LITERAL);
|
ObjWrite8 (EXPR_LITERAL);
|
||||||
ObjWrite32 (Expr->V.Val);
|
ObjWrite32 (Expr->V.Val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXPR_SYMBOL:
|
case EXPR_SYMBOL:
|
||||||
if (SymIsImport (Expr->V.Sym)) {
|
if (SymIsImport (Expr->V.Sym)) {
|
||||||
ObjWrite8 (EXPR_SYMBOL);
|
ObjWrite8 (EXPR_SYMBOL);
|
||||||
ObjWriteVar (GetSymIndex (Expr->V.Sym));
|
ObjWriteVar (GetSymIndex (Expr->V.Sym));
|
||||||
} else {
|
} else {
|
||||||
@ -1728,4 +1728,41 @@ void WriteExpr (ExprNode* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize)
|
||||||
|
/* Mark the address size of the given expression tree as guessed. The address
|
||||||
|
* size passed as argument is the one NOT used, because the actual address
|
||||||
|
* size wasn't known. Example: Zero page addressing was not used because symbol
|
||||||
|
* is undefined, and absolute addressing was available.
|
||||||
|
* This function will actually parse the expression tree for undefined symbols,
|
||||||
|
* and mark these symbols accordingly.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Accept NULL expressions */
|
||||||
|
if (Expr == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check the type code */
|
||||||
|
switch (Expr->Op & EXPR_TYPEMASK) {
|
||||||
|
|
||||||
|
case EXPR_LEAFNODE:
|
||||||
|
if (Expr->Op == EXPR_SYMBOL) {
|
||||||
|
if (!SymIsDef (Expr->V.Sym)) {
|
||||||
|
/* Symbol is undefined, mark it */
|
||||||
|
SymGuessedAddrSize (Expr->V.Sym, AddrSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
case EXPR_BINARYNODE:
|
||||||
|
ExprGuessedAddrSize (Expr->Right, AddrSize);
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
|
case EXPR_UNARYNODE:
|
||||||
|
ExprGuessedAddrSize (Expr->Left, AddrSize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -137,6 +137,15 @@ ExprNode* CloneExpr (ExprNode* Expr);
|
|||||||
void WriteExpr (ExprNode* Expr);
|
void WriteExpr (ExprNode* Expr);
|
||||||
/* Write the given expression to the object file */
|
/* Write the given expression to the object file */
|
||||||
|
|
||||||
|
void ExprGuessedAddrSize (const ExprNode* Expr, unsigned char AddrSize);
|
||||||
|
/* Mark the address size of the given expression tree as guessed. The address
|
||||||
|
* size passed as argument is the one NOT used, because the actual address
|
||||||
|
* size wasn't known. Example: Zero page addressing was not used because symbol
|
||||||
|
* is undefined, and absolute addressing was available.
|
||||||
|
* This function will actually parse the expression tree for undefined symbols,
|
||||||
|
* and mark these symbols accordingly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of expr.h */
|
/* End of expr.h */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2005, Ullrich von Bassewitz */
|
/* (C) 1998-2006, Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Römerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -946,11 +946,19 @@ static int EvalEA (const InsDesc* Ins, EffAddr* A)
|
|||||||
/* Simplify it if possible */
|
/* Simplify it if possible */
|
||||||
A->Expr = SimplifyExpr (A->Expr, &ED);
|
A->Expr = SimplifyExpr (A->Expr, &ED);
|
||||||
|
|
||||||
/* If we don't know how big the expression is, assume the default
|
|
||||||
* address size for data.
|
|
||||||
*/
|
|
||||||
if (ED.AddrSize == ADDR_SIZE_DEFAULT) {
|
if (ED.AddrSize == ADDR_SIZE_DEFAULT) {
|
||||||
|
/* If we don't know how big the expression is, assume the
|
||||||
|
* default address size for data. If this default address
|
||||||
|
* size is unequal to zero page addressing, but zero page
|
||||||
|
* addressing is allowed by the instruction, mark all symbols
|
||||||
|
* in the expression tree. This mark will be checked at end
|
||||||
|
* of assembly, and a warning is issued, if a zero page symbol
|
||||||
|
* was guessed wrong here.
|
||||||
|
*/
|
||||||
ED.AddrSize = DataAddrSize;
|
ED.AddrSize = DataAddrSize;
|
||||||
|
if (ED.AddrSize > ADDR_SIZE_ZP && (A->AddrModeSet & AM65_SET_ZP)) {
|
||||||
|
ExprGuessedAddrSize (A->Expr, ADDR_SIZE_ZP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the size */
|
/* Check the size */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -75,16 +75,21 @@ SymEntry* SymLast = 0;
|
|||||||
SymEntry* NewSymEntry (const char* Name, unsigned Flags)
|
SymEntry* NewSymEntry (const char* Name, unsigned Flags)
|
||||||
/* Allocate a symbol table entry, initialize and return it */
|
/* Allocate a symbol table entry, initialize and return it */
|
||||||
{
|
{
|
||||||
|
unsigned I;
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
SymEntry* S = xmalloc (sizeof (SymEntry));
|
SymEntry* S = xmalloc (sizeof (SymEntry));
|
||||||
|
|
||||||
/* Initialize the entry */
|
/* Initialize the entry */
|
||||||
S->Left = 0;
|
S->Left = 0;
|
||||||
S->Right = 0;
|
S->Right = 0;
|
||||||
S->Locals = 0;
|
S->Locals = 0;
|
||||||
S->SymTab = 0;
|
S->SymTab = 0;
|
||||||
S->Pos = CurPos;
|
S->Pos = CurPos;
|
||||||
S->Flags = Flags;
|
for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
|
||||||
|
S->GuessedUse[I] = 0;
|
||||||
|
}
|
||||||
|
S->Flags = Flags;
|
||||||
S->Expr = 0;
|
S->Expr = 0;
|
||||||
S->ExprRefs = AUTO_COLLECTION_INITIALIZER;
|
S->ExprRefs = AUTO_COLLECTION_INITIALIZER;
|
||||||
S->ExportSize = ADDR_SIZE_DEFAULT;
|
S->ExportSize = ADDR_SIZE_DEFAULT;
|
||||||
@ -193,7 +198,7 @@ static void SymReplaceExprRefs (SymEntry* S)
|
|||||||
/* Safety */
|
/* Safety */
|
||||||
CHECK (E->Op == EXPR_SYMBOL && E->V.Sym == S);
|
CHECK (E->Op == EXPR_SYMBOL && E->V.Sym == S);
|
||||||
|
|
||||||
/* We cannot touch the root node, since there are pointers to it.
|
/* We cannot touch the root node, since there are pointers to it.
|
||||||
* Replace it by a literal node.
|
* Replace it by a literal node.
|
||||||
*/
|
*/
|
||||||
E->Op = EXPR_LITERAL;
|
E->Op = EXPR_LITERAL;
|
||||||
@ -252,7 +257,7 @@ void SymDef (SymEntry* S, ExprNode* Expr, unsigned char AddrSize, unsigned Flags
|
|||||||
/* Set the symbol value */
|
/* Set the symbol value */
|
||||||
S->Expr = Expr;
|
S->Expr = Expr;
|
||||||
|
|
||||||
/* In case of a variable symbol, walk over all expressions containing
|
/* In case of a variable symbol, walk over all expressions containing
|
||||||
* this symbol and replace the (sub-)expression by the literal value of
|
* this symbol and replace the (sub-)expression by the literal value of
|
||||||
* the tree. Be sure to replace the expression node in place, since there
|
* the tree. Be sure to replace the expression node in place, since there
|
||||||
* may be pointers to it.
|
* may be pointers to it.
|
||||||
@ -549,6 +554,32 @@ void SymConDes (SymEntry* S, unsigned char AddrSize, unsigned Type, unsigned Pri
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize)
|
||||||
|
/* Mark the address size of the given symbol as guessed. The address size
|
||||||
|
* passed as argument is the one NOT used, because the actual address size
|
||||||
|
* wasn't known. Example: Zero page addressing was not used because symbol
|
||||||
|
* is undefined, and absolute addressing was available.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* We must have a valid address size passed */
|
||||||
|
PRECONDITION (AddrSize != ADDR_SIZE_DEFAULT);
|
||||||
|
|
||||||
|
/* We do not support all address sizes currently */
|
||||||
|
if (AddrSize > sizeof (Sym->GuessedUse) / sizeof (Sym->GuessedUse[0])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We can only remember one such occurance */
|
||||||
|
if (Sym->GuessedUse[AddrSize-1]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ok, remember the file position */
|
||||||
|
Sym->GuessedUse[AddrSize-1] = xdup (&CurPos, sizeof (CurPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SymExportFromGlobal (SymEntry* S)
|
void SymExportFromGlobal (SymEntry* S)
|
||||||
/* Called at the end of assembly. Converts a global symbol that is defined
|
/* Called at the end of assembly. Converts a global symbol that is defined
|
||||||
* into an export.
|
* into an export.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -78,21 +78,27 @@
|
|||||||
/* Structure of a symbol table entry */
|
/* Structure of a symbol table entry */
|
||||||
typedef struct SymEntry SymEntry;
|
typedef struct SymEntry SymEntry;
|
||||||
struct SymEntry {
|
struct SymEntry {
|
||||||
SymEntry* Left; /* Lexically smaller entry */
|
SymEntry* Left; /* Lexically smaller entry */
|
||||||
SymEntry* Right; /* Lexically larger entry */
|
SymEntry* Right; /* Lexically larger entry */
|
||||||
SymEntry* List; /* List of all entries */
|
SymEntry* List; /* List of all entries */
|
||||||
SymEntry* Locals; /* Root of subtree for local symbols */
|
SymEntry* Locals; /* Root of subtree for local symbols */
|
||||||
struct SymTable* SymTab; /* Table this symbol is in, 0 for locals */
|
struct SymTable* SymTab; /* Table this symbol is in, 0 for locals */
|
||||||
FilePos Pos; /* File position for this symbol */
|
FilePos Pos; /* File position for this symbol */
|
||||||
unsigned Flags; /* Symbol flags */
|
FilePos* GuessedUse[1]; /* File position where symbol
|
||||||
unsigned Index; /* Index of import/export entries */
|
* address size was guessed, and the
|
||||||
struct ExprNode* Expr; /* Symbol expression */
|
* smallest possible addressing was NOT
|
||||||
Collection ExprRefs; /* Expressions using this symbol */
|
* used. Currently only for zero page
|
||||||
unsigned char ExportSize; /* Export address size */
|
* addressing
|
||||||
unsigned char AddrSize; /* Address size of label */
|
*/
|
||||||
unsigned char ConDesPrio[CD_TYPE_COUNT]; /* ConDes priorities... */
|
unsigned Flags; /* Symbol flags */
|
||||||
|
unsigned Index; /* Index of import/export entries */
|
||||||
|
struct ExprNode* Expr; /* Symbol expression */
|
||||||
|
Collection ExprRefs; /* Expressions using this symbol */
|
||||||
|
unsigned char ExportSize; /* Export address size */
|
||||||
|
unsigned char AddrSize; /* Address size of label */
|
||||||
|
unsigned char ConDesPrio[CD_TYPE_COUNT]; /* ConDes priorities... */
|
||||||
/* ...actually value+1 (used as flag) */
|
/* ...actually value+1 (used as flag) */
|
||||||
unsigned Name; /* Name index in global string pool */
|
unsigned Name; /* Name index in global string pool */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* List of all symbol table entries */
|
/* List of all symbol table entries */
|
||||||
@ -166,6 +172,13 @@ void SymConDes (SymEntry* Sym, unsigned char AddrSize, unsigned Type, unsigned P
|
|||||||
* mark the symbol as an export. Initializers may never be zero page symbols.
|
* mark the symbol as an export. Initializers may never be zero page symbols.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void SymGuessedAddrSize (SymEntry* Sym, unsigned char AddrSize);
|
||||||
|
/* Mark the address size of the given symbol as guessed. The address size
|
||||||
|
* passed as argument is the one NOT used, because the actual address size
|
||||||
|
* wasn't known. Example: Zero page addressing was not used because symbol
|
||||||
|
* is undefined, and absolute addressing was available.
|
||||||
|
*/
|
||||||
|
|
||||||
void SymExportFromGlobal (SymEntry* S);
|
void SymExportFromGlobal (SymEntry* S);
|
||||||
/* Called at the end of assembly. Converts a global symbol that is defined
|
/* Called at the end of assembly. Converts a global symbol that is defined
|
||||||
* into an export.
|
* into an export.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2006 Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -600,6 +600,25 @@ void SymCheck (void)
|
|||||||
}
|
}
|
||||||
ED_Done (&ED);
|
ED_Done (&ED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the address size of the symbol was guessed, check the guess
|
||||||
|
* against the actual address size and print a warning if the two
|
||||||
|
* differ.
|
||||||
|
*/
|
||||||
|
if (S->AddrSize != ADDR_SIZE_DEFAULT) {
|
||||||
|
/* Do we have data for this address size? */
|
||||||
|
if (S->AddrSize <= sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0])) {
|
||||||
|
/* Get the file position where the symbol was used */
|
||||||
|
const FilePos* P = S->GuessedUse[S->AddrSize - 1];
|
||||||
|
if (P) {
|
||||||
|
PWarning (P, 0,
|
||||||
|
"Didn't use %s addressing for `%s'",
|
||||||
|
AddrSizeToStr (S->AddrSize),
|
||||||
|
GetSymName (S));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next symbol */
|
/* Next symbol */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user