mod.rs 1.35 KB
Newer Older
1
pub mod mm;
qinsoon's avatar
qinsoon committed
2 3
pub mod thread;

4 5
pub use runtime::mm::common::Address;
pub use runtime::mm::common::ObjectReference;
6

7
use utils;
8 9 10 11
use ast::ir::*;
use compiler::backend::Word;
use compiler::backend::RegGroup;

12
#[derive(Clone, Debug)]
13 14 15 16 17 18 19 20 21 22 23 24 25 26
pub enum ValueLocation {
    Register(RegGroup, MuID),
    Direct(RegGroup, Address),
    Indirect(RegGroup, Address),
    Constant(RegGroup, Word),
    
    Relocatable(RegGroup, MuName)
}

impl ValueLocation {
    pub fn load_value(&self) -> (RegGroup, Word) {
        match self {
            &ValueLocation::Register(_, _)
            | &ValueLocation::Direct(_, _)
27 28 29 30 31
            | &ValueLocation::Indirect(_, _) => unimplemented!(),
            
            &ValueLocation::Constant(group, word) => {
                (group, word)
            }
32 33 34
            &ValueLocation::Relocatable(_, _) => panic!("expect a runtime value")
        }
    }
qinsoon's avatar
qinsoon committed
35
    
36
    #[allow(unused_variables)]
qinsoon's avatar
qinsoon committed
37
    pub fn from_constant(c: Constant) -> ValueLocation {
38 39 40 41 42 43 44
        match c {
            Constant::Int(int_val) => ValueLocation::Constant(RegGroup::GPR, utils::mem::u64_to_raw(int_val)),
            Constant::Float(f32_val) => ValueLocation::Constant(RegGroup::FPR, utils::mem::f32_to_raw(f32_val)),
            Constant::Double(f64_val) => ValueLocation::Constant(RegGroup::FPR, utils::mem::f64_to_raw(f64_val)),
            
            _ => unimplemented!()
        }
qinsoon's avatar
qinsoon committed
45
    }
qinsoon's avatar
qinsoon committed
46
}