-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompile.py
More file actions
52 lines (47 loc) · 1.63 KB
/
compile.py
File metadata and controls
52 lines (47 loc) · 1.63 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
import os
import sys
srcPath = ""
exePath = "~/.config/sharkc/sharkc"
fileFormat = "macho64"
output = "a.out"
i = 1
while i < len(sys.argv):
arg = sys.argv[i]
if arg == "-f" or arg == "--format":
i += 1
fileFormat = sys.argv[i]
elif arg == "-o" or arg == "--output":
i += 1
output = sys.argv[i]
elif arg == "-h" or arg == "--help":
os.system(exePath + "-h")
exit(0)
elif arg == "-m" or arg == "--mir":
os.system(exePath + " " + srcPath + " -m")
exit(0)
elif arg == "-i" or arg == "--ir":
os.system(exePath + " " + srcPath + " -i")
exit(0)
elif arg == "-a" or arg == "--ast":
os.system(exePath + " " + srcPath + " -a")
exit(0)
elif arg == "-t" or arg == "--tokens":
os.system(exePath + " " + srcPath + " -t")
exit(0)
else:
srcPath = sys.argv[i]
i += 1
asmOutput = "~/.config/sharkc/{}.asm".format(output)
objOutput = "~/.config/sharkc/{}.o".format(output)
if os.system("{} {} -f {} -o {}".format(exePath, srcPath, fileFormat, asmOutput)) != 0:
os.system("rm -f {} {}".format(asmOutput, objOutput))
exit(101)
if os.system("nasm {} -f {} -o {}".format(asmOutput, fileFormat, objOutput)) != 0:
os.system("rm -f {} {}".format(asmOutput, objOutput))
exit(102)
if os.system("gcc -no-pie {} -o {} > /dev/null 2>&1".format(objOutput, output)) != 0:
print("linker exits with a non-zero exit code:")
os.system("gcc -no-pie {} -o {}".format(objOutput, output))
os.system("rm -f {} {}".format(asmOutput, objOutput))
exit(102)
os.system("rm -f {} {}".format(asmOutput, objOutput))