-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
87 lines (64 loc) · 2.09 KB
/
Main.py
File metadata and controls
87 lines (64 loc) · 2.09 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
76
77
78
79
80
81
82
83
84
85
86
from Computer import *
from Debugger import *
from Preprocessor import *
from Assembler import *
from Compiler import *
from Exceptions import PreprocessorError, AssemblerError, CompilerError, ExcecutionError
from Cpu import *
import sys
# python -m mypy Main.py
def Run(source: str, debug: bool):
try:
prog = Program(source)
preproc = Preprocessor()
preproc.preprocess(prog)
# for l in prog.preprocessed:
# print(l)
assembler = Assembler()
assembler.assemble(prog)
# for l in prog.labels:
# print(l, f" Position: {l.position}")
# for i in prog.instructions:
# print(i, f" Position: {i.position} Label: {i.labelName}")
# for p in i.parameters:
# print(" ", p, end = "")
# if p.labelName != None:
# print(f" {p.labelName}")
# else:
# print("")
# for b in prog.binary:
# print("%04X " % b, end = "")
# print("")
computer = Computer()
computer.loadProgram(prog)
if debug == False:
computer.run()
for l in prog.labels:
if l.size > 0:
print("%13s (%6s[%3d]): " % (l.name, l.datatype, l.size), end ="")
for i in range(l.position, l.position + l.size):
print("%d " % computer.memory[i], end = "")
print("")
else:
debugger = Debugger(computer, prog)
debugger.run()
except PreprocessorError as e:
print(e)
except AssemblerError as e:
print(e)
except CompilerError as e:
print(e)
except Exception as e:
raise e
if __name__ == "__main__":
useDebugger = False
source = None
for i, arg in enumerate(sys.argv):
if arg == "--debug":
useDebugger = True
elif arg[-5:] == ".iasm":
source = arg
if source == None:
print("Usage: python Main.py <source> [--debug]")
else:
Run(source, useDebugger)