/* */
/* */
/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 1998-2004 Ullrich von Bassewitz */
+/* Römerstraße 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* common */
#include "check.h"
#include "tgttrans.h"
-#include "xmalloc.h"
/* cc65 */
#include "asmlabel.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-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 */
+static StrBuf LiteralPool = STATIC_STRBUF_INITIALIZER;
/* Initialize the literal pool */
{
/* Get the pool label */
- LiteralPoolLabel = GetLabel ();
+ LiteralPoolLabel = GetLocalLabel ();
}
* charset.
*/
{
- TgtTranslateBuf (LiteralPoolBuf + Offs, LiteralPoolOffs - Offs);
+ TgtTranslateBuf (SB_GetBuf (&LiteralPool) + Offs, SB_GetLen (&LiteralPool) - Offs);
}
/* Dump the literal pool */
{
/* If nothing there, exit... */
- if (LiteralPoolOffs == 0) {
+ if (SB_GetLen (&LiteralPool) == 0) {
return;
}
/* Switch to the data segment */
- if (WriteableStrings) {
+ if (IS_Get (&WritableStrings)) {
g_usedata ();
} else {
g_userodata ();
}
/* Define the label */
- g_defloclabel (LiteralPoolLabel);
+ g_defdatalabel (LiteralPoolLabel);
/* Translate the buffer contents into the target charset */
TranslateLiteralPool (0);
/* Output the buffer data */
- g_defbytes (LiteralPoolBuf, LiteralPoolOffs);
-
- /* Switch back to the code segment */
- g_usecode ();
+ g_defbytes (SB_GetConstBuf (&LiteralPool), SB_GetLen (&LiteralPool));
}
unsigned GetLiteralPoolOffs (void)
/* Return the current offset into the literal pool */
{
- return LiteralPoolOffs;
+ return SB_GetLen (&LiteralPool);
}
* removing values from the pool.
*/
{
- CHECK (Offs <= LiteralPoolOffs);
- LiteralPoolOffs = Offs;
+ CHECK (Offs <= SB_GetLen (&LiteralPool));
+ SB_Cut (&LiteralPool, Offs);
}
void AddLiteralChar (char C)
/* Add one character to the literal pool */
{
- /* Grow the buffer if needed */
- if (LiteralPoolOffs >= LiteralPoolSize) {
- if (LiteralPoolSize == 0) {
- /* First call */
- LiteralPoolSize = 256;
- } else {
- LiteralPoolSize *= 2;
- }
- LiteralPoolBuf = xrealloc (LiteralPoolBuf, LiteralPoolSize);
- }
-
- /* Store the character */
- LiteralPoolBuf[LiteralPoolOffs++] = C;
+ SB_AppendChar (&LiteralPool, C);
}
*/
{
/* Remember the starting offset */
- unsigned Start = LiteralPoolOffs;
+ unsigned Start = SB_GetLen (&LiteralPool);
/* Copy the string including the terminator growing the buffer if needed */
- do {
- AddLiteralChar (*S);
- } while (*S++);
+ SB_AppendBuf (&LiteralPool, S, strlen (S) + 1);
/* Return the starting offset */
return Start;
const char* GetLiteral (unsigned Offs)
/* Get a pointer to the literal with the given offset in the pool */
{
- CHECK (Offs < LiteralPoolOffs);
- return (const char*) &LiteralPoolBuf[Offs];
+ CHECK (Offs < SB_GetLen (&LiteralPool));
+ return SB_GetConstBuf (&LiteralPool) + Offs;
+}
+
+
+
+void GetLiteralStrBuf (StrBuf* Target, unsigned Offs)
+/* Copy the string starting at Offs and lasting to the end of the buffer
+ * into Target.
+ */
+{
+ CHECK (Offs <= SB_GetLen (&LiteralPool));
+ SB_Slice (Target, &LiteralPool, Offs, SB_GetLen (&LiteralPool) - Offs);
}
void PrintLiteralPoolStats (FILE* F)
/* Print statistics about the literal space used */
{
- fprintf (F, "Literal space used: %u bytes\n", LiteralPoolOffs);
+ fprintf (F, "Literal space used: %u bytes\n", SB_GetLen (&LiteralPool));
}