pswalk.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: pswalk - Parser routines to walk parsed op tree(s)
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acparser.h"
  12. #define _COMPONENT ACPI_PARSER
  13. ACPI_MODULE_NAME("pswalk")
  14. /*******************************************************************************
  15. *
  16. * FUNCTION: acpi_ps_delete_parse_tree
  17. *
  18. * PARAMETERS: subtree_root - Root of tree (or subtree) to delete
  19. *
  20. * RETURN: None
  21. *
  22. * DESCRIPTION: Delete a portion of or an entire parse tree.
  23. *
  24. ******************************************************************************/
  25. #include "amlcode.h"
  26. void acpi_ps_delete_parse_tree(union acpi_parse_object *subtree_root)
  27. {
  28. union acpi_parse_object *op = subtree_root;
  29. union acpi_parse_object *next = NULL;
  30. union acpi_parse_object *parent = NULL;
  31. u32 level = 0;
  32. ACPI_FUNCTION_TRACE_PTR(ps_delete_parse_tree, subtree_root);
  33. ACPI_DEBUG_PRINT((ACPI_DB_PARSE_TREES, " root %p\n", subtree_root));
  34. /* Visit all nodes in the subtree */
  35. while (op) {
  36. if (op != parent) {
  37. /* This is the descending case */
  38. if (ACPI_IS_DEBUG_ENABLED
  39. (ACPI_LV_PARSE_TREES, _COMPONENT)) {
  40. /* This debug option will print the entire parse tree */
  41. acpi_os_printf(" %*.s%s %p", (level * 4),
  42. " ",
  43. acpi_ps_get_opcode_name(op->
  44. common.
  45. aml_opcode),
  46. op);
  47. if (op->named.aml_opcode == AML_INT_NAMEPATH_OP) {
  48. acpi_os_printf(" %4.4s",
  49. op->common.value.string);
  50. }
  51. if (op->named.aml_opcode == AML_STRING_OP) {
  52. acpi_os_printf(" %s",
  53. op->common.value.string);
  54. }
  55. acpi_os_printf("\n");
  56. }
  57. /* Look for an argument or child of the current op */
  58. next = acpi_ps_get_arg(op, 0);
  59. if (next) {
  60. /* Still going downward in tree (Op is not completed yet) */
  61. op = next;
  62. level++;
  63. continue;
  64. }
  65. }
  66. /* No more children, this Op is complete. */
  67. next = op->common.next;
  68. parent = op->common.parent;
  69. acpi_ps_free_op(op);
  70. /* If we are back to the starting point, the walk is complete. */
  71. if (op == subtree_root) {
  72. return_VOID;
  73. }
  74. if (next) {
  75. op = next;
  76. } else {
  77. level--;
  78. op = parent;
  79. }
  80. }
  81. return_VOID;
  82. }