From 2294180c3778d0fcfa877818e98c420fcd54bb8a Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 5 Dec 2023 22:08:06 +0000 Subject: deploy: 7e98f5def5942969f97f5f015e7fb8417793d132 --- tiny_vm/all.html | 1 + tiny_vm/enum.TinyInsn.html | 32 ++++++++++++++++++++++++++++++++ tiny_vm/enum.TinyReg.html | 19 +++++++++++++++++++ tiny_vm/fn.make_tinyvm_fib.html | 2 ++ tiny_vm/fn.make_tinyvm_jit_perf.html | 2 ++ tiny_vm/fn.make_tinyvm_jit_test.html | 2 ++ tiny_vm/index.html | 34 ++++++++++++++++++++++++++++++++++ tiny_vm/sidebar-items.js | 1 + tiny_vm/struct.Fixup.html | 14 ++++++++++++++ tiny_vm/struct.PhysAddr.html | 12 ++++++++++++ tiny_vm/struct.TinyVm.html | 21 +++++++++++++++++++++ 11 files changed, 140 insertions(+) create mode 100644 tiny_vm/all.html create mode 100644 tiny_vm/enum.TinyInsn.html create mode 100644 tiny_vm/enum.TinyReg.html create mode 100644 tiny_vm/fn.make_tinyvm_fib.html create mode 100644 tiny_vm/fn.make_tinyvm_jit_perf.html create mode 100644 tiny_vm/fn.make_tinyvm_jit_test.html create mode 100644 tiny_vm/index.html create mode 100644 tiny_vm/sidebar-items.js create mode 100644 tiny_vm/struct.Fixup.html create mode 100644 tiny_vm/struct.PhysAddr.html create mode 100644 tiny_vm/struct.TinyVm.html (limited to 'tiny_vm') diff --git a/tiny_vm/all.html b/tiny_vm/all.html new file mode 100644 index 0000000..f24eb24 --- /dev/null +++ b/tiny_vm/all.html @@ -0,0 +1 @@ +List of all items in this crate
\ No newline at end of file diff --git a/tiny_vm/enum.TinyInsn.html b/tiny_vm/enum.TinyInsn.html new file mode 100644 index 0000000..ac8d1b9 --- /dev/null +++ b/tiny_vm/enum.TinyInsn.html @@ -0,0 +1,32 @@ +TinyInsn in tiny_vm - Rust

Enum tiny_vm::TinyInsn

source ·
pub enum TinyInsn {
+    Halt,
+    LoadImm(TinyReg, u16),
+    Load(TinyReg, u16),
+    Store(TinyReg, u16),
+    Add(TinyReg, TinyReg),
+    Addi(TinyReg, i16),
+    Branch(usize),
+    BranchZero(TinyReg, usize),
+}
Expand description

The instructions for the TinyVm.

+

Variants§

§

Halt

Halt the VM.

+
§

LoadImm(TinyReg, u16)

Load the immediate value into the register reg = imm.

+
§

Load(TinyReg, u16)

Load a value from the memory (absolute addressing) into the register reg = mem[imm].

+
§

Store(TinyReg, u16)

Store a value from the register into the memory (absolute addressing) mem[imm] = reg.

+
§

Add(TinyReg, TinyReg)

Add the register to the register reg1 += reg2.

+
§

Addi(TinyReg, i16)

Add the immediate to the register reg += imm.

+
§

Branch(usize)

Jump unconditional (absolute addressing) pc = disp.

+
§

BranchZero(TinyReg, usize)

Jump if the register is zero (absolute addressing) pc = (reg == 0) ? disp : pc++.

+

Trait Implementations§

source§

impl Clone for TinyInsn

source§

fn clone(&self) -> TinyInsn

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TinyInsn

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<TinyInsn> for TinyInsn

source§

fn eq(&self, other: &TinyInsn) -> bool

This method tests for self and other values to be equal, and is used +by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always +sufficient, and should not be overridden without very good reason.
source§

impl Copy for TinyInsn

source§

impl StructuralPartialEq for TinyInsn

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere + T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere + T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere + T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

+
source§

impl<T, U> Into<U> for Twhere + U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

+

That is, this conversion is whatever the implementation of +From<T> for U chooses to do.

+
source§

impl<T> ToOwned for Twhere + T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere + U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere + U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
\ No newline at end of file diff --git a/tiny_vm/enum.TinyReg.html b/tiny_vm/enum.TinyReg.html new file mode 100644 index 0000000..61495de --- /dev/null +++ b/tiny_vm/enum.TinyReg.html @@ -0,0 +1,19 @@ +TinyReg in tiny_vm - Rust

Enum tiny_vm::TinyReg

source ·
pub enum TinyReg {
+    A,
+    B,
+    C,
+}
Expand description

The registers for the TinyVm.

+

Variants§

Trait Implementations§

source§

impl Clone for TinyReg

source§

fn clone(&self) -> TinyReg

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TinyReg

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<TinyReg> for TinyReg

source§

fn eq(&self, other: &TinyReg) -> bool

This method tests for self and other values to be equal, and is used +by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always +sufficient, and should not be overridden without very good reason.
source§

impl Copy for TinyReg

source§

impl StructuralPartialEq for TinyReg

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere + T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere + T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere + T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

+
source§

impl<T, U> Into<U> for Twhere + U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

+

That is, this conversion is whatever the implementation of +From<T> for U chooses to do.

+
source§

impl<T> ToOwned for Twhere + T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere + U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere + U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
\ No newline at end of file diff --git a/tiny_vm/fn.make_tinyvm_fib.html b/tiny_vm/fn.make_tinyvm_fib.html new file mode 100644 index 0000000..03ed4e0 --- /dev/null +++ b/tiny_vm/fn.make_tinyvm_fib.html @@ -0,0 +1,2 @@ +make_tinyvm_fib in tiny_vm - Rust

Function tiny_vm::make_tinyvm_fib

source ·
pub fn make_tinyvm_fib(start_n: u16) -> Vec<TinyInsn>
Expand description

Generate a guest program to compute the fiibonacci sequence for n.

+
\ No newline at end of file diff --git a/tiny_vm/fn.make_tinyvm_jit_perf.html b/tiny_vm/fn.make_tinyvm_jit_perf.html new file mode 100644 index 0000000..fa4fee2 --- /dev/null +++ b/tiny_vm/fn.make_tinyvm_jit_perf.html @@ -0,0 +1,2 @@ +make_tinyvm_jit_perf in tiny_vm - Rust
pub fn make_tinyvm_jit_perf() -> Vec<TinyInsn>
Expand description

Generate a simple count down loop to crunch some instructions.

+
\ No newline at end of file diff --git a/tiny_vm/fn.make_tinyvm_jit_test.html b/tiny_vm/fn.make_tinyvm_jit_test.html new file mode 100644 index 0000000..88ebf5b --- /dev/null +++ b/tiny_vm/fn.make_tinyvm_jit_test.html @@ -0,0 +1,2 @@ +make_tinyvm_jit_test in tiny_vm - Rust
pub fn make_tinyvm_jit_test() -> Vec<TinyInsn>
Expand description

Generate a test program for the jit.

+
\ No newline at end of file diff --git a/tiny_vm/index.html b/tiny_vm/index.html new file mode 100644 index 0000000..38f37bd --- /dev/null +++ b/tiny_vm/index.html @@ -0,0 +1,34 @@ +tiny_vm - Rust

Crate tiny_vm

source ·
Expand description

TinyVm example.

+

This example introduces as simple 16 bit virtual machine the TinyVm. The VM consits of +three registers defined in TinyReg, a separate data and insutrction memory and a small +set of instructions TinyInsn, sufficient to implement a guest program to compute the +fiibonacci sequence.

+

The TinyVm implements a simple just-in-time (JIT) compiler to demonstrate the +juicebox_asm crate. Additionally, it implements a reference interpreter.

+ +
fn main() {
+  let mut prog = Vec::new();
+  prog.push(TinyInsn::LoadImm(TinyReg::A, 100));
+  prog.push(TinyInsn::Add(TinyReg::B, TinyReg::A));
+  prog.push(TinyInsn::Addi(TinyReg::C, 100));
+  prog.push(TinyInsn::Halt);
+
+  let mut vm = TinyVm::new(prog);
+  vm.interp();
+
+  assert_eq!(100, vm.read_reg(TinyReg::A));
+  assert_eq!(100, vm.read_reg(TinyReg::B));
+  assert_eq!(100, vm.read_reg(TinyReg::C));
+  assert_eq!(4, vm.icnt);
+  assert_eq!(4, vm.pc);
+
+  vm.pc = 0;
+  vm.jit();
+
+  assert_eq!(100, vm.read_reg(TinyReg::A));
+  assert_eq!(200, vm.read_reg(TinyReg::B));
+  assert_eq!(200, vm.read_reg(TinyReg::C));
+  assert_eq!(8, vm.icnt);
+  assert_eq!(4, vm.pc);
+}
+

Structs

  • A minial fixup utility to implement jump labels when constructing guest programs.
  • A guest physical address.
  • The TinyVm virtual machine state.

Enums

Functions

\ No newline at end of file diff --git a/tiny_vm/sidebar-items.js b/tiny_vm/sidebar-items.js new file mode 100644 index 0000000..dd9930b --- /dev/null +++ b/tiny_vm/sidebar-items.js @@ -0,0 +1 @@ +window.SIDEBAR_ITEMS = {"enum":["TinyInsn","TinyReg"],"fn":["make_tinyvm_fib","make_tinyvm_jit_perf","make_tinyvm_jit_test"],"struct":["Fixup","PhysAddr","TinyVm"]}; \ No newline at end of file diff --git a/tiny_vm/struct.Fixup.html b/tiny_vm/struct.Fixup.html new file mode 100644 index 0000000..0711c0b --- /dev/null +++ b/tiny_vm/struct.Fixup.html @@ -0,0 +1,14 @@ +Fixup in tiny_vm - Rust

Struct tiny_vm::Fixup

source ·
pub struct Fixup { /* private fields */ }
Expand description

A minial fixup utility to implement jump labels when constructing guest programs.

+

Implementations§

source§

impl Fixup

source

pub fn new(pc: usize) -> Self

Create a new Fixup at the current pc.

+
source

pub fn bind(self, prog: &mut Vec<TinyInsn>)

Bind the Fixup to the current location of prog and resolve the Fixup.

+

Auto Trait Implementations§

§

impl RefUnwindSafe for Fixup

§

impl Send for Fixup

§

impl Sync for Fixup

§

impl Unpin for Fixup

§

impl UnwindSafe for Fixup

Blanket Implementations§

source§

impl<T> Any for Twhere + T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere + T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere + T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

+
source§

impl<T, U> Into<U> for Twhere + U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

+

That is, this conversion is whatever the implementation of +From<T> for U chooses to do.

+
source§

impl<T, U> TryFrom<U> for Twhere + U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere + U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
\ No newline at end of file diff --git a/tiny_vm/struct.PhysAddr.html b/tiny_vm/struct.PhysAddr.html new file mode 100644 index 0000000..3e549f7 --- /dev/null +++ b/tiny_vm/struct.PhysAddr.html @@ -0,0 +1,12 @@ +PhysAddr in tiny_vm - Rust

Struct tiny_vm::PhysAddr

source ·
pub struct PhysAddr(pub u16);
Expand description

A guest physical address.

+

Tuple Fields§

§0: u16

Trait Implementations§

source§

impl Into<usize> for PhysAddr

source§

fn into(self) -> usize

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere + T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere + T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere + T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

+
source§

impl<T, U> Into<U> for Twhere + U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

+

That is, this conversion is whatever the implementation of +From<T> for U chooses to do.

+
source§

impl<T, U> TryFrom<U> for Twhere + U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere + U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
\ No newline at end of file diff --git a/tiny_vm/struct.TinyVm.html b/tiny_vm/struct.TinyVm.html new file mode 100644 index 0000000..a7c57cf --- /dev/null +++ b/tiny_vm/struct.TinyVm.html @@ -0,0 +1,21 @@ +TinyVm in tiny_vm - Rust

Struct tiny_vm::TinyVm

source ·
pub struct TinyVm { /* private fields */ }
Expand description

The TinyVm virtual machine state.

+

Implementations§

source§

impl TinyVm

source

pub fn new(code: Vec<TinyInsn>) -> Self

Create a new TinyVm and initialize the instruction memory from code.

+
source

pub fn read_reg(&self, reg: TinyReg) -> u16

Read guest register.

+
source

pub fn write_reg(&mut self, reg: TinyReg, val: u16)

Write guest register.

+
source

pub fn read_mem(&self, paddr: PhysAddr) -> u16

Read guest data memory.

+
source

pub fn write_mem(&mut self, paddr: PhysAddr, val: u16)

Write guest data memory.

+
source

pub fn dump(&self)

Dump the VM state to stdout.

+
source

pub fn interp(&mut self)

Run in interpreter mode until the next TinyInsn::Halt instruction is hit.

+
source

pub fn jit(&mut self)

Run in JIT mode until the next TinyInsn::Halt instruction is hit. Translate guest +basic blocks on demand.

+

Auto Trait Implementations§

§

impl RefUnwindSafe for TinyVm

§

impl !Send for TinyVm

§

impl !Sync for TinyVm

§

impl Unpin for TinyVm

§

impl UnwindSafe for TinyVm

Blanket Implementations§

source§

impl<T> Any for Twhere + T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere + T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere + T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

+
source§

impl<T, U> Into<U> for Twhere + U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

+

That is, this conversion is whatever the implementation of +From<T> for U chooses to do.

+
source§

impl<T, U> TryFrom<U> for Twhere + U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere + U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
\ No newline at end of file -- cgit v1.2.3