Commit 0c6d365a authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Almost working swapstack

parent 5d318fee
Pipeline #942 failed with stages
in 3 minutes and 3 seconds
......@@ -4435,69 +4435,60 @@ impl<'a> InstructionSelection {
if is_exception {
assert!(arg_values.len() == 1);
//Reserve temporary space for the exception throwing routine
emit_sub_u64(self.backend.as_mut(), &SP, &SP, (WORD_SIZE*CALLEE_SAVED_COUNT) as u64);
// Throw the exception
self.emit_runtime_entry(
&entrypoints::THROW_EXCEPTION_INTERNAL,
vec![arg_values[0].clone(), new_sp.clone()],
Some(vec![]),
Some(node),
f_context,
vm
);
// Pass the base of this area as an extra argument
arg_values.push(new_sp.clone());
} else {
self.backend.emit_pop_pair(&FP, &LR, &SP);
}
// Emit precall convention
let arg_tys = arg_nodes.iter().map(|a| a.ty()).collect::<Vec<_>>();
let (stack_arg_size, arg_regs) = self.emit_precall_convention(
&new_sp,
// The frame contains space for all callee saved registers (including the FP and LR)
((CALLEE_SAVED_COUNT + 2) * POINTER_SIZE) as isize,
false,
&arg_values,
&arg_tys,
0,
f_context,
vm
);
// Emit precall convention
let arg_tys = arg_values.iter().map(|a| a.ty.clone()).collect::<Vec<_>>();
let (stack_arg_size, arg_regs) = self.emit_precall_convention(
&new_sp,
// The frame contains space for all callee saved registers (including the FP and LR)
((CALLEE_SAVED_COUNT + 2) * POINTER_SIZE) as isize,
false,
&arg_values,
&arg_tys,
0,
f_context,
vm
);
let potentially_excepting = {
if resumption.is_some() {
let target_id = resumption.unwrap().exn_dest.target;
Some(f_content.get_block(target_id).name())
} else {
None
}
};
let potentially_excepting = {
if resumption.is_some() {
let target_id = resumption.unwrap().exn_dest.target;
Some(f_content.get_block(target_id).name())
} else {
None
}
};
// Call the function that swaps the stack
let callsite = {
if vm.is_doing_jit() {
unimplemented!()
// Call the function that swaps the stack
let callsite = {
if vm.is_doing_jit() {
unimplemented!()
} else {
if is_exception {
// Throw an exception, don't call the swapee's resumption point
self.backend.emit_b_call(callsite_label, "throw_exception_internal".to_string(), potentially_excepting, arg_regs, ALL_USABLE_MACHINE_REGS.to_vec(), true, false)
} else {
let caller_saved = if is_kill {
vec![]
} else {
ALL_USABLE_MACHINE_REGS.to_vec()
};
self.backend.emit_br_call(callsite_label, &LR, potentially_excepting, arg_regs, caller_saved, false)
self.backend.emit_br_call(callsite_label, &LR, potentially_excepting, arg_regs, ALL_USABLE_MACHINE_REGS.to_vec(), false)
}
};
}
};
if resumption.is_some() {
let ref exn_dest = resumption.as_ref().unwrap().exn_dest;
let target_block = exn_dest.target;
if resumption.is_some() {
let ref exn_dest = resumption.as_ref().unwrap().exn_dest;
let target_block = exn_dest.target;
self.current_callsites.push_back((callsite.unwrap().to_relocatable(), target_block, stack_arg_size));
} else if !is_kill {
self.current_callsites.push_back((callsite.unwrap().to_relocatable(), 0, stack_arg_size));
}
self.current_callsites.push_back((callsite.unwrap().to_relocatable(), target_block, stack_arg_size));
} else if !is_kill {
self.current_callsites.push_back((callsite.unwrap().to_relocatable(), 0, stack_arg_size));
}
if !is_kill {
self.emit_unload_arguments(inst.value.as_ref().unwrap(), res_locs, f_context, vm);
emit_add_u64(self.backend.as_mut(), &SP, &SP, res_stack_size as u64);
......
......@@ -582,9 +582,30 @@ fn copy_inline_blocks(
block_content.body.push(TreeNode::new_boxed_inst(switch));
}
&Instruction_::SwapStackExc {
stack,
is_exception,
ref args,
ref resume
} => {
let swapstack = Instruction {
hdr: hdr,
value: value.clone(),
ops: ops.clone(),
v: Instruction_::SwapStackExc {
stack: stack,
is_exception: is_exception,
args: args.clone(),
resume: fix_resume(resume.clone())
}
};
trace!("rewrite to: {}", swapstack);
block_content.body.push(TreeNode::new_boxed_inst(swapstack));
}
&Instruction_::Watchpoint { .. } |
&Instruction_::WPBranch { .. } |
&Instruction_::SwapStackExc { .. } | // Should be safe, just inline it like a call...
&Instruction_::ExnInstruction { .. } => unimplemented!(),
_ => {
......
......@@ -179,16 +179,6 @@ lazy_static! {
jit: RwLock::new(None),
};
pub static ref THROW_EXCEPTION_INTERNAL : RuntimeEntrypoint = RuntimeEntrypoint {
sig: P(MuFuncSig {
hdr: MuEntityHeader::unnamed(ir::new_internal_id()),
ret_tys: vec![],
arg_tys: vec![ADDRESS_TYPE.clone(), ADDRESS_TYPE.clone()]
}),
aot: ValueLocation::Relocatable(RegGroup::GPR, String::from("muentry_throw_exception_internal")),
jit: RwLock::new(None),
};
// impl/decl: math.rs
pub static ref FREM32 : RuntimeEntrypoint = RuntimeEntrypoint {
sig: P(MuFuncSig{
......
......@@ -38,7 +38,8 @@ use runtime::*;
/// (and are accessed by get/set_return_address and get/set_previous_frame and may be passed
/// real frame pointers or the frame cursor)
#[no_mangle]
pub extern "C" fn throw_exception_internal(exception_obj: Address, frame_cursor: Address) -> ! {
pub extern "C" fn throw_exception_internal(exception_obj: Address, frame_cursor: Address) ->
! {
trace!("throwing exception: {}", exception_obj);
if cfg!(debug_assertions) {
......
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