Commit 605a8a5f authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Implemented NEW and NEWHYBRID as calls to malloc

parent c429e547
...@@ -1566,38 +1566,13 @@ impl<'a> InstructionSelection { ...@@ -1566,38 +1566,13 @@ impl<'a> InstructionSelection {
Instruction_::New(ref ty) => { Instruction_::New(ref ty) => {
trace!("instsel on NEW"); trace!("instsel on NEW");
if cfg!(debug_assertions) { let tmp_res = self.get_result_value(node, 0);
match ty.v {
MuType_::Hybrid(_) => {
panic!("cannot use NEW for hybrid, use NEWHYBRID instead")
}
_ => {}
}
}
let ty_info = vm.get_backend_type_info(ty.id()); let ty_info = vm.get_backend_type_info(ty.id());
let size = ty_info.size; let size = make_value_int_const(ty_info.size as u64, vm);
let ty_align = ty_info.alignment;
let const_size = make_value_int_const(size as u64, vm);
let tmp_allocator = self.emit_get_allocator(f_context, vm);
let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(),
const_size,
ty_align,
node,
f_context,
vm
);
// ASM: call muentry_init_object(%allocator, %tmp_res, %encode)
let encode =
make_value_int_const(mm::get_gc_type_encode(ty_info.gc_type.id), vm);
self.emit_runtime_entry( self.emit_runtime_entry(
&entrypoints::INIT_OBJ, &entrypoints::FAKE_NEW,
vec![tmp_allocator.clone(), tmp_res.clone(), encode], vec![size],
None, Some(vec![tmp_res]),
Some(node), Some(node),
f_context, f_context,
vm vm
...@@ -1606,35 +1581,20 @@ impl<'a> InstructionSelection { ...@@ -1606,35 +1581,20 @@ impl<'a> InstructionSelection {
Instruction_::NewHybrid(ref ty, var_len) => { Instruction_::NewHybrid(ref ty, var_len) => {
trace!("instsel on NEWHYBRID"); trace!("instsel on NEWHYBRID");
if cfg!(debug_assertions) {
match ty.v {
MuType_::Hybrid(_) => {}
_ => {
panic!(
"NEWHYBRID is only for allocating hybrid types, \
use NEW for others"
)
}
}
}
let ty_info = vm.get_backend_type_info(ty.id()); let ty_info = vm.get_backend_type_info(ty.id());
let ty_align = ty_info.alignment; let ty_align = ty_info.alignment;
let fix_part_size = ty_info.size; let fix_part_size = ty_info.size;
let var_ty_size = ty_info.elem_size.unwrap(); let var_ty_size = ty_info.elem_size.unwrap();
// actual size = fix_part_size + var_ty_size * len // actual size = fix_part_size + var_ty_size * len
let (actual_size, length) = { let actual_size = {
let ref ops = inst.ops; let ref ops = inst.ops;
let ref var_len = ops[var_len]; let ref var_len = ops[var_len];
if match_node_int_imm(var_len) { if match_node_int_imm(var_len) {
let var_len = node_imm_to_u64(var_len); let var_len = node_imm_to_u64(var_len);
let actual_size = fix_part_size + var_ty_size * (var_len as usize); let actual_size = fix_part_size + var_ty_size * (var_len as usize);
( make_value_int_const(actual_size as u64, vm)
make_value_int_const(actual_size as u64, vm),
make_value_int_const(var_len as u64, vm)
)
} else { } else {
let tmp_actual_size = let tmp_actual_size =
make_temporary(f_context, UINT64_TYPE.clone(), vm); make_temporary(f_context, UINT64_TYPE.clone(), vm);
...@@ -1654,27 +1614,15 @@ impl<'a> InstructionSelection { ...@@ -1654,27 +1614,15 @@ impl<'a> InstructionSelection {
&tmp_actual_size, &tmp_actual_size,
fix_part_size as u64 fix_part_size as u64
); );
(tmp_actual_size, tmp_var_len) tmp_actual_size
} }
}; };
let tmp_allocator = self.emit_get_allocator(f_context, vm); let tmp_res = self.get_result_value(node, 0);
let tmp_res = self.emit_alloc_sequence(
tmp_allocator.clone(),
actual_size,
ty_align,
node,
f_context,
vm
);
// ASM: call muentry_init_object(%allocator, %tmp_res, %encode)
let encode =
make_value_int_const(mm::get_gc_type_encode(ty_info.gc_type.id), vm);
self.emit_runtime_entry( self.emit_runtime_entry(
&entrypoints::INIT_HYBRID, &entrypoints::FAKE_NEW,
vec![tmp_allocator.clone(), tmp_res.clone(), encode, length], vec![actual_size],
None, Some(vec![tmp_res]),
Some(node), Some(node),
f_context, f_context,
vm vm
......
...@@ -112,6 +112,10 @@ lazy_static! { ...@@ -112,6 +112,10 @@ lazy_static! {
"muentry_unpin_object", "muentry_unpin_object",
vec![ADDRESS_TYPE.clone()], vec![ADDRESS_TYPE.clone()],
vec![]); vec![]);
pub static ref FAKE_NEW : RuntimeEntrypoint = RuntimeEntrypoint::new(
"malloc",
vec![UINT64_TYPE.clone()],
vec![ADDRESS_TYPE.clone()]);
} }
// decl: exception.rs // decl: exception.rs
......
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