1 /******************************************************************************
3 * Module Name: aslprune - Parse tree prune utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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"
48 #define _COMPONENT ACPI_COMPILER
49 ACPI_MODULE_NAME ("aslprune")
52 /* Local prototypes */
56 ACPI_PARSE_OBJECT *Op,
61 PrPrintObjectAtLevel (
63 const char *ObjectName);
66 /* Structure used for the pruning parse tree walk */
68 typedef struct acpi_prune_info
77 /*******************************************************************************
79 * FUNCTION: AslPruneParseTree
81 * PARAMETERS: PruneDepth - Number of levels to prune
82 * Type - Prune type (Device, Method, etc.)
86 * DESCRIPTION: Prune off one or more levels of the ASL parse tree
88 ******************************************************************************/
95 ACPI_PRUNE_INFO PruneObj;
98 PruneObj.PruneLevel = PruneDepth;
104 PruneObj.ParseOpcode = (UINT16) PARSEOP_DEVICE;
108 PruneObj.ParseOpcode = (UINT16) PARSEOP_METHOD;
112 PruneObj.ParseOpcode = (UINT16) PARSEOP_IF;
116 AcpiOsPrintf ("Unsupported type: %u\n", Type);
120 AcpiOsPrintf ("Pruning parse tree, from depth %u\n",
123 AcpiOsPrintf ("\nRemoving Objects:\n");
125 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
126 PrTreePruneWalk, NULL, ACPI_CAST_PTR (void, &PruneObj));
128 AcpiOsPrintf ("\n%u Total Objects Removed\n", PruneObj.Count);
132 /*******************************************************************************
134 * FUNCTION: PrPrintObjectAtLevel
136 * PARAMETERS: Level - Current nesting level
137 * ObjectName - ACPI name for the object
141 * DESCRIPTION: Print object name with indent
143 ******************************************************************************/
146 PrPrintObjectAtLevel (
148 const char *ObjectName)
153 for (i = 0; i < Level; i++)
158 AcpiOsPrintf ("[%s] at Level [%u]\n", ObjectName, Level);
162 /*******************************************************************************
164 * FUNCTION: PrTreePruneWalk
166 * PARAMETERS: Parse tree walk callback
170 * DESCRIPTION: Prune off one or more levels of the ASL parse tree
172 * Current objects that can be pruned are: Devices, Methods, and If/Else
175 ******************************************************************************/
179 ACPI_PARSE_OBJECT *Op,
183 ACPI_PRUNE_INFO *PruneObj = (ACPI_PRUNE_INFO *) Context;
186 /* We only care about objects below the Prune Level threshold */
188 if (Level <= PruneObj->PruneLevel)
193 if ((Op->Asl.ParseOpcode != PruneObj->ParseOpcode) &&
194 !(Op->Asl.ParseOpcode == PARSEOP_ELSE &&
195 PruneObj->ParseOpcode == PARSEOP_IF))
200 switch (Op->Asl.ParseOpcode)
204 AcpiOsPrintf ("Method");
205 PrPrintObjectAtLevel (Level, Op->Asl.Child->Asl.Value.Name);
206 Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next->Asl.Next->Asl.Next->Asl.Next = NULL;
212 AcpiOsPrintf ("Device");
213 PrPrintObjectAtLevel (Level, Op->Asl.Child->Asl.Value.Name);
214 Op->Asl.Child->Asl.Next = NULL;
221 if (Op->Asl.ParseOpcode == PARSEOP_ELSE)
223 PrPrintObjectAtLevel(Level, "Else");
224 Op->Asl.Child = NULL;
228 PrPrintObjectAtLevel(Level, "If");
229 Op->Asl.Child->Asl.Next = NULL;