Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / asllisting.c
blobc8e2a6e7daaa27cfc366864f68d640e4e5d72a15
1 /******************************************************************************
3 * Module Name: asllisting - Listing file generation
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46 #include "amlcode.h"
47 #include "acparser.h"
48 #include "acnamesp.h"
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("asllisting")
55 /* Local prototypes */
57 static void
58 LsGenerateListing (
59 UINT32 FileId);
61 static ACPI_STATUS
62 LsAmlListingWalk (
63 ACPI_PARSE_OBJECT *Op,
64 UINT32 Level,
65 void *Context);
67 static ACPI_STATUS
68 LsTreeWriteWalk (
69 ACPI_PARSE_OBJECT *Op,
70 UINT32 Level,
71 void *Context);
73 static void
74 LsWriteNodeToListing (
75 ACPI_PARSE_OBJECT *Op,
76 UINT32 FileId);
78 static void
79 LsFinishSourceListing (
80 UINT32 FileId);
83 /*******************************************************************************
85 * FUNCTION: LsDoListings
87 * PARAMETERS: None. Examines the various output file global flags.
89 * RETURN: None
91 * DESCRIPTION: Generate all requested listing files.
93 ******************************************************************************/
95 void
96 LsDoListings (
97 void)
100 if (Gbl_C_OutputFlag)
102 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
105 if (Gbl_ListingFlag)
107 LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
110 if (Gbl_AsmOutputFlag)
112 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
115 if (Gbl_C_IncludeOutputFlag)
117 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
120 if (Gbl_AsmIncludeOutputFlag)
122 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
125 if (Gbl_C_OffsetTableFlag)
127 LsGenerateListing (ASL_FILE_C_OFFSET_OUTPUT);
132 /*******************************************************************************
134 * FUNCTION: LsGenerateListing
136 * PARAMETERS: FileId - ID of listing file
138 * RETURN: None
140 * DESCRIPTION: Generate a listing file. This can be one of the several types
141 * of "listings" supported.
143 ******************************************************************************/
145 static void
146 LsGenerateListing (
147 UINT32 FileId)
150 /* Start at the beginning of both the source and AML files */
152 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
153 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
154 Gbl_SourceLine = 0;
155 Gbl_CurrentHexColumn = 0;
156 LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
158 if (FileId == ASL_FILE_C_OFFSET_OUTPUT)
160 Gbl_CurrentAmlOffset = 0;
162 /* Offset table file has a special header and footer */
164 LsDoOffsetTableHeader (FileId);
166 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlOffsetWalk,
167 NULL, (void *) ACPI_TO_POINTER (FileId));
168 LsDoOffsetTableFooter (FileId);
169 return;
172 /* Process all parse nodes */
174 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
175 NULL, (void *) ACPI_TO_POINTER (FileId));
177 /* Final processing */
179 LsFinishSourceListing (FileId);
183 /*******************************************************************************
185 * FUNCTION: LsAmlListingWalk
187 * PARAMETERS: ASL_WALK_CALLBACK
189 * RETURN: Status
191 * DESCRIPTION: Process one node during a listing file generation.
193 ******************************************************************************/
195 static ACPI_STATUS
196 LsAmlListingWalk (
197 ACPI_PARSE_OBJECT *Op,
198 UINT32 Level,
199 void *Context)
201 UINT8 FileByte;
202 UINT32 i;
203 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
206 LsWriteNodeToListing (Op, FileId);
208 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
210 /* Buffer is a resource template, don't dump the data all at once */
212 return (AE_OK);
215 /* Write the hex bytes to the listing file(s) (if requested) */
217 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
219 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
221 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
222 AslAbort ();
224 LsWriteListingHexBytes (&FileByte, 1, FileId);
227 return (AE_OK);
231 /*******************************************************************************
233 * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
235 * PARAMETERS: None
237 * RETURN: None
239 * DESCRIPTION: Dump entire parse tree, for compiler debug only
241 ******************************************************************************/
243 void
244 LsDumpParseTree (
245 void)
248 if (!Gbl_DebugFlag)
250 return;
253 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
254 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
255 LsTreeWriteWalk, NULL, NULL);
259 static ACPI_STATUS
260 LsTreeWriteWalk (
261 ACPI_PARSE_OBJECT *Op,
262 UINT32 Level,
263 void *Context)
266 /* Debug output */
268 DbgPrint (ASL_TREE_OUTPUT,
269 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
271 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
273 DbgPrint (ASL_TREE_OUTPUT, " (%.4X)\n", Op->Asl.ParseOpcode);
274 return (AE_OK);
278 /*******************************************************************************
280 * FUNCTION: LsWriteNodeToListing
282 * PARAMETERS: Op - Parse node to write to the listing file.
283 * FileId - ID of current listing file
285 * RETURN: None.
287 * DESCRIPTION: Write "a node" to the listing file. This means to
288 * 1) Write out all of the source text associated with the node
289 * 2) Write out all of the AML bytes associated with the node
290 * 3) Write any compiler exceptions associated with the node
292 ******************************************************************************/
294 static void
295 LsWriteNodeToListing (
296 ACPI_PARSE_OBJECT *Op,
297 UINT32 FileId)
299 const ACPI_OPCODE_INFO *OpInfo;
300 UINT32 OpClass;
301 char *Pathname;
302 UINT32 Length;
303 UINT32 i;
306 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
307 OpClass = OpInfo->Class;
309 /* TBD: clean this up with a single flag that says:
310 * I start a named output block
312 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
314 switch (Op->Asl.ParseOpcode)
316 case PARSEOP_DEFINITIONBLOCK:
317 case PARSEOP_METHODCALL:
318 case PARSEOP_INCLUDE:
319 case PARSEOP_INCLUDE_END:
320 case PARSEOP_DEFAULT_ARG:
322 break;
324 default:
326 switch (OpClass)
328 case AML_CLASS_NAMED_OBJECT:
330 switch (Op->Asl.AmlOpcode)
332 case AML_SCOPE_OP:
333 case AML_ALIAS_OP:
335 break;
337 default:
339 if (Op->Asl.ExternalName)
341 LsFlushListingBuffer (FileId);
342 FlPrintFile (FileId, " };\n");
344 break;
346 break;
348 default:
350 /* Don't care about other objects */
352 break;
354 break;
358 /* These cases do not have a corresponding AML opcode */
360 switch (Op->Asl.ParseOpcode)
362 case PARSEOP_DEFINITIONBLOCK:
364 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
366 /* Use the table Signature and TableId to build a unique name */
368 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
370 FlPrintFile (FileId,
371 "%s_%s_Header \\\n",
372 Gbl_TableSignature, Gbl_TableId);
374 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
376 FlPrintFile (FileId,
377 " unsigned char %s_%s_Header [] =\n {\n",
378 Gbl_TableSignature, Gbl_TableId);
380 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
382 FlPrintFile (FileId,
383 "extrn %s_%s_Header : byte\n",
384 Gbl_TableSignature, Gbl_TableId);
386 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
388 FlPrintFile (FileId,
389 "extern unsigned char %s_%s_Header [];\n",
390 Gbl_TableSignature, Gbl_TableId);
392 return;
395 case PARSEOP_METHODCALL:
397 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
398 FileId);
399 return;
402 case PARSEOP_INCLUDE:
404 /* Flush everything up to and including the include source line */
406 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
407 FileId);
409 /* Create a new listing node and push it */
411 LsPushNode (Op->Asl.Child->Asl.Value.String);
412 return;
415 case PARSEOP_INCLUDE_END:
417 /* Flush out the rest of the include file */
419 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
420 FileId);
422 /* Pop off this listing node and go back to the parent file */
424 (void) LsPopNode ();
425 return;
428 case PARSEOP_DEFAULT_ARG:
430 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
432 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
433 FileId);
435 return;
438 default:
440 /* All other opcodes have an AML opcode */
442 break;
446 * Otherwise, we look at the AML opcode because we can
447 * switch on the opcode type, getting an entire class
448 * at once
450 switch (OpClass)
452 case AML_CLASS_ARGUMENT: /* argument type only */
453 case AML_CLASS_INTERNAL:
455 break;
457 case AML_CLASS_NAMED_OBJECT:
459 switch (Op->Asl.AmlOpcode)
461 case AML_FIELD_OP:
462 case AML_INDEX_FIELD_OP:
463 case AML_BANK_FIELD_OP:
465 * For fields, we want to dump all the AML after the
466 * entire definition
468 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
469 FileId);
470 break;
472 case AML_NAME_OP:
474 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
476 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
477 FileId);
479 else
482 * For fields, we want to dump all the AML after the
483 * entire definition
485 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
486 FileId);
488 break;
490 default:
492 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
493 FileId);
494 break;
497 switch (Op->Asl.AmlOpcode)
499 case AML_SCOPE_OP:
500 case AML_ALIAS_OP:
502 /* These opcodes do not declare a new object, ignore them */
504 break;
506 default:
508 /* All other named object opcodes come here */
510 switch (FileId)
512 case ASL_FILE_ASM_SOURCE_OUTPUT:
513 case ASL_FILE_C_SOURCE_OUTPUT:
514 case ASL_FILE_ASM_INCLUDE_OUTPUT:
515 case ASL_FILE_C_INCLUDE_OUTPUT:
517 * For named objects, we will create a valid symbol so that the
518 * AML code can be referenced from C or ASM
520 if (Op->Asl.ExternalName)
522 /* Get the full pathname associated with this node */
524 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
525 Length = strlen (Pathname);
526 if (Length >= 4)
528 /* Convert all dots in the path to underscores */
530 for (i = 0; i < Length; i++)
532 if (Pathname[i] == '.')
534 Pathname[i] = '_';
538 /* Create the appropriate symbol in the output file */
540 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
542 FlPrintFile (FileId,
543 "%s_%s_%s \\\n",
544 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
546 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
548 FlPrintFile (FileId,
549 " unsigned char %s_%s_%s [] =\n {\n",
550 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
552 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
554 FlPrintFile (FileId,
555 "extrn %s_%s_%s : byte\n",
556 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
558 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
560 FlPrintFile (FileId,
561 "extern unsigned char %s_%s_%s [];\n",
562 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
565 ACPI_FREE (Pathname);
567 break;
569 default:
571 /* Nothing to do for listing file */
573 break;
576 break;
578 case AML_CLASS_EXECUTE:
579 case AML_CLASS_CREATE:
580 default:
582 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
583 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
585 return;
588 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
589 FileId);
590 break;
592 case AML_CLASS_UNKNOWN:
594 break;
599 /*******************************************************************************
601 * FUNCTION: LsFinishSourceListing
603 * PARAMETERS: FileId - ID of current listing file.
605 * RETURN: None
607 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
608 * listing buffer, and flush out any remaining lines in the
609 * source input file.
611 ******************************************************************************/
613 static void
614 LsFinishSourceListing (
615 UINT32 FileId)
618 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
619 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
621 return;
624 LsFlushListingBuffer (FileId);
625 Gbl_CurrentAmlOffset = 0;
627 /* Flush any remaining text in the source file */
629 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
631 FlPrintFile (FileId, " /*\n");
634 while (LsWriteOneSourceLine (FileId))
635 { ; }
637 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
639 FlPrintFile (FileId, "\n */\n };\n");
642 FlPrintFile (FileId, "\n");
644 if (FileId == ASL_FILE_LISTING_OUTPUT)
646 /* Print a summary of the compile exceptions */
648 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
649 AePrintErrorLog (FileId);
650 FlPrintFile (FileId, "\n");
651 UtDisplaySummary (FileId);
652 FlPrintFile (FileId, "\n");