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