public op io

This commit is contained in:
Graham Kelly 2024-01-12 15:39:19 -05:00
parent 1878db1c1d
commit c3705d8186
3 changed files with 11 additions and 5 deletions

View file

@ -1674,8 +1674,8 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
}
fn emit(&mut self, op: Operator, loc: SourceLoc) -> Result<()> {
let inputs = op_inputs(self.module, &self.op_stack[..], &op)?;
let outputs = op_outputs(self.module, &self.op_stack[..], &op)?;
let inputs = op_inputs(self.module, Some(&self.op_stack[..]), &op)?;
let outputs = op_outputs(self.module, Some(&self.op_stack[..]), &op)?;
log::trace!(
"emit into block {:?}: op {:?} inputs {:?}",

View file

@ -11,7 +11,7 @@ pub mod entity;
mod errors;
mod frontend;
mod ir;
mod op_traits;
pub mod op_traits;
mod ops;
pub mod passes;
pub mod pool;

View file

@ -7,7 +7,7 @@ use std::borrow::Cow;
pub fn op_inputs(
module: &Module,
op_stack: &[(Type, Value)],
op_stack: Option<&[(Type, Value)]>,
op: &Operator,
) -> Result<Cow<'static, [Type]>> {
match op {
@ -24,6 +24,9 @@ pub fn op_inputs(
}
&Operator::Select => {
let Some(op_stack) = op_stack else{
anyhow::bail!("selects cannot be typed with no stack");
};
let val_ty = op_stack[op_stack.len() - 2].0;
Ok(vec![val_ty, val_ty, Type::I32].into())
}
@ -226,7 +229,7 @@ pub fn op_inputs(
pub fn op_outputs(
module: &Module,
op_stack: &[(Type, Value)],
op_stack: Option<&[(Type, Value)]>,
op: &Operator,
) -> Result<Cow<'static, [Type]>> {
match op {
@ -241,6 +244,9 @@ pub fn op_outputs(
}
&Operator::Select => {
let Some(op_stack) = op_stack else{
anyhow::bail!("selects cannot be typed with no stack");
};
let val_ty = op_stack[op_stack.len() - 2].0;
Ok(vec![val_ty].into())
}