Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 1 | import sys |
| 2 | import getopt |
| 3 | |
| 4 | from compiler import compile, visitor |
| 5 | |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame^] | 6 | import profile |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 7 | |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 8 | def main(): |
| 9 | VERBOSE = 0 |
Jeremy Hylton | e7f710c | 2000-10-13 21:59:32 +0000 | [diff] [blame] | 10 | DISPLAY = 0 |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame^] | 11 | PROFILE = 0 |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 12 | CONTINUE = 0 |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame^] | 13 | opts, args = getopt.getopt(sys.argv[1:], 'vqdcp') |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 14 | for k, v in opts: |
| 15 | if k == '-v': |
| 16 | VERBOSE = 1 |
| 17 | visitor.ASTVisitor.VERBOSE = visitor.ASTVisitor.VERBOSE + 1 |
| 18 | if k == '-q': |
Jeremy Hylton | 0a4f1ff | 2000-05-02 22:29:46 +0000 | [diff] [blame] | 19 | if sys.platform[:3]=="win": |
| 20 | f = open('nul', 'wb') # /dev/null fails on Windows... |
| 21 | else: |
| 22 | f = open('/dev/null', 'wb') |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 23 | sys.stdout = f |
Jeremy Hylton | e7f710c | 2000-10-13 21:59:32 +0000 | [diff] [blame] | 24 | if k == '-d': |
| 25 | DISPLAY = 1 |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 26 | if k == '-c': |
| 27 | CONTINUE = 1 |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame^] | 28 | if k == '-p': |
| 29 | PROFILE = 1 |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 30 | if not args: |
| 31 | print "no files to compile" |
| 32 | else: |
| 33 | for filename in args: |
| 34 | if VERBOSE: |
| 35 | print filename |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 36 | try: |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame^] | 37 | if PROFILE: |
| 38 | profile.run('compile(%s, %s)' % (`filename`, `DISPLAY`), |
| 39 | filename + ".prof") |
| 40 | else: |
| 41 | compile(filename, DISPLAY) |
| 42 | |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 43 | except SyntaxError, err: |
| 44 | print err |
| 45 | print err.lineno |
| 46 | if not CONTINUE: |
| 47 | sys.exit(-1) |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 48 | |
| 49 | if __name__ == "__main__": |
| 50 | main() |