Commit 13d6c939 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Implemented new_ir_builder

parent a7fb3d0d
Pipeline #1132 passed with stages
in 45 minutes
......@@ -50,7 +50,7 @@ use super::deps::*;
// defined in api_c.rs is encoded as *mut c_void rather than *mut MuVM or other concrete pointers.
// But it doesn't matter, because the header is only ever read in these three functions.
#[inline(always)]
fn from_MuVM_ptr(ptr: *mut CMuVM) -> *mut MuVM {
pub fn from_MuVM_ptr(ptr: *mut CMuVM) -> *mut MuVM {
debug_assert!(!ptr.is_null());
unsafe { (*ptr).header as *mut MuVM }
}
......
......@@ -493,21 +493,7 @@ impl MuCtx {
pub fn new_ir_builder(&mut self) -> *mut CMuIRBuilder {
info!("Creating MuIRBuilder...");
let b: Box<MuIRBuilder> = MuIRBuilder::new(self.mvm);
let b_ptr = Box::into_raw(b);
debug!("The MuIRBuilder address: {:?}", b_ptr);
let cb = make_new_MuIRBuilder(b_ptr as *mut c_void);
debug!("The C-visible CMuIRBuilder struct address: {:?}", cb);
unsafe {
(*b_ptr).c_struct = cb;
}
cb
MuIRBuilder::new_c(self.mvm)
}
pub fn make_boot_image(
......
......@@ -65,6 +65,18 @@ pub struct TransientBundle {
}
impl MuIRBuilder {
pub fn new_c(mvm: *const MuVM) -> *mut CMuIRBuilder {
let b: Box<MuIRBuilder> = MuIRBuilder::new(mvm);
let b_ptr = Box::into_raw(b);
debug!("The MuIRBuilder address: {:?}", b_ptr);
let cb = make_new_MuIRBuilder(b_ptr as *mut c_void);
debug!("The C-visible CMuIRBuilder struct address: {:?}", cb);
unsafe { (*b_ptr).c_struct = cb; }
cb
}
pub fn new(mvm: *const MuVM) -> Box<MuIRBuilder> {
Box::new(MuIRBuilder {
mvm: mvm,
......@@ -4316,13 +4328,14 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
}
CMU_CI_UVM_IRBUILDER_LOAD ... CMU_CI_UVM_IRBUILDER_NEW_COMMINST => {
CMU_CI_UVM_IRBUILDER_NEW_IR_BUILDER ... CMU_CI_UVM_IRBUILDER_NEW_COMMINST => {
assert_ir!(
tys.is_empty() && sigs.is_empty() && flags.is_empty() &&
exc_clause.is_none() && keepalives.is_none()
);
let (func_name, arg_tys, ret_tys) = match opcode {
CMU_CI_UVM_IRBUILDER_NEW_IR_BUILDER => ("muentry_new_ir_builder", vec![], vec![self.ensure_irbuilderref()]),
CMU_CI_UVM_IRBUILDER_LOAD => ("_forwarder__MuIRBuilder__load", vec![self.ensure_irbuilderref()], vec![]),
CMU_CI_UVM_IRBUILDER_ABORT => ("_forwarder__MuIRBuilder__abort", vec![self.ensure_irbuilderref()], vec![]),
CMU_CI_UVM_IRBUILDER_GEN_SYM => ("_forwarder__MuIRBuilder__gen_sym", vec![self.ensure_irbuilderref(), self.ensure_iref_i8()], vec![self.ensure_i32()]),
......@@ -4406,14 +4419,14 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
_ => unreachable!()
};
self.build_irbuilder_inst(fcb, hdr, result_ids, opcode, args, func_name, arg_tys, ret_tys)
self.build_runtime_entry(fcb, hdr, result_ids, opcode, args, func_name, arg_tys, ret_tys)
}
_ => unimplemented!()
}
}
fn build_irbuilder_inst(
fn build_runtime_entry(
&mut self,
fcb: &mut FuncCtxBuilder,
hdr: MuEntityHeader,
......
......@@ -51,6 +51,13 @@ impl MuVM {
}
}
pub fn from_vm(vm: Arc<VM>) -> MuVM {
MuVM {
vm: vm,
name_cache: Mutex::new(HashMap::new())
}
}
pub fn new_context(&self) -> *mut CMuCtx {
info!("Creating MuCtx...");
......@@ -117,6 +124,7 @@ impl MuVM {
pub fn current_thread_as_mu_thread(&self, threadlocal: CMuCPtr) {
unsafe {
//MuThread::current_thread_as_mu_thread
thread::MuThread::current_thread_as_mu_thread(
transmute::<CMuCPtr, Address>(threadlocal),
self.vm.clone()
......@@ -172,6 +180,27 @@ pub extern "C" fn mu_fastimpl_new_with_opts(opts: *const c_char) -> *mut CMuVM {
c_mvm
}
#[no_mangle]
pub extern "C" fn mu_fastimpl_get_running_vm() -> *mut CMuVM {
info!("Getting the running Mu micro VM fast implementation instance...");
let mvm = Box::new(MuVM::from_vm(thread::MuThread::current().vm.clone()));
let mvm_ptr = Box::into_raw(mvm);
debug!("The MuVM instance address: {:?}", mvm_ptr);
let c_mvm = make_new_MuVM(mvm_ptr as *mut c_void);
debug!("The C-visible CMuVM struct address: {:?}", c_mvm);
c_mvm
}
#[no_mangle]
pub extern "C" fn muentry_new_ir_builder () -> *mut CMuIRBuilder {
let mvm = mu_fastimpl_get_running_vm();
info!("Creating MuIRBuilder...");
MuIRBuilder::new_c(super::super::api_bridge::from_MuVM_ptr(mvm))
}
use vm::built_info;
#[no_mangle]
......
......@@ -41,6 +41,8 @@ pub use self::api_impl::mu_fastimpl_new;
/// creates a Zebu instance with specified options
/// See vm_options.rs for supported options.
pub use self::api_impl::mu_fastimpl_new_with_opts;
pub use self::api_impl::mu_fastimpl_get_running_vm;
pub use self::api_impl::muentry_new_ir_builder;
/// returns a version string for current Zebu build
pub use self::api_impl::mu_get_version;
......
......@@ -22,6 +22,7 @@ extern "C" {
#endif
MuVM *mu_fastimpl_new();
MuVM *mu_fastimpl_get_running_vm();
MuVM *mu_fastimpl_new_with_opts(const char*);
const char* mu_get_version();
......
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