deimos-lang/dmc-lib/src/ir/ir_get_field_ref_mut.rs
2026-03-13 09:16:41 -05:00

65 lines
1.7 KiB
Rust

use crate::ir::ir_variable::{IrVariable, IrVariableDescriptor, IrVrVariableDescriptor};
use crate::ir::register_allocation::{OffsetCounter, VrUser};
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::fmt::{Display, Formatter};
use std::rc::Rc;
pub struct IrGetFieldRefMut {
self_variable: Rc<RefCell<IrVariable>>,
field_index: usize,
}
impl IrGetFieldRefMut {
pub fn new(self_variable: Rc<RefCell<IrVariable>>, field_index: usize) -> Self {
Self {
self_variable,
field_index,
}
}
pub fn self_variable(&self) -> &Rc<RefCell<IrVariable>> {
&self.self_variable
}
pub fn field_index(&self) -> usize {
self.field_index
}
}
impl Display for IrGetFieldRefMut {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"&mut {}.{}",
self.self_variable.borrow(),
self.field_index()
)
}
}
impl VrUser for IrGetFieldRefMut {
fn vr_definitions(&self) -> HashSet<IrVrVariableDescriptor> {
HashSet::new()
}
fn vr_uses(&self) -> HashSet<IrVrVariableDescriptor> {
match self.self_variable.borrow().descriptor() {
IrVariableDescriptor::VirtualRegister(vr_variable) => {
HashSet::from([vr_variable.clone()])
}
IrVariableDescriptor::Stack(stack_variable) => HashSet::new(),
}
}
fn propagate_spills(&mut self, spills: &HashSet<IrVrVariableDescriptor>) {}
fn propagate_register_assignments(
&mut self,
assignments: &HashMap<IrVrVariableDescriptor, usize>,
) {
}
fn propagate_stack_offsets(&mut self, counter: &mut OffsetCounter) {}
}