Skip to content

Commit 9cc6179

Browse files
committed
Allow overlapping extensions with --warn-overlap
1 parent 0a08518 commit 9cc6179

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/riscv_opcodes/parse.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def generate_extensions(
3131
go: bool,
3232
latex: bool,
3333
svg: bool,
34+
warn_overlap: bool = False,
3435
):
35-
instr_dict = create_inst_dict(extensions, include_pseudo)
36+
instr_dict = create_inst_dict(extensions, include_pseudo, warn_overlap=warn_overlap)
3637
instr_dict = dict(sorted(instr_dict.items()))
3738
instr_dict_with_segment = add_segmented_vls_insn(instr_dict)
3839

@@ -41,7 +42,7 @@ def generate_extensions(
4142

4243
if c:
4344
instr_dict_c = create_inst_dict(
44-
extensions, False, include_pseudo_ops=emitted_pseudo_ops
45+
extensions, False, include_pseudo_ops=emitted_pseudo_ops, warn_overlap=warn_overlap
4546
)
4647
instr_dict_c = dict(sorted(instr_dict_c.items()))
4748
make_c(instr_dict_c)
@@ -97,6 +98,11 @@ def main():
9798
parser.add_argument("-go", action="store_true", help="Generate output for Go")
9899
parser.add_argument("-latex", action="store_true", help="Generate output for Latex")
99100
parser.add_argument("-svg", action="store_true", help="Generate .svg output")
101+
parser.add_argument(
102+
"--warn-overlap",
103+
action="store_true",
104+
help="Warn instead of error on overlapping instruction encodings",
105+
)
100106
parser.add_argument(
101107
"extensions",
102108
nargs="*",
@@ -118,4 +124,5 @@ def main():
118124
args.go,
119125
args.latex,
120126
args.svg,
127+
args.warn_overlap,
121128
)

src/riscv_opcodes/shared_utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def read_lines(file: str) -> "list[str]":
407407

408408
# Update the instruction dictionary
409409
def process_standard_instructions(
410-
lines: "list[str]", instr_dict: InstrDict, file_name: str
410+
lines: "list[str]", instr_dict: InstrDict, file_name: str, warn_overlap: bool = False
411411
):
412412
"""Processes standard instructions from the given lines and updates the instruction dictionary."""
413413
for line in lines:
@@ -437,9 +437,11 @@ def process_standard_instructions(
437437
and not instruction_overlap_allowed(name, key)
438438
and same_base_isa(ext_name, item["extension"])
439439
):
440-
log_and_exit(
441-
f'Instruction {name} in extension {ext_name} overlaps with {key} in {item["extension"]}'
442-
)
440+
overlap_msg = f'Instruction {name} in extension {ext_name} overlaps with {key} in {item["extension"]}'
441+
if warn_overlap:
442+
logging.warning(overlap_msg)
443+
else:
444+
log_and_exit(overlap_msg)
443445

444446
instr_dict[name] = single_dict
445447

@@ -543,6 +545,7 @@ def create_inst_dict(
543545
file_filter: "list[str]",
544546
include_pseudo: bool = False,
545547
include_pseudo_ops: "Optional[list[str]]" = None,
548+
warn_overlap: bool = False,
546549
) -> InstrDict:
547550
"""
548551
Creates a dictionary of instructions based on the provided file filters.
@@ -607,7 +610,7 @@ def create_inst_dict(
607610
for file_name in file_names:
608611
logging.debug(f"Parsing File: {file_name} for standard instructions")
609612
lines = read_lines(file_name)
610-
process_standard_instructions(lines, instr_dict, file_name)
613+
process_standard_instructions(lines, instr_dict, file_name, warn_overlap)
611614

612615
logging.debug("Collecting pseudo instructions")
613616
for file_name in file_names:

0 commit comments

Comments
 (0)