prscan.c revision 1.1.1.1.10.2 1 1.1.1.1.10.2 tls /******************************************************************************
2 1.1.1.1.10.2 tls *
3 1.1.1.1.10.2 tls * Module Name: prscan - Preprocessor start-up and file scan module
4 1.1.1.1.10.2 tls *
5 1.1.1.1.10.2 tls *****************************************************************************/
6 1.1.1.1.10.2 tls
7 1.1.1.1.10.2 tls /*
8 1.1.1.1.10.2 tls * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1.1.1.10.2 tls * All rights reserved.
10 1.1.1.1.10.2 tls *
11 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
13 1.1.1.1.10.2 tls * are met:
14 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.10.2 tls * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.10.2 tls * without modification.
17 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.10.2 tls * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.10.2 tls * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.10.2 tls * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.10.2 tls * binary redistribution.
22 1.1.1.1.10.2 tls * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.10.2 tls * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.10.2 tls * from this software without specific prior written permission.
25 1.1.1.1.10.2 tls *
26 1.1.1.1.10.2 tls * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.10.2 tls * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.10.2 tls * Software Foundation.
29 1.1.1.1.10.2 tls *
30 1.1.1.1.10.2 tls * NO WARRANTY
31 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.10.2 tls * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.10.2 tls * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.10.2 tls * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.10.2 tls * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.10.2 tls * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.10.2 tls * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.10.2 tls * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.10.2 tls */
43 1.1.1.1.10.2 tls
44 1.1.1.1.10.2 tls #define _DECLARE_PR_GLOBALS
45 1.1.1.1.10.2 tls
46 1.1.1.1.10.2 tls #include "aslcompiler.h"
47 1.1.1.1.10.2 tls #include "dtcompiler.h"
48 1.1.1.1.10.2 tls
49 1.1.1.1.10.2 tls /*
50 1.1.1.1.10.2 tls * TBDs:
51 1.1.1.1.10.2 tls *
52 1.1.1.1.10.2 tls * No nested macros, maybe never
53 1.1.1.1.10.2 tls * Implement ASL "Include" as well as "#include" here?
54 1.1.1.1.10.2 tls */
55 1.1.1.1.10.2 tls #define _COMPONENT ASL_PREPROCESSOR
56 1.1.1.1.10.2 tls ACPI_MODULE_NAME ("prscan")
57 1.1.1.1.10.2 tls
58 1.1.1.1.10.2 tls
59 1.1.1.1.10.2 tls /* Local prototypes */
60 1.1.1.1.10.2 tls
61 1.1.1.1.10.2 tls static void
62 1.1.1.1.10.2 tls PrPreprocessInputFile (
63 1.1.1.1.10.2 tls void);
64 1.1.1.1.10.2 tls
65 1.1.1.1.10.2 tls static void
66 1.1.1.1.10.2 tls PrDoDirective (
67 1.1.1.1.10.2 tls char *DirectiveToken,
68 1.1.1.1.10.2 tls char **Next);
69 1.1.1.1.10.2 tls
70 1.1.1.1.10.2 tls static int
71 1.1.1.1.10.2 tls PrMatchDirective (
72 1.1.1.1.10.2 tls char *Directive);
73 1.1.1.1.10.2 tls
74 1.1.1.1.10.2 tls static void
75 1.1.1.1.10.2 tls PrPushDirective (
76 1.1.1.1.10.2 tls int Directive,
77 1.1.1.1.10.2 tls char *Argument);
78 1.1.1.1.10.2 tls
79 1.1.1.1.10.2 tls static ACPI_STATUS
80 1.1.1.1.10.2 tls PrPopDirective (
81 1.1.1.1.10.2 tls void);
82 1.1.1.1.10.2 tls
83 1.1.1.1.10.2 tls static void
84 1.1.1.1.10.2 tls PrDbgPrint (
85 1.1.1.1.10.2 tls char *Action,
86 1.1.1.1.10.2 tls char *DirectiveName);
87 1.1.1.1.10.2 tls
88 1.1.1.1.10.2 tls
89 1.1.1.1.10.2 tls /*
90 1.1.1.1.10.2 tls * Supported preprocessor directives
91 1.1.1.1.10.2 tls */
92 1.1.1.1.10.2 tls static const PR_DIRECTIVE_INFO Gbl_DirectiveInfo[] =
93 1.1.1.1.10.2 tls {
94 1.1.1.1.10.2 tls {"define", 1},
95 1.1.1.1.10.2 tls {"elif", 0}, /* Converted to #else..#if internally */
96 1.1.1.1.10.2 tls {"else", 0},
97 1.1.1.1.10.2 tls {"endif", 0},
98 1.1.1.1.10.2 tls {"error", 1},
99 1.1.1.1.10.2 tls {"if", 1},
100 1.1.1.1.10.2 tls {"ifdef", 1},
101 1.1.1.1.10.2 tls {"ifndef", 1},
102 1.1.1.1.10.2 tls {"include", 0}, /* Argument is not standard format, so 0 */
103 1.1.1.1.10.2 tls {"line", 1},
104 1.1.1.1.10.2 tls {"pragma", 1},
105 1.1.1.1.10.2 tls {"undef", 1},
106 1.1.1.1.10.2 tls {"warning", 1},
107 1.1.1.1.10.2 tls {NULL, 0}
108 1.1.1.1.10.2 tls };
109 1.1.1.1.10.2 tls
110 1.1.1.1.10.2 tls enum Gbl_DirectiveIndexes
111 1.1.1.1.10.2 tls {
112 1.1.1.1.10.2 tls PR_DIRECTIVE_DEFINE = 0,
113 1.1.1.1.10.2 tls PR_DIRECTIVE_ELIF,
114 1.1.1.1.10.2 tls PR_DIRECTIVE_ELSE,
115 1.1.1.1.10.2 tls PR_DIRECTIVE_ENDIF,
116 1.1.1.1.10.2 tls PR_DIRECTIVE_ERROR,
117 1.1.1.1.10.2 tls PR_DIRECTIVE_IF,
118 1.1.1.1.10.2 tls PR_DIRECTIVE_IFDEF,
119 1.1.1.1.10.2 tls PR_DIRECTIVE_IFNDEF,
120 1.1.1.1.10.2 tls PR_DIRECTIVE_INCLUDE,
121 1.1.1.1.10.2 tls PR_DIRECTIVE_LINE,
122 1.1.1.1.10.2 tls PR_DIRECTIVE_PRAGMA,
123 1.1.1.1.10.2 tls PR_DIRECTIVE_UNDEF,
124 1.1.1.1.10.2 tls PR_DIRECTIVE_WARNING,
125 1.1.1.1.10.2 tls };
126 1.1.1.1.10.2 tls
127 1.1.1.1.10.2 tls #define ASL_DIRECTIVE_NOT_FOUND -1
128 1.1.1.1.10.2 tls
129 1.1.1.1.10.2 tls
130 1.1.1.1.10.2 tls /*******************************************************************************
131 1.1.1.1.10.2 tls *
132 1.1.1.1.10.2 tls * FUNCTION: PrInitializePreprocessor
133 1.1.1.1.10.2 tls *
134 1.1.1.1.10.2 tls * PARAMETERS: None
135 1.1.1.1.10.2 tls *
136 1.1.1.1.10.2 tls * RETURN: None
137 1.1.1.1.10.2 tls *
138 1.1.1.1.10.2 tls * DESCRIPTION: Startup initialization for the Preprocessor.
139 1.1.1.1.10.2 tls *
140 1.1.1.1.10.2 tls ******************************************************************************/
141 1.1.1.1.10.2 tls
142 1.1.1.1.10.2 tls void
143 1.1.1.1.10.2 tls PrInitializePreprocessor (
144 1.1.1.1.10.2 tls void)
145 1.1.1.1.10.2 tls {
146 1.1.1.1.10.2 tls /* Init globals and the list of #defines */
147 1.1.1.1.10.2 tls
148 1.1.1.1.10.2 tls PrInitializeGlobals ();
149 1.1.1.1.10.2 tls Gbl_DefineList = NULL;
150 1.1.1.1.10.2 tls }
151 1.1.1.1.10.2 tls
152 1.1.1.1.10.2 tls
153 1.1.1.1.10.2 tls /*******************************************************************************
154 1.1.1.1.10.2 tls *
155 1.1.1.1.10.2 tls * FUNCTION: PrInitializeGlobals
156 1.1.1.1.10.2 tls *
157 1.1.1.1.10.2 tls * PARAMETERS: None
158 1.1.1.1.10.2 tls *
159 1.1.1.1.10.2 tls * RETURN: None
160 1.1.1.1.10.2 tls *
161 1.1.1.1.10.2 tls * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup
162 1.1.1.1.10.2 tls * initialization and re-initialization between compiles during
163 1.1.1.1.10.2 tls * a multiple source file compile.
164 1.1.1.1.10.2 tls *
165 1.1.1.1.10.2 tls ******************************************************************************/
166 1.1.1.1.10.2 tls
167 1.1.1.1.10.2 tls void
168 1.1.1.1.10.2 tls PrInitializeGlobals (
169 1.1.1.1.10.2 tls void)
170 1.1.1.1.10.2 tls {
171 1.1.1.1.10.2 tls /* Init globals */
172 1.1.1.1.10.2 tls
173 1.1.1.1.10.2 tls Gbl_InputFileList = NULL;
174 1.1.1.1.10.2 tls Gbl_CurrentLineNumber = 0;
175 1.1.1.1.10.2 tls Gbl_PreprocessorLineNumber = 1;
176 1.1.1.1.10.2 tls Gbl_PreprocessorError = FALSE;
177 1.1.1.1.10.2 tls
178 1.1.1.1.10.2 tls /* These are used to track #if/#else blocks (possibly nested) */
179 1.1.1.1.10.2 tls
180 1.1.1.1.10.2 tls Gbl_IfDepth = 0;
181 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = FALSE;
182 1.1.1.1.10.2 tls Gbl_DirectiveStack = NULL;
183 1.1.1.1.10.2 tls }
184 1.1.1.1.10.2 tls
185 1.1.1.1.10.2 tls
186 1.1.1.1.10.2 tls /*******************************************************************************
187 1.1.1.1.10.2 tls *
188 1.1.1.1.10.2 tls * FUNCTION: PrTerminatePreprocessor
189 1.1.1.1.10.2 tls *
190 1.1.1.1.10.2 tls * PARAMETERS: None
191 1.1.1.1.10.2 tls *
192 1.1.1.1.10.2 tls * RETURN: None
193 1.1.1.1.10.2 tls *
194 1.1.1.1.10.2 tls * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any
195 1.1.1.1.10.2 tls * defines that were specified on the command line, in order to
196 1.1.1.1.10.2 tls * support multiple compiles with a single compiler invocation.
197 1.1.1.1.10.2 tls *
198 1.1.1.1.10.2 tls ******************************************************************************/
199 1.1.1.1.10.2 tls
200 1.1.1.1.10.2 tls void
201 1.1.1.1.10.2 tls PrTerminatePreprocessor (
202 1.1.1.1.10.2 tls void)
203 1.1.1.1.10.2 tls {
204 1.1.1.1.10.2 tls PR_DEFINE_INFO *DefineInfo;
205 1.1.1.1.10.2 tls
206 1.1.1.1.10.2 tls
207 1.1.1.1.10.2 tls /*
208 1.1.1.1.10.2 tls * The persistent defines (created on the command line) are always at the
209 1.1.1.1.10.2 tls * end of the list. We save them.
210 1.1.1.1.10.2 tls */
211 1.1.1.1.10.2 tls while ((Gbl_DefineList) && (!Gbl_DefineList->Persist))
212 1.1.1.1.10.2 tls {
213 1.1.1.1.10.2 tls DefineInfo = Gbl_DefineList;
214 1.1.1.1.10.2 tls Gbl_DefineList = DefineInfo->Next;
215 1.1.1.1.10.2 tls
216 1.1.1.1.10.2 tls ACPI_FREE (DefineInfo->Replacement);
217 1.1.1.1.10.2 tls ACPI_FREE (DefineInfo->Identifier);
218 1.1.1.1.10.2 tls ACPI_FREE (DefineInfo);
219 1.1.1.1.10.2 tls }
220 1.1.1.1.10.2 tls }
221 1.1.1.1.10.2 tls
222 1.1.1.1.10.2 tls
223 1.1.1.1.10.2 tls /*******************************************************************************
224 1.1.1.1.10.2 tls *
225 1.1.1.1.10.2 tls * FUNCTION: PrDoPreprocess
226 1.1.1.1.10.2 tls *
227 1.1.1.1.10.2 tls * PARAMETERS: None
228 1.1.1.1.10.2 tls *
229 1.1.1.1.10.2 tls * RETURN: None
230 1.1.1.1.10.2 tls *
231 1.1.1.1.10.2 tls * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must
232 1.1.1.1.10.2 tls * be already open. Handles multiple input files via the
233 1.1.1.1.10.2 tls * #include directive.
234 1.1.1.1.10.2 tls *
235 1.1.1.1.10.2 tls ******************************************************************************/
236 1.1.1.1.10.2 tls
237 1.1.1.1.10.2 tls void
238 1.1.1.1.10.2 tls PrDoPreprocess (
239 1.1.1.1.10.2 tls void)
240 1.1.1.1.10.2 tls {
241 1.1.1.1.10.2 tls BOOLEAN MoreInputFiles;
242 1.1.1.1.10.2 tls
243 1.1.1.1.10.2 tls
244 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n");
245 1.1.1.1.10.2 tls
246 1.1.1.1.10.2 tls
247 1.1.1.1.10.2 tls FlSeekFile (ASL_FILE_INPUT, 0);
248 1.1.1.1.10.2 tls PrDumpPredefinedNames ();
249 1.1.1.1.10.2 tls
250 1.1.1.1.10.2 tls /* Main preprocessor loop, handles include files */
251 1.1.1.1.10.2 tls
252 1.1.1.1.10.2 tls do
253 1.1.1.1.10.2 tls {
254 1.1.1.1.10.2 tls PrPreprocessInputFile ();
255 1.1.1.1.10.2 tls MoreInputFiles = PrPopInputFileStack ();
256 1.1.1.1.10.2 tls
257 1.1.1.1.10.2 tls } while (MoreInputFiles);
258 1.1.1.1.10.2 tls
259 1.1.1.1.10.2 tls /* Point compiler input to the new preprocessor output file (.i) */
260 1.1.1.1.10.2 tls
261 1.1.1.1.10.2 tls FlCloseFile (ASL_FILE_INPUT);
262 1.1.1.1.10.2 tls Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle;
263 1.1.1.1.10.2 tls AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle;
264 1.1.1.1.10.2 tls
265 1.1.1.1.10.2 tls /* Reset globals to allow compiler to run */
266 1.1.1.1.10.2 tls
267 1.1.1.1.10.2 tls FlSeekFile (ASL_FILE_INPUT, 0);
268 1.1.1.1.10.2 tls Gbl_CurrentLineNumber = 1;
269 1.1.1.1.10.2 tls
270 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n");
271 1.1.1.1.10.2 tls }
272 1.1.1.1.10.2 tls
273 1.1.1.1.10.2 tls
274 1.1.1.1.10.2 tls /*******************************************************************************
275 1.1.1.1.10.2 tls *
276 1.1.1.1.10.2 tls * FUNCTION: PrPreprocessInputFile
277 1.1.1.1.10.2 tls *
278 1.1.1.1.10.2 tls * PARAMETERS: None
279 1.1.1.1.10.2 tls *
280 1.1.1.1.10.2 tls * RETURN: None
281 1.1.1.1.10.2 tls *
282 1.1.1.1.10.2 tls * DESCRIPTION: Preprocess one entire file, line-by-line.
283 1.1.1.1.10.2 tls *
284 1.1.1.1.10.2 tls * Input: Raw user ASL from ASL_FILE_INPUT
285 1.1.1.1.10.2 tls * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR
286 1.1.1.1.10.2 tls *
287 1.1.1.1.10.2 tls ******************************************************************************/
288 1.1.1.1.10.2 tls
289 1.1.1.1.10.2 tls static void
290 1.1.1.1.10.2 tls PrPreprocessInputFile (
291 1.1.1.1.10.2 tls void)
292 1.1.1.1.10.2 tls {
293 1.1.1.1.10.2 tls UINT32 Offset;
294 1.1.1.1.10.2 tls char *Token;
295 1.1.1.1.10.2 tls char *ReplaceString;
296 1.1.1.1.10.2 tls PR_DEFINE_INFO *DefineInfo;
297 1.1.1.1.10.2 tls ACPI_SIZE TokenOffset;
298 1.1.1.1.10.2 tls char *Next;
299 1.1.1.1.10.2 tls int OffsetAdjust;
300 1.1.1.1.10.2 tls
301 1.1.1.1.10.2 tls
302 1.1.1.1.10.2 tls /* Scan line-by-line. Comments and blank lines are skipped by this function */
303 1.1.1.1.10.2 tls
304 1.1.1.1.10.2 tls while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF)
305 1.1.1.1.10.2 tls {
306 1.1.1.1.10.2 tls /* Need a copy of the input line for strok() */
307 1.1.1.1.10.2 tls
308 1.1.1.1.10.2 tls strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer);
309 1.1.1.1.10.2 tls Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next);
310 1.1.1.1.10.2 tls OffsetAdjust = 0;
311 1.1.1.1.10.2 tls
312 1.1.1.1.10.2 tls /* All preprocessor directives must begin with '#' */
313 1.1.1.1.10.2 tls
314 1.1.1.1.10.2 tls if (Token && (*Token == '#'))
315 1.1.1.1.10.2 tls {
316 1.1.1.1.10.2 tls if (strlen (Token) == 1)
317 1.1.1.1.10.2 tls {
318 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
319 1.1.1.1.10.2 tls }
320 1.1.1.1.10.2 tls else
321 1.1.1.1.10.2 tls {
322 1.1.1.1.10.2 tls Token++; /* Skip leading # */
323 1.1.1.1.10.2 tls }
324 1.1.1.1.10.2 tls
325 1.1.1.1.10.2 tls /* Execute the directive, do not write line to output file */
326 1.1.1.1.10.2 tls
327 1.1.1.1.10.2 tls PrDoDirective (Token, &Next);
328 1.1.1.1.10.2 tls continue;
329 1.1.1.1.10.2 tls }
330 1.1.1.1.10.2 tls
331 1.1.1.1.10.2 tls /*
332 1.1.1.1.10.2 tls * If we are currently within the part of an IF/ELSE block that is
333 1.1.1.1.10.2 tls * FALSE, ignore the line and do not write it to the output file.
334 1.1.1.1.10.2 tls * This continues until an #else or #endif is encountered.
335 1.1.1.1.10.2 tls */
336 1.1.1.1.10.2 tls if (Gbl_IgnoringThisCodeBlock)
337 1.1.1.1.10.2 tls {
338 1.1.1.1.10.2 tls continue;
339 1.1.1.1.10.2 tls }
340 1.1.1.1.10.2 tls
341 1.1.1.1.10.2 tls /* Match and replace all #defined names within this source line */
342 1.1.1.1.10.2 tls
343 1.1.1.1.10.2 tls while (Token)
344 1.1.1.1.10.2 tls {
345 1.1.1.1.10.2 tls DefineInfo = PrMatchDefine (Token);
346 1.1.1.1.10.2 tls if (DefineInfo)
347 1.1.1.1.10.2 tls {
348 1.1.1.1.10.2 tls if (DefineInfo->Body)
349 1.1.1.1.10.2 tls {
350 1.1.1.1.10.2 tls /* This is a macro */
351 1.1.1.1.10.2 tls
352 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
353 1.1.1.1.10.2 tls "Matched Macro: %s->%s\n",
354 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, DefineInfo->Identifier,
355 1.1.1.1.10.2 tls DefineInfo->Replacement);
356 1.1.1.1.10.2 tls
357 1.1.1.1.10.2 tls PrDoMacroInvocation (Gbl_MainTokenBuffer, Token,
358 1.1.1.1.10.2 tls DefineInfo, &Next);
359 1.1.1.1.10.2 tls }
360 1.1.1.1.10.2 tls else
361 1.1.1.1.10.2 tls {
362 1.1.1.1.10.2 tls ReplaceString = DefineInfo->Replacement;
363 1.1.1.1.10.2 tls
364 1.1.1.1.10.2 tls /* Replace the name in the original line buffer */
365 1.1.1.1.10.2 tls
366 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust;
367 1.1.1.1.10.2 tls PrReplaceData (
368 1.1.1.1.10.2 tls &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token),
369 1.1.1.1.10.2 tls ReplaceString, strlen (ReplaceString));
370 1.1.1.1.10.2 tls
371 1.1.1.1.10.2 tls /* Adjust for length difference between old and new name length */
372 1.1.1.1.10.2 tls
373 1.1.1.1.10.2 tls OffsetAdjust += strlen (ReplaceString) - strlen (Token);
374 1.1.1.1.10.2 tls
375 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
376 1.1.1.1.10.2 tls "Matched #define: %s->%s\n",
377 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Token,
378 1.1.1.1.10.2 tls *ReplaceString ? ReplaceString : "(NULL STRING)");
379 1.1.1.1.10.2 tls }
380 1.1.1.1.10.2 tls }
381 1.1.1.1.10.2 tls
382 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next);
383 1.1.1.1.10.2 tls }
384 1.1.1.1.10.2 tls
385 1.1.1.1.10.2 tls #if 0
386 1.1.1.1.10.2 tls /* Line prefix */
387 1.1.1.1.10.2 tls FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s %.5u i:%.5u */ ",
388 1.1.1.1.10.2 tls Gbl_Files[ASL_FILE_INPUT].Filename,
389 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber);
390 1.1.1.1.10.2 tls #endif
391 1.1.1.1.10.2 tls
392 1.1.1.1.10.2 tls /*
393 1.1.1.1.10.2 tls * Emit a #line directive if necessary, to keep the line numbers in
394 1.1.1.1.10.2 tls * the (.i) file synchronized with the original source code file, so
395 1.1.1.1.10.2 tls * that the correct line number appears in any error messages
396 1.1.1.1.10.2 tls * generated by the actual compiler.
397 1.1.1.1.10.2 tls */
398 1.1.1.1.10.2 tls if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1))
399 1.1.1.1.10.2 tls {
400 1.1.1.1.10.2 tls FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n",
401 1.1.1.1.10.2 tls Gbl_CurrentLineNumber);
402 1.1.1.1.10.2 tls }
403 1.1.1.1.10.2 tls
404 1.1.1.1.10.2 tls Gbl_PreviousLineNumber = Gbl_CurrentLineNumber;
405 1.1.1.1.10.2 tls Gbl_PreprocessorLineNumber++;
406 1.1.1.1.10.2 tls
407 1.1.1.1.10.2 tls /*
408 1.1.1.1.10.2 tls * Now we can write the possibly modified source line to the
409 1.1.1.1.10.2 tls * preprocessor (.i) file
410 1.1.1.1.10.2 tls */
411 1.1.1.1.10.2 tls FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer,
412 1.1.1.1.10.2 tls strlen (Gbl_CurrentLineBuffer));
413 1.1.1.1.10.2 tls }
414 1.1.1.1.10.2 tls }
415 1.1.1.1.10.2 tls
416 1.1.1.1.10.2 tls
417 1.1.1.1.10.2 tls /*******************************************************************************
418 1.1.1.1.10.2 tls *
419 1.1.1.1.10.2 tls * FUNCTION: PrDoDirective
420 1.1.1.1.10.2 tls *
421 1.1.1.1.10.2 tls * PARAMETERS: Directive - Pointer to directive name token
422 1.1.1.1.10.2 tls * Next - "Next" buffer from GetNextToken
423 1.1.1.1.10.2 tls *
424 1.1.1.1.10.2 tls * RETURN: None.
425 1.1.1.1.10.2 tls *
426 1.1.1.1.10.2 tls * DESCRIPTION: Main processing for all preprocessor directives
427 1.1.1.1.10.2 tls *
428 1.1.1.1.10.2 tls ******************************************************************************/
429 1.1.1.1.10.2 tls
430 1.1.1.1.10.2 tls static void
431 1.1.1.1.10.2 tls PrDoDirective (
432 1.1.1.1.10.2 tls char *DirectiveToken,
433 1.1.1.1.10.2 tls char **Next)
434 1.1.1.1.10.2 tls {
435 1.1.1.1.10.2 tls char *Token = Gbl_MainTokenBuffer;
436 1.1.1.1.10.2 tls char *Token2;
437 1.1.1.1.10.2 tls char *End;
438 1.1.1.1.10.2 tls UINT64 Value;
439 1.1.1.1.10.2 tls ACPI_SIZE TokenOffset;
440 1.1.1.1.10.2 tls int Directive;
441 1.1.1.1.10.2 tls ACPI_STATUS Status;
442 1.1.1.1.10.2 tls
443 1.1.1.1.10.2 tls
444 1.1.1.1.10.2 tls if (!DirectiveToken)
445 1.1.1.1.10.2 tls {
446 1.1.1.1.10.2 tls goto SyntaxError;
447 1.1.1.1.10.2 tls }
448 1.1.1.1.10.2 tls
449 1.1.1.1.10.2 tls Directive = PrMatchDirective (DirectiveToken);
450 1.1.1.1.10.2 tls if (Directive == ASL_DIRECTIVE_NOT_FOUND)
451 1.1.1.1.10.2 tls {
452 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE,
453 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (DirectiveToken));
454 1.1.1.1.10.2 tls
455 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
456 1.1.1.1.10.2 tls "#%s: Unknown directive\n",
457 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, DirectiveToken);
458 1.1.1.1.10.2 tls return;
459 1.1.1.1.10.2 tls }
460 1.1.1.1.10.2 tls
461 1.1.1.1.10.2 tls /*
462 1.1.1.1.10.2 tls * If we are currently ignoring this block and we encounter a #else or
463 1.1.1.1.10.2 tls * #elif, we must ignore their blocks also if the parent block is also
464 1.1.1.1.10.2 tls * being ignored.
465 1.1.1.1.10.2 tls */
466 1.1.1.1.10.2 tls if (Gbl_IgnoringThisCodeBlock)
467 1.1.1.1.10.2 tls {
468 1.1.1.1.10.2 tls switch (Directive)
469 1.1.1.1.10.2 tls {
470 1.1.1.1.10.2 tls case PR_DIRECTIVE_ELSE:
471 1.1.1.1.10.2 tls case PR_DIRECTIVE_ELIF:
472 1.1.1.1.10.2 tls
473 1.1.1.1.10.2 tls if (Gbl_DirectiveStack && Gbl_DirectiveStack->IgnoringThisCodeBlock)
474 1.1.1.1.10.2 tls {
475 1.1.1.1.10.2 tls PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
476 1.1.1.1.10.2 tls return;
477 1.1.1.1.10.2 tls }
478 1.1.1.1.10.2 tls break;
479 1.1.1.1.10.2 tls
480 1.1.1.1.10.2 tls default:
481 1.1.1.1.10.2 tls break;
482 1.1.1.1.10.2 tls }
483 1.1.1.1.10.2 tls }
484 1.1.1.1.10.2 tls
485 1.1.1.1.10.2 tls /*
486 1.1.1.1.10.2 tls * Need to always check for #else, #elif, #endif regardless of
487 1.1.1.1.10.2 tls * whether we are ignoring the current code block, since these
488 1.1.1.1.10.2 tls * are conditional code block terminators.
489 1.1.1.1.10.2 tls */
490 1.1.1.1.10.2 tls switch (Directive)
491 1.1.1.1.10.2 tls {
492 1.1.1.1.10.2 tls case PR_DIRECTIVE_ELSE:
493 1.1.1.1.10.2 tls
494 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
495 1.1.1.1.10.2 tls PrDbgPrint ("Executing", "else block");
496 1.1.1.1.10.2 tls return;
497 1.1.1.1.10.2 tls
498 1.1.1.1.10.2 tls case PR_DIRECTIVE_ELIF:
499 1.1.1.1.10.2 tls
500 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = !(Gbl_IgnoringThisCodeBlock);
501 1.1.1.1.10.2 tls Directive = PR_DIRECTIVE_IF;
502 1.1.1.1.10.2 tls
503 1.1.1.1.10.2 tls if (Gbl_IgnoringThisCodeBlock == TRUE)
504 1.1.1.1.10.2 tls {
505 1.1.1.1.10.2 tls /* Not executing the ELSE part -- all done here */
506 1.1.1.1.10.2 tls PrDbgPrint ("Ignoring", "elif block");
507 1.1.1.1.10.2 tls return;
508 1.1.1.1.10.2 tls }
509 1.1.1.1.10.2 tls
510 1.1.1.1.10.2 tls /*
511 1.1.1.1.10.2 tls * After this, we will execute the IF part further below.
512 1.1.1.1.10.2 tls * First, however, pop off the original #if directive.
513 1.1.1.1.10.2 tls */
514 1.1.1.1.10.2 tls if (ACPI_FAILURE (PrPopDirective ()))
515 1.1.1.1.10.2 tls {
516 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
517 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (DirectiveToken));
518 1.1.1.1.10.2 tls }
519 1.1.1.1.10.2 tls
520 1.1.1.1.10.2 tls PrDbgPrint ("Executing", "elif block");
521 1.1.1.1.10.2 tls break;
522 1.1.1.1.10.2 tls
523 1.1.1.1.10.2 tls case PR_DIRECTIVE_ENDIF:
524 1.1.1.1.10.2 tls
525 1.1.1.1.10.2 tls PrDbgPrint ("Executing", "endif");
526 1.1.1.1.10.2 tls
527 1.1.1.1.10.2 tls /* Pop the owning #if/#ifdef/#ifndef */
528 1.1.1.1.10.2 tls
529 1.1.1.1.10.2 tls if (ACPI_FAILURE (PrPopDirective ()))
530 1.1.1.1.10.2 tls {
531 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH,
532 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (DirectiveToken));
533 1.1.1.1.10.2 tls }
534 1.1.1.1.10.2 tls return;
535 1.1.1.1.10.2 tls
536 1.1.1.1.10.2 tls default:
537 1.1.1.1.10.2 tls break;
538 1.1.1.1.10.2 tls }
539 1.1.1.1.10.2 tls
540 1.1.1.1.10.2 tls /* Most directives have at least one argument */
541 1.1.1.1.10.2 tls
542 1.1.1.1.10.2 tls if (Gbl_DirectiveInfo[Directive].ArgCount == 1)
543 1.1.1.1.10.2 tls {
544 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
545 1.1.1.1.10.2 tls if (!Token)
546 1.1.1.1.10.2 tls {
547 1.1.1.1.10.2 tls goto SyntaxError;
548 1.1.1.1.10.2 tls }
549 1.1.1.1.10.2 tls }
550 1.1.1.1.10.2 tls
551 1.1.1.1.10.2 tls /*
552 1.1.1.1.10.2 tls * At this point, if we are ignoring the current code block,
553 1.1.1.1.10.2 tls * do not process any more directives (i.e., ignore them also.)
554 1.1.1.1.10.2 tls * For "if" style directives, open/push a new block anyway. We
555 1.1.1.1.10.2 tls * must do this to keep track of #endif directives
556 1.1.1.1.10.2 tls */
557 1.1.1.1.10.2 tls if (Gbl_IgnoringThisCodeBlock)
558 1.1.1.1.10.2 tls {
559 1.1.1.1.10.2 tls switch (Directive)
560 1.1.1.1.10.2 tls {
561 1.1.1.1.10.2 tls case PR_DIRECTIVE_IF:
562 1.1.1.1.10.2 tls case PR_DIRECTIVE_IFDEF:
563 1.1.1.1.10.2 tls case PR_DIRECTIVE_IFNDEF:
564 1.1.1.1.10.2 tls
565 1.1.1.1.10.2 tls PrPushDirective (Directive, Token);
566 1.1.1.1.10.2 tls PrDbgPrint ("Ignoring", Gbl_DirectiveInfo[Directive].Name);
567 1.1.1.1.10.2 tls break;
568 1.1.1.1.10.2 tls
569 1.1.1.1.10.2 tls default:
570 1.1.1.1.10.2 tls break;
571 1.1.1.1.10.2 tls }
572 1.1.1.1.10.2 tls
573 1.1.1.1.10.2 tls return;
574 1.1.1.1.10.2 tls }
575 1.1.1.1.10.2 tls
576 1.1.1.1.10.2 tls /*
577 1.1.1.1.10.2 tls * Execute the directive
578 1.1.1.1.10.2 tls */
579 1.1.1.1.10.2 tls PrDbgPrint ("Begin execution", Gbl_DirectiveInfo[Directive].Name);
580 1.1.1.1.10.2 tls
581 1.1.1.1.10.2 tls switch (Directive)
582 1.1.1.1.10.2 tls {
583 1.1.1.1.10.2 tls case PR_DIRECTIVE_IF:
584 1.1.1.1.10.2 tls
585 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer;
586 1.1.1.1.10.2 tls
587 1.1.1.1.10.2 tls /* Need to expand #define macros in the expression string first */
588 1.1.1.1.10.2 tls
589 1.1.1.1.10.2 tls Status = PrResolveIntegerExpression (
590 1.1.1.1.10.2 tls &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
591 1.1.1.1.10.2 tls if (ACPI_FAILURE (Status))
592 1.1.1.1.10.2 tls {
593 1.1.1.1.10.2 tls return;
594 1.1.1.1.10.2 tls }
595 1.1.1.1.10.2 tls
596 1.1.1.1.10.2 tls PrPushDirective (Directive, Token);
597 1.1.1.1.10.2 tls if (!Value)
598 1.1.1.1.10.2 tls {
599 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = TRUE;
600 1.1.1.1.10.2 tls }
601 1.1.1.1.10.2 tls
602 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
603 1.1.1.1.10.2 tls "Resolved #if: %8.8X%8.8X %s\n",
604 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value),
605 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>");
606 1.1.1.1.10.2 tls break;
607 1.1.1.1.10.2 tls
608 1.1.1.1.10.2 tls case PR_DIRECTIVE_IFDEF:
609 1.1.1.1.10.2 tls
610 1.1.1.1.10.2 tls PrPushDirective (Directive, Token);
611 1.1.1.1.10.2 tls if (!PrMatchDefine (Token))
612 1.1.1.1.10.2 tls {
613 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = TRUE;
614 1.1.1.1.10.2 tls }
615 1.1.1.1.10.2 tls
616 1.1.1.1.10.2 tls PrDbgPrint ("Evaluated", "ifdef");
617 1.1.1.1.10.2 tls break;
618 1.1.1.1.10.2 tls
619 1.1.1.1.10.2 tls case PR_DIRECTIVE_IFNDEF:
620 1.1.1.1.10.2 tls
621 1.1.1.1.10.2 tls PrPushDirective (Directive, Token);
622 1.1.1.1.10.2 tls if (PrMatchDefine (Token))
623 1.1.1.1.10.2 tls {
624 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = TRUE;
625 1.1.1.1.10.2 tls }
626 1.1.1.1.10.2 tls
627 1.1.1.1.10.2 tls PrDbgPrint ("Evaluated", "ifndef");
628 1.1.1.1.10.2 tls break;
629 1.1.1.1.10.2 tls
630 1.1.1.1.10.2 tls case PR_DIRECTIVE_DEFINE:
631 1.1.1.1.10.2 tls /*
632 1.1.1.1.10.2 tls * By definition, if first char after the name is a paren,
633 1.1.1.1.10.2 tls * this is a function macro.
634 1.1.1.1.10.2 tls */
635 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token);
636 1.1.1.1.10.2 tls if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(')
637 1.1.1.1.10.2 tls {
638 1.1.1.1.10.2 tls #ifndef MACROS_SUPPORTED
639 1.1.1.1.10.2 tls AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n",
640 1.1.1.1.10.2 tls Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber);
641 1.1.1.1.10.2 tls exit(1);
642 1.1.1.1.10.2 tls #else
643 1.1.1.1.10.2 tls PrAddMacro (Token, Next);
644 1.1.1.1.10.2 tls #endif
645 1.1.1.1.10.2 tls }
646 1.1.1.1.10.2 tls else
647 1.1.1.1.10.2 tls {
648 1.1.1.1.10.2 tls /* Use the remainder of the line for the #define */
649 1.1.1.1.10.2 tls
650 1.1.1.1.10.2 tls Token2 = *Next;
651 1.1.1.1.10.2 tls if (Token2)
652 1.1.1.1.10.2 tls {
653 1.1.1.1.10.2 tls while ((*Token2 == ' ') || (*Token2 == '\t'))
654 1.1.1.1.10.2 tls {
655 1.1.1.1.10.2 tls Token2++;
656 1.1.1.1.10.2 tls }
657 1.1.1.1.10.2 tls End = Token2;
658 1.1.1.1.10.2 tls while (*End != '\n')
659 1.1.1.1.10.2 tls {
660 1.1.1.1.10.2 tls End++;
661 1.1.1.1.10.2 tls }
662 1.1.1.1.10.2 tls *End = 0;
663 1.1.1.1.10.2 tls }
664 1.1.1.1.10.2 tls else
665 1.1.1.1.10.2 tls {
666 1.1.1.1.10.2 tls Token2 = "";
667 1.1.1.1.10.2 tls }
668 1.1.1.1.10.2 tls #if 0
669 1.1.1.1.10.2 tls Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next);
670 1.1.1.1.10.2 tls if (!Token2)
671 1.1.1.1.10.2 tls {
672 1.1.1.1.10.2 tls Token2 = "";
673 1.1.1.1.10.2 tls }
674 1.1.1.1.10.2 tls #endif
675 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
676 1.1.1.1.10.2 tls "New #define: %s->%s\n",
677 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Token, Token2);
678 1.1.1.1.10.2 tls
679 1.1.1.1.10.2 tls PrAddDefine (Token, Token2, FALSE);
680 1.1.1.1.10.2 tls }
681 1.1.1.1.10.2 tls break;
682 1.1.1.1.10.2 tls
683 1.1.1.1.10.2 tls case PR_DIRECTIVE_ERROR:
684 1.1.1.1.10.2 tls
685 1.1.1.1.10.2 tls /* Note: No macro expansion */
686 1.1.1.1.10.2 tls
687 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE,
688 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (Token));
689 1.1.1.1.10.2 tls
690 1.1.1.1.10.2 tls Gbl_SourceLine = 0;
691 1.1.1.1.10.2 tls Gbl_NextError = Gbl_ErrorLog;
692 1.1.1.1.10.2 tls CmCleanupAndExit ();
693 1.1.1.1.10.2 tls exit(1);
694 1.1.1.1.10.2 tls
695 1.1.1.1.10.2 tls case PR_DIRECTIVE_INCLUDE:
696 1.1.1.1.10.2 tls
697 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, " \"<>", Next);
698 1.1.1.1.10.2 tls if (!Token)
699 1.1.1.1.10.2 tls {
700 1.1.1.1.10.2 tls goto SyntaxError;
701 1.1.1.1.10.2 tls }
702 1.1.1.1.10.2 tls
703 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
704 1.1.1.1.10.2 tls "Start #include file \"%s\"\n", Gbl_CurrentLineNumber,
705 1.1.1.1.10.2 tls Token, Gbl_CurrentLineNumber);
706 1.1.1.1.10.2 tls
707 1.1.1.1.10.2 tls PrOpenIncludeFile (Token);
708 1.1.1.1.10.2 tls break;
709 1.1.1.1.10.2 tls
710 1.1.1.1.10.2 tls case PR_DIRECTIVE_LINE:
711 1.1.1.1.10.2 tls
712 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer;
713 1.1.1.1.10.2 tls
714 1.1.1.1.10.2 tls Status = PrResolveIntegerExpression (
715 1.1.1.1.10.2 tls &Gbl_CurrentLineBuffer[TokenOffset-1], &Value);
716 1.1.1.1.10.2 tls if (ACPI_FAILURE (Status))
717 1.1.1.1.10.2 tls {
718 1.1.1.1.10.2 tls return;
719 1.1.1.1.10.2 tls }
720 1.1.1.1.10.2 tls
721 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
722 1.1.1.1.10.2 tls "User #line invocation %s\n", Gbl_CurrentLineNumber,
723 1.1.1.1.10.2 tls Token);
724 1.1.1.1.10.2 tls
725 1.1.1.1.10.2 tls /* Update local line numbers */
726 1.1.1.1.10.2 tls
727 1.1.1.1.10.2 tls Gbl_CurrentLineNumber = (UINT32) Value;
728 1.1.1.1.10.2 tls Gbl_PreviousLineNumber = 0;
729 1.1.1.1.10.2 tls
730 1.1.1.1.10.2 tls /* Emit #line into the preprocessor file */
731 1.1.1.1.10.2 tls
732 1.1.1.1.10.2 tls FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n",
733 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename);
734 1.1.1.1.10.2 tls break;
735 1.1.1.1.10.2 tls
736 1.1.1.1.10.2 tls case PR_DIRECTIVE_PRAGMA:
737 1.1.1.1.10.2 tls
738 1.1.1.1.10.2 tls if (!strcmp (Token, "disable"))
739 1.1.1.1.10.2 tls {
740 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
741 1.1.1.1.10.2 tls if (!Token)
742 1.1.1.1.10.2 tls {
743 1.1.1.1.10.2 tls goto SyntaxError;
744 1.1.1.1.10.2 tls }
745 1.1.1.1.10.2 tls
746 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer;
747 1.1.1.1.10.2 tls AslDisableException (&Gbl_CurrentLineBuffer[TokenOffset]);
748 1.1.1.1.10.2 tls }
749 1.1.1.1.10.2 tls else if (!strcmp (Token, "message"))
750 1.1.1.1.10.2 tls {
751 1.1.1.1.10.2 tls Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next);
752 1.1.1.1.10.2 tls if (!Token)
753 1.1.1.1.10.2 tls {
754 1.1.1.1.10.2 tls goto SyntaxError;
755 1.1.1.1.10.2 tls }
756 1.1.1.1.10.2 tls
757 1.1.1.1.10.2 tls TokenOffset = Token - Gbl_MainTokenBuffer;
758 1.1.1.1.10.2 tls AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]);
759 1.1.1.1.10.2 tls }
760 1.1.1.1.10.2 tls else
761 1.1.1.1.10.2 tls {
762 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA,
763 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (Token));
764 1.1.1.1.10.2 tls return;
765 1.1.1.1.10.2 tls }
766 1.1.1.1.10.2 tls
767 1.1.1.1.10.2 tls break;
768 1.1.1.1.10.2 tls
769 1.1.1.1.10.2 tls case PR_DIRECTIVE_UNDEF:
770 1.1.1.1.10.2 tls
771 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
772 1.1.1.1.10.2 tls "#undef: %s\n", Gbl_CurrentLineNumber, Token);
773 1.1.1.1.10.2 tls
774 1.1.1.1.10.2 tls PrRemoveDefine (Token);
775 1.1.1.1.10.2 tls break;
776 1.1.1.1.10.2 tls
777 1.1.1.1.10.2 tls case PR_DIRECTIVE_WARNING:
778 1.1.1.1.10.2 tls
779 1.1.1.1.10.2 tls PrError (ASL_WARNING, ASL_MSG_WARNING_DIRECTIVE,
780 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (Token));
781 1.1.1.1.10.2 tls break;
782 1.1.1.1.10.2 tls
783 1.1.1.1.10.2 tls default:
784 1.1.1.1.10.2 tls
785 1.1.1.1.10.2 tls /* Should never get here */
786 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID
787 1.1.1.1.10.2 tls "Unrecognized directive: %u\n",
788 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Directive);
789 1.1.1.1.10.2 tls break;
790 1.1.1.1.10.2 tls }
791 1.1.1.1.10.2 tls
792 1.1.1.1.10.2 tls return;
793 1.1.1.1.10.2 tls
794 1.1.1.1.10.2 tls SyntaxError:
795 1.1.1.1.10.2 tls
796 1.1.1.1.10.2 tls PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX,
797 1.1.1.1.10.2 tls THIS_TOKEN_OFFSET (DirectiveToken));
798 1.1.1.1.10.2 tls return;
799 1.1.1.1.10.2 tls }
800 1.1.1.1.10.2 tls
801 1.1.1.1.10.2 tls
802 1.1.1.1.10.2 tls /*******************************************************************************
803 1.1.1.1.10.2 tls *
804 1.1.1.1.10.2 tls * FUNCTION: PrMatchDirective
805 1.1.1.1.10.2 tls *
806 1.1.1.1.10.2 tls * PARAMETERS: Directive - Pointer to directive name token
807 1.1.1.1.10.2 tls *
808 1.1.1.1.10.2 tls * RETURN: Index into command array, -1 if not found
809 1.1.1.1.10.2 tls *
810 1.1.1.1.10.2 tls * DESCRIPTION: Lookup the incoming directive in the known directives table.
811 1.1.1.1.10.2 tls *
812 1.1.1.1.10.2 tls ******************************************************************************/
813 1.1.1.1.10.2 tls
814 1.1.1.1.10.2 tls static int
815 1.1.1.1.10.2 tls PrMatchDirective (
816 1.1.1.1.10.2 tls char *Directive)
817 1.1.1.1.10.2 tls {
818 1.1.1.1.10.2 tls int i;
819 1.1.1.1.10.2 tls
820 1.1.1.1.10.2 tls
821 1.1.1.1.10.2 tls if (!Directive || Directive[0] == 0)
822 1.1.1.1.10.2 tls {
823 1.1.1.1.10.2 tls return (ASL_DIRECTIVE_NOT_FOUND);
824 1.1.1.1.10.2 tls }
825 1.1.1.1.10.2 tls
826 1.1.1.1.10.2 tls for (i = 0; Gbl_DirectiveInfo[i].Name; i++)
827 1.1.1.1.10.2 tls {
828 1.1.1.1.10.2 tls if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive))
829 1.1.1.1.10.2 tls {
830 1.1.1.1.10.2 tls return (i);
831 1.1.1.1.10.2 tls }
832 1.1.1.1.10.2 tls }
833 1.1.1.1.10.2 tls
834 1.1.1.1.10.2 tls return (ASL_DIRECTIVE_NOT_FOUND); /* Command not recognized */
835 1.1.1.1.10.2 tls }
836 1.1.1.1.10.2 tls
837 1.1.1.1.10.2 tls
838 1.1.1.1.10.2 tls /*******************************************************************************
839 1.1.1.1.10.2 tls *
840 1.1.1.1.10.2 tls * FUNCTION: PrPushDirective
841 1.1.1.1.10.2 tls *
842 1.1.1.1.10.2 tls * PARAMETERS: Directive - Encoded directive ID
843 1.1.1.1.10.2 tls * Argument - String containing argument to the
844 1.1.1.1.10.2 tls * directive
845 1.1.1.1.10.2 tls *
846 1.1.1.1.10.2 tls * RETURN: None
847 1.1.1.1.10.2 tls *
848 1.1.1.1.10.2 tls * DESCRIPTION: Push an item onto the directive stack. Used for processing
849 1.1.1.1.10.2 tls * nested #if/#else type conditional compilation directives.
850 1.1.1.1.10.2 tls * Specifically: Used on detection of #if/#ifdef/#ifndef to open
851 1.1.1.1.10.2 tls * a block.
852 1.1.1.1.10.2 tls *
853 1.1.1.1.10.2 tls ******************************************************************************/
854 1.1.1.1.10.2 tls
855 1.1.1.1.10.2 tls static void
856 1.1.1.1.10.2 tls PrPushDirective (
857 1.1.1.1.10.2 tls int Directive,
858 1.1.1.1.10.2 tls char *Argument)
859 1.1.1.1.10.2 tls {
860 1.1.1.1.10.2 tls DIRECTIVE_INFO *Info;
861 1.1.1.1.10.2 tls
862 1.1.1.1.10.2 tls
863 1.1.1.1.10.2 tls /* Allocate and populate a stack info item */
864 1.1.1.1.10.2 tls
865 1.1.1.1.10.2 tls Info = ACPI_ALLOCATE (sizeof (DIRECTIVE_INFO));
866 1.1.1.1.10.2 tls
867 1.1.1.1.10.2 tls Info->Next = Gbl_DirectiveStack;
868 1.1.1.1.10.2 tls Info->Directive = Directive;
869 1.1.1.1.10.2 tls Info->IgnoringThisCodeBlock = Gbl_IgnoringThisCodeBlock;
870 1.1.1.1.10.2 tls strncpy (Info->Argument, Argument, MAX_ARGUMENT_LENGTH);
871 1.1.1.1.10.2 tls
872 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT,
873 1.1.1.1.10.2 tls "Pr(%.4u) - [%u %s] %*s Pushed [#%s %s]: IgnoreFlag = %s\n",
874 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Gbl_IfDepth,
875 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock ? "I" : "E",
876 1.1.1.1.10.2 tls Gbl_IfDepth * 4, " ",
877 1.1.1.1.10.2 tls Gbl_DirectiveInfo[Directive].Name,
878 1.1.1.1.10.2 tls Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
879 1.1.1.1.10.2 tls
880 1.1.1.1.10.2 tls /* Push new item */
881 1.1.1.1.10.2 tls
882 1.1.1.1.10.2 tls Gbl_DirectiveStack = Info;
883 1.1.1.1.10.2 tls Gbl_IfDepth++;
884 1.1.1.1.10.2 tls }
885 1.1.1.1.10.2 tls
886 1.1.1.1.10.2 tls
887 1.1.1.1.10.2 tls /*******************************************************************************
888 1.1.1.1.10.2 tls *
889 1.1.1.1.10.2 tls * FUNCTION: PrPopDirective
890 1.1.1.1.10.2 tls *
891 1.1.1.1.10.2 tls * PARAMETERS: None
892 1.1.1.1.10.2 tls *
893 1.1.1.1.10.2 tls * RETURN: Status. Error if the stack is empty.
894 1.1.1.1.10.2 tls *
895 1.1.1.1.10.2 tls * DESCRIPTION: Pop an item off the directive stack. Used for processing
896 1.1.1.1.10.2 tls * nested #if/#else type conditional compilation directives.
897 1.1.1.1.10.2 tls * Specifically: Used on detection of #elif and #endif to remove
898 1.1.1.1.10.2 tls * the original #if/#ifdef/#ifndef from the stack and close
899 1.1.1.1.10.2 tls * the block.
900 1.1.1.1.10.2 tls *
901 1.1.1.1.10.2 tls ******************************************************************************/
902 1.1.1.1.10.2 tls
903 1.1.1.1.10.2 tls static ACPI_STATUS
904 1.1.1.1.10.2 tls PrPopDirective (
905 1.1.1.1.10.2 tls void)
906 1.1.1.1.10.2 tls {
907 1.1.1.1.10.2 tls DIRECTIVE_INFO *Info;
908 1.1.1.1.10.2 tls
909 1.1.1.1.10.2 tls
910 1.1.1.1.10.2 tls /* Check for empty stack */
911 1.1.1.1.10.2 tls
912 1.1.1.1.10.2 tls Info = Gbl_DirectiveStack;
913 1.1.1.1.10.2 tls if (!Info)
914 1.1.1.1.10.2 tls {
915 1.1.1.1.10.2 tls return (AE_ERROR);
916 1.1.1.1.10.2 tls }
917 1.1.1.1.10.2 tls
918 1.1.1.1.10.2 tls /* Pop one item, keep globals up-to-date */
919 1.1.1.1.10.2 tls
920 1.1.1.1.10.2 tls Gbl_IfDepth--;
921 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock = Info->IgnoringThisCodeBlock;
922 1.1.1.1.10.2 tls Gbl_DirectiveStack = Info->Next;
923 1.1.1.1.10.2 tls
924 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT,
925 1.1.1.1.10.2 tls "Pr(%.4u) - [%u %s] %*s Popped [#%s %s]: IgnoreFlag now = %s\n",
926 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Gbl_IfDepth,
927 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock ? "I" : "E",
928 1.1.1.1.10.2 tls Gbl_IfDepth * 4, " ",
929 1.1.1.1.10.2 tls Gbl_DirectiveInfo[Info->Directive].Name,
930 1.1.1.1.10.2 tls Info->Argument, Gbl_IgnoringThisCodeBlock ? "TRUE" : "FALSE");
931 1.1.1.1.10.2 tls
932 1.1.1.1.10.2 tls ACPI_FREE (Info);
933 1.1.1.1.10.2 tls return (AE_OK);
934 1.1.1.1.10.2 tls }
935 1.1.1.1.10.2 tls
936 1.1.1.1.10.2 tls
937 1.1.1.1.10.2 tls /*******************************************************************************
938 1.1.1.1.10.2 tls *
939 1.1.1.1.10.2 tls * FUNCTION: PrDbgPrint
940 1.1.1.1.10.2 tls *
941 1.1.1.1.10.2 tls * PARAMETERS: Action - Action being performed
942 1.1.1.1.10.2 tls * DirectiveName - Directive being processed
943 1.1.1.1.10.2 tls *
944 1.1.1.1.10.2 tls * RETURN: None
945 1.1.1.1.10.2 tls *
946 1.1.1.1.10.2 tls * DESCRIPTION: Special debug print for directive processing.
947 1.1.1.1.10.2 tls *
948 1.1.1.1.10.2 tls ******************************************************************************/
949 1.1.1.1.10.2 tls
950 1.1.1.1.10.2 tls static void
951 1.1.1.1.10.2 tls PrDbgPrint (
952 1.1.1.1.10.2 tls char *Action,
953 1.1.1.1.10.2 tls char *DirectiveName)
954 1.1.1.1.10.2 tls {
955 1.1.1.1.10.2 tls
956 1.1.1.1.10.2 tls DbgPrint (ASL_DEBUG_OUTPUT, "Pr(%.4u) - [%u %s] "
957 1.1.1.1.10.2 tls "%*s %s #%s, Depth %u\n",
958 1.1.1.1.10.2 tls Gbl_CurrentLineNumber, Gbl_IfDepth,
959 1.1.1.1.10.2 tls Gbl_IgnoringThisCodeBlock ? "I" : "E",
960 1.1.1.1.10.2 tls Gbl_IfDepth * 4, " ",
961 1.1.1.1.10.2 tls Action, DirectiveName, Gbl_IfDepth);
962 1.1.1.1.10.2 tls }
963