Commit 485c6b38 authored by qinsoon's avatar qinsoon

more debug info for api calls

parent 1fe63f37
......@@ -79,6 +79,20 @@ impl MuType {
}
}
pub fn is_ref(&self) -> bool {
match self.v {
MuType_::Ref(_) => true,
_ => false
}
}
pub fn is_iref(&self) -> bool {
match self.v {
MuType_::IRef(_) => true,
_ => false
}
}
pub fn get_elem_ty(&self) -> Option<P<MuType>> {
match self.v {
MuType_::Array(ref elem_ty, _) => Some(elem_ty.clone()),
......
......@@ -247,9 +247,7 @@ fn build_live_set (cf: &mut CompiledFunction, func: &MuFunctionVersion) {
let mut i = 0;
while is_changed {
if TRACE_BUILD_LIVE_SET {
trace!("---iteration {}---", i);
}
trace!("---iteration {}---", i);
i += 1;
// reset
......
......@@ -56,122 +56,151 @@ impl MuCtx {
}
pub fn handle_from_sint8(&mut self, num: i8, len: c_int) -> *const APIHandle {
trace!("handle_from_sint8");
prepare_handle((self.get_mvm().vm.handle_from_sint8(num, len as usize)))
}
pub fn handle_from_uint8(&mut self, num: u8, len: c_int) -> *const APIHandle {
trace!("handle_from_uint8");
prepare_handle((self.get_mvm().vm.handle_from_uint8(num, len as usize)))
}
pub fn handle_from_sint16(&mut self, num: i16, len: c_int) -> *const APIHandle {
trace!("handle_from_sint16");
prepare_handle((self.get_mvm().vm.handle_from_sint16(num, len as usize)))
}
pub fn handle_from_uint16(&mut self, num: u16, len: c_int) -> *const APIHandle {
trace!("handle_from_uint16");
prepare_handle((self.get_mvm().vm.handle_from_uint16(num, len as usize)))
}
pub fn handle_from_sint32(&mut self, num: i32, len: c_int) -> *const APIHandle {
trace!("handle_from_sint32");
prepare_handle((self.get_mvm().vm.handle_from_sint32(num, len as usize)))
}
pub fn handle_from_uint32(&mut self, num: u32, len: c_int) -> *const APIHandle {
trace!("handle_from_uint32");
prepare_handle((self.get_mvm().vm.handle_from_uint32(num, len as usize)))
}
pub fn handle_from_sint64(&mut self, num: i64, len: c_int) -> *const APIHandle {
trace!("handle_from_sint64");
prepare_handle((self.get_mvm().vm.handle_from_sint64(num, len as usize)))
}
pub fn handle_from_uint64(&mut self, num: u64, len: c_int) -> *const APIHandle {
trace!("handle_from_uint64");
prepare_handle((self.get_mvm().vm.handle_from_uint64(num, len as usize)))
}
pub fn handle_from_uint64s(&mut self, nums: &[u64], len: c_int) -> *const APIHandle {
trace!("handle_from_uint64s");
panic!("Zebu doesnt implement int with length larger than 64bits")
}
pub fn handle_from_float(&mut self, num: f32) -> *const APIHandle {
trace!("handle_from_float");
prepare_handle((self.get_mvm().vm.handle_from_float(num)))
}
pub fn handle_from_double(&mut self, num: f64) -> *const APIHandle {
trace!("handle_from_double");
prepare_handle((self.get_mvm().vm.handle_from_double(num)))
}
pub fn handle_from_ptr(&mut self, mu_type: MuID, ptr: CMuCPtr) -> *const APIHandle {
trace!("handle_from_ptr: ty#{}, {:?}", mu_type, ptr);
let addr = Address::from_mut_ptr(ptr);
prepare_handle((self.get_mvm().vm.handle_from_uptr(mu_type, addr)))
}
pub fn handle_from_fp(&mut self, mu_type: MuID, fp: CMuCFP) -> *const APIHandle {
trace!("handle_from_fp: ty#{}, {:?}", mu_type, fp);
let addr = Address::from_mut_ptr(fp);
prepare_handle((self.get_mvm().vm.handle_from_ufp(mu_type, addr)))
}
pub fn handle_to_sint8(&mut self, opnd: &APIHandle) -> i8 {
trace!("handle_to_sint8: {}", opnd);
self.get_mvm().vm.handle_to_sint8(opnd)
}
pub fn handle_to_uint8(&mut self, opnd: &APIHandle) -> u8 {
trace!("handle_to_uint8: {}", opnd);
self.get_mvm().vm.handle_to_uint8(opnd)
}
pub fn handle_to_sint16(&mut self, opnd: &APIHandle) -> i16 {
trace!("handle_to_sint16: {}", opnd);
self.get_mvm().vm.handle_to_sint16(opnd)
}
pub fn handle_to_uint16(&mut self, opnd: &APIHandle) -> u16 {
trace!("handle_to_uint16: {}", opnd);
self.get_mvm().vm.handle_to_uint16(opnd)
}
pub fn handle_to_sint32(&mut self, opnd: &APIHandle) -> i32 {
trace!("handle_to_sint32: {}", opnd);
self.get_mvm().vm.handle_to_sint32(opnd)
}
pub fn handle_to_uint32(&mut self, opnd: &APIHandle) -> u32 {
trace!("handle_to_uint32: {}", opnd);
self.get_mvm().vm.handle_to_uint32(opnd)
}
pub fn handle_to_sint64(&mut self, opnd: &APIHandle) -> i64 {
trace!("handle_to_sint64: {}", opnd);
self.get_mvm().vm.handle_to_sint64(opnd)
}
pub fn handle_to_uint64(&mut self, opnd: &APIHandle) -> u64 {
trace!("handle_to_uint64: {}", opnd);
self.get_mvm().vm.handle_to_uint64(opnd)
}
pub fn handle_to_float(&mut self, opnd: &APIHandle) -> f32 {
trace!("handle_to_float: {}", opnd);
self.get_mvm().vm.handle_to_float(opnd)
}
pub fn handle_to_double(&mut self, opnd: &APIHandle) -> f64 {
trace!("handle_to_double: {}", opnd);
self.get_mvm().vm.handle_to_double(opnd)
}
pub fn handle_to_ptr(&mut self, opnd: &APIHandle) -> CMuCPtr {
trace!("handle_to_ptr: {}", opnd);
self.get_mvm().vm.handle_to_uptr(opnd).to_ptr_mut()
}
pub fn handle_to_fp(&mut self, opnd: &APIHandle) -> CMuCFP {
trace!("handle_to_fp: {}", opnd);
self.get_mvm().vm.handle_to_ufp(opnd).to_ptr_mut()
}
pub fn handle_from_const(&mut self, id: MuID) -> *const APIHandle {
trace!("handle_from_const");
prepare_handle(self.get_mvm().vm.handle_from_const(id))
}
pub fn handle_from_global(&mut self, id: MuID) -> *const APIHandle {
trace!("handle_from_global");
prepare_handle(self.get_mvm().vm.handle_from_global(id))
}
pub fn handle_from_func(&mut self, id: MuID) -> *const APIHandle {
trace!("handle_from_func");
prepare_handle(self.get_mvm().vm.handle_from_func(id))
}
pub fn handle_from_expose(&mut self, id: MuID) -> *const APIHandle {
trace!("handle_from_Expose");
panic!("Not implemented")
}
......@@ -204,42 +233,52 @@ impl MuCtx {
}
pub fn new_fixed(&mut self, mu_type: MuID) -> *const APIHandle {
trace!("new_fixed: ty#{}", mu_type);
prepare_handle(self.get_mvm().vm.new_fixed(mu_type))
}
pub fn new_hybrid(&mut self, mu_type: MuID, length: &APIHandle) -> *const APIHandle {
trace!("new_hybrid: ty#{}, len {}", mu_type, length);
prepare_handle(self.get_mvm().vm.new_hybrid(mu_type, length))
}
pub fn refcast(&mut self, opnd: &APIHandle, new_type: MuID) -> *const APIHandle {
panic!("Not implemented")
trace!("refcast: {} to ty#{}", opnd, new_type);
prepare_handle(self.get_mvm().vm.handle_refcast(opnd, new_type))
}
pub fn get_iref(&mut self, opnd: &APIHandle) -> *const APIHandle {
trace!("get_iref: {}", opnd);
prepare_handle(self.get_mvm().vm.handle_get_iref(opnd))
}
pub fn get_field_iref(&mut self, opnd: &APIHandle, field: c_int) -> *const APIHandle {
trace!("get_field_iref: {}, field {}", opnd, field);
prepare_handle(self.get_mvm().vm.handle_get_field_iref(opnd, field as usize))
}
pub fn get_elem_iref(&mut self, opnd: &APIHandle, index: &APIHandle) -> *const APIHandle {
trace!("get_elem_iref: {}, index {}", opnd, index);
prepare_handle(self.get_mvm().vm.handle_get_elem_iref(opnd, index))
}
pub fn shift_iref(&mut self, opnd: &APIHandle, offset: &APIHandle) -> *const APIHandle {
trace!("shift_iref: {}, offset {}", opnd, offset);
prepare_handle(self.get_mvm().vm.handle_shift_iref(opnd, offset))
}
pub fn get_var_part_iref(&mut self, opnd: &APIHandle) -> *const APIHandle {
trace!("get_var_part_iref: {}", opnd);
prepare_handle(self.get_mvm().vm.handle_get_var_part_iref(opnd))
}
pub fn load(&mut self, ord: CMuMemOrd, loc: &APIHandle) -> *const APIHandle {
trace!("load: {}", loc);
prepare_handle(self.get_mvm().vm.handle_load(impl_memorder(ord), loc))
}
pub fn store(&mut self, ord: CMuMemOrd, loc: &APIHandle, newval: &APIHandle) {
trace!("store: {} val {}", loc, newval);
self.get_mvm().vm.handle_store(impl_memorder(ord), loc, newval);
}
......@@ -412,6 +451,8 @@ impl MuCtx {
}
fn prepare_handle(handle: APIHandleResult) -> *const APIHandle {
trace!("got handle: {:?}", handle);
Box::into_raw(handle)
}
......
......@@ -5,16 +5,30 @@ use ast::types::*;
use utils::BitSize;
use utils::Address;
use std::fmt;
pub type APIHandleResult = Box<APIHandle>;
pub type APIHandleArg<'a> = &'a APIHandle;
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct APIHandle {
pub id: MuID,
pub v: APIHandleValue
}
#[derive(Clone, Debug)]
impl fmt::Display for APIHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{:?}", self)
}
}
impl fmt::Debug for APIHandle {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "Handle#{}=[{:?}]", self.id, self.v)
}
}
#[derive(Clone)]
pub enum APIHandleValue {
Int(u64, BitSize),
Float(f32),
......@@ -57,6 +71,47 @@ pub enum APIHandleValue {
InstRes,
}
impl fmt::Display for APIHandleValue {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{:?}", self)
}
}
impl fmt::Debug for APIHandleValue {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::APIHandleValue::*;
match self {
&Int(val, len) => write!(f, "{} as int<{}>", val, len),
&Float(val) => write!(f, "{}", val),
&Double(val) => write!(f, "{}", val),
&UPtr(ref ty, addr) => write!(f, "uptr<{}> to {}", ty, addr),
&UFP(ref sig, addr) => write!(f, "ufp<{}> to {}", sig, addr),
&Struct(ref vec) => write!(f, "struct{{{:?}}}", vec),
&Array(ref vec) => write!(f, "array{{{:?}}}", vec),
&Vector(ref vec) => write!(f, "vector{{{:?}}}", vec),
&Ref(ref ty, addr) => write!(f, "ref<{}> to {}", ty, addr),
&IRef(ref ty, addr) => write!(f, "iref<{}> to {}", ty, addr),
&TagRef64(val) => write!(f, "tagref64 0x{:x}", val),
&FuncRef => write!(f, "funcref"),
&ThreadRef => write!(f, "threadref"),
&StackRef => write!(f, "stackref"),
&FCRef => write!(f, "framecursorref"),
&Bundle => write!(f, "IR.bundle"),
&Type(id) => write!(f, "IR.type to #{}", id),
&FuncSig(id) => write!(f, "IR.funcsig to #{}", id),
&FuncVer(id) => write!(f, "IR.funcver to #{}", id),
&BB => write!(f, "IR.BB"),
&Inst => write!(f, "IR.inst"),
&Global(id) => write!(f, "IR.global to #{}", id),
&Func(id) => write!(f, "IR.func to #{}", id),
&ExpFunc => write!(f, "IR.expfunc"),
&NorParam => write!(f, "IR.norparam"),
&ExcParam => write!(f, "IR.excparam"),
&InstRes => write!(f, "IR.instres")
}
}
}
impl APIHandleValue {
pub fn as_ref_or_iref(&self) -> (P<MuType>, Address) {
match self {
......
......@@ -1072,6 +1072,37 @@ impl <'a> VM {
})
}
pub fn handle_refcast(&self, from_op: APIHandleArg, to_ty: MuID) -> APIHandleResult {
let handle_id = self.next_id();
let to_ty = self.get_type(to_ty);
trace!("API: refcast {} into type {}", from_op, to_ty);
match from_op.v {
APIHandleValue::Ref(_, addr) => {
assert!(to_ty.is_ref());
let inner_ty = to_ty.get_referenced_ty().unwrap();
self.new_handle(APIHandle {
id: handle_id,
v: APIHandleValue::Ref(inner_ty, addr)
})
},
APIHandleValue::IRef(_, addr) => {
assert!(to_ty.is_iref());
let inner_ty = to_ty.get_referenced_ty().unwrap();
self.new_handle(APIHandle {
id: handle_id,
v : APIHandleValue::IRef(inner_ty, addr)
})
},
APIHandleValue::FuncRef => unimplemented!(),
_ => panic!("unexpected operand for refcast: {:?}", from_op)
}
}
pub fn handle_get_iref(&self, handle_ref: APIHandleArg) -> APIHandleResult {
let (ty, addr) = handle_ref.v.as_ref();
......@@ -1079,12 +1110,15 @@ impl <'a> VM {
// iref has the same address as ref
trace!("API: get iref from {:?}", handle_ref);
trace!("API: result {} {:?}", ty, addr);
self.new_handle(APIHandle {
let ret = self.new_handle(APIHandle {
id: self.next_id(),
v : APIHandleValue::IRef(ty, addr)
})
});
trace!("API: result {:?}", ret);
ret
}
pub fn handle_shift_iref(&self, handle_iref: APIHandleArg, offset: APIHandleArg) -> APIHandleResult {
......@@ -1141,6 +1175,8 @@ impl <'a> VM {
}
pub fn handle_get_field_iref(&self, handle_iref: APIHandleArg, field: usize) -> APIHandleResult {
trace!("API: get field iref from {:?}", handle_iref);
let (ty, addr) = handle_iref.v.as_iref();
let field_ty = match ty.get_field_ty(field) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment