diff options
| author | Max Bernstein <max.bernstein@shopify.com> | 2025-02-07 09:36:02 -0500 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-04-18 21:52:57 +0900 |
| commit | ea98a5ae39087edd18a1225f3fe4614dfefe4fe6 (patch) | |
| tree | 6b823c27613aac9c13325a6d6d58f1c1aafff196 | |
| parent | 6a7578632295a3d6ad271c96b73e66c66b7f428b (diff) | |
Display FrameState
Also make pc a VALUE instead of ptr to VALUE
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13131
| -rw-r--r-- | zjit/src/ir.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/zjit/src/ir.rs b/zjit/src/ir.rs index cfdbcfd15e..6b8a4124d0 100644 --- a/zjit/src/ir.rs +++ b/zjit/src/ir.rs @@ -29,6 +29,16 @@ pub enum Opnd { Insn(InsnId), } +fn write_vec<T: std::fmt::Display>(f: &mut std::fmt::Formatter, objs: &Vec<T>) -> std::fmt::Result { + write!(f, "[")?; + let mut prefix = ""; + for obj in objs { + write!(f, "{prefix}{obj}")?; + prefix = ", "; + } + write!(f, "]") +} + impl std::fmt::Display for Opnd { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { @@ -186,6 +196,7 @@ impl<'a> std::fmt::Display for FunctionPrinter<'a> { } } Insn::Test { val } => { write!(f, "Test {val}")?; } + Insn::Snapshot { state } => { write!(f, "Snapshot {state}")?; } insn => { write!(f, "{insn:?}")?; } } writeln!(f, "")?; @@ -198,7 +209,7 @@ impl<'a> std::fmt::Display for FunctionPrinter<'a> { #[derive(Debug, Clone)] pub struct FrameState { // Ruby bytecode instruction pointer - pc: *mut VALUE, + pc: VALUE, stack: Vec<Opnd>, locals: Vec<Opnd>, @@ -206,7 +217,7 @@ pub struct FrameState { impl FrameState { fn new() -> FrameState { - FrameState { pc: 0 as *mut VALUE, stack: vec![], locals: vec![] } + FrameState { pc: VALUE(0), stack: vec![], locals: vec![] } } fn push(&mut self, opnd: Opnd) { @@ -236,6 +247,16 @@ impl FrameState { } } +impl std::fmt::Display for FrameState { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "FrameState {{ pc: {:?}, stack: ", self.pc.as_ptr::<u8>())?; + write_vec(f, &self.stack)?; + write!(f, ", locals: ")?; + write_vec(f, &self.locals)?; + write!(f, " }}") + } +} + /// Get instruction argument fn get_arg(pc: *const VALUE, arg_idx: isize) -> VALUE { unsafe { *(pc.offset(arg_idx + 1)) } @@ -271,6 +292,8 @@ fn compute_jump_targets(iseq: *const rb_iseq_t) -> Vec<u32> { pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function { let mut fun = Function::new(iseq); + // TODO(max): Queue TranslationContexts so that we can assign states to basic blocks instead of + // flowing one state through the linear iseq let mut state = FrameState::new(); let mut block = fun.entry_block; @@ -295,7 +318,7 @@ pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function { // Get the current pc and opcode let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx.into()) }; - state.pc = pc; + state.pc = unsafe { *pc }; fun.push_insn(block, Insn::Snapshot { state: state.clone() }); |
