/Tools/compiler/compile.py

http://unladen-swallow.googlecode.com/ · Python · 51 lines · 46 code · 5 blank · 0 comment · 19 complexity · 42b99420e248d15942f4c776b420ba2a MD5 · raw file

  1. import sys
  2. import getopt
  3. from compiler import compileFile, visitor
  4. import profile
  5. def main():
  6. VERBOSE = 0
  7. DISPLAY = 0
  8. PROFILE = 0
  9. CONTINUE = 0
  10. opts, args = getopt.getopt(sys.argv[1:], 'vqdcp')
  11. for k, v in opts:
  12. if k == '-v':
  13. VERBOSE = 1
  14. visitor.ASTVisitor.VERBOSE = visitor.ASTVisitor.VERBOSE + 1
  15. if k == '-q':
  16. if sys.platform[:3]=="win":
  17. f = open('nul', 'wb') # /dev/null fails on Windows...
  18. else:
  19. f = open('/dev/null', 'wb')
  20. sys.stdout = f
  21. if k == '-d':
  22. DISPLAY = 1
  23. if k == '-c':
  24. CONTINUE = 1
  25. if k == '-p':
  26. PROFILE = 1
  27. if not args:
  28. print "no files to compile"
  29. else:
  30. for filename in args:
  31. if VERBOSE:
  32. print filename
  33. try:
  34. if PROFILE:
  35. profile.run('compileFile(%r, %r)' % (filename, DISPLAY),
  36. filename + ".prof")
  37. else:
  38. compileFile(filename, DISPLAY)
  39. except SyntaxError, err:
  40. print err
  41. if err.lineno is not None:
  42. print err.lineno
  43. if not CONTINUE:
  44. sys.exit(-1)
  45. if __name__ == "__main__":
  46. main()