This is an archive of the discontinued LLVM Phabricator instance.

Expose MCInst in C Disassembler API
Needs ReviewPublic

Authored by maurer on Jun 20 2014, 12:08 PM.

Details

Reviewers
wanders
Summary

Partially expose the MCInst struct from the C Disassembler API to allow mechanized examination of opcodes and arguments.

Diff Detail

Event Timeline

maurer updated this revision to Diff 10701.Jun 20 2014, 12:08 PM
maurer retitled this revision from to Expose MCInst in C Disassembler API.
maurer updated this object.
maurer edited the test plan for this revision. (Show Details)
maurer set the repository for this revision to rL LLVM.
maurer added a subscriber: Unknown Object (MLST).
wanders edited edge metadata.Jun 24 2014, 1:57 AM

I would find this to be a useful addition the the API. Especially if it could be extended with a function like LLVMMCInstIsFlowControl

include/llvm-c/MCInst.h
53–61

Can't this struct be kept opaque, like almost every other exposed type in the llvm-c api? Instead create accessor functions.

Does the API get too clunky if you get rid of the LLVMMCOperandRef type entirely? And instead have functions like LLVMMCInstGetOperandKind, LLVMMCInstGetOperandRegVal and so on?

lib/MC/MCInst.cpp
98–104

This looks like copy-paste error of isReg here.

tools/llvm-c-test/disassemble.c
46–49

It would be nice if the tests requested an MCInst here and dumped some information from it to make the new code at least run on tests. If you could add some checks on the output even better.

maurer edited edge metadata.Jun 24 2014, 3:16 PM
maurer set the repository for this revision to rL LLVM.
maurer updated this revision to Diff 10810.Jun 24 2014, 3:21 PM

Can you give some background on motivation here? I can't see why we'd
like to do this right now.

-eric

@echristo: I'm currently working on a redesign of a framework for doing analysis of compiled code. Our new ARM support works by using LLVM's disassembly capabilities from within OCaml. OCaml cannot bind directly to C++, and must bind against C instead.

My lab is not the only group which does binary analysis, and the hope in adding bindings like this is to make it easier for people working in languages other than C++ to use LLVM to help them go from binary strings to an object they can use.

Is there anything further that I can do to try to get these features or something similar in? This patch has been sitting dead for a while, and it would be nice if my projects could depend on mainline LLVM instead of needing to direct everyone working with me to install a patched version.

Have you addressed Kevin's comments in the email review thread?

maurer updated this revision to Diff 12413.Aug 12 2014, 1:07 PM
maurer updated this revision to Diff 12416.Aug 12 2014, 1:37 PM

Fixed whitespace issue