aslcompile.c revision 1.3.4.2 1 1.3.4.2 rmind
2 1.3.4.2 rmind /******************************************************************************
3 1.3.4.2 rmind *
4 1.3.4.2 rmind * Module Name: aslcompile - top level compile module
5 1.3.4.2 rmind *
6 1.3.4.2 rmind *****************************************************************************/
7 1.3.4.2 rmind
8 1.3.4.2 rmind /*
9 1.3.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
10 1.3.4.2 rmind * All rights reserved.
11 1.3.4.2 rmind *
12 1.3.4.2 rmind * Redistribution and use in source and binary forms, with or without
13 1.3.4.2 rmind * modification, are permitted provided that the following conditions
14 1.3.4.2 rmind * are met:
15 1.3.4.2 rmind * 1. Redistributions of source code must retain the above copyright
16 1.3.4.2 rmind * notice, this list of conditions, and the following disclaimer,
17 1.3.4.2 rmind * without modification.
18 1.3.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.3.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
20 1.3.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
21 1.3.4.2 rmind * including a substantially similar Disclaimer requirement for further
22 1.3.4.2 rmind * binary redistribution.
23 1.3.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
24 1.3.4.2 rmind * of any contributors may be used to endorse or promote products derived
25 1.3.4.2 rmind * from this software without specific prior written permission.
26 1.3.4.2 rmind *
27 1.3.4.2 rmind * Alternatively, this software may be distributed under the terms of the
28 1.3.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
29 1.3.4.2 rmind * Software Foundation.
30 1.3.4.2 rmind *
31 1.3.4.2 rmind * NO WARRANTY
32 1.3.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.3.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.3.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.3.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.3.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.3.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.3.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.3.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.3.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.3.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.3.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
43 1.3.4.2 rmind */
44 1.3.4.2 rmind
45 1.3.4.2 rmind #include "aslcompiler.h"
46 1.3.4.2 rmind
47 1.3.4.2 rmind #include <stdio.h>
48 1.3.4.2 rmind #include <time.h>
49 1.3.4.2 rmind #include <acapps.h>
50 1.3.4.2 rmind
51 1.3.4.2 rmind #define _COMPONENT ACPI_COMPILER
52 1.3.4.2 rmind ACPI_MODULE_NAME ("aslcompile")
53 1.3.4.2 rmind
54 1.3.4.2 rmind /* Local prototypes */
55 1.3.4.2 rmind
56 1.3.4.2 rmind static void
57 1.3.4.2 rmind CmFlushSourceCode (
58 1.3.4.2 rmind void);
59 1.3.4.2 rmind
60 1.3.4.2 rmind static void
61 1.3.4.2 rmind FlConsumeAnsiComment (
62 1.3.4.2 rmind ASL_FILE_INFO *FileInfo,
63 1.3.4.2 rmind ASL_FILE_STATUS *Status);
64 1.3.4.2 rmind
65 1.3.4.2 rmind static void
66 1.3.4.2 rmind FlConsumeNewComment (
67 1.3.4.2 rmind ASL_FILE_INFO *FileInfo,
68 1.3.4.2 rmind ASL_FILE_STATUS *Status);
69 1.3.4.2 rmind
70 1.3.4.2 rmind
71 1.3.4.2 rmind /*******************************************************************************
72 1.3.4.2 rmind *
73 1.3.4.2 rmind * FUNCTION: AslCompilerSignon
74 1.3.4.2 rmind *
75 1.3.4.2 rmind * PARAMETERS: FileId - ID of the output file
76 1.3.4.2 rmind *
77 1.3.4.2 rmind * RETURN: None
78 1.3.4.2 rmind *
79 1.3.4.2 rmind * DESCRIPTION: Display compiler signon
80 1.3.4.2 rmind *
81 1.3.4.2 rmind ******************************************************************************/
82 1.3.4.2 rmind
83 1.3.4.2 rmind void
84 1.3.4.2 rmind AslCompilerSignon (
85 1.3.4.2 rmind UINT32 FileId)
86 1.3.4.2 rmind {
87 1.3.4.2 rmind char *Prefix = "";
88 1.3.4.2 rmind char *UtilityName;
89 1.3.4.2 rmind
90 1.3.4.2 rmind
91 1.3.4.2 rmind /* Set line prefix depending on the destination file type */
92 1.3.4.2 rmind
93 1.3.4.2 rmind switch (FileId)
94 1.3.4.2 rmind {
95 1.3.4.2 rmind case ASL_FILE_ASM_SOURCE_OUTPUT:
96 1.3.4.2 rmind case ASL_FILE_ASM_INCLUDE_OUTPUT:
97 1.3.4.2 rmind
98 1.3.4.2 rmind Prefix = "; ";
99 1.3.4.2 rmind break;
100 1.3.4.2 rmind
101 1.3.4.2 rmind case ASL_FILE_HEX_OUTPUT:
102 1.3.4.2 rmind
103 1.3.4.2 rmind if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
104 1.3.4.2 rmind {
105 1.3.4.2 rmind Prefix = "; ";
106 1.3.4.2 rmind }
107 1.3.4.2 rmind else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
108 1.3.4.2 rmind (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
109 1.3.4.2 rmind {
110 1.3.4.2 rmind FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
111 1.3.4.2 rmind Prefix = " * ";
112 1.3.4.2 rmind }
113 1.3.4.2 rmind break;
114 1.3.4.2 rmind
115 1.3.4.2 rmind case ASL_FILE_C_SOURCE_OUTPUT:
116 1.3.4.2 rmind case ASL_FILE_C_INCLUDE_OUTPUT:
117 1.3.4.2 rmind
118 1.3.4.2 rmind Prefix = " * ";
119 1.3.4.2 rmind break;
120 1.3.4.2 rmind
121 1.3.4.2 rmind default:
122 1.3.4.2 rmind /* No other output types supported */
123 1.3.4.2 rmind break;
124 1.3.4.2 rmind }
125 1.3.4.2 rmind
126 1.3.4.2 rmind /* Running compiler or disassembler? */
127 1.3.4.2 rmind
128 1.3.4.2 rmind if (Gbl_DisasmFlag)
129 1.3.4.2 rmind {
130 1.3.4.2 rmind UtilityName = AML_DISASSEMBLER_NAME;
131 1.3.4.2 rmind }
132 1.3.4.2 rmind else
133 1.3.4.2 rmind {
134 1.3.4.2 rmind UtilityName = ASL_COMPILER_NAME;
135 1.3.4.2 rmind }
136 1.3.4.2 rmind
137 1.3.4.2 rmind /* Compiler signon with copyright */
138 1.3.4.2 rmind
139 1.3.4.2 rmind FlPrintFile (FileId, "%s\n", Prefix);
140 1.3.4.2 rmind FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix));
141 1.3.4.2 rmind }
142 1.3.4.2 rmind
143 1.3.4.2 rmind
144 1.3.4.2 rmind /*******************************************************************************
145 1.3.4.2 rmind *
146 1.3.4.2 rmind * FUNCTION: AslCompilerFileHeader
147 1.3.4.2 rmind *
148 1.3.4.2 rmind * PARAMETERS: FileId - ID of the output file
149 1.3.4.2 rmind *
150 1.3.4.2 rmind * RETURN: None
151 1.3.4.2 rmind *
152 1.3.4.2 rmind * DESCRIPTION: Header used at the beginning of output files
153 1.3.4.2 rmind *
154 1.3.4.2 rmind ******************************************************************************/
155 1.3.4.2 rmind
156 1.3.4.2 rmind void
157 1.3.4.2 rmind AslCompilerFileHeader (
158 1.3.4.2 rmind UINT32 FileId)
159 1.3.4.2 rmind {
160 1.3.4.2 rmind struct tm *NewTime;
161 1.3.4.2 rmind time_t Aclock;
162 1.3.4.2 rmind char *Prefix = "";
163 1.3.4.2 rmind
164 1.3.4.2 rmind
165 1.3.4.2 rmind /* Set line prefix depending on the destination file type */
166 1.3.4.2 rmind
167 1.3.4.2 rmind switch (FileId)
168 1.3.4.2 rmind {
169 1.3.4.2 rmind case ASL_FILE_ASM_SOURCE_OUTPUT:
170 1.3.4.2 rmind case ASL_FILE_ASM_INCLUDE_OUTPUT:
171 1.3.4.2 rmind
172 1.3.4.2 rmind Prefix = "; ";
173 1.3.4.2 rmind break;
174 1.3.4.2 rmind
175 1.3.4.2 rmind case ASL_FILE_HEX_OUTPUT:
176 1.3.4.2 rmind
177 1.3.4.2 rmind if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
178 1.3.4.2 rmind {
179 1.3.4.2 rmind Prefix = "; ";
180 1.3.4.2 rmind }
181 1.3.4.2 rmind else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
182 1.3.4.2 rmind (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
183 1.3.4.2 rmind {
184 1.3.4.2 rmind Prefix = " * ";
185 1.3.4.2 rmind }
186 1.3.4.2 rmind break;
187 1.3.4.2 rmind
188 1.3.4.2 rmind case ASL_FILE_C_SOURCE_OUTPUT:
189 1.3.4.2 rmind case ASL_FILE_C_INCLUDE_OUTPUT:
190 1.3.4.2 rmind
191 1.3.4.2 rmind Prefix = " * ";
192 1.3.4.2 rmind break;
193 1.3.4.2 rmind
194 1.3.4.2 rmind default:
195 1.3.4.2 rmind /* No other output types supported */
196 1.3.4.2 rmind break;
197 1.3.4.2 rmind }
198 1.3.4.2 rmind
199 1.3.4.2 rmind /* Compilation header with timestamp */
200 1.3.4.2 rmind
201 1.3.4.2 rmind (void) time (&Aclock);
202 1.3.4.2 rmind NewTime = localtime (&Aclock);
203 1.3.4.2 rmind
204 1.3.4.2 rmind FlPrintFile (FileId,
205 1.3.4.2 rmind "%sCompilation of \"%s\" - %s%s\n",
206 1.3.4.2 rmind Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
207 1.3.4.2 rmind Prefix);
208 1.3.4.2 rmind
209 1.3.4.2 rmind switch (FileId)
210 1.3.4.2 rmind {
211 1.3.4.2 rmind case ASL_FILE_C_SOURCE_OUTPUT:
212 1.3.4.2 rmind case ASL_FILE_C_INCLUDE_OUTPUT:
213 1.3.4.2 rmind FlPrintFile (FileId, " */\n");
214 1.3.4.2 rmind break;
215 1.3.4.2 rmind
216 1.3.4.2 rmind default:
217 1.3.4.2 rmind /* Nothing to do for other output types */
218 1.3.4.2 rmind break;
219 1.3.4.2 rmind }
220 1.3.4.2 rmind }
221 1.3.4.2 rmind
222 1.3.4.2 rmind
223 1.3.4.2 rmind /*******************************************************************************
224 1.3.4.2 rmind *
225 1.3.4.2 rmind * FUNCTION: CmFlushSourceCode
226 1.3.4.2 rmind *
227 1.3.4.2 rmind * PARAMETERS: None
228 1.3.4.2 rmind *
229 1.3.4.2 rmind * RETURN: None
230 1.3.4.2 rmind *
231 1.3.4.2 rmind * DESCRIPTION: Read in any remaining source code after the parse tree
232 1.3.4.2 rmind * has been constructed.
233 1.3.4.2 rmind *
234 1.3.4.2 rmind ******************************************************************************/
235 1.3.4.2 rmind
236 1.3.4.2 rmind static void
237 1.3.4.2 rmind CmFlushSourceCode (
238 1.3.4.2 rmind void)
239 1.3.4.2 rmind {
240 1.3.4.2 rmind char Buffer;
241 1.3.4.2 rmind
242 1.3.4.2 rmind
243 1.3.4.2 rmind while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
244 1.3.4.2 rmind {
245 1.3.4.2 rmind InsertLineBuffer ((int) Buffer);
246 1.3.4.2 rmind }
247 1.3.4.2 rmind
248 1.3.4.2 rmind ResetCurrentLineBuffer ();
249 1.3.4.2 rmind }
250 1.3.4.2 rmind
251 1.3.4.2 rmind
252 1.3.4.2 rmind /*******************************************************************************
253 1.3.4.2 rmind *
254 1.3.4.2 rmind * FUNCTION: FlConsume*
255 1.3.4.2 rmind *
256 1.3.4.2 rmind * PARAMETERS: FileInfo - Points to an open input file
257 1.3.4.2 rmind *
258 1.3.4.2 rmind * RETURN: Number of lines consumed
259 1.3.4.2 rmind *
260 1.3.4.2 rmind * DESCRIPTION: Step over both types of comment during check for ascii chars
261 1.3.4.2 rmind *
262 1.3.4.2 rmind ******************************************************************************/
263 1.3.4.2 rmind
264 1.3.4.2 rmind static void
265 1.3.4.2 rmind FlConsumeAnsiComment (
266 1.3.4.2 rmind ASL_FILE_INFO *FileInfo,
267 1.3.4.2 rmind ASL_FILE_STATUS *Status)
268 1.3.4.2 rmind {
269 1.3.4.2 rmind UINT8 Byte;
270 1.3.4.2 rmind BOOLEAN ClosingComment = FALSE;
271 1.3.4.2 rmind
272 1.3.4.2 rmind
273 1.3.4.2 rmind while (fread (&Byte, 1, 1, FileInfo->Handle))
274 1.3.4.2 rmind {
275 1.3.4.2 rmind /* Scan until comment close is found */
276 1.3.4.2 rmind
277 1.3.4.2 rmind if (ClosingComment)
278 1.3.4.2 rmind {
279 1.3.4.2 rmind if (Byte == '/')
280 1.3.4.2 rmind {
281 1.3.4.2 rmind return;
282 1.3.4.2 rmind }
283 1.3.4.2 rmind
284 1.3.4.2 rmind if (Byte != '*')
285 1.3.4.2 rmind {
286 1.3.4.2 rmind /* Reset */
287 1.3.4.2 rmind
288 1.3.4.2 rmind ClosingComment = FALSE;
289 1.3.4.2 rmind }
290 1.3.4.2 rmind }
291 1.3.4.2 rmind else if (Byte == '*')
292 1.3.4.2 rmind {
293 1.3.4.2 rmind ClosingComment = TRUE;
294 1.3.4.2 rmind }
295 1.3.4.2 rmind
296 1.3.4.2 rmind /* Maintain line count */
297 1.3.4.2 rmind
298 1.3.4.2 rmind if (Byte == 0x0A)
299 1.3.4.2 rmind {
300 1.3.4.2 rmind Status->Line++;
301 1.3.4.2 rmind }
302 1.3.4.2 rmind
303 1.3.4.2 rmind Status->Offset++;
304 1.3.4.2 rmind }
305 1.3.4.2 rmind }
306 1.3.4.2 rmind
307 1.3.4.2 rmind
308 1.3.4.2 rmind static void
309 1.3.4.2 rmind FlConsumeNewComment (
310 1.3.4.2 rmind ASL_FILE_INFO *FileInfo,
311 1.3.4.2 rmind ASL_FILE_STATUS *Status)
312 1.3.4.2 rmind {
313 1.3.4.2 rmind UINT8 Byte;
314 1.3.4.2 rmind
315 1.3.4.2 rmind
316 1.3.4.2 rmind while (fread (&Byte, 1, 1, FileInfo->Handle))
317 1.3.4.2 rmind {
318 1.3.4.2 rmind Status->Offset++;
319 1.3.4.2 rmind
320 1.3.4.2 rmind /* Comment ends at newline */
321 1.3.4.2 rmind
322 1.3.4.2 rmind if (Byte == 0x0A)
323 1.3.4.2 rmind {
324 1.3.4.2 rmind Status->Line++;
325 1.3.4.2 rmind return;
326 1.3.4.2 rmind }
327 1.3.4.2 rmind }
328 1.3.4.2 rmind }
329 1.3.4.2 rmind
330 1.3.4.2 rmind
331 1.3.4.2 rmind /*******************************************************************************
332 1.3.4.2 rmind *
333 1.3.4.2 rmind * FUNCTION: FlCheckForAscii
334 1.3.4.2 rmind *
335 1.3.4.2 rmind * PARAMETERS: FileInfo - Points to an open input file
336 1.3.4.2 rmind *
337 1.3.4.2 rmind * RETURN: Status
338 1.3.4.2 rmind *
339 1.3.4.2 rmind * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters
340 1.3.4.2 rmind * within comments. Note: does not handle nested comments and does
341 1.3.4.2 rmind * not handle comment delimiters within string literals. However,
342 1.3.4.2 rmind * on the rare chance this happens and an invalid character is
343 1.3.4.2 rmind * missed, the parser will catch the error by failing in some
344 1.3.4.2 rmind * spectactular manner.
345 1.3.4.2 rmind *
346 1.3.4.2 rmind ******************************************************************************/
347 1.3.4.2 rmind
348 1.3.4.2 rmind ACPI_STATUS
349 1.3.4.2 rmind FlCheckForAscii (
350 1.3.4.2 rmind ASL_FILE_INFO *FileInfo)
351 1.3.4.2 rmind {
352 1.3.4.2 rmind UINT8 Byte;
353 1.3.4.2 rmind ACPI_SIZE BadBytes = 0;
354 1.3.4.2 rmind BOOLEAN OpeningComment = FALSE;
355 1.3.4.2 rmind ASL_FILE_STATUS Status;
356 1.3.4.2 rmind
357 1.3.4.2 rmind
358 1.3.4.2 rmind Status.Line = 1;
359 1.3.4.2 rmind Status.Offset = 0;
360 1.3.4.2 rmind
361 1.3.4.2 rmind /* Read the entire file */
362 1.3.4.2 rmind
363 1.3.4.2 rmind while (fread (&Byte, 1, 1, FileInfo->Handle))
364 1.3.4.2 rmind {
365 1.3.4.2 rmind /* Ignore comment fields (allow non-ascii within) */
366 1.3.4.2 rmind
367 1.3.4.2 rmind if (OpeningComment)
368 1.3.4.2 rmind {
369 1.3.4.2 rmind /* Check for second comment open delimiter */
370 1.3.4.2 rmind
371 1.3.4.2 rmind if (Byte == '*')
372 1.3.4.2 rmind {
373 1.3.4.2 rmind FlConsumeAnsiComment (FileInfo, &Status);
374 1.3.4.2 rmind }
375 1.3.4.2 rmind
376 1.3.4.2 rmind if (Byte == '/')
377 1.3.4.2 rmind {
378 1.3.4.2 rmind FlConsumeNewComment (FileInfo, &Status);
379 1.3.4.2 rmind }
380 1.3.4.2 rmind
381 1.3.4.2 rmind /* Reset */
382 1.3.4.2 rmind
383 1.3.4.2 rmind OpeningComment = FALSE;
384 1.3.4.2 rmind }
385 1.3.4.2 rmind else if (Byte == '/')
386 1.3.4.2 rmind {
387 1.3.4.2 rmind OpeningComment = TRUE;
388 1.3.4.2 rmind }
389 1.3.4.2 rmind
390 1.3.4.2 rmind /* Check for an ASCII character */
391 1.3.4.2 rmind
392 1.3.4.2 rmind if (!ACPI_IS_ASCII (Byte))
393 1.3.4.2 rmind {
394 1.3.4.2 rmind if (BadBytes < 10)
395 1.3.4.2 rmind {
396 1.3.4.2 rmind AcpiOsPrintf (
397 1.3.4.2 rmind "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
398 1.3.4.2 rmind Byte, Status.Line, Status.Offset);
399 1.3.4.2 rmind }
400 1.3.4.2 rmind
401 1.3.4.2 rmind BadBytes++;
402 1.3.4.2 rmind }
403 1.3.4.2 rmind
404 1.3.4.2 rmind /* Update line counter */
405 1.3.4.2 rmind
406 1.3.4.2 rmind else if (Byte == 0x0A)
407 1.3.4.2 rmind {
408 1.3.4.2 rmind Status.Line++;
409 1.3.4.2 rmind }
410 1.3.4.2 rmind
411 1.3.4.2 rmind Status.Offset++;
412 1.3.4.2 rmind }
413 1.3.4.2 rmind
414 1.3.4.2 rmind /* Seek back to the beginning of the source file */
415 1.3.4.2 rmind
416 1.3.4.2 rmind fseek (FileInfo->Handle, 0, SEEK_SET);
417 1.3.4.2 rmind
418 1.3.4.2 rmind /* Were there any non-ASCII characters in the file? */
419 1.3.4.2 rmind
420 1.3.4.2 rmind if (BadBytes)
421 1.3.4.2 rmind {
422 1.3.4.2 rmind AcpiOsPrintf (
423 1.3.4.2 rmind "%u non-ASCII characters found in input source text, could be a binary file\n",
424 1.3.4.2 rmind BadBytes);
425 1.3.4.2 rmind AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename);
426 1.3.4.2 rmind return (AE_BAD_CHARACTER);
427 1.3.4.2 rmind }
428 1.3.4.2 rmind
429 1.3.4.2 rmind /* File is OK */
430 1.3.4.2 rmind
431 1.3.4.2 rmind return (AE_OK);
432 1.3.4.2 rmind }
433 1.3.4.2 rmind
434 1.3.4.2 rmind
435 1.3.4.2 rmind /*******************************************************************************
436 1.3.4.2 rmind *
437 1.3.4.2 rmind * FUNCTION: CmDoCompile
438 1.3.4.2 rmind *
439 1.3.4.2 rmind * PARAMETERS: None
440 1.3.4.2 rmind *
441 1.3.4.2 rmind * RETURN: Status (0 = OK)
442 1.3.4.2 rmind *
443 1.3.4.2 rmind * DESCRIPTION: This procedure performs the entire compile
444 1.3.4.2 rmind *
445 1.3.4.2 rmind ******************************************************************************/
446 1.3.4.2 rmind
447 1.3.4.2 rmind int
448 1.3.4.2 rmind CmDoCompile (
449 1.3.4.2 rmind void)
450 1.3.4.2 rmind {
451 1.3.4.2 rmind ACPI_STATUS Status;
452 1.3.4.2 rmind UINT8 FullCompile;
453 1.3.4.2 rmind UINT8 Event;
454 1.3.4.2 rmind
455 1.3.4.2 rmind
456 1.3.4.2 rmind FullCompile = UtBeginEvent ("*** Total Compile time ***");
457 1.3.4.2 rmind Event = UtBeginEvent ("Open input and output files");
458 1.3.4.2 rmind UtEndEvent (Event);
459 1.3.4.2 rmind
460 1.3.4.2 rmind /* Build the parse tree */
461 1.3.4.2 rmind
462 1.3.4.2 rmind Event = UtBeginEvent ("Parse source code and build parse tree");
463 1.3.4.2 rmind AslCompilerparse();
464 1.3.4.2 rmind UtEndEvent (Event);
465 1.3.4.2 rmind
466 1.3.4.2 rmind /* Flush out any remaining source after parse tree is complete */
467 1.3.4.2 rmind
468 1.3.4.2 rmind Event = UtBeginEvent ("Flush source input");
469 1.3.4.2 rmind CmFlushSourceCode ();
470 1.3.4.2 rmind
471 1.3.4.2 rmind /* Did the parse tree get successfully constructed? */
472 1.3.4.2 rmind
473 1.3.4.2 rmind if (!RootNode)
474 1.3.4.2 rmind {
475 1.3.4.2 rmind CmCleanupAndExit ();
476 1.3.4.2 rmind return -1;
477 1.3.4.2 rmind }
478 1.3.4.2 rmind
479 1.3.4.2 rmind /* Optional parse tree dump, compiler debug output only */
480 1.3.4.2 rmind
481 1.3.4.2 rmind LsDumpParseTree ();
482 1.3.4.2 rmind
483 1.3.4.2 rmind OpcGetIntegerWidth (RootNode);
484 1.3.4.2 rmind UtEndEvent (Event);
485 1.3.4.2 rmind
486 1.3.4.2 rmind /* Pre-process parse tree for any operator transforms */
487 1.3.4.2 rmind
488 1.3.4.2 rmind Event = UtBeginEvent ("Parse tree transforms");
489 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
490 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
491 1.3.4.2 rmind TrAmlTransformWalk, NULL, NULL);
492 1.3.4.2 rmind UtEndEvent (Event);
493 1.3.4.2 rmind
494 1.3.4.2 rmind /* Generate AML opcodes corresponding to the parse tokens */
495 1.3.4.2 rmind
496 1.3.4.2 rmind Event = UtBeginEvent ("Generate AML opcodes");
497 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n");
498 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
499 1.3.4.2 rmind OpcAmlOpcodeWalk, NULL);
500 1.3.4.2 rmind UtEndEvent (Event);
501 1.3.4.2 rmind
502 1.3.4.2 rmind /*
503 1.3.4.2 rmind * Now that the input is parsed, we can open the AML output file.
504 1.3.4.2 rmind * Note: by default, the name of this file comes from the table descriptor
505 1.3.4.2 rmind * within the input file.
506 1.3.4.2 rmind */
507 1.3.4.2 rmind Event = UtBeginEvent ("Open AML output file");
508 1.3.4.2 rmind Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
509 1.3.4.2 rmind if (ACPI_FAILURE (Status))
510 1.3.4.2 rmind {
511 1.3.4.2 rmind AePrintErrorLog (ASL_FILE_STDERR);
512 1.3.4.2 rmind return -1;
513 1.3.4.2 rmind }
514 1.3.4.2 rmind UtEndEvent (Event);
515 1.3.4.2 rmind
516 1.3.4.2 rmind /* Interpret and generate all compile-time constants */
517 1.3.4.2 rmind
518 1.3.4.2 rmind Event = UtBeginEvent ("Constant folding via AML interpreter");
519 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT,
520 1.3.4.2 rmind "\nInterpreting compile-time constant expressions\n\n");
521 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
522 1.3.4.2 rmind OpcAmlConstantWalk, NULL, NULL);
523 1.3.4.2 rmind UtEndEvent (Event);
524 1.3.4.2 rmind
525 1.3.4.2 rmind /* Update AML opcodes if necessary, after constant folding */
526 1.3.4.2 rmind
527 1.3.4.2 rmind Event = UtBeginEvent ("Updating AML opcodes after constant folding");
528 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT,
529 1.3.4.2 rmind "\nUpdating AML opcodes after constant folding\n\n");
530 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
531 1.3.4.2 rmind NULL, OpcAmlOpcodeUpdateWalk, NULL);
532 1.3.4.2 rmind UtEndEvent (Event);
533 1.3.4.2 rmind
534 1.3.4.2 rmind /* Calculate all AML package lengths */
535 1.3.4.2 rmind
536 1.3.4.2 rmind Event = UtBeginEvent ("Generate AML package lengths");
537 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
538 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
539 1.3.4.2 rmind LnPackageLengthWalk, NULL);
540 1.3.4.2 rmind UtEndEvent (Event);
541 1.3.4.2 rmind
542 1.3.4.2 rmind if (Gbl_ParseOnlyFlag)
543 1.3.4.2 rmind {
544 1.3.4.2 rmind AePrintErrorLog (ASL_FILE_STDOUT);
545 1.3.4.2 rmind UtDisplaySummary (ASL_FILE_STDOUT);
546 1.3.4.2 rmind if (Gbl_DebugFlag)
547 1.3.4.2 rmind {
548 1.3.4.2 rmind /* Print error summary to the debug file */
549 1.3.4.2 rmind
550 1.3.4.2 rmind AePrintErrorLog (ASL_FILE_STDERR);
551 1.3.4.2 rmind UtDisplaySummary (ASL_FILE_STDERR);
552 1.3.4.2 rmind }
553 1.3.4.2 rmind return 0;
554 1.3.4.2 rmind }
555 1.3.4.2 rmind
556 1.3.4.2 rmind /*
557 1.3.4.2 rmind * Create an internal namespace and use it as a symbol table
558 1.3.4.2 rmind */
559 1.3.4.2 rmind
560 1.3.4.2 rmind /* Namespace loading */
561 1.3.4.2 rmind
562 1.3.4.2 rmind Event = UtBeginEvent ("Create ACPI Namespace");
563 1.3.4.2 rmind Status = LdLoadNamespace (RootNode);
564 1.3.4.2 rmind UtEndEvent (Event);
565 1.3.4.2 rmind if (ACPI_FAILURE (Status))
566 1.3.4.2 rmind {
567 1.3.4.2 rmind return -1;
568 1.3.4.2 rmind }
569 1.3.4.2 rmind
570 1.3.4.2 rmind /* Namespace cross-reference */
571 1.3.4.2 rmind
572 1.3.4.2 rmind AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
573 1.3.4.2 rmind Status = LkCrossReferenceNamespace ();
574 1.3.4.2 rmind if (ACPI_FAILURE (Status))
575 1.3.4.2 rmind {
576 1.3.4.2 rmind return -1;
577 1.3.4.2 rmind }
578 1.3.4.2 rmind
579 1.3.4.2 rmind /* Namespace - Check for non-referenced objects */
580 1.3.4.2 rmind
581 1.3.4.2 rmind LkFindUnreferencedObjects ();
582 1.3.4.2 rmind UtEndEvent (AslGbl_NamespaceEvent);
583 1.3.4.2 rmind
584 1.3.4.2 rmind /*
585 1.3.4.2 rmind * Semantic analysis. This can happen only after the
586 1.3.4.2 rmind * namespace has been loaded and cross-referenced.
587 1.3.4.2 rmind *
588 1.3.4.2 rmind * part one - check control methods
589 1.3.4.2 rmind */
590 1.3.4.2 rmind Event = UtBeginEvent ("Analyze control method return types");
591 1.3.4.2 rmind AnalysisWalkInfo.MethodStack = NULL;
592 1.3.4.2 rmind
593 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n");
594 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
595 1.3.4.2 rmind AnMethodAnalysisWalkBegin,
596 1.3.4.2 rmind AnMethodAnalysisWalkEnd, &AnalysisWalkInfo);
597 1.3.4.2 rmind UtEndEvent (Event);
598 1.3.4.2 rmind
599 1.3.4.2 rmind /* Semantic error checking part two - typing of method returns */
600 1.3.4.2 rmind
601 1.3.4.2 rmind Event = UtBeginEvent ("Determine object types returned by methods");
602 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n");
603 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
604 1.3.4.2 rmind NULL, AnMethodTypingWalkEnd, NULL);
605 1.3.4.2 rmind UtEndEvent (Event);
606 1.3.4.2 rmind
607 1.3.4.2 rmind /* Semantic error checking part three - operand type checking */
608 1.3.4.2 rmind
609 1.3.4.2 rmind Event = UtBeginEvent ("Analyze AML operand types");
610 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n");
611 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
612 1.3.4.2 rmind NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
613 1.3.4.2 rmind UtEndEvent (Event);
614 1.3.4.2 rmind
615 1.3.4.2 rmind /* Semantic error checking part four - other miscellaneous checks */
616 1.3.4.2 rmind
617 1.3.4.2 rmind Event = UtBeginEvent ("Miscellaneous analysis");
618 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n");
619 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
620 1.3.4.2 rmind AnOtherSemanticAnalysisWalkBegin,
621 1.3.4.2 rmind NULL, &AnalysisWalkInfo);
622 1.3.4.2 rmind UtEndEvent (Event);
623 1.3.4.2 rmind
624 1.3.4.2 rmind /* Calculate all AML package lengths */
625 1.3.4.2 rmind
626 1.3.4.2 rmind Event = UtBeginEvent ("Finish AML package length generation");
627 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
628 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
629 1.3.4.2 rmind LnInitLengthsWalk, NULL);
630 1.3.4.2 rmind TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
631 1.3.4.2 rmind LnPackageLengthWalk, NULL);
632 1.3.4.2 rmind UtEndEvent (Event);
633 1.3.4.2 rmind
634 1.3.4.2 rmind /* Code generation - emit the AML */
635 1.3.4.2 rmind
636 1.3.4.2 rmind Event = UtBeginEvent ("Generate AML code and write output files");
637 1.3.4.2 rmind CgGenerateAmlOutput ();
638 1.3.4.2 rmind UtEndEvent (Event);
639 1.3.4.2 rmind
640 1.3.4.2 rmind Event = UtBeginEvent ("Write optional output files");
641 1.3.4.2 rmind CmDoOutputFiles ();
642 1.3.4.2 rmind UtEndEvent (Event);
643 1.3.4.2 rmind
644 1.3.4.2 rmind UtEndEvent (FullCompile);
645 1.3.4.2 rmind CmCleanupAndExit ();
646 1.3.4.2 rmind return 0;
647 1.3.4.2 rmind }
648 1.3.4.2 rmind
649 1.3.4.2 rmind
650 1.3.4.2 rmind /*******************************************************************************
651 1.3.4.2 rmind *
652 1.3.4.2 rmind * FUNCTION: CmDoOutputFiles
653 1.3.4.2 rmind *
654 1.3.4.2 rmind * PARAMETERS: None
655 1.3.4.2 rmind *
656 1.3.4.2 rmind * RETURN: None.
657 1.3.4.2 rmind *
658 1.3.4.2 rmind * DESCRIPTION: Create all "listing" type files
659 1.3.4.2 rmind *
660 1.3.4.2 rmind ******************************************************************************/
661 1.3.4.2 rmind
662 1.3.4.2 rmind void
663 1.3.4.2 rmind CmDoOutputFiles (
664 1.3.4.2 rmind void)
665 1.3.4.2 rmind {
666 1.3.4.2 rmind
667 1.3.4.2 rmind /* Create listings and hex files */
668 1.3.4.2 rmind
669 1.3.4.2 rmind LsDoListings ();
670 1.3.4.2 rmind LsDoHexOutput ();
671 1.3.4.2 rmind
672 1.3.4.2 rmind /* Dump the namespace to the .nsp file if requested */
673 1.3.4.2 rmind
674 1.3.4.2 rmind (void) LsDisplayNamespace ();
675 1.3.4.2 rmind }
676 1.3.4.2 rmind
677 1.3.4.2 rmind
678 1.3.4.2 rmind /*******************************************************************************
679 1.3.4.2 rmind *
680 1.3.4.2 rmind * FUNCTION: CmDumpEvent
681 1.3.4.2 rmind *
682 1.3.4.2 rmind * PARAMETERS: Event - A compiler event struct
683 1.3.4.2 rmind *
684 1.3.4.2 rmind * RETURN: None.
685 1.3.4.2 rmind *
686 1.3.4.2 rmind * DESCRIPTION: Dump a compiler event struct
687 1.3.4.2 rmind *
688 1.3.4.2 rmind ******************************************************************************/
689 1.3.4.2 rmind
690 1.3.4.2 rmind static void
691 1.3.4.2 rmind CmDumpEvent (
692 1.3.4.2 rmind ASL_EVENT_INFO *Event)
693 1.3.4.2 rmind {
694 1.3.4.2 rmind UINT32 Delta;
695 1.3.4.2 rmind UINT32 USec;
696 1.3.4.2 rmind UINT32 MSec;
697 1.3.4.2 rmind
698 1.3.4.2 rmind if (!Event->Valid)
699 1.3.4.2 rmind {
700 1.3.4.2 rmind return;
701 1.3.4.2 rmind }
702 1.3.4.2 rmind
703 1.3.4.2 rmind /* Delta will be in 100-nanosecond units */
704 1.3.4.2 rmind
705 1.3.4.2 rmind Delta = (UINT32) (Event->EndTime - Event->StartTime);
706 1.3.4.2 rmind
707 1.3.4.2 rmind USec = Delta / 10;
708 1.3.4.2 rmind MSec = Delta / 10000;
709 1.3.4.2 rmind
710 1.3.4.2 rmind /* Round milliseconds up */
711 1.3.4.2 rmind
712 1.3.4.2 rmind if ((USec - (MSec * 1000)) >= 500)
713 1.3.4.2 rmind {
714 1.3.4.2 rmind MSec++;
715 1.3.4.2 rmind }
716 1.3.4.2 rmind
717 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
718 1.3.4.2 rmind USec, MSec, Event->EventName);
719 1.3.4.2 rmind }
720 1.3.4.2 rmind
721 1.3.4.2 rmind
722 1.3.4.2 rmind /*******************************************************************************
723 1.3.4.2 rmind *
724 1.3.4.2 rmind * FUNCTION: CmCleanupAndExit
725 1.3.4.2 rmind *
726 1.3.4.2 rmind * PARAMETERS: None
727 1.3.4.2 rmind *
728 1.3.4.2 rmind * RETURN: None.
729 1.3.4.2 rmind *
730 1.3.4.2 rmind * DESCRIPTION: Close all open files and exit the compiler
731 1.3.4.2 rmind *
732 1.3.4.2 rmind ******************************************************************************/
733 1.3.4.2 rmind
734 1.3.4.2 rmind void
735 1.3.4.2 rmind CmCleanupAndExit (
736 1.3.4.2 rmind void)
737 1.3.4.2 rmind {
738 1.3.4.2 rmind UINT32 i;
739 1.3.4.2 rmind
740 1.3.4.2 rmind
741 1.3.4.2 rmind AePrintErrorLog (ASL_FILE_STDOUT);
742 1.3.4.2 rmind if (Gbl_DebugFlag)
743 1.3.4.2 rmind {
744 1.3.4.2 rmind /* Print error summary to the debug file */
745 1.3.4.2 rmind
746 1.3.4.2 rmind AePrintErrorLog (ASL_FILE_STDERR);
747 1.3.4.2 rmind }
748 1.3.4.2 rmind
749 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
750 1.3.4.2 rmind for (i = 0; i < AslGbl_NextEvent; i++)
751 1.3.4.2 rmind {
752 1.3.4.2 rmind CmDumpEvent (&AslGbl_Events[i]);
753 1.3.4.2 rmind }
754 1.3.4.2 rmind
755 1.3.4.2 rmind if (Gbl_CompileTimesFlag)
756 1.3.4.2 rmind {
757 1.3.4.2 rmind printf ("\nElapsed time for major events\n\n");
758 1.3.4.2 rmind for (i = 0; i < AslGbl_NextEvent; i++)
759 1.3.4.2 rmind {
760 1.3.4.2 rmind CmDumpEvent (&AslGbl_Events[i]);
761 1.3.4.2 rmind }
762 1.3.4.2 rmind
763 1.3.4.2 rmind printf ("\nMiscellaneous compile statistics\n\n");
764 1.3.4.2 rmind printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
765 1.3.4.2 rmind printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
766 1.3.4.2 rmind printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
767 1.3.4.2 rmind printf ("%11u : %s\n", TotalMethods, "Control methods");
768 1.3.4.2 rmind printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
769 1.3.4.2 rmind printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
770 1.3.4.2 rmind printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
771 1.3.4.2 rmind printf ("\n");
772 1.3.4.2 rmind }
773 1.3.4.2 rmind
774 1.3.4.2 rmind if (Gbl_NsLookupCount)
775 1.3.4.2 rmind {
776 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT,
777 1.3.4.2 rmind "\n\nMiscellaneous compile statistics\n\n");
778 1.3.4.2 rmind
779 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT,
780 1.3.4.2 rmind "%32s : %u\n", "Total Namespace searches",
781 1.3.4.2 rmind Gbl_NsLookupCount);
782 1.3.4.2 rmind
783 1.3.4.2 rmind DbgPrint (ASL_DEBUG_OUTPUT,
784 1.3.4.2 rmind "%32s : %u usec\n", "Time per search", ((UINT32)
785 1.3.4.2 rmind (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
786 1.3.4.2 rmind AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
787 1.3.4.2 rmind Gbl_NsLookupCount);
788 1.3.4.2 rmind }
789 1.3.4.2 rmind
790 1.3.4.2 rmind if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
791 1.3.4.2 rmind {
792 1.3.4.2 rmind printf ("\nMaximum error count (%u) exceeded\n",
793 1.3.4.2 rmind ASL_MAX_ERROR_COUNT);
794 1.3.4.2 rmind }
795 1.3.4.2 rmind
796 1.3.4.2 rmind UtDisplaySummary (ASL_FILE_STDOUT);
797 1.3.4.2 rmind
798 1.3.4.2 rmind /* Close all open files */
799 1.3.4.2 rmind
800 1.3.4.2 rmind for (i = 2; i < ASL_MAX_FILE_TYPE; i++)
801 1.3.4.2 rmind {
802 1.3.4.2 rmind FlCloseFile (i);
803 1.3.4.2 rmind }
804 1.3.4.2 rmind
805 1.3.4.2 rmind /* Delete AML file if there are errors */
806 1.3.4.2 rmind
807 1.3.4.2 rmind if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) &&
808 1.3.4.2 rmind Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
809 1.3.4.2 rmind {
810 1.3.4.2 rmind if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename))
811 1.3.4.2 rmind {
812 1.3.4.2 rmind printf ("%s: ",
813 1.3.4.2 rmind Gbl_Files[ASL_FILE_AML_OUTPUT].Filename);
814 1.3.4.2 rmind perror ("Could not delete AML file");
815 1.3.4.2 rmind }
816 1.3.4.2 rmind }
817 1.3.4.2 rmind
818 1.3.4.2 rmind /*
819 1.3.4.2 rmind * Delete intermediate ("combined") source file (if -ls flag not set)
820 1.3.4.2 rmind * This file is created during normal ASL/AML compiles. It is not
821 1.3.4.2 rmind * created by the data table compiler.
822 1.3.4.2 rmind *
823 1.3.4.2 rmind * If the -ls flag is set, then the .SRC file should not be deleted.
824 1.3.4.2 rmind * In this case, Gbl_SourceOutputFlag is set to TRUE.
825 1.3.4.2 rmind *
826 1.3.4.2 rmind * Note: Handles are cleared by FlCloseFile above, so we look at the
827 1.3.4.2 rmind * filename instead, to determine if the .SRC file was actually
828 1.3.4.2 rmind * created.
829 1.3.4.2 rmind *
830 1.3.4.2 rmind * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
831 1.3.4.2 rmind */
832 1.3.4.2 rmind if (!Gbl_SourceOutputFlag && Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)
833 1.3.4.2 rmind {
834 1.3.4.2 rmind if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename))
835 1.3.4.2 rmind {
836 1.3.4.2 rmind printf ("%s: ",
837 1.3.4.2 rmind Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
838 1.3.4.2 rmind perror ("Could not delete SRC file");
839 1.3.4.2 rmind }
840 1.3.4.2 rmind }
841 1.3.4.2 rmind }
842 1.3.4.2 rmind
843 1.3.4.2 rmind
844