1 /******************************************************************************
3 * Module Name: aslprune - Parse tree prune utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/acapps.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 typedef struct acpi_prune_info
75 /*******************************************************************************
77 * FUNCTION: AslPruneParseTree
79 * PARAMETERS: PruneDepth - Number of levels to prune
80 * Type - Prune type (Device, Method, etc.)
84 * DESCRIPTION: Prune off one or more levels of the ASL parse tree
86 ******************************************************************************/
93 ACPI_PRUNE_INFO PruneObj;
96 PruneObj.PruneLevel = PruneDepth;
102 PruneObj.ParseOpcode = (UINT16) PARSEOP_DEVICE;
106 PruneObj.ParseOpcode = (UINT16) PARSEOP_METHOD;
110 PruneObj.ParseOpcode = (UINT16) PARSEOP_IF;
114 AcpiOsPrintf ("Unsupported type: %u\n", Type);
118 AcpiOsPrintf ("Pruning parse tree, from depth %u\n",
121 AcpiOsPrintf ("\nRemoving Objects:\n");
123 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
124 PrTreePruneWalk, NULL, ACPI_CAST_PTR (void, &PruneObj));
126 AcpiOsPrintf ("\n%u Total Objects Removed\n", PruneObj.Count);
130 /*******************************************************************************
132 * FUNCTION: PrPrintObjectAtLevel
134 * PARAMETERS: Level - Current nesting level
135 * ObjectName - ACPI name for the object
139 * DESCRIPTION: Print object name with indent
141 ******************************************************************************/
144 PrPrintObjectAtLevel (
146 const char *ObjectName)
151 for (i = 0; i < Level; i++)
156 AcpiOsPrintf ("[%s] at Level [%u]\n", ObjectName, Level);
160 /*******************************************************************************
162 * FUNCTION: PrTreePruneWalk
164 * PARAMETERS: Parse tree walk callback
168 * DESCRIPTION: Prune off one or more levels of the ASL parse tree
170 * Current objects that can be pruned are: Devices, Methods, and If/Else
173 ******************************************************************************/
177 ACPI_PARSE_OBJECT *Op,
181 ACPI_PRUNE_INFO *PruneObj = (ACPI_PRUNE_INFO *) Context;
184 /* We only care about objects below the Prune Level threshold */
186 if (Level <= PruneObj->PruneLevel)
191 if ((Op->Asl.ParseOpcode != PruneObj->ParseOpcode) &&
192 !(Op->Asl.ParseOpcode == PARSEOP_ELSE &&
193 PruneObj->ParseOpcode == PARSEOP_IF))
198 switch (Op->Asl.ParseOpcode)
202 AcpiOsPrintf ("Method");
203 PrPrintObjectAtLevel (Level, Op->Asl.Child->Asl.Value.Name);
204 Op->Asl.Child->Asl.Next->Asl.Next->Asl.Next->Asl.Next->Asl.Next->Asl.Next = NULL;
210 AcpiOsPrintf ("Device");
211 PrPrintObjectAtLevel (Level, Op->Asl.Child->Asl.Value.Name);
212 Op->Asl.Child->Asl.Next = NULL;
219 if (Op->Asl.ParseOpcode == PARSEOP_ELSE)
221 PrPrintObjectAtLevel(Level, "Else");
222 Op->Asl.Child = NULL;
226 PrPrintObjectAtLevel(Level, "If");
227 Op->Asl.Child->Asl.Next = NULL;