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)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub fn main() -> Result<()> {
    let mut adr = AdressManager::new((0, 0));
    let mut func = Function::new(
        "five",
        &mut adr
    );

    func.ret_int(5);

    unsafe {
        let typed = func.typed::<(), u32>().unwrap();
        let res = typed();

        println!("5 = {}", res);
    };

    Ok(())
}
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)
4
5
6
7
8
9
10
11
12
13
14
pub fn main() -> Result<(), ArtifactError>{
    let mut builder = Builder::new();

    let func = builder.add_function("call");
    func.call("callme");
    func.ret_int(5);

    builder.build("test.o")?;

    Ok(())
}
More examples
Hide additional examples
examples/jit.rs (line 12)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub fn main() -> Result<()> {
    let mut adr = AdressManager::new((0, 0));
    let mut func = Function::new(
        "five",
        &mut adr
    );

    func.ret_int(5);

    unsafe {
        let typed = func.typed::<(), u32>().unwrap();
        let res = typed();

        println!("5 = {}", res);
    };

    Ok(())
}
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)
4
5
6
7
8
9
10
11
12
13
14
pub fn main() -> Result<(), ArtifactError>{
    let mut builder = Builder::new();

    let func = builder.add_function("call");
    func.call("callme");
    func.ret_int(5);

    builder.build("test.o")?;

    Ok(())
}
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> 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,

§

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>,

§

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>,

§

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.