1 /*****************************************************************************/
5 /* Pragma handling for the cc65 C compiler */
9 /* (C) 1998 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 /* Tokens for the #pragmas */
73 /*****************************************************************************/
75 /*****************************************************************************/
79 static void StringPragma (void (*Func) (const char*))
80 /* Handle a pragma that expects a string parameter */
82 if (curtok != SCONST) {
83 Error (ERR_STRLIT_EXPECTED);
86 const char* Name = GetLiteral (curval);
88 /* Call the given function with the string argument */
91 /* Reset the string pointer, removing the string from the pool */
92 ResetLiteralOffs (curval);
95 /* Skip the string (or error) token */
101 static void FlagPragma (unsigned char* Flag)
102 /* Handle a pragma that expects a boolean paramater */
104 /* Read a constant expression */
108 /* Store the value into the flag parameter */
109 *Flag = (val.e_const != 0);
117 static const struct tok_elt Pragmas [] = {
118 { "bssseg", PR_BSSSEG },
119 { "codeseg", PR_CODESEG },
120 { "dataseg", PR_DATASEG },
121 { "regvaraddr", PR_REGVARADDR },
122 { "rodataseg", PR_RODATASEG },
123 { "signedchars", PR_SIGNEDCHARS },
124 { "staticlocals", PR_STATICLOCALS },
125 { "zpsym", PR_ZPSYM },
131 /* Skip the token itself */
134 /* Identifier must follow */
135 if (curtok != IDENT) {
136 Error (ERR_IDENT_EXPECTED);
140 /* Do we know this pragma? */
141 Pragma = searchtok (CurTok.Ident, Pragmas);
142 if (Pragma == PR_ILLEGAL) {
143 /* According to the ANSI standard, we're not allowed to generate errors
144 * for unknown pragmas, however, we're allowed to warn - and we will
145 * do so. Otherwise one typo may give you hours of bug hunting...
147 Warning (WARN_UNKNOWN_PRAGMA);
151 /* Skip the identifier and check for an open paren */
155 /* Switch for the different pragmas */
159 StringPragma (g_bssname);
163 StringPragma (g_codename);
167 StringPragma (g_dataname);
171 FlagPragma (&AllowRegVarAddr);
175 StringPragma (g_rodataname);
179 FlagPragma (&SignedChars);
182 case PR_STATICLOCALS:
183 FlagPragma (&LocalsAreStatic);
187 StringPragma (MakeZPSym);
191 Internal ("Invalid pragma");
194 /* Closing paren needed */