From 9644b17279bb39eac6d6951d04341eb7324720ea Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Fri, 14 Feb 2025 14:26:37 -0500 Subject: [PATCH] Add minor comments --- zjit/src/hir.rs | 13 ++++++++++--- zjit/src/lib.rs | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index 7e552872c0..ea50332c6d 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -1,7 +1,11 @@ // We use the YARV bytecode constants which have a CRuby-style name #![allow(non_upper_case_globals)] -use crate::{cruby::*, get_option, options::DumpSSA}; +use crate::{ + cruby::*, + get_option, + options::DumpSSA +}; use std::collections::{HashMap, HashSet}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] @@ -85,6 +89,7 @@ pub enum Insn { NewArray { count: usize }, ArraySet { idx: usize, val: Opnd }, ArrayDup { val: Opnd }, + // Check if the value is truthy and "return" a C boolean. In reality, we will likely fuse this // with IfTrue/IfFalse in the backend to generate jcc. Test { val: Opnd }, @@ -108,7 +113,8 @@ pub enum Insn { IfFalse { val: Opnd, target: BranchEdge }, // Call a C function - // TODO: should we store the C function name? + // NOTE: should we store the C function name for pretty-printing? + // or can we backtranslate the function pointer into a name string? CCall { cfun: *const u8, args: Vec }, // Send with dynamic dispatch @@ -277,11 +283,12 @@ impl std::fmt::Display for FrameState { } } -/// Get instruction argument +/// Get YARV instruction argument fn get_arg(pc: *const VALUE, arg_idx: isize) -> VALUE { unsafe { *(pc.offset(arg_idx + 1)) } } +/// Compute YARV instruction index at relative offset fn insn_idx_at_offset(idx: u32, offset: i64) -> u32 { ((idx as isize) + (offset as isize)) as u32 } diff --git a/zjit/src/lib.rs b/zjit/src/lib.rs index c86728d80e..6782cc584d 100644 --- a/zjit/src/lib.rs +++ b/zjit/src/lib.rs @@ -95,6 +95,8 @@ pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *co let cb = ZJITState::get_code_block(); match gen_function(cb, &ssa) { Some(start_ptr) => start_ptr.raw_ptr(cb), + + // Compilation failed, continue executing in the interpreter only None => std::ptr::null(), } }