Skip to content

Comments

Implement fmt::Display for Instruction#5

Open
marlls1989 wants to merge 2 commits intofintelia:mainfrom
marlls1989:master
Open

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

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