b43-beautifier 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python
  2. """
  3. # b43 firmware assembly code beautifier
  4. #
  5. # Copyright (C) 2008-2010 Michael Buesch <m@bues.ch>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 3
  9. # as published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. import getopt
  20. import sys
  21. from libb43 import *
  22. def usage():
  23. print "b43 firmware assembly code beautifier"
  24. print ""
  25. print "Copyright (C) 2008 Michael Buesch <m@bues.ch>"
  26. print "Licensed under the GNU/GPL version 3"
  27. print ""
  28. print "Usage: b43-beautifier [OPTIONS]"
  29. print ""
  30. print "-h|--help Print this help text"
  31. print "-a|--asmfile [FILE] Assembly code source file"
  32. print "-d|--defs [DIR] Directory containing the defs files"
  33. print ""
  34. print "The options -d and -a are essential."
  35. print "The \"include\" directory can be used for --defs"
  36. def parseArgs():
  37. global opt_asmfile
  38. global opt_defsfiles
  39. opt_asmfile = None
  40. opt_defsfiles = None
  41. try:
  42. (opts, args) = getopt.getopt(sys.argv[1:],
  43. "ha:d:",
  44. [ "help", "asmfile=", "defs=" ])
  45. except getopt.GetoptError:
  46. usage()
  47. sys.exit(1)
  48. for (o, v) in opts:
  49. if o in ("-h", "--help"):
  50. usage()
  51. sys.exit(0)
  52. if o in ("-a", "--asmfile"):
  53. opt_asmfile = v
  54. if o in ("-d", "--defs"):
  55. opt_defsfiles = v
  56. if not opt_asmfile:
  57. print "Must provide --asmfile"
  58. sys.exit(1)
  59. if not opt_defsfiles:
  60. print "Must provide --defs"
  61. sys.exit(1)
  62. def main():
  63. parseArgs()
  64. try:
  65. asm = file(opt_asmfile).read()
  66. except IOError, e:
  67. print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
  68. return 1
  69. try:
  70. b = B43Beautifier(asm, opt_defsfiles)
  71. sys.stdout.write(b.getAsm())
  72. except B43Exception:
  73. return 1
  74. return 0
  75. if __name__ == "__main__":
  76. sys.exit(main())