From 7e758f4d684199c90ec1bb9107908e506bf736cf Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 20 Dec 2024 22:36:06 +0000 Subject: deploy: 6cc2331c8ff8e7372cd6e9a339250a9d8b58a547 --- src/juicebox_asm/asm.rs.html | 28 ++++++++++- src/juicebox_asm/disasm.rs.html | 103 ++++++++++++++++++++++++++++++++++++++++ src/juicebox_asm/lib.rs.html | 4 +- src/juicebox_asm/rt.rs.html | 78 +----------------------------- 4 files changed, 135 insertions(+), 78 deletions(-) create mode 100644 src/juicebox_asm/disasm.rs.html (limited to 'src') diff --git a/src/juicebox_asm/asm.rs.html b/src/juicebox_asm/asm.rs.html index ebc7c4a..7013bab 100644 --- a/src/juicebox_asm/asm.rs.html +++ b/src/juicebox_asm/asm.rs.html @@ -426,7 +426,20 @@ 425 426 427 -428
//! The `x64` jit assembler.
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
//! The `x64` jit assembler.
 
 use crate::imm::Imm;
 use crate::mem::{AddrMode, Mem, Mem16, Mem32, Mem64, Mem8};
@@ -470,6 +483,19 @@
         self.buf
     }
 
+    /// Disassemble the code currently added to the runtime, using
+    /// [`ndisasm`](https://nasm.us/index.php) and print it to _stdout_. If
+    /// `ndisasm` is not available on the system this prints a warning and
+    /// becomes a nop.
+    ///
+    /// # Panics
+    ///
+    /// Panics if anything goes wrong with spawning, writing to or reading from
+    /// the `ndisasm` child process.
+    pub fn disasm(&self) {
+        crate::disasm::disasm(&self.buf);
+    }
+
     /// Emit a slice of bytes.
     pub(crate) fn emit(&mut self, bytes: &[u8]) {
         self.buf.extend_from_slice(bytes);
diff --git a/src/juicebox_asm/disasm.rs.html b/src/juicebox_asm/disasm.rs.html
new file mode 100644
index 0000000..7532d9a
--- /dev/null
+++ b/src/juicebox_asm/disasm.rs.html
@@ -0,0 +1,103 @@
+disasm.rs - source

juicebox_asm/
disasm.rs

+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
use std::io::{ErrorKind, Write};
+use std::process::{Command, Stdio};
+
+/// Disassemble the code currently added to the runtime, using
+/// [`ndisasm`](https://nasm.us/index.php) and print it to _stdout_. If
+/// `ndisasm` is not available on the system this prints a warning and
+/// becomes a nop.
+///
+/// # Panics
+///
+/// Panics if anything goes wrong with spawning, writing to or reading from
+/// the `ndisasm` child process.
+pub(crate) fn disasm<T: AsRef<[u8]>>(code: T) {
+    let code = code.as_ref();
+
+    // Create ndisasm process, which expects input on stdin.
+    let mut child = match Command::new("ndisasm")
+        .args(["-b64", "-"])
+        .stdin(Stdio::piped())
+        .stdout(Stdio::piped())
+        .spawn()
+    {
+        Ok(child) => child,
+        Err(err) if err.kind() == ErrorKind::NotFound => {
+            println!("disasm: skipping, ndisasm not found");
+            return;
+        }
+        Err(err) => {
+            panic!("{:?}", err);
+        }
+    };
+
+    // Write code to stdin of ndisasm.
+    child
+        .stdin
+        .take()
+        .expect("failed to take stdin")
+        .write_all(code)
+        .expect("failed to write bytes to stdin");
+
+    // Wait for output from ndisasm and print to stdout.
+    println!(
+        "{}",
+        String::from_utf8_lossy(
+            &child
+                .wait_with_output()
+                .expect("failed to get stdout")
+                .stdout
+        )
+    );
+}
+
\ No newline at end of file diff --git a/src/juicebox_asm/lib.rs.html b/src/juicebox_asm/lib.rs.html index 4b32e80..3cc3369 100644 --- a/src/juicebox_asm/lib.rs.html +++ b/src/juicebox_asm/lib.rs.html @@ -88,7 +88,8 @@ 87 88 89 -90
//! A simple `x64` jit assembler with a minimal runtime to execute emitted code for fun.
+90
+91
//! A simple `x64` jit assembler with a minimal runtime to execute emitted code for fun.
 //!
 //! The following is an fibonacci example implementation.
 //! ```rust
@@ -164,6 +165,7 @@
 //! ```
 
 mod asm;
+mod disasm;
 mod imm;
 mod label;
 mod mem;
diff --git a/src/juicebox_asm/rt.rs.html b/src/juicebox_asm/rt.rs.html
index d138a8e..0bef785 100644
--- a/src/juicebox_asm/rt.rs.html
+++ b/src/juicebox_asm/rt.rs.html
@@ -262,44 +262,7 @@
 261
 262
 263
-264
-265
-266
-267
-268
-269
-270
-271
-272
-273
-274
-275
-276
-277
-278
-279
-280
-281
-282
-283
-284
-285
-286
-287
-288
-289
-290
-291
-292
-293
-294
-295
-296
-297
-298
-299
-300
-301
//! Simple `mmap`ed runtime.
+264
//! Simple `mmap`ed runtime.
 //!
 //! This runtime supports adding code to executable pages and turn the added code into user
 //! specified function pointer.
@@ -468,44 +431,7 @@
     /// the `ndisasm` child process.
     pub fn disasm(&self) {
         assert!(self.idx <= self.len);
-        let code = unsafe { core::slice::from_raw_parts(self.buf, self.idx) };
-
-        // Create ndisasm process, which expects input on stdin.
-        let mut child = match std::process::Command::new("ndisasm")
-            .args(["-b64", "-"])
-            .stdin(std::process::Stdio::piped())
-            .stdout(std::process::Stdio::piped())
-            .spawn()
-        {
-            Ok(child) => child,
-            Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
-                println!("Runtime::disasm: ndisasm not found, skipping!");
-                return;
-            }
-            Err(err) => {
-                panic!("{:?}", err);
-            }
-        };
-
-        // Write code to stdin of ndisasm.
-        use std::io::Write;
-        child
-            .stdin
-            .take()
-            .expect("failed to take stdin")
-            .write_all(code)
-            .expect("failed to write bytes to stdin");
-
-        // Wait for output from ndisasm and print to stdout.
-        println!(
-            "{}",
-            String::from_utf8_lossy(
-                &child
-                    .wait_with_output()
-                    .expect("failed to get stdout")
-                    .stdout
-            )
-        );
+        crate::disasm::disasm(unsafe { core::slice::from_raw_parts(self.buf, self.idx) });
     }
 
     /// Reinterpret the block of code pointed to by `fn_start` as `F`.
-- 
cgit v1.2.3