aslcompile.c revision 1.26 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aslcompile - top level compile module
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.25 christos /******************************************************************************
8 1.25 christos *
9 1.25 christos * 1. Copyright Notice
10 1.25 christos *
11 1.26 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.25 christos * 2. License
15 1.25 christos *
16 1.25 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.25 christos * rights. You may have additional license terms from the party that provided
18 1.25 christos * you this software, covering your right to use that party's intellectual
19 1.25 christos * property rights.
20 1.25 christos *
21 1.25 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.25 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.25 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.25 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.25 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.25 christos * Code in any form, with the right to sublicense such rights; and
27 1.25 christos *
28 1.25 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.25 christos * license (with the right to sublicense), under only those claims of Intel
30 1.25 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.25 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.25 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.25 christos * license, and in no event shall the patent license extend to any additions
34 1.25 christos * to or modifications of the Original Intel Code. No other license or right
35 1.25 christos * is granted directly or by implication, estoppel or otherwise;
36 1.25 christos *
37 1.25 christos * The above copyright and patent license is granted only if the following
38 1.25 christos * conditions are met:
39 1.25 christos *
40 1.25 christos * 3. Conditions
41 1.25 christos *
42 1.25 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.25 christos * Redistribution of source code of any substantial portion of the Covered
44 1.25 christos * Code or modification with rights to further distribute source must include
45 1.25 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.25 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.25 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.25 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.25 christos * Code and the date of any change. Licensee must include in that file the
50 1.25 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.25 christos * must include a prominent statement that the modification is derived,
52 1.25 christos * directly or indirectly, from Original Intel Code.
53 1.25 christos *
54 1.25 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.25 christos * Redistribution of source code of any substantial portion of the Covered
56 1.25 christos * Code or modification without rights to further distribute source must
57 1.25 christos * include the following Disclaimer and Export Compliance provision in the
58 1.25 christos * documentation and/or other materials provided with distribution. In
59 1.25 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.25 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.25 christos * license from Licensee to its licensee is limited to the intellectual
62 1.25 christos * property embodied in the software Licensee provides to its licensee, and
63 1.25 christos * not to intellectual property embodied in modifications its licensee may
64 1.25 christos * make.
65 1.25 christos *
66 1.25 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.25 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.25 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.25 christos * provision in the documentation and/or other materials provided with the
70 1.25 christos * distribution.
71 1.25 christos *
72 1.25 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.25 christos * Intel Code.
74 1.25 christos *
75 1.25 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.25 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.25 christos * other dealings in products derived from or relating to the Covered Code
78 1.25 christos * without prior written authorization from Intel.
79 1.25 christos *
80 1.25 christos * 4. Disclaimer and Export Compliance
81 1.25 christos *
82 1.25 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.25 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.25 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.25 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.25 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.25 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.25 christos * PARTICULAR PURPOSE.
89 1.25 christos *
90 1.25 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.25 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.25 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.25 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.25 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.25 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.25 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.25 christos * LIMITED REMEDY.
98 1.25 christos *
99 1.25 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.25 christos * software or system incorporating such software without first obtaining any
101 1.25 christos * required license or other approval from the U. S. Department of Commerce or
102 1.25 christos * any other agency or department of the United States Government. In the
103 1.25 christos * event Licensee exports any such software from the United States or
104 1.25 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.25 christos * ensure that the distribution and export/re-export of the software is in
106 1.25 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.25 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.25 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.25 christos * software, or service, directly or indirectly, to any country for which the
110 1.25 christos * United States government or any agency thereof requires an export license,
111 1.25 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.25 christos * such license, approval or letter.
113 1.25 christos *
114 1.25 christos *****************************************************************************
115 1.25 christos *
116 1.25 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.25 christos * following license:
118 1.25 christos *
119 1.3 jruoho * Redistribution and use in source and binary forms, with or without
120 1.3 jruoho * modification, are permitted provided that the following conditions
121 1.3 jruoho * are met:
122 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
123 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
124 1.3 jruoho * without modification.
125 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
127 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
128 1.3 jruoho * including a substantially similar Disclaimer requirement for further
129 1.3 jruoho * binary redistribution.
130 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
131 1.3 jruoho * of any contributors may be used to endorse or promote products derived
132 1.3 jruoho * from this software without specific prior written permission.
133 1.3 jruoho *
134 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.20 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.25 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.25 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.25 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.25 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.25 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.25 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.25 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.25 christos *
146 1.25 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.25 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.25 christos * Software Foundation.
149 1.25 christos *
150 1.25 christos *****************************************************************************/
151 1.3 jruoho
152 1.3 jruoho #include "aslcompiler.h"
153 1.5 christos #include "acnamesp.h"
154 1.1 jruoho
155 1.1 jruoho #include <stdio.h>
156 1.1 jruoho #include <time.h>
157 1.3 jruoho #include <acapps.h>
158 1.1 jruoho
159 1.1 jruoho #define _COMPONENT ACPI_COMPILER
160 1.1 jruoho ACPI_MODULE_NAME ("aslcompile")
161 1.1 jruoho
162 1.4 christos /*
163 1.4 christos * Main parser entry
164 1.4 christos * External is here in case the parser emits the same external in the
165 1.4 christos * generated header. (Newer versions of Bison)
166 1.4 christos */
167 1.4 christos int
168 1.4 christos AslCompilerparse(
169 1.4 christos void);
170 1.4 christos
171 1.1 jruoho /* Local prototypes */
172 1.1 jruoho
173 1.1 jruoho static void
174 1.1 jruoho CmFlushSourceCode (
175 1.1 jruoho void);
176 1.1 jruoho
177 1.3 jruoho static void
178 1.4 christos CmDumpAllEvents (
179 1.4 christos void);
180 1.4 christos
181 1.16 christos static void
182 1.16 christos CmFinishFiles(
183 1.16 christos BOOLEAN DeleteAmlFile);
184 1.16 christos
185 1.1 jruoho
186 1.1 jruoho /*******************************************************************************
187 1.1 jruoho *
188 1.1 jruoho * FUNCTION: CmDoCompile
189 1.1 jruoho *
190 1.1 jruoho * PARAMETERS: None
191 1.1 jruoho *
192 1.1 jruoho * RETURN: Status (0 = OK)
193 1.1 jruoho *
194 1.1 jruoho * DESCRIPTION: This procedure performs the entire compile
195 1.1 jruoho *
196 1.1 jruoho ******************************************************************************/
197 1.1 jruoho
198 1.16 christos ACPI_STATUS
199 1.1 jruoho CmDoCompile (
200 1.1 jruoho void)
201 1.1 jruoho {
202 1.1 jruoho UINT8 FullCompile;
203 1.1 jruoho UINT8 Event;
204 1.16 christos ASL_GLOBAL_FILE_NODE *FileNode;
205 1.1 jruoho
206 1.1 jruoho
207 1.1 jruoho FullCompile = UtBeginEvent ("*** Total Compile time ***");
208 1.1 jruoho Event = UtBeginEvent ("Open input and output files");
209 1.1 jruoho UtEndEvent (Event);
210 1.1 jruoho
211 1.4 christos Event = UtBeginEvent ("Preprocess input file");
212 1.15 christos if (AslGbl_PreprocessFlag)
213 1.4 christos {
214 1.7 christos /* Enter compiler name as a #define */
215 1.7 christos
216 1.7 christos PrAddDefine (ASL_DEFINE, "", FALSE);
217 1.7 christos
218 1.4 christos /* Preprocessor */
219 1.4 christos
220 1.4 christos PrDoPreprocess ();
221 1.15 christos AslGbl_CurrentLineNumber = 1;
222 1.15 christos AslGbl_LogicalLineNumber = 1;
223 1.18 christos AslGbl_CurrentLineOffset = 0;
224 1.7 christos
225 1.15 christos if (AslGbl_PreprocessOnly)
226 1.4 christos {
227 1.4 christos UtEndEvent (Event);
228 1.16 christos return (AE_OK);
229 1.4 christos }
230 1.4 christos }
231 1.4 christos UtEndEvent (Event);
232 1.4 christos
233 1.7 christos
234 1.1 jruoho /* Build the parse tree */
235 1.1 jruoho
236 1.1 jruoho Event = UtBeginEvent ("Parse source code and build parse tree");
237 1.1 jruoho AslCompilerparse();
238 1.1 jruoho UtEndEvent (Event);
239 1.1 jruoho
240 1.6 christos /* Check for parser-detected syntax errors */
241 1.1 jruoho
242 1.15 christos if (AslGbl_SyntaxError)
243 1.4 christos {
244 1.22 christos AslError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
245 1.8 christos "Compiler aborting due to parser-detected syntax error(s)\n");
246 1.16 christos
247 1.16 christos /* Flag this error in the FileNode for compilation summary */
248 1.16 christos
249 1.16 christos FileNode = FlGetCurrentFileNode ();
250 1.16 christos FileNode->ParserErrorDetected = TRUE;
251 1.16 christos AslGbl_ParserErrorDetected = TRUE;
252 1.4 christos LsDumpParseTree ();
253 1.22 christos AePrintErrorLog(ASL_FILE_STDERR);
254 1.22 christos
255 1.4 christos goto ErrorExit;
256 1.4 christos }
257 1.1 jruoho
258 1.1 jruoho /* Did the parse tree get successfully constructed? */
259 1.1 jruoho
260 1.15 christos if (!AslGbl_ParseTreeRoot)
261 1.1 jruoho {
262 1.4 christos /*
263 1.4 christos * If there are no errors, then we have some sort of
264 1.4 christos * internal problem.
265 1.4 christos */
266 1.4 christos AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
267 1.4 christos NULL, "- Could not resolve parse tree root node");
268 1.4 christos
269 1.4 christos goto ErrorExit;
270 1.1 jruoho }
271 1.1 jruoho
272 1.22 christos AePrintErrorLog(ASL_FILE_STDERR);
273 1.22 christos
274 1.4 christos /* Flush out any remaining source after parse tree is complete */
275 1.4 christos
276 1.4 christos Event = UtBeginEvent ("Flush source input");
277 1.4 christos CmFlushSourceCode ();
278 1.4 christos
279 1.6 christos /* Prune the parse tree if requested (debug purposes only) */
280 1.6 christos
281 1.15 christos if (AslGbl_PruneParseTree)
282 1.6 christos {
283 1.15 christos AslPruneParseTree (AslGbl_PruneDepth, AslGbl_PruneType);
284 1.6 christos }
285 1.6 christos
286 1.1 jruoho /* Optional parse tree dump, compiler debug output only */
287 1.1 jruoho
288 1.1 jruoho LsDumpParseTree ();
289 1.1 jruoho
290 1.22 christos AslGbl_ParserErrorDetected = FALSE;
291 1.22 christos AslGbl_SyntaxError = FALSE;
292 1.19 christos UtEndEvent (Event);
293 1.16 christos UtEndEvent (FullCompile);
294 1.16 christos
295 1.22 christos AslGbl_ParserErrorDetected = FALSE;
296 1.22 christos AslGbl_SyntaxError = FALSE;
297 1.16 christos ErrorExit:
298 1.16 christos UtEndEvent (FullCompile);
299 1.16 christos return (AE_ERROR);
300 1.16 christos }
301 1.16 christos
302 1.16 christos
303 1.16 christos /*******************************************************************************
304 1.16 christos *
305 1.16 christos * FUNCTION: CmDoAslMiddleAndBackEnd
306 1.16 christos *
307 1.16 christos * PARAMETERS: None
308 1.16 christos *
309 1.16 christos * RETURN: Status of middle-end and back-end
310 1.16 christos *
311 1.16 christos * DESCRIPTION: Perform compiler middle-end (type checking and semantic
312 1.16 christos * analysis) and back-end (code generation)
313 1.16 christos *
314 1.16 christos ******************************************************************************/
315 1.16 christos
316 1.16 christos int
317 1.16 christos CmDoAslMiddleAndBackEnd (
318 1.16 christos void)
319 1.16 christos {
320 1.16 christos UINT8 Event;
321 1.16 christos ACPI_STATUS Status;
322 1.16 christos
323 1.1 jruoho
324 1.18 christos OpcGetIntegerWidth (AslGbl_ParseTreeRoot->Asl.Child);
325 1.18 christos
326 1.18 christos /* Pre-process parse tree for any operator transforms */
327 1.18 christos
328 1.18 christos Event = UtBeginEvent ("Parse tree transforms");
329 1.18 christos DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
330 1.18 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
331 1.18 christos TrAmlTransformWalkBegin, TrAmlTransformWalkEnd, NULL);
332 1.18 christos UtEndEvent (Event);
333 1.18 christos
334 1.18 christos /* Generate AML opcodes corresponding to the parse tokens */
335 1.18 christos
336 1.18 christos Event = UtBeginEvent ("Generate AML opcodes");
337 1.18 christos DbgPrint (ASL_DEBUG_OUTPUT, "Generating AML opcodes\n\n");
338 1.18 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
339 1.18 christos NULL, OpcAmlOpcodeWalk, NULL);
340 1.18 christos UtEndEvent (Event);
341 1.18 christos
342 1.18 christos
343 1.1 jruoho /* Interpret and generate all compile-time constants */
344 1.1 jruoho
345 1.1 jruoho Event = UtBeginEvent ("Constant folding via AML interpreter");
346 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
347 1.9 christos "Interpreting compile-time constant expressions\n\n");
348 1.6 christos
349 1.15 christos if (AslGbl_FoldConstants)
350 1.6 christos {
351 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
352 1.9 christos NULL, OpcAmlConstantWalk, NULL);
353 1.6 christos }
354 1.6 christos else
355 1.6 christos {
356 1.6 christos DbgPrint (ASL_PARSE_OUTPUT, " Optional folding disabled\n");
357 1.6 christos }
358 1.1 jruoho UtEndEvent (Event);
359 1.1 jruoho
360 1.1 jruoho /* Update AML opcodes if necessary, after constant folding */
361 1.1 jruoho
362 1.1 jruoho Event = UtBeginEvent ("Updating AML opcodes after constant folding");
363 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
364 1.9 christos "Updating AML opcodes after constant folding\n\n");
365 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
366 1.1 jruoho NULL, OpcAmlOpcodeUpdateWalk, NULL);
367 1.1 jruoho UtEndEvent (Event);
368 1.1 jruoho
369 1.1 jruoho /* Calculate all AML package lengths */
370 1.1 jruoho
371 1.1 jruoho Event = UtBeginEvent ("Generate AML package lengths");
372 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
373 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
374 1.1 jruoho LnPackageLengthWalk, NULL);
375 1.1 jruoho UtEndEvent (Event);
376 1.1 jruoho
377 1.15 christos if (AslGbl_ParseOnlyFlag)
378 1.1 jruoho {
379 1.4 christos AePrintErrorLog (ASL_FILE_STDERR);
380 1.4 christos UtDisplaySummary (ASL_FILE_STDERR);
381 1.15 christos if (AslGbl_DebugFlag)
382 1.1 jruoho {
383 1.4 christos /* Print error summary to the stdout also */
384 1.1 jruoho
385 1.4 christos AePrintErrorLog (ASL_FILE_STDOUT);
386 1.4 christos UtDisplaySummary (ASL_FILE_STDOUT);
387 1.1 jruoho }
388 1.4 christos return (0);
389 1.1 jruoho }
390 1.1 jruoho
391 1.1 jruoho /*
392 1.1 jruoho * Create an internal namespace and use it as a symbol table
393 1.1 jruoho */
394 1.1 jruoho
395 1.1 jruoho /* Namespace loading */
396 1.1 jruoho
397 1.1 jruoho Event = UtBeginEvent ("Create ACPI Namespace");
398 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Creating ACPI Namespace\n\n");
399 1.15 christos Status = LdLoadNamespace (AslGbl_ParseTreeRoot);
400 1.1 jruoho UtEndEvent (Event);
401 1.1 jruoho if (ACPI_FAILURE (Status))
402 1.1 jruoho {
403 1.16 christos return (-1);
404 1.1 jruoho }
405 1.1 jruoho
406 1.1 jruoho /* Namespace cross-reference */
407 1.1 jruoho
408 1.8 christos AslGbl_NamespaceEvent = UtBeginEvent (
409 1.8 christos "Cross reference parse tree and Namespace");
410 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Cross referencing namespace\n\n");
411 1.4 christos Status = XfCrossReferenceNamespace ();
412 1.1 jruoho if (ACPI_FAILURE (Status))
413 1.1 jruoho {
414 1.16 christos return (-1);
415 1.1 jruoho }
416 1.1 jruoho
417 1.1 jruoho /* Namespace - Check for non-referenced objects */
418 1.1 jruoho
419 1.1 jruoho LkFindUnreferencedObjects ();
420 1.1 jruoho UtEndEvent (AslGbl_NamespaceEvent);
421 1.1 jruoho
422 1.9 christos /* Resolve External Declarations */
423 1.9 christos
424 1.15 christos Event = UtBeginEvent ("Resolve all Externals");
425 1.15 christos DbgPrint (ASL_DEBUG_OUTPUT, "\nResolve Externals\n\n");
426 1.15 christos
427 1.15 christos if (AslGbl_DoExternalsInPlace)
428 1.15 christos {
429 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
430 1.15 christos ExAmlExternalWalkBegin, NULL, NULL);
431 1.15 christos }
432 1.15 christos else
433 1.9 christos {
434 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
435 1.15 christos ExAmlExternalWalkBegin, ExAmlExternalWalkEnd, NULL);
436 1.9 christos }
437 1.15 christos UtEndEvent (Event);
438 1.9 christos
439 1.1 jruoho /*
440 1.4 christos * Semantic analysis. This can happen only after the
441 1.1 jruoho * namespace has been loaded and cross-referenced.
442 1.1 jruoho *
443 1.1 jruoho * part one - check control methods
444 1.1 jruoho */
445 1.1 jruoho Event = UtBeginEvent ("Analyze control method return types");
446 1.15 christos AslGbl_AnalysisWalkInfo.MethodStack = NULL;
447 1.1 jruoho
448 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method analysis\n\n");
449 1.9 christos
450 1.15 christos if (AslGbl_CrossReferenceOutput)
451 1.9 christos {
452 1.9 christos OtPrintHeaders ("Part 1: Object Reference Map "
453 1.9 christos "(Object references from within each control method)");
454 1.9 christos }
455 1.9 christos
456 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
457 1.4 christos MtMethodAnalysisWalkBegin,
458 1.15 christos MtMethodAnalysisWalkEnd, &AslGbl_AnalysisWalkInfo);
459 1.1 jruoho UtEndEvent (Event);
460 1.1 jruoho
461 1.9 christos /* Generate the object cross-reference file if requested */
462 1.9 christos
463 1.9 christos Event = UtBeginEvent ("Generate cross-reference file");
464 1.9 christos OtCreateXrefFile ();
465 1.9 christos UtEndEvent (Event);
466 1.9 christos
467 1.1 jruoho /* Semantic error checking part two - typing of method returns */
468 1.1 jruoho
469 1.1 jruoho Event = UtBeginEvent ("Determine object types returned by methods");
470 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - Method typing\n\n");
471 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
472 1.3 jruoho NULL, AnMethodTypingWalkEnd, NULL);
473 1.1 jruoho UtEndEvent (Event);
474 1.1 jruoho
475 1.1 jruoho /* Semantic error checking part three - operand type checking */
476 1.1 jruoho
477 1.1 jruoho Event = UtBeginEvent ("Analyze AML operand types");
478 1.8 christos DbgPrint (ASL_DEBUG_OUTPUT,
479 1.9 christos "Semantic analysis - Operand type checking\n\n");
480 1.15 christos if (AslGbl_DoTypechecking)
481 1.8 christos {
482 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD,
483 1.15 christos NULL, AnOperandTypecheckWalkEnd, &AslGbl_AnalysisWalkInfo);
484 1.8 christos }
485 1.1 jruoho UtEndEvent (Event);
486 1.1 jruoho
487 1.1 jruoho /* Semantic error checking part four - other miscellaneous checks */
488 1.1 jruoho
489 1.1 jruoho Event = UtBeginEvent ("Miscellaneous analysis");
490 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Semantic analysis - miscellaneous\n\n");
491 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
492 1.1 jruoho AnOtherSemanticAnalysisWalkBegin,
493 1.15 christos NULL, &AslGbl_AnalysisWalkInfo);
494 1.1 jruoho UtEndEvent (Event);
495 1.1 jruoho
496 1.11 christos /*
497 1.11 christos * ASL-/ASL+ converter: Gbl_ParseTreeRoot->CommentList contains the
498 1.11 christos * very last comment of a given ASL file because it's the last constructed
499 1.11 christos * node during compilation. We take the very last comment and save it in a
500 1.11 christos * global for it to be used by the disassembler.
501 1.11 christos */
502 1.14 christos if (AcpiGbl_CaptureComments)
503 1.11 christos {
504 1.15 christos AcpiGbl_LastListHead = AslGbl_ParseTreeRoot->Asl.CommentList;
505 1.15 christos AslGbl_ParseTreeRoot->Asl.CommentList = NULL;
506 1.11 christos }
507 1.11 christos
508 1.1 jruoho /* Calculate all AML package lengths */
509 1.1 jruoho
510 1.1 jruoho Event = UtBeginEvent ("Finish AML package length generation");
511 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Generating Package lengths\n\n");
512 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
513 1.1 jruoho LnInitLengthsWalk, NULL);
514 1.15 christos TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_UPWARD, NULL,
515 1.1 jruoho LnPackageLengthWalk, NULL);
516 1.1 jruoho UtEndEvent (Event);
517 1.1 jruoho
518 1.1 jruoho /* Code generation - emit the AML */
519 1.1 jruoho
520 1.1 jruoho Event = UtBeginEvent ("Generate AML code and write output files");
521 1.9 christos DbgPrint (ASL_DEBUG_OUTPUT, "Writing AML byte code\n\n");
522 1.16 christos
523 1.16 christos AslGbl_CurrentDB = AslGbl_ParseTreeRoot->Asl.Child;
524 1.16 christos
525 1.16 christos while (AslGbl_CurrentDB)
526 1.16 christos {
527 1.16 christos switch (FlSwitchFileSet(AslGbl_CurrentDB->Asl.Filename))
528 1.16 christos {
529 1.16 christos case SWITCH_TO_DIFFERENT_FILE:
530 1.16 christos /*
531 1.16 christos * Reset these parameters when definition blocks belong in
532 1.16 christos * different files. If they belong in the same file, there is
533 1.16 christos * no need to reset these parameters
534 1.16 christos */
535 1.16 christos FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
536 1.16 christos AslGbl_SourceLine = 0;
537 1.16 christos AslGbl_NextError = AslGbl_ErrorLog;
538 1.16 christos
539 1.16 christos /* fall-through */
540 1.16 christos
541 1.16 christos case SWITCH_TO_SAME_FILE:
542 1.16 christos
543 1.16 christos CgGenerateAmlOutput ();
544 1.16 christos CmDoOutputFiles ();
545 1.16 christos AslGbl_CurrentDB = AslGbl_CurrentDB->Asl.Next;
546 1.16 christos
547 1.16 christos break;
548 1.16 christos
549 1.16 christos default: /* FILE_NOT_FOUND */
550 1.16 christos
551 1.16 christos /* The requested file could not be found. Get out of here */
552 1.16 christos
553 1.16 christos AslGbl_CurrentDB = NULL;
554 1.16 christos break;
555 1.16 christos }
556 1.16 christos }
557 1.1 jruoho UtEndEvent (Event);
558 1.1 jruoho
559 1.1 jruoho Event = UtBeginEvent ("Write optional output files");
560 1.1 jruoho UtEndEvent (Event);
561 1.1 jruoho
562 1.4 christos return (0);
563 1.1 jruoho }
564 1.1 jruoho
565 1.1 jruoho
566 1.1 jruoho /*******************************************************************************
567 1.1 jruoho *
568 1.5 christos * FUNCTION: AslCompilerSignon
569 1.5 christos *
570 1.5 christos * PARAMETERS: FileId - ID of the output file
571 1.5 christos *
572 1.5 christos * RETURN: None
573 1.5 christos *
574 1.5 christos * DESCRIPTION: Display compiler signon
575 1.5 christos *
576 1.5 christos ******************************************************************************/
577 1.5 christos
578 1.5 christos void
579 1.5 christos AslCompilerSignon (
580 1.5 christos UINT32 FileId)
581 1.5 christos {
582 1.5 christos char *Prefix = "";
583 1.5 christos char *UtilityName;
584 1.5 christos
585 1.5 christos
586 1.5 christos /* Set line prefix depending on the destination file type */
587 1.5 christos
588 1.5 christos switch (FileId)
589 1.5 christos {
590 1.5 christos case ASL_FILE_ASM_SOURCE_OUTPUT:
591 1.5 christos case ASL_FILE_ASM_INCLUDE_OUTPUT:
592 1.5 christos
593 1.5 christos Prefix = "; ";
594 1.5 christos break;
595 1.5 christos
596 1.5 christos case ASL_FILE_HEX_OUTPUT:
597 1.5 christos
598 1.15 christos if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
599 1.5 christos {
600 1.5 christos Prefix = "; ";
601 1.5 christos }
602 1.15 christos else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
603 1.15 christos (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
604 1.5 christos {
605 1.5 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
606 1.5 christos Prefix = " * ";
607 1.5 christos }
608 1.5 christos break;
609 1.5 christos
610 1.5 christos case ASL_FILE_C_SOURCE_OUTPUT:
611 1.5 christos case ASL_FILE_C_OFFSET_OUTPUT:
612 1.5 christos case ASL_FILE_C_INCLUDE_OUTPUT:
613 1.5 christos
614 1.5 christos Prefix = " * ";
615 1.5 christos break;
616 1.5 christos
617 1.5 christos default:
618 1.5 christos
619 1.5 christos /* No other output types supported */
620 1.5 christos
621 1.5 christos break;
622 1.5 christos }
623 1.5 christos
624 1.5 christos /* Running compiler or disassembler? */
625 1.5 christos
626 1.12 christos if (AcpiGbl_DisasmFlag)
627 1.5 christos {
628 1.5 christos UtilityName = AML_DISASSEMBLER_NAME;
629 1.5 christos }
630 1.5 christos else
631 1.5 christos {
632 1.5 christos UtilityName = ASL_COMPILER_NAME;
633 1.5 christos }
634 1.5 christos
635 1.5 christos /* Compiler signon with copyright */
636 1.5 christos
637 1.5 christos FlPrintFile (FileId, "%s\n", Prefix);
638 1.5 christos FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
639 1.5 christos }
640 1.5 christos
641 1.5 christos
642 1.5 christos /*******************************************************************************
643 1.5 christos *
644 1.5 christos * FUNCTION: AslCompilerFileHeader
645 1.5 christos *
646 1.5 christos * PARAMETERS: FileId - ID of the output file
647 1.5 christos *
648 1.5 christos * RETURN: None
649 1.5 christos *
650 1.5 christos * DESCRIPTION: Header used at the beginning of output files
651 1.5 christos *
652 1.5 christos ******************************************************************************/
653 1.5 christos
654 1.5 christos void
655 1.5 christos AslCompilerFileHeader (
656 1.5 christos UINT32 FileId)
657 1.5 christos {
658 1.19 christos char *NewTime;
659 1.5 christos time_t Aclock;
660 1.5 christos char *Prefix = "";
661 1.5 christos
662 1.5 christos
663 1.5 christos /* Set line prefix depending on the destination file type */
664 1.5 christos
665 1.5 christos switch (FileId)
666 1.5 christos {
667 1.5 christos case ASL_FILE_ASM_SOURCE_OUTPUT:
668 1.5 christos case ASL_FILE_ASM_INCLUDE_OUTPUT:
669 1.5 christos
670 1.5 christos Prefix = "; ";
671 1.5 christos break;
672 1.5 christos
673 1.5 christos case ASL_FILE_HEX_OUTPUT:
674 1.5 christos
675 1.15 christos if (AslGbl_HexOutputFlag == HEX_OUTPUT_ASM)
676 1.5 christos {
677 1.5 christos Prefix = "; ";
678 1.5 christos }
679 1.15 christos else if ((AslGbl_HexOutputFlag == HEX_OUTPUT_C) ||
680 1.15 christos (AslGbl_HexOutputFlag == HEX_OUTPUT_ASL))
681 1.5 christos {
682 1.5 christos Prefix = " * ";
683 1.5 christos }
684 1.5 christos break;
685 1.5 christos
686 1.5 christos case ASL_FILE_C_SOURCE_OUTPUT:
687 1.5 christos case ASL_FILE_C_OFFSET_OUTPUT:
688 1.5 christos case ASL_FILE_C_INCLUDE_OUTPUT:
689 1.5 christos
690 1.5 christos Prefix = " * ";
691 1.5 christos break;
692 1.5 christos
693 1.5 christos default:
694 1.5 christos
695 1.5 christos /* No other output types supported */
696 1.5 christos
697 1.5 christos break;
698 1.5 christos }
699 1.5 christos
700 1.24 christos /* Compilation header (with timestamp) */
701 1.5 christos
702 1.5 christos FlPrintFile (FileId,
703 1.24 christos "%sCompilation of \"%s\"",
704 1.19 christos Prefix, AslGbl_Files[ASL_FILE_INPUT].Filename);
705 1.19 christos
706 1.24 christos if (!AslGbl_Deterministic)
707 1.24 christos {
708 1.24 christos Aclock = time (NULL);
709 1.24 christos NewTime = ctime (&Aclock);
710 1.24 christos if (NewTime)
711 1.24 christos {
712 1.24 christos FlPrintFile (FileId, " - %s%s\n", NewTime, Prefix);
713 1.24 christos }
714 1.24 christos }
715 1.24 christos else
716 1.19 christos {
717 1.24 christos FlPrintFile (FileId, "\n");
718 1.19 christos }
719 1.5 christos
720 1.5 christos switch (FileId)
721 1.5 christos {
722 1.5 christos case ASL_FILE_C_SOURCE_OUTPUT:
723 1.5 christos case ASL_FILE_C_OFFSET_OUTPUT:
724 1.5 christos case ASL_FILE_C_INCLUDE_OUTPUT:
725 1.5 christos
726 1.5 christos FlPrintFile (FileId, " */\n");
727 1.5 christos break;
728 1.5 christos
729 1.5 christos default:
730 1.5 christos
731 1.5 christos /* Nothing to do for other output types */
732 1.5 christos
733 1.5 christos break;
734 1.5 christos }
735 1.5 christos }
736 1.5 christos
737 1.5 christos
738 1.5 christos /*******************************************************************************
739 1.5 christos *
740 1.5 christos * FUNCTION: CmFlushSourceCode
741 1.5 christos *
742 1.5 christos * PARAMETERS: None
743 1.5 christos *
744 1.5 christos * RETURN: None
745 1.5 christos *
746 1.5 christos * DESCRIPTION: Read in any remaining source code after the parse tree
747 1.5 christos * has been constructed.
748 1.5 christos *
749 1.5 christos ******************************************************************************/
750 1.5 christos
751 1.5 christos static void
752 1.5 christos CmFlushSourceCode (
753 1.5 christos void)
754 1.5 christos {
755 1.5 christos char Buffer;
756 1.5 christos
757 1.5 christos
758 1.5 christos while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
759 1.5 christos {
760 1.5 christos AslInsertLineBuffer ((int) Buffer);
761 1.5 christos }
762 1.5 christos
763 1.5 christos AslResetCurrentLineBuffer ();
764 1.5 christos }
765 1.5 christos
766 1.5 christos
767 1.5 christos /*******************************************************************************
768 1.5 christos *
769 1.1 jruoho * FUNCTION: CmDoOutputFiles
770 1.1 jruoho *
771 1.1 jruoho * PARAMETERS: None
772 1.1 jruoho *
773 1.1 jruoho * RETURN: None.
774 1.1 jruoho *
775 1.1 jruoho * DESCRIPTION: Create all "listing" type files
776 1.1 jruoho *
777 1.1 jruoho ******************************************************************************/
778 1.1 jruoho
779 1.1 jruoho void
780 1.1 jruoho CmDoOutputFiles (
781 1.1 jruoho void)
782 1.1 jruoho {
783 1.1 jruoho
784 1.1 jruoho /* Create listings and hex files */
785 1.1 jruoho
786 1.1 jruoho LsDoListings ();
787 1.4 christos HxDoHexOutput ();
788 1.1 jruoho
789 1.1 jruoho /* Dump the namespace to the .nsp file if requested */
790 1.1 jruoho
791 1.4 christos (void) NsDisplayNamespace ();
792 1.5 christos
793 1.5 christos /* Dump the device mapping file */
794 1.5 christos
795 1.5 christos MpEmitMappingInfo ();
796 1.1 jruoho }
797 1.1 jruoho
798 1.1 jruoho
799 1.1 jruoho /*******************************************************************************
800 1.1 jruoho *
801 1.4 christos * FUNCTION: CmDumpAllEvents
802 1.1 jruoho *
803 1.4 christos * PARAMETERS: None
804 1.1 jruoho *
805 1.1 jruoho * RETURN: None.
806 1.1 jruoho *
807 1.4 christos * DESCRIPTION: Dump all compiler events
808 1.1 jruoho *
809 1.1 jruoho ******************************************************************************/
810 1.1 jruoho
811 1.1 jruoho static void
812 1.4 christos CmDumpAllEvents (
813 1.4 christos void)
814 1.1 jruoho {
815 1.4 christos ASL_EVENT_INFO *Event;
816 1.1 jruoho UINT32 Delta;
817 1.8 christos UINT32 MicroSeconds;
818 1.8 christos UINT32 MilliSeconds;
819 1.4 christos UINT32 i;
820 1.4 christos
821 1.1 jruoho
822 1.4 christos Event = AslGbl_Events;
823 1.4 christos
824 1.4 christos DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
825 1.15 christos if (AslGbl_CompileTimesFlag)
826 1.1 jruoho {
827 1.4 christos printf ("\nElapsed time for major events\n\n");
828 1.1 jruoho }
829 1.1 jruoho
830 1.4 christos for (i = 0; i < AslGbl_NextEvent; i++)
831 1.4 christos {
832 1.4 christos if (Event->Valid)
833 1.4 christos {
834 1.4 christos /* Delta will be in 100-nanosecond units */
835 1.1 jruoho
836 1.4 christos Delta = (UINT32) (Event->EndTime - Event->StartTime);
837 1.1 jruoho
838 1.8 christos MicroSeconds = Delta / ACPI_100NSEC_PER_USEC;
839 1.8 christos MilliSeconds = Delta / ACPI_100NSEC_PER_MSEC;
840 1.1 jruoho
841 1.4 christos /* Round milliseconds up */
842 1.1 jruoho
843 1.8 christos if ((MicroSeconds - (MilliSeconds * ACPI_USEC_PER_MSEC)) >= 500)
844 1.4 christos {
845 1.8 christos MilliSeconds++;
846 1.4 christos }
847 1.4 christos
848 1.4 christos DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
849 1.8 christos MicroSeconds, MilliSeconds, Event->EventName);
850 1.4 christos
851 1.15 christos if (AslGbl_CompileTimesFlag)
852 1.4 christos {
853 1.4 christos printf ("%8u usec %8u msec - %s\n",
854 1.8 christos MicroSeconds, MilliSeconds, Event->EventName);
855 1.4 christos }
856 1.4 christos }
857 1.4 christos
858 1.4 christos Event++;
859 1.1 jruoho }
860 1.1 jruoho }
861 1.1 jruoho
862 1.1 jruoho
863 1.1 jruoho /*******************************************************************************
864 1.1 jruoho *
865 1.1 jruoho * FUNCTION: CmCleanupAndExit
866 1.1 jruoho *
867 1.1 jruoho * PARAMETERS: None
868 1.1 jruoho *
869 1.1 jruoho * RETURN: None.
870 1.1 jruoho *
871 1.1 jruoho * DESCRIPTION: Close all open files and exit the compiler
872 1.1 jruoho *
873 1.1 jruoho ******************************************************************************/
874 1.1 jruoho
875 1.17 christos int
876 1.1 jruoho CmCleanupAndExit (
877 1.1 jruoho void)
878 1.1 jruoho {
879 1.17 christos int Status = 0;
880 1.4 christos BOOLEAN DeleteAmlFile = FALSE;
881 1.16 christos ASL_GLOBAL_FILE_NODE *CurrentFileNode = AslGbl_FilesList;
882 1.1 jruoho
883 1.1 jruoho
884 1.16 christos /* Check if any errors occurred during compile */
885 1.16 christos
886 1.16 christos (void) AslCheckForErrorExit ();
887 1.16 christos
888 1.4 christos AePrintErrorLog (ASL_FILE_STDERR);
889 1.15 christos if (AslGbl_DebugFlag)
890 1.1 jruoho {
891 1.4 christos /* Print error summary to stdout also */
892 1.1 jruoho
893 1.4 christos AePrintErrorLog (ASL_FILE_STDOUT);
894 1.1 jruoho }
895 1.1 jruoho
896 1.4 christos /* Emit compile times if enabled */
897 1.4 christos
898 1.4 christos CmDumpAllEvents ();
899 1.1 jruoho
900 1.15 christos if (AslGbl_CompileTimesFlag)
901 1.1 jruoho {
902 1.1 jruoho printf ("\nMiscellaneous compile statistics\n\n");
903 1.15 christos printf ("%11u : %s\n", AslGbl_TotalParseNodes, "Parse nodes");
904 1.15 christos printf ("%11u : %s\n", AslGbl_NsLookupCount, "Namespace searches");
905 1.15 christos printf ("%11u : %s\n", AslGbl_TotalNamedObjects, "Named objects");
906 1.15 christos printf ("%11u : %s\n", AslGbl_TotalMethods, "Control methods");
907 1.15 christos printf ("%11u : %s\n", AslGbl_TotalAllocations, "Memory Allocations");
908 1.15 christos printf ("%11u : %s\n", AslGbl_TotalAllocated, "Total allocated memory");
909 1.15 christos printf ("%11u : %s\n", AslGbl_TotalFolds, "Constant subtrees folded");
910 1.1 jruoho printf ("\n");
911 1.1 jruoho }
912 1.1 jruoho
913 1.15 christos if (AslGbl_NsLookupCount)
914 1.1 jruoho {
915 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
916 1.1 jruoho "\n\nMiscellaneous compile statistics\n\n");
917 1.1 jruoho
918 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
919 1.1 jruoho "%32s : %u\n", "Total Namespace searches",
920 1.15 christos AslGbl_NsLookupCount);
921 1.1 jruoho
922 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
923 1.1 jruoho "%32s : %u usec\n", "Time per search", ((UINT32)
924 1.1 jruoho (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
925 1.1 jruoho AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
926 1.15 christos AslGbl_NsLookupCount);
927 1.1 jruoho }
928 1.1 jruoho
929 1.15 christos if (AslGbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
930 1.1 jruoho {
931 1.21 christos printf ("\nMaximum error count (%d) exceeded (aslcompile.c)\n",
932 1.1 jruoho ASL_MAX_ERROR_COUNT);
933 1.1 jruoho }
934 1.1 jruoho
935 1.1 jruoho UtDisplaySummary (ASL_FILE_STDOUT);
936 1.1 jruoho
937 1.4 christos /*
938 1.17 christos * Delete the AML file if there are errors and the force AML output option
939 1.17 christos * (-f) has not been used.
940 1.17 christos *
941 1.17 christos * Return -1 as a status of the compiler if no AML files are generated. If
942 1.17 christos * the AML file is generated in the presence of errors, return 0. In the
943 1.17 christos * latter case, the errors were ignored by the user so the compilation is
944 1.17 christos * considered successful.
945 1.4 christos */
946 1.17 christos if (AslGbl_ParserErrorDetected || AslGbl_PreprocessOnly ||
947 1.17 christos ((AslGbl_ExceptionCount[ASL_ERROR] > 0) &&
948 1.15 christos (!AslGbl_IgnoreErrors) &&
949 1.16 christos AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle))
950 1.4 christos {
951 1.4 christos DeleteAmlFile = TRUE;
952 1.17 christos Status = -1;
953 1.4 christos }
954 1.4 christos
955 1.1 jruoho /* Close all open files */
956 1.1 jruoho
957 1.16 christos while (CurrentFileNode)
958 1.16 christos {
959 1.17 christos /*
960 1.17 christos * Set the program return status based on file errors. If there are any
961 1.17 christos * errors and during compilation, the command is not considered
962 1.17 christos * successful.
963 1.17 christos */
964 1.17 christos if (Status != -1 && !AslGbl_IgnoreErrors &&
965 1.17 christos CurrentFileNode->ParserErrorDetected)
966 1.17 christos {
967 1.17 christos Status = -1;
968 1.17 christos }
969 1.17 christos
970 1.16 christos switch (FlSwitchFileSet (CurrentFileNode->Files[ASL_FILE_INPUT].Filename))
971 1.16 christos {
972 1.16 christos case SWITCH_TO_SAME_FILE:
973 1.16 christos case SWITCH_TO_DIFFERENT_FILE:
974 1.16 christos
975 1.16 christos CmFinishFiles (DeleteAmlFile);
976 1.16 christos CurrentFileNode = CurrentFileNode->Next;
977 1.16 christos break;
978 1.16 christos
979 1.16 christos case FILE_NOT_FOUND:
980 1.16 christos default:
981 1.16 christos
982 1.16 christos CurrentFileNode = NULL;
983 1.16 christos break;
984 1.16 christos }
985 1.16 christos }
986 1.16 christos
987 1.16 christos /* Final cleanup after compiling one file */
988 1.16 christos
989 1.16 christos if (!AslGbl_DoAslConversion)
990 1.16 christos {
991 1.16 christos UtDeleteLocalCaches ();
992 1.16 christos }
993 1.17 christos
994 1.17 christos return (Status);
995 1.16 christos }
996 1.16 christos
997 1.16 christos
998 1.16 christos /*******************************************************************************
999 1.16 christos *
1000 1.16 christos * FUNCTION: CmFinishFiles
1001 1.16 christos *
1002 1.16 christos * PARAMETERS: DeleteAmlFile
1003 1.16 christos *
1004 1.16 christos * RETURN: None.
1005 1.16 christos *
1006 1.16 christos * DESCRIPTION: Close all open files, delete AML files depending on the
1007 1.16 christos * function parameter is true.
1008 1.16 christos *
1009 1.16 christos ******************************************************************************/
1010 1.16 christos
1011 1.16 christos static void
1012 1.16 christos CmFinishFiles(
1013 1.16 christos BOOLEAN DeleteAmlFile)
1014 1.16 christos {
1015 1.16 christos UINT32 i;
1016 1.16 christos
1017 1.16 christos
1018 1.4 christos /*
1019 1.7 christos * Take care with the preprocessor file (.pre), it might be the same
1020 1.4 christos * as the "input" file, depending on where the compiler has terminated
1021 1.4 christos * or aborted. Prevent attempt to close the same file twice in
1022 1.4 christos * loop below.
1023 1.4 christos */
1024 1.15 christos if (AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle ==
1025 1.15 christos AslGbl_Files[ASL_FILE_INPUT].Handle)
1026 1.4 christos {
1027 1.15 christos AslGbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL;
1028 1.4 christos }
1029 1.4 christos
1030 1.4 christos /* Close the standard I/O files */
1031 1.4 christos
1032 1.4 christos for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++)
1033 1.1 jruoho {
1034 1.16 christos /*
1035 1.16 christos * Some files such as debug output files could be pointing to
1036 1.16 christos * stderr or stdout. Leave these alone.
1037 1.16 christos */
1038 1.16 christos if (AslGbl_Files[i].Handle != stderr &&
1039 1.16 christos AslGbl_Files[i].Handle != stdout)
1040 1.16 christos {
1041 1.16 christos FlCloseFile (i);
1042 1.16 christos }
1043 1.1 jruoho }
1044 1.1 jruoho
1045 1.1 jruoho /* Delete AML file if there are errors */
1046 1.1 jruoho
1047 1.4 christos if (DeleteAmlFile)
1048 1.4 christos {
1049 1.4 christos FlDeleteFile (ASL_FILE_AML_OUTPUT);
1050 1.4 christos }
1051 1.4 christos
1052 1.7 christos /* Delete the preprocessor temp file unless full debug was specified */
1053 1.4 christos
1054 1.15 christos if (AslGbl_PreprocessFlag && !AslGbl_KeepPreprocessorTempFile)
1055 1.1 jruoho {
1056 1.4 christos FlDeleteFile (ASL_FILE_PREPROCESSOR);
1057 1.1 jruoho }
1058 1.1 jruoho
1059 1.1 jruoho /*
1060 1.1 jruoho * Delete intermediate ("combined") source file (if -ls flag not set)
1061 1.3 jruoho * This file is created during normal ASL/AML compiles. It is not
1062 1.3 jruoho * created by the data table compiler.
1063 1.3 jruoho *
1064 1.3 jruoho * If the -ls flag is set, then the .SRC file should not be deleted.
1065 1.3 jruoho * In this case, Gbl_SourceOutputFlag is set to TRUE.
1066 1.3 jruoho *
1067 1.3 jruoho * Note: Handles are cleared by FlCloseFile above, so we look at the
1068 1.3 jruoho * filename instead, to determine if the .SRC file was actually
1069 1.3 jruoho * created.
1070 1.1 jruoho */
1071 1.15 christos if (!AslGbl_SourceOutputFlag)
1072 1.1 jruoho {
1073 1.4 christos FlDeleteFile (ASL_FILE_SOURCE_OUTPUT);
1074 1.1 jruoho }
1075 1.5 christos }
1076