Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemZ Auto-Sync refactor #2462

Merged
merged 71 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
511e671
Make ASUpdater a command.
Rot127 Aug 25, 2024
7c7d41c
Use the Targets.py defined values also in ASUpdater.
Rot127 Aug 25, 2024
d311aae
Remove old SystemZ files
Rot127 Aug 25, 2024
6f1e670
Fix regex strings.
Rot127 Aug 25, 2024
bb8d27e
Add SystemZ Inlcudes.
Rot127 Aug 26, 2024
8c396f9
Add SystemZ basic config
Rot127 Aug 26, 2024
a6a96f8
Allow to copy translated instead of diffed files.
Rot127 Aug 26, 2024
c50d29c
Rename SysZ -> SystemZ
Rot127 Aug 26, 2024
0a4d142
Move IncGenerator config to own file.
Rot127 Aug 26, 2024
a2d09ff
Add SystemZMCTargetDesc src files.
Rot127 Aug 26, 2024
c6ddedd
Patch assert with CS_ASSERT()
Rot127 Aug 26, 2024
fa49fd8
Add isUIntN patch
Rot127 Aug 26, 2024
c666dfd
Remove invalid include.
Rot127 Aug 26, 2024
b1bd90c
Add MCAsmInfo struct.
Rot127 Aug 26, 2024
b9e783f
Handle getExpr
Rot127 Aug 26, 2024
fbcb3e0
Add printer for expressions.
Rot127 Aug 26, 2024
edc4650
Add assembly dialect for SystemZ
Rot127 Aug 26, 2024
0a65ca4
Handle isExpr
Rot127 Aug 26, 2024
e711c98
Add getter for Expr
Rot127 Aug 26, 2024
39218d6
Add markup_OS()
Rot127 Aug 26, 2024
0a6614a
Add refactored SystemZ module.
Rot127 Aug 28, 2024
3921edf
Use universal Target list in Differ
Rot127 Aug 28, 2024
7f2c823
Fix: Skip tests which test for symbols.
Rot127 Aug 28, 2024
c90d542
Update SystemZ MC tests
Rot127 Aug 28, 2024
48dd9f3
Add buffer overflow checks.
Rot127 Aug 28, 2024
550de85
Fix several overflows
Rot127 Aug 28, 2024
c9623e6
Add and use readBytes48 and 64
Rot127 Aug 28, 2024
1163fab
Set default assmebly syntax to HLASM
Rot127 Aug 28, 2024
1ba79f6
Print signed integer as signed not unsigned.
Rot127 Aug 28, 2024
0d7103c
Add MCUpdater config for test case unification.
Rot127 Aug 28, 2024
54a7fb1
Unify all SystemZ test cases.
Rot127 Aug 28, 2024
ae1d749
Track total number of decoded instructions.
Rot127 Aug 28, 2024
1ddb707
Add all CPU modes to SystemZ
Rot127 Aug 29, 2024
2b80172
Allow to map LLVM attributes to Capstone mode identifiers
Rot127 Aug 29, 2024
0e27be3
Update SystemZ tests.
Rot127 Aug 29, 2024
b974a72
Fix SystemZ feature check
Rot127 Aug 30, 2024
3d0679d
Add SystemZInstPrinter to the patch list of AddCSDetail
Rot127 Aug 30, 2024
13a8a77
Add details for SystemZ
Rot127 Aug 30, 2024
ffe5628
Update release guide
Rot127 Aug 30, 2024
a5a327c
Fix detail tests.
Rot127 Aug 30, 2024
35287eb
Move feature tables.
Rot127 Aug 31, 2024
254a6a7
Update const generator for SystemZ
Rot127 Aug 31, 2024
05f4fb5
Update Python bindings to work with refactored SystemZ module.
Rot127 Aug 31, 2024
9809c2d
Remove empty feature array
Rot127 Aug 31, 2024
616a4ff
Fix segfault if skipped test cases exists.
Rot127 Aug 31, 2024
73fa54a
Fix comparison of memory address mode
Rot127 Aug 31, 2024
e8f83e3
Fix: missing prefix to function name
Rot127 Aug 31, 2024
edebb84
More renaming of SYSZ -> SYSTEMZ
Rot127 Aug 31, 2024
084c979
Delete unused files.
Rot127 Aug 31, 2024
14812b5
Fix faulty name in header.
Rot127 Aug 31, 2024
143db74
Add SystemZ compatibility header and tests.
Rot127 Sep 1, 2024
4aee98d
Add missing modes
Rot127 Sep 1, 2024
1deb92b
Fix markup tests and add overflow unit tests
Rot127 Sep 1, 2024
78da233
Update saved patches and fix Differ if new node is first.
Rot127 Sep 1, 2024
4846c3c
Add SystemZ to Auto-Sync test
Rot127 Sep 1, 2024
2737940
Fix value of CS_ARCH_SYSTEMZ in Python bindings
Rot127 Sep 1, 2024
5e5967f
Make multiple test files with same byte input the default.
Rot127 Sep 1, 2024
8c1aecb
Fix gcc warning
Rot127 Sep 1, 2024
c1d82b5
Fix: Remove access to non existent attribute.
Rot127 Sep 1, 2024
ad6831d
Update v6 release notes with SystemZ renaming instructions
Rot127 Sep 1, 2024
42f5bd5
Formatting
Rot127 Sep 1, 2024
a419d27
Fix signed printing with printInt8 and printInt16
Rot127 Sep 1, 2024
0006f11
Reintroduce mutex
Rot127 Sep 1, 2024
e7b22a8
Fix printing of minimal signed integer values in hex.
Rot127 Sep 3, 2024
20a15df
Run correct integration tests in CI
Rot127 Sep 3, 2024
483ab77
Formatting
Rot127 Sep 3, 2024
c99d819
Remove check for saved diffs, since it doesn't produce reproducable r…
Rot127 Sep 4, 2024
af4b72d
Fix rebasing issues
Rot127 Sep 9, 2024
4ae6215
Fix binary search returning too early if m == 0 but next index would …
Rot127 Sep 9, 2024
19cfcea
Move deletion to static method
Rot127 Sep 9, 2024
a4b009b
Fix rebase issue. Only replace options outside of LLVM cmd
Rot127 Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,20 @@ jobs:
# Work-around ASAN bug https://github.com/google/sanitizers/issues/1716
sudo sysctl vm.mmap_rnd_bits=28

- name: "Compatibility header test"
- name: unit tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R unit_*

- name: "Integration tests"
if: startsWith(matrix.config.build-system, 'cmake') && matrix.config.diet-build == 'OFF'
run: |
ctest --test-dir build --output-on-failure -R ASCompatibilityHeaderTest
ctest --test-dir build --output-on-failure -R integration_*

- name: cstool - reaches disassembler engine
run: |
sh suite/run_invalid_cstool.sh

- name: cstest unit tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R UnitCSTest

- name: cstest integration tests
if: startsWith(matrix.config.build-system, 'cmake')
run: |
ctest --test-dir build --output-on-failure -R IntegrationCSTest

- name: cstest MC
if: startsWith(matrix.config.build-system, 'cmake')
run: |
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/auto-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
./src/autosync/ASUpdater.py -d -a PPC -s IncGen
./src/autosync/ASUpdater.py -d -a LoongArch -s IncGen
./src/autosync/ASUpdater.py -d -a Mips -s IncGen
./src/autosync/ASUpdater.py -d -a SystemZ -s IncGen

- name: CppTranslator - Patch tests
run: |
Expand All @@ -94,10 +95,4 @@ jobs:
./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate
./src/autosync/ASUpdater.py --ci -d -a LoongArch -s Translate
./src/autosync/ASUpdater.py --ci -d -a Mips -s Translate

- name: Differ - Test save file is up-to-date
run: |
./src/autosync/cpptranslator/Differ.py -a AArch64 --check_saved
./src/autosync/cpptranslator/Differ.py -a ARM --check_saved
./src/autosync/cpptranslator/Differ.py -a PPC --check_saved
./src/autosync/cpptranslator/Differ.py -a LoongArch --check_saved
./src/autosync/ASUpdater.py --ci -d -a SystemZ -s Translate
42 changes: 23 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
endif()

set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH)
set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSTEMZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA HPPA LOONGARCH)
set(SUPPORTED_ARCHITECTURE_LABELS ARM AARCH64 M68K MIPS PowerPC Sparc SystemZ XCore x86 TMS320C64x M680x EVM MOS65XX WASM BPF RISCV SH TriCore Alpha HPPA LoongArch)

# If building for OSX it's best to allow CMake to handle building both architectures
Expand Down Expand Up @@ -200,6 +200,7 @@ set(HEADERS_COMMON
include/capstone/x86.h
include/capstone/sparc.h
include/capstone/systemz.h
include/capstone/systemz_compatibility.h
include/capstone/xcore.h
include/capstone/m68k.h
include/capstone/tms320c64x.h
Expand Down Expand Up @@ -412,27 +413,34 @@ if(CAPSTONE_SPARC_SUPPORT)
)
endif()

if(CAPSTONE_SYSZ_SUPPORT)
add_definitions(-DCAPSTONE_HAS_SYSZ)
set(SOURCES_SYSZ
if(CAPSTONE_SYSTEMZ_SUPPORT)
add_definitions(-DCAPSTONE_HAS_SYSTEMZ)
set(SOURCES_SYSTEMZ
arch/SystemZ/SystemZDisassembler.c
arch/SystemZ/SystemZDisassemblerExtension.c
arch/SystemZ/SystemZInstPrinter.c
arch/SystemZ/SystemZMapping.c
arch/SystemZ/SystemZModule.c
arch/SystemZ/SystemZMCTargetDesc.c
)
set(HEADERS_SYSZ
arch/SystemZ/SystemZDisassembler.h
set(HEADERS_SYSTEMZ
arch/SystemZ/SystemZLinkage.h
arch/SystemZ/SystemZDisassemblerExtension.h
arch/SystemZ/SystemZInstPrinter.h
arch/SystemZ/SystemZMCTargetDesc.h
arch/SystemZ/SystemZMapping.h
arch/SystemZ/SystemZModule.h
arch/SystemZ/SystemZGenAsmWriter.inc
arch/SystemZ/SystemZGenCSAliasMnemMap.inc
arch/SystemZ/SystemZGenCSFeatureName.inc
arch/SystemZ/SystemZGenCSMappingInsn.inc
arch/SystemZ/SystemZGenCSMappingInsnName.inc
arch/SystemZ/SystemZGenCSMappingInsnOp.inc
arch/SystemZ/SystemZGenCSOpGroup.inc
arch/SystemZ/SystemZGenDisassemblerTables.inc
arch/SystemZ/SystemZGenInsnNameMaps.inc
arch/SystemZ/SystemZGenInstrInfo.inc
arch/SystemZ/SystemZGenRegisterInfo.inc
arch/SystemZ/SystemZGenSubtargetInfo.inc
arch/SystemZ/SystemZInstPrinter.h
arch/SystemZ/SystemZMapping.h
arch/SystemZ/SystemZMappingInsn.inc
arch/SystemZ/SystemZMCTargetDesc.h
)
endif()

Expand Down Expand Up @@ -688,7 +696,7 @@ set(ALL_SOURCES
${SOURCES_PPC}
${SOURCES_X86}
${SOURCES_SPARC}
${SOURCES_SYSZ}
${SOURCES_SYSTEMZ}
${SOURCES_XCORE}
${SOURCES_M68K}
${SOURCES_TMS320C64X}
Expand All @@ -714,7 +722,7 @@ set(ALL_HEADERS
${HEADERS_PPC}
${HEADERS_X86}
${HEADERS_SPARC}
${HEADERS_SYSZ}
${HEADERS_SYSTEMZ}
${HEADERS_XCORE}
${HEADERS_M68K}
${HEADERS_TMS320C64X}
Expand Down Expand Up @@ -765,7 +773,7 @@ source_group("Source\\AARCH64" FILES ${SOURCES_AARCH64})
source_group("Source\\Mips" FILES ${SOURCES_MIPS})
source_group("Source\\PowerPC" FILES ${SOURCES_PPC})
source_group("Source\\Sparc" FILES ${SOURCES_SPARC})
source_group("Source\\SystemZ" FILES ${SOURCES_SYSZ})
source_group("Source\\SystemZ" FILES ${SOURCES_SYSTEMZ})
source_group("Source\\X86" FILES ${SOURCES_X86})
source_group("Source\\XCore" FILES ${SOURCES_XCORE})
source_group("Source\\M68K" FILES ${SOURCES_M68K})
Expand All @@ -789,7 +797,7 @@ source_group("Include\\AARCH64" FILES ${HEADERS_AARCH64})
source_group("Include\\Mips" FILES ${HEADERS_MIPS})
source_group("Include\\PowerPC" FILES ${HEADERS_PPC})
source_group("Include\\Sparc" FILES ${HEADERS_SPARC})
source_group("Include\\SystemZ" FILES ${HEADERS_SYSZ})
source_group("Include\\SystemZ" FILES ${HEADERS_SYSTEMZ})
source_group("Include\\X86" FILES ${HEADERS_X86})
source_group("Include\\XCore" FILES ${HEADERS_XCORE})
source_group("Include\\M68K" FILES ${HEADERS_M68K})
Expand Down Expand Up @@ -898,8 +906,4 @@ if(CAPSTONE_BUILD_CSTEST)
add_subdirectory(${TESTS_INTEGRATION_DIR})
set(TESTS_UNIT_DIR ${PROJECT_SOURCE_DIR}/tests/unit)
add_subdirectory(${TESTS_UNIT_DIR})

# Unit tests for auto-sync
set(AUTO_SYNC_C_TEST_DIR ${PROJECT_SOURCE_DIR}/suite/auto-sync/c_tests/)
add_subdirectory(${AUTO_SYNC_C_TEST_DIR})
endif()
2 changes: 1 addition & 1 deletion COMPILE_CMAKE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Get CMake for free from http://www.cmake.org.
- CAPSTONE_MOS65XX_SUPPORT: support MOS65XX. Run cmake with -DCAPSTONE_MOS65XX_SUPPORT=0 to remove MOS65XX.
- CAPSTONE_PPC_SUPPORT: support PPC. Run cmake with -DCAPSTONE_PPC_SUPPORT=0 to remove PPC.
- CAPSTONE_SPARC_SUPPORT: support Sparc. Run cmake with -DCAPSTONE_SPARC_SUPPORT=0 to remove Sparc.
- CAPSTONE_SYSZ_SUPPORT: support SystemZ. Run cmake with -DCAPSTONE_SYSZ_SUPPORT=0 to remove SystemZ.
- CAPSTONE_SYSTEMZ_SUPPORT: support SystemZ. Run cmake with -DCAPSTONE_SYSTEMZ_SUPPORT=0 to remove SystemZ.
- CAPSTONE_XCORE_SUPPORT: support XCore. Run cmake with -DCAPSTONE_XCORE_SUPPORT=0 to remove XCore.
- CAPSTONE_TRICORE_SUPPORT: support TriCore. Run cmake with -DCAPSTONE_TRICORE_SUPPORT=0 to remove TriCore.
- CAPSTONE_X86_SUPPORT: support X86. Run cmake with -DCAPSTONE_X86_SUPPORT=0 to remove X86.
Expand Down
19 changes: 19 additions & 0 deletions MCAsmInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © 2024 Rot127 <[email protected]>
// SPDX-License-Identifier: BSD-3

/// The equivalent of the MCAsmInfo class in LLVM.
/// We save only some flags of the original class here.

#ifndef CS_MCASMINFO_H
#define CS_MCASMINFO_H

typedef enum {
SYSTEMZASMDIALECT_AD_ATT = 0,
SYSTEMZASMDIALECT_AD_HLASM = 1,
} MCAsmInfoAssemblerDialect;

typedef struct {
MCAsmInfoAssemblerDialect assemblerDialect;
} MCAsmInfo;

#endif // CS_MCASMINFO_H
16 changes: 15 additions & 1 deletion MCInst.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)

void MCInst_Init(MCInst *inst)
void MCInst_Init(MCInst *inst, cs_arch arch)
{
// unnecessary to initialize in loop . its expensive and inst->size should be honored
inst->Operands[0].Kind = kInvalid;
Expand All @@ -37,6 +37,15 @@ void MCInst_Init(MCInst *inst)
inst->isAliasInstr = false;
inst->fillDetailOps = false;
memset(&inst->hppa_ext, 0, sizeof(inst->hppa_ext));

// Set default assembly dialect.
switch (arch) {
default:
break;
case CS_ARCH_SYSTEMZ:
inst->MAI.assemblerDialect = SYSTEMZASMDIALECT_AD_HLASM;
break;
}
}

void MCInst_clear(MCInst *inst)
Expand Down Expand Up @@ -150,6 +159,11 @@ int64_t MCOperand_getImm(const MCOperand *op)
return op->ImmVal;
}

int64_t MCOperand_getExpr(const MCOperand *op)
{
return op->ImmVal;
}

void MCOperand_setImm(MCOperand *op, int64_t Val)
{
op->ImmVal = Val;
Expand Down
6 changes: 5 additions & 1 deletion MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define CS_MCINST_H

#include "include/capstone/capstone.h"
#include "MCAsmInfo.h"
#include "MCInstrDesc.h"
#include "MCRegisterInfo.h"

Expand Down Expand Up @@ -73,6 +74,8 @@ int64_t MCOperand_getImm(const MCOperand *op);

void MCOperand_setImm(MCOperand *op, int64_t Val);

int64_t MCOperand_getExpr(const MCOperand *op);

double MCOperand_getFPImm(const MCOperand *op);

void MCOperand_setFPImm(MCOperand *op, double Val);
Expand Down Expand Up @@ -133,9 +136,10 @@ struct MCInst {
bool isAliasInstr; // Flag if this MCInst is an alias.
bool fillDetailOps; // If set, detail->operands gets filled.
hppa_ext hppa_ext; ///< for HPPA operand. Contains info about modifiers and their effect on the instruction
MCAsmInfo MAI; ///< The equivalent to MCAsmInfo in LLVM. It holds flags relevant for the asm style to print.
};

void MCInst_Init(MCInst *inst);
void MCInst_Init(MCInst *inst, cs_arch arch);

void MCInst_clear(MCInst *inst);

Expand Down
3 changes: 2 additions & 1 deletion Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ DEFINE_get_detail_op(hppa, HPPA);
DEFINE_get_detail_op(loongarch, LoongArch);
DEFINE_get_detail_op(mips, Mips);
DEFINE_get_detail_op(riscv, RISCV);
DEFINE_get_detail_op(systemz, SystemZ);

/// Returns true if for this architecture the
/// alias operands should be filled.
Expand Down Expand Up @@ -433,7 +434,7 @@ uint64_t enum_map_bin_search(const cs_enum_id_map *map, size_t map_len,
} else if (id[i] > map[m].str[j]) {
l = m + 1;
}
if (m == 0 || (l + r) / 2 >= map_len) {
if ((m == 0 && id[i] < map[m].str[j]) || (l + r) / 2 >= map_len) {
// Break before we go out of bounds.
break;
}
Expand Down
5 changes: 5 additions & 0 deletions Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct insn_map {
ppc_suppl_info ppc;
loongarch_suppl_info loongarch;
aarch64_suppl_info aarch64;
systemz_suppl_info systemz;
} suppl_info; // Supplementary information for each instruction.
#endif
} insn_map;
Expand Down Expand Up @@ -140,6 +141,7 @@ DECL_get_detail_op(hppa, HPPA);
DECL_get_detail_op(loongarch, LoongArch);
DECL_get_detail_op(mips, Mips);
DECL_get_detail_op(riscv, RISCV);
DECL_get_detail_op(systemz, SystemZ);

/// Increments the detail->arch.op_count by one.
#define DEFINE_inc_detail_op_count(arch, ARCH) \
Expand Down Expand Up @@ -173,6 +175,8 @@ DEFINE_inc_detail_op_count(mips, Mips);
DEFINE_dec_detail_op_count(mips, Mips);
DEFINE_inc_detail_op_count(riscv, RISCV);
DEFINE_dec_detail_op_count(riscv, RISCV);
DEFINE_inc_detail_op_count(systemz, SystemZ);
DEFINE_dec_detail_op_count(systemz, SystemZ);

/// Returns true if a memory operand is currently edited.
static inline bool doing_mem(const MCInst *MI)
Expand Down Expand Up @@ -203,6 +207,7 @@ DEFINE_get_arch_detail(hppa, HPPA);
DEFINE_get_arch_detail(loongarch, LoongArch);
DEFINE_get_arch_detail(mips, Mips);
DEFINE_get_arch_detail(riscv, RISCV);
DEFINE_get_arch_detail(systemz, SystemZ);

static inline bool detail_is_set(const MCInst *MI)
{
Expand Down
Loading
Loading