capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.53k stars 1.55k forks source link

expose tablegen API #1945

Open gogo2464 opened 1 year ago

gogo2464 commented 1 year ago

I am writting a cryptanalysis library. I need to get statistics on opcodes repartition on the code. So I need to generate any valid assembled <-> disassembled instructions on a BiBTreeMap in rust.

I need to implement bindings for tablegen to this library : https://github.com/capstone-rust/capstone-rs/ and I imagine the library author needs an exposed library first.

Could you assign me to this issue please?

The files I want to edit are here: https://github.com/capstone-engine/capstone/tree/next/suite/synctools/tablegen

gogo2464 commented 1 year ago

It is the bad branch. Anyway I plan to add api in https://github.com/capstone-engine/capstone/tree/master/include/capstone

XVilka commented 1 year ago

It's related to the work being done by @Rot127, see https://github.com/capstone-engine/capstone/issues/1936#issuecomment-1336483495

Rot127 commented 1 year ago

@gogo2464 If I understand your problem correctly you need primarily information what bit in an instruction encodes what (regs, imms, opcode etc.) + certain constraints. It seems your issue is related to https://github.com/capstone-engine/capstone/issues/2031?

If you need access to the TableGen definitions in all its detail, I highly recommend to write a new backend for TableGen and generate the map there. Simply because there is no reasonable way to provide access to all records of the .td files.

If you are still interested in this it is probably better to wait until the main auto-sync work is done (minimum requirement is https://github.com/capstone-engine/capstone/pull/2026) and then discuss how to add this info.

To learn how we generate code with the help of refactored TableGen backends, see the llvm-capstone docs.

gogo2464 commented 1 year ago

I currently have hardcoded the statistics. This is very imprecise. Can I wait in order to overwrite my hardcoded value with more specific data please?

Rot127 commented 1 year ago

Yes, of cause. Feel free to come back to it when you find time.

XVilka commented 6 months ago

@gogo2464 now that auto-sync code was refactored and merged, could you please check the code and if anything is missing.

Rot127 commented 6 months ago

@gogo2464 And please check if https://github.com/capstone-engine/capstone/pull/2296 was merged before. It is a refactor and clean up PR for the scripts. So use the code from there please.