codegen.rs 2.3 KB
Newer Older
1 2
use ast::ptr::P;
use ast::ir::*;
qinsoon's avatar
qinsoon committed
3
use ast::inst::*;
4

5 6
use vm::machine_code::MachineCode;

7
pub trait CodeGenerator {
8
    fn start_code(&mut self, func_name: MuTag);
9
    fn finish_code(&mut self) -> Box<MachineCode>;
10 11 12 13
    
    fn print_cur_code(&self);
    
    fn start_block(&mut self, block_name: MuTag);
14 15
    fn set_block_livein(&mut self, block_name: MuTag, live_in: &Vec<P<Value>>);
    fn set_block_liveout(&mut self, block_name: MuTag, live_out: &Vec<P<Value>>);
16
    fn end_block(&mut self, block_name: MuTag);
17
    
18
    fn emit_cmp_r64_r64(&mut self, op1: &P<Value>, op2: &P<Value>);
qinsoon's avatar
qinsoon committed
19
    fn emit_cmp_r64_imm32(&mut self, op1: &P<Value>, op2: u32);
20 21
    fn emit_cmp_r64_mem64(&mut self, op1: &P<Value>, op2: &P<Value>);
    
qinsoon's avatar
qinsoon committed
22
    fn emit_mov_r64_imm32(&mut self, dest: &P<Value>, src: u32);
23
    fn emit_mov_r64_mem64(&mut self, dest: &P<Value>, src: &P<Value>);
qinsoon's avatar
qinsoon committed
24
    fn emit_mov_r64_r64(&mut self, dest: &P<Value>, src: &P<Value>);
25
    fn emit_mov_mem64_r64(&mut self, src: &P<Value>, dest: &P<Value>);
qinsoon's avatar
qinsoon committed
26 27 28 29 30 31 32 33 34
    
    fn emit_add_r64_r64(&mut self, dest: &P<Value>, src: &P<Value>);
    fn emit_add_r64_mem64(&mut self, dest: &P<Value>, src: &P<Value>);
    fn emit_add_r64_imm32(&mut self, dest: &P<Value>, src: u32);
    
    fn emit_sub_r64_r64(&mut self, dest: &P<Value>, src: &P<Value>);
    fn emit_sub_r64_mem64(&mut self, dest: &P<Value>, src: &P<Value>);
    fn emit_sub_r64_imm32(&mut self, dest: &P<Value>, src: u32);
    
35 36 37
    fn emit_mul_r64(&mut self, src: &P<Value>);
    fn emit_mul_mem64(&mut self, src: &P<Value>);
    
qinsoon's avatar
qinsoon committed
38 39 40 41 42 43 44
    fn emit_jmp(&mut self, dest: &Destination);
    fn emit_je(&mut self, dest: &Destination);
    fn emit_jne(&mut self, dest: &Destination);
    fn emit_ja(&mut self, dest: &Destination);
    fn emit_jae(&mut self, dest: &Destination);
    fn emit_jb(&mut self, dest: &Destination);
    fn emit_jbe(&mut self, dest: &Destination);
45 46 47 48
    fn emit_jg(&mut self, dest: &Destination);
    fn emit_jge(&mut self, dest: &Destination);
    fn emit_jl(&mut self, dest: &Destination);
    fn emit_jle(&mut self, dest: &Destination);
qinsoon's avatar
qinsoon committed
49
    
50 51 52 53
    fn emit_call_near_rel32(&mut self, func: MuTag);
    fn emit_call_near_r64(&mut self, func: &P<Value>);
    fn emit_call_near_mem64(&mut self, func: &P<Value>);
    
qinsoon's avatar
qinsoon committed
54
    fn emit_ret(&mut self);
55
    
56 57
    fn emit_push_r64(&mut self, src: &P<Value>);
    fn emit_pop_r64(&mut self, dest: &P<Value>);
58
}