From c3705d81862c688a5810b8afde35a70f1e476ce8 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Fri, 12 Jan 2024 15:39:19 -0500 Subject: [PATCH] public op io --- src/frontend.rs | 4 ++-- src/lib.rs | 2 +- src/op_traits.rs | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/frontend.rs b/src/frontend.rs index 4b66d7a..0c21fab 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -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 {:?}", diff --git a/src/lib.rs b/src/lib.rs index a5b038f..870f51c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/op_traits.rs b/src/op_traits.rs index 8e6a887..8c44e74 100644 --- a/src/op_traits.rs +++ b/src/op_traits.rs @@ -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> { 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> { 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()) }