aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--examples/add.rs4
-rw-r--r--examples/fib.rs3
-rw-r--r--examples/tiny_vm.rs3
-rw-r--r--src/imm.rs2
-rw-r--r--src/insn/add.rs3
-rw-r--r--src/insn/call.rs3
-rw-r--r--src/insn/cmp.rs3
-rw-r--r--src/insn/dec.rs3
-rw-r--r--src/insn/jmp.rs3
-rw-r--r--src/insn/jnz.rs3
-rw-r--r--src/insn/jz.rs3
-rw-r--r--src/insn/mov.rs3
-rw-r--r--src/insn/test.rs3
-rw-r--r--src/label.rs3
-rw-r--r--src/lib.rs8
-rw-r--r--src/prelude.rs10
-rw-r--r--src/reg.rs5
-rw-r--r--tests/jmp.rs3
-rw-r--r--tests/mov.rs3
20 files changed, 43 insertions, 35 deletions
diff --git a/README.md b/README.md
index ebb4b28..d0760d2 100644
--- a/README.md
+++ b/README.md
@@ -15,8 +15,9 @@ An `x64` jit assembler for learning purpose with the following two main goals:
## Example
```rust
-use juicebox_asm::prelude::{Reg32::*, *};
+use juicebox_asm::insn::*;
use juicebox_asm::Runtime;
+use juicebox_asm::{Asm, Imm32, Label, Reg32::*};
fn main() {
let mut asm = Asm::new();
@@ -45,8 +46,8 @@ fn main() {
asm.ret();
- let rt = Runtime::new(&asm.into_code());
- let func = unsafe { rt.as_fn::<extern "C" fn() -> u32>() };
+ let mut rt = Runtime::new();
+ let func = unsafe { rt.add_code::<extern "C" fn() -> u32>(&asm.into_code()) };
assert_eq!(func(), (0..=42).into_iter().sum());
}
```
diff --git a/examples/add.rs b/examples/add.rs
index 6935803..687d205 100644
--- a/examples/add.rs
+++ b/examples/add.rs
@@ -6,9 +6,9 @@
#[cfg(not(any(target_arch = "x86_64", target_os = "linux")))]
compile_error!("Only supported on x86_64 with SystemV abi");
-use juicebox_asm::prelude::*;
+use juicebox_asm::insn::*;
use juicebox_asm::Runtime;
-use Reg64::*;
+use juicebox_asm::{Asm, Imm64, Reg64::*};
extern "C" fn add(a: u32, b: u32) -> u32 {
a + b
diff --git a/examples/fib.rs b/examples/fib.rs
index e523b9d..c7505bb 100644
--- a/examples/fib.rs
+++ b/examples/fib.rs
@@ -3,8 +3,9 @@
//! Jit compile a function at runtime (generate native host code) to compute the fibonacci sequence
//! to demonstrate the [`juicebox_asm`] crate.
-use juicebox_asm::prelude::*;
+use juicebox_asm::insn::*;
use juicebox_asm::Runtime;
+use juicebox_asm::{Asm, Imm64, Label, Reg64};
const fn fib_rs(n: u64) -> u64 {
match n {
diff --git a/examples/tiny_vm.rs b/examples/tiny_vm.rs
index 51a8d44..bdeb202 100644
--- a/examples/tiny_vm.rs
+++ b/examples/tiny_vm.rs
@@ -39,8 +39,9 @@
#[cfg(not(any(target_arch = "x86_64", target_os = "linux")))]
compile_error!("Only supported on x86_64 with SystemV abi");
-use juicebox_asm::prelude::*;
+use juicebox_asm::insn::*;
use juicebox_asm::Runtime;
+use juicebox_asm::{Asm, Imm16, Imm64, Label, MemOp, Reg16, Reg64};
/// A guest physical address.
pub struct PhysAddr(pub u16);
diff --git a/src/imm.rs b/src/imm.rs
index ee51ae5..006f808 100644
--- a/src/imm.rs
+++ b/src/imm.rs
@@ -60,4 +60,4 @@ mod test {
assert_eq!(size_of::<usize>(), size_of::<Imm64>());
assert_eq!(size_of::<isize>(), size_of::<Imm64>());
}
-} \ No newline at end of file
+}
diff --git a/src/insn/add.rs b/src/insn/add.rs
index 8232fe4..0a6772a 100644
--- a/src/insn/add.rs
+++ b/src/insn/add.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Add;
+use crate::{Asm, Imm16, MemOp, Reg16, Reg32, Reg64};
impl Add<Reg64, Reg64> for Asm {
fn add(&mut self, op1: Reg64, op2: Reg64) {
diff --git a/src/insn/call.rs b/src/insn/call.rs
index 8a71db8..f089512 100644
--- a/src/insn/call.rs
+++ b/src/insn/call.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Call;
+use crate::{Asm, Reg64};
impl Call<Reg64> for Asm {
fn call(&mut self, op1: Reg64) {
diff --git a/src/insn/cmp.rs b/src/insn/cmp.rs
index 93aa26c..835202c 100644
--- a/src/insn/cmp.rs
+++ b/src/insn/cmp.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Cmp;
+use crate::{Asm, Imm16, MemOp};
impl Cmp<MemOp, Imm16> for Asm {
fn cmp(&mut self, op1: MemOp, op2: Imm16) {
diff --git a/src/insn/dec.rs b/src/insn/dec.rs
index c5803e7..1377d1c 100644
--- a/src/insn/dec.rs
+++ b/src/insn/dec.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Dec;
+use crate::{Asm, Reg32, Reg64};
impl Dec<Reg64> for Asm {
fn dec(&mut self, op1: Reg64) {
diff --git a/src/insn/jmp.rs b/src/insn/jmp.rs
index 71d1dbc..0539318 100644
--- a/src/insn/jmp.rs
+++ b/src/insn/jmp.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Jmp;
+use crate::{Asm, Label};
impl Jmp<&mut Label> for Asm {
fn jmp(&mut self, op1: &mut Label) {
diff --git a/src/insn/jnz.rs b/src/insn/jnz.rs
index 6517bd7..739d013 100644
--- a/src/insn/jnz.rs
+++ b/src/insn/jnz.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Jnz;
+use crate::{Asm, Label};
impl Jnz<&mut Label> for Asm {
fn jnz(&mut self, op1: &mut Label) {
diff --git a/src/insn/jz.rs b/src/insn/jz.rs
index 6563ca2..c591b1d 100644
--- a/src/insn/jz.rs
+++ b/src/insn/jz.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Jz;
+use crate::{Asm, Label};
impl Jz<&mut Label> for Asm {
fn jz(&mut self, op1: &mut Label) {
diff --git a/src/insn/mov.rs b/src/insn/mov.rs
index 2614d82..2f61e07 100644
--- a/src/insn/mov.rs
+++ b/src/insn/mov.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Mov;
+use crate::{Asm, Imm16, Imm32, Imm64, Imm8, MemOp, Reg16, Reg32, Reg64, Reg8};
// -- MOV : reg reg
diff --git a/src/insn/test.rs b/src/insn/test.rs
index b7ac774..e90d855 100644
--- a/src/insn/test.rs
+++ b/src/insn/test.rs
@@ -1,4 +1,5 @@
-use crate::prelude::*;
+use super::Test;
+use crate::{Asm, Imm16, MemOp, Reg32, Reg64};
impl Test<Reg64, Reg64> for Asm {
fn test(&mut self, op1: Reg64, op2: Reg64) {
diff --git a/src/label.rs b/src/label.rs
index a0bd864..4b441d9 100644
--- a/src/label.rs
+++ b/src/label.rs
@@ -6,7 +6,8 @@ use std::collections::HashSet;
/// A label which is used as target for jump instructions.
///
/// ```rust
-/// use juicebox_asm::prelude::*;
+/// use juicebox_asm::{Asm, Label, Reg64};
+/// use juicebox_asm::insn::{Mov, Jmp};
///
/// let mut lbl = Label::new();
/// let mut asm = Asm::new();
diff --git a/src/lib.rs b/src/lib.rs
index 8348435..65d70b5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,8 @@
//!
//! The following is an fibonacci example implementation.
//! ```rust
-//! use juicebox_asm::prelude::*;
+//! use juicebox_asm::{Asm, Reg64, Imm64, Label};
+//! use juicebox_asm::insn::*;
//! use juicebox_asm::Runtime;
//!
//! const fn fib_rs(n: u64) -> u64 {
@@ -72,14 +73,13 @@
//! }
//! ```
-pub mod prelude;
-
mod imm;
-mod insn;
mod label;
mod reg;
mod rt;
+pub mod insn;
+
pub use imm::{Imm16, Imm32, Imm64, Imm8};
pub use label::Label;
pub use reg::{Reg16, Reg32, Reg64, Reg8};
diff --git a/src/prelude.rs b/src/prelude.rs
deleted file mode 100644
index d8dd912..0000000
--- a/src/prelude.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-//! Crate prelude, which can be used to import the most important types at once.
-
-pub use crate::Asm;
-pub use crate::MemOp;
-
-pub use crate::imm::{Imm16, Imm32, Imm64, Imm8};
-pub use crate::label::Label;
-pub use crate::reg::{Reg16, Reg32, Reg64, Reg8};
-
-pub use crate::insn::{Add, Call, Cmp, Dec, Jmp, Jnz, Jz, Mov, Test};
diff --git a/src/reg.rs b/src/reg.rs
index 15417c4..43fd8af 100644
--- a/src/reg.rs
+++ b/src/reg.rs
@@ -158,7 +158,10 @@ mod tests {
assert!(!r.rexw());
// Check need REX byte.
- let rex = matches!(r, r8l | r9l | r10l | r11l | r12l | r13l | r14l | r15l | spl | bpl | sil | dil);
+ let rex = matches!(
+ r,
+ r8l | r9l | r10l | r11l | r12l | r13l | r14l | r15l | spl | bpl | sil | dil
+ );
assert_eq!(r.need_rex(), rex);
// Check need SIB byte.
diff --git a/tests/jmp.rs b/tests/jmp.rs
index 2524218..5f430ac 100644
--- a/tests/jmp.rs
+++ b/tests/jmp.rs
@@ -1,4 +1,5 @@
-use juicebox_asm::prelude::*;
+use juicebox_asm::insn::Jmp;
+use juicebox_asm::{Asm, Label};
#[test]
#[should_panic]
diff --git a/tests/mov.rs b/tests/mov.rs
index 58c0508..8cc0b19 100644
--- a/tests/mov.rs
+++ b/tests/mov.rs
@@ -1,4 +1,5 @@
-use juicebox_asm::prelude::{Reg16::*, Reg32::*, Reg64::*, Reg8::*, *};
+use juicebox_asm::insn::Mov;
+use juicebox_asm::{Asm, Imm16, Imm32, Imm64, Imm8, MemOp, Reg16::*, Reg32::*, Reg64::*, Reg8::*};
macro_rules! mov {
($op1:expr, $op2:expr) => {{