capstone icon indicating copy to clipboard operation
capstone copied to clipboard

expose tablegen API

Open gogo2464 opened this issue 1 year ago • 7 comments

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 avatar Dec 25 '22 03:12 gogo2464

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

gogo2464 avatar Dec 25 '22 03:12 gogo2464

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

XVilka avatar Jan 04 '23 04:01 XVilka

@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.

Rot127 avatar Jun 04 '23 15:06 Rot127

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?

gogo2464 avatar Jun 04 '23 20:06 gogo2464

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

Rot127 avatar Jun 04 '23 21:06 Rot127

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

XVilka avatar Apr 07 '24 05:04 XVilka

@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.

Rot127 avatar Apr 07 '24 05:04 Rot127