Skip to content

Commit

Permalink
adding support for spinalhdl code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
neelgala committed May 2, 2022
1 parent 738fa4a commit bc92b79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ inst.go
instr-table.tex
priv-instr-table.tex
inst.rs

inst.spinalhdl
inst.sverilog

instr_dict.yaml

__pycache__/
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install: everything

.PHONY : everything
everything:
@./parse.py -c -chisel -sverilog -rust -latex $(EXTENSIONS)
@./parse.py -c -chisel -sverilog -rust -latex -spinalhdl $(EXTENSIONS)

.PHONY : encoding.out.h
encoding.out.h:
Expand Down Expand Up @@ -47,3 +47,7 @@ instr-table.tex: latex

.PHONY: priv-instr-table.tex
priv-instr-table.tex: latex

.PHONY: inst.spinalhdl
inst.spinalhdl:
@./parse.py -spinalhdl $(EXTENSIONS)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ The following artifacts can be generated using parse.py:
- inst.chisel : chisel code to decode instructions
- inst.sverilog : system verilog code to decode instructions
- inst.rs : rust code containing mask and match variables for all instructions
- inst.spinalhdl : spinalhdl code to decode instructions

Make sure you install the required python pre-requisites are installed by executing the following
command:
Expand Down
16 changes: 13 additions & 3 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,16 @@ def make_ext_latex_table(type_list, dataset, latex_file, ilen, caption):
latex_file.write(header+content+endtable)


def make_chisel(instr_dict):
def make_chisel(instr_dict, spinal_hdl=False):

chisel_names=''
cause_names_str=''
csr_names_str = ''
for i in instr_dict:
chisel_names += f' def {i.upper().replace(".","_"):<18s} = BitPat("b{instr_dict[i]["encoding"].replace("-","?")}")\n'
if spinal_hdl:
chisel_names += f' def {i.upper().replace(".","_"):<18s} = M"b{instr_dict[i]["encoding"].replace("-","-")}"\n'
else:
chisel_names += f' def {i.upper().replace(".","_"):<18s} = BitPat("b{instr_dict[i]["encoding"].replace("-","?")}")\n'
for num, name in causes:
cause_names_str += f' val {name.lower().replace(" ","_")} = {hex(num)}\n'
cause_names_str += ''' val all = {
Expand Down Expand Up @@ -740,7 +743,10 @@ def make_chisel(instr_dict):
csr_names_str += ''' res.toArray
}'''

chisel_file = open('inst.chisel','w')
if spinal_hdl:
chisel_file = open('inst.spinalhdl','w')
else:
chisel_file = open('inst.chisel','w')
chisel_file.write(f'''
/* Automatically generated by parse_opcodes */
object Instructions {{
Expand Down Expand Up @@ -857,6 +863,10 @@ def make_c(instr_dict):
if '-chisel' in sys.argv[1:]:
make_chisel(instr_dict)
logging.info('inst.chisel generated successfully')

if '-spinalhdl' in sys.argv[1:]:
make_chisel(instr_dict, True)
logging.info('inst.spinalhdl generated successfully')

if '-sverilog' in sys.argv[1:]:
make_sverilog(instr_dict)
Expand Down

0 comments on commit bc92b79

Please sign in to comment.