Sha256: 07819007a57db858c3cd22e0b22e6a8f59c9f704861fb28bd335a0f3e6679908

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

use crate::{Operand, OperandConstraint, OperandKind};

pub struct Operands<'a>(pub &'a [Operand]);

impl<'a> Operands<'a> {
    pub fn new(operands: &'a [Operand]) -> Self {
        Self(operands)
    }

    pub fn matches<F: Fn(Operand) -> bool + 'a>(
        &self,
        predicate: F,
    ) -> impl Iterator<Item = (usize, Operand)> + 'a {
        self.0
            .iter()
            .cloned()
            .enumerate()
            .filter(move |(_, op)| predicate(*op))
    }

    pub fn def_ops(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
        self.matches(|op| op.kind() == OperandKind::Def)
    }

    pub fn use_ops(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
        self.matches(|op| op.kind() == OperandKind::Use)
    }

    pub fn reuse(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
        self.matches(|op| matches!(op.constraint(), OperandConstraint::Reuse(_)))
    }

    pub fn fixed(&self) -> impl Iterator<Item = (usize, Operand)> + 'a {
        self.matches(|op| matches!(op.constraint(), OperandConstraint::FixedReg(_)))
    }
}

impl<'a> core::ops::Index<usize> for Operands<'a> {
    type Output = Operand;

    fn index(&self, index: usize) -> &Self::Output {
        &self.0[index]
    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/regalloc2-0.11.1/src/fastalloc/iter.rs
wasmtime-28.0.0 ./ext/cargo-vendor/regalloc2-0.11.1/src/fastalloc/iter.rs