1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Remove the hardcoded limit from the literal pool.

git-svn-id: svn://svn.cc65.org/cc65/trunk@678 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-03-26 21:57:07 +00:00
parent 1ced0327ed
commit 2eab65ad24
12 changed files with 152 additions and 84 deletions

View File

@ -253,9 +253,6 @@ void Compile (void)
char* Path; char* Path;
/* Setup variables */
LiteralLabel = GetLabel ();
/* Add some standard paths to the include search path */ /* Add some standard paths to the include search path */
AddIncludePath ("", INC_USER); /* Current directory */ AddIncludePath ("", INC_USER); /* Current directory */
AddIncludePath ("include", INC_SYS); AddIncludePath ("include", INC_SYS);
@ -291,6 +288,9 @@ void Compile (void)
} }
} }
/* Initialize the literal pool */
InitLiteralPool ();
/* Create the base lexical level */ /* Create the base lexical level */
EnterGlobalLevel (); EnterGlobalLevel ();
@ -300,14 +300,14 @@ void Compile (void)
/* Ok, start the ball rolling... */ /* Ok, start the ball rolling... */
Parse (); Parse ();
/* Dump literal pool. */ /* Dump the literal pool. */
DumpLiteralPool (); DumpLiteralPool ();
/* Write imported/exported symbols */ /* Write imported/exported symbols */
EmitExternals (); EmitExternals ();
if (Debug) { if (Debug) {
PrintLiteralStats (stdout); PrintLiteralPoolStats (stdout);
PrintMacroStats (stdout); PrintMacroStats (stdout);
} }

View File

@ -1,8 +1,35 @@
/* /*****************************************************************************/
* declare.c /* */
* /* declare.c */
* Ullrich von Bassewitz, 20.06.1998 /* */
*/ /* Parse variable and function declarations */
/* */
/* */
/* */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
@ -1025,11 +1052,11 @@ static void ParseStructInit (type* Type)
void ParseInit (type* T) void ParseInit (type* T)
/* Parse initialization of variables. */ /* Parse initialization of variables. */
{ {
int count;
struct expent lval; struct expent lval;
type* t; type* t;
const char* str; const char* str;
int sz; int Count;
int Size;
switch (UnqualifiedType (*T)) { switch (UnqualifiedType (*T)) {
@ -1070,32 +1097,32 @@ void ParseInit (type* T)
break; break;
case T_ARRAY: case T_ARRAY:
sz = Decode (T + 1); Size = Decode (T + 1);
t = T + DECODE_SIZE + 1; t = T + DECODE_SIZE + 1;
if (IsTypeChar(t) && curtok == TOK_SCONST) { if (IsTypeChar(t) && curtok == TOK_SCONST) {
str = GetLiteral (curval); str = GetLiteral (curval);
count = strlen (str) + 1; Count = strlen (str) + 1;
TranslateLiteralPool (curval); /* Translate into target charset */ TranslateLiteralPool (curval); /* Translate into target charset */
g_defbytes (str, count); g_defbytes (str, Count);
ResetLiteralOffs (curval); /* Remove string from pool */ ResetLiteralPoolOffs (curval); /* Remove string from pool */
NextToken (); NextToken ();
} else { } else {
ConsumeLCurly (); ConsumeLCurly ();
count = 0; Count = 0;
while (curtok != TOK_RCURLY) { while (curtok != TOK_RCURLY) {
ParseInit (T + DECODE_SIZE + 1); ParseInit (T + DECODE_SIZE + 1);
++count; ++Count;
if (curtok != TOK_COMMA) if (curtok != TOK_COMMA)
break; break;
NextToken (); NextToken ();
} }
ConsumeRCurly (); ConsumeRCurly ();
} }
if (sz == 0) { if (Size == 0) {
Encode (T + 1, count); Encode (T + 1, Count);
} else if (count < sz) { } else if (Count < Size) {
g_zerobytes ((sz - count) * SizeOf (T + DECODE_SIZE + 1)); g_zerobytes ((Size - Count) * SizeOf (T + DECODE_SIZE + 1));
} else if (count > sz) { } else if (Count > Size) {
Error ("Too many initializers"); Error ("Too many initializers");
} }
break; break;

View File

@ -1,8 +1,35 @@
/* /*****************************************************************************/
* declare.h /* */
* /* declare.h */
* Ullrich von Bassewitz, 20.06.1998 /* */
*/ /* Parse variable and function declarations */
/* */
/* */
/* */
/* (C) 1998-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
@ -11,13 +38,14 @@
/* cc65 */
#include "scanner.h" #include "scanner.h"
#include "symtab.h" #include "symtab.h"
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
@ -31,7 +59,7 @@
typedef struct DeclSpec DeclSpec; typedef struct DeclSpec DeclSpec;
struct DeclSpec { struct DeclSpec {
unsigned StorageClass; /* One of the SC_xxx flags */ unsigned StorageClass; /* One of the SC_xxx flags */
type Type [MAXTYPELEN]; /* Type of the declaration spec */ type Type [MAXTYPELEN]; /* Type of the declaration spec */
unsigned Flags; /* Bitmapped flags */ unsigned Flags; /* Bitmapped flags */
}; };
@ -42,7 +70,7 @@ struct Declaration {
type Type [MAXTYPELEN]; /* The type */ type Type [MAXTYPELEN]; /* The type */
/* Working variables */ /* Working variables */
type* T; /* Used to build Type */ type* T; /* Used to build Type */
}; };
/* Modes for ParseDecl */ /* Modes for ParseDecl */
@ -73,7 +101,7 @@ void CheckEmptyDecl (const DeclSpec* D);
* warning if not. * warning if not.
*/ */
void ParseInit (type* tptr); void ParseInit (type* T);
/* Parse initialization of variables. */ /* Parse initialization of variables. */

View File

@ -309,7 +309,7 @@ void DefineData (struct expent* lval)
case E_TLIT: case E_TLIT:
/* a literal of some kind */ /* a literal of some kind */
g_defdata (CF_STATIC, LiteralLabel, lval->e_const); g_defdata (CF_STATIC, LiteralPoolLabel, lval->e_const);
break; break;
default: default:
@ -352,7 +352,7 @@ static void lconst (unsigned flags, struct expent* lval)
case E_TLIT: case E_TLIT:
/* Literal string */ /* Literal string */
g_getimmed (CF_STATIC, LiteralLabel, lval->e_const); g_getimmed (CF_STATIC, LiteralPoolLabel, lval->e_const);
break; break;
default: default:
@ -756,7 +756,7 @@ void doasm (void)
* will fail if the next token is also a string token, but that's a * will fail if the next token is also a string token, but that's a
* syntax error anyway, because we expect a right paren. * syntax error anyway, because we expect a right paren.
*/ */
ResetLiteralOffs (curval); ResetLiteralPoolOffs (curval);
} }
/* Skip the string token */ /* Skip the string token */

View File

@ -333,9 +333,6 @@ void NewFunc (SymEntry* Func)
/* Emit references to imports/exports */ /* Emit references to imports/exports */
EmitExternals (); EmitExternals ();
/* Dump literal data created by the function */
DumpLiteralPool ();
/* Cleanup register variables */ /* Cleanup register variables */
DoneRegVars (); DoneRegVars ();

View File

@ -38,6 +38,7 @@
/* common */ /* common */
#include "check.h" #include "check.h"
#include "tgttrans.h" #include "tgttrans.h"
#include "xmalloc.h"
/* cc65 */ /* cc65 */
#include "asmlabel.h" #include "asmlabel.h"
@ -49,32 +50,39 @@
/*****************************************************************************/ /*****************************************************************************/
/* Data */ /* Data */
/*****************************************************************************/ /*****************************************************************************/
#define LITPOOL_SIZE 4096 /* Max strings per function */ static unsigned char* LiteralPoolBuf = 0; /* Pointer to buffer */
static unsigned char LiteralPool[LITPOOL_SIZE]; /* The literal pool */ static unsigned LiteralPoolSize = 0; /* Size of pool */
static unsigned LiteralOffs = 0; /* Current pool offset */ static unsigned LiteralPoolOffs = 0; /* Current offset into pool */
static unsigned LiteralSpace = 0; /* Space used (stats only) */ unsigned LiteralPoolLabel = 0; /* Pool asm label */
unsigned LiteralLabel = 1; /* Pool asm label */
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
void InitLiteralPool (void)
/* Initialize the literal pool */
{
/* Get the pool label */
LiteralPoolLabel = GetLabel ();
}
void TranslateLiteralPool (unsigned Offs) void TranslateLiteralPool (unsigned Offs)
/* Translate the literals starting from the given offset into the target /* Translate the literals starting from the given offset into the target
* charset. * charset.
*/ */
{ {
TgtTranslateBuf (LiteralPool + Offs, LiteralOffs - Offs); TgtTranslateBuf (LiteralPoolBuf + Offs, LiteralPoolOffs - Offs);
} }
@ -82,8 +90,8 @@ void TranslateLiteralPool (unsigned Offs)
void DumpLiteralPool (void) void DumpLiteralPool (void)
/* Dump the literal pool */ /* Dump the literal pool */
{ {
/* if nothing there, exit... */ /* If nothing there, exit... */
if (LiteralOffs == 0) { if (LiteralPoolOffs == 0) {
return; return;
} }
@ -95,40 +103,35 @@ void DumpLiteralPool (void)
} }
/* Define the label */ /* Define the label */
g_defloclabel (LiteralLabel); g_defloclabel (LiteralPoolLabel);
/* Translate the buffer contents into the target charset */ /* Translate the buffer contents into the target charset */
TranslateLiteralPool (0); TranslateLiteralPool (0);
/* Output the buffer data */ /* Output the buffer data */
g_defbytes (LiteralPool, LiteralOffs); g_defbytes (LiteralPoolBuf, LiteralPoolOffs);
/* Switch back to the code segment */ /* Switch back to the code segment */
g_usecode (); g_usecode ();
/* Reset the buffer */
LiteralSpace += LiteralOffs; /* Count literal bytes emitted */
LiteralLabel = GetLabel (); /* Get a new pool label */
LiteralOffs = 0;
} }
unsigned GetLiteralOffs (void) unsigned GetLiteralPoolOffs (void)
/* Return the current offset into the literal pool */ /* Return the current offset into the literal pool */
{ {
return LiteralOffs; return LiteralPoolOffs;
} }
void ResetLiteralOffs (unsigned Offs) void ResetLiteralPoolOffs (unsigned Offs)
/* Reset the offset into the literal pool to some earlier value, effectively /* Reset the offset into the literal pool to some earlier value, effectively
* removing values from the pool. * removing values from the pool.
*/ */
{ {
CHECK (Offs <= LiteralOffs); CHECK (Offs <= LiteralPoolOffs);
LiteralOffs = Offs; LiteralPoolOffs = Offs;
} }
@ -136,10 +139,19 @@ void ResetLiteralOffs (unsigned Offs)
void AddLiteralChar (char C) void AddLiteralChar (char C)
/* Add one character to the literal pool */ /* Add one character to the literal pool */
{ {
if (LiteralOffs >= LITPOOL_SIZE) { /* Grow the buffer if needed */
Fatal ("Out of literal space"); if (LiteralPoolOffs >= LiteralPoolSize) {
if (LiteralPoolSize == 0) {
/* First call */
LiteralPoolSize = 256;
} else {
LiteralPoolSize *= 2;
}
LiteralPoolBuf = xrealloc (LiteralPoolBuf, LiteralPoolSize);
} }
LiteralPool[LiteralOffs++] = C;
/* Store the character */
LiteralPoolBuf[LiteralPoolOffs++] = C;
} }
@ -150,9 +162,9 @@ unsigned AddLiteral (const char* S)
*/ */
{ {
/* Remember the starting offset */ /* Remember the starting offset */
unsigned Start = LiteralOffs; unsigned Start = LiteralPoolOffs;
/* Copy the string doing a range check */ /* Copy the string including the terminator growing the buffer if needed */
do { do {
AddLiteralChar (*S); AddLiteralChar (*S);
} while (*S++); } while (*S++);
@ -166,16 +178,16 @@ unsigned AddLiteral (const char* S)
const char* GetLiteral (unsigned Offs) const char* GetLiteral (unsigned Offs)
/* Get a pointer to the literal with the given offset in the pool */ /* Get a pointer to the literal with the given offset in the pool */
{ {
CHECK (Offs < LiteralOffs); CHECK (Offs < LiteralPoolOffs);
return (const char*) &LiteralPool[Offs]; return (const char*) &LiteralPoolBuf[Offs];
} }
void PrintLiteralStats (FILE* F) void PrintLiteralPoolStats (FILE* F)
/* Print statistics about the literal space used */ /* Print statistics about the literal space used */
{ {
fprintf (F, "Literal space used: %d bytes\n", LiteralSpace); fprintf (F, "Literal space used: %u bytes\n", LiteralPoolOffs);
} }

View File

@ -48,16 +48,19 @@
extern unsigned LiteralLabel; /* Pool asm label */ extern unsigned LiteralPoolLabel; /* Pool asm label */
/*****************************************************************************/ /*****************************************************************************/
/* Code */ /* Code */
/*****************************************************************************/ /*****************************************************************************/
void InitLiteralPool (void);
/* Initialize the literal pool */
void TranslateLiteralPool (unsigned Offs); void TranslateLiteralPool (unsigned Offs);
/* Translate the literals starting from the given offset into the target /* Translate the literals starting from the given offset into the target
* charset. * charset.
@ -66,10 +69,10 @@ void TranslateLiteralPool (unsigned Offs);
void DumpLiteralPool (void); void DumpLiteralPool (void);
/* Dump the literal pool */ /* Dump the literal pool */
unsigned GetLiteralOffs (void); unsigned GetLiteralPoolOffs (void);
/* Return the current offset into the literal pool */ /* Return the current offset into the literal pool */
void ResetLiteralOffs (unsigned Offs); void ResetLiteralPoolOffs (unsigned Offs);
/* Reset the offset into the literal pool to some earlier value, effectively /* Reset the offset into the literal pool to some earlier value, effectively
* removing values from the pool. * removing values from the pool.
*/ */
@ -85,7 +88,7 @@ unsigned AddLiteral (const char* S);
const char* GetLiteral (unsigned Offs); const char* GetLiteral (unsigned Offs);
/* Get a pointer to the literal with the given offset in the pool */ /* Get a pointer to the literal with the given offset in the pool */
void PrintLiteralStats (FILE* F); void PrintLiteralPoolStats (FILE* F);
/* Print statistics about the literal space used */ /* Print statistics about the literal space used */
@ -95,3 +98,4 @@ void PrintLiteralStats (FILE* F);

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000 Ullrich von Bassewitz */ /* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */

View File

@ -179,7 +179,7 @@ ExprNode* DoAsm (void)
* will fail if the next token is also a string token, but that's a * will fail if the next token is also a string token, but that's a
* syntax error anyway, because we expect a right paren. * syntax error anyway, because we expect a right paren.
*/ */
ResetLiteralOffs (CurTok.IVal); ResetLiteralPoolOffs (CurTok.IVal);
} }
/* Skip the string token */ /* Skip the string token */

View File

@ -129,7 +129,7 @@ static void StringPragma (void (*Func) (const char*))
Func (Name); Func (Name);
/* Reset the string pointer, removing the string from the pool */ /* Reset the string pointer, removing the string from the pool */
ResetLiteralOffs (curval); ResetLiteralPoolOffs (curval);
} }
/* Skip the string (or error) token */ /* Skip the string (or error) token */
@ -161,7 +161,7 @@ static void SegNamePragma (void (*Func) (const char*))
} }
/* Reset the string pointer, removing the string from the pool */ /* Reset the string pointer, removing the string from the pool */
ResetLiteralOffs (curval); ResetLiteralPoolOffs (curval);
} }
/* Skip the string (or error) token */ /* Skip the string (or error) token */

View File

@ -340,7 +340,7 @@ static void CharConst (void)
static void StringConst (void) static void StringConst (void)
/* Parse a quoted string */ /* Parse a quoted string */
{ {
nxtval = GetLiteralOffs (); nxtval = GetLiteralPoolOffs ();
nxttok = TOK_SCONST; nxttok = TOK_SCONST;
/* Be sure to concatenate strings */ /* Be sure to concatenate strings */

View File

@ -153,7 +153,7 @@ struct Token_ {
double FVal; /* The float attribute */ double FVal; /* The float attribute */
ident Ident; /* Identifier if IDENT */ ident Ident; /* Identifier if IDENT */
unsigned Pos; /* Source line where the token comes from */ unsigned Pos; /* Source line where the token comes from */
type* Type; /* Type if integer or float constant */ type* Type; /* Type if integer or float constant */
}; };
extern Token CurTok; /* The current token */ extern Token CurTok; /* The current token */