cubecl_ir/
processing.rs

1use core::fmt::Display;
2
3use alloc::string::ToString;
4use alloc::vec::Vec;
5
6use crate::{Allocator, TypeMap};
7
8use super::{Instruction, Variable};
9
10pub trait Processor: core::fmt::Debug {
11    fn transform(&self, processing: ScopeProcessing, allocator: Allocator) -> ScopeProcessing;
12}
13
14/// Information necessary when compiling a scope.
15pub struct ScopeProcessing {
16    /// The variable declarations.
17    pub variables: Vec<Variable>,
18    /// The operations.
19    pub instructions: Vec<Instruction>,
20    /// The type map
21    pub typemap: TypeMap,
22}
23
24impl Display for ScopeProcessing {
25    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
26        writeln!(f, "{{")?;
27        for instruction in self.instructions.iter() {
28            let instruction_str = instruction.to_string();
29            if !instruction_str.is_empty() {
30                writeln!(f, "    {instruction_str}")?;
31            }
32        }
33        write!(f, "}}")?;
34        Ok(())
35    }
36}