Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 1 | import sys |
| 2 | import getopt |
| 3 | |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame^] | 4 | from compiler import compileFile, visitor |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 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: |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame^] | 38 | profile.run('compileFile(%s, %s)' % (`filename`, |
| 39 | `DISPLAY`), |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame] | 40 | filename + ".prof") |
| 41 | else: |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame^] | 42 | compileFile(filename, DISPLAY) |
Jeremy Hylton | bf80a03 | 2001-09-17 18:08:40 +0000 | [diff] [blame] | 43 | |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 44 | except SyntaxError, err: |
| 45 | print err |
Jeremy Hylton | 5d1e34a | 2001-09-17 21:31:35 +0000 | [diff] [blame^] | 46 | if err.lineno is not None: |
| 47 | print err.lineno |
Jeremy Hylton | 33c2a62 | 2001-08-27 20:39:21 +0000 | [diff] [blame] | 48 | if not CONTINUE: |
| 49 | sys.exit(-1) |
Jeremy Hylton | 0c3208a | 2000-03-06 19:13:21 +0000 | [diff] [blame] | 50 | |
| 51 | if __name__ == "__main__": |
| 52 | main() |