Skip to content

Refactoring the RISCV architecture to Auto-Sync on LLVM#2756

Merged
Rot127 merged 32 commits into
capstone-engine:nextfrom
moste00:refactor_riscv_autosync
Feb 1, 2026
Merged

Refactoring the RISCV architecture to Auto-Sync on LLVM#2756
Rot127 merged 32 commits into
capstone-engine:nextfrom
moste00:refactor_riscv_autosync

Conversation

@moste00
Copy link
Copy Markdown
Contributor

@moste00 moste00 commented Jul 16, 2025

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

This PR is attempting to refactor the RISCV architecture to be updatable from the Auto-Sync tool, such that it automatically follows RISCV-in-LLVM additions and fixes. Following the refactoring guide

depends-on: capstone-engine/llvm-capstone#83

Test plan

...

Closing issues

...

Comment thread arch/RISCV/RISCVInstPrinter.c Outdated
Comment thread arch/RISCV/RISCVInstPrinter.c Outdated
Comment thread arch/RISCV/RISCVInstPrinter.c Outdated
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Aug 14, 2025

cc @hainest You are probably aware of this PR, just wanted to ping you as well. Because you mentioned in the Zydis discussion you use Capstone for RISCV as well.

@hainest
Copy link
Copy Markdown
Contributor

hainest commented Aug 14, 2025

cc @hainest You are probably aware of this PR, just wanted to ping you as well. Because you mentioned in the Zydis discussion you use Capstone for RISCV as well.

I had not seen this. @wxrdnx have you looked at this?

Comment thread tests/MC/RISCV/XCVmac_valid_riscv32_xcvmac.txt.yaml Outdated
Comment thread suite/cstest/include/test_mapping.h Outdated
Comment on lines +188 to +189
{ .str = "riscv32", .val = CS_MODE_RISCV32 },
{ .str = "riscv64", .val = CS_MODE_RISCV64 },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In response to above. Please stick with the Capstone flag naming convention.
Is RSICV32 is anything else than just 32bit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a point, but I don't know, RISCV[32|64] and RISCVC were legacy flags that were already in the old plugin, so I kept them.

Removing them would probably not affect anything but just be a hassle, it could also be the case that the generated code references them from lots of places and changing the generated code is always a hassle.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generated code references them

Which one? The test files from the MCUpdater? Those ones can be replaced as described here #2756 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rot127 sorry for the late reply, yes, only the yaml MC tests reference those values, plus a few references in handwritten code in the cstool.c and so on, so it's doable to replace them, will do.

Although this might break APIs, because I see some Python usage from my editor search, until now I have avoided deleting enum members from includes/riscv.h, that's why we still have CS_MODE_RISCV_C and CS_MODE_RISCVC.

Comment thread include/capstone/capstone.h Outdated
Comment thread suite/cstest/include/test_mapping.h Outdated
@Rot127 Rot127 added this to the v6 - Beta milestone Sep 1, 2025
@Rot127 Rot127 added the blocker Must be finished with the assigned milestone. label Sep 1, 2025
Comment thread cstool/cstool.c Outdated
Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check out the helper functions in Mapping.h. They should always be used for these tasks. Because they do bounds checking and such. Accessing the struct members directly (e.g. like details->groups[details->groups_count]) should be the absolute exception, not the rule.

You can also see how the helpers are used in other architectures and just do it the same way. LoongArch is a good example, because it is relatively simple.
AArch64 has many very complex operands. You can check its code if you need examples for these cases.

Comment thread arch/RISCV/RISCVMapping.c Outdated
Comment thread arch/RISCV/RISCVMapping.c Outdated
Comment thread arch/RISCV/RISCVMapping.c Outdated
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Sep 17, 2025

The conflicts are coming from the clang-format formatting we did recently btw. So nothing to preserve there.
You can just accept all your changes.

Comment thread suite/cstest/include/test_compare.h
Comment thread arch/RISCV/RISCVMapping.c
@moste00 moste00 force-pushed the refactor_riscv_autosync branch from 12882dc to 1d59145 Compare October 17, 2025 01:16
@moste00 moste00 marked this pull request as ready for review October 17, 2025 01:19
Comment thread include/capstone/capstone.h Outdated
Comment thread arch/RISCV/RISCVBaseInfo.c
Comment thread arch/RISCV/RISCVMapping.c Outdated
@github-actions github-actions Bot added the Python Bindings label Nov 14, 2025
@moste00 moste00 force-pushed the refactor_riscv_autosync branch 2 times, most recently from 0e5a2a8 to f99aa52 Compare November 15, 2025 22:28
@moste00 moste00 force-pushed the refactor_riscv_autosync branch from 96b38b1 to 6b3d2f0 Compare December 23, 2025 21:58
Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moste00 One exceptionally important thing still missing is the documentation in the v6 release guide. It is the first thing we will send people to for questions.

…t broke due to fixing it, add command line switches to turn on and off ZB* and ZBK* extensions
@moste00 moste00 mentioned this pull request Jan 10, 2026
2 tasks
Comment thread arch/RISCV/RISCVBaseInfo.c Outdated
Comment thread arch/RISCV/RISCVBaseInfo.c Outdated
Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know it already, but terrific job you did there!
Thanks a lot!

I have only this last change.
Otherwise this lgtm.

Comment thread arch/RISCV/RISCVMapping.c Outdated
@Rot127 Rot127 merged commit ec6428f into capstone-engine:next Feb 1, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Sync-files Auto-Sync blocker Must be finished with the assigned milestone. CS-core-files auto-sync LLVM-core-files auto-sync LLVM-generated-files Python Bindings RISCV Arch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants