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