char* Path;
- /* Setup variables */
- LiteralLabel = GetLabel ();
-
/* Add some standard paths to the include search path */
AddIncludePath ("", INC_USER); /* Current directory */
AddIncludePath ("include", INC_SYS);
}
}
+ /* Initialize the literal pool */
+ InitLiteralPool ();
+
/* Create the base lexical level */
EnterGlobalLevel ();
/* Ok, start the ball rolling... */
Parse ();
- /* Dump literal pool. */
+ /* Dump the literal pool. */
DumpLiteralPool ();
/* Write imported/exported symbols */
EmitExternals ();
if (Debug) {
- PrintLiteralStats (stdout);
+ PrintLiteralPoolStats (stdout);
PrintMacroStats (stdout);
}
-/*
- * declare.c
- *
- * Ullrich von Bassewitz, 20.06.1998
- */
+/*****************************************************************************/
+/* */
+/* declare.c */
+/* */
+/* 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. */
+/* */
+/*****************************************************************************/
void ParseInit (type* T)
/* Parse initialization of variables. */
{
- int count;
struct expent lval;
type* t;
const char* str;
- int sz;
+ int Count;
+ int Size;
switch (UnqualifiedType (*T)) {
break;
case T_ARRAY:
- sz = Decode (T + 1);
+ Size = Decode (T + 1);
t = T + DECODE_SIZE + 1;
if (IsTypeChar(t) && curtok == TOK_SCONST) {
str = GetLiteral (curval);
- count = strlen (str) + 1;
+ Count = strlen (str) + 1;
TranslateLiteralPool (curval); /* Translate into target charset */
- g_defbytes (str, count);
- ResetLiteralOffs (curval); /* Remove string from pool */
+ g_defbytes (str, Count);
+ ResetLiteralPoolOffs (curval); /* Remove string from pool */
NextToken ();
} else {
ConsumeLCurly ();
- count = 0;
+ Count = 0;
while (curtok != TOK_RCURLY) {
ParseInit (T + DECODE_SIZE + 1);
- ++count;
+ ++Count;
if (curtok != TOK_COMMA)
break;
NextToken ();
}
ConsumeRCurly ();
}
- if (sz == 0) {
- Encode (T + 1, count);
- } else if (count < sz) {
- g_zerobytes ((sz - count) * SizeOf (T + DECODE_SIZE + 1));
- } else if (count > sz) {
+ if (Size == 0) {
+ Encode (T + 1, Count);
+ } else if (Count < Size) {
+ g_zerobytes ((Size - Count) * SizeOf (T + DECODE_SIZE + 1));
+ } else if (Count > Size) {
Error ("Too many initializers");
}
break;
-/*
- * declare.h
- *
- * Ullrich von Bassewitz, 20.06.1998
- */
+/*****************************************************************************/
+/* */
+/* declare.h */
+/* */
+/* 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. */
+/* */
+/*****************************************************************************/
+/* cc65 */
#include "scanner.h"
#include "symtab.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
typedef struct DeclSpec DeclSpec;
struct DeclSpec {
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 */
};
type Type [MAXTYPELEN]; /* The type */
/* Working variables */
- type* T; /* Used to build Type */
+ type* T; /* Used to build Type */
};
/* Modes for ParseDecl */
* warning if not.
*/
-void ParseInit (type* tptr);
+void ParseInit (type* T);
/* Parse initialization of variables. */
case E_TLIT:
/* a literal of some kind */
- g_defdata (CF_STATIC, LiteralLabel, lval->e_const);
+ g_defdata (CF_STATIC, LiteralPoolLabel, lval->e_const);
break;
default:
case E_TLIT:
/* Literal string */
- g_getimmed (CF_STATIC, LiteralLabel, lval->e_const);
+ g_getimmed (CF_STATIC, LiteralPoolLabel, lval->e_const);
break;
default:
* will fail if the next token is also a string token, but that's a
* syntax error anyway, because we expect a right paren.
*/
- ResetLiteralOffs (curval);
+ ResetLiteralPoolOffs (curval);
}
/* Skip the string token */
/* Emit references to imports/exports */
EmitExternals ();
- /* Dump literal data created by the function */
- DumpLiteralPool ();
-
/* Cleanup register variables */
DoneRegVars ();
/* common */
#include "check.h"
#include "tgttrans.h"
+#include "xmalloc.h"
/* cc65 */
#include "asmlabel.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-#define LITPOOL_SIZE 4096 /* Max strings per function */
-static unsigned char LiteralPool[LITPOOL_SIZE]; /* The literal pool */
-static unsigned LiteralOffs = 0; /* Current pool offset */
-static unsigned LiteralSpace = 0; /* Space used (stats only) */
-
-unsigned LiteralLabel = 1; /* Pool asm label */
+static unsigned char* LiteralPoolBuf = 0; /* Pointer to buffer */
+static unsigned LiteralPoolSize = 0; /* Size of pool */
+static unsigned LiteralPoolOffs = 0; /* Current offset into pool */
+unsigned LiteralPoolLabel = 0; /* Pool asm label */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
+void InitLiteralPool (void)
+/* Initialize the literal pool */
+{
+ /* Get the pool label */
+ LiteralPoolLabel = GetLabel ();
+}
+
+
+
void TranslateLiteralPool (unsigned Offs)
/* Translate the literals starting from the given offset into the target
* charset.
*/
{
- TgtTranslateBuf (LiteralPool + Offs, LiteralOffs - Offs);
+ TgtTranslateBuf (LiteralPoolBuf + Offs, LiteralPoolOffs - Offs);
}
void DumpLiteralPool (void)
/* Dump the literal pool */
{
- /* if nothing there, exit... */
- if (LiteralOffs == 0) {
+ /* If nothing there, exit... */
+ if (LiteralPoolOffs == 0) {
return;
}
}
/* Define the label */
- g_defloclabel (LiteralLabel);
+ g_defloclabel (LiteralPoolLabel);
/* Translate the buffer contents into the target charset */
TranslateLiteralPool (0);
/* Output the buffer data */
- g_defbytes (LiteralPool, LiteralOffs);
+ g_defbytes (LiteralPoolBuf, LiteralPoolOffs);
/* Switch back to the code segment */
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 LiteralOffs;
+ return LiteralPoolOffs;
}
-void ResetLiteralOffs (unsigned Offs)
+void ResetLiteralPoolOffs (unsigned Offs)
/* Reset the offset into the literal pool to some earlier value, effectively
* removing values from the pool.
*/
{
- CHECK (Offs <= LiteralOffs);
- LiteralOffs = Offs;
+ CHECK (Offs <= LiteralPoolOffs);
+ LiteralPoolOffs = Offs;
}
void AddLiteralChar (char C)
/* Add one character to the literal pool */
{
- if (LiteralOffs >= LITPOOL_SIZE) {
- Fatal ("Out of literal space");
+ /* Grow the buffer if needed */
+ 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;
}
*/
{
/* 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 {
AddLiteralChar (*S);
} while (*S++);
const char* GetLiteral (unsigned Offs)
/* Get a pointer to the literal with the given offset in the pool */
{
- CHECK (Offs < LiteralOffs);
- return (const char*) &LiteralPool[Offs];
+ CHECK (Offs < LiteralPoolOffs);
+ return (const char*) &LiteralPoolBuf[Offs];
}
-void PrintLiteralStats (FILE* F)
+void PrintLiteralPoolStats (FILE* F)
/* 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);
}
-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);
/* Translate the literals starting from the given offset into the target
* charset.
void DumpLiteralPool (void);
/* Dump the literal pool */
-unsigned GetLiteralOffs (void);
+unsigned GetLiteralPoolOffs (void);
/* 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
* removing values from the pool.
*/
const char* GetLiteral (unsigned Offs);
/* 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 */
+
/* */
/* */
/* */
-/* (C) 2000 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2001 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
* will fail if the next token is also a string token, but that's a
* syntax error anyway, because we expect a right paren.
*/
- ResetLiteralOffs (CurTok.IVal);
+ ResetLiteralPoolOffs (CurTok.IVal);
}
/* Skip the string token */
Func (Name);
/* Reset the string pointer, removing the string from the pool */
- ResetLiteralOffs (curval);
+ ResetLiteralPoolOffs (curval);
}
/* Skip the string (or error) token */
}
/* Reset the string pointer, removing the string from the pool */
- ResetLiteralOffs (curval);
+ ResetLiteralPoolOffs (curval);
}
/* Skip the string (or error) token */
static void StringConst (void)
/* Parse a quoted string */
{
- nxtval = GetLiteralOffs ();
+ nxtval = GetLiteralPoolOffs ();
nxttok = TOK_SCONST;
/* Be sure to concatenate strings */
double FVal; /* The float attribute */
ident Ident; /* Identifier if IDENT */
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 */