-static void ExportImport (void (*SymFunc) (const char*, int), int ZP)
+static void ExportImport (void (*SymFunc) (const char*))
/* Export or import symbols */
{
while (1) {
ErrorSkip (ERR_IDENT_EXPECTED);
break;
}
- SymFunc (SVal, ZP);
+ SymFunc (SVal);
NextTok ();
if (Tok == TOK_COMMA) {
NextTok ();
static void DoExport (void)
/* Export a symbol */
{
- ExportImport (SymExport, 0);
+ ExportImport (SymExport);
}
static void DoExportZP (void)
/* Export a zeropage symbol */
{
- ExportImport (SymExport, 1);
+ ExportImport (SymExportZP);
}
+static void DoForceImport (void)
+/* Do a forced import on a symbol */
+{
+ ExportImport (SymImportForced);
+}
+
+
+
static void DoGlobal (void)
/* Declare a global symbol */
{
- ExportImport (SymGlobal, 0);
+ ExportImport (SymGlobal);
}
static void DoGlobalZP (void)
/* Declare a global zeropage symbol */
{
- ExportImport (SymGlobal, 1);
+ ExportImport (SymGlobalZP);
}
static void DoImport (void)
/* Import a symbol */
{
- ExportImport (SymImport, 0);
+ ExportImport (SymImport);
}
static void DoImportZP (void)
/* Import a zero page symbol */
{
- ExportImport (SymImport, 1);
+ ExportImport (SymImportZP);
}
{ ccNone, DoFarAddr },
{ ccNone, DoFeature },
{ ccNone, DoFileOpt },
+ { ccNone, DoForceImport },
{ ccNone, DoUnexpected }, /* .FORCEWORD */
{ ccNone, DoGlobal },
{ ccNone, DoGlobalZP },
/* */
/* */
/* */
-/* (C) 1998-2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2003 Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Bits for the Flags value in SymEntry */
+#define SF_NONE 0x0000 /* Empty flag set */
#define SF_USER 0x0001 /* User bit */
#define SF_TRAMPOLINE 0x0002 /* Trampoline entry */
#define SF_EXPORT 0x0004 /* Export this symbol */
#define SF_ZP 0x0020 /* Declared as zeropage symbol */
#define SF_ABS 0x0040 /* Declared as absolute symbol */
#define SF_LABEL 0x0080 /* Used as a label */
+#define SF_FORCED 0x0100 /* Forced import, SF_IMPORT also set */
#define SF_INDEXED 0x0800 /* Index is valid */
#define SF_CONST 0x1000 /* The symbol has a constant value */
#define SF_MULTDEF 0x2000 /* Multiply defined symbol */
/* Combined stuff */
#define SF_UNDEFMASK (SF_REFERENCED | SF_DEFINED | SF_IMPORT)
#define SF_UNDEFVAL (SF_REFERENCED)
-#define SF_IMPMASK (SF_TRAMPOLINE | SF_IMPORT | SF_REFERENCED)
-#define SF_IMPVAL (SF_IMPORT | SF_REFERENCED)
#define SF_EXPMASK (SF_TRAMPOLINE | SF_EXPORT)
#define SF_EXPVAL (SF_EXPORT)
#define SF_DBGINFOMASK (SF_TRAMPOLINE | SF_DEFINED | SF_EXPORT | SF_IMPORT)
-void SymImport (const char* Name, int ZP)
+static void SymImportInternal (const char* Name, unsigned Flags)
/* Mark the given symbol as an imported symbol */
{
SymEntry* S;
return;
}
- /* If the symbol is marked as global, check the symbol size, then do
+ /* If the symbol is marked as global, check the symbol flags, then do
* silently remove the global flag
*/
if (S->Flags & SF_GLOBAL) {
- if ((ZP != 0) != ((S->Flags & SF_ZP) != 0)) {
+ if ((Flags & (SF_ZP | SF_FORCED)) != (S->Flags & (SF_ZP | SF_FORCED))) {
Error (ERR_SYM_REDECL_MISMATCH, Name);
}
S->Flags &= ~SF_GLOBAL;
}
/* Set the symbol data */
- S->Flags |= SF_IMPORT;
- if (ZP) {
- S->Flags |= SF_ZP;
- }
+ S->Flags |= (SF_IMPORT | Flags);
+}
+
+
+
+void SymImport (const char* Name)
+/* Mark the given symbol as an imported symbol */
+{
+ SymImportInternal (Name, SF_NONE);
+}
+
+
+
+void SymImportZP (const char* Name)
+/* Mark the given symbol as a forced imported symbol */
+{
+ SymImportInternal (Name, SF_ZP);
}
-void SymExport (const char* Name, int ZP)
+void SymImportForced (const char* Name)
+/* Mark the given symbol as a forced imported symbol */
+{
+ SymImportInternal (Name, SF_FORCED);
+}
+
+
+
+static void SymExportInternal (const char* Name, unsigned Flags)
/* Mark the given symbol as an exported symbol */
{
SymEntry* S;
* silently remove the global flag
*/
if (S->Flags & SF_GLOBAL) {
- if ((ZP != 0) != ((S->Flags & SF_ZP) != 0)) {
+ if ((Flags & SF_ZP) != (S->Flags & SF_ZP)) {
Error (ERR_SYM_REDECL_MISMATCH, Name);
}
S->Flags &= ~SF_GLOBAL;
}
/* Set the symbol data */
- S->Flags |= SF_EXPORT | SF_REFERENCED;
- if (ZP) {
- S->Flags |= SF_ZP;
- }
+ S->Flags |= (SF_EXPORT | SF_REFERENCED | Flags);
+}
+
+
+
+void SymExport (const char* Name)
+/* Mark the given symbol as an exported symbol */
+{
+ SymExportInternal (Name, SF_NONE);
+}
+
+
+
+void SymExportZP (const char* Name)
+/* Mark the given symbol as an exported zeropage symbol */
+{
+ SymExportInternal (Name, SF_ZP);
}
-void SymGlobal (const char* Name, int ZP)
+static void SymGlobalInternal (const char* Name, unsigned Flags)
/* Mark the given symbol as a global symbol, that is, as a symbol that is
* either imported or exported.
*/
/* If the symbol is already marked as import or export, check the
* size of the definition, then bail out. */
if (S->Flags & SF_IMPORT || S->Flags & SF_EXPORT) {
- if ((ZP != 0) != ((S->Flags & SF_ZP) != 0)) {
+ if ((Flags & SF_ZP) != (S->Flags & SF_ZP)) {
Error (ERR_SYM_REDECL_MISMATCH, Name);
}
return;
}
/* Mark the symbol */
- S->Flags |= SF_GLOBAL;
- if (ZP) {
- S->Flags |= SF_ZP;
- }
+ S->Flags |= (SF_GLOBAL | Flags);
+}
+
+
+
+void SymGlobal (const char* Name)
+/* Mark the given symbol as a global symbol, that is, as a symbol that is
+ * either imported or exported.
+ */
+{
+ SymGlobalInternal (Name, SF_NONE);
+}
+
+
+
+void SymGlobalZP (const char* Name)
+/* Mark the given symbol as a global zeropage symbol, that is, as a symbol
+ * that is either imported or exported.
+ */
+{
+ SymGlobalInternal (Name, SF_ZP);
}
PWarning (&S->Pos, WARN_SYM_NOT_REFERENCED, S->Name);
}
if (S->Flags & SF_IMPORT) {
- if ((S->Flags & SF_REFERENCED) == 0) {
+ if ((S->Flags & (SF_REFERENCED | SF_FORCED)) == SF_NONE) {
/* Imported symbol is not referenced */
PWarning (&S->Pos, WARN_IMPORT_NOT_REFERENCED, S->Name);
} else {
/* Write the import count to the list */
ObjWriteVar (ImportCount);
- /* Walk throught list and write all imports to the file */
+ /* Walk throught list and write all valid imports to the file. An import
+ * is considered valid, if it is either referenced, or the forced bit is
+ * set. Otherwise, the import is ignored (no need to link in something
+ * that isn't used).
+ */
S = SymList;
while (S) {
- if ((S->Flags & SF_IMPMASK) == SF_IMPVAL) {
+ printf ("%s: %04X - ", S->Name, S->Flags);
+ if ((S->Flags & (SF_TRAMPOLINE | SF_IMPORT)) == SF_IMPORT &&
+ (S->Flags & (SF_REFERENCED | SF_FORCED)) != 0) {
+
+ printf ("imported\n");
if (S->Flags & SF_ZP) {
ObjWrite8 (IMP_ZP);
} else {
}
ObjWriteStr (S->Name);
ObjWritePos (&S->Pos);
- }
+ } else {
+ printf ("ignored\n");
+ }
S = S->List;
}
/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2003 Ullrich von Bassewitz */
+/* Römerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
int SymIsRef (const char* Name, int Scope);
/* Return true if the given symbol has been referenced */
-void SymImport (const char* Name, int ZP);
+void SymImport (const char* Name);
/* Mark the given symbol as an imported symbol */
-void SymExport (const char* Name, int ZP);
+void SymImportZP (const char* Name);
+/* Mark the given symbol as a imported zeropage symbol */
+
+void SymImportForced (const char* Name);
+/* Mark the given symbol as a forced imported symbol */
+
+void SymExport (const char* Name);
/* Mark the given symbol as an exported symbol */
-void SymGlobal (const char* Name, int ZP);
+void SymExportZP (const char* Name);
+/* Mark the given symbol as an exported zeropage symbol */
+
+void SymGlobal (const char* Name);
/* Mark the given symbol as a global symbol, that is, as a symbol that is
* either imported or exported.
*/
+
+void SymGlobalZP (const char* Name);
+/* Mark the given symbol as a global zeropage symbol, that is, as a symbol
+ * that is either imported or exported.
+ */
void SymConDes (const char* Name, unsigned Type, unsigned Prio);
/* Mark the given symbol as a module constructor/destructor. This will also