Path: blob/main/sys/contrib/dev/acpica/compiler/aslparseop.c
48373 views
/******************************************************************************1*2* Module Name: aslparseop - Parse op create/allocate/cache interfaces3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/compiler/aslcompiler.h>152#include "aslcompiler.y.h"153#include <contrib/dev/acpica/include/acapps.h>154#include <contrib/dev/acpica/include/acconvert.h>155156#define _COMPONENT ACPI_COMPILER157ACPI_MODULE_NAME ("aslparseop")158159160/*******************************************************************************161*162* FUNCTION: TrCreateOp163*164* PARAMETERS: ParseOpcode - Opcode to be assigned to the op165* NumChildren - Number of children to follow166* ... - A list of child ops to link to the new167* op. NumChildren long.168*169* RETURN: Pointer to the new op. Aborts on allocation failure170*171* DESCRIPTION: Create a new parse op and link together a list of child172* ops underneath the new op.173*174******************************************************************************/175176ACPI_PARSE_OBJECT *177TrCreateOp (178UINT32 ParseOpcode,179UINT32 NumChildren,180...)181{182ACPI_PARSE_OBJECT *Op;183ACPI_PARSE_OBJECT *Child;184ACPI_PARSE_OBJECT *PrevChild;185va_list ap;186UINT32 i;187BOOLEAN FirstChild;188189190va_start (ap, NumChildren);191192/* Allocate one new op */193194Op = TrAllocateOp (ParseOpcode);195196DbgPrint (ASL_PARSE_OUTPUT,197"\nCreateOp Ln/Col %u/%u NewParent %p Child %u Op %s ",198Op->Asl.LineNumber, Op->Asl.Column, Op,199NumChildren, UtGetOpName(ParseOpcode));200201/* Some extra debug output based on the parse opcode */202203switch (ParseOpcode)204{205case PARSEOP_ASL_CODE:206207AslGbl_ParseTreeRoot = Op;208Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;209DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");210break;211212case PARSEOP_DEFINITION_BLOCK:213214DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");215break;216217case PARSEOP_OPERATIONREGION:218219DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");220break;221222case PARSEOP_OR:223224DbgPrint (ASL_PARSE_OUTPUT, "OR->");225break;226227default:228229/* Nothing to do for other opcodes */230231break;232}233234/* Link the new op to its children */235236PrevChild = NULL;237FirstChild = TRUE;238for (i = 0; i < NumChildren; i++)239{240/* Get the next child */241242Child = va_arg (ap, ACPI_PARSE_OBJECT *);243DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);244245/*246* If child is NULL, this means that an optional argument247* was omitted. We must create a placeholder with a special248* opcode (DEFAULT_ARG) so that the code generator will know249* that it must emit the correct default for this argument250*/251if (!Child)252{253Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);254}255256/* Link first child to parent */257258if (FirstChild)259{260FirstChild = FALSE;261Op->Asl.Child = Child;262263/*264* For the ASL-/ASL+ converter: if the ParseOp is a Connection,265* External, Offset or AccessAs, it means that the comments in the266* FirstChild belongs to their parent due to the parsing order in267* the .y files. To correct this, take the comments in the268* FirstChild place it in the parent. This also means that269* legitimate comments for the child gets put to the parent.270*/271if (AcpiGbl_CaptureComments &&272((ParseOpcode == PARSEOP_CONNECTION) ||273(ParseOpcode == PARSEOP_EXTERNAL) ||274(ParseOpcode == PARSEOP_OFFSET) ||275(ParseOpcode == PARSEOP_ACCESSAS)))276{277Op->Asl.CommentList = Child->Asl.CommentList;278Op->Asl.EndBlkComment = Child->Asl.EndBlkComment;279Op->Asl.InlineComment = Child->Asl.InlineComment;280Op->Asl.FileChanged = Child->Asl.FileChanged;281282Child->Asl.CommentList = NULL;283Child->Asl.EndBlkComment = NULL;284Child->Asl.InlineComment = NULL;285Child->Asl.FileChanged = FALSE;286287/*288* These do not need to be "passed off". They can be copied289* because the code for these opcodes should be printed in the290* same file.291*/292Op->Asl.Filename = Child->Asl.Filename;293Op->Asl.ParentFilename = Child->Asl.ParentFilename;294}295}296297/* Point all children to parent */298299Child->Asl.Parent = Op;300301/* Link children in a peer list */302303if (PrevChild)304{305PrevChild->Asl.Next = Child;306};307308/* Get the comment from last child in the resource template call */309310if (AcpiGbl_CaptureComments &&311(Op->Asl.ParseOpcode == PARSEOP_RESOURCETEMPLATE))312{313CvDbgPrint ("Transferred current comment list to this op.\n");314Op->Asl.CommentList = Child->Asl.CommentList;315Child->Asl.CommentList = NULL;316317Op->Asl.InlineComment = Child->Asl.InlineComment;318Child->Asl.InlineComment = NULL;319}320321/*322* This child might be a list, point all ops in the list323* to the same parent324*/325while (Child->Asl.Next)326{327Child = Child->Asl.Next;328Child->Asl.Parent = Op;329}330331PrevChild = Child;332}333334va_end(ap);335DbgPrint (ASL_PARSE_OUTPUT, "\n");336return (Op);337}338339340/*******************************************************************************341*342* FUNCTION: TrCreateLeafOp343*344* PARAMETERS: ParseOpcode - New opcode to be assigned to the op345*346* RETURN: Pointer to the new op. Aborts on allocation failure347*348* DESCRIPTION: Create a simple leaf op (no children or peers, and no value349* assigned to the op)350*351******************************************************************************/352353ACPI_PARSE_OBJECT *354TrCreateLeafOp (355UINT32 ParseOpcode)356{357ACPI_PARSE_OBJECT *Op;358359360Op = TrAllocateOp (ParseOpcode);361362DbgPrint (ASL_PARSE_OUTPUT,363"\nCreateLeafOp Ln/Col %u/%u NewOp %p Op %s\n\n",364Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode));365366return (Op);367}368369370/*******************************************************************************371*372* FUNCTION: TrCreateValuedLeafOp373*374* PARAMETERS: ParseOpcode - New opcode to be assigned to the op375* Value - Value to be assigned to the op376*377* RETURN: Pointer to the new op. Aborts on allocation failure378*379* DESCRIPTION: Create a leaf op (no children or peers) with a value380* assigned to it381*382******************************************************************************/383384ACPI_PARSE_OBJECT *385TrCreateValuedLeafOp (386UINT32 ParseOpcode,387UINT64 Value)388{389ACPI_PARSE_OBJECT *Op;390UINT32 i;391char *StringPtr = NULL;392393394Op = TrAllocateOp (ParseOpcode);395Op->Asl.Value.Integer = Value;396397DbgPrint (ASL_PARSE_OUTPUT,398"\nCreateValuedLeafOp Ln/Col %u/%u NewOp %p "399"Op %s Value %8.8X%8.8X ",400Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode),401ACPI_FORMAT_UINT64 (Value));402403switch (ParseOpcode)404{405case PARSEOP_STRING_LITERAL:406407DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Op->Asl.Value.String);408break;409410case PARSEOP_NAMESEG:411412/* Check for mixed case (or all lower case). Issue a remark in this case */413414for (i = 0; i < ACPI_NAMESEG_SIZE; i++)415{416if (islower ((int) Op->Asl.Value.Name[i]))417{418AcpiUtStrupr (&Op->Asl.Value.Name[i]);419AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMESEG, Op, Op->Asl.Value.Name);420break;421}422}423DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Op->Asl.Value.String);424break;425426case PARSEOP_NAMESTRING:427428/* Check for mixed case (or all lower case). Issue a remark in this case */429430StringPtr = Op->Asl.Value.Name;431for (i = 0; *StringPtr; i++)432{433if (islower ((int) *StringPtr))434{435AcpiUtStrupr (&Op->Asl.Value.Name[i]);436AslError (ASL_REMARK, ASL_MSG_LOWER_CASE_NAMEPATH, Op, Op->Asl.Value.Name);437break;438}439StringPtr++;440}441DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Op->Asl.Value.String);442break;443444case PARSEOP_EISAID:445446DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Op->Asl.Value.String);447break;448449case PARSEOP_METHOD:450451DbgPrint (ASL_PARSE_OUTPUT, "METHOD");452break;453454case PARSEOP_INTEGER:455456DbgPrint (ASL_PARSE_OUTPUT, "INTEGER->%8.8X%8.8X",457ACPI_FORMAT_UINT64 (Value));458break;459460default:461break;462}463464DbgPrint (ASL_PARSE_OUTPUT, "\n\n");465return (Op);466}467468469/*******************************************************************************470*471* FUNCTION: TrCreateTargetOp472*473* PARAMETERS: OriginalOp - Op to be copied474*475* RETURN: Pointer to the new op. Aborts on allocation failure476*477* DESCRIPTION: Copy an existing op (and subtree). Used in ASL+ (C-style)478* expressions where the target is the same as one of the479* operands. A new op and subtree must be created from the480* original so that the parse tree can be linked properly.481*482* NOTE: This code is specific to target operands that are the last483* operand in an ASL/AML operator. Meaning that the top-level484* parse Op in a possible subtree has a NULL Next pointer.485* This simplifies the recursion.486*487* Subtree example:488* DeRefOf (Local1) += 32489*490* This gets converted to:491* Add (DeRefOf (Local1), 32, DeRefOf (Local1))492*493* Each DeRefOf has a single child, Local1. Even more complex494* subtrees can be created via the Index and DeRefOf operators.495*496******************************************************************************/497498ACPI_PARSE_OBJECT *499TrCreateTargetOp (500ACPI_PARSE_OBJECT *OriginalOp,501ACPI_PARSE_OBJECT *ParentOp)502{503ACPI_PARSE_OBJECT *Op;504505506if (!OriginalOp)507{508return (NULL);509}510511Op = UtParseOpCacheCalloc ();512513/* Copy the pertinent values (omit link pointer fields) */514515Op->Asl.Value = OriginalOp->Asl.Value;516Op->Asl.Filename = OriginalOp->Asl.Filename;517Op->Asl.LineNumber = OriginalOp->Asl.LineNumber;518Op->Asl.LogicalLineNumber = OriginalOp->Asl.LogicalLineNumber;519Op->Asl.LogicalByteOffset = OriginalOp->Asl.LogicalByteOffset;520Op->Asl.Column = OriginalOp->Asl.Column;521Op->Asl.Flags = OriginalOp->Asl.Flags;522Op->Asl.CompileFlags = OriginalOp->Asl.CompileFlags;523Op->Asl.AmlOpcode = OriginalOp->Asl.AmlOpcode;524Op->Asl.ParseOpcode = OriginalOp->Asl.ParseOpcode;525Op->Asl.Parent = ParentOp;526527UtSetParseOpName (Op);528529/* Copy a possible subtree below this op */530531if (OriginalOp->Asl.Child)532{533Op->Asl.Child = TrCreateTargetOp (OriginalOp->Asl.Child, Op);534}535536if (OriginalOp->Asl.Next) /* Null for top-level op */537{538Op->Asl.Next = TrCreateTargetOp (OriginalOp->Asl.Next, ParentOp);539}540541return (Op);542}543544545/*******************************************************************************546*547* FUNCTION: TrCreateAssignmentOp548*549* PARAMETERS: Target - Assignment target550* Source - Assignment source551*552* RETURN: Pointer to the new op. Aborts on allocation failure553*554* DESCRIPTION: Implements the C-style '=' operator. It changes the parse555* tree if possible to utilize the last argument of the math556* operators which is a target operand -- thus saving invocation557* of and additional Store() operator. An optimization.558*559******************************************************************************/560561ACPI_PARSE_OBJECT *562TrCreateAssignmentOp (563ACPI_PARSE_OBJECT *Target,564ACPI_PARSE_OBJECT *Source)565{566ACPI_PARSE_OBJECT *TargetOp;567ACPI_PARSE_OBJECT *SourceOp1;568ACPI_PARSE_OBJECT *SourceOp2;569ACPI_PARSE_OBJECT *Operator;570571572DbgPrint (ASL_PARSE_OUTPUT,573"\nTrCreateAssignmentOp Line [%u to %u] Source %s Target %s\n",574Source->Asl.LineNumber, Source->Asl.EndLine,575UtGetOpName (Source->Asl.ParseOpcode),576UtGetOpName (Target->Asl.ParseOpcode));577578TrSetOpFlags (Target, OP_IS_TARGET);579580switch (Source->Asl.ParseOpcode)581{582/*583* Only these operators can be optimized because they have584* a target operand585*/586case PARSEOP_ADD:587case PARSEOP_AND:588case PARSEOP_DIVIDE:589case PARSEOP_INDEX:590case PARSEOP_MOD:591case PARSEOP_MULTIPLY:592case PARSEOP_NOT:593case PARSEOP_OR:594case PARSEOP_SHIFTLEFT:595case PARSEOP_SHIFTRIGHT:596case PARSEOP_SUBTRACT:597case PARSEOP_XOR:598599break;600601/* Otherwise, just create a normal Store operator */602603default:604goto CannotOptimize;605}606607/*608* Transform the parse tree such that the target is moved to the609* last operand of the operator610*/611SourceOp1 = Source->Asl.Child;612SourceOp2 = SourceOp1->Asl.Next;613614/* NOT only has one operand, but has a target */615616if (Source->Asl.ParseOpcode == PARSEOP_NOT)617{618SourceOp2 = SourceOp1;619}620621/* DIVIDE has an extra target operand (remainder) */622623if (Source->Asl.ParseOpcode == PARSEOP_DIVIDE)624{625SourceOp2 = SourceOp2->Asl.Next;626}627628TargetOp = SourceOp2->Asl.Next;629630/*631* Can't perform this optimization if there already is a target632* for the operator (ZERO is a "no target" placeholder).633*/634if (TargetOp->Asl.ParseOpcode != PARSEOP_ZERO)635{636goto CannotOptimize;637}638639/* Link in the target as the final operand */640641SourceOp2->Asl.Next = Target;642Target->Asl.Parent = Source;643return (Source);644645646CannotOptimize:647648Operator = TrAllocateOp (PARSEOP_STORE);649TrLinkOpChildren (Operator, 2, Source, Target);650651/* Set the appropriate line numbers for the new op */652653Operator->Asl.LineNumber = Target->Asl.LineNumber;654Operator->Asl.LogicalLineNumber = Target->Asl.LogicalLineNumber;655Operator->Asl.LogicalByteOffset = Target->Asl.LogicalByteOffset;656Operator->Asl.Column = Target->Asl.Column;657658return (Operator);659}660661662/*******************************************************************************663*664* FUNCTION: TrCreateNullTargetOp665*666* PARAMETERS: None667*668* RETURN: Pointer to the new op. Aborts on allocation failure669*670* DESCRIPTION: Create a "null" target op. This is defined by the ACPI671* specification to be a zero AML opcode, and indicates that672* no target has been specified for the parent operation673*674******************************************************************************/675676ACPI_PARSE_OBJECT *677TrCreateNullTargetOp (678void)679{680ACPI_PARSE_OBJECT *Op;681682683Op = TrAllocateOp (PARSEOP_ZERO);684Op->Asl.CompileFlags |= (OP_IS_TARGET | OP_COMPILE_TIME_CONST);685686DbgPrint (ASL_PARSE_OUTPUT,687"\nCreateNullTargetOp Ln/Col %u/%u NewOp %p Op %s\n",688Op->Asl.LineNumber, Op->Asl.Column, Op,689UtGetOpName (Op->Asl.ParseOpcode));690691return (Op);692}693694695/*******************************************************************************696*697* FUNCTION: TrCreateConstantLeafOp698*699* PARAMETERS: ParseOpcode - The constant opcode700*701* RETURN: Pointer to the new op. Aborts on allocation failure702*703* DESCRIPTION: Create a leaf op (no children or peers) for one of the704* special constants - __LINE__, __FILE__, and __DATE__.705*706* Note: The fullimplemenation of __METHOD__ cannot happen here because we707* don't have a full parse tree at this time and cannot find the parent708* control method. __METHOD__ must be implemented later, after the parse709* tree has been fully constructed.710*711******************************************************************************/712713ACPI_PARSE_OBJECT *714TrCreateConstantLeafOp (715UINT32 ParseOpcode)716{717ACPI_PARSE_OBJECT *Op = NULL;718time_t CurrentTime;719char *StaticTimeString;720char *TimeString;721char *Filename = NULL;722ACPI_STATUS Status;723724725switch (ParseOpcode)726{727case PARSEOP___LINE__:728729Op = TrAllocateOp (PARSEOP_INTEGER);730Op->Asl.Value.Integer = Op->Asl.LineNumber;731break;732733case PARSEOP___METHOD__:734735/* Will become a string literal later */736737Op = TrAllocateOp (PARSEOP___METHOD__);738Op->Asl.Value.String = NULL;739break;740741case PARSEOP___PATH__:742743Op = TrAllocateOp (PARSEOP_STRING_LITERAL);744745/* Op.Asl.Filename contains the full pathname to the file */746747Op->Asl.Value.String = Op->Asl.Filename;748break;749750case PARSEOP___FILE__:751752Op = TrAllocateOp (PARSEOP_STRING_LITERAL);753754/* Get the simple filename from the full path */755756Status = FlSplitInputPathname (Op->Asl.Filename, NULL, &Filename);757if (ACPI_FAILURE (Status))758{759return (NULL);760}761762Op->Asl.Value.String = Filename;763break;764765case PARSEOP___DATE__:766767Op = TrAllocateOp (PARSEOP_STRING_LITERAL);768769/* Get a copy of the current time */770771Op->Asl.Value.String = "";772CurrentTime = time (NULL);773774StaticTimeString = ctime (&CurrentTime);775if (StaticTimeString)776{777TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1);778strcpy (TimeString, StaticTimeString);779780TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */781Op->Asl.Value.String = TimeString;782}783break;784785default: /* This would be an internal error */786787return (NULL);788}789790DbgPrint (ASL_PARSE_OUTPUT,791"\nCreateConstantLeafOp Ln/Col %u/%u NewOp %p "792"Op %s Value %8.8X%8.8X\n",793Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode),794ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));795796return (Op);797}798799800/*******************************************************************************801*802* FUNCTION: TrAllocateOp803*804* PARAMETERS: ParseOpcode - Opcode to be assigned to the op805*806* RETURN: New parse op. Aborts on allocation failure807*808* DESCRIPTION: Allocate and initialize a new parse op for the parse tree809*810******************************************************************************/811812ACPI_PARSE_OBJECT *813TrAllocateOp (814UINT32 ParseOpcode)815{816ACPI_PARSE_OBJECT *Op;817ACPI_PARSE_OBJECT *LatestOp;818819ACPI_FUNCTION_NAME (TrAllocateOp);820821822Op = UtParseOpCacheCalloc ();823824Op->Asl.ParseOpcode = (UINT16) ParseOpcode;825Op->Asl.Filename = AslGbl_Files[ASL_FILE_INPUT].Filename;826Op->Asl.LineNumber = AslGbl_CurrentLineNumber;827Op->Asl.LogicalLineNumber = AslGbl_LogicalLineNumber;828Op->Asl.LogicalByteOffset = AslGbl_CurrentLineOffset;829Op->Asl.Column = AslGbl_CurrentColumn;830831UtSetParseOpName (Op);832833/* The following is for capturing comments */834835if (AcpiGbl_CaptureComments)836{837LatestOp = AslGbl_CommentState.LatestParseOp;838Op->Asl.InlineComment = NULL;839Op->Asl.EndNodeComment = NULL;840Op->Asl.CommentList = NULL;841Op->Asl.FileChanged = FALSE;842843/*844* Check to see if the file name has changed before resetting the845* latest parse op.846*/847if (LatestOp &&848(ParseOpcode != PARSEOP_INCLUDE) &&849(ParseOpcode != PARSEOP_INCLUDE_END) &&850strcmp (LatestOp->Asl.Filename, Op->Asl.Filename))851{852CvDbgPrint ("latest op: %s\n", LatestOp->Asl.ParseOpName);853Op->Asl.FileChanged = TRUE;854if (AslGbl_IncludeFileStack)855{856Op->Asl.ParentFilename = AslGbl_IncludeFileStack->Filename;857}858else859{860Op->Asl.ParentFilename = NULL;861}862}863864AslGbl_CommentState.LatestParseOp = Op;865CvDbgPrint ("%s=Set latest parse op to this op.\n", ACPI_GET_FUNCTION_NAME);866CvDbgPrint (" Op->Asl.ParseOpName = %s\n",867AslGbl_CommentState.LatestParseOp->Asl.ParseOpName);868CvDbgPrint (" Op->Asl.ParseOpcode = 0x%x\n", ParseOpcode);869870if (Op->Asl.FileChanged)871{872CvDbgPrint(" file has been changed!\n");873}874875/*876* if this parse op's syntax uses () and {} (i.e. Package(1){0x00}) then877* set a flag in the comment state. This facilitates paring comments for878* these types of opcodes.879*/880if ((CvParseOpBlockType(Op) == (BLOCK_PAREN | BLOCK_BRACE)) &&881(ParseOpcode != PARSEOP_DEFINITION_BLOCK))882{883CvDbgPrint ("Parsing paren/Brace op now!\n");884AslGbl_CommentState.ParsingParenBraceNode = Op;885}886887if (AslGbl_CommentListHead)888{889CvDbgPrint ("Transferring...\n");890Op->Asl.CommentList = AslGbl_CommentListHead;891AslGbl_CommentListHead = NULL;892AslGbl_CommentListTail = NULL;893CvDbgPrint (" Transferred current comment list to this op.\n");894CvDbgPrint (" %s\n", Op->Asl.CommentList->Comment);895}896897if (AslGbl_InlineCommentBuffer)898{899Op->Asl.InlineComment = AslGbl_InlineCommentBuffer;900AslGbl_InlineCommentBuffer = NULL;901CvDbgPrint ("Transferred current inline comment list to this op.\n");902}903}904905return (Op);906}907908909/*******************************************************************************910*911* FUNCTION: TrPrintOpFlags912*913* PARAMETERS: Flags - Flags word to be decoded914* OutputLevel - Debug output level: ASL_TREE_OUTPUT etc.915*916* RETURN: None917*918* DESCRIPTION: Decode a flags word to text. Displays all flags that are set.919*920******************************************************************************/921922void923TrPrintOpFlags (924UINT32 Flags,925UINT32 OutputLevel)926{927UINT32 FlagBit = 1;928UINT32 i;929930931for (i = 0; i < ACPI_NUM_OP_FLAGS; i++)932{933if (Flags & FlagBit)934{935DbgPrint (OutputLevel, " %s", AslGbl_OpFlagNames[i]);936}937938FlagBit <<= 1;939}940}941942943