Skip to content

Commit

Permalink
add spinalhdl support (riscv#108)
Browse files Browse the repository at this point in the history
* add spinalhdl support

Signed-off-by: ncer <[email protected]>

* restruct chisel and spinalhdl parser

Signed-off-by: ncer <[email protected]>
  • Loading branch information
Ncerzzk authored May 1, 2022
1 parent 75b28f2 commit 71ecf35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.*.swp
encoding.out.h
inst.chisel
inst.spinalhdl
inst.go
instr-table.tex
priv-instr-table.tex
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ALL_REAL_OPCODES := $(ALL_REAL_ILEN32_OPCODES) opcodes-rvc opcodes-rv32c opcodes

ALL_OPCODES := opcodes-pseudo $(ALL_REAL_OPCODES) opcodes-rvv-pseudo

install: encoding.out.h inst.chisel instr-table.tex priv-instr-table.tex
install: encoding.out.h inst.chisel inst.spinalhdl instr-table.tex priv-instr-table.tex
set -e; for FILE in $(INSTALL_HEADER_FILES); do cp -f encoding.out.h $$FILE; done

encoding.out.h: $(ALL_OPCODES) parse_opcodes encoding.h
Expand All @@ -26,6 +26,9 @@ encoding.out.h: $(ALL_OPCODES) parse_opcodes encoding.h
inst.chisel: $(ALL_OPCODES) parse_opcodes
cat $(ALL_OPCODES) | ./parse_opcodes -chisel > $@

inst.spinalhdl: $(ALL_OPCODES) parse_opcodes
cat $(ALL_OPCODES) | ./parse_opcodes -spinalhdl > $@

inst.go: $(ALL_REAL_ILEN32_OPCODES) parse_opcodes
cat $(ALL_REAL_ILEN32_OPCODES) | ./parse_opcodes -go > $@

Expand Down
25 changes: 23 additions & 2 deletions parse_opcodes
Original file line number Diff line number Diff line change
Expand Up @@ -1037,11 +1037,24 @@ def print_chisel_insn(name):
s = s + '?'
print(s + "\")")

def make_chisel():
def print_spinalhdl_insn(name):
s = " def %-18s = M\"" % name.replace('.', '_').upper()
for i in range(31, -1, -1):
if yank(mask[name], i, 1):
s = '%s%d' % (s, yank(match[name], i, 1))
else:
s = s + '-'
print(s + "\"")

def make_scala(hdl):
if hdl == "chisel":
print_fun=print_chisel_insn
else:
print_fun=print_spinalhdl_insn
print('/* Automatically generated by parse_opcodes */')
print('object Instructions {')
for name in namelist:
print_chisel_insn(name)
print_fun(name)
print('}')
print('object Causes {')
for num, name in causes:
Expand Down Expand Up @@ -1070,6 +1083,12 @@ def make_chisel():
print(' }')
print('}')

def make_chisel():
make_scala("chisel")

def make_spinalhdl():
make_scala("spinalhdl")

def print_sverilog_insn(name):
s = " localparam [31:0] %-18s = 32'b" % name.replace('.', '_').upper()
for i in range(31, -1, -1):
Expand Down Expand Up @@ -1228,6 +1247,8 @@ if __name__ == "__main__":
make_supervisor_latex_table()
elif sys.argv[1] == '-chisel':
make_chisel()
elif sys.argv[1] == '-spinalhdl':
make_spinalhdl()
elif sys.argv[1] == '-sverilog':
make_sverilog()
elif sys.argv[1] == '-c':
Expand Down

0 comments on commit 71ecf35

Please sign in to comment.