/* common */
#include "check.h"
+#include "strbuf.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;
* 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;
}
TranslateLiteralPool (0);
/* Output the buffer data */
- g_defbytes (LiteralPoolBuf, LiteralPoolOffs);
+ 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 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));
}