Blame view

src/Rust/backend.rs 1.13 KB
Ulrich Schoepp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
use std::fmt::{Debug, Display};
use ident::{Ident, Label};
use tree;

pub trait MachineInstr {
    type UseIterator: Iterator<Item = Ident>;
    type DefIterator: Iterator<Item = Ident>;
    type TargetIterator: Iterator<Item = Label>;

    fn uses(&self) -> Self::UseIterator;

    fn defs(&self) -> Self::DefIterator;

    fn is_fall_through(&self) -> bool;

    fn jumps(&self) -> Self::TargetIterator;

    fn is_move_between_temps(&self) -> Option<(Ident, Ident)>;

    fn is_label(&self) -> Option<Label>;

    fn rename(&mut self, sigma: &Fn(Ident) -> Ident);
}

pub trait MachineFunction<A: MachineInstr>: Debug {
    fn name(&self) -> &Label;
    fn body(&self) -> &Vec<A>;
    fn spill(&mut self, to_spill: &Vec<Ident>);
    fn rename(&mut self, sigma: &Fn(Ident) -> Ident);
}

pub trait MachinePrg<A: MachineInstr, F: MachineFunction<A>>: Debug + Display {
    fn functions(&self) -> &Vec<F>;
    fn functions_mut(&mut self) -> &mut Vec<F>;
}

pub trait CodeGen<A: MachineInstr, F: MachineFunction<A>, P: MachinePrg<A, F>> {
    fn all_registers() -> Vec<Ident>;
    fn general_purpose_registers() -> Vec<Ident>;
    fn code_gen(c: tree::Prg) -> P;
}