machine_code.rs 1.3 KB
Newer Older
1
use ast::ir::*;
qinsoon's avatar
qinsoon committed
2
use compiler::frame::*;
3
use std::ops;
4
use std::collections::HashMap;
5 6

pub struct CompiledFunction {
qinsoon's avatar
qinsoon committed
7
    pub func_id: MuID,
qinsoon's avatar
qinsoon committed
8
    pub func_ver_id: MuID,
9
    pub temps: HashMap<MuID, MuID>, // assumes one temperary maps to one register
qinsoon's avatar
qinsoon committed
10 11 12
    pub mc: Box<MachineCode>,
    
    pub frame: Frame
13 14 15
}

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