-
Notifications
You must be signed in to change notification settings - Fork 2
/
testconst.py
64 lines (54 loc) · 1.79 KB
/
testconst.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
from utility import *
filename = 'src/test/scala/Constants.scala'
writer = ScalaWriter(filename)
namespace = writer.namespace
B = getbits
@ScalaWriter.Seq('ALU')
def ALUmode():
return [('"%s"' % code['name'].upper(), '{}L', B(code, 14, 12) + (B(code, 30) << 3)) for code in codes if B(code, 6, 2) == 0b01100]
@ScalaWriter.Seq('Opcode')
def Opcode():
fmt = '{}L'
return map(lambda x:('"' + x[0] + '"', fmt, x[1]), [
('LUI', 0b0110111),
('AUIPC', 0b0010111),
('JAL', 0b1101111),
('JALR', 0b1100111),
('BRANCH', 0b1100011),
('LOAD', 0b0000011),
('STORE', 0b0100011),
('ITYPE', 0b0010011),
('RTYPE', 0b0110011),
('MEMORY', 0b0001111),
('SYSTEM', 0b1110011),
])
@ScalaWriter.Seq('BranchCodes')
def BranchCodes():
return [('"%s"' % code['name'].upper(), '{}L', B(code, 14, 12)) for code in codes if B(code, 6, 2) == 0b11000]
@ScalaWriter.Seq('LoadCodes')
def LoadCodes():
return [('"%s"' % code['name'].upper(), '{}L', B(code, 14, 12)) for code in codes if B(code, 6, 2) == 0b00000]
@ScalaWriter.Seq('StoreCodes')
def StoreCodes():
return [('"%s"' % code['name'].upper(), '{}L', B(code, 14, 12)) for code in codes if B(code, 6, 2) == 0b01000]
@ScalaWriter.Seq('ControlActs')
def ControlActs():
c = ["ALU", "BRC", "LDS", "FEN", "SYS", "LUI", "AUI", "JMP"]
fmt = '{}L'
return [('"' + c[i] + '"', fmt, i) for i in range(len(c))]
@ScalaWriter.Seq('ImmModes')
def ImmModes():
modes = 'RISUJBZ'
fmt = '{}L'
return [('"' + modes[i] + '"', fmt, i) for i in range(len(modes))]
@namespace('Constants')
def constant():
return [
*ALUmode(),
*Opcode(),
*BranchCodes(),
*LoadCodes(),
*StoreCodes(),
*ControlActs(),
*ImmModes(),
]