1/*****************************************************************************/
2/* */
3/* litpool.h */
4/* */
5/* Literal string handling for the cc65 C compiler */
6/* */
7/* */
8/* */
9/* (C) 1998-2009, Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
13/* */
14/* */
15/* This software is provided 'as-is', without any expressed or implied */
16/* warranty. In no event will the authors be held liable for any damages */
17/* arising from the use of this software. */
18/* */
19/* Permission is granted to anyone to use this software for any purpose, */
20/* including commercial applications, and to alter it and redistribute it */
21/* freely, subject to the following restrictions: */
22/* */
23/* 1. The origin of this software must not be misrepresented; you must not */
24/* claim that you wrote the original software. If you use this software */
25/* in a product, an acknowledgment in the product documentation would be */
26/* appreciated but is not required. */
27/* 2. Altered source versions must be plainly marked as such, and must not */
28/* be misrepresented as being the original software. */
29/* 3. This notice may not be removed or altered from any source */
30/* distribution. */
31/* */
32/*****************************************************************************/
33
34
35
36#ifndef LITPOOL_H
37#define LITPOOL_H
38
39
40
41#include <stdio.h>
42
43/* common */
44#include "strbuf.h"
45
46
47
48/*****************************************************************************/
49/* Data */
50/*****************************************************************************/
51
52
53
54/* Forward for struct SymEntry */
55struct SymEntry;
56
57/* Forward for a literal */
58typedef struct Literal Literal;
59
60/* Forward for a literal pool */
61typedef struct LiteralPool LiteralPool;
62
63
64
65/*****************************************************************************/
66/* struct Literal */
67/*****************************************************************************/
68
69
70
71Literal* UseLiteral (Literal* L);
72/* Increase the reference counter for the literal and return it */
73
74void ReleaseLiteral (Literal* L);
75/* Decrement the reference counter for the literal */
76
77void TranslateLiteral (Literal* L);
78/* Translate a literal into the target charset. */
79
80unsigned GetLiteralLabel (const Literal* L);
81/* Return the asm label for a literal */
82
83const char* GetLiteralStr (const Literal* L);
84/* Return the data for a literal as pointer to char */
85
86const StrBuf* GetLiteralStrBuf (const Literal* L);
87/* Return the data for a literal as pointer to the string buffer */
88
89unsigned GetLiteralSize (const Literal* L);
90/* Get the size of a literal string */
91
92
93
94/*****************************************************************************/
95/* Code */
96/*****************************************************************************/
97
98
99
100void InitLiteralPool (void);
101/* Initialize the literal pool */
102
103void PushLiteralPool (struct SymEntry* Func);
104/* Push the current literal pool onto the stack and create a new one */
105
106LiteralPool* PopLiteralPool (void);
107/* Pop the last literal pool from TOS and activate it. Return the old
108** literal pool.
109*/
110
111void MoveLiteralPool (LiteralPool* LocalPool);
112/* Move all referenced literals in LocalPool to the global literal pool. This
113** function will free LocalPool after moving the used string literals.
114*/
115
116void OutputLiteralPool (void);
117/* Output the literal pool */
118
119Literal* AddLiteral (const char* S);
120/* Add a literal string to the literal pool. Return the literal. */
121
122Literal* AddLiteralBuf (const void* Buf, unsigned Len);
123/* Add a buffer containing a literal string to the literal pool. Return the
124** literal.
125*/
126
127Literal* AddLiteralStr (const StrBuf* S);
128/* Add a literal string to the literal pool. Return the literal. */
129
130
131
132/* End of litpool.h */
133
134#endif
135