2
0

acpi_extract_preprocess.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python
  2. # Copyright (C) 2011 Red Hat, Inc., Michael S. Tsirkin <mst@redhat.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program; if not, see <http://www.gnu.org/licenses/>.
  16. # Read a preprocessed ASL listing and put each ACPI_EXTRACT
  17. # directive in a comment, to make iasl skip it.
  18. # We also put each directive on a new line, the machinery
  19. # in tools/acpi_extract.py requires this.
  20. import re;
  21. import sys;
  22. import fileinput;
  23. def die(diag):
  24. sys.stderr.write("Error: %s\n" % (diag))
  25. sys.exit(1)
  26. # Note: () around pattern make split return matched string as part of list
  27. psplit = re.compile(r''' (
  28. \b # At word boundary
  29. ACPI_EXTRACT_\w+ # directive
  30. \s+ # some whitespace
  31. \w+ # array name
  32. )''', re.VERBOSE);
  33. lineno = 0
  34. for line in fileinput.input():
  35. # line number and debug string to output in case of errors
  36. lineno = lineno + 1
  37. debug = "input line %d: %s" % (lineno, line.rstrip())
  38. s = psplit.split(line);
  39. # The way split works, each odd item is the matching ACPI_EXTRACT directive.
  40. # Put each in a comment, and on a line by itself.
  41. for i in range(len(s)):
  42. if (i % 2):
  43. sys.stdout.write("\n/* %s */\n" % s[i])
  44. else:
  45. sys.stdout.write(s[i])