Skip to content
This repository was archived by the owner on Jun 21, 2026. It is now read-only.

Implement fmt::Display for Instruction - #5

Open
marlls1989 wants to merge 2 commits into
fintelia:mainfrom
marlls1989:master
Open

Implement fmt::Display for Instruction#5
marlls1989 wants to merge 2 commits into
fintelia:mainfrom
marlls1989:master

Conversation

@marlls1989

Copy link
Copy Markdown

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

@fintelia fintelia left a comment

Copy link
Copy Markdown
Owner

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

Comment thread src/instruction.rs

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

Copy link
Copy Markdown
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?

Comment thread src/instruction.rs
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants