aslcompile.c revision 1.1 1 1.1 jruoho
2 1.1 jruoho /******************************************************************************
3 1.1 jruoho *
4 1.1 jruoho * Module Name: aslcompile - top level compile module
5 1.1 jruoho *
6 1.1 jruoho *****************************************************************************/
7 1.1 jruoho
8 1.1 jruoho /******************************************************************************
9 1.1 jruoho *
10 1.1 jruoho * 1. Copyright Notice
11 1.1 jruoho *
12 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 1.1 jruoho * All rights reserved.
14 1.1 jruoho *
15 1.1 jruoho * 2. License
16 1.1 jruoho *
17 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
18 1.1 jruoho * rights. You may have additional license terms from the party that provided
19 1.1 jruoho * you this software, covering your right to use that party's intellectual
20 1.1 jruoho * property rights.
21 1.1 jruoho *
22 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
24 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
26 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
27 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
28 1.1 jruoho *
29 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
31 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
32 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
33 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
34 1.1 jruoho * license, and in no event shall the patent license extend to any additions
35 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
36 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
37 1.1 jruoho *
38 1.1 jruoho * The above copyright and patent license is granted only if the following
39 1.1 jruoho * conditions are met:
40 1.1 jruoho *
41 1.1 jruoho * 3. Conditions
42 1.1 jruoho *
43 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
45 1.1 jruoho * Code or modification with rights to further distribute source must include
46 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
47 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
48 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
49 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
50 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
51 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
52 1.1 jruoho * must include a prominent statement that the modification is derived,
53 1.1 jruoho * directly or indirectly, from Original Intel Code.
54 1.1 jruoho *
55 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
57 1.1 jruoho * Code or modification without rights to further distribute source must
58 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
59 1.1 jruoho * documentation and/or other materials provided with distribution. In
60 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
61 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
62 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
63 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
64 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
65 1.1 jruoho * make.
66 1.1 jruoho *
67 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
69 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
70 1.1 jruoho * provision in the documentation and/or other materials provided with the
71 1.1 jruoho * distribution.
72 1.1 jruoho *
73 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
74 1.1 jruoho * Intel Code.
75 1.1 jruoho *
76 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
78 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
79 1.1 jruoho * without prior written authorization from Intel.
80 1.1 jruoho *
81 1.1 jruoho * 4. Disclaimer and Export Compliance
82 1.1 jruoho *
83 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 1.1 jruoho * PARTICULAR PURPOSE.
90 1.1 jruoho *
91 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 1.1 jruoho * LIMITED REMEDY.
99 1.1 jruoho *
100 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 1.1 jruoho * software or system incorporating such software without first obtaining any
102 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
103 1.1 jruoho * any other agency or department of the United States Government. In the
104 1.1 jruoho * event Licensee exports any such software from the United States or
105 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
106 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
107 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
108 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
110 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
111 1.1 jruoho * United States government or any agency thereof requires an export license,
112 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
113 1.1 jruoho * such license, approval or letter.
114 1.1 jruoho *
115 1.1 jruoho *****************************************************************************/
116 1.1 jruoho
117 1.1 jruoho #include <stdio.h>
118 1.1 jruoho #include <time.h>
119 1.1 jruoho #include "aslcompiler.h"
120 1.1 jruoho
121 1.1 jruoho #define _COMPONENT ACPI_COMPILER
122 1.1 jruoho ACPI_MODULE_NAME ("aslcompile")
123 1.1 jruoho
124 1.1 jruoho /* Local prototypes */
125 1.1 jruoho
126 1.1 jruoho static void
127 1.1 jruoho CmFlushSourceCode (
128 1.1 jruoho void);
129 1.1 jruoho
130 1.1 jruoho void
131 1.1 jruoho FlConsumeAnsiComment (
132 1.1 jruoho ASL_FILE_INFO *FileInfo,
133 1.1 jruoho ASL_FILE_STATUS *Status);
134 1.1 jruoho
135 1.1 jruoho void
136 1.1 jruoho FlConsumeNewComment (
137 1.1 jruoho ASL_FILE_INFO *FileInfo,
138 1.1 jruoho ASL_FILE_STATUS *Status);
139 1.1 jruoho
140 1.1 jruoho
141 1.1 jruoho /*******************************************************************************
142 1.1 jruoho *
143 1.1 jruoho * FUNCTION: AslCompilerSignon
144 1.1 jruoho *
145 1.1 jruoho * PARAMETERS: FileId - ID of the output file
146 1.1 jruoho *
147 1.1 jruoho * RETURN: None
148 1.1 jruoho *
149 1.1 jruoho * DESCRIPTION: Display compiler signon
150 1.1 jruoho *
151 1.1 jruoho ******************************************************************************/
152 1.1 jruoho
153 1.1 jruoho void
154 1.1 jruoho AslCompilerSignon (
155 1.1 jruoho UINT32 FileId)
156 1.1 jruoho {
157 1.1 jruoho char *Prefix = "";
158 1.1 jruoho
159 1.1 jruoho
160 1.1 jruoho /* Set line prefix depending on the destination file type */
161 1.1 jruoho
162 1.1 jruoho switch (FileId)
163 1.1 jruoho {
164 1.1 jruoho case ASL_FILE_ASM_SOURCE_OUTPUT:
165 1.1 jruoho case ASL_FILE_ASM_INCLUDE_OUTPUT:
166 1.1 jruoho
167 1.1 jruoho Prefix = "; ";
168 1.1 jruoho break;
169 1.1 jruoho
170 1.1 jruoho case ASL_FILE_HEX_OUTPUT:
171 1.1 jruoho
172 1.1 jruoho if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
173 1.1 jruoho {
174 1.1 jruoho Prefix = "; ";
175 1.1 jruoho }
176 1.1 jruoho else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
177 1.1 jruoho (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
178 1.1 jruoho {
179 1.1 jruoho FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n");
180 1.1 jruoho Prefix = " * ";
181 1.1 jruoho }
182 1.1 jruoho break;
183 1.1 jruoho
184 1.1 jruoho case ASL_FILE_C_SOURCE_OUTPUT:
185 1.1 jruoho case ASL_FILE_C_INCLUDE_OUTPUT:
186 1.1 jruoho
187 1.1 jruoho Prefix = " * ";
188 1.1 jruoho break;
189 1.1 jruoho
190 1.1 jruoho default:
191 1.1 jruoho /* No other output types supported */
192 1.1 jruoho break;
193 1.1 jruoho }
194 1.1 jruoho
195 1.1 jruoho /*
196 1.1 jruoho * Compiler signon with copyright
197 1.1 jruoho */
198 1.1 jruoho FlPrintFile (FileId,
199 1.1 jruoho "%s\n%s%s\n%s",
200 1.1 jruoho Prefix,
201 1.1 jruoho Prefix, IntelAcpiCA,
202 1.1 jruoho Prefix);
203 1.1 jruoho
204 1.1 jruoho /* Running compiler or disassembler? */
205 1.1 jruoho
206 1.1 jruoho if (Gbl_DisasmFlag)
207 1.1 jruoho {
208 1.1 jruoho FlPrintFile (FileId,
209 1.1 jruoho "%s", DisassemblerId);
210 1.1 jruoho }
211 1.1 jruoho else
212 1.1 jruoho {
213 1.1 jruoho FlPrintFile (FileId,
214 1.1 jruoho "%s", CompilerId);
215 1.1 jruoho }
216 1.1 jruoho
217 1.1 jruoho /* Version, build date, copyright, compliance */
218 1.1 jruoho
219 1.1 jruoho FlPrintFile (FileId,
220 1.1 jruoho " version %X [%s]\n%s%s\n%s%s\n%s\n",
221 1.1 jruoho (UINT32) ACPI_CA_VERSION, __DATE__,
222 1.1 jruoho Prefix, CompilerCopyright,
223 1.1 jruoho Prefix, CompilerCompliance,
224 1.1 jruoho Prefix);
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho
228 1.1 jruoho /*******************************************************************************
229 1.1 jruoho *
230 1.1 jruoho * FUNCTION: AslCompilerFileHeader
231 1.1 jruoho *
232 1.1 jruoho * PARAMETERS: FileId - ID of the output file
233 1.1 jruoho *
234 1.1 jruoho * RETURN: None
235 1.1 jruoho *
236 1.1 jruoho * DESCRIPTION: Header used at the beginning of output files
237 1.1 jruoho *
238 1.1 jruoho ******************************************************************************/
239 1.1 jruoho
240 1.1 jruoho void
241 1.1 jruoho AslCompilerFileHeader (
242 1.1 jruoho UINT32 FileId)
243 1.1 jruoho {
244 1.1 jruoho struct tm *NewTime;
245 1.1 jruoho time_t Aclock;
246 1.1 jruoho char *Prefix = "";
247 1.1 jruoho
248 1.1 jruoho
249 1.1 jruoho /* Set line prefix depending on the destination file type */
250 1.1 jruoho
251 1.1 jruoho switch (FileId)
252 1.1 jruoho {
253 1.1 jruoho case ASL_FILE_ASM_SOURCE_OUTPUT:
254 1.1 jruoho case ASL_FILE_ASM_INCLUDE_OUTPUT:
255 1.1 jruoho
256 1.1 jruoho Prefix = "; ";
257 1.1 jruoho break;
258 1.1 jruoho
259 1.1 jruoho case ASL_FILE_HEX_OUTPUT:
260 1.1 jruoho
261 1.1 jruoho if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM)
262 1.1 jruoho {
263 1.1 jruoho Prefix = "; ";
264 1.1 jruoho }
265 1.1 jruoho else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) ||
266 1.1 jruoho (Gbl_HexOutputFlag == HEX_OUTPUT_ASL))
267 1.1 jruoho {
268 1.1 jruoho Prefix = " * ";
269 1.1 jruoho }
270 1.1 jruoho break;
271 1.1 jruoho
272 1.1 jruoho case ASL_FILE_C_SOURCE_OUTPUT:
273 1.1 jruoho case ASL_FILE_C_INCLUDE_OUTPUT:
274 1.1 jruoho
275 1.1 jruoho Prefix = " * ";
276 1.1 jruoho break;
277 1.1 jruoho
278 1.1 jruoho default:
279 1.1 jruoho /* No other output types supported */
280 1.1 jruoho break;
281 1.1 jruoho }
282 1.1 jruoho
283 1.1 jruoho /* Compilation header with timestamp */
284 1.1 jruoho
285 1.1 jruoho (void) time (&Aclock);
286 1.1 jruoho NewTime = localtime (&Aclock);
287 1.1 jruoho
288 1.1 jruoho FlPrintFile (FileId,
289 1.1 jruoho "%sCompilation of \"%s\" - %s%s\n",
290 1.1 jruoho Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime),
291 1.1 jruoho Prefix);
292 1.1 jruoho
293 1.1 jruoho switch (FileId)
294 1.1 jruoho {
295 1.1 jruoho case ASL_FILE_C_SOURCE_OUTPUT:
296 1.1 jruoho case ASL_FILE_C_INCLUDE_OUTPUT:
297 1.1 jruoho FlPrintFile (FileId, " */\n");
298 1.1 jruoho break;
299 1.1 jruoho
300 1.1 jruoho default:
301 1.1 jruoho /* Nothing to do for other output types */
302 1.1 jruoho break;
303 1.1 jruoho }
304 1.1 jruoho }
305 1.1 jruoho
306 1.1 jruoho
307 1.1 jruoho /*******************************************************************************
308 1.1 jruoho *
309 1.1 jruoho * FUNCTION: CmFlushSourceCode
310 1.1 jruoho *
311 1.1 jruoho * PARAMETERS: None
312 1.1 jruoho *
313 1.1 jruoho * RETURN: None
314 1.1 jruoho *
315 1.1 jruoho * DESCRIPTION: Read in any remaining source code after the parse tree
316 1.1 jruoho * has been constructed.
317 1.1 jruoho *
318 1.1 jruoho ******************************************************************************/
319 1.1 jruoho
320 1.1 jruoho static void
321 1.1 jruoho CmFlushSourceCode (
322 1.1 jruoho void)
323 1.1 jruoho {
324 1.1 jruoho char Buffer;
325 1.1 jruoho
326 1.1 jruoho
327 1.1 jruoho while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR)
328 1.1 jruoho {
329 1.1 jruoho InsertLineBuffer ((int) Buffer);
330 1.1 jruoho }
331 1.1 jruoho
332 1.1 jruoho ResetCurrentLineBuffer ();
333 1.1 jruoho }
334 1.1 jruoho
335 1.1 jruoho
336 1.1 jruoho /*******************************************************************************
337 1.1 jruoho *
338 1.1 jruoho * FUNCTION: FlConsume*
339 1.1 jruoho *
340 1.1 jruoho * PARAMETERS: FileInfo - Points to an open input file
341 1.1 jruoho *
342 1.1 jruoho * RETURN: Number of lines consumed
343 1.1 jruoho *
344 1.1 jruoho * DESCRIPTION: Step over both types of comment during check for ascii chars
345 1.1 jruoho *
346 1.1 jruoho ******************************************************************************/
347 1.1 jruoho
348 1.1 jruoho void
349 1.1 jruoho FlConsumeAnsiComment (
350 1.1 jruoho ASL_FILE_INFO *FileInfo,
351 1.1 jruoho ASL_FILE_STATUS *Status)
352 1.1 jruoho {
353 1.1 jruoho UINT8 Byte;
354 1.1 jruoho BOOLEAN ClosingComment = FALSE;
355 1.1 jruoho
356 1.1 jruoho
357 1.1 jruoho while (fread (&Byte, 1, 1, FileInfo->Handle))
358 1.1 jruoho {
359 1.1 jruoho /* Scan until comment close is found */
360 1.1 jruoho
361 1.1 jruoho if (ClosingComment)
362 1.1 jruoho {
363 1.1 jruoho if (Byte == '/')
364 1.1 jruoho {
365 1.1 jruoho return;
366 1.1 jruoho }
367 1.1 jruoho
368 1.1 jruoho if (Byte != '*')
369 1.1 jruoho {
370 1.1 jruoho /* Reset */
371 1.1 jruoho
372 1.1 jruoho ClosingComment = FALSE;
373 1.1 jruoho }
374 1.1 jruoho }
375 1.1 jruoho else if (Byte == '*')
376 1.1 jruoho {
377 1.1 jruoho ClosingComment = TRUE;
378 1.1 jruoho }
379 1.1 jruoho
380 1.1 jruoho /* Maintain line count */
381 1.1 jruoho
382 1.1 jruoho if (Byte == 0x0A)
383 1.1 jruoho {
384 1.1 jruoho Status->Line++;
385 1.1 jruoho }
386 1.1 jruoho
387 1.1 jruoho Status->Offset++;
388 1.1 jruoho }
389 1.1 jruoho }
390 1.1 jruoho
391 1.1 jruoho
392 1.1 jruoho void
393 1.1 jruoho FlConsumeNewComment (
394 1.1 jruoho ASL_FILE_INFO *FileInfo,
395 1.1 jruoho ASL_FILE_STATUS *Status)
396 1.1 jruoho {
397 1.1 jruoho UINT8 Byte;
398 1.1 jruoho
399 1.1 jruoho
400 1.1 jruoho while (fread (&Byte, 1, 1, FileInfo->Handle))
401 1.1 jruoho {
402 1.1 jruoho Status->Offset++;
403 1.1 jruoho
404 1.1 jruoho /* Comment ends at newline */
405 1.1 jruoho
406 1.1 jruoho if (Byte == 0x0A)
407 1.1 jruoho {
408 1.1 jruoho Status->Line++;
409 1.1 jruoho return;
410 1.1 jruoho }
411 1.1 jruoho }
412 1.1 jruoho }
413 1.1 jruoho
414 1.1 jruoho
415 1.1 jruoho /*******************************************************************************
416 1.1 jruoho *
417 1.1 jruoho * FUNCTION: FlCheckForAscii
418 1.1 jruoho *
419 1.1 jruoho * PARAMETERS: FileInfo - Points to an open input file
420 1.1 jruoho *
421 1.1 jruoho * RETURN: Status
422 1.1 jruoho *
423 1.1 jruoho * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters
424 1.1 jruoho * within comments. Note: does not handle nested comments and does
425 1.1 jruoho * not handle comment delimiters within string literals. However,
426 1.1 jruoho * on the rare chance this happens and an invalid character is
427 1.1 jruoho * missed, the parser will catch the error by failing in some
428 1.1 jruoho * spectactular manner.
429 1.1 jruoho *
430 1.1 jruoho ******************************************************************************/
431 1.1 jruoho
432 1.1 jruoho ACPI_STATUS
433 1.1 jruoho FlCheckForAscii (
434 1.1 jruoho ASL_FILE_INFO *FileInfo)
435 1.1 jruoho {
436 1.1 jruoho UINT8 Byte;
437 1.1 jruoho ACPI_SIZE BadBytes = 0;
438 1.1 jruoho BOOLEAN OpeningComment = FALSE;
439 1.1 jruoho ASL_FILE_STATUS Status;
440 1.1 jruoho
441 1.1 jruoho
442 1.1 jruoho Status.Line = 1;
443 1.1 jruoho Status.Offset = 0;
444 1.1 jruoho
445 1.1 jruoho /* Read the entire file */
446 1.1 jruoho
447 1.1 jruoho while (fread (&Byte, 1, 1, FileInfo->Handle))
448 1.1 jruoho {
449 1.1 jruoho /* Ignore comment fields (allow non-ascii within) */
450 1.1 jruoho
451 1.1 jruoho if (OpeningComment)
452 1.1 jruoho {
453 1.1 jruoho /* Check for second comment open delimiter */
454 1.1 jruoho
455 1.1 jruoho if (Byte == '*')
456 1.1 jruoho {
457 1.1 jruoho FlConsumeAnsiComment (FileInfo, &Status);
458 1.1 jruoho }
459 1.1 jruoho
460 1.1 jruoho if (Byte == '/')
461 1.1 jruoho {
462 1.1 jruoho FlConsumeNewComment (FileInfo, &Status);
463 1.1 jruoho }
464 1.1 jruoho
465 1.1 jruoho /* Reset */
466 1.1 jruoho
467 1.1 jruoho OpeningComment = FALSE;
468 1.1 jruoho }
469 1.1 jruoho else if (Byte == '/')
470 1.1 jruoho {
471 1.1 jruoho OpeningComment = TRUE;
472 1.1 jruoho }
473 1.1 jruoho
474 1.1 jruoho /* Check for an ASCII character */
475 1.1 jruoho
476 1.1 jruoho if (!ACPI_IS_ASCII (Byte))
477 1.1 jruoho {
478 1.1 jruoho if (BadBytes < 10)
479 1.1 jruoho {
480 1.1 jruoho AcpiOsPrintf (
481 1.1 jruoho "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n",
482 1.1 jruoho Byte, Status.Line, Status.Offset);
483 1.1 jruoho }
484 1.1 jruoho
485 1.1 jruoho BadBytes++;
486 1.1 jruoho }
487 1.1 jruoho
488 1.1 jruoho /* Update line counter */
489 1.1 jruoho
490 1.1 jruoho else if (Byte == 0x0A)
491 1.1 jruoho {
492 1.1 jruoho Status.Line++;
493 1.1 jruoho }
494 1.1 jruoho
495 1.1 jruoho Status.Offset++;
496 1.1 jruoho }
497 1.1 jruoho
498 1.1 jruoho /* Seek back to the beginning of the source file */
499 1.1 jruoho
500 1.1 jruoho fseek (FileInfo->Handle, 0, SEEK_SET);
501 1.1 jruoho
502 1.1 jruoho /* Were there any non-ASCII characters in the file? */
503 1.1 jruoho
504 1.1 jruoho if (BadBytes)
505 1.1 jruoho {
506 1.1 jruoho AcpiOsPrintf (
507 1.1 jruoho "%u non-ASCII characters found in input source text, could be a binary file\n",
508 1.1 jruoho BadBytes);
509 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename);
510 1.1 jruoho return (AE_BAD_CHARACTER);
511 1.1 jruoho }
512 1.1 jruoho
513 1.1 jruoho /* File is OK */
514 1.1 jruoho
515 1.1 jruoho return (AE_OK);
516 1.1 jruoho }
517 1.1 jruoho
518 1.1 jruoho
519 1.1 jruoho /*******************************************************************************
520 1.1 jruoho *
521 1.1 jruoho * FUNCTION: CmDoCompile
522 1.1 jruoho *
523 1.1 jruoho * PARAMETERS: None
524 1.1 jruoho *
525 1.1 jruoho * RETURN: Status (0 = OK)
526 1.1 jruoho *
527 1.1 jruoho * DESCRIPTION: This procedure performs the entire compile
528 1.1 jruoho *
529 1.1 jruoho ******************************************************************************/
530 1.1 jruoho
531 1.1 jruoho int
532 1.1 jruoho CmDoCompile (
533 1.1 jruoho void)
534 1.1 jruoho {
535 1.1 jruoho ACPI_STATUS Status;
536 1.1 jruoho UINT8 FullCompile;
537 1.1 jruoho UINT8 Event;
538 1.1 jruoho
539 1.1 jruoho
540 1.1 jruoho FullCompile = UtBeginEvent ("*** Total Compile time ***");
541 1.1 jruoho Event = UtBeginEvent ("Open input and output files");
542 1.1 jruoho UtEndEvent (Event);
543 1.1 jruoho
544 1.1 jruoho /* Build the parse tree */
545 1.1 jruoho
546 1.1 jruoho Event = UtBeginEvent ("Parse source code and build parse tree");
547 1.1 jruoho AslCompilerparse();
548 1.1 jruoho UtEndEvent (Event);
549 1.1 jruoho
550 1.1 jruoho /* Flush out any remaining source after parse tree is complete */
551 1.1 jruoho
552 1.1 jruoho Event = UtBeginEvent ("Flush source input");
553 1.1 jruoho CmFlushSourceCode ();
554 1.1 jruoho
555 1.1 jruoho /* Did the parse tree get successfully constructed? */
556 1.1 jruoho
557 1.1 jruoho if (!RootNode)
558 1.1 jruoho {
559 1.1 jruoho CmCleanupAndExit ();
560 1.1 jruoho return -1;
561 1.1 jruoho }
562 1.1 jruoho
563 1.1 jruoho /* Optional parse tree dump, compiler debug output only */
564 1.1 jruoho
565 1.1 jruoho LsDumpParseTree ();
566 1.1 jruoho
567 1.1 jruoho OpcGetIntegerWidth (RootNode);
568 1.1 jruoho UtEndEvent (Event);
569 1.1 jruoho
570 1.1 jruoho /* Pre-process parse tree for any operator transforms */
571 1.1 jruoho
572 1.1 jruoho Event = UtBeginEvent ("Parse tree transforms");
573 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n");
574 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
575 1.1 jruoho TrAmlTransformWalk, NULL, NULL);
576 1.1 jruoho UtEndEvent (Event);
577 1.1 jruoho
578 1.1 jruoho /* Generate AML opcodes corresponding to the parse tokens */
579 1.1 jruoho
580 1.1 jruoho Event = UtBeginEvent ("Generate AML opcodes");
581 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n");
582 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
583 1.1 jruoho OpcAmlOpcodeWalk, NULL);
584 1.1 jruoho UtEndEvent (Event);
585 1.1 jruoho
586 1.1 jruoho /*
587 1.1 jruoho * Now that the input is parsed, we can open the AML output file.
588 1.1 jruoho * Note: by default, the name of this file comes from the table descriptor
589 1.1 jruoho * within the input file.
590 1.1 jruoho */
591 1.1 jruoho Event = UtBeginEvent ("Open AML output file");
592 1.1 jruoho Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
593 1.1 jruoho if (ACPI_FAILURE (Status))
594 1.1 jruoho {
595 1.1 jruoho AePrintErrorLog (ASL_FILE_STDERR);
596 1.1 jruoho return -1;
597 1.1 jruoho }
598 1.1 jruoho UtEndEvent (Event);
599 1.1 jruoho
600 1.1 jruoho /* Interpret and generate all compile-time constants */
601 1.1 jruoho
602 1.1 jruoho Event = UtBeginEvent ("Constant folding via AML interpreter");
603 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
604 1.1 jruoho "\nInterpreting compile-time constant expressions\n\n");
605 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
606 1.1 jruoho OpcAmlConstantWalk, NULL, NULL);
607 1.1 jruoho UtEndEvent (Event);
608 1.1 jruoho
609 1.1 jruoho /* Update AML opcodes if necessary, after constant folding */
610 1.1 jruoho
611 1.1 jruoho Event = UtBeginEvent ("Updating AML opcodes after constant folding");
612 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
613 1.1 jruoho "\nUpdating AML opcodes after constant folding\n\n");
614 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD,
615 1.1 jruoho NULL, OpcAmlOpcodeUpdateWalk, NULL);
616 1.1 jruoho UtEndEvent (Event);
617 1.1 jruoho
618 1.1 jruoho /* Calculate all AML package lengths */
619 1.1 jruoho
620 1.1 jruoho Event = UtBeginEvent ("Generate AML package lengths");
621 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
622 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
623 1.1 jruoho LnPackageLengthWalk, NULL);
624 1.1 jruoho UtEndEvent (Event);
625 1.1 jruoho
626 1.1 jruoho if (Gbl_ParseOnlyFlag)
627 1.1 jruoho {
628 1.1 jruoho AePrintErrorLog (ASL_FILE_STDOUT);
629 1.1 jruoho UtDisplaySummary (ASL_FILE_STDOUT);
630 1.1 jruoho if (Gbl_DebugFlag)
631 1.1 jruoho {
632 1.1 jruoho /* Print error summary to the debug file */
633 1.1 jruoho
634 1.1 jruoho AePrintErrorLog (ASL_FILE_STDERR);
635 1.1 jruoho UtDisplaySummary (ASL_FILE_STDERR);
636 1.1 jruoho }
637 1.1 jruoho return 0;
638 1.1 jruoho }
639 1.1 jruoho
640 1.1 jruoho /*
641 1.1 jruoho * Create an internal namespace and use it as a symbol table
642 1.1 jruoho */
643 1.1 jruoho
644 1.1 jruoho /* Namespace loading */
645 1.1 jruoho
646 1.1 jruoho Event = UtBeginEvent ("Create ACPI Namespace");
647 1.1 jruoho Status = LdLoadNamespace (RootNode);
648 1.1 jruoho UtEndEvent (Event);
649 1.1 jruoho if (ACPI_FAILURE (Status))
650 1.1 jruoho {
651 1.1 jruoho return -1;
652 1.1 jruoho }
653 1.1 jruoho
654 1.1 jruoho /* Namespace cross-reference */
655 1.1 jruoho
656 1.1 jruoho AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace");
657 1.1 jruoho Status = LkCrossReferenceNamespace ();
658 1.1 jruoho if (ACPI_FAILURE (Status))
659 1.1 jruoho {
660 1.1 jruoho return -1;
661 1.1 jruoho }
662 1.1 jruoho
663 1.1 jruoho /* Namespace - Check for non-referenced objects */
664 1.1 jruoho
665 1.1 jruoho LkFindUnreferencedObjects ();
666 1.1 jruoho UtEndEvent (AslGbl_NamespaceEvent);
667 1.1 jruoho
668 1.1 jruoho /*
669 1.1 jruoho * Semantic analysis. This can happen only after the
670 1.1 jruoho * namespace has been loaded and cross-referenced.
671 1.1 jruoho *
672 1.1 jruoho * part one - check control methods
673 1.1 jruoho */
674 1.1 jruoho Event = UtBeginEvent ("Analyze control method return types");
675 1.1 jruoho AnalysisWalkInfo.MethodStack = NULL;
676 1.1 jruoho
677 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n");
678 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
679 1.1 jruoho AnMethodAnalysisWalkBegin,
680 1.1 jruoho AnMethodAnalysisWalkEnd, &AnalysisWalkInfo);
681 1.1 jruoho UtEndEvent (Event);
682 1.1 jruoho
683 1.1 jruoho /* Semantic error checking part two - typing of method returns */
684 1.1 jruoho
685 1.1 jruoho Event = UtBeginEvent ("Determine object types returned by methods");
686 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n");
687 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
688 1.1 jruoho AnMethodTypingWalkBegin,
689 1.1 jruoho AnMethodTypingWalkEnd, NULL);
690 1.1 jruoho UtEndEvent (Event);
691 1.1 jruoho
692 1.1 jruoho /* Semantic error checking part three - operand type checking */
693 1.1 jruoho
694 1.1 jruoho Event = UtBeginEvent ("Analyze AML operand types");
695 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n");
696 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
697 1.1 jruoho AnOperandTypecheckWalkBegin,
698 1.1 jruoho AnOperandTypecheckWalkEnd, &AnalysisWalkInfo);
699 1.1 jruoho UtEndEvent (Event);
700 1.1 jruoho
701 1.1 jruoho /* Semantic error checking part four - other miscellaneous checks */
702 1.1 jruoho
703 1.1 jruoho Event = UtBeginEvent ("Miscellaneous analysis");
704 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n");
705 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE,
706 1.1 jruoho AnOtherSemanticAnalysisWalkBegin,
707 1.1 jruoho AnOtherSemanticAnalysisWalkEnd, &AnalysisWalkInfo);
708 1.1 jruoho UtEndEvent (Event);
709 1.1 jruoho
710 1.1 jruoho /* Calculate all AML package lengths */
711 1.1 jruoho
712 1.1 jruoho Event = UtBeginEvent ("Finish AML package length generation");
713 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n");
714 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
715 1.1 jruoho LnInitLengthsWalk, NULL);
716 1.1 jruoho TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL,
717 1.1 jruoho LnPackageLengthWalk, NULL);
718 1.1 jruoho UtEndEvent (Event);
719 1.1 jruoho
720 1.1 jruoho /* Code generation - emit the AML */
721 1.1 jruoho
722 1.1 jruoho Event = UtBeginEvent ("Generate AML code and write output files");
723 1.1 jruoho CgGenerateAmlOutput ();
724 1.1 jruoho UtEndEvent (Event);
725 1.1 jruoho
726 1.1 jruoho Event = UtBeginEvent ("Write optional output files");
727 1.1 jruoho CmDoOutputFiles ();
728 1.1 jruoho UtEndEvent (Event);
729 1.1 jruoho
730 1.1 jruoho UtEndEvent (FullCompile);
731 1.1 jruoho CmCleanupAndExit ();
732 1.1 jruoho return 0;
733 1.1 jruoho }
734 1.1 jruoho
735 1.1 jruoho
736 1.1 jruoho /*******************************************************************************
737 1.1 jruoho *
738 1.1 jruoho * FUNCTION: CmDoOutputFiles
739 1.1 jruoho *
740 1.1 jruoho * PARAMETERS: None
741 1.1 jruoho *
742 1.1 jruoho * RETURN: None.
743 1.1 jruoho *
744 1.1 jruoho * DESCRIPTION: Create all "listing" type files
745 1.1 jruoho *
746 1.1 jruoho ******************************************************************************/
747 1.1 jruoho
748 1.1 jruoho void
749 1.1 jruoho CmDoOutputFiles (
750 1.1 jruoho void)
751 1.1 jruoho {
752 1.1 jruoho
753 1.1 jruoho /* Create listings and hex files */
754 1.1 jruoho
755 1.1 jruoho LsDoListings ();
756 1.1 jruoho LsDoHexOutput ();
757 1.1 jruoho
758 1.1 jruoho /* Dump the namespace to the .nsp file if requested */
759 1.1 jruoho
760 1.1 jruoho (void) LsDisplayNamespace ();
761 1.1 jruoho }
762 1.1 jruoho
763 1.1 jruoho
764 1.1 jruoho /*******************************************************************************
765 1.1 jruoho *
766 1.1 jruoho * FUNCTION: CmDumpEvent
767 1.1 jruoho *
768 1.1 jruoho * PARAMETERS: Event - A compiler event struct
769 1.1 jruoho *
770 1.1 jruoho * RETURN: None.
771 1.1 jruoho *
772 1.1 jruoho * DESCRIPTION: Dump a compiler event struct
773 1.1 jruoho *
774 1.1 jruoho ******************************************************************************/
775 1.1 jruoho
776 1.1 jruoho static void
777 1.1 jruoho CmDumpEvent (
778 1.1 jruoho ASL_EVENT_INFO *Event)
779 1.1 jruoho {
780 1.1 jruoho UINT32 Delta;
781 1.1 jruoho UINT32 USec;
782 1.1 jruoho UINT32 MSec;
783 1.1 jruoho
784 1.1 jruoho if (!Event->Valid)
785 1.1 jruoho {
786 1.1 jruoho return;
787 1.1 jruoho }
788 1.1 jruoho
789 1.1 jruoho /* Delta will be in 100-nanosecond units */
790 1.1 jruoho
791 1.1 jruoho Delta = (UINT32) (Event->EndTime - Event->StartTime);
792 1.1 jruoho
793 1.1 jruoho USec = Delta / 10;
794 1.1 jruoho MSec = Delta / 10000;
795 1.1 jruoho
796 1.1 jruoho /* Round milliseconds up */
797 1.1 jruoho
798 1.1 jruoho if ((USec - (MSec * 1000)) >= 500)
799 1.1 jruoho {
800 1.1 jruoho MSec++;
801 1.1 jruoho }
802 1.1 jruoho
803 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n",
804 1.1 jruoho USec, MSec, Event->EventName);
805 1.1 jruoho }
806 1.1 jruoho
807 1.1 jruoho
808 1.1 jruoho /*******************************************************************************
809 1.1 jruoho *
810 1.1 jruoho * FUNCTION: CmCleanupAndExit
811 1.1 jruoho *
812 1.1 jruoho * PARAMETERS: None
813 1.1 jruoho *
814 1.1 jruoho * RETURN: None.
815 1.1 jruoho *
816 1.1 jruoho * DESCRIPTION: Close all open files and exit the compiler
817 1.1 jruoho *
818 1.1 jruoho ******************************************************************************/
819 1.1 jruoho
820 1.1 jruoho void
821 1.1 jruoho CmCleanupAndExit (
822 1.1 jruoho void)
823 1.1 jruoho {
824 1.1 jruoho UINT32 i;
825 1.1 jruoho
826 1.1 jruoho
827 1.1 jruoho AePrintErrorLog (ASL_FILE_STDOUT);
828 1.1 jruoho if (Gbl_DebugFlag)
829 1.1 jruoho {
830 1.1 jruoho /* Print error summary to the debug file */
831 1.1 jruoho
832 1.1 jruoho AePrintErrorLog (ASL_FILE_STDERR);
833 1.1 jruoho }
834 1.1 jruoho
835 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n");
836 1.1 jruoho for (i = 0; i < AslGbl_NextEvent; i++)
837 1.1 jruoho {
838 1.1 jruoho CmDumpEvent (&AslGbl_Events[i]);
839 1.1 jruoho }
840 1.1 jruoho
841 1.1 jruoho if (Gbl_CompileTimesFlag)
842 1.1 jruoho {
843 1.1 jruoho printf ("\nElapsed time for major events\n\n");
844 1.1 jruoho for (i = 0; i < AslGbl_NextEvent; i++)
845 1.1 jruoho {
846 1.1 jruoho CmDumpEvent (&AslGbl_Events[i]);
847 1.1 jruoho }
848 1.1 jruoho
849 1.1 jruoho printf ("\nMiscellaneous compile statistics\n\n");
850 1.1 jruoho printf ("%11u : %s\n", TotalParseNodes, "Parse nodes");
851 1.1 jruoho printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches");
852 1.1 jruoho printf ("%11u : %s\n", TotalNamedObjects, "Named objects");
853 1.1 jruoho printf ("%11u : %s\n", TotalMethods, "Control methods");
854 1.1 jruoho printf ("%11u : %s\n", TotalAllocations, "Memory Allocations");
855 1.1 jruoho printf ("%11u : %s\n", TotalAllocated, "Total allocated memory");
856 1.1 jruoho printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded");
857 1.1 jruoho printf ("\n");
858 1.1 jruoho }
859 1.1 jruoho
860 1.1 jruoho if (Gbl_NsLookupCount)
861 1.1 jruoho {
862 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
863 1.1 jruoho "\n\nMiscellaneous compile statistics\n\n");
864 1.1 jruoho
865 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
866 1.1 jruoho "%32s : %u\n", "Total Namespace searches",
867 1.1 jruoho Gbl_NsLookupCount);
868 1.1 jruoho
869 1.1 jruoho DbgPrint (ASL_DEBUG_OUTPUT,
870 1.1 jruoho "%32s : %u usec\n", "Time per search", ((UINT32)
871 1.1 jruoho (AslGbl_Events[AslGbl_NamespaceEvent].EndTime -
872 1.1 jruoho AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) /
873 1.1 jruoho Gbl_NsLookupCount);
874 1.1 jruoho }
875 1.1 jruoho
876 1.1 jruoho if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT)
877 1.1 jruoho {
878 1.1 jruoho printf ("\nMaximum error count (%u) exceeded\n",
879 1.1 jruoho ASL_MAX_ERROR_COUNT);
880 1.1 jruoho }
881 1.1 jruoho
882 1.1 jruoho UtDisplaySummary (ASL_FILE_STDOUT);
883 1.1 jruoho
884 1.1 jruoho /* Close all open files */
885 1.1 jruoho
886 1.1 jruoho for (i = 2; i < ASL_MAX_FILE_TYPE; i++)
887 1.1 jruoho {
888 1.1 jruoho FlCloseFile (i);
889 1.1 jruoho }
890 1.1 jruoho
891 1.1 jruoho /* Delete AML file if there are errors */
892 1.1 jruoho
893 1.1 jruoho if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) &&
894 1.1 jruoho Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)
895 1.1 jruoho {
896 1.1 jruoho if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename))
897 1.1 jruoho {
898 1.1 jruoho printf ("%s: ",
899 1.1 jruoho Gbl_Files[ASL_FILE_AML_OUTPUT].Filename);
900 1.1 jruoho perror ("Could not delete AML file");
901 1.1 jruoho }
902 1.1 jruoho }
903 1.1 jruoho
904 1.1 jruoho /*
905 1.1 jruoho * Delete intermediate ("combined") source file (if -ls flag not set)
906 1.1 jruoho *
907 1.1 jruoho * TBD: SourceOutput should be .TMP, then rename if we want to keep it?
908 1.1 jruoho */
909 1.1 jruoho if (!Gbl_SourceOutputFlag)
910 1.1 jruoho {
911 1.1 jruoho if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename))
912 1.1 jruoho {
913 1.1 jruoho printf ("%s: ",
914 1.1 jruoho Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
915 1.1 jruoho perror ("Could not delete SRC file");
916 1.1 jruoho }
917 1.1 jruoho }
918 1.1 jruoho }
919 1.1 jruoho
920 1.1 jruoho
921