Struct CodeGenLib::x86::function::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
impl Function
sourcepub fn new(name: &str, adrmng: &mut AdressManager) -> Function
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(())
}
sourcepub fn asm_mov_reg(&mut self, from: REGISTER, to: REGISTER) -> &mut Self
pub fn asm_mov_reg(&mut self, from: REGISTER, to: REGISTER) -> &mut Self
Adds a assembly mov from register to register command
sourcepub fn asm_adc_reg(&mut self, dest: REGISTER, src: REGISTER) -> &mut Self
pub fn asm_adc_reg(&mut self, dest: REGISTER, src: REGISTER) -> &mut Self
Adds a assembly adc command which adds the registers together
sourcepub fn ret_int(&mut self, value: u64) -> &mut Self
pub fn ret_int(&mut self, value: u64) -> &mut Self
Returns an intenger
Examples found in repository?
More 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(())
}
sourcepub fn create_var(&mut self, name: &str, typ: VarDataType) -> Variabel
pub fn create_var(&mut self, name: &str, typ: VarDataType) -> Variabel
Adds a variable to the function
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more