replace expect by Error for backend code
This commit is contained in:
@@ -104,7 +104,7 @@ impl GPR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arg_locs(types: impl IntoIterator<Item = SignlessType>) -> Vec<CCLoc> {
|
pub fn arg_locs(types: impl IntoIterator<Item = SignlessType>) -> Result<Vec<CCLoc>, Error> {
|
||||||
let types = types.into_iter();
|
let types = types.into_iter();
|
||||||
let mut out = Vec::with_capacity(types.size_hint().0);
|
let mut out = Vec::with_capacity(types.size_hint().0);
|
||||||
// TODO: VmCtx is in the first register
|
// TODO: VmCtx is in the first register
|
||||||
@@ -121,19 +121,21 @@ pub fn arg_locs(types: impl IntoIterator<Item = SignlessType>) -> Vec<CCLoc> {
|
|||||||
out
|
out
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
F32 | F64 => out.push(
|
F32 | F64 => match float_gpr_iter.next() {
|
||||||
float_gpr_iter
|
None => {
|
||||||
.next()
|
return Err(Error::Microwasm(
|
||||||
.map(|&r| CCLoc::Reg(r))
|
"Float args on stack not yet supported".to_string(),
|
||||||
.expect("Float args on stack not yet supported"),
|
))
|
||||||
),
|
}
|
||||||
|
Some(val) => out.push(CCLoc::Reg(*val)),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ret_locs(types: impl IntoIterator<Item = SignlessType>) -> Vec<CCLoc> {
|
pub fn ret_locs(types: impl IntoIterator<Item = SignlessType>) -> Result<Vec<CCLoc>, Error> {
|
||||||
let types = types.into_iter();
|
let types = types.into_iter();
|
||||||
let mut out = Vec::with_capacity(types.size_hint().0);
|
let mut out = Vec::with_capacity(types.size_hint().0);
|
||||||
// TODO: VmCtx is in the first register
|
// TODO: VmCtx is in the first register
|
||||||
@@ -142,20 +144,26 @@ pub fn ret_locs(types: impl IntoIterator<Item = SignlessType>) -> Vec<CCLoc> {
|
|||||||
|
|
||||||
for ty in types {
|
for ty in types {
|
||||||
match ty {
|
match ty {
|
||||||
I32 | I64 => out.push(CCLoc::Reg(
|
I32 | I64 => match int_gpr_iter.next() {
|
||||||
*int_gpr_iter
|
None => {
|
||||||
.next()
|
return Err(Error::Microwasm(
|
||||||
.expect("We don't support stack returns yet"),
|
"We don't support stack returns yet".to_string(),
|
||||||
)),
|
))
|
||||||
F32 | F64 => out.push(CCLoc::Reg(
|
}
|
||||||
*float_gpr_iter
|
Some(val) => out.push(CCLoc::Reg(*val)),
|
||||||
.next()
|
},
|
||||||
.expect("We don't support stack returns yet"),
|
F32 | F64 => match float_gpr_iter.next() {
|
||||||
)),
|
None => {
|
||||||
|
return Err(Error::Microwasm(
|
||||||
|
"We don't support stack returns yet".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Some(val) => out.push(CCLoc::Reg(*val)),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
@@ -280,7 +288,6 @@ impl Default for Registers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Registers {
|
impl Registers {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let result = Self {
|
let result = Self {
|
||||||
@@ -5345,7 +5352,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
rets: impl IntoIterator<Item = SignlessType>,
|
rets: impl IntoIterator<Item = SignlessType>,
|
||||||
preserve_vmctx: bool,
|
preserve_vmctx: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let locs = arg_locs(args);
|
let locs = arg_locs(args)?;
|
||||||
|
|
||||||
self.save_volatile(..locs.len())?;
|
self.save_volatile(..locs.len())?;
|
||||||
|
|
||||||
@@ -5552,20 +5559,25 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pending.len() == start_len {
|
if pending.len() == start_len {
|
||||||
let src = *pending
|
let src =
|
||||||
.iter()
|
match pending
|
||||||
.filter_map(|(src, _)| {
|
.iter()
|
||||||
if let ValueLocation::Reg(reg) = src {
|
.filter_map(|(src, _)| {
|
||||||
Some(reg)
|
if let ValueLocation::Reg(reg) = src {
|
||||||
} else {
|
Some(reg)
|
||||||
None
|
} else {
|
||||||
}
|
None
|
||||||
})
|
}
|
||||||
.next()
|
})
|
||||||
.expect(
|
.next()
|
||||||
"Programmer error: We shouldn't need to push \
|
{
|
||||||
intermediate args if we don't have any argument sources in registers",
|
None => return Err(Error::Microwasm(
|
||||||
);
|
"Programmer error: We shouldn't need to push \
|
||||||
|
intermediate args if we don't have any argument sources in registers"
|
||||||
|
.to_string(),
|
||||||
|
)),
|
||||||
|
Some(val) => *val,
|
||||||
|
};
|
||||||
let new_src = self.push_physical(ValueLocation::Reg(src))?;
|
let new_src = self.push_physical(ValueLocation::Reg(src))?;
|
||||||
for (old_src, _) in pending.iter_mut() {
|
for (old_src, _) in pending.iter_mut() {
|
||||||
if *old_src == ValueLocation::Reg(src) {
|
if *old_src == ValueLocation::Reg(src) {
|
||||||
@@ -5583,7 +5595,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
returns: impl IntoIterator<Item = SignlessType>,
|
returns: impl IntoIterator<Item = SignlessType>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
for loc in ret_locs(returns) {
|
for loc in ret_locs(returns)? {
|
||||||
if let CCLoc::Reg(reg) = loc {
|
if let CCLoc::Reg(reg) = loc {
|
||||||
self.block_state.regs.mark_used(reg);
|
self.block_state.regs.mark_used(reg);
|
||||||
}
|
}
|
||||||
@@ -5599,7 +5611,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
arg_types: impl IntoIterator<Item = SignlessType>,
|
arg_types: impl IntoIterator<Item = SignlessType>,
|
||||||
return_types: impl IntoIterator<Item = SignlessType>,
|
return_types: impl IntoIterator<Item = SignlessType>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let locs = arg_locs(arg_types);
|
let locs = arg_locs(arg_types)?;
|
||||||
|
|
||||||
for &loc in &locs {
|
for &loc in &locs {
|
||||||
if let CCLoc::Reg(r) = loc {
|
if let CCLoc::Reg(r) = loc {
|
||||||
@@ -5749,7 +5761,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
arg_types: impl IntoIterator<Item = SignlessType>,
|
arg_types: impl IntoIterator<Item = SignlessType>,
|
||||||
return_types: impl IntoIterator<Item = SignlessType>,
|
return_types: impl IntoIterator<Item = SignlessType>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let locs = arg_locs(arg_types);
|
let locs = arg_locs(arg_types)?;
|
||||||
|
|
||||||
self.save_volatile(..locs.len())?;
|
self.save_volatile(..locs.len())?;
|
||||||
|
|
||||||
@@ -5775,7 +5787,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
arg_types: impl IntoIterator<Item = SignlessType>,
|
arg_types: impl IntoIterator<Item = SignlessType>,
|
||||||
return_types: impl IntoIterator<Item = SignlessType>,
|
return_types: impl IntoIterator<Item = SignlessType>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let locs = arg_locs(arg_types);
|
let locs = arg_locs(arg_types)?;
|
||||||
|
|
||||||
dynasm!(self.asm
|
dynasm!(self.asm
|
||||||
; push Rq(VMCTX)
|
; push Rq(VMCTX)
|
||||||
@@ -5821,7 +5833,8 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
params: impl IntoIterator<Item = SignlessType>,
|
params: impl IntoIterator<Item = SignlessType>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let locs = Vec::from_iter(arg_locs(params));
|
let i_locs = arg_locs(params)?;
|
||||||
|
let locs = Vec::from_iter(i_locs);
|
||||||
|
|
||||||
self.apply_cc(&BlockCallingConvention::function_start(locs))?;
|
self.apply_cc(&BlockCallingConvention::function_start(locs))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -134,14 +134,14 @@ where
|
|||||||
|
|
||||||
let num_returns = func_type.returns().len();
|
let num_returns = func_type.returns().len();
|
||||||
|
|
||||||
|
let loc = ret_locs(func_type.returns().iter().map(|t| t.to_microwasm_type()))?;
|
||||||
|
|
||||||
blocks.insert(
|
blocks.insert(
|
||||||
BrTarget::Return,
|
BrTarget::Return,
|
||||||
Block {
|
Block {
|
||||||
label: BrTarget::Return,
|
label: BrTarget::Return,
|
||||||
params: num_returns as u32,
|
params: num_returns as u32,
|
||||||
calling_convention: Some(Left(BlockCallingConvention::function_start(ret_locs(
|
calling_convention: Some(Left(BlockCallingConvention::function_start(loc))),
|
||||||
func_type.returns().iter().map(|t| t.to_microwasm_type()),
|
|
||||||
)))),
|
|
||||||
is_next: false,
|
is_next: false,
|
||||||
has_backwards_callers: false,
|
has_backwards_callers: false,
|
||||||
actual_num_callers: 0,
|
actual_num_callers: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user