use crate::{Symbol, Type};
pub mod impls;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Variable(pub usize);
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Place {
Variable(Variable),
Global(Symbol),
Deref(Box<Place>),
Field(Box<Place>, usize),
}
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub enum Operand {
Place(Place),
IConst(i128, crate::types::IntegerSize),
UConst(u128, crate::types::IntegerSize),
FConst(f64, u16),
}
pub trait BodyCodegen {
fn declare_var(&mut self, ty: Type) -> Variable;
fn arg_var(&self, idx: usize) -> Variable;
fn assign(&mut self, value: Operand, destination: Place);
fn call(&mut self, function: Operand, args: Vec<Operand>, destination: Place);
fn return_(&mut self, value: Operand);
fn acf(&mut self) -> &mut impl ACFCodegen {
Box::leak(Box::new(impls::Unsupported))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Label(pub usize);
pub trait ACFCodegen {
fn label(&mut self, label: Label);
fn jump(&mut self, label: Label);
fn cjump(&mut self, lhs: Operand, rhs: u128, equal: bool, label: Label);
}
pub trait CodegenBackend: Sync {
fn function(&self, name: Symbol) -> impl BodyCodegen;
}