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

Extract DecodedInst::disassemble to a fmt module? #4

Open
flier opened this issue Feb 19, 2024 · 2 comments
Open

Extract DecodedInst::disassemble to a fmt module? #4

flier opened this issue Feb 19, 2024 · 2 comments

Comments

@flier
Copy link

flier commented Feb 19, 2024

There are a lot options about disassemble, we may need a fmt module for it, and need consider the issue of symbol resolution base on the context.

@Phantomical
Copy link
Member

I think a good approach might be to see how far we can push a DisassembleOptions struct with all those options. I'll try it. We might still need a fmt module to hold associated types but I prefer to keep commonly used items in the root module as long as it is reasonable to do so.

Phantomical added a commit to Phantomical/xed-rs that referenced this issue Feb 24, 2024
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
@Phantomical
Copy link
Member

I took a shot at wrapping disassemble over in #8. I did still end up needing a module for it see the PR for details :)

Would appreciate some opinions on it.

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

No branches or pull requests

2 participants