summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bernstein <max.bernstein@shopify.com>2025-02-06 10:58:38 -0500
committerTakashi Kokubun <takashikkbn@gmail.com>2025-04-18 21:52:55 +0900
commit41786d355a464d990865084c7a8d5689fd233e9a (patch)
tree99da20baa5968bb2f50de37dc76380525e02a88f
parent50908a7fe2a99357c7b7b0a5f629dc566b28db9f (diff)
Bring back Opnd
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
-rw-r--r--zjit/src/lib.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/zjit/src/lib.rs b/zjit/src/lib.rs
index 8429d2aa05..e40009f89d 100644
--- a/zjit/src/lib.rs
+++ b/zjit/src/lib.rs
@@ -20,10 +20,15 @@ pub struct InsnId(usize);
pub struct BlockId(usize);
#[derive(Debug, PartialEq)]
+enum Opnd {
+ Const(VALUE),
+ Insn(InsnId),
+}
+
+#[derive(Debug, PartialEq)]
enum Insn {
Param { idx: usize },
- Const { val: VALUE },
- Return { val: InsnId },
+ Return { val: Opnd },
}
#[derive(Debug, PartialEq)]
@@ -65,7 +70,7 @@ enum RubyOpcode {
}
struct FrameState {
- stack: Vec<InsnId>,
+ stack: Vec<Opnd>,
}
impl FrameState {
@@ -73,11 +78,11 @@ impl FrameState {
FrameState { stack: vec![] }
}
- fn push(&mut self, val: InsnId) {
- self.stack.push(val);
+ fn push(&mut self, opnd: Opnd) {
+ self.stack.push(opnd);
}
- fn pop(&mut self) -> InsnId {
+ fn pop(&mut self) -> Opnd {
self.stack.pop().expect("Bytecode stack mismatch")
}
}
@@ -89,7 +94,7 @@ fn to_ssa(opcodes: &Vec<RubyOpcode>) -> Function {
for opcode in opcodes {
match opcode {
RubyOpcode::Putnil => {
- state.push(result.push_insn(block, Insn::Const { val: Qnil }));
+ state.push(Opnd::Const(Qnil));
},
RubyOpcode::Leave => {
result.push_insn(block, Insn::Return { val: state.pop() });
@@ -113,10 +118,10 @@ mod tests {
assert_eq!(function, Function {
entry_block: BlockId(0),
insns: vec![
- Insn::Const { val: RubyValue::Nil },
- Insn::Return { val: InsnId(0) }],
+ Insn::Return { val: Opnd::Const(Qnil) }
+ ],
blocks: vec![
- Block { params: vec![], insns: vec![InsnId(0), InsnId(1)] }
+ Block { params: vec![], insns: vec![InsnId(0)] }
],
});
}