compile.py 1.41 KB
Newer Older
1 2 3
import sys
import getopt

4
from compiler import compileFile, visitor
5

6
import profile
7

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

if __name__ == "__main__":
    main()