Skip to content

Commit

Permalink
fix extension merge and add name and encoding conflict checking (risc…
Browse files Browse the repository at this point in the history
…v#116)

* fix extension merge and add name and encoding conflict checking

* fix comments

* uniform code's indentation
  • Loading branch information
lhtin authored Aug 4, 2022
1 parent 8ab2df7 commit c532daf
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ def process_enc_line(line, ext):

return (name, single_dict)

def same_base_ext (ext_name, ext_name_list):
type1 = ext_name.split("_")[0]
for ext_name1 in ext_name_list:
type2 = ext_name1.split("_")[0]
# "rv" mean insn for rv32 and rv64
if (type1 == type2 or
(type2 == "rv" and (type1 == "rv32" or type1 == "rv64")) or
(type1 == "rv" and (type2 == "rv32" or type2 == "rv64"))):
return True
return False

def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
'''
Expand Down Expand Up @@ -205,20 +215,38 @@ def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
# call process_enc_line to get the data about the current
# instruction
(name, single_dict) = process_enc_line(line, f)
ext_name = f.split("/")[-1]

# if an instruction has already been added to the filtered
# instruction dictionary throw an error saying the given
# instruction is already imported and raise SystemExit
if name in instr_dict:
var = instr_dict[name]["extension"]
if instr_dict[name]['encoding'] != single_dict['encoding']:
if same_base_ext(ext_name, var):
# disable same names on the same base extensions
err_msg = f'instruction : {name} from '
err_msg += f'{f.split("/")[-1]} is already '
err_msg += f'added from {var} but each have different encodings for the same instruction'
err_msg += f'{ext_name} is already '
err_msg += f'added from {var} in same base extensions'
logging.error(err_msg)
raise SystemExit(1)
instr_dict[name]['extension'].append(single_dict['extension'])

elif instr_dict[name]['encoding'] != single_dict['encoding']:
# disable same names with different encodings on different base extensions
err_msg = f'instruction : {name} from '
err_msg += f'{ext_name} is already '
err_msg += f'added from {var} but each have different encodings in different base extensions'
logging.error(err_msg)
raise SystemExit(1)
instr_dict[name]['extension'].extend(single_dict['extension'])
else:
for key in instr_dict:
item = instr_dict[key]
if item["encoding"] == single_dict['encoding'] and same_base_ext(ext_name, item["extension"]):
# disable different names with same encodings on the same base extensions
err_msg = f'instruction : {name} from '
err_msg += f'{ext_name} has the same encoding with instruction {key} '
err_msg += f'added from {item["extension"]} in same base extensions'
logging.error(err_msg)
raise SystemExit(1)
# update the final dict with the instruction
instr_dict[name] = single_dict

Expand Down

0 comments on commit c532daf

Please sign in to comment.