-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute2.py
98 lines (86 loc) · 3.2 KB
/
execute2.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
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
87
88
89
90
91
92
93
94
95
96
97
98
import globalss
from I_phase2 import *
from R_phase2 import *
from SSBU_phase2 import *
# from UJ_phase2 import *
def execute(reg):
# reg[rd,rs1,rs2,imm,type,oriname]
if reg[4] == 'R':
if reg[5] == 'add':
reg.append(addinst(reg[1], reg[2]))
elif reg[5] == 'and':
reg.append(andinst(reg[1], reg[2]))
elif reg[5] == 'or':
reg.append(orinst(reg[1], reg[2]))
elif reg[5] == 'sll':
reg.append(sllinst(reg[1], reg[2]))
elif reg[5] == 'slt':
reg.append(sltinst(reg[1], reg[2]))
elif reg[5] == 'sra':
reg.append(srainst(reg[1], reg[2]))
elif reg[5] == 'srl':
reg.append(srlinst(reg[1], reg[2]))
elif reg[5] == 'sub':
reg.append(subinst(reg[1], reg[2]))
elif reg[5] == 'xor':
reg.append(xorinst(reg[1], reg[2]))
elif reg[5] == 'mul':
reg.append(mulinst(reg[1], reg[2]))
elif reg[5] == 'div':
reg.append(divinst(reg[1], reg[2]))
elif reg[5] == 'rem':
reg.append(reminst(reg[1], reg[2]))
elif reg[4] == 'I_1':
if reg[5] == 'addi':
reg.append(addiinst(reg[1], reg[3])) # reg[3] is immediate
elif reg[5] == 'andi':
reg.append(andiinst(reg[1], reg[3]))
elif reg[5] == 'ori':
reg.append(oriinst(reg[1], reg[3]))
elif reg[4] == 'I_2':
if reg[5] == 'lb':
reg.append(lbinst(reg[1], reg[3]))
elif reg[5] == 'ld':
reg.append(ldinst(reg[1], reg[3]))
elif reg[5] == 'lh':
reg.append(lhinst(reg[1], reg[3]))
elif reg[5] == 'lw':
reg.append(lwinst(reg[1], reg[3]))
elif reg[4] == 'I_3':
if reg[5] == 'jalr':
reg.append(jalrinst(reg[1], reg[3]))
globalss.PC_execution = reg[6]
elif reg[4] == 'S':
if reg[5] == 'sb':
reg.append(sbinst(reg[1], reg[3])) # sending rs1 and imm
elif reg[5] == 'sw':
reg.append(swinst(reg[1], reg[3]))
elif reg[5] == 'sd':
reg.append(sdinst(reg[1], reg[3]))
elif reg[5] == 'sh':
reg.append(shinst(reg[1], reg[3]))
elif reg[4] == 'SB':
if reg[5] == 'beq':
reg.append(beqinst(reg[1], reg[2]))
elif reg[5] == 'bne':
reg.append(bneinst(reg[1], reg[2]))
elif reg[5] == 'bge':
reg.append(bgeinst(reg[1], reg[2]))
elif reg[5] == 'blt':
reg.append(bltinst(reg[1], reg[2]))
# if reg[6]==1:
# globalss.PC_execution=globalss.PC_execution + reg[3]
# else:
# globalss.PC_execution=globalss.PC_execution+4
elif reg[4] == 'U_lui':
if reg[5] == 'lui':
reg.append(luiinst(reg[3])) # it is incomplete
elif reg[4] == 'U_auipc':
if reg[5] == 'auipc':
reg.append(auipcinst(reg[3]))
elif reg[4] == 'UJ':
if reg[5] == 'jal':
reg.append(globalss.PC_execution + 4)
globalss.PC_execution = globalss.PC_execution + reg[3]
# it is incomplete
return reg