bundle.rs 3.03 KB
Newer Older
qinsoon's avatar
qinsoon committed
1 2 3
use ast::ir::*;
use ast::ptr::*;
use ast::types::*;
qinsoon's avatar
qinsoon committed
4
use vm::api::*;
qinsoon's avatar
qinsoon committed
5 6 7 8

use std::collections::HashMap;

pub struct MuBundle {
qinsoon's avatar
qinsoon committed
9 10
    pub id: MuID,
    
qinsoon's avatar
qinsoon committed
11 12 13
    pub type_defs: HashMap<MuID, P<MuType>>,
    pub func_sigs: HashMap<MuID, P<MuFuncSig>>,
    pub constants: HashMap<MuID, P<Value>>,
qinsoon's avatar
qinsoon committed
14
    pub globals  : HashMap<MuID, P<Value>>,
qinsoon's avatar
qinsoon committed
15 16 17 18 19 20 21 22
    pub func_defs: HashMap<MuID, MuFunction>,
    pub func_decls: HashMap<MuID, MuFunctionVersion>,
    
//    id_name_map: HashMap<MuID, MuName>,
//    name_id_map: HashMap<MuName, MuID>
}

impl MuBundle {
qinsoon's avatar
qinsoon committed
23
    pub fn new(id: MuID) -> MuBundle {
qinsoon's avatar
qinsoon committed
24
        MuBundle {
qinsoon's avatar
qinsoon committed
25 26
            id: id,
            
qinsoon's avatar
qinsoon committed
27 28 29 30 31 32 33 34 35 36 37 38 39
            type_defs: HashMap::new(),
            func_sigs: HashMap::new(),
            constants: HashMap::new(),
            globals: HashMap::new(),
            func_defs: HashMap::new(),
            func_decls: HashMap::new(),
            
//            id_name_map: HashMap::new(),
//            name_id_map: HashMap::new()
        }
    }
}

qinsoon's avatar
qinsoon committed
40 41
#[derive(Copy, Clone, Debug)]
pub struct MuValue {
qinsoon's avatar
qinsoon committed
42
    pub id: MuID,
qinsoon's avatar
qinsoon committed
43 44
    pub v: MuValueKind
} 
qinsoon's avatar
qinsoon committed
45

qinsoon's avatar
qinsoon committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#[derive(Copy, Clone, Debug)]
pub enum MuValueKind {
    Int,
    Float,
    Double,
    UPtr,
    UFP,
    
    // SeqValue
    Struct,
    Array,
    Vector,
    
    // GenRef
    Ref,
    IRef,
    TagRef64,
    FuncRef,
    ThreadRef,
    StackRef,
    FCRef, // frame cursor ref        
    
    // GenRef->IR
    Bundle,
    
    // GenRef->IR->Child
qinsoon's avatar
qinsoon committed
72 73 74 75
    Type,
    FuncSig,
    FuncVer,
    BB,
qinsoon's avatar
qinsoon committed
76 77 78
    Inst,
    
    // GenRef->IR->Child->Var->Global
qinsoon's avatar
qinsoon committed
79 80 81
    Const,
    Global,
    Func,
qinsoon's avatar
qinsoon committed
82 83 84
    ExpFunc,
    
    // GenRef->IR->Child->Var->Local
qinsoon's avatar
qinsoon committed
85 86
    NorParam,
    ExcParam,
qinsoon's avatar
qinsoon committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    InstRes,    
}

macro_rules! handle_constructor {
    ($fn_name: ident, $kind: ident) => {
        pub fn $fn_name(id: MuID) -> MuValue {
            MuValue{
                id: id, v: MuValueKind::$kind
            }
        }
    }
}

handle_constructor!(handle_int, Int);
handle_constructor!(handle_float, Float);
handle_constructor!(handle_double, Double);
handle_constructor!(handle_uptr, UPtr);
handle_constructor!(handle_ufp, UFP);

handle_constructor!(handle_struct, Struct);
handle_constructor!(handle_array, Array);
handle_constructor!(handle_vector, Vector);

handle_constructor!(handle_ref, Ref);
handle_constructor!(handle_iref, IRef);
handle_constructor!(handle_tagref64, TagRef64);
handle_constructor!(handle_funcref, FuncRef);
handle_constructor!(handle_threadref, ThreadRef);
handle_constructor!(handle_stackref, StackRef);
handle_constructor!(handle_fcref, FCRef);

handle_constructor!(handle_bundle, Bundle);

handle_constructor!(handle_type, Type);
handle_constructor!(handle_funcsig, FuncSig);
handle_constructor!(handle_funcver, FuncVer);
handle_constructor!(handle_bb, BB);
handle_constructor!(handle_inst, Inst);

handle_constructor!(handle_const, Const);
handle_constructor!(handle_global, Global);
handle_constructor!(handle_func, Func);
handle_constructor!(handle_expfunc, ExpFunc);

handle_constructor!(handle_norparam, NorParam);
handle_constructor!(handle_excparam, ExcParam);
handle_constructor!(handle_instres, InstRes);