49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use crate::ir::ir_expression::IrExpression;
|
|
use crate::ir::ir_variable::{IrStackVariable, IrVariable, IrVirtualRegisterVariable};
|
|
use crate::type_info::TypeInfo;
|
|
use std::collections::HashSet;
|
|
use std::fmt::{Display, Formatter};
|
|
use std::rc::Rc;
|
|
|
|
pub struct IrCall {
|
|
function_name: Rc<str>,
|
|
arguments: Vec<IrExpression>,
|
|
}
|
|
|
|
impl IrCall {
|
|
pub fn new(function_name: Rc<str>, arguments: Vec<IrExpression>) -> Self {
|
|
Self {
|
|
function_name,
|
|
arguments,
|
|
}
|
|
}
|
|
|
|
pub fn vr_uses(&self) -> HashSet<Rc<IrVirtualRegisterVariable>> {
|
|
let mut set = HashSet::new();
|
|
for argument in &self.arguments {
|
|
set.extend(argument.vr_uses())
|
|
}
|
|
set
|
|
}
|
|
|
|
pub fn propagate_spills(&mut self, spills: &HashSet<Rc<IrVirtualRegisterVariable>>) {
|
|
for argument in &mut self.arguments {
|
|
argument.propagate_spills(spills);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Display for IrCall {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}(", self.function_name)?;
|
|
for (i, argument) in self.arguments.iter().enumerate() {
|
|
write!(f, "{}", argument)?;
|
|
if i < self.arguments.len() - 1 {
|
|
write!(f, ", ")?;
|
|
}
|
|
}
|
|
write!(f, ")")?;
|
|
Ok(())
|
|
}
|
|
}
|