Struct Function

Source
pub struct Function {
    pub name: String,
    pub gen: Vec<Vec<u8>>,
    pub esymbols: Vec<ExternSymbol>,
    pub vars: Vec<Variabel>,
    /* private fields */
}
Expand description

The Function class is a handler for the code generation of one function

Fields§

§name: String§gen: Vec<Vec<u8>>§esymbols: Vec<ExternSymbol>§vars: Vec<Variabel>

Implementations§

Source§

impl Function

Source

pub fn new(name: &str, adrmng: &mut AdressManager) -> Function

Examples found in repository?
examples/jit.rs (lines 7-10)
5pub fn main() -> Result<()> {
6    let mut adr = AdressManager::new((0, 0));
7    let mut func = Function::new(
8        "five",
9        &mut adr
10    );
11
12    func.ret_int(5);
13
14    unsafe {
15        let typed = func.typed::<(), u32>().unwrap();
16        let res = typed();
17
18        println!("5 = {}", res);
19    };
20
21    Ok(())
22}
Source

pub fn asm_ret(&mut self) -> &mut Self

Adds a return

Source

pub fn asm_mov(&mut self, reg: REGISTER, value: u64) -> &mut Self

Adds a assembly mov command

Source

pub fn asm_mov_reg(&mut self, from: REGISTER, to: REGISTER) -> &mut Self

Adds a assembly mov from register to register command

Source

pub fn asm_adc(&mut self, reg: REGISTER, value: u64) -> &mut Self

Adds a assembly adc command

Source

pub fn asm_adc_reg(&mut self, dest: REGISTER, src: REGISTER) -> &mut Self

Adds a assembly adc command which adds the registers together

Source

pub fn ret_int(&mut self, value: u64) -> &mut Self

Returns an intenger

Examples found in repository?
examples/simple.rs (line 9)
4pub fn main() -> Result<(), ArtifactError>{
5    let mut builder = Builder::new();
6
7    let func = builder.add_function("call");
8    func.call("callme");
9    func.ret_int(5);
10
11    builder.build("test.o")?;
12
13    Ok(())
14}
More examples
Hide additional examples
examples/jit.rs (line 12)
5pub fn main() -> Result<()> {
6    let mut adr = AdressManager::new((0, 0));
7    let mut func = Function::new(
8        "five",
9        &mut adr
10    );
11
12    func.ret_int(5);
13
14    unsafe {
15        let typed = func.typed::<(), u32>().unwrap();
16        let res = typed();
17
18        println!("5 = {}", res);
19    };
20
21    Ok(())
22}
Source

pub fn asm_call(&mut self, adr: u32) -> &mut Self

Adds an call to the adress

Source

pub fn call(&mut self, dest: &str) -> &mut Self

Calls a function with the name of dest

Examples found in repository?
examples/simple.rs (line 8)
4pub fn main() -> Result<(), ArtifactError>{
5    let mut builder = Builder::new();
6
7    let func = builder.add_function("call");
8    func.call("callme");
9    func.ret_int(5);
10
11    builder.build("test.o")?;
12
13    Ok(())
14}
Source

pub fn create_var(&mut self, name: &str, typ: VarDataType) -> Variabel

Adds a variable to the function

Source

pub fn get_gen(&mut self) -> Vec<u8>

Returns the generated code of the function

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

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 JitRuntime for Function

Source§

unsafe fn typed<Params, Ret>(&mut self) -> Result<extern "C" fn() -> Ret>

Tr

Source§

impl Optimize for Function

Source§

fn optimize(&mut self)

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.