Added new .FORCEIMPORT pseudo op

git-svn-id: svn://svn.cc65.org/cc65/trunk@2007 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-03-07 11:33:14 +00:00
parent d5d0d65cd6
commit b06d37d809
5 changed files with 140 additions and 54 deletions

View File

@@ -140,7 +140,7 @@ static void SetBoolOption (unsigned char* Flag)
static void ExportImport (void (*SymFunc) (const char*, int), int ZP) static void ExportImport (void (*SymFunc) (const char*))
/* Export or import symbols */ /* Export or import symbols */
{ {
while (1) { while (1) {
@@ -148,7 +148,7 @@ static void ExportImport (void (*SymFunc) (const char*, int), int ZP)
ErrorSkip (ERR_IDENT_EXPECTED); ErrorSkip (ERR_IDENT_EXPECTED);
break; break;
} }
SymFunc (SVal, ZP); SymFunc (SVal);
NextTok (); NextTok ();
if (Tok == TOK_COMMA) { if (Tok == TOK_COMMA) {
NextTok (); NextTok ();
@@ -640,7 +640,7 @@ static void DoExitMacro (void)
static void DoExport (void) static void DoExport (void)
/* Export a symbol */ /* Export a symbol */
{ {
ExportImport (SymExport, 0); ExportImport (SymExport);
} }
@@ -648,7 +648,7 @@ static void DoExport (void)
static void DoExportZP (void) static void DoExportZP (void)
/* Export a zeropage symbol */ /* Export a zeropage symbol */
{ {
ExportImport (SymExport, 1); ExportImport (SymExportZP);
} }
@@ -791,10 +791,18 @@ static void DoFileOpt (void)
static void DoForceImport (void)
/* Do a forced import on a symbol */
{
ExportImport (SymImportForced);
}
static void DoGlobal (void) static void DoGlobal (void)
/* Declare a global symbol */ /* Declare a global symbol */
{ {
ExportImport (SymGlobal, 0); ExportImport (SymGlobal);
} }
@@ -802,7 +810,7 @@ static void DoGlobal (void)
static void DoGlobalZP (void) static void DoGlobalZP (void)
/* Declare a global zeropage symbol */ /* Declare a global zeropage symbol */
{ {
ExportImport (SymGlobal, 1); ExportImport (SymGlobalZP);
} }
@@ -836,7 +844,7 @@ static void DoI8 (void)
static void DoImport (void) static void DoImport (void)
/* Import a symbol */ /* Import a symbol */
{ {
ExportImport (SymImport, 0); ExportImport (SymImport);
} }
@@ -844,7 +852,7 @@ static void DoImport (void)
static void DoImportZP (void) static void DoImportZP (void)
/* Import a zero page symbol */ /* Import a zero page symbol */
{ {
ExportImport (SymImport, 1); ExportImport (SymImportZP);
} }
@@ -1435,6 +1443,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoFarAddr }, { ccNone, DoFarAddr },
{ ccNone, DoFeature }, { ccNone, DoFeature },
{ ccNone, DoFileOpt }, { ccNone, DoFileOpt },
{ ccNone, DoForceImport },
{ ccNone, DoUnexpected }, /* .FORCEWORD */ { ccNone, DoUnexpected }, /* .FORCEWORD */
{ ccNone, DoGlobal }, { ccNone, DoGlobal },
{ ccNone, DoGlobalZP }, { ccNone, DoGlobalZP },

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2002 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -167,6 +167,7 @@ struct DotKeyword {
{ ".FEATURE", TOK_FEATURE }, { ".FEATURE", TOK_FEATURE },
{ ".FILEOPT", TOK_FILEOPT }, { ".FILEOPT", TOK_FILEOPT },
{ ".FOPT", TOK_FILEOPT }, { ".FOPT", TOK_FILEOPT },
{ ".FORCEIMPORT", TOK_FORCEIMPORT },
{ ".FORCEWORD", TOK_FORCEWORD }, { ".FORCEWORD", TOK_FORCEWORD },
{ ".GLOBAL", TOK_GLOBAL }, { ".GLOBAL", TOK_GLOBAL },
{ ".GLOBALZP", TOK_GLOBALZP }, { ".GLOBALZP", TOK_GLOBALZP },

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2002 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -106,7 +106,7 @@ enum Token {
TOK_RBRACK, /* ] */ TOK_RBRACK, /* ] */
TOK_MACPARAM, /* Macro parameter, not generated by scanner */ TOK_MACPARAM, /* Macro parameter, not generated by scanner */
TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */ TOK_REPCOUNTER, /* Repeat counter, not generated by scanner */
/* The next ones are tokens for the pseudo instructions. Keep together! */ /* The next ones are tokens for the pseudo instructions. Keep together! */
TOK_FIRSTPSEUDO, TOK_FIRSTPSEUDO,
@@ -149,6 +149,7 @@ enum Token {
TOK_FARADDR, TOK_FARADDR,
TOK_FEATURE, TOK_FEATURE,
TOK_FILEOPT, TOK_FILEOPT,
TOK_FORCEIMPORT,
TOK_FORCEWORD, TOK_FORCEWORD,
TOK_GLOBAL, TOK_GLOBAL,
TOK_GLOBALZP, TOK_GLOBALZP,
@@ -234,7 +235,7 @@ extern int ForcedEnd; /* Force end of assembly */
/*****************************************************************************/ /*****************************************************************************/
void NewInputFile (const char* Name); void NewInputFile (const char* Name);
/* Open a new input file */ /* Open a new input file */

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2002 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -59,6 +59,7 @@
/* Bits for the Flags value in SymEntry */ /* Bits for the Flags value in SymEntry */
#define SF_NONE 0x0000 /* Empty flag set */
#define SF_USER 0x0001 /* User bit */ #define SF_USER 0x0001 /* User bit */
#define SF_TRAMPOLINE 0x0002 /* Trampoline entry */ #define SF_TRAMPOLINE 0x0002 /* Trampoline entry */
#define SF_EXPORT 0x0004 /* Export this symbol */ #define SF_EXPORT 0x0004 /* Export this symbol */
@@ -67,6 +68,7 @@
#define SF_ZP 0x0020 /* Declared as zeropage symbol */ #define SF_ZP 0x0020 /* Declared as zeropage symbol */
#define SF_ABS 0x0040 /* Declared as absolute symbol */ #define SF_ABS 0x0040 /* Declared as absolute symbol */
#define SF_LABEL 0x0080 /* Used as a label */ #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_INDEXED 0x0800 /* Index is valid */
#define SF_CONST 0x1000 /* The symbol has a constant value */ #define SF_CONST 0x1000 /* The symbol has a constant value */
#define SF_MULTDEF 0x2000 /* Multiply defined symbol */ #define SF_MULTDEF 0x2000 /* Multiply defined symbol */
@@ -76,8 +78,6 @@
/* Combined stuff */ /* Combined stuff */
#define SF_UNDEFMASK (SF_REFERENCED | SF_DEFINED | SF_IMPORT) #define SF_UNDEFMASK (SF_REFERENCED | SF_DEFINED | SF_IMPORT)
#define SF_UNDEFVAL (SF_REFERENCED) #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_EXPMASK (SF_TRAMPOLINE | SF_EXPORT)
#define SF_EXPVAL (SF_EXPORT) #define SF_EXPVAL (SF_EXPORT)
#define SF_DBGINFOMASK (SF_TRAMPOLINE | SF_DEFINED | SF_EXPORT | SF_IMPORT) #define SF_DBGINFOMASK (SF_TRAMPOLINE | SF_DEFINED | SF_EXPORT | SF_IMPORT)
@@ -462,7 +462,7 @@ SymEntry* SymRef (const char* Name, int Scope)
void SymImport (const char* Name, int ZP) static void SymImportInternal (const char* Name, unsigned Flags)
/* Mark the given symbol as an imported symbol */ /* Mark the given symbol as an imported symbol */
{ {
SymEntry* S; SymEntry* S;
@@ -486,26 +486,47 @@ void SymImport (const char* Name, int ZP)
return; 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 * silently remove the global flag
*/ */
if (S->Flags & SF_GLOBAL) { 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); Error (ERR_SYM_REDECL_MISMATCH, Name);
} }
S->Flags &= ~SF_GLOBAL; S->Flags &= ~SF_GLOBAL;
} }
/* Set the symbol data */ /* Set the symbol data */
S->Flags |= SF_IMPORT; S->Flags |= (SF_IMPORT | Flags);
if (ZP) {
S->Flags |= SF_ZP;
}
} }
void SymExport (const char* Name, int ZP) 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 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 */ /* Mark the given symbol as an exported symbol */
{ {
SymEntry* S; SymEntry* S;
@@ -528,22 +549,35 @@ void SymExport (const char* Name, int ZP)
* silently remove the global flag * silently remove the global flag
*/ */
if (S->Flags & SF_GLOBAL) { 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); Error (ERR_SYM_REDECL_MISMATCH, Name);
} }
S->Flags &= ~SF_GLOBAL; S->Flags &= ~SF_GLOBAL;
} }
/* Set the symbol data */ /* Set the symbol data */
S->Flags |= SF_EXPORT | SF_REFERENCED; S->Flags |= (SF_EXPORT | SF_REFERENCED | Flags);
if (ZP) {
S->Flags |= SF_ZP;
}
} }
void SymGlobal (const char* Name, int ZP) 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);
}
static void SymGlobalInternal (const char* Name, unsigned Flags)
/* Mark the given symbol as a global symbol, that is, as a symbol that is /* Mark the given symbol as a global symbol, that is, as a symbol that is
* either imported or exported. * either imported or exported.
*/ */
@@ -562,17 +596,34 @@ void SymGlobal (const char* Name, int ZP)
/* If the symbol is already marked as import or export, check the /* If the symbol is already marked as import or export, check the
* size of the definition, then bail out. */ * size of the definition, then bail out. */
if (S->Flags & SF_IMPORT || S->Flags & SF_EXPORT) { 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); Error (ERR_SYM_REDECL_MISMATCH, Name);
} }
return; return;
} }
/* Mark the symbol */ /* Mark the symbol */
S->Flags |= SF_GLOBAL; S->Flags |= (SF_GLOBAL | Flags);
if (ZP) { }
S->Flags |= SF_ZP;
}
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);
} }
@@ -1005,7 +1056,7 @@ void SymCheck (void)
PWarning (&S->Pos, WARN_SYM_NOT_REFERENCED, S->Name); PWarning (&S->Pos, WARN_SYM_NOT_REFERENCED, S->Name);
} }
if (S->Flags & SF_IMPORT) { 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 */ /* Imported symbol is not referenced */
PWarning (&S->Pos, WARN_IMPORT_NOT_REFERENCED, S->Name); PWarning (&S->Pos, WARN_IMPORT_NOT_REFERENCED, S->Name);
} else { } else {
@@ -1063,10 +1114,18 @@ void WriteImports (void)
/* Write the import count to the list */ /* Write the import count to the list */
ObjWriteVar (ImportCount); 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; S = SymList;
while (S) { 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) { if (S->Flags & SF_ZP) {
ObjWrite8 (IMP_ZP); ObjWrite8 (IMP_ZP);
} else { } else {
@@ -1074,7 +1133,9 @@ void WriteImports (void)
} }
ObjWriteStr (S->Name); ObjWriteStr (S->Name);
ObjWritePos (&S->Pos); ObjWritePos (&S->Pos);
} } else {
printf ("ignored\n");
}
S = S->List; S = S->List;
} }

View File

@@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998 Ullrich von Bassewitz */ /* (C) 1998-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@cc65.org */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@@ -85,16 +85,30 @@ int SymIsDef (const char* Name, int Scope);
int SymIsRef (const char* Name, int Scope); int SymIsRef (const char* Name, int Scope);
/* Return true if the given symbol has been referenced */ /* 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 */ /* 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 */ /* 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 /* Mark the given symbol as a global symbol, that is, as a symbol that is
* either imported or exported. * 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); void SymConDes (const char* Name, unsigned Type, unsigned Prio);
/* Mark the given symbol as a module constructor/destructor. This will also /* Mark the given symbol as a module constructor/destructor. This will also