machine_code.rs 1.1 KB
Newer Older
1
use ast::ir::*;
2
use std::ops;
3
use std::collections::HashMap;
4 5 6

pub struct CompiledFunction {
    pub fn_name: MuTag,
7
    pub temps: HashMap<MuID, MuID>, // assumes one temperary maps to one register
8 9 10 11
    pub mc: Box<MachineCode>
}

pub trait MachineCode {
12 13 14
    fn trace_mc(&self);
    fn trace_inst(&self, index: usize);
    
15
    fn emit(&self) -> Vec<u8>;
16 17
    
    fn number_of_insts(&self) -> usize;
qinsoon's avatar
qinsoon committed
18
    
19
    fn is_move(&self, index: usize) -> bool;
qinsoon's avatar
qinsoon committed
20 21
    fn is_using_mem_op(&self, index: usize) -> bool;
    
qinsoon's avatar
qinsoon committed
22 23
    fn get_succs(&self, index: usize) -> &Vec<usize>;
    fn get_preds(&self, index: usize) -> &Vec<usize>;
24 25 26
    
    fn get_inst_reg_uses(&self, index: usize) -> &Vec<MuID>;
    fn get_inst_reg_defines(&self, index: usize) -> &Vec<MuID>;
27
    
28 29 30 31 32
    fn get_ir_block_livein(&self, block: MuTag) -> Option<&Vec<MuID>>;
    fn get_ir_block_liveout(&self, block: MuTag) -> Option<&Vec<MuID>>;
    
    fn get_all_blocks(&self) -> &Vec<MuTag>;
    fn get_block_range(&self, block: MuTag) -> Option<ops::Range<usize>>;
33 34 35
    
    fn replace_reg(&mut self, from: MuID, to: MuID);
    fn set_inst_nop(&mut self, index: usize);
36
}