luaur-code-gen 0.1.3

Native (A64/X64) code generation for Luau (Rust).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::records::ir_block::IrBlock;
use crate::records::ir_function::IrFunction;

impl IrFunction {
    pub fn get_block_index(&self, block: &IrBlock) -> u32 {
        // Can only be called with blocks from our vector
        let block_ptr = block as *const IrBlock as usize;
        let base_ptr = self.blocks.as_ptr() as usize;
        let end_ptr = unsafe { self.blocks.as_ptr().add(self.blocks.len()) } as usize;

        if !(block_ptr >= base_ptr && block_ptr <= end_ptr) {
            panic!("IrFunction::get_block_index: block not from this function");
        }

        let offset = block_ptr - base_ptr;
        (offset / core::mem::size_of::<IrBlock>()) as u32
    }
}