fn compile(mut self) -> CompiledBlock {
        self.emit_prolog();

        // Copy out `mem` because borrowck complains. Luckily, the memory is quite small, but I
        // wonder if there isn't a better solution (that doesn't involve calling `borrow_mut` every
        // like 3 cycles).
        let mem = self.state_rc.borrow_mut().mem;
        loop {
            let instr = (&mem[self.pc as usize..]).read_u16::<BigEndian>().unwrap();
            self.pc += 2;
            if self.compile_instr(instr) {
                break;
            }
        }

        self.finalize_function();

        debug!("jit completed, code dump: {}", utils::hexdump(&self.code_buffer));

        // Copy the code buffer into a memory region and make it executable:
        let mut mmap = Mmap::anonymous(self.code_buffer.len(), Protection::ReadWrite).unwrap();
        unsafe {
            mmap.as_mut_slice().copy_from_slice(&self.code_buffer);
        }

        mmap.set_protection(Protection::ReadExecute).unwrap();
        debug!("code is at {:p}", mmap.ptr());

        CompiledBlock {
            state: self.state_rc,
            memory: mmap,
            start: self.start_pc,
            len: self.pc - self.start_pc,
        }
    }
/// Compiles the basic block starting at the current program counter.
Compiles the basic block starting at the current program counter.
Compiles the basic block starting at the current program counter .
fn compile(mut self) -> CompiledBlock {
        self.emit_prolog();
        // Copy out `mem` because borrowck complains. Luckily, the memory is quite small, but I
        // wonder if there isn't a better solution (that doesn't involve calling `borrow_mut` every
        // like 3 cycles).
        let mem = self.state_rc.borrow_mut().mem;
        loop {
            let instr = (&mem[self.pc as usize..]).read_u16::<BigEndian>().unwrap();
            self.pc += 2;
            if self.compile_instr(instr) {
                break;
            }
        }
        self.finalize_function();
        debug!("jit completed, code dump: {}", utils::hexdump(&self.code_buffer));
        // Copy the code buffer into a memory region and make it executable:
        let mut mmap = Mmap::anonymous(self.code_buffer.len(), Protection::ReadWrite).unwrap();
        unsafe {
            mmap.as_mut_slice().copy_from_slice(&self.code_buffer);
        }
        mmap.set_protection(Protection::ReadExecute).unwrap();
        debug!("code is at {:p}", mmap.ptr());
        CompiledBlock {
            state: self.state_rc,
            memory: mmap,
            start: self.start_pc,
            len: self.pc - self.start_pc,
        }
    }
fn compile ( mut self ) -> CompiledBlock { self . emit_prolog ( ) ; // Copy out `mem` because borrowck complains. Luckily, the memory is quite small, but I // wonder if there isn't a better solution (that doesn't involve calling `borrow_mut` every // like 3 cycles). let mem = self . state_rc . borrow_mut ( ) . mem ; loop { let instr = ( & mem [ self . pc as usize .. ] ) . read_u16 :: < BigEndian > ( ) . unwrap ( ) ; self . pc += 2 ; if self . compile_instr ( instr ) { break ; } } self . finalize_function ( ) ; debug ! ( " " utils hexdump ( self code_buffer ) ) ; // Copy the code buffer into a memory region and make it executable: let mut mmap = Mmap :: anonymous ( self . code_buffer . len ( ) , Protection :: ReadWrite ) . unwrap ( ) ; unsafe { mmap . as_mut_slice ( ) . copy_from_slice ( & self . code_buffer ) ; } mmap . set_protection ( Protection :: ReadExecute ) . unwrap ( ) ; debug ! ( " " mmap ptr ( ) ) ; CompiledBlock { state : self . state_rc , memory : mmap , start : self . start_pc , len : self . pc - self . start_pc , } }
Compiles the basic block starting at the current program counter.
Compiles the basic block starting at the current program counter .
mut self
mut self