44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use crate::ir::ir_expression::IrExpression;
|
|
use crate::ir::ir_variable::IrVariableId;
|
|
use crate::ir::register_allocation::VrUser;
|
|
use std::collections::HashSet;
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
#[derive(Debug)]
|
|
pub struct IrSetField {
|
|
field_ref_variable: IrVariableId,
|
|
initializer: Box<IrExpression>,
|
|
}
|
|
|
|
impl IrSetField {
|
|
pub fn new(field_ref_variable: IrVariableId, initializer: IrExpression) -> Self {
|
|
Self {
|
|
field_ref_variable,
|
|
initializer: initializer.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl VrUser for IrSetField {
|
|
fn vr_uses(&self) -> HashSet<IrVariableId> {
|
|
let mut set = HashSet::new();
|
|
set.insert(self.field_ref_variable);
|
|
set.extend(self.initializer.vr_uses());
|
|
set
|
|
}
|
|
}
|
|
|
|
// impl Assemble for IrSetField {
|
|
// fn assemble(&self, builder: &mut InstructionsBuilder, constants_table: &mut ConstantsTable) {
|
|
// let field_ref_location = self.field_ref_variable.borrow().descriptor().as_location();
|
|
// let set_field_operand = self.initializer.set_field_operand(constants_table);
|
|
// builder.push(Instruction::SetField(field_ref_location, set_field_operand));
|
|
// }
|
|
// }
|
|
|
|
impl Display for IrSetField {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "*{} = {}", self.field_ref_variable, self.initializer)
|
|
}
|
|
}
|