[前][次][番号順一覧][スレッド一覧]

ruby-changes:73202

From: Noah <ko1@a...>
Date: Tue, 30 Aug 2022 01:00:25 +0900 (JST)
Subject: [ruby-changes:73202] f5f58d8283 (master): Update disasm to work on ARM (https://github.com/Shopify/ruby/pull/331)

https://git.ruby-lang.org/ruby.git/commit/?id=f5f58d8283

From f5f58d82834cf84fe15dd1b28754923404a9fc75 Mon Sep 17 00:00:00 2001
From: Noah Gibbs <the.codefolio.guy@g...>
Date: Wed, 20 Jul 2022 15:56:13 +0100
Subject: Update disasm to work on ARM
 (https://github.com/Shopify/ruby/pull/331)

---
 yjit/src/backend/arm64/mod.rs | 24 ++++++++++++++++++++++++
 yjit/src/disasm.rs            |  9 +++++++++
 2 files changed, 33 insertions(+)

diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs
index be329f61cf..c5ddbea7c1 100644
--- a/yjit/src/backend/arm64/mod.rs
+++ b/yjit/src/backend/arm64/mod.rs
@@ -767,4 +767,28 @@ mod tests { https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L767
 
         asm.compile_with_num_regs(&mut cb, 1);
     }
+
+    #[test]
+    #[cfg(feature = "disasm")]
+    fn test_simple_disasm() -> std::result::Result<(), capstone::Error> {
+        // Test drive Capstone with simple input
+        use capstone::prelude::*;
+
+        let cs = Capstone::new()
+            .arm64()
+            .mode(arch::arm64::ArchMode::Arm)
+            .build()?;
+
+        let insns = cs.disasm_all(&[0x60, 0x0f, 0x80, 0xF2], 0x1000)?;
+
+        match insns.as_ref() {
+            [insn] => {
+                assert_eq!(Some("movk"), insn.mnemonic());
+                Ok(())
+            }
+            _ => Err(capstone::Error::CustomError(
+                "expected to disassemble to movk",
+            )),
+        }
+    }
 }
diff --git a/yjit/src/disasm.rs b/yjit/src/disasm.rs
index 83c80d6c66..62b270bce9 100644
--- a/yjit/src/disasm.rs
+++ b/yjit/src/disasm.rs
@@ -69,6 +69,8 @@ pub fn disasm_iseq_insn_range(iseq: IseqPtr, start_idx: u32, end_idx: u32) -> St https://github.com/ruby/ruby/blob/trunk/yjit/src/disasm.rs#L69
 
     // Initialize capstone
     use capstone::prelude::*;
+
+    #[cfg(target_arch = "x86_64")]
     let cs = Capstone::new()
         .x86()
         .mode(arch::x86::ArchMode::Mode64)
@@ -76,6 +78,13 @@ pub fn disasm_iseq_insn_range(iseq: IseqPtr, start_idx: u32, end_idx: u32) -> St https://github.com/ruby/ruby/blob/trunk/yjit/src/disasm.rs#L78
         .build()
         .unwrap();
 
+    #[cfg(target_arch = "aarch64")]
+    let cs = Capstone::new()
+        .arm64()
+        .mode(arch::arm64::ArchMode::Arm)
+        .build()
+        .unwrap();
+
     out.push_str(&format!("NUM BLOCK VERSIONS: {}\n", block_list.len()));
     out.push_str(&format!(
         "TOTAL INLINE CODE SIZE: {} bytes\n",
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]