-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
39 lines (31 loc) · 1.11 KB
/
main.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
from hwc.hplio import loadProgram, writeAssembly, writeWhitespace
from hwc.compiler import compileProgram
from hwc.whitespace import translateAssembly
from sys import argv
def printUsage():
message = '\n'
message += " HaPyLi -> Whitespace Compiler \n"
message += " By Kevin Gundlach \n"
message += "Usage: python main.py [-asm] <input file> <output file>\n"
print(message)
if __name__ == "__main__":
if len(argv) == 3:
inputFile = argv[1]
outputFile = argv[2]
asmFlag = False
elif len(argv) == 4:
option = argv[1]
inputFile = argv[2]
outputFile = argv[3]
asmFlag = (option == "-asm")
else:
printUsage()
exit()
program = loadProgram(inputFile)
assembly = compileProgram(program)
if asmFlag:
writeAssembly(outputFile, assembly)
else:
whitespace = translateAssembly(assembly)
writeWhitespace(outputFile, whitespace)
print("Success!")