Implement fmt::Display for Instruction#5
Open
marlls1989 wants to merge 2 commits intofintelia:mainfrom
Open
Conversation
fintelia
reviewed
Jul 17, 2022
Owner
fintelia
left a comment
There was a problem hiding this comment.
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 { |
Owner
There was a problem hiding this comment.
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"), |
Owner
There was a problem hiding this comment.
Are there any instructions missing? Would it be possible to switch this to an exhaustive match by panicking on Instruction::__Nonexhaustive?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow pretty printing decoded instructions, good for debugging and disassembly proposes.