From 2c67d1873f94793a03289d12bf0574b88915266b Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 28 Feb 2021 23:11:21 -0500 Subject: [PATCH] Remove the Interface processor --- src/proc/interface.rs | 234 ------------------------------------------ src/proc/mod.rs | 2 - 2 files changed, 236 deletions(-) delete mode 100644 src/proc/interface.rs diff --git a/src/proc/interface.rs b/src/proc/interface.rs deleted file mode 100644 index 2d11f29ef..000000000 --- a/src/proc/interface.rs +++ /dev/null @@ -1,234 +0,0 @@ -use crate::arena::{Arena, Handle}; -use bit_set::BitSet; - -pub struct Interface<'a, T> { - pub visitor: T, - pub expressions: &'a Arena, - pub local_variables: &'a Arena, - pub mask: &'a mut BitSet, -} - -pub trait Visitor { - fn visit_expr(&mut self, _: Handle, _: &crate::Expression) {} - fn visit_lhs_expr(&mut self, _: Handle, _: &crate::Expression) {} - fn visit_fun(&mut self, _: Handle) {} -} - -impl<'a, T: Visitor> Interface<'a, T> { - pub fn traverse_expr(&mut self, handle: Handle) { - use crate::Expression as E; - - if !self.mask.insert(handle.index()) { - return; - } - let expr = &self.expressions[handle]; - - self.visitor.visit_expr(handle, expr); - - match *expr { - E::Access { base, index } => { - self.traverse_expr(base); - self.traverse_expr(index); - } - E::AccessIndex { base, .. } => { - self.traverse_expr(base); - } - E::Constant(_) => {} - E::Compose { ref components, .. } => { - for &comp in components { - self.traverse_expr(comp); - } - } - E::FunctionArgument(_) | E::GlobalVariable(_) | E::LocalVariable(_) => {} - E::Load { pointer } => { - self.traverse_expr(pointer); - } - E::ImageSample { - image, - sampler, - coordinate, - array_index, - offset: _, - level, - depth_ref, - } => { - self.traverse_expr(image); - self.traverse_expr(sampler); - self.traverse_expr(coordinate); - if let Some(layer) = array_index { - self.traverse_expr(layer); - } - match level { - crate::SampleLevel::Auto | crate::SampleLevel::Zero => (), - crate::SampleLevel::Exact(h) | crate::SampleLevel::Bias(h) => { - self.traverse_expr(h); - } - crate::SampleLevel::Gradient { x, y } => { - self.traverse_expr(x); - self.traverse_expr(y); - } - } - if let Some(dref) = depth_ref { - self.traverse_expr(dref); - } - } - E::ImageLoad { - image, - coordinate, - array_index, - index, - } => { - self.traverse_expr(image); - self.traverse_expr(coordinate); - if let Some(layer) = array_index { - self.traverse_expr(layer); - } - if let Some(index) = index { - self.traverse_expr(index); - } - } - E::ImageQuery { image, query } => { - self.traverse_expr(image); - match query { - crate::ImageQuery::Size { level: Some(expr) } => self.traverse_expr(expr), - crate::ImageQuery::Size { .. } - | crate::ImageQuery::NumLevels - | crate::ImageQuery::NumLayers - | crate::ImageQuery::NumSamples => (), - } - } - E::Unary { expr, .. } => { - self.traverse_expr(expr); - } - E::Binary { left, right, .. } => { - self.traverse_expr(left); - self.traverse_expr(right); - } - E::Select { - condition, - accept, - reject, - } => { - self.traverse_expr(condition); - self.traverse_expr(accept); - self.traverse_expr(reject); - } - E::Derivative { expr, .. } => { - self.traverse_expr(expr); - } - E::Relational { argument, .. } => { - self.traverse_expr(argument); - } - E::Math { - arg, arg1, arg2, .. - } => { - self.traverse_expr(arg); - if let Some(arg) = arg1 { - self.traverse_expr(arg); - } - if let Some(arg) = arg2 { - self.traverse_expr(arg); - } - } - E::As { expr, .. } => { - self.traverse_expr(expr); - } - E::Call(function) => { - self.visitor.visit_fun(function); - } - E::ArrayLength(expr) => { - self.traverse_expr(expr); - } - } - } - - pub fn traverse(&mut self, block: &[crate::Statement]) { - for statement in block { - use crate::Statement as S; - match *statement { - //TODO: we could make `traverse_expr` to work on the emitted expressions - // instead of recursive descend. - // Or we can just remove the whole `Interface` entirely. - S::Emit(_) | S::Break | S::Continue | S::Kill => (), - S::Block(ref b) => { - self.traverse(b); - } - S::If { - condition, - ref accept, - ref reject, - } => { - self.traverse_expr(condition); - self.traverse(accept); - self.traverse(reject); - } - S::Switch { - selector, - ref cases, - ref default, - } => { - self.traverse_expr(selector); - for case in cases.iter() { - self.traverse(&case.body); - } - self.traverse(default); - } - S::Loop { - ref body, - ref continuing, - } => { - self.traverse(body); - self.traverse(continuing); - } - S::Return { value } => { - if let Some(expr) = value { - self.traverse_expr(expr); - } - } - S::Store { pointer, value } => { - let mut left = pointer; - loop { - match self.expressions[left] { - crate::Expression::Access { base, index } => { - self.traverse_expr(index); - left = base; - } - crate::Expression::AccessIndex { base, .. } => { - left = base; - } - _ => break, - } - } - self.visitor.visit_lhs_expr(left, &self.expressions[left]); - self.traverse_expr(value); - } - S::ImageStore { - image, - coordinate, - array_index, - value, - } => { - self.visitor.visit_lhs_expr(image, &self.expressions[image]); - self.traverse_expr(coordinate); - if let Some(expr) = array_index { - self.traverse_expr(expr); - } - self.traverse_expr(value); - } - S::Call { - function, - ref arguments, - result, - } => { - for &argument in arguments { - self.traverse_expr(argument); - } - self.visitor.visit_fun(function); - if let Some(expr) = result { - self.traverse_expr(expr); - } - } - } - } - } -} diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 4b8e46817..965e5021c 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -1,14 +1,12 @@ //! Module processing functionality. pub mod analyzer; -mod interface; mod layouter; mod namer; mod terminator; mod typifier; mod validator; -pub use interface::{Interface, Visitor}; pub use layouter::{Alignment, Layouter}; pub use namer::{EntryPointIndex, NameKey, Namer}; pub use terminator::ensure_block_returns;