]> git.sur5r.net Git - cc65/blob - src/ld65/scanner.h
Fixed an error: The amount of fill bytes for a section was declared as an
[cc65] / src / ld65 / scanner.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 scanner.h                                 */
4 /*                                                                           */
5 /*              Configuration file scanner for the ld65 linker               */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2010, 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 SCANNER_H
37 #define SCANNER_H
38
39
40
41 /* common */
42 #include "filepos.h"
43 #include "strbuf.h"
44
45
46
47 /*****************************************************************************/
48 /*                                   Data                                    */
49 /*****************************************************************************/
50
51
52
53 /* Config file tokens */
54 typedef enum {
55     CFGTOK_NONE,
56     CFGTOK_INTCON,              /* Integer constant */
57     CFGTOK_STRCON,              /* String constant */
58     CFGTOK_IDENT,               /* Identifier */
59     CFGTOK_PLUS,
60     CFGTOK_MINUS,
61     CFGTOK_MUL,
62     CFGTOK_DIV,
63     CFGTOK_LPAR,
64     CFGTOK_RPAR,
65     CFGTOK_LCURLY,
66     CFGTOK_RCURLY,
67     CFGTOK_SEMI,
68     CFGTOK_COMMA,
69     CFGTOK_EQ,
70     CFGTOK_COLON,
71     CFGTOK_DOT,
72     CFGTOK_EOF,
73
74     /* Special identifiers */
75     CFGTOK_MEMORY,
76     CFGTOK_FILES,
77     CFGTOK_SEGMENTS,
78     CFGTOK_FORMATS,
79     CFGTOK_FEATURES,
80     CFGTOK_SYMBOLS,
81
82     CFGTOK_START,
83     CFGTOK_SIZE,
84     CFGTOK_TYPE,
85     CFGTOK_FILE,
86     CFGTOK_DEFINE,
87     CFGTOK_FILL,
88     CFGTOK_FILLVAL,
89     CFGTOK_EXPORT,
90     CFGTOK_IMPORT,
91     CFGTOK_OS,
92     CFGTOK_ID,
93     CFGTOK_VERSION,
94     CFGTOK_FORMAT,
95
96     CFGTOK_LOAD,
97     CFGTOK_RUN,
98     CFGTOK_ALIGN,
99     CFGTOK_ALIGN_LOAD,
100     CFGTOK_OFFSET,
101     CFGTOK_OPTIONAL,
102
103     CFGTOK_RO,
104     CFGTOK_RW,
105     CFGTOK_BSS,
106     CFGTOK_ZP,
107
108     CFGTOK_O65,
109     CFGTOK_BIN,
110
111     CFGTOK_SMALL,
112     CFGTOK_LARGE,
113
114     CFGTOK_TRUE,
115     CFGTOK_FALSE,
116
117     CFGTOK_LUNIX,
118     CFGTOK_OSA65,
119     CFGTOK_CC65,
120     CFGTOK_OPENCBM,
121
122     CFGTOK_CONDES,
123     CFGTOK_STARTADDRESS,
124
125     CFGTOK_ADDRSIZE,
126     CFGTOK_VALUE,
127
128     CFGTOK_WEAK,
129
130     CFGTOK_ABS,
131     CFGTOK_FAR,
132     CFGTOK_LONG,
133
134     CFGTOK_SEGMENT,
135     CFGTOK_LABEL,
136     CFGTOK_COUNT,
137     CFGTOK_ORDER,
138
139     CFGTOK_CONSTRUCTOR,
140     CFGTOK_DESTRUCTOR,
141     CFGTOK_INTERRUPTOR,
142
143     CFGTOK_DECREASING,
144     CFGTOK_INCREASING,
145
146     CFGTOK_DEFAULT
147
148 } cfgtok_t;
149
150
151
152 /* Mapping table entry, special identifier --> token */
153 typedef struct IdentTok IdentTok;
154 struct IdentTok {
155     const char* Ident;          /* Identifier */
156     cfgtok_t    Tok;            /* Token for identifier */
157 };
158 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
159
160
161
162 /* Current token and attributes */
163 extern cfgtok_t         CfgTok;
164 extern StrBuf           CfgSVal;
165 extern unsigned long    CfgIVal;
166
167 /* Error location. PLEASE NOTE: I'm abusing the FilePos structure to some
168  * degree. It is used mostly to hold a file position, where the Name member
169  * is an index into the source file table of an object file. As used in config
170  * file processing, the Name member is a string pool index instead. This is
171  * distinguished by the object file pointer being NULL or not in the structs
172  * where this is relevant.
173  */
174 extern FilePos          CfgErrorPos;
175
176
177
178 /*****************************************************************************/
179 /*                                   Code                                    */
180 /*****************************************************************************/
181
182
183
184 void CfgWarning (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
185 /* Print a warning message adding file name and line number of the config file */
186
187 void CfgError (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
188 /* Print an error message adding file name and line number of a given file */
189
190 void CfgNextTok (void);
191 /* Read the next token from the input stream */
192
193 void CfgConsume (cfgtok_t T, const char* Msg);
194 /* Skip a token, print an error message if not found */
195
196 void CfgConsumeSemi (void);
197 /* Consume a semicolon */
198
199 void CfgConsumeColon (void);
200 /* Consume a colon */
201
202 void CfgOptionalComma (void);
203 /* Consume a comma if there is one */
204
205 void CfgOptionalAssign (void);
206 /* Consume an equal sign if there is one */
207
208 void CfgAssureInt (void);
209 /* Make sure the next token is an integer */
210
211 void CfgAssureStr (void);
212 /* Make sure the next token is a string constant */
213
214 void CfgAssureIdent (void);
215 /* Make sure the next token is an identifier */
216
217 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
218 /* Check the range of CfgIVal */
219
220 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
221 /* Map an identifier to one of the special tokens in the table */
222
223 void CfgBoolToken (void);
224 /* Map an identifier or integer to a boolean token */
225
226 void CfgSetName (const char* Name);
227 /* Set a name for a config file */
228
229 void CfgSetBuf (const char* Buf);
230 /* Set a memory buffer for the config */
231
232 int CfgAvail (void);
233 /* Return true if we have a configuration available */
234
235 void CfgOpenInput (void);
236 /* Open the input file if we have one */
237
238 void CfgCloseInput (void);
239 /* Close the input file if we have one */
240
241
242
243 /* End of scanner.h */
244 #endif
245
246
247
248