parent
fe59626953
commit
8e35a82c91
8 changed files with 87 additions and 11 deletions
|
@ -3,7 +3,7 @@ SYMBOLS {
|
||||||
__STACKSIZE__: type = weak, value = $0800; # 2k stack
|
__STACKSIZE__: type = weak, value = $0800; # 2k stack
|
||||||
}
|
}
|
||||||
MEMORY {
|
MEMORY {
|
||||||
ZP: file = "", start = $0000, size = $001A;
|
ZP: file = "", start = $0000, size = $001B;
|
||||||
HEADER: file = %O, start = $0000, size = $0001;
|
HEADER: file = %O, start = $0000, size = $0001;
|
||||||
MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
|
MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ SYMBOLS {
|
||||||
__STACKSIZE__: type = weak, value = $0800; # 2k stack
|
__STACKSIZE__: type = weak, value = $0800; # 2k stack
|
||||||
}
|
}
|
||||||
MEMORY {
|
MEMORY {
|
||||||
ZP: file = "", start = $0000, size = $001A;
|
ZP: file = "", start = $0000, size = $001B;
|
||||||
HEADER: file = %O, start = $0000, size = $0001;
|
HEADER: file = %O, start = $0000, size = $0001;
|
||||||
MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
|
MAIN: file = %O, define = yes, start = $0200, size = $FDF0 - __STACKSIZE__;
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,8 +242,7 @@ static void Parse (void)
|
||||||
Error ("Variable `%s' has unknown size", Decl.Ident);
|
Error ("Variable `%s' has unknown size", Decl.Ident);
|
||||||
}
|
}
|
||||||
Entry->Flags &= ~(SC_STORAGE | SC_DEF);
|
Entry->Flags &= ~(SC_STORAGE | SC_DEF);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
/* A global (including static) uninitialized variable
|
/* A global (including static) uninitialized variable
|
||||||
** is only a tentative definition. For example, this is valid:
|
** is only a tentative definition. For example, this is valid:
|
||||||
** int i;
|
** int i;
|
||||||
|
@ -251,7 +250,16 @@ static void Parse (void)
|
||||||
** static int j;
|
** static int j;
|
||||||
** static int j = 42;
|
** static int j = 42;
|
||||||
** Code for these will be generated in FinishCompile.
|
** Code for these will be generated in FinishCompile.
|
||||||
|
** For now, just save the BSS segment name
|
||||||
|
** (can be set with #pragma bss-name)
|
||||||
*/
|
*/
|
||||||
|
const char* bssName = GetSegName (SEG_BSS);
|
||||||
|
if (Entry->V.BssName && strcmp (Entry->V.BssName, bssName) != 0) {
|
||||||
|
Error ("Global variable `%s' has already been defined in `%s' segment",
|
||||||
|
Entry->Name, Entry->V.BssName);
|
||||||
|
}
|
||||||
|
Entry->V.BssName = xstrdup (bssName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -418,6 +426,8 @@ void FinishCompile (void)
|
||||||
} else if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) {
|
} else if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) {
|
||||||
/* Tentative definition of uninitialized global variable */
|
/* Tentative definition of uninitialized global variable */
|
||||||
g_usebss ();
|
g_usebss ();
|
||||||
|
SetSegName (SEG_BSS, Entry->V.BssName);
|
||||||
|
g_segname (SEG_BSS); /* TODO: skip if same as before */
|
||||||
g_defgloblabel (Entry->Name);
|
g_defgloblabel (Entry->Name);
|
||||||
g_res (SizeOf (Entry->Type));
|
g_res (SizeOf (Entry->Type));
|
||||||
/* Mark as defined, so that it will be exported not imported */
|
/* Mark as defined, so that it will be exported not imported */
|
||||||
|
|
|
@ -71,6 +71,7 @@ SymEntry* NewSymEntry (const char* Name, unsigned Flags)
|
||||||
E->Type = 0;
|
E->Type = 0;
|
||||||
E->Attr = 0;
|
E->Attr = 0;
|
||||||
E->AsmName = 0;
|
E->AsmName = 0;
|
||||||
|
E->V.BssName = 0;
|
||||||
memcpy (E->Name, Name, Len+1);
|
memcpy (E->Name, Name, Len+1);
|
||||||
|
|
||||||
/* Return the new entry */
|
/* Return the new entry */
|
||||||
|
|
|
@ -153,6 +153,8 @@ struct SymEntry {
|
||||||
struct LiteralPool* LitPool; /* Literal pool for this function */
|
struct LiteralPool* LitPool; /* Literal pool for this function */
|
||||||
} F;
|
} F;
|
||||||
|
|
||||||
|
/* Segment name for tentantive global definitions */
|
||||||
|
const char* BssName;
|
||||||
} V;
|
} V;
|
||||||
char Name[1]; /* Name, dynamically allocated */
|
char Name[1]; /* Name, dynamically allocated */
|
||||||
};
|
};
|
||||||
|
|
20
test/err/bss-name-conflict.c
Normal file
20
test/err/bss-name-conflict.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
!!DESCRIPTION!! conflicting bss-name pragmas
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Piotr Fusik
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/409
|
||||||
|
*/
|
||||||
|
|
||||||
|
char oam_off;
|
||||||
|
#pragma bss-name (push,"ZEROPAGE")
|
||||||
|
char oam_off;
|
||||||
|
#pragma bss-name (pop)
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
22
test/val/bss-name-decl.c
Normal file
22
test/val/bss-name-decl.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
!!DESCRIPTION!! bss-name pragma not affecting declarations
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Piotr Fusik
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/409
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma bss-name (push,"ZEROPAGE")
|
||||||
|
|
||||||
|
char n; /* only a declaration because followed by definition */
|
||||||
|
char n = 1; /* not BSS */
|
||||||
|
|
||||||
|
#pragma bss-name (pop)
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return (unsigned) &n >= 0x100 ? 0 : 1;
|
||||||
|
}
|
21
test/val/bss-name.c
Normal file
21
test/val/bss-name.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
!!DESCRIPTION!! bss-name pragma
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Piotr Fusik
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
see: https://github.com/cc65/cc65/issues/409
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma bss-name (push,"ZEROPAGE")
|
||||||
|
|
||||||
|
char zp_var;
|
||||||
|
|
||||||
|
#pragma bss-name (pop)
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return (unsigned) &zp_var < 0x100 ? 0 : 1;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue