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

Implement fmt::Display for Instruction #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marlls1989
Copy link

Allow pretty printing decoded instructions, good for debugging and disassembly proposes.

Copy link
Owner

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for proposing this! I'm in favor of adding a display implementation for instructions, but I think it would be good if it matched the disassembler output. I think that should mostly be a matter of adding commas between fields, and prefixing register names by "x".


impl Display for Instruction {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also handle Instruction::Illegal with opcode unimp?

Instruction::Fcvtsw(r) => write!(f, "fcvtsw {} {}", r.rd(), r.rs1()),
Instruction::Fcvtswu(r) => write!(f, "fcvtswu {} {}", r.rd(), r.rs1()),
Instruction::Fmvwx(r) => write!(f, "fmvwx {} {}", r.rd(), r.rs1()),
_ => write!(f, "unknown"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any instructions missing? Would it be possible to switch this to an exhaustive match by panicking on Instruction::__Nonexhaustive?

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.

2 participants