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:
cuz 2006-04-09 10:56:23 +00:00
parent 44405a0bb5
commit c13f40a9f1
6 changed files with 151 additions and 34 deletions

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2004 Ullrich von Bassewitz */
/* (C) 1998-2006 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -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;
}
}

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* (C) 1998-2006 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -137,6 +137,15 @@ ExprNode* CloneExpr (ExprNode* Expr);
void WriteExpr (ExprNode* Expr);
/* 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 */

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2005, Ullrich von Bassewitz */
/* (C) 1998-2006, Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -946,11 +946,19 @@ static int EvalEA (const InsDesc* Ins, EffAddr* A)
/* Simplify it if possible */
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 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;
if (ED.AddrSize > ADDR_SIZE_ZP && (A->AddrModeSet & AM65_SET_ZP)) {
ExprGuessedAddrSize (A->Expr, ADDR_SIZE_ZP);
}
}
/* Check the size */

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2004 Ullrich von Bassewitz */
/* (C) 1998-2006 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -75,6 +75,8 @@ SymEntry* SymLast = 0;
SymEntry* NewSymEntry (const char* Name, unsigned Flags)
/* Allocate a symbol table entry, initialize and return it */
{
unsigned I;
/* Allocate memory */
SymEntry* S = xmalloc (sizeof (SymEntry));
@ -84,6 +86,9 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags)
S->Locals = 0;
S->SymTab = 0;
S->Pos = CurPos;
for (I = 0; I < sizeof (S->GuessedUse) / sizeof (S->GuessedUse[0]); ++I) {
S->GuessedUse[I] = 0;
}
S->Flags = Flags;
S->Expr = 0;
S->ExprRefs = AUTO_COLLECTION_INITIALIZER;
@ -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)
/* Called at the end of assembly. Converts a global symbol that is defined
* into an export.

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2004 Ullrich von Bassewitz */
/* (C) 1998-2006 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -84,6 +84,12 @@ struct SymEntry {
SymEntry* Locals; /* Root of subtree for local symbols */
struct SymTable* SymTab; /* Table this symbol is in, 0 for locals */
FilePos Pos; /* File position for this symbol */
FilePos* GuessedUse[1]; /* File position where symbol
* address size was guessed, and the
* smallest possible addressing was NOT
* used. Currently only for zero page
* addressing
*/
unsigned Flags; /* Symbol flags */
unsigned Index; /* Index of import/export entries */
struct ExprNode* Expr; /* Symbol expression */
@ -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.
*/
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);
/* Called at the end of assembly. Converts a global symbol that is defined
* into an export.

View file

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 1998-2004 Ullrich von Bassewitz */
/* (C) 1998-2006 Ullrich von Bassewitz */
/* Römerstraße 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -600,6 +600,25 @@ void SymCheck (void)
}
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 */