aboutsummaryrefslogtreecommitdiff
path: root/parse.py
diff options
context:
space:
mode:
authorLehua Ding <lehuading@qq.com>2022-08-04 23:17:27 +0800
committerGitHub <noreply@github.com>2022-08-04 08:17:27 -0700
commitc532dafd8e2205615d54c6c83366000968ca9c03 (patch)
tree6415463d0540ede974daedb53cf5af0ef10e52e3 /parse.py
parent8ab2df7431d19d2942ec2a3b8386dfefe0620c88 (diff)
downloadriscv-opcodes-c532dafd8e2205615d54c6c83366000968ca9c03.zip
riscv-opcodes-c532dafd8e2205615d54c6c83366000968ca9c03.tar.gz
riscv-opcodes-c532dafd8e2205615d54c6c83366000968ca9c03.tar.bz2
fix extension merge and add name and encoding conflict checking (#116)
* fix extension merge and add name and encoding conflict checking * fix comments * uniform code's indentation
Diffstat (limited to 'parse.py')
-rwxr-xr-xparse.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/parse.py b/parse.py
index c389eb8..2cf1e7e 100755
--- a/parse.py
+++ b/parse.py
@@ -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=[]):
'''
@@ -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