Compare commits

..

No commits in common. "30d2d7577d4beeeba1174301f67e2c290e49ee6e" and "b3d75a1a465034e7e50920cd4f5ae47389db790a" have entirely different histories.

8 changed files with 88 additions and 80 deletions

View file

@ -7,9 +7,10 @@ CFLAGS=-Wall -g
OBJ=yacc.tab.o lex.yy.o table.o operations.o blocs.o asmTable.o OBJ=yacc.tab.o lex.yy.o table.o operations.o blocs.o asmTable.o
asm: $(BIN) all: $(BIN)
@touch testFile # to prevent an error in case of deletion @touch testFile # to prevent an error in case of deletion
./out < testFile ./out < testFile
build: $(BIN) build: $(BIN)
@ -28,9 +29,3 @@ $(BIN): $(OBJ)
clean: clean:
rm $(OBJ) yacc.tab.c yacc.tab.h lex.yy.c rm $(OBJ) yacc.tab.c yacc.tab.h lex.yy.c
vhdl: clean asm
python3 post-process.py
inter: clean asm
python3 graph_interpreter.py

37
asm
View file

@ -1,13 +1,24 @@
AFC 1 5 AFC 5 0
COP 0 1 COP 0 5
AFC 1 8 AFC 5 20
EQ 2 0 1 COP 1 5
NOT 3 2 AFC 5 0
JMF 3 13 COP 3 5
AFC 4 20 AFC 5 1
INF 2 0 4 COP 4 5
JMF 2 13 ADD 5 3 4
AFC 1 2 COP 2 5
ADD 4 0 1 AFC 5 3
COP 0 4 SUB 6 1 5
JMP 6 COP 1 6
SUP 5 0 1
NOT 6 5
JMF 6 24
COP 3 4
COP 4 2
ADD 5 3 4
COP 2 5
AFC 5 1
ADD 6 0 5
COP 0 6
JMP 13

69
asm2
View file

@ -1,31 +1,58 @@
AFC 0 5 AFC 0 0
STORE 1 0 STORE 5 0
LOAD 0 1 LOAD 0 5
STORE 0 0 STORE 0 0
AFC 0 8
STORE 1 0
LOAD 0 0
LOAD 1 1
EQ 2 1 0
STORE 2 2
LOAD 0 2
NOT 2 0
STORE 3 2
JMF 3 30
AFC 0 20 AFC 0 20
STORE 5 0
LOAD 0 5
STORE 1 0
AFC 0 0
STORE 5 0
LOAD 0 5
STORE 3 0
AFC 0 1
STORE 5 0
LOAD 0 5
STORE 4 0 STORE 4 0
LOAD 0 0 LOAD 0 3
LOAD 1 4 LOAD 1 4
INF 2 0 1 ADD 0 0 1
STORE 2 2 STORE 5 0
JMF 2 30 LOAD 0 5
AFC 0 2 STORE 2 0
AFC 0 3
STORE 5 0
LOAD 0 1
LOAD 1 5
SUB 0 0 1
STORE 6 0
LOAD 0 6
STORE 1 0 STORE 1 0
LOAD 0 0 LOAD 0 0
LOAD 1 1 LOAD 1 1
ADD 0 0 1 SUP 2 1 0
STORE 4 0 STORE 5 2
LOAD 0 5
NOT 2 0
STORE 6 2
JMF 6 57
LOAD 0 4 LOAD 0 4
STORE 3 0
LOAD 0 2
STORE 4 0
LOAD 0 3
LOAD 1 4
ADD 0 0 1
STORE 5 0
LOAD 0 5
STORE 2 0
AFC 0 1
STORE 5 0
LOAD 0 0
LOAD 1 5
ADD 0 0 1
STORE 6 0
LOAD 0 6
STORE 0 0 STORE 0 0
JMP 14 JMP 30
NOP NOP

2
asm3
View file

@ -1 +1 @@
((x"06000500"),(x"08010000"),(x"07000100"),(x"08000000"),(x"06000800"),(x"08010000"),(x"07000000"),(x"07010100"),(x"0B020100"),(x"08020200"),(x"07000200"),(x"0C020000"),(x"08030200"),(x"10031E00"),(x"06001400"),(x"08040000"),(x"07000000"),(x"07010400"),(x"09020001"),(x"08020200"),(x"10021E00"),(x"06000200"),(x"08010000"),(x"07000000"),(x"07010100"),(x"01000001"),(x"08040000"),(x"07000400"),(x"08000000"),(x"0F0E0000"),(x"FF000000"),others => (x"ff000000")) ((x"06000000"),(x"08050000"),(x"07000500"),(x"08000000"),(x"06001400"),(x"08050000"),(x"07000500"),(x"08010000"),(x"06000000"),(x"08050000"),(x"07000500"),(x"08030000"),(x"06000100"),(x"08050000"),(x"07000500"),(x"08040000"),(x"07000300"),(x"07010400"),(x"01000001"),(x"08050000"),(x"07000500"),(x"08020000"),(x"06000300"),(x"08050000"),(x"07000100"),(x"07010500"),(x"03000001"),(x"08060000"),(x"07000600"),(x"08010000"),(x"07000000"),(x"07010100"),(x"0A020100"),(x"08050200"),(x"07000500"),(x"0C020000"),(x"08060200"),(x"10063900"),(x"07000400"),(x"08030000"),(x"07000200"),(x"08040000"),(x"07000300"),(x"07010400"),(x"01000001"),(x"08050000"),(x"07000500"),(x"08020000"),(x"06000100"),(x"08050000"),(x"07000000"),(x"07010500"),(x"01000001"),(x"08060000"),(x"07000600"),(x"08000000"),(x"0F1E0000"),(x"FF000000"),others => (x"ff000000"))

View file

@ -1,15 +1,9 @@
import sys import sys
from textual.color import Color
from textual import events
try: from textual.app import App, ComposeResult
from textual.color import Color from textual.containers import Container, VerticalScroll
from textual import events from textual.widgets import Footer, Header, Static
from textual.app import App, ComposeResult
from textual.containers import Container, VerticalScroll
from textual.widgets import Footer, Header, Static
except:
print("please install textual and rich !")
def getLinesToShow(ip, lines): def getLinesToShow(ip, lines):
if ip > 1 and ip + 2 < len(lines): if ip > 1 and ip + 2 < len(lines):

View file

@ -131,7 +131,7 @@ int cond_sup(int addr1, int addr2){
int cond_eq(int addr1, int addr2) { int cond_eq(int addr1, int addr2) {
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "EQ %d %d %d", addr, addr1, addr2); sprintf(s, "EQU %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }

View file

@ -75,59 +75,44 @@ def convertToRegister(s):
case "JMP": case "JMP":
l.append(" ".join(s)) l.append(" ".join(s))
case "JMF": case "JMF":
if len(s) == 3: l.append(" ".join(s))
l.append(" ".join(s))
else :
l.append(s[0]+ " 0 " + s[1])
case "INF": case "INF":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("LOAD 1 " + s[3 + incr]) l.append("LOAD 1 " + s[3 + incr])
l.append("INF 2 0 1") l.append("INF 2 0 1")
l.append("STORE " + s[1 + incr] + " 2")
case "SUP": case "SUP":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("LOAD 1 " + s[3 + incr]) l.append("LOAD 1 " + s[3 + incr])
l.append("SUP 2 1 0") l.append("SUP 2 1 0")
l.append("STORE " + s[1 + incr] + " 2")
case "EQ": case "EQ":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("LOAD 1 " + s[3 + incr]) l.append("LOAD 1 " + s[3 + incr])
l.append("EQ 2 1 0") l.append("EQ 2 1 0")
l.append("STORE " + s[1 + incr] + " 2")
case "PRI": case "PRI":
l.append(optionalFlag + "PRI " + s[2 + incr]) l.append(optionalFlag + "PRI " + s[2 + incr])
case "AND": case "AND":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("LOAD 1 " + s[3 + incr]) l.append("LOAD 1 " + s[3 + incr])
l.append("AND 2 0 1") l.append("AND 2 0 1")
l.append("STORE " + s[1 + incr] + " 2")
case "OR": case "OR":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("LOAD 1 " + s[3 + incr]) l.append("LOAD 1 " + s[3 + incr])
l.append("OR 2 0 1") l.append("OR 2 0 1")
l.append("STORE " + s[1 + incr] + " 2")
case "NOT": case "NOT":
l.append(optionalFlag + "LOAD 0 " + s[2 + incr]) l.append(optionalFlag + "LOAD 0 " + s[2 + incr])
l.append("NOT 2 0") l.append("NOT 2 0")
l.append("STORE " + s[1 + incr] + " 2")
case default:
l.append(" ".join(s))
""" R2 will contain the information whether to jump or not""" """ R2 will contain the information whether to jump or not"""
return l return l
totalLine = 0 totalLine = 0 # TODO Check the number of line is never reached
labelCount = 0 # used to create a new label each time labelCount = 0 # used to create a new label each time
fileInput = open("asm", "r") fileInput = open("asm", "r")
ASMLines = list(map(lambda e: e.rstrip("\n"), fileInput.readlines())) ASMLines = list(map(lambda e: e.rstrip("\n"), fileInput.readlines()))
fileInput.close() fileInput.close()
# added to prevent problems when cross compiling some code representing a jump to after the last line
ASMLines.append("NOP")
ASMLinesLabel = ASMLines[:] # will contain at the end of the first loop the code with labels inserted ASMLinesLabel = ASMLines[:] # will contain at the end of the first loop the code with labels inserted
ASMLinesRegister = [] # will contain at the end of the 2nd loop the registry-based code with labels ASMLinesRegister = [] # will contain at the end of the 2nd loop the registry-based code with labels
ASMLinesFinal = [] # will contain the output, register-based, code ASMLinesFinal = [] # will contain the output, register-based, code
@ -135,7 +120,9 @@ ASMLinesFinal = [] # will contain the output, register-based, code
for i, l in enumerate(ASMLines): for i, l in enumerate(ASMLines):
items = l.split(" ") items = l.split(" ")
if items[0] in ["JMP", "JMF"]: if items[0] in ["JMP", "JMF"]:
lineToJumpTo = int(items[-1]) lineToJumpTo = int(items[
1 if items[0] == "JMP" else 2
])
if re.match(r"\d_LABEL .*", ASMLinesLabel[lineToJumpTo]): if re.match(r"\d_LABEL .*", ASMLinesLabel[lineToJumpTo]):
ASMLinesLabel[i] = " ".join(ASMLines[i].split()[:-1] + [ASMLinesLabel[lineToJumpTo].split()[0]]) ASMLinesLabel[i] = " ".join(ASMLines[i].split()[:-1] + [ASMLinesLabel[lineToJumpTo].split()[0]])
else: else:
@ -171,12 +158,6 @@ for i, l in enumerate(ASMLinesFinal):
while len(arr) < 4: while len(arr) < 4:
arr.append(0) arr.append(0)
lines.append(f"(x\"{opToBinOP[arr[0]]}{int(arr[1]):02X}{int(arr[2]):02X}{int(arr[3]):02X}\")") lines.append(f"(x\"{opToBinOP[arr[0]]}{int(arr[1]):02X}{int(arr[2]):02X}{int(arr[3]):02X}\")")
ASMLinesConverted = "(" + ",".join(lines) + ",others => (x\"ff000000\"))" ASMLinesConverted = "(" + ",".join(lines) + ",others => (x\"ff000000\")"
print("converted to VHDL-friendly format : " + ASMLinesConverted) print("converted to VHDL-friendly format : " + ASMLinesConverted)
output(ASMLinesConverted, 3, True) output(ASMLinesConverted, 3, True)
""" Used to generate the beautiful table in the report
for i in range(10):
print(f"{ASMLines[i]} & {ASMLinesFinal[i]} & {ASMLinesConverted.split(',')[i]} \\\\")
"""