Skip to content

Commit f40e53e

Browse files
authored
Add basic pulley disassembly support to clif-util (#9721)
* Add basic pulley disassembly support to `clif-util` Helpful when running `clif-util compile -D --target pulley64` over the input. * Fix non-pulley build
1 parent 350a6e2 commit f40e53e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cranelift/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ rustc-hash = { workspace = true }
5252
# Note that this just enables `trace-log` for `clif-util` and doesn't turn it on
5353
# for all of Cranelift, which would be bad.
5454
regalloc2 = { workspace = true, features = ["trace-log"] }
55+
pulley-interpreter = { workspace = true, optional = true }
5556

5657
[features]
5758
default = [
@@ -64,3 +65,4 @@ disas = ["capstone"]
6465
souper-harvest = ["cranelift-codegen/souper-harvest", "rayon"]
6566
all-arch = ["cranelift-codegen/all-arch"]
6667
all-native-arch = ["cranelift-codegen/all-native-arch"]
68+
pulley = ['cranelift-codegen/pulley', 'dep:pulley-interpreter']

cranelift/src/disasm.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,22 @@ pub fn print_traps(traps: &[MachTrap]) -> String {
3939
cfg_if! {
4040
if #[cfg(feature = "disas")] {
4141
pub fn print_disassembly(func: &Function, isa: &dyn TargetIsa, mem: &[u8]) -> Result<()> {
42+
#[cfg(feature = "pulley")]
43+
let is_pulley = match isa.triple().architecture {
44+
target_lexicon::Architecture::Pulley32 | target_lexicon::Architecture::Pulley64 => true,
45+
_ => false,
46+
};
47+
println!("\nDisassembly of {} bytes <{}>:", mem.len(), func.name);
48+
49+
#[cfg(feature = "pulley")]
50+
if is_pulley {
51+
let mut disas = pulley_interpreter::disas::Disassembler::new(mem);
52+
pulley_interpreter::decode::Decoder::decode_all(&mut disas)?;
53+
println!("{}", disas.disas());
54+
return Ok(());
55+
}
4256
let cs = isa.to_capstone().map_err(|e| anyhow::format_err!("{}", e))?;
4357

44-
println!("\nDisassembly of {} bytes <{}>:", mem.len(), func.name);
4558
let insns = cs.disasm_all(&mem, 0x0).unwrap();
4659
for i in insns.iter() {
4760
let mut line = String::new();

pulley/src/disas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'a> OpVisitor for Disassembler<'a> {
274274
write!(&mut self.disas, "{space}{byte:02x}").unwrap();
275275
need_space = true;
276276
}
277-
for _ in 0..11_usize.saturating_sub(size) {
277+
for _ in 0..12_usize.saturating_sub(size) {
278278
write!(&mut self.disas, " ").unwrap();
279279
}
280280
}

0 commit comments

Comments
 (0)