Browse Source

fix one bug + refactor Option handling in some func

pull/672/head
Patrick Ventuzelo 5 years ago
parent
commit
e4d60d23ed
  1. 47
      crates/lightbeam/src/backend.rs

47
crates/lightbeam/src/backend.rs

@ -3215,13 +3215,13 @@ impl<'this, M: ModuleContext> Context<'this, M> {
ty: impl Into<Option<GPRType>>, ty: impl Into<Option<GPRType>>,
val: &mut ValueLocation, val: &mut ValueLocation,
) -> Result<Option<GPR>, Error> { ) -> Result<Option<GPR>, Error> {
let out = match self.to_reg(ty, *val) { if let Some(out) = self.to_reg(ty, *val)? {
Err(e) => return Err(e),
Ok(o) => o.unwrap(),
};
self.free_value(*val)?; self.free_value(*val)?;
*val = ValueLocation::Reg(out); *val = ValueLocation::Reg(out);
Ok(Some(out)) Ok(Some(out))
} else {
Ok(None)
}
} }
/// Clones this value into a register so that it can be efficiently read /// Clones this value into a register so that it can be efficiently read
@ -3236,13 +3236,13 @@ impl<'this, M: ModuleContext> Context<'this, M> {
self.block_state.regs.mark_used(r); self.block_state.regs.mark_used(r);
Ok(Some(r)) Ok(Some(r))
} }
val => { val => match self.take_reg(ty.unwrap_or(GPRType::Rq)) {
let scratch = self.take_reg(ty.unwrap_or(GPRType::Rq)).unwrap(); Some(scratch) => {
self.copy_value(val, CCLoc::Reg(scratch))?; self.copy_value(val, CCLoc::Reg(scratch))?;
Ok(Some(scratch)) Ok(Some(scratch))
} }
None => Ok(None),
},
} }
} }
@ -3253,13 +3253,14 @@ impl<'this, M: ModuleContext> Context<'this, M> {
ty: impl Into<Option<GPRType>>, ty: impl Into<Option<GPRType>>,
val: &mut ValueLocation, val: &mut ValueLocation,
) -> Result<Option<GPR>, Error> { ) -> Result<Option<GPR>, Error> {
let out = match self.to_temp_reg(ty, *val) { let out = self.to_temp_reg(ty, *val)?;
Err(e) => return Err(e), if let Some(o) = out {
Ok(o) => o.unwrap(),
};
self.free_value(*val)?; self.free_value(*val)?;
*val = ValueLocation::Reg(out); *val = ValueLocation::Reg(o);
Ok(Some(out)) Ok(Some(o))
} else {
return Ok(None);
}
} }
fn into_temp_loc( fn into_temp_loc(
@ -3288,25 +3289,25 @@ impl<'this, M: ModuleContext> Context<'this, M> {
val: ValueLocation, val: ValueLocation,
) -> Result<Option<GPR>, Error> { ) -> Result<Option<GPR>, Error> {
// If we have `None` as the type then it always matches (`.unwrap_or(true)`) // If we have `None` as the type then it always matches (`.unwrap_or(true)`)
let res = match val { match val {
ValueLocation::Reg(r) => { ValueLocation::Reg(r) => {
let ty = ty.into(); let ty = ty.into();
let type_matches = ty.map(|t| t == r.type_()).unwrap_or(true); let type_matches = ty.map(|t| t == r.type_()).unwrap_or(true);
if self.block_state.regs.num_usages(r) <= 1 && type_matches { if self.block_state.regs.num_usages(r) <= 1 && type_matches {
self.block_state.regs.mark_used(r); self.block_state.regs.mark_used(r);
Some(r) Ok(Some(r))
} else { } else {
let scratch = self.take_reg(ty.unwrap_or(GPRType::Rq)).unwrap(); if let Some(scratch) = self.take_reg(ty.unwrap_or(GPRType::Rq)) {
self.copy_value(val, CCLoc::Reg(scratch))?; self.copy_value(val, CCLoc::Reg(scratch))?;
Ok(Some(scratch))
Some(scratch) } else {
Ok(None)
} }
} }
val => self.to_reg(ty, val)?, }
}; val => self.to_reg(ty, val),
Ok(res) }
} }
pub fn f32_neg(&mut self) -> Result<(), Error> { pub fn f32_neg(&mut self) -> Result<(), Error> {

Loading…
Cancel
Save