Skip to content

Commit

Permalink
Fix rebase issue. Only replace options outside of LLVM cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Sep 9, 2024
1 parent 19cfcea commit 169777d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
32 changes: 9 additions & 23 deletions suite/auto-sync/src/autosync/MCUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@


class LLVM_MC_Command:
def __init__(self, cmd_line: str, mattr: str, mattr_map: dict = dict()):
def __init__(self, cmd_line: str, mattr: str):
self.cmd: str = ""
self.opts: str = ""
self.file: Path | None = None
self.additional_mattr: str = mattr
self.mattr_map: dict = mattr_map

self.cmd, self.opts, self.file = self.parse_llvm_mc_line(cmd_line)
if not (self.cmd and self.opts and self.file):
Expand All @@ -48,10 +47,7 @@ def parse_llvm_mc_line(self, line: str) -> tuple[str, str, Path]:
processed_attr = list()
for m in mattr:
attribute = m.group(2).strip("+")
if attribute in self.mattr_map:
processed_attr.append(self.mattr_map[attribute])
else:
processed_attr.append(attribute)
processed_attr.append(attribute)
opts += ",".join(processed_attr)
return cmd, opts, Path(test_file)

Expand Down Expand Up @@ -90,11 +86,7 @@ class MCTest:

def __init__(self, arch: str, opts: list[str], encoding: str, asm_text: str):
self.arch = arch
if arch.lower() in ["arm", "powerpc", "ppc", "aarch64"]:
# Arch and PPC require this option for MC tests.
self.opts = ["CS_OPT_NO_BRANCH_OFFSET"] + opts
else:
self.opts = opts
self.opts = opts
self.encoding: list[str] = [encoding]
self.asm_text: list[str] = [asm_text]

Expand Down Expand Up @@ -275,7 +267,7 @@ def __init__(
else ""
)
# A list of options which are always added.
self.mandatory_options: str = (
self.mandatory_options: list[str] = (
self.conf["mandatory_options"][self.arch]
if self.arch in self.conf["mandatory_options"]
else list()
Expand All @@ -286,13 +278,15 @@ def __init__(
else list()
)
self.remove_options = [x.lower() for x in self.remove_options]
self.replace_option_map: str = (
self.replace_option_map: dict = (
self.conf["replace_option_map"][self.arch]
if self.arch in self.conf["replace_option_map"]
else {}
)
self.replace_option_map = {
k.lower(): v for k, v in self.replace_option_map.items()
k.lower(): v
for k, v in self.replace_option_map.items()
if k.lower not in self.remove_options
}
self.multi_mode = multi_mode

Expand Down Expand Up @@ -471,15 +465,7 @@ def extract_llvm_mc_cmds(self, cmds: str) -> list[LLVM_MC_Command]:
continue
if any(re.search(x, match) is not None for x in self.excluded):
continue
llvm_mc_cmd = LLVM_MC_Command(
match,
self.mattr,
(
self.conf["mode_map"][self.arch]
if self.arch in self.conf["mode_map"]
else dict()
),
)
llvm_mc_cmd = LLVM_MC_Command(match, self.mattr)
if not llvm_mc_cmd.cmd:
# Invalid
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0x00, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13" ]
expected:
insns:
-
Expand All @@ -13,7 +13,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0xf0, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13" ]
expected:
insns:
-
Expand All @@ -23,7 +23,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0x0f, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13" ]
expected:
insns:
-
Expand All @@ -33,7 +33,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x10, 0x00, 0x00, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_Z13" ]
expected:
insns:
-
Expand All @@ -43,7 +43,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0x00, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11" ]
expected:
insns:
-
Expand All @@ -53,7 +53,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0xf0, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11" ]
expected:
insns:
-
Expand All @@ -63,7 +63,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x00, 0x00, 0x0f, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11" ]
expected:
insns:
-
Expand All @@ -73,7 +73,7 @@ test_cases:
input:
bytes: [ 0xed, 0x00, 0x10, 0x00, 0x00, 0xae ]
arch: "CS_ARCH_SYSTEMZ"
options: [ "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11", "CS_MODE_BIG_ENDIAN" ]
options: [ "CS_MODE_BIG_ENDIAN", "s390x-linux-gnu", "CS_MODE_SYSTEMZ_ARCH11" ]
expected:
insns:
-
Expand Down
12 changes: 12 additions & 0 deletions suite/auto-sync/src/autosync/mcupdater.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"Mips":
[
"CS_OPT_SYNTAX_NOREGNAME"
],
"PPC":
[
"CS_OPT_NO_BRANCH_OFFSET"
],
"ARM":
[
"CS_OPT_NO_BRANCH_OFFSET"
],
"AArch64":
[
"CS_OPT_NO_BRANCH_OFFSET"
]
},
"remove_options":
Expand Down

0 comments on commit 169777d

Please sign in to comment.