39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use crate::ir::ir_parameter::IrParameter;
|
|
use crate::ir::ir_variable::IrVariable;
|
|
use dvm_lib::instruction::Location;
|
|
use std::cell::RefCell;
|
|
use std::fmt::{Display, Formatter};
|
|
use std::rc::Rc;
|
|
|
|
#[derive(Clone)]
|
|
pub enum IrParameterOrVariable {
|
|
IrParameter(Rc<IrParameter>),
|
|
Variable(Rc<RefCell<IrVariable>>),
|
|
}
|
|
|
|
impl IrParameterOrVariable {
|
|
pub fn as_location(&self) -> Location {
|
|
match self {
|
|
IrParameterOrVariable::IrParameter(ir_parameter) => {
|
|
Location::StackFrameOffset(ir_parameter.stack_offset())
|
|
}
|
|
IrParameterOrVariable::Variable(ir_variable) => {
|
|
ir_variable.borrow().descriptor().as_location()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Display for IrParameterOrVariable {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
IrParameterOrVariable::IrParameter(ir_parameter) => {
|
|
write!(f, "{}", ir_parameter)
|
|
}
|
|
IrParameterOrVariable::Variable(ir_variable) => {
|
|
write!(f, "{}", ir_variable.borrow())
|
|
}
|
|
}
|
|
}
|
|
}
|