mirror of
https://github.com/cc65/cc65.git
synced 2025-01-26 17:36:57 +00:00
Set the address size once assembly is terminated
git-svn-id: svn://svn.cc65.org/cc65/trunk@2750 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
042c63f278
commit
6a3ea29429
@ -85,7 +85,7 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags)
|
|||||||
S->SymTab = 0;
|
S->SymTab = 0;
|
||||||
S->Pos = CurPos;
|
S->Pos = CurPos;
|
||||||
S->Flags = Flags;
|
S->Flags = Flags;
|
||||||
S->V.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;
|
||||||
S->AddrSize = ADDR_SIZE_DEFAULT;
|
S->AddrSize = ADDR_SIZE_DEFAULT;
|
||||||
@ -200,7 +200,7 @@ void SymDef (SymEntry* S, ExprNode* Expr, unsigned char AddrSize, unsigned Flags
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the symbol value */
|
/* Set the symbol value */
|
||||||
S->V.Expr = Expr;
|
S->Expr = Expr;
|
||||||
|
|
||||||
/* If the symbol is marked as global, export it. Address size is checked
|
/* If the symbol is marked as global, export it. Address size is checked
|
||||||
* below.
|
* below.
|
||||||
@ -480,7 +480,7 @@ int SymIsConst (SymEntry* S, long* Val)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Check for constness */
|
/* Check for constness */
|
||||||
return (SymHasExpr (S) && IsConstExpr (S->V.Expr, Val));
|
return (SymHasExpr (S) && IsConstExpr (S->Expr, Val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ struct ExprNode* GetSymExpr (SymEntry* S)
|
|||||||
/* Get the expression for a non-const symbol */
|
/* Get the expression for a non-const symbol */
|
||||||
{
|
{
|
||||||
PRECONDITION (S != 0 && SymHasExpr (S));
|
PRECONDITION (S != 0 && SymHasExpr (S));
|
||||||
return S->V.Expr;
|
return S->Expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ const struct ExprNode* SymResolve (const SymEntry* S)
|
|||||||
* NULL. Do not call in other contexts!
|
* NULL. Do not call in other contexts!
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
return SymHasExpr (S)? S->V.Expr : 0;
|
return SymHasExpr (S)? S->Expr : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,10 +85,7 @@ struct SymEntry {
|
|||||||
FilePos Pos; /* File position for this symbol */
|
FilePos Pos; /* File position for this symbol */
|
||||||
unsigned Flags; /* Symbol flags */
|
unsigned Flags; /* Symbol flags */
|
||||||
unsigned Index; /* Index of import/export entries */
|
unsigned Index; /* Index of import/export entries */
|
||||||
union {
|
|
||||||
struct ExprNode* Expr; /* Symbol expression */
|
struct ExprNode* Expr; /* Symbol expression */
|
||||||
SymEntry* Sym; /* Symbol (if trampoline entry) */
|
|
||||||
} V;
|
|
||||||
Collection ExprRefs; /* Expressions using this symbol */
|
Collection ExprRefs; /* Expressions using this symbol */
|
||||||
unsigned char ExportSize; /* Export address size */
|
unsigned char ExportSize; /* Export address size */
|
||||||
unsigned char AddrSize; /* Address size of label */
|
unsigned char AddrSize; /* Address size of label */
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
#include "sizeof.h"
|
#include "sizeof.h"
|
||||||
#include "spool.h"
|
#include "spool.h"
|
||||||
|
#include "studyexpr.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
|
|
||||||
|
|
||||||
@ -384,15 +385,16 @@ SymEntry* SymFindAny (SymTable* Scope, const char* Name)
|
|||||||
Sym = SymFind (Scope, Name, SYM_FIND_EXISTING);
|
Sym = SymFind (Scope, Name, SYM_FIND_EXISTING);
|
||||||
if (Sym) {
|
if (Sym) {
|
||||||
/* Found, return it */
|
/* Found, return it */
|
||||||
return Sym;
|
break;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
/* Not found, search in the parent scope, if we have one */
|
/* Not found, search in the parent scope, if we have one */
|
||||||
Scope = Scope->Parent;
|
Scope = Scope->Parent;
|
||||||
}
|
|
||||||
} while (Sym == 0 && Scope != 0);
|
} while (Sym == 0 && Scope != 0);
|
||||||
|
|
||||||
/* Not found */
|
/* Return the result */
|
||||||
return 0;
|
return Sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -420,26 +422,17 @@ static void SymCheckUndefined (SymEntry* S)
|
|||||||
* AutoImport flag is not set, it's an error.
|
* AutoImport flag is not set, it's an error.
|
||||||
*/
|
*/
|
||||||
SymEntry* Sym = 0;
|
SymEntry* Sym = 0;
|
||||||
if (S->SymTab) {
|
SymTable* Tab = GetSymParentScope (S);
|
||||||
/* It's a global symbol, get the higher level table */
|
|
||||||
SymTable* Tab = S->SymTab->Parent;
|
|
||||||
while (Tab) {
|
while (Tab) {
|
||||||
Sym = SymFindAny (Tab, GetString (S->Name));
|
Sym = SymFind (Tab, GetString (S->Name), SYM_FIND_EXISTING);
|
||||||
if (Sym) {
|
if (Sym && (Sym->Flags & (SF_DEFINED | SF_IMPORT)) != 0) {
|
||||||
if (Sym->Flags & (SF_DEFINED | SF_IMPORT)) {
|
|
||||||
/* We've found a symbol in a higher level that is
|
/* We've found a symbol in a higher level that is
|
||||||
* either defined in the source, or an import.
|
* either defined in the source, or an import.
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
/* The symbol found is undefined itself. Look further */
|
|
||||||
Tab = Sym->SymTab->Parent;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* No symbol found */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* No matching symbol found in this level. Look further */
|
||||||
|
Tab = Tab->Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Sym) {
|
if (Sym) {
|
||||||
@ -545,20 +538,24 @@ void SymCheck (void)
|
|||||||
S = S->List;
|
S = S->List;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Second pass: Walk again through the symbols. Ignore undefined's, since
|
/* Second pass: Walk again through the symbols. Count exports and imports
|
||||||
* we handled them in the last pass, and ignore unused symbols, since
|
* and set address sizes where this has not happened before. Ignore
|
||||||
* we handled them in the last pass, too.
|
* undefined's, since we handled them in the last pass, and ignore unused
|
||||||
|
* symbols, since we handled them in the last pass, too.
|
||||||
*/
|
*/
|
||||||
S = SymList;
|
S = SymList;
|
||||||
while (S) {
|
while (S) {
|
||||||
if ((S->Flags & SF_UNUSED) == 0 &&
|
if ((S->Flags & SF_UNUSED) == 0 &&
|
||||||
(S->Flags & SF_UNDEFMASK) != SF_UNDEFVAL) {
|
(S->Flags & SF_UNDEFMASK) != SF_UNDEFVAL) {
|
||||||
|
|
||||||
|
/* Check for defined symbols that were never referenced */
|
||||||
if ((S->Flags & SF_DEFINED) != 0 && (S->Flags & SF_REFERENCED) == 0) {
|
if ((S->Flags & SF_DEFINED) != 0 && (S->Flags & SF_REFERENCED) == 0) {
|
||||||
/* Symbol was defined but never referenced */
|
|
||||||
PWarning (&S->Pos, 2,
|
PWarning (&S->Pos, 2,
|
||||||
"Symbol `%s' is defined but never used",
|
"Symbol `%s' is defined but never used",
|
||||||
GetString (S->Name));
|
GetString (S->Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assign an index to all imports */
|
||||||
if (S->Flags & SF_IMPORT) {
|
if (S->Flags & SF_IMPORT) {
|
||||||
if ((S->Flags & (SF_REFERENCED | SF_FORCED)) == SF_NONE) {
|
if ((S->Flags & (SF_REFERENCED | SF_FORCED)) == SF_NONE) {
|
||||||
/* Imported symbol is not referenced */
|
/* Imported symbol is not referenced */
|
||||||
@ -571,11 +568,24 @@ void SymCheck (void)
|
|||||||
S->Flags |= SF_INDEXED;
|
S->Flags |= SF_INDEXED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assign an index to all exports */
|
||||||
if (S->Flags & SF_EXPORT) {
|
if (S->Flags & SF_EXPORT) {
|
||||||
/* Give the export an index, count exports */
|
/* Give the export an index, count exports */
|
||||||
S->Index = ExportCount++;
|
S->Index = ExportCount++;
|
||||||
S->Flags |= SF_INDEXED;
|
S->Flags |= SF_INDEXED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the symbol is defined but has an unknown address size,
|
||||||
|
* recalculate it.
|
||||||
|
*/
|
||||||
|
if (SymHasExpr (S) && S->AddrSize == ADDR_SIZE_DEFAULT) {
|
||||||
|
ExprDesc ED;
|
||||||
|
ED_Init (&ED);
|
||||||
|
StudyExpr (S->Expr, &ED);
|
||||||
|
S->AddrSize = ED.AddrSize;
|
||||||
|
ED_Done (&ED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next symbol */
|
/* Next symbol */
|
||||||
@ -696,7 +706,7 @@ void WriteExports (void)
|
|||||||
ObjWrite32 (ConstVal);
|
ObjWrite32 (ConstVal);
|
||||||
} else {
|
} else {
|
||||||
/* Expression involved */
|
/* Expression involved */
|
||||||
WriteExpr (S->V.Expr);
|
WriteExpr (S->Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the source file position */
|
/* Write the source file position */
|
||||||
@ -762,7 +772,7 @@ void WriteDbgSyms (void)
|
|||||||
ObjWrite32 (ConstVal);
|
ObjWrite32 (ConstVal);
|
||||||
} else {
|
} else {
|
||||||
/* Expression involved */
|
/* Expression involved */
|
||||||
WriteExpr (S->V.Expr);
|
WriteExpr (S->Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the source file position */
|
/* Write the source file position */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user