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

Add bindings for instruction disassembly #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Phantomical
Copy link
Member

This is my attempt at wrapping xed_format_generic in an idiomatic wrapper. I'm rather happy with how it turned out.

This PR introduces three function variants to cover the different use cases for xed_format_generic. All three are methods of DecodedInst.

fn disassemble(&self, syntax: Syntax) -> String

This is the simplest one. No configuration, just provide a syntax and get a disassembly string.

fn disassemble_with<F>(&self, options: DisassembleOptions<F>) -> String

More complex. Now you configure it by passing in options. This variant is still infallible so it probably won't work with any complicated disassembly callback. In order to be infallible it requires that the callback's error type is std::convert::Infallible.

fn try_disassemble_with<F>(&self, options: DisassembleOptions<F>) -> Result<String, F::Error>

This one supports the most options. It supports any disassembly callback and takes care of plumbing the error around in the XED callback.

There are a couple of different types that are used as part of this API. I've created a new top-level disassemble module and stuck them in there. It also gives a convenient place to stick some guide level documentation and example on how to use the API.

Other notes

  • It's not possible to implement DisassemblyCallback for both FnMut(u64, &mut WriteBuf<'_>) -> Option<u64> and FnMut(u64, &mut WriteBuf<'_>) -> Result<Option<u64>, E>. I've chosen to only implement it for the first one with the idea that actually implementing the trait on a type is less likely to be as much of an issue when the disassembly callback is complicated enough to need to return a result.

src/disassemble.rs Fixed Show fixed Hide fixed
src/disassemble.rs Fixed Show fixed Hide fixed
This is my attempt at wrapping xed_format_generic in an idiomatic
wrapper. I'm rather happy with how it turned out.

This PR introduces three function variants to cover the different use
cases for xed_format_generic. All three are methods of `DecodedInst`.

fn disassemble(&self, syntax: Syntax) -> String

This is the simplest one. No configuration, just provide a syntax and
get a disassembly string.

fn disassemble_with<F>(&self, options: DisassembleOptions<F>) -> String

More complex. Now you configure it by passing in options. This variant
is still infallible so it probably won't work with any complicated
disassembly callback. In order to be infallible it requires that the
callback's error type is std::convert::Infallible.

fn try_disassemble_with<F>(&self, options: DisassembleOptions<F>)
    -> Result<String, F::Error>

This one supports the most options. It supports any disassembly callback
and takes care of plumbing the error around in the XED callback.

There are a couple of different types that are used as part of this API.
I've created a new top-level `disassemble` module and stuck them in
there. It also gives a convenient place to stick some guide level
documentation and example on how to use the API.

Closes rust-xed#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant