]> git.sur5r.net Git - cc65/blob - src/ld65/scanner.h
Changed most "backticks" (grave accents) into apostrophes.
[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-2013, 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_BANK,
88     CFGTOK_FILL,
89     CFGTOK_FILLVAL,
90     CFGTOK_EXPORT,
91     CFGTOK_IMPORT,
92     CFGTOK_OS,
93     CFGTOK_ID,
94     CFGTOK_VERSION,
95     CFGTOK_FORMAT,
96
97     CFGTOK_LOAD,
98     CFGTOK_RUN,
99     CFGTOK_ALIGN,
100     CFGTOK_ALIGN_LOAD,
101     CFGTOK_OFFSET,
102     CFGTOK_OPTIONAL,
103
104     CFGTOK_RO,
105     CFGTOK_RW,
106     CFGTOK_BSS,
107     CFGTOK_ZP,
108     CFGTOK_OVERWRITE,
109
110     CFGTOK_O65,
111     CFGTOK_BIN,
112
113     CFGTOK_SMALL,
114     CFGTOK_LARGE,
115
116     CFGTOK_TRUE,
117     CFGTOK_FALSE,
118
119     CFGTOK_LUNIX,
120     CFGTOK_OSA65,
121     CFGTOK_CC65,
122     CFGTOK_OPENCBM,
123
124     CFGTOK_CONDES,
125     CFGTOK_STARTADDRESS,
126
127     CFGTOK_ADDRSIZE,
128     CFGTOK_VALUE,
129
130     CFGTOK_WEAK,
131
132     CFGTOK_ABS,
133     CFGTOK_FAR,
134     CFGTOK_LONG,
135
136     CFGTOK_SEGMENT,
137     CFGTOK_LABEL,
138     CFGTOK_COUNT,
139     CFGTOK_ORDER,
140
141     CFGTOK_CONSTRUCTOR,
142     CFGTOK_DESTRUCTOR,
143     CFGTOK_INTERRUPTOR,
144
145     CFGTOK_DECREASING,
146     CFGTOK_INCREASING,
147
148     CFGTOK_DEFAULT
149
150 } cfgtok_t;
151
152
153
154 /* Mapping table entry, special identifier --> token */
155 typedef struct IdentTok IdentTok;
156 struct IdentTok {
157     const char* Ident;          /* Identifier */
158     cfgtok_t    Tok;            /* Token for identifier */
159 };
160 #define ENTRY_COUNT(s)  (sizeof (s) / sizeof (s [0]))
161
162
163
164 /* Current token and attributes */
165 extern cfgtok_t         CfgTok;
166 extern StrBuf           CfgSVal;
167 extern unsigned long    CfgIVal;
168
169 /* Error location. PLEASE NOTE: I'm abusing the FilePos structure to some
170 ** degree. It is used mostly to hold a file position, where the Name member
171 ** is an index into the source file table of an object file. As used in config
172 ** file processing, the Name member is a string pool index instead. This is
173 ** distinguished by the object file pointer being NULL or not in the structs
174 ** where this is relevant.
175 */
176 extern FilePos          CfgErrorPos;
177
178
179
180 /*****************************************************************************/
181 /*                                   Code                                    */
182 /*****************************************************************************/
183
184
185
186 void CfgWarning (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
187 /* Print a warning message adding file name and line number of the config file */
188
189 void CfgError (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
190 /* Print an error message adding file name and line number of a given file */
191
192 void CfgNextTok (void);
193 /* Read the next token from the input stream */
194
195 void CfgConsume (cfgtok_t T, const char* Msg);
196 /* Skip a token, print an error message if not found */
197
198 void CfgConsumeSemi (void);
199 /* Consume a semicolon */
200
201 void CfgConsumeColon (void);
202 /* Consume a colon */
203
204 void CfgOptionalComma (void);
205 /* Consume a comma if there is one */
206
207 void CfgOptionalAssign (void);
208 /* Consume an equal sign if there is one */
209
210 void CfgAssureInt (void);
211 /* Make sure the next token is an integer */
212
213 void CfgAssureStr (void);
214 /* Make sure the next token is a string constant */
215
216 void CfgAssureIdent (void);
217 /* Make sure the next token is an identifier */
218
219 void CfgRangeCheck (unsigned long Lo, unsigned long Hi);
220 /* Check the range of CfgIVal */
221
222 void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name);
223 /* Map an identifier to one of the special tokens in the table */
224
225 void CfgBoolToken (void);
226 /* Map an identifier or integer to a boolean token */
227
228 void CfgSetName (const char* Name);
229 /* Set a name for a config file */
230
231 int CfgAvail (void);
232 /* Return true if we have a configuration available */
233
234 void CfgOpenInput (void);
235 /* Open the input file if we have one */
236
237 void CfgCloseInput (void);
238 /* Close the input file if we have one */
239
240
241
242 /* End of scanner.h */
243
244 #endif