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