10d84335fSJung-uk Kim /******************************************************************************
20d84335fSJung-uk Kim *
30d84335fSJung-uk Kim * Module Name: cvcompiler - ASL-/ASL+ converter functions
40d84335fSJung-uk Kim *
50d84335fSJung-uk Kim *****************************************************************************/
60d84335fSJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*722b1667SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
120d84335fSJung-uk Kim * All rights reserved.
130d84335fSJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
1190d84335fSJung-uk Kim * Redistribution and use in source and binary forms, with or without
1200d84335fSJung-uk Kim * modification, are permitted provided that the following conditions
1210d84335fSJung-uk Kim * are met:
1220d84335fSJung-uk Kim * 1. Redistributions of source code must retain the above copyright
1230d84335fSJung-uk Kim * notice, this list of conditions, and the following disclaimer,
1240d84335fSJung-uk Kim * without modification.
1250d84335fSJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1260d84335fSJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
1270d84335fSJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
1280d84335fSJung-uk Kim * including a substantially similar Disclaimer requirement for further
1290d84335fSJung-uk Kim * binary redistribution.
1300d84335fSJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
1310d84335fSJung-uk Kim * of any contributors may be used to endorse or promote products derived
1320d84335fSJung-uk Kim * from this software without specific prior written permission.
1330d84335fSJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1470d84335fSJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
1480d84335fSJung-uk Kim * Software Foundation.
1490d84335fSJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
1510d84335fSJung-uk Kim
1520d84335fSJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
1530d84335fSJung-uk Kim #include "aslcompiler.y.h"
1540d84335fSJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
1550d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
1560d84335fSJung-uk Kim #include <contrib/dev/acpica/include/acconvert.h>
1570d84335fSJung-uk Kim
1580d84335fSJung-uk Kim
1590d84335fSJung-uk Kim /*******************************************************************************
1600d84335fSJung-uk Kim *
1610d84335fSJung-uk Kim * FUNCTION: CvProcessComment
1620d84335fSJung-uk Kim *
1630d84335fSJung-uk Kim * PARAMETERS: CurrentState Current comment parse state
1640d84335fSJung-uk Kim * StringBuffer Buffer containing the comment being processed
1650d84335fSJung-uk Kim * c1 Current input
1660d84335fSJung-uk Kim *
1675f9b24faSJung-uk Kim * RETURN: None
1680d84335fSJung-uk Kim *
1690d84335fSJung-uk Kim * DESCRIPTION: Process a single line comment of a c Style comment. This
1700d84335fSJung-uk Kim * function captures a line of a c style comment in a char* and
171cd6518c7SJung-uk Kim * places the comment in the appropriate global buffer.
1720d84335fSJung-uk Kim *
1730d84335fSJung-uk Kim ******************************************************************************/
1740d84335fSJung-uk Kim
1750d84335fSJung-uk Kim void
CvProcessComment(ASL_COMMENT_STATE CurrentState,char * StringBuffer,int c1)1760d84335fSJung-uk Kim CvProcessComment (
1770d84335fSJung-uk Kim ASL_COMMENT_STATE CurrentState,
1780d84335fSJung-uk Kim char *StringBuffer,
1790d84335fSJung-uk Kim int c1)
1800d84335fSJung-uk Kim {
1810d84335fSJung-uk Kim UINT64 i;
1820d84335fSJung-uk Kim char *LineToken;
1830d84335fSJung-uk Kim char *FinalLineToken;
1840d84335fSJung-uk Kim BOOLEAN CharStart;
1850d84335fSJung-uk Kim char *CommentString;
1860d84335fSJung-uk Kim char *FinalCommentString;
1870d84335fSJung-uk Kim
1880d84335fSJung-uk Kim
189f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
1900d84335fSJung-uk Kim {
1910d84335fSJung-uk Kim *StringBuffer = (char) c1;
1920d84335fSJung-uk Kim ++StringBuffer;
1930d84335fSJung-uk Kim *StringBuffer = 0;
194af051161SJung-uk Kim
1950d84335fSJung-uk Kim CvDbgPrint ("Multi-line comment\n");
1966f1f1a63SJung-uk Kim CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
1976f1f1a63SJung-uk Kim strcpy (CommentString, AslGbl_MsgBuffer);
1980d84335fSJung-uk Kim
1990d84335fSJung-uk Kim CvDbgPrint ("CommentString: %s\n", CommentString);
2000d84335fSJung-uk Kim
2010d84335fSJung-uk Kim /*
202af051161SJung-uk Kim * Determine whether if this comment spans multiple lines. If so,
203af051161SJung-uk Kim * break apart the comment by storing each line in a different node
204af051161SJung-uk Kim * within the comment list. This allows the disassembler to
205af051161SJung-uk Kim * properly indent a multi-line comment.
2060d84335fSJung-uk Kim */
2070d84335fSJung-uk Kim LineToken = strtok (CommentString, "\n");
208af051161SJung-uk Kim
209af051161SJung-uk Kim if (LineToken)
210af051161SJung-uk Kim {
21167d9aa44SJung-uk Kim FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
2120d84335fSJung-uk Kim strcpy (FinalLineToken, LineToken);
2130d84335fSJung-uk Kim
2140d84335fSJung-uk Kim /* Get rid of any carriage returns */
2150d84335fSJung-uk Kim
2160d84335fSJung-uk Kim if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
2170d84335fSJung-uk Kim {
2180d84335fSJung-uk Kim FinalLineToken[strlen(FinalLineToken)-1] = 0;
2190d84335fSJung-uk Kim }
2205f9b24faSJung-uk Kim
2210d84335fSJung-uk Kim CvAddToCommentList (FinalLineToken);
2220d84335fSJung-uk Kim LineToken = strtok (NULL, "\n");
2230d84335fSJung-uk Kim while (LineToken != NULL)
2240d84335fSJung-uk Kim {
2250d84335fSJung-uk Kim /*
2260d84335fSJung-uk Kim * It is assumed that each line has some sort of indentation.
2275f9b24faSJung-uk Kim * This means that we need to find the first character that
2285f9b24faSJung-uk Kim * is not a white space within each line.
2290d84335fSJung-uk Kim */
2300d84335fSJung-uk Kim CharStart = FALSE;
2310d84335fSJung-uk Kim for (i = 0; (i < (strlen (LineToken) + 1)) && !CharStart; i++)
2320d84335fSJung-uk Kim {
2330d84335fSJung-uk Kim if (LineToken[i] != ' ' && LineToken[i] != '\t')
2340d84335fSJung-uk Kim {
2350d84335fSJung-uk Kim CharStart = TRUE;
2360d84335fSJung-uk Kim LineToken += i-1;
2370d84335fSJung-uk Kim LineToken [0] = ' '; /* Pad for Formatting */
2380d84335fSJung-uk Kim }
2390d84335fSJung-uk Kim }
2405f9b24faSJung-uk Kim
24167d9aa44SJung-uk Kim FinalLineToken = UtLocalCacheCalloc (strlen (LineToken) + 1);
2420d84335fSJung-uk Kim strcat (FinalLineToken, LineToken);
2430d84335fSJung-uk Kim
2440d84335fSJung-uk Kim /* Get rid of any carriage returns */
2450d84335fSJung-uk Kim
2460d84335fSJung-uk Kim if (FinalLineToken[strlen (FinalLineToken) - 1] == 0x0D)
2470d84335fSJung-uk Kim {
2480d84335fSJung-uk Kim FinalLineToken[strlen(FinalLineToken) - 1] = 0;
2490d84335fSJung-uk Kim }
2505f9b24faSJung-uk Kim
2510d84335fSJung-uk Kim CvAddToCommentList (FinalLineToken);
2520d84335fSJung-uk Kim LineToken = strtok (NULL,"\n");
2530d84335fSJung-uk Kim }
2540d84335fSJung-uk Kim }
2550d84335fSJung-uk Kim
2560d84335fSJung-uk Kim /*
2575f9b24faSJung-uk Kim * If this only spans a single line, check to see whether if this
2585f9b24faSJung-uk Kim * comment appears on the same line as a line of code. If does,
2595f9b24faSJung-uk Kim * retain it's position for stylistic reasons. If it doesn't,
2605f9b24faSJung-uk Kim * add it to the comment list so that it can be associated with
2615f9b24faSJung-uk Kim * the next node that's created.
2620d84335fSJung-uk Kim */
2630d84335fSJung-uk Kim else
2640d84335fSJung-uk Kim {
2650d84335fSJung-uk Kim /*
2665f9b24faSJung-uk Kim * If this is not a regular comment, pad with extra spaces that
2675f9b24faSJung-uk Kim * appeared in the original source input to retain the original
2685f9b24faSJung-uk Kim * spacing.
2690d84335fSJung-uk Kim */
270af051161SJung-uk Kim FinalCommentString =
27167d9aa44SJung-uk Kim UtLocalCacheCalloc (strlen (CommentString) +
272af051161SJung-uk Kim CurrentState.SpacesBefore + 1);
273af051161SJung-uk Kim
2740d84335fSJung-uk Kim for (i = 0; (CurrentState.CommentType != ASL_COMMENT_STANDARD) &&
2755f9b24faSJung-uk Kim (i < CurrentState.SpacesBefore); i++)
2760d84335fSJung-uk Kim {
2770d84335fSJung-uk Kim FinalCommentString[i] = ' ';
2780d84335fSJung-uk Kim }
2795f9b24faSJung-uk Kim
2800d84335fSJung-uk Kim strcat (FinalCommentString, CommentString);
2810d84335fSJung-uk Kim CvPlaceComment (CurrentState.CommentType, FinalCommentString);
2820d84335fSJung-uk Kim }
2830d84335fSJung-uk Kim }
2840d84335fSJung-uk Kim }
2850d84335fSJung-uk Kim
2860d84335fSJung-uk Kim
2870d84335fSJung-uk Kim /*******************************************************************************
2880d84335fSJung-uk Kim *
2890d84335fSJung-uk Kim * FUNCTION: CvProcessCommentType2
2900d84335fSJung-uk Kim *
2910d84335fSJung-uk Kim * PARAMETERS: CurrentState Current comment parse state
2920d84335fSJung-uk Kim * StringBuffer Buffer containing the comment being processed
2930d84335fSJung-uk Kim *
2940d84335fSJung-uk Kim * RETURN: none
2950d84335fSJung-uk Kim *
2960d84335fSJung-uk Kim * DESCRIPTION: Process a single line comment. This function captures a comment
297cd6518c7SJung-uk Kim * in a char* and places the comment in the appropriate global
2980d84335fSJung-uk Kim * buffer through CvPlaceComment
2990d84335fSJung-uk Kim *
3000d84335fSJung-uk Kim ******************************************************************************/
3010d84335fSJung-uk Kim
3020d84335fSJung-uk Kim void
CvProcessCommentType2(ASL_COMMENT_STATE CurrentState,char * StringBuffer)3030d84335fSJung-uk Kim CvProcessCommentType2 (
3040d84335fSJung-uk Kim ASL_COMMENT_STATE CurrentState,
3050d84335fSJung-uk Kim char *StringBuffer)
3060d84335fSJung-uk Kim {
3070d84335fSJung-uk Kim UINT32 i;
3080d84335fSJung-uk Kim char *CommentString;
3090d84335fSJung-uk Kim char *FinalCommentString;
3100d84335fSJung-uk Kim
3110d84335fSJung-uk Kim
312f1db5ef7SJung-uk Kim if (AcpiGbl_CaptureComments && CurrentState.CaptureComments)
3130d84335fSJung-uk Kim {
3140d84335fSJung-uk Kim *StringBuffer = 0; /* null terminate */
3150d84335fSJung-uk Kim CvDbgPrint ("Single-line comment\n");
3166f1f1a63SJung-uk Kim CommentString = UtLocalCacheCalloc (strlen (AslGbl_MsgBuffer) + 1);
3176f1f1a63SJung-uk Kim strcpy (CommentString, AslGbl_MsgBuffer);
3180d84335fSJung-uk Kim
3195f9b24faSJung-uk Kim /* If this comment lies on the same line as the latest parse op,
3205f9b24faSJung-uk Kim * assign it to that op's CommentAfter field. Saving in this field
3215f9b24faSJung-uk Kim * will allow us to support comments that come after code on the
3225f9b24faSJung-uk Kim * same line as the code itself. For example,
3230d84335fSJung-uk Kim * Name(A,"") //comment
3240d84335fSJung-uk Kim *
3250d84335fSJung-uk Kim * will be retained rather than transformed into
3260d84335fSJung-uk Kim *
3270d84335fSJung-uk Kim * Name(A,"")
3280d84335fSJung-uk Kim * //comment
3290d84335fSJung-uk Kim *
3300d84335fSJung-uk Kim * For this case, we only need to add one comment since
3310d84335fSJung-uk Kim *
3320d84335fSJung-uk Kim * Name(A,"") //comment1 //comment2 ... more comments here.
3330d84335fSJung-uk Kim *
3340d84335fSJung-uk Kim * would be lexically analyzed as a single comment.
3350d84335fSJung-uk Kim *
336cd6518c7SJung-uk Kim * Create a new string with the appropriate spaces. Since we need
3370d84335fSJung-uk Kim * to account for the proper spacing, the actual comment,
3380d84335fSJung-uk Kim * extra 2 spaces so that this comment can be converted to the "/ *"
3395f9b24faSJung-uk Kim * style and the null terminator, the string would look something
3405f9b24faSJung-uk Kim * like:
3410d84335fSJung-uk Kim *
3420d84335fSJung-uk Kim * [ (spaces) (comment) ( * /) ('\0') ]
3430d84335fSJung-uk Kim *
3440d84335fSJung-uk Kim */
34567d9aa44SJung-uk Kim FinalCommentString = UtLocalCacheCalloc (CurrentState.SpacesBefore +
346af051161SJung-uk Kim strlen (CommentString) + 3 + 1);
347af051161SJung-uk Kim
3485f9b24faSJung-uk Kim for (i = 0; (CurrentState.CommentType != 1) &&
3495f9b24faSJung-uk Kim (i < CurrentState.SpacesBefore); i++)
3500d84335fSJung-uk Kim {
3510d84335fSJung-uk Kim FinalCommentString[i] = ' ';
3520d84335fSJung-uk Kim }
3535f9b24faSJung-uk Kim
3540d84335fSJung-uk Kim strcat (FinalCommentString, CommentString);
3550d84335fSJung-uk Kim
3560d84335fSJung-uk Kim /* convert to a "/ *" style comment */
3570d84335fSJung-uk Kim
3580d84335fSJung-uk Kim strcat (FinalCommentString, " */");
3595f9b24faSJung-uk Kim FinalCommentString [CurrentState.SpacesBefore +
3605f9b24faSJung-uk Kim strlen (CommentString) + 3] = 0;
3610d84335fSJung-uk Kim
3620d84335fSJung-uk Kim /* get rid of the carriage return */
3630d84335fSJung-uk Kim
3640d84335fSJung-uk Kim if (FinalCommentString[strlen (FinalCommentString) - 1] == 0x0D)
3650d84335fSJung-uk Kim {
3660d84335fSJung-uk Kim FinalCommentString[strlen(FinalCommentString) - 1] = 0;
3670d84335fSJung-uk Kim }
3685f9b24faSJung-uk Kim
3690d84335fSJung-uk Kim CvPlaceComment (CurrentState.CommentType, FinalCommentString);
3700d84335fSJung-uk Kim }
3710d84335fSJung-uk Kim }
3720d84335fSJung-uk Kim
3730d84335fSJung-uk Kim
3740d84335fSJung-uk Kim /*******************************************************************************
3750d84335fSJung-uk Kim *
3760d84335fSJung-uk Kim * FUNCTION: CgCalculateCommentLengths
3770d84335fSJung-uk Kim *
3780d84335fSJung-uk Kim * PARAMETERS: Op - Calculate all comments of this Op
3790d84335fSJung-uk Kim *
3805f9b24faSJung-uk Kim * RETURN: TotalCommentLength - Length of all comments within this op.
3810d84335fSJung-uk Kim *
3825f9b24faSJung-uk Kim * DESCRIPTION: Calculate the length that the each comment takes up within Op.
383cd6518c7SJung-uk Kim * Comments look like the following: [0xA9 OptionBtye comment 0x00]
3840d84335fSJung-uk Kim * therefore, we add 1 + 1 + strlen (comment) + 1 to get the actual
3850d84335fSJung-uk Kim * length of this comment.
3860d84335fSJung-uk Kim *
3870d84335fSJung-uk Kim ******************************************************************************/
3880d84335fSJung-uk Kim
3890d84335fSJung-uk Kim UINT32
CvCalculateCommentLengths(ACPI_PARSE_OBJECT * Op)3900d84335fSJung-uk Kim CvCalculateCommentLengths(
3910d84335fSJung-uk Kim ACPI_PARSE_OBJECT *Op)
3920d84335fSJung-uk Kim {
3930d84335fSJung-uk Kim UINT32 CommentLength = 0;
3940d84335fSJung-uk Kim UINT32 TotalCommentLength = 0;
3950d84335fSJung-uk Kim ACPI_COMMENT_NODE *Current = NULL;
3960d84335fSJung-uk Kim
3970d84335fSJung-uk Kim
398f1db5ef7SJung-uk Kim if (!AcpiGbl_CaptureComments)
3990d84335fSJung-uk Kim {
4000d84335fSJung-uk Kim return (0);
4010d84335fSJung-uk Kim }
4020d84335fSJung-uk Kim
4035f9b24faSJung-uk Kim CvDbgPrint ("==Calculating comment lengths for %s\n",
4045f9b24faSJung-uk Kim Op->Asl.ParseOpName);
4055f9b24faSJung-uk Kim
4060d84335fSJung-uk Kim if (Op->Asl.FileChanged)
4070d84335fSJung-uk Kim {
4080d84335fSJung-uk Kim TotalCommentLength += strlen (Op->Asl.Filename) + 3;
4090d84335fSJung-uk Kim
4100d84335fSJung-uk Kim if (Op->Asl.ParentFilename &&
4110d84335fSJung-uk Kim AcpiUtStricmp (Op->Asl.Filename, Op->Asl.ParentFilename))
4120d84335fSJung-uk Kim {
4130d84335fSJung-uk Kim TotalCommentLength += strlen (Op->Asl.ParentFilename) + 3;
4140d84335fSJung-uk Kim }
4150d84335fSJung-uk Kim }
4165f9b24faSJung-uk Kim
4170d84335fSJung-uk Kim if (Op->Asl.CommentList)
4180d84335fSJung-uk Kim {
4190d84335fSJung-uk Kim Current = Op->Asl.CommentList;
4200d84335fSJung-uk Kim while (Current)
4210d84335fSJung-uk Kim {
4220d84335fSJung-uk Kim CommentLength = strlen (Current->Comment)+3;
4230d84335fSJung-uk Kim CvDbgPrint ("Length of standard comment: %d\n", CommentLength);
4240d84335fSJung-uk Kim CvDbgPrint (" Comment string: %s\n\n", Current->Comment);
4250d84335fSJung-uk Kim TotalCommentLength += CommentLength;
4260d84335fSJung-uk Kim Current = Current->Next;
4270d84335fSJung-uk Kim }
4280d84335fSJung-uk Kim }
4295f9b24faSJung-uk Kim
4300d84335fSJung-uk Kim if (Op->Asl.EndBlkComment)
4310d84335fSJung-uk Kim {
4320d84335fSJung-uk Kim Current = Op->Asl.EndBlkComment;
4330d84335fSJung-uk Kim while (Current)
4340d84335fSJung-uk Kim {
4350d84335fSJung-uk Kim CommentLength = strlen (Current->Comment)+3;
4360d84335fSJung-uk Kim CvDbgPrint ("Length of endblkcomment: %d\n", CommentLength);
4370d84335fSJung-uk Kim CvDbgPrint (" Comment string: %s\n\n", Current->Comment);
4380d84335fSJung-uk Kim TotalCommentLength += CommentLength;
4390d84335fSJung-uk Kim Current = Current->Next;
4400d84335fSJung-uk Kim }
4410d84335fSJung-uk Kim }
4425f9b24faSJung-uk Kim
4430d84335fSJung-uk Kim if (Op->Asl.InlineComment)
4440d84335fSJung-uk Kim {
4450d84335fSJung-uk Kim CommentLength = strlen (Op->Asl.InlineComment)+3;
4460d84335fSJung-uk Kim CvDbgPrint ("Length of inline comment: %d\n", CommentLength);
4470d84335fSJung-uk Kim CvDbgPrint (" Comment string: %s\n\n", Op->Asl.InlineComment);
4480d84335fSJung-uk Kim TotalCommentLength += CommentLength;
4490d84335fSJung-uk Kim }
4505f9b24faSJung-uk Kim
4510d84335fSJung-uk Kim if (Op->Asl.EndNodeComment)
4520d84335fSJung-uk Kim {
4530d84335fSJung-uk Kim CommentLength = strlen(Op->Asl.EndNodeComment)+3;
4540d84335fSJung-uk Kim CvDbgPrint ("Length of end node comment +3: %d\n", CommentLength);
4550d84335fSJung-uk Kim CvDbgPrint (" Comment string: %s\n\n", Op->Asl.EndNodeComment);
4560d84335fSJung-uk Kim TotalCommentLength += CommentLength;
4570d84335fSJung-uk Kim }
4580d84335fSJung-uk Kim
4590d84335fSJung-uk Kim if (Op->Asl.CloseBraceComment)
4600d84335fSJung-uk Kim {
4610d84335fSJung-uk Kim CommentLength = strlen (Op->Asl.CloseBraceComment)+3;
4620d84335fSJung-uk Kim CvDbgPrint ("Length of close brace comment: %d\n", CommentLength);
4630d84335fSJung-uk Kim CvDbgPrint (" Comment string: %s\n\n", Op->Asl.CloseBraceComment);
4640d84335fSJung-uk Kim TotalCommentLength += CommentLength;
4650d84335fSJung-uk Kim }
4660d84335fSJung-uk Kim
4670d84335fSJung-uk Kim CvDbgPrint("\n\n");
4685f9b24faSJung-uk Kim return (TotalCommentLength);
4690d84335fSJung-uk Kim }
4700d84335fSJung-uk Kim
4710d84335fSJung-uk Kim
4720d84335fSJung-uk Kim /*******************************************************************************
4730d84335fSJung-uk Kim *
4740d84335fSJung-uk Kim * FUNCTION: CgWriteAmlDefBlockComment
4750d84335fSJung-uk Kim *
4760d84335fSJung-uk Kim * PARAMETERS: Op - Current parse op
4770d84335fSJung-uk Kim *
4780d84335fSJung-uk Kim * RETURN: None
4790d84335fSJung-uk Kim *
4800d84335fSJung-uk Kim * DESCRIPTION: Write all comments for a particular definition block.
4810d84335fSJung-uk Kim * For definition blocks, the comments need to come after the
4820d84335fSJung-uk Kim * definition block header. The regular comments above the
4830d84335fSJung-uk Kim * definition block would be categorized as
4840d84335fSJung-uk Kim * STD_DEFBLK_COMMENT and comments after the closing brace
4850d84335fSJung-uk Kim * is categorized as END_DEFBLK_COMMENT.
4860d84335fSJung-uk Kim *
4870d84335fSJung-uk Kim ******************************************************************************/
4880d84335fSJung-uk Kim
4890d84335fSJung-uk Kim void
CgWriteAmlDefBlockComment(ACPI_PARSE_OBJECT * Op)4900d84335fSJung-uk Kim CgWriteAmlDefBlockComment(
4910d84335fSJung-uk Kim ACPI_PARSE_OBJECT *Op)
4920d84335fSJung-uk Kim {
4930d84335fSJung-uk Kim UINT8 CommentOption;
4940d84335fSJung-uk Kim ACPI_COMMENT_NODE *Current;
4950d84335fSJung-uk Kim char *NewFilename;
4960d84335fSJung-uk Kim char *Position;
4970d84335fSJung-uk Kim char *DirectoryPosition;
4980d84335fSJung-uk Kim
4990d84335fSJung-uk Kim
500f1db5ef7SJung-uk Kim if (!AcpiGbl_CaptureComments ||
5010d84335fSJung-uk Kim (Op->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK))
5020d84335fSJung-uk Kim {
5030d84335fSJung-uk Kim return;
5040d84335fSJung-uk Kim }
5050d84335fSJung-uk Kim
5060d84335fSJung-uk Kim CvDbgPrint ("Printing comments for a definition block..\n");
5070d84335fSJung-uk Kim
5085f9b24faSJung-uk Kim /* First, print the file name comment after changing .asl to .dsl */
5090d84335fSJung-uk Kim
51067d9aa44SJung-uk Kim NewFilename = UtLocalCacheCalloc (strlen (Op->Asl.Filename));
5110d84335fSJung-uk Kim strcpy (NewFilename, Op->Asl.Filename);
5120d84335fSJung-uk Kim DirectoryPosition = strrchr (NewFilename, '/');
5130d84335fSJung-uk Kim Position = strrchr (NewFilename, '.');
5140d84335fSJung-uk Kim
5150d84335fSJung-uk Kim if (Position && (Position > DirectoryPosition))
5160d84335fSJung-uk Kim {
5170d84335fSJung-uk Kim /* Tack on the new suffix */
5180d84335fSJung-uk Kim
5190d84335fSJung-uk Kim Position++;
5200d84335fSJung-uk Kim *Position = 0;
5210d84335fSJung-uk Kim strcat (Position, FILE_SUFFIX_DISASSEMBLY);
5220d84335fSJung-uk Kim }
5230d84335fSJung-uk Kim else
5240d84335fSJung-uk Kim {
5250d84335fSJung-uk Kim /* No dot, add one and then the suffix */
5260d84335fSJung-uk Kim
5270d84335fSJung-uk Kim strcat (NewFilename, ".");
5280d84335fSJung-uk Kim strcat (NewFilename, FILE_SUFFIX_DISASSEMBLY);
5290d84335fSJung-uk Kim }
5300d84335fSJung-uk Kim
5310d84335fSJung-uk Kim CommentOption = FILENAME_COMMENT;
5320d84335fSJung-uk Kim CgWriteOneAmlComment(Op, NewFilename, CommentOption);
5330d84335fSJung-uk Kim
5340d84335fSJung-uk Kim Current = Op->Asl.CommentList;
5350d84335fSJung-uk Kim CommentOption = STD_DEFBLK_COMMENT;
5365f9b24faSJung-uk Kim
5370d84335fSJung-uk Kim while (Current)
5380d84335fSJung-uk Kim {
5390d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
5400d84335fSJung-uk Kim CvDbgPrint ("Printing comment: %s\n", Current->Comment);
5410d84335fSJung-uk Kim Current = Current->Next;
5420d84335fSJung-uk Kim }
5435f9b24faSJung-uk Kim
5440d84335fSJung-uk Kim Op->Asl.CommentList = NULL;
5450d84335fSJung-uk Kim
5465f9b24faSJung-uk Kim /* Print any Inline comments associated with this node */
5470d84335fSJung-uk Kim
5480d84335fSJung-uk Kim if (Op->Asl.CloseBraceComment)
5490d84335fSJung-uk Kim {
5500d84335fSJung-uk Kim CommentOption = END_DEFBLK_COMMENT;
5510d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
5520d84335fSJung-uk Kim Op->Asl.CloseBraceComment = NULL;
5530d84335fSJung-uk Kim }
5540d84335fSJung-uk Kim }
5550d84335fSJung-uk Kim
5560d84335fSJung-uk Kim
5570d84335fSJung-uk Kim /*******************************************************************************
5580d84335fSJung-uk Kim *
5590d84335fSJung-uk Kim * FUNCTION: CgWriteOneAmlComment
5600d84335fSJung-uk Kim *
5610d84335fSJung-uk Kim * PARAMETERS: Op - Current parse op
5620d84335fSJung-uk Kim * CommentToPrint - Comment that's printed
5630d84335fSJung-uk Kim * InputOption - Denotes the comment option.
5640d84335fSJung-uk Kim *
5650d84335fSJung-uk Kim * RETURN: None
5660d84335fSJung-uk Kim *
5670d84335fSJung-uk Kim * DESCRIPTION: write a single comment.
5680d84335fSJung-uk Kim *
5690d84335fSJung-uk Kim ******************************************************************************/
5700d84335fSJung-uk Kim
5710d84335fSJung-uk Kim void
CgWriteOneAmlComment(ACPI_PARSE_OBJECT * Op,char * CommentToPrint,UINT8 InputOption)5720d84335fSJung-uk Kim CgWriteOneAmlComment(
5730d84335fSJung-uk Kim ACPI_PARSE_OBJECT *Op,
5740d84335fSJung-uk Kim char* CommentToPrint,
5750d84335fSJung-uk Kim UINT8 InputOption)
5760d84335fSJung-uk Kim {
5770d84335fSJung-uk Kim UINT8 CommentOption = InputOption;
5780d84335fSJung-uk Kim UINT8 CommentOpcode = (UINT8) AML_COMMENT_OP;
5790d84335fSJung-uk Kim
580af051161SJung-uk Kim
581af051161SJung-uk Kim if (!CommentToPrint)
582af051161SJung-uk Kim {
583af051161SJung-uk Kim return;
584af051161SJung-uk Kim }
585af051161SJung-uk Kim
5860d84335fSJung-uk Kim CgLocalWriteAmlData (Op, &CommentOpcode, 1);
5870d84335fSJung-uk Kim CgLocalWriteAmlData (Op, &CommentOption, 1);
5880d84335fSJung-uk Kim
5890d84335fSJung-uk Kim /* The strlen (..) + 1 is to include the null terminator */
5900d84335fSJung-uk Kim
5910d84335fSJung-uk Kim CgLocalWriteAmlData (Op, CommentToPrint, strlen (CommentToPrint) + 1);
5920d84335fSJung-uk Kim }
5930d84335fSJung-uk Kim
5940d84335fSJung-uk Kim
5950d84335fSJung-uk Kim /*******************************************************************************
5960d84335fSJung-uk Kim *
5970d84335fSJung-uk Kim * FUNCTION: CgWriteAmlComment
5980d84335fSJung-uk Kim *
5990d84335fSJung-uk Kim * PARAMETERS: Op - Current parse op
6000d84335fSJung-uk Kim *
6010d84335fSJung-uk Kim * RETURN: None
6020d84335fSJung-uk Kim *
6035f9b24faSJung-uk Kim * DESCRIPTION: Write all comments pertaining to the current parse op
6040d84335fSJung-uk Kim *
6050d84335fSJung-uk Kim ******************************************************************************/
6060d84335fSJung-uk Kim
6070d84335fSJung-uk Kim void
CgWriteAmlComment(ACPI_PARSE_OBJECT * Op)6080d84335fSJung-uk Kim CgWriteAmlComment(
6090d84335fSJung-uk Kim ACPI_PARSE_OBJECT *Op)
6100d84335fSJung-uk Kim {
6110d84335fSJung-uk Kim ACPI_COMMENT_NODE *Current;
6120d84335fSJung-uk Kim UINT8 CommentOption;
6130d84335fSJung-uk Kim char *NewFilename;
6140d84335fSJung-uk Kim char *ParentFilename;
6150d84335fSJung-uk Kim
6160d84335fSJung-uk Kim
6170d84335fSJung-uk Kim if ((Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) ||
618f1db5ef7SJung-uk Kim !AcpiGbl_CaptureComments)
6190d84335fSJung-uk Kim {
6200d84335fSJung-uk Kim return;
6210d84335fSJung-uk Kim }
6220d84335fSJung-uk Kim
6230d84335fSJung-uk Kim /* Print out the filename comment if needed */
6240d84335fSJung-uk Kim
6250d84335fSJung-uk Kim if (Op->Asl.FileChanged)
6260d84335fSJung-uk Kim {
6270d84335fSJung-uk Kim
6285f9b24faSJung-uk Kim /* First, print the file name comment after changing .asl to .dsl */
6290d84335fSJung-uk Kim
6300d84335fSJung-uk Kim NewFilename =
6310d84335fSJung-uk Kim FlGenerateFilename (Op->Asl.Filename, FILE_SUFFIX_DISASSEMBLY);
632af051161SJung-uk Kim if (NewFilename)
633af051161SJung-uk Kim {
6340d84335fSJung-uk Kim CvDbgPrint ("Writing file comment, \"%s\" for %s\n",
6350d84335fSJung-uk Kim NewFilename, Op->Asl.ParseOpName);
636af051161SJung-uk Kim }
637af051161SJung-uk Kim
6380d84335fSJung-uk Kim CgWriteOneAmlComment(Op, NewFilename, FILENAME_COMMENT);
6390d84335fSJung-uk Kim
6400d84335fSJung-uk Kim if (Op->Asl.ParentFilename &&
6410d84335fSJung-uk Kim AcpiUtStricmp (Op->Asl.ParentFilename, Op->Asl.Filename))
6420d84335fSJung-uk Kim {
6430d84335fSJung-uk Kim ParentFilename = FlGenerateFilename (Op->Asl.ParentFilename,
6440d84335fSJung-uk Kim FILE_SUFFIX_DISASSEMBLY);
6450d84335fSJung-uk Kim CgWriteOneAmlComment(Op, ParentFilename, PARENTFILENAME_COMMENT);
6460d84335fSJung-uk Kim }
6470d84335fSJung-uk Kim
6485f9b24faSJung-uk Kim /* Prevent multiple writes of the same comment */
6490d84335fSJung-uk Kim
6500d84335fSJung-uk Kim Op->Asl.FileChanged = FALSE;
6510d84335fSJung-uk Kim }
6520d84335fSJung-uk Kim
6530d84335fSJung-uk Kim /*
6540d84335fSJung-uk Kim * Regular comments are stored in a list of comments within an Op.
6550d84335fSJung-uk Kim * If there is a such list in this node, print out the comment
6560d84335fSJung-uk Kim * as byte code.
6570d84335fSJung-uk Kim */
6580d84335fSJung-uk Kim Current = Op->Asl.CommentList;
6590d84335fSJung-uk Kim if (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)
6600d84335fSJung-uk Kim {
6610d84335fSJung-uk Kim CommentOption = INCLUDE_COMMENT;
6620d84335fSJung-uk Kim }
6630d84335fSJung-uk Kim else
6640d84335fSJung-uk Kim {
6650d84335fSJung-uk Kim CommentOption = STANDARD_COMMENT;
6660d84335fSJung-uk Kim }
6670d84335fSJung-uk Kim
6680d84335fSJung-uk Kim while (Current)
6690d84335fSJung-uk Kim {
6700d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
6710d84335fSJung-uk Kim Current = Current->Next;
6720d84335fSJung-uk Kim }
6735f9b24faSJung-uk Kim
6740d84335fSJung-uk Kim Op->Asl.CommentList = NULL;
6750d84335fSJung-uk Kim
6760d84335fSJung-uk Kim Current = Op->Asl.EndBlkComment;
6770d84335fSJung-uk Kim CommentOption = ENDBLK_COMMENT;
6780d84335fSJung-uk Kim while (Current)
6790d84335fSJung-uk Kim {
6800d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Current->Comment, CommentOption);
6810d84335fSJung-uk Kim Current = Current->Next;
6820d84335fSJung-uk Kim }
6835f9b24faSJung-uk Kim
6840d84335fSJung-uk Kim Op->Asl.EndBlkComment = NULL;
6850d84335fSJung-uk Kim
6865f9b24faSJung-uk Kim /* Print any Inline comments associated with this node */
6870d84335fSJung-uk Kim
6880d84335fSJung-uk Kim if (Op->Asl.InlineComment)
6890d84335fSJung-uk Kim {
6900d84335fSJung-uk Kim CommentOption = INLINE_COMMENT;
6910d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Op->Asl.InlineComment, CommentOption);
6920d84335fSJung-uk Kim Op->Asl.InlineComment = NULL;
6930d84335fSJung-uk Kim }
6940d84335fSJung-uk Kim
6950d84335fSJung-uk Kim if (Op->Asl.EndNodeComment)
6960d84335fSJung-uk Kim {
6970d84335fSJung-uk Kim CommentOption = ENDNODE_COMMENT;
6980d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Op->Asl.EndNodeComment, CommentOption);
6990d84335fSJung-uk Kim Op->Asl.EndNodeComment = NULL;
7000d84335fSJung-uk Kim }
7010d84335fSJung-uk Kim
7020d84335fSJung-uk Kim if (Op->Asl.CloseBraceComment)
7030d84335fSJung-uk Kim {
7040d84335fSJung-uk Kim CommentOption = CLOSE_BRACE_COMMENT;
7050d84335fSJung-uk Kim CgWriteOneAmlComment(Op, Op->Asl.CloseBraceComment, CommentOption);
7060d84335fSJung-uk Kim Op->Asl.CloseBraceComment = NULL;
7070d84335fSJung-uk Kim }
7080d84335fSJung-uk Kim }
7090d84335fSJung-uk Kim
7100d84335fSJung-uk Kim
7110d84335fSJung-uk Kim /*******************************************************************************
7120d84335fSJung-uk Kim *
7130d84335fSJung-uk Kim * FUNCTION: CvCommentNodeCalloc
7140d84335fSJung-uk Kim *
7155f9b24faSJung-uk Kim * PARAMETERS: None
7160d84335fSJung-uk Kim *
7170d84335fSJung-uk Kim * RETURN: Pointer to the comment node. Aborts on allocation failure
7180d84335fSJung-uk Kim *
7190d84335fSJung-uk Kim * DESCRIPTION: Allocate a string node buffer.
7200d84335fSJung-uk Kim *
7210d84335fSJung-uk Kim ******************************************************************************/
7220d84335fSJung-uk Kim
7230d84335fSJung-uk Kim ACPI_COMMENT_NODE *
CvCommentNodeCalloc(void)7240d84335fSJung-uk Kim CvCommentNodeCalloc (
7250d84335fSJung-uk Kim void)
7260d84335fSJung-uk Kim {
7270d84335fSJung-uk Kim ACPI_COMMENT_NODE *NewCommentNode;
7280d84335fSJung-uk Kim
7290d84335fSJung-uk Kim
730af051161SJung-uk Kim NewCommentNode = UtLocalCalloc (sizeof (ACPI_COMMENT_NODE));
7310d84335fSJung-uk Kim NewCommentNode->Next = NULL;
732af051161SJung-uk Kim return (NewCommentNode);
7330d84335fSJung-uk Kim }
7340d84335fSJung-uk Kim
7350d84335fSJung-uk Kim
7360d84335fSJung-uk Kim /*******************************************************************************
7370d84335fSJung-uk Kim *
7380d84335fSJung-uk Kim * FUNCTION: CvParseOpBlockType
7390d84335fSJung-uk Kim *
7400d84335fSJung-uk Kim * PARAMETERS: Op - Object to be examined
7410d84335fSJung-uk Kim *
7420d84335fSJung-uk Kim * RETURN: BlockType - not a block, parens, braces, or even both.
7430d84335fSJung-uk Kim *
7440d84335fSJung-uk Kim * DESCRIPTION: Type of block for this ASL parseop (parens or braces)
7450d84335fSJung-uk Kim * keep this in sync with aslprimaries.y, aslresources.y and
7460d84335fSJung-uk Kim * aslrules.y
7470d84335fSJung-uk Kim *
7480d84335fSJung-uk Kim ******************************************************************************/
7490d84335fSJung-uk Kim
7500d84335fSJung-uk Kim UINT32
CvParseOpBlockType(ACPI_PARSE_OBJECT * Op)7510d84335fSJung-uk Kim CvParseOpBlockType (
7520d84335fSJung-uk Kim ACPI_PARSE_OBJECT *Op)
7530d84335fSJung-uk Kim {
7545f9b24faSJung-uk Kim
7550d84335fSJung-uk Kim if (!Op)
7560d84335fSJung-uk Kim {
7570d84335fSJung-uk Kim return (BLOCK_NONE);
7580d84335fSJung-uk Kim }
7590d84335fSJung-uk Kim
7600d84335fSJung-uk Kim switch (Op->Asl.ParseOpcode)
7610d84335fSJung-uk Kim {
7625f9b24faSJung-uk Kim /* From aslprimaries.y */
7630d84335fSJung-uk Kim
7640d84335fSJung-uk Kim case PARSEOP_VAR_PACKAGE:
7650d84335fSJung-uk Kim case PARSEOP_BANKFIELD:
7660d84335fSJung-uk Kim case PARSEOP_BUFFER:
7670d84335fSJung-uk Kim case PARSEOP_CASE:
7680d84335fSJung-uk Kim case PARSEOP_DEVICE:
7690d84335fSJung-uk Kim case PARSEOP_FIELD:
7700d84335fSJung-uk Kim case PARSEOP_FOR:
7710d84335fSJung-uk Kim case PARSEOP_FUNCTION:
7720d84335fSJung-uk Kim case PARSEOP_IF:
7730d84335fSJung-uk Kim case PARSEOP_ELSEIF:
7740d84335fSJung-uk Kim case PARSEOP_INDEXFIELD:
7750d84335fSJung-uk Kim case PARSEOP_METHOD:
7760d84335fSJung-uk Kim case PARSEOP_POWERRESOURCE:
7770d84335fSJung-uk Kim case PARSEOP_PROCESSOR:
7780d84335fSJung-uk Kim case PARSEOP_DATABUFFER:
7790d84335fSJung-uk Kim case PARSEOP_SCOPE:
7800d84335fSJung-uk Kim case PARSEOP_SWITCH:
7810d84335fSJung-uk Kim case PARSEOP_THERMALZONE:
7820d84335fSJung-uk Kim case PARSEOP_WHILE:
7830d84335fSJung-uk Kim
7845f9b24faSJung-uk Kim /* From aslresources.y */
7850d84335fSJung-uk Kim
7860d84335fSJung-uk Kim case PARSEOP_RESOURCETEMPLATE: /* optional parens */
7870d84335fSJung-uk Kim case PARSEOP_VENDORLONG:
7880d84335fSJung-uk Kim case PARSEOP_VENDORSHORT:
7890d84335fSJung-uk Kim case PARSEOP_INTERRUPT:
7900d84335fSJung-uk Kim case PARSEOP_IRQNOFLAGS:
7910d84335fSJung-uk Kim case PARSEOP_IRQ:
7920d84335fSJung-uk Kim case PARSEOP_GPIO_INT:
7930d84335fSJung-uk Kim case PARSEOP_GPIO_IO:
7940d84335fSJung-uk Kim case PARSEOP_DMA:
7950d84335fSJung-uk Kim
7965f9b24faSJung-uk Kim /* From aslrules.y */
7970d84335fSJung-uk Kim
7980d84335fSJung-uk Kim case PARSEOP_DEFINITION_BLOCK:
7990d84335fSJung-uk Kim return (BLOCK_PAREN | BLOCK_BRACE);
8000d84335fSJung-uk Kim
8010d84335fSJung-uk Kim default:
8020d84335fSJung-uk Kim return (BLOCK_NONE);
8030d84335fSJung-uk Kim }
8040d84335fSJung-uk Kim }
8050d84335fSJung-uk Kim
8060d84335fSJung-uk Kim
8070d84335fSJung-uk Kim /*******************************************************************************
8080d84335fSJung-uk Kim *
8090d84335fSJung-uk Kim * FUNCTION: CvProcessCommentState
8100d84335fSJung-uk Kim *
8115f9b24faSJung-uk Kim * PARAMETERS: Input - Input character
8120d84335fSJung-uk Kim *
8130d84335fSJung-uk Kim * RETURN: None
8140d84335fSJung-uk Kim *
8150d84335fSJung-uk Kim * DESCRIPTION: Take the given input. If this character is
8160d84335fSJung-uk Kim * defined as a comment table entry, then update the state
8170d84335fSJung-uk Kim * accordingly.
8180d84335fSJung-uk Kim *
8190d84335fSJung-uk Kim ******************************************************************************/
8200d84335fSJung-uk Kim
8210d84335fSJung-uk Kim void
CvProcessCommentState(char Input)8220d84335fSJung-uk Kim CvProcessCommentState (
8235f9b24faSJung-uk Kim char Input)
8240d84335fSJung-uk Kim {
8250d84335fSJung-uk Kim
8265f9b24faSJung-uk Kim if (Input != ' ')
8270d84335fSJung-uk Kim {
8286f1f1a63SJung-uk Kim AslGbl_CommentState.SpacesBefore = 0;
8290d84335fSJung-uk Kim }
8300d84335fSJung-uk Kim
8315f9b24faSJung-uk Kim switch (Input)
8320d84335fSJung-uk Kim {
8330d84335fSJung-uk Kim case '\n':
8340d84335fSJung-uk Kim
8356f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
8360d84335fSJung-uk Kim break;
8370d84335fSJung-uk Kim
8380d84335fSJung-uk Kim case ' ':
8390d84335fSJung-uk Kim
8400d84335fSJung-uk Kim /* Keep the CommentType the same */
8410d84335fSJung-uk Kim
8426f1f1a63SJung-uk Kim AslGbl_CommentState.SpacesBefore++;
8430d84335fSJung-uk Kim break;
8440d84335fSJung-uk Kim
8450d84335fSJung-uk Kim case '(':
8460d84335fSJung-uk Kim
8476f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASL_COMMENT_OPEN_PAREN;
8480d84335fSJung-uk Kim break;
8490d84335fSJung-uk Kim
8500d84335fSJung-uk Kim case ')':
8510d84335fSJung-uk Kim
8526f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_PAREN;
8530d84335fSJung-uk Kim break;
8540d84335fSJung-uk Kim
8550d84335fSJung-uk Kim case '{':
8560d84335fSJung-uk Kim
8576f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASL_COMMENT_STANDARD;
8586f1f1a63SJung-uk Kim AslGbl_CommentState.ParsingParenBraceNode = NULL;
8590d84335fSJung-uk Kim CvDbgPrint ("End Parsing paren/Brace node!\n");
8600d84335fSJung-uk Kim break;
8610d84335fSJung-uk Kim
8620d84335fSJung-uk Kim case '}':
8630d84335fSJung-uk Kim
8646f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASL_COMMENT_CLOSE_BRACE;
8650d84335fSJung-uk Kim break;
8660d84335fSJung-uk Kim
8670d84335fSJung-uk Kim case ',':
8680d84335fSJung-uk Kim
8696f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
8700d84335fSJung-uk Kim break;
8710d84335fSJung-uk Kim
8720d84335fSJung-uk Kim default:
8730d84335fSJung-uk Kim
8746f1f1a63SJung-uk Kim AslGbl_CommentState.CommentType = ASLCOMMENT_INLINE;
8750d84335fSJung-uk Kim break;
8760d84335fSJung-uk Kim }
8770d84335fSJung-uk Kim }
8780d84335fSJung-uk Kim
8790d84335fSJung-uk Kim
8800d84335fSJung-uk Kim /*******************************************************************************
8810d84335fSJung-uk Kim *
8820d84335fSJung-uk Kim * FUNCTION: CvAddToCommentList
8830d84335fSJung-uk Kim *
8845f9b24faSJung-uk Kim * PARAMETERS: ToAdd - Contains the comment to be inserted
8850d84335fSJung-uk Kim *
8860d84335fSJung-uk Kim * RETURN: None
8870d84335fSJung-uk Kim *
8880d84335fSJung-uk Kim * DESCRIPTION: Add the given char* to a list of comments in the global list
8890d84335fSJung-uk Kim * of comments.
8900d84335fSJung-uk Kim *
8910d84335fSJung-uk Kim ******************************************************************************/
8920d84335fSJung-uk Kim
8930d84335fSJung-uk Kim void
CvAddToCommentList(char * ToAdd)8940d84335fSJung-uk Kim CvAddToCommentList (
8950d84335fSJung-uk Kim char *ToAdd)
8960d84335fSJung-uk Kim {
8975f9b24faSJung-uk Kim
8986f1f1a63SJung-uk Kim if (AslGbl_CommentListHead)
8990d84335fSJung-uk Kim {
9006f1f1a63SJung-uk Kim AslGbl_CommentListTail->Next = CvCommentNodeCalloc ();
9016f1f1a63SJung-uk Kim AslGbl_CommentListTail = AslGbl_CommentListTail->Next;
9020d84335fSJung-uk Kim }
9030d84335fSJung-uk Kim else
9040d84335fSJung-uk Kim {
9056f1f1a63SJung-uk Kim AslGbl_CommentListHead = CvCommentNodeCalloc ();
9066f1f1a63SJung-uk Kim AslGbl_CommentListTail = AslGbl_CommentListHead;
9070d84335fSJung-uk Kim }
9080d84335fSJung-uk Kim
9096f1f1a63SJung-uk Kim AslGbl_CommentListTail->Comment = ToAdd;
9100d84335fSJung-uk Kim }
9110d84335fSJung-uk Kim
9125f9b24faSJung-uk Kim
9130d84335fSJung-uk Kim /*******************************************************************************
9140d84335fSJung-uk Kim *
9150d84335fSJung-uk Kim * FUNCTION: CvAppendInlineComment
9160d84335fSJung-uk Kim *
9170d84335fSJung-uk Kim * PARAMETERS: InlineComment - Append to the end of this string.
9180d84335fSJung-uk Kim * toAdd - Contains the comment to be inserted
9190d84335fSJung-uk Kim *
9200d84335fSJung-uk Kim * RETURN: Str - toAdd appended to InlineComment
9210d84335fSJung-uk Kim *
9220d84335fSJung-uk Kim * DESCRIPTION: Concatenate ToAdd to InlineComment
9230d84335fSJung-uk Kim *
9240d84335fSJung-uk Kim ******************************************************************************/
9250d84335fSJung-uk Kim
9260d84335fSJung-uk Kim char *
CvAppendInlineComment(char * InlineComment,char * ToAdd)9270d84335fSJung-uk Kim CvAppendInlineComment (
9280d84335fSJung-uk Kim char *InlineComment,
9290d84335fSJung-uk Kim char *ToAdd)
9300d84335fSJung-uk Kim {
9310d84335fSJung-uk Kim char* Str;
9320d84335fSJung-uk Kim UINT32 Size = 0;
9330d84335fSJung-uk Kim
9340d84335fSJung-uk Kim
9350d84335fSJung-uk Kim if (!InlineComment)
9360d84335fSJung-uk Kim {
9375f9b24faSJung-uk Kim return (ToAdd);
9380d84335fSJung-uk Kim }
9395f9b24faSJung-uk Kim
940af051161SJung-uk Kim if (!ToAdd)
9410d84335fSJung-uk Kim {
9425f9b24faSJung-uk Kim return (InlineComment);
9430d84335fSJung-uk Kim }
944af051161SJung-uk Kim
945af051161SJung-uk Kim Size = strlen (ToAdd);
9460d84335fSJung-uk Kim Size += strlen (InlineComment);
94767d9aa44SJung-uk Kim Str = UtLocalCacheCalloc (Size + 1);
9485f9b24faSJung-uk Kim
9490d84335fSJung-uk Kim strcpy (Str, InlineComment);
9500d84335fSJung-uk Kim strcat (Str, ToAdd);
9510d84335fSJung-uk Kim Str[Size +1] = 0;
9525f9b24faSJung-uk Kim return (Str);
9530d84335fSJung-uk Kim }
9540d84335fSJung-uk Kim
9550d84335fSJung-uk Kim
9560d84335fSJung-uk Kim /*******************************************************************************
9570d84335fSJung-uk Kim *
9580d84335fSJung-uk Kim * FUNCTION: CvPlaceComment
9590d84335fSJung-uk Kim *
9605f9b24faSJung-uk Kim * PARAMETERS: UINT8 - Type
9610d84335fSJung-uk Kim * char * - CommentString
9620d84335fSJung-uk Kim *
9630d84335fSJung-uk Kim * RETURN: None
9640d84335fSJung-uk Kim *
9650d84335fSJung-uk Kim * DESCRIPTION: Given type and CommentString, this function places the
966cd6518c7SJung-uk Kim * CommentString in the appropriate global comment list or char*
9670d84335fSJung-uk Kim *
9680d84335fSJung-uk Kim ******************************************************************************/
9690d84335fSJung-uk Kim
9700d84335fSJung-uk Kim void
CvPlaceComment(UINT8 Type,char * CommentString)9710d84335fSJung-uk Kim CvPlaceComment(
9720d84335fSJung-uk Kim UINT8 Type,
9730d84335fSJung-uk Kim char *CommentString)
9740d84335fSJung-uk Kim {
9750d84335fSJung-uk Kim ACPI_PARSE_OBJECT *LatestParseNode;
9760d84335fSJung-uk Kim ACPI_PARSE_OBJECT *ParenBraceNode;
9770d84335fSJung-uk Kim
9780d84335fSJung-uk Kim
9796f1f1a63SJung-uk Kim LatestParseNode = AslGbl_CommentState.LatestParseOp;
9806f1f1a63SJung-uk Kim ParenBraceNode = AslGbl_CommentState.ParsingParenBraceNode;
9810d84335fSJung-uk Kim CvDbgPrint ("Placing comment %s for type %d\n", CommentString, Type);
9820d84335fSJung-uk Kim
9830d84335fSJung-uk Kim switch (Type)
9840d84335fSJung-uk Kim {
9850d84335fSJung-uk Kim case ASL_COMMENT_STANDARD:
9860d84335fSJung-uk Kim
9870d84335fSJung-uk Kim CvAddToCommentList (CommentString);
9880d84335fSJung-uk Kim break;
9890d84335fSJung-uk Kim
9900d84335fSJung-uk Kim case ASLCOMMENT_INLINE:
9910d84335fSJung-uk Kim
9920d84335fSJung-uk Kim LatestParseNode->Asl.InlineComment =
9930d84335fSJung-uk Kim CvAppendInlineComment (LatestParseNode->Asl.InlineComment,
9940d84335fSJung-uk Kim CommentString);
9950d84335fSJung-uk Kim break;
9960d84335fSJung-uk Kim
9970d84335fSJung-uk Kim case ASL_COMMENT_OPEN_PAREN:
9980d84335fSJung-uk Kim
9996f1f1a63SJung-uk Kim AslGbl_InlineCommentBuffer =
10006f1f1a63SJung-uk Kim CvAppendInlineComment(AslGbl_InlineCommentBuffer,
10010d84335fSJung-uk Kim CommentString);
10020d84335fSJung-uk Kim break;
10030d84335fSJung-uk Kim
10040d84335fSJung-uk Kim case ASL_COMMENT_CLOSE_PAREN:
10050d84335fSJung-uk Kim
10060d84335fSJung-uk Kim if (ParenBraceNode)
10070d84335fSJung-uk Kim {
10080d84335fSJung-uk Kim ParenBraceNode->Asl.EndNodeComment =
10090d84335fSJung-uk Kim CvAppendInlineComment (ParenBraceNode->Asl.EndNodeComment,
10100d84335fSJung-uk Kim CommentString);
10110d84335fSJung-uk Kim }
10120d84335fSJung-uk Kim else
10130d84335fSJung-uk Kim {
10140d84335fSJung-uk Kim LatestParseNode->Asl.EndNodeComment =
10150d84335fSJung-uk Kim CvAppendInlineComment (LatestParseNode->Asl.EndNodeComment,
10160d84335fSJung-uk Kim CommentString);
10170d84335fSJung-uk Kim }
10180d84335fSJung-uk Kim break;
10190d84335fSJung-uk Kim
10200d84335fSJung-uk Kim case ASL_COMMENT_CLOSE_BRACE:
10210d84335fSJung-uk Kim
10220d84335fSJung-uk Kim LatestParseNode->Asl.CloseBraceComment = CommentString;
10230d84335fSJung-uk Kim break;
10240d84335fSJung-uk Kim
10250d84335fSJung-uk Kim default:
10260d84335fSJung-uk Kim
10270d84335fSJung-uk Kim break;
10280d84335fSJung-uk Kim }
10290d84335fSJung-uk Kim }
1030