-
Notifications
You must be signed in to change notification settings - Fork 20
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
ckb-debugger support decode instruction #94
Conversation
ckb-debugger/src/decode.rs
Outdated
OP_SUB => Rtype(self.instruction).to_string(), | ||
OP_SUBW => Rtype(self.instruction).to_string(), | ||
OP_ADD => Rtype(self.instruction).to_string(), | ||
OP_ADDW => Rtype(self.instruction).to_string(), | ||
OP_XOR => Rtype(self.instruction).to_string(), | ||
OP_OR => Rtype(self.instruction).to_string(), | ||
OP_AND => Rtype(self.instruction).to_string(), | ||
OP_SLL => Rtype(self.instruction).to_string(), | ||
OP_SLLW => Rtype(self.instruction).to_string(), | ||
OP_SRL => Rtype(self.instruction).to_string(), | ||
OP_SRLW => Rtype(self.instruction).to_string(), | ||
OP_SRA => Rtype(self.instruction).to_string(), | ||
OP_SRAW => Rtype(self.instruction).to_string(), | ||
OP_SLT => Rtype(self.instruction).to_string(), | ||
OP_SLTU => Rtype(self.instruction).to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These match arms can be merged.
ckb-debugger/src/decode.rs
Outdated
ISA::Imc => "Base Instruction", | ||
ISA::A => "A extension", | ||
ISA::B => "B extension", | ||
ISA::Mop => "MOP extension", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RISC-V doesn't have MOP extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use TaggedInstruction to get this job done
if let Some(i) = instructions::i::factory::<u64>(instruction, VERSION2) {
let tagged_instruction_option = instructions::tagged::TaggedInstruction::try_from(i);
if let Ok(tagged_instruction) = tagged_instruction_option {
println!("{}", tagged_instruction)
} else {
println!("unknown instruction");
}
}
result:
addi a7,93(zero) # if instruction is 0x05d00893
ckb-debugger/src/decode.rs
Outdated
} | ||
|
||
pub fn decode_instruction(data: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
let has_0x = data.find("0x"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data.start_with("0x")
ckb-debugger/src/decode.rs
Outdated
} | ||
} | ||
|
||
fn get_isa(ins_opcode: InstructionOpcode) -> ISA { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ckb-vm does not guarantee that the instructions in an instruction set are ordered together. For example branch instructions in IMC are not grouped with other IMC instructions, See: https://github.com/nervosnetwork/ckb-vm/blob/develop/definitions/src/instructions.rs#L270-L287
I think there is an easier way to do it, just do things like below if let Some(i) = instructions::i::factory::<u64>(instruction, VERSION2) {
let tagged_instruction = instructions::tagged::TaggedInstruction::try_from(i).unwrap();
println!("{} (ISA_I)", tagged_instruction)
}
if let Some(i) = instructions::m::factory::<u64>(instruction, VERSION2) {
let tagged_instruction = instructions::tagged::TaggedInstruction::try_from(i).unwrap();
println!("{} (ISA_M)", tagged_instruction)
}
if let Some(i) = instructions::a::factory::<u64>(instruction, VERSION2) {
let tagged_instruction = instructions::tagged::TaggedInstruction::try_from(i).unwrap();
println!("{} (ISA_A)", tagged_instruction)
}
if let Some(i) = instructions::b::factory::<u64>(instruction, VERSION2) {
let tagged_instruction = instructions::tagged::TaggedInstruction::try_from(i).unwrap();
println!("{} (ISA_B)", tagged_instruction)
}
if let Some(i) = instructions::rvc::factory::<u64>(instruction, VERSION2) {
let tagged_instruction = instructions::tagged::TaggedInstruction::try_from(i).unwrap();
println!("{} (ISA_RVC)", tagged_instruction)
} |
No description provided.