Skip to content

Commit

Permalink
Update compiler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
timofey260 authored Dec 20, 2021
1 parent 3f9cd0b commit 5db90b1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
marks = {}
constants = {}
registers0 = ["REG0", "REG1", "REG2", "REG3", "REG4", "REG5", "COUNTER", "INP", "OUT"]
registers1 = ["REG0", "REG1", "REG2", "REG3", "REG4", "REG5", "REG6", "REG7", "REG8", "REG9", "REG10", "REG11", "REG12", "REG13", "COUNTER", "INP", "OUT"]
registers1 = ["REG0", "REG1", "REG2", "REG3", "REG4", "REG5", "REG6", "REG7", "REG8", "REG9", "REG10", "REG11", "REG12",
"REG13", "COUNTER", "INP", "OUT"]
registers2 = ["REG" + str(i) for i in range(30)]
registers2.append("COUNTER")
registers2.append("INP")
registers2.append("OUT")
registers = registers0
operators = ["=", "!=", "<", "<=", ">", ">="]
inst = []
Expand Down Expand Up @@ -56,6 +61,9 @@ def getr(var: str):
case str(registers1):
if d == "00010000":
d = "00001111"
case str(registers2):
if d == "00100000":
d = "00011111"
except ValueError:
ext("Error: wrong TimCPU version!")
return d
Expand Down Expand Up @@ -99,7 +107,10 @@ def cmp(code: list[str,]): # code compiler
case "ORII":
thrnums(line, "000011")
case "NOTI":
thrnums(line, "000100")
OPCODE = f"{codp(line[1], '0')}000100"
ARG1 = getvar(line[1])
ARG2 = zero
RESULT = getr(line[2])
case "XORI":
thrnums(line, "000101")
case "SFTL":
Expand Down Expand Up @@ -205,11 +216,12 @@ def help():
print("-ma: memeory addon")
print("-o: output file")
print("-c: current counter position, default: 0")
print("-v: number of TimCPU version (0 - original(default), 1 - mini)")
print("-v: number of TimCPU version (0 - original(default), 1 - mini, 2 - mega)")
print("-h: help")
print("Arguments: file")
ext()


if len(sys.argv) == 1: # if you just launch app
help()

Expand All @@ -235,6 +247,8 @@ def help():
registers = registers0
case "1":
registers = registers1
case "2":
registers = registers2
count += 1

try:
Expand Down

0 comments on commit 5db90b1

Please sign in to comment.