-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompile.py
executable file
·107 lines (94 loc) · 2.39 KB
/
compile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import sys
import os.path
import argparse
import sh
def compile_project(quit_pdb, optimize, jit, debug, output):
target_path = os.path.join(
os.path.dirname(__file__),
"src/target.py"
)
args = {
"opt": optimize,
"gc": "incminimark",
"output": output,
}
if jit:
args["translation-jit"] = True
# args["translation-jit_profiler"] = True
if debug:
args["lldebug"] = True
args["lldebug0"] = True
if quit_pdb:
args["batch"] = True
rpython_path = "rpython"
if "RPYTHON_PATH" in os.environ:
rpython_path = os.path.join(
os.environ["RPYTHON_PATH"],
"rpython"
)
try:
rpython = sh.Command(rpython_path)
except sh.CommandNotFound:
raise ValueError(
"rpython not found!\n\nPut it into $PATH or use $RPYTHON_PATH env "
"variable to specify it."
)
try:
rpython(args, target_path, _fg=True)
except sh.ErrorReturnCode_1:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
"-q",
"--quit-pdb",
action="store_true",
help=(
"Jump out of the PDB shell in case there was an error in "
"compilation."
)
)
default_level = 1
parser.add_argument(
"-O",
"--optimize",
default=default_level,
metavar="LEVEL",
type=int,
help="Level of optimization. Default %d." % default_level
)
default_name = "tSelf"
parser.add_argument(
"-r",
"--output",
default=default_name,
metavar="NAME",
help="Name of the output file. Default %s." % default_name
)
parser.add_argument(
"-j",
"--jit",
action="store_true",
help="Add support for JIT. Warning: really, slow compilation."
)
parser.add_argument(
"-d",
"--debug",
action="store_true",
help="Add debug informations into the binary."
)
args = parser.parse_args()
try:
compile_project(
args.quit_pdb,
args.optimize,
args.jit,
args.debug,
args.output,
)
except Exception as e:
sys.stderr.write(e.message + "\n")
sys.exit(1)