Skip to content

Commit

Permalink
Merge pull request riscv#126 from incoresemi/explicit-pseudo-op-inclu…
Browse files Browse the repository at this point in the history
…sion

Explicit pseudo op inclusion
  • Loading branch information
aswaterman authored Jun 9, 2022
2 parents 08ca2b1 + 6650e55 commit 4c1f976
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ everything:

.PHONY : encoding.out.h
encoding.out.h:
@./parse.py -c $(EXTENSIONS)
@./parse.py -c rv* unratified/rv_* unratified/rv32* unratified/rv64*

.PHONY : inst.chisel
inst.chisel:
Expand Down
22 changes: 14 additions & 8 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def process_enc_line(line, ext):
return (name, single_dict)


def create_inst_dict(file_filter, include_pseudo=False):
def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
'''
This function return a dictionary containing all instructions associated
with an extension defined by the file_filter input. The file_filter input
Expand Down Expand Up @@ -177,11 +177,11 @@ def create_inst_dict(file_filter, include_pseudo=False):
file_names = []
for fil in file_filter:
file_names += glob.glob(f'{opcodes_dir}{fil}')

file_names.sort(reverse=True)
# first pass if for standard/regular instructions
logging.debug('Collecting standard instructions first')
for f in file_names:
logging.debug(f'Parsing File: {f}')
logging.debug(f'Parsing File: {f} for standard instructions')
with open(f) as fp:
lines = (line.rstrip()
for line in fp) # All lines including the blank ones
Expand Down Expand Up @@ -225,7 +225,7 @@ def create_inst_dict(file_filter, include_pseudo=False):
# second pass if for pseudo instructions
logging.debug('Collecting pseudo instructions now')
for f in file_names:
logging.debug(f'Parsing File: {f}')
logging.debug(f'Parsing File: {f} for pseudo_ops')
with open(f) as fp:
lines = (line.rstrip()
for line in fp) # All lines including the blank ones
Expand Down Expand Up @@ -271,21 +271,24 @@ def create_inst_dict(file_filter, include_pseudo=False):
raise SystemExit(1)


(name, single_dict) = process_enc_line(pseudo_inst + ' ' + line, f)
# add the pseudo_op to the dictionary only if the original
# instruction is not already in the dictionary.
if orig_inst.replace('.','_') not in instr_dict or include_pseudo:
(name, single_dict) = process_enc_line(pseudo_inst + ' ' + line, f)
if orig_inst.replace('.','_') not in instr_dict \
or include_pseudo \
or name in include_pseudo_ops:

# update the final dict with the instruction
if name not in instr_dict:
instr_dict[name] = single_dict
logging.debug(f' including pseudo_ops:{name}')
else:
logging.debug(f'Skipping pseudo_op {pseudo_inst} since original instruction {orig_inst} already selected in list')

# third pass if for imported instructions
logging.debug('Collecting imported instructions')
for f in file_names:
logging.debug(f'Parsing File: {f}')
logging.debug(f'Parsing File: {f} for imported ops')
with open(f) as fp:
lines = (line.rstrip()
for line in fp) # All lines including the blank ones
Expand Down Expand Up @@ -918,7 +921,10 @@ def signed(value, width):
instr_dict = collections.OrderedDict(sorted(instr_dict.items()))

if '-c' in sys.argv[1:]:
make_c(instr_dict)
instr_dict_c = create_inst_dict(extensions, False,
include_pseudo_ops=['pause', 'prefetch_r', 'prefetch_w', 'prefetch_i'])
instr_dict_c = collections.OrderedDict(sorted(instr_dict_c.items()))
make_c(instr_dict_c)
logging.info('encoding.out.h generated successfully')

if '-chisel' in sys.argv[1:]:
Expand Down

0 comments on commit 4c1f976

Please sign in to comment.