forked from mkst/mwccgap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmwccgap.py
More file actions
executable file
·75 lines (58 loc) · 2.33 KB
/
mwccgap.py
File metadata and controls
executable file
·75 lines (58 loc) · 2.33 KB
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
import argparse
import sys
import traceback
import tempfile
from pathlib import Path
from mwccgap.mwccgap import process_c_file
def main() -> None:
parser = argparse.ArgumentParser()
read_from_file = sys.stdin.isatty()
if not read_from_file:
in_lines = sys.stdin.readlines()
if len(in_lines) == 0:
read_from_file = True
if read_from_file:
parser.add_argument("c_file", type=Path)
parser.add_argument("o_file", type=Path)
parser.add_argument("--mwcc-path", type=Path, default=Path("mwccpsp.exe"))
parser.add_argument("--as-path", type=Path, default=Path("mipsel-linux-gnu-as"))
parser.add_argument("--as-march", type=str, default="allegrex")
parser.add_argument("--as-mabi", type=str, default="32")
parser.add_argument("--use-wibo", action="store_true")
parser.add_argument("--wibo-path", type=Path, default=Path("wibo"))
parser.add_argument("--asm-dir-prefix", type=Path)
parser.add_argument("--macro-inc-path", type=Path)
parser.add_argument("--target-encoding", type=str)
args, c_flags = parser.parse_known_args()
as_flags = ["-G0"] # TODO: base this on -sdatathreshold value from c_flags
try:
with tempfile.NamedTemporaryFile(suffix=".c") as temp_c_file:
c_file = args.c_file if read_from_file else Path(temp_c_file.name)
if not read_from_file:
temp_c_file.writelines([x.encode("utf") for x in in_lines])
temp_c_file.flush()
process_c_file(
c_file,
args.o_file,
c_flags,
mwcc_path=args.mwcc_path,
as_path=args.as_path,
as_march=args.as_march,
as_mabi=args.as_mabi,
use_wibo=args.use_wibo,
wibo_path=args.wibo_path,
as_flags=as_flags,
asm_dir_prefix=args.asm_dir_prefix,
macro_inc_path=args.macro_inc_path,
c_file_encoding=args.target_encoding,
)
except Exception as e:
sys.stderr.write(f"Exception processing {c_file.name}: {e}\n")
sys.stderr.write(traceback.format_exc())
sys.stderr.write("\n")
# cleanup
args.o_file.unlink(missing_ok=True)
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main()