GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit 1168f297 authored by qinsoon's avatar qinsoon

[wip] get handle from global, and create handle from int

parent 55aa2fe5
use ir::*;
use ptr::*;
use types::*;
use utils::Address;
use std::collections::HashMap;
......@@ -36,120 +35,3 @@ impl MuBundle {
}
}
}
\ No newline at end of file
#[derive(Copy, Clone, Debug)]
pub struct APIHandleKey {
pub id: MuID,
pub v: APIHandleKeyKind
}
#[derive(Copy, Clone, Debug)]
pub enum APIHandleKeyKind {
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
Type,
FuncSig,
FuncVer,
BB,
Inst,
// GenRef->IR->Child->Var->Global
Const,
Global,
Func,
ExpFunc,
// GenRef->IR->Child->Var->Local
NorParam,
ExcParam,
InstRes,
}
macro_rules! handle_constructor {
($fn_name: ident, $kind: ident) => {
pub fn $fn_name(id: MuID) -> APIHandleKey {
APIHandleKey{
id: id, v: APIHandleKeyKind::$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);
#[derive(Clone)]
pub enum APIHandleValue {
Int(u64),
Float(f32),
Double(f64),
UPtr(Address),
UFP(Address),
Struct(Vec<APIHandleValue>),
Array(Vec<APIHandleValue>),
Vector(Vec<APIHandleValue>),
Ref(Address),
IRef(Address),
TagRef64(u64),
FuncRef(MuID),
ThreadRef,
StackRef,
FCRef,
IBRef
}
\ No newline at end of file
extern crate byteorder;
extern crate rustc_serialize;
pub type BitSize = usize;
pub type ByteOffset = isize;
pub type ByteSize = usize;
pub type Word = usize;
......
......@@ -19,7 +19,7 @@ mod deps {
pub type MuName = String;
pub type CName = MuName;
pub struct APIHandleKey {
pub struct APIHandle {
// stub
}
......
......@@ -77,195 +77,195 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn handle_from_sint8(&mut self, num: i8, len: c_int) -> *const APIHandleKey {
pub fn handle_from_sint8(&mut self, num: i8, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_uint8(&mut self, num: u8, len: c_int) -> *const APIHandleKey {
pub fn handle_from_uint8(&mut self, num: u8, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_sint16(&mut self, num: i16, len: c_int) -> *const APIHandleKey {
pub fn handle_from_sint16(&mut self, num: i16, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_uint16(&mut self, num: u16, len: c_int) -> *const APIHandleKey {
pub fn handle_from_uint16(&mut self, num: u16, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_sint32(&mut self, num: i32, len: c_int) -> *const APIHandleKey {
pub fn handle_from_sint32(&mut self, num: i32, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_uint32(&mut self, num: u32, len: c_int) -> *const APIHandleKey {
pub fn handle_from_uint32(&mut self, num: u32, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_sint64(&mut self, num: i64, len: c_int) -> *const APIHandleKey {
pub fn handle_from_sint64(&mut self, num: i64, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_uint64(&mut self, num: u64, len: c_int) -> *const APIHandleKey {
pub fn handle_from_uint64(&mut self, num: u64, len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_uint64s(&mut self, nums: &[u64], len: c_int) -> *const APIHandleKey {
pub fn handle_from_uint64s(&mut self, nums: &[u64], len: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_float(&mut self, num: f32) -> *const APIHandleKey {
pub fn handle_from_float(&mut self, num: f32) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_double(&mut self, num: f64) -> *const APIHandleKey {
pub fn handle_from_double(&mut self, num: f64) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_ptr(&mut self, mu_type: MuID, ptr: CMuCPtr) -> *const APIHandleKey {
pub fn handle_from_ptr(&mut self, mu_type: MuID, ptr: CMuCPtr) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_fp(&mut self, mu_type: MuID, fp: CMuCFP) -> *const APIHandleKey {
pub fn handle_from_fp(&mut self, mu_type: MuID, fp: CMuCFP) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_to_sint8(&mut self, opnd: &APIHandleKey) -> i8 {
pub fn handle_to_sint8(&mut self, opnd: &APIHandle) -> i8 {
panic!("Not implemented")
}
pub fn handle_to_uint8(&mut self, opnd: &APIHandleKey) -> u8 {
pub fn handle_to_uint8(&mut self, opnd: &APIHandle) -> u8 {
panic!("Not implemented")
}
pub fn handle_to_sint16(&mut self, opnd: &APIHandleKey) -> i16 {
pub fn handle_to_sint16(&mut self, opnd: &APIHandle) -> i16 {
panic!("Not implemented")
}
pub fn handle_to_uint16(&mut self, opnd: &APIHandleKey) -> u16 {
pub fn handle_to_uint16(&mut self, opnd: &APIHandle) -> u16 {
panic!("Not implemented")
}
pub fn handle_to_sint32(&mut self, opnd: &APIHandleKey) -> i32 {
pub fn handle_to_sint32(&mut self, opnd: &APIHandle) -> i32 {
panic!("Not implemented")
}
pub fn handle_to_uint32(&mut self, opnd: &APIHandleKey) -> u32 {
pub fn handle_to_uint32(&mut self, opnd: &APIHandle) -> u32 {
panic!("Not implemented")
}
pub fn handle_to_sint64(&mut self, opnd: &APIHandleKey) -> i64 {
pub fn handle_to_sint64(&mut self, opnd: &APIHandle) -> i64 {
panic!("Not implemented")
}
pub fn handle_to_uint64(&mut self, opnd: &APIHandleKey) -> u64 {
pub fn handle_to_uint64(&mut self, opnd: &APIHandle) -> u64 {
panic!("Not implemented")
}
pub fn handle_to_float(&mut self, opnd: &APIHandleKey) -> f32 {
pub fn handle_to_float(&mut self, opnd: &APIHandle) -> f32 {
panic!("Not implemented")
}
pub fn handle_to_double(&mut self, opnd: &APIHandleKey) -> f64 {
pub fn handle_to_double(&mut self, opnd: &APIHandle) -> f64 {
panic!("Not implemented")
}
pub fn handle_to_ptr(&mut self, opnd: &APIHandleKey) -> CMuCPtr {
pub fn handle_to_ptr(&mut self, opnd: &APIHandle) -> CMuCPtr {
panic!("Not implemented")
}
pub fn handle_to_fp(&mut self, opnd: &APIHandleKey) -> CMuCFP {
pub fn handle_to_fp(&mut self, opnd: &APIHandle) -> CMuCFP {
panic!("Not implemented")
}
pub fn handle_from_const(&mut self, id: MuID) -> *const APIHandleKey {
pub fn handle_from_const(&mut self, id: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_global(&mut self, id: MuID) -> *const APIHandleKey {
pub fn handle_from_global(&mut self, id: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_func(&mut self, id: MuID) -> *const APIHandleKey {
pub fn handle_from_func(&mut self, id: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn handle_from_expose(&mut self, id: MuID) -> *const APIHandleKey {
pub fn handle_from_expose(&mut self, id: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn delete_value(&mut self, opnd: &APIHandleKey) {
pub fn delete_value(&mut self, opnd: &APIHandle) {
panic!("Not implemented")
}
pub fn ref_eq(&mut self, lhs: &APIHandleKey, rhs: &APIHandleKey) -> bool {
pub fn ref_eq(&mut self, lhs: &APIHandle, rhs: &APIHandle) -> bool {
panic!("Not implemented")
}
pub fn ref_ult(&mut self, lhs: &APIHandleKey, rhs: &APIHandleKey) -> bool {
pub fn ref_ult(&mut self, lhs: &APIHandle, rhs: &APIHandle) -> bool {
panic!("Not implemented")
}
pub fn extract_value(&mut self, str: &APIHandleKey, index: c_int) -> *const APIHandleKey {
pub fn extract_value(&mut self, str: &APIHandle, index: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn insert_value(&mut self, str: &APIHandleKey, index: c_int, newval: &APIHandleKey) -> *const APIHandleKey {
pub fn insert_value(&mut self, str: &APIHandle, index: c_int, newval: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn extract_element(&mut self, str: &APIHandleKey, index: &APIHandleKey) -> *const APIHandleKey {
pub fn extract_element(&mut self, str: &APIHandle, index: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn insert_element(&mut self, str: &APIHandleKey, index: &APIHandleKey, newval: &APIHandleKey) -> *const APIHandleKey {
pub fn insert_element(&mut self, str: &APIHandle, index: &APIHandle, newval: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn new_fixed(&mut self, mu_type: MuID) -> *const APIHandleKey {
pub fn new_fixed(&mut self, mu_type: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn new_hybrid(&mut self, mu_type: MuID, length: &APIHandleKey) -> *const APIHandleKey {
pub fn new_hybrid(&mut self, mu_type: MuID, length: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn refcast(&mut self, opnd: &APIHandleKey, new_type: MuID) -> *const APIHandleKey {
pub fn refcast(&mut self, opnd: &APIHandle, new_type: MuID) -> *const APIHandle {
panic!("Not implemented")
}
pub fn get_iref(&mut self, opnd: &APIHandleKey) -> *const APIHandleKey {
pub fn get_iref(&mut self, opnd: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn get_field_iref(&mut self, opnd: &APIHandleKey, field: c_int) -> *const APIHandleKey {
pub fn get_field_iref(&mut self, opnd: &APIHandle, field: c_int) -> *const APIHandle {
panic!("Not implemented")
}
pub fn get_elem_iref(&mut self, opnd: &APIHandleKey, index: &APIHandleKey) -> *const APIHandleKey {
pub fn get_elem_iref(&mut self, opnd: &APIHandle, index: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn shift_iref(&mut self, opnd: &APIHandleKey, offset: &APIHandleKey) -> *const APIHandleKey {
pub fn shift_iref(&mut self, opnd: &APIHandle, offset: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn get_var_part_iref(&mut self, opnd: &APIHandleKey) -> *const APIHandleKey {
pub fn get_var_part_iref(&mut self, opnd: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn load(&mut self, ord: CMuMemOrd, loc: &APIHandleKey) -> *const APIHandleKey {
pub fn load(&mut self, ord: CMuMemOrd, loc: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn store(&mut self, ord: CMuMemOrd, loc: &APIHandleKey, newval: &APIHandleKey) {
pub fn store(&mut self, ord: CMuMemOrd, loc: &APIHandle, newval: &APIHandle) {
panic!("Not implemented")
}
pub fn cmpxchg(&mut self, ord_succ: CMuMemOrd, ord_fail: CMuMemOrd, weak: bool, loc: &APIHandleKey, expected: &APIHandleKey, desired: &APIHandleKey, is_succ: *mut CMuBool) -> *const APIHandleKey {
pub fn cmpxchg(&mut self, ord_succ: CMuMemOrd, ord_fail: CMuMemOrd, weak: bool, loc: &APIHandle, expected: &APIHandle, desired: &APIHandle, is_succ: *mut CMuBool) -> *const APIHandle {
panic!("Not implemented")
}
pub fn atomicrmw(&mut self, ord: CMuMemOrd, op: CMuAtomicRMWOptr, loc: &APIHandleKey, opnd: &APIHandleKey) -> *const APIHandleKey {
pub fn atomicrmw(&mut self, ord: CMuMemOrd, op: CMuAtomicRMWOptr, loc: &APIHandle, opnd: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
......@@ -273,107 +273,107 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn new_stack(&mut self, func: &APIHandleKey) -> *const APIHandleKey {
pub fn new_stack(&mut self, func: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn new_thread_nor(&mut self, stack: &APIHandleKey, threadlocal: Option<&APIHandleKey>, vals: Vec<&APIHandleKey>) -> *const APIHandleKey {
pub fn new_thread_nor(&mut self, stack: &APIHandle, threadlocal: Option<&APIHandle>, vals: Vec<&APIHandle>) -> *const APIHandle {
panic!("Not implemented")
}
pub fn new_thread_exc(&mut self, stack: &APIHandleKey, threadlocal: Option<&APIHandleKey>, exc: &APIHandleKey) -> *const APIHandleKey {
pub fn new_thread_exc(&mut self, stack: &APIHandle, threadlocal: Option<&APIHandle>, exc: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn kill_stack(&mut self, stack: &APIHandleKey) {
pub fn kill_stack(&mut self, stack: &APIHandle) {
panic!("Not implemented")
}
pub fn set_threadlocal(&mut self, thread: &APIHandleKey, threadlocal: &APIHandleKey) {
pub fn set_threadlocal(&mut self, thread: &APIHandle, threadlocal: &APIHandle) {
panic!("Not implemented")
}
pub fn get_threadlocal(&mut self, thread: &APIHandleKey) -> *const APIHandleKey {
pub fn get_threadlocal(&mut self, thread: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn new_cursor(&mut self, stack: &APIHandleKey) -> *const APIHandleKey {
pub fn new_cursor(&mut self, stack: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn next_frame(&mut self, cursor: &APIHandleKey) {
pub fn next_frame(&mut self, cursor: &APIHandle) {
panic!("Not implemented")
}
pub fn copy_cursor(&mut self, cursor: &APIHandleKey) -> *const APIHandleKey {
pub fn copy_cursor(&mut self, cursor: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn close_cursor(&mut self, cursor: &APIHandleKey) {
pub fn close_cursor(&mut self, cursor: &APIHandle) {
panic!("Not implemented")
}
pub fn cur_func(&mut self, cursor: &APIHandleKey) -> MuID {
pub fn cur_func(&mut self, cursor: &APIHandle) -> MuID {
panic!("Not implemented")
}
pub fn cur_func_ver(&mut self, cursor: &APIHandleKey) -> MuID {
pub fn cur_func_ver(&mut self, cursor: &APIHandle) -> MuID {
panic!("Not implemented")
}
pub fn cur_inst(&mut self, cursor: &APIHandleKey) -> MuID {
pub fn cur_inst(&mut self, cursor: &APIHandle) -> MuID {
panic!("Not implemented")
}
pub fn dump_keepalives(&mut self, cursor: &APIHandleKey, results: *mut CMuValue) {
pub fn dump_keepalives(&mut self, cursor: &APIHandle, results: *mut CMuValue) {
panic!("Not implemented")
}
pub fn pop_frames_to(&mut self, cursor: &APIHandleKey) {
pub fn pop_frames_to(&mut self, cursor: &APIHandle) {
panic!("Not implemented")
}
pub fn push_frame(&mut self, stack: &APIHandleKey, func: &APIHandleKey) {
pub fn push_frame(&mut self, stack: &APIHandle, func: &APIHandle) {
panic!("Not implemented")
}
pub fn tr64_is_fp(&mut self, value: &APIHandleKey) -> bool {
pub fn tr64_is_fp(&mut self, value: &APIHandle) -> bool {
panic!("Not implemented")
}
pub fn tr64_is_int(&mut self, value: &APIHandleKey) -> bool {
pub fn tr64_is_int(&mut self, value: &APIHandle) -> bool {
panic!("Not implemented")
}
pub fn tr64_is_ref(&mut self, value: &APIHandleKey) -> bool {
pub fn tr64_is_ref(&mut self, value: &APIHandle) -> bool {
panic!("Not implemented")
}
pub fn tr64_to_fp(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_to_fp(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_to_int(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_to_int(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_to_ref(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_to_ref(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_to_tag(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_to_tag(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_from_fp(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_from_fp(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_from_int(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_from_int(&mut self, value: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn tr64_from_ref(&mut self, reff: &APIHandleKey, tag: &APIHandleKey) -> *const APIHandleKey {
pub fn tr64_from_ref(&mut self, reff: &APIHandle, tag: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
......@@ -385,23 +385,23 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn pin(&mut self, loc: &APIHandleKey) -> *const APIHandleKey {
pub fn pin(&mut self, loc: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn unpin(&mut self, loc: &APIHandleKey) {
pub fn unpin(&mut self, loc: &APIHandle) {
panic!("Not implemented")
}
pub fn get_addr(&mut self, loc: &APIHandleKey) -> *const APIHandleKey {
pub fn get_addr(&mut self, loc: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn expose(&mut self, func: &APIHandleKey, call_conv: CMuCallConv, cookie: &APIHandleKey) -> *const APIHandleKey {
pub fn expose(&mut self, func: &APIHandle, call_conv: CMuCallConv, cookie: &APIHandle) -> *const APIHandle {
panic!("Not implemented")
}
pub fn unexpose(&mut self, call_conv: CMuCallConv, value: &APIHandleKey) {
pub fn unexpose(&mut self, call_conv: CMuCallConv, value: &APIHandle) {
panic!("Not implemented")
}
......@@ -409,7 +409,7 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn make_boot_image(&mut self, whitelist: Vec<MuID>, primordial_func: Option<&APIHandleKey>, primordial_stack: Option<&APIHandleKey>, primordial_threadlocal: Option<&APIHandleKey>, sym_fields: Vec<&APIHandleKey>, sym_strings: Vec<String>, reloc_fields: Vec<&APIHandleKey>, reloc_strings: Vec<String>, output_file: String) {
pub fn make_boot_image(&mut self, whitelist: Vec<MuID>, primordial_func: Option<&APIHandle>, primordial_stack: Option<&APIHandle>, primordial_threadlocal: Option<&APIHandle>, sym_fields: Vec<&APIHandle>, sym_strings: Vec<String>, reloc_fields: Vec<&APIHandle>, reloc_strings: Vec<String>, output_file: String) {
panic!("Not implemented")
}
......
......@@ -105,17 +105,17 @@ fn from_MuBool(cbool: CMuBool) -> bool {
cbool != 0
}
// APIHandleKey is immutable when used.
// APIHandle is immutable when used.
#[inline(always)]
fn from_handle<'a>(cmuvalue: CMuValue) -> &'a APIHandleKey {
fn from_handle<'a>(cmuvalue: CMuValue) -> &'a APIHandle {
debug_assert!(!cmuvalue.is_null());
unsafe {
&*(cmuvalue as *const APIHandleKey)
&*(cmuvalue as *const APIHandle)
}
}
#[inline(always)]
fn from_handle_optional<'a>(cmuvalue: CMuValue) -> Option<&'a APIHandleKey> {