codegen.rs 2.5 KB
Newer Older
1 2 3
use ast::ptr::P;
use ast::ir::*;

qinsoon's avatar
qinsoon committed
4
use vm::MachineCode;
5

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