Sha256: 9aef1caef3bd18b825865a3380563cec92bad2046eaae81640fb7cc14e41e493

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

//! Program points.

use crate::ir::{Block, Inst};
use core::fmt;

/// A `ProgramPoint` represents a position in a function where the live range of an SSA value can
/// begin or end. It can be either:
///
/// 1. An instruction or
/// 2. A block header.
///
/// This corresponds more or less to the lines in the textual form of Cranelift IR.
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum ProgramPoint {
    /// An instruction in the function.
    Inst(Inst),
    /// A block header.
    Block(Block),
}

impl ProgramPoint {
    /// Get the instruction we know is inside.
    pub fn unwrap_inst(self) -> Inst {
        match self {
            Self::Inst(x) => x,
            Self::Block(x) => panic!("expected inst: {}", x),
        }
    }
}

impl From<Inst> for ProgramPoint {
    fn from(inst: Inst) -> Self {
        Self::Inst(inst)
    }
}

impl From<Block> for ProgramPoint {
    fn from(block: Block) -> Self {
        Self::Block(block)
    }
}

impl fmt::Display for ProgramPoint {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Self::Inst(x) => write!(f, "{}", x),
            Self::Block(x) => write!(f, "{}", x),
        }
    }
}

impl fmt::Debug for ProgramPoint {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "ProgramPoint({})", self)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::entity::EntityRef;
    use crate::ir::{Block, Inst};
    use alloc::string::ToString;

    #[test]
    fn convert() {
        let i5 = Inst::new(5);
        let b3 = Block::new(3);

        let pp1: ProgramPoint = i5.into();
        let pp2: ProgramPoint = b3.into();

        assert_eq!(pp1.to_string(), "inst5");
        assert_eq!(pp2.to_string(), "block3");
    }
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-18.0.3 ./ext/cargo-vendor/cranelift-codegen-0.105.3/src/ir/progpoint.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cranelift-codegen-0.104.1/src/ir/progpoint.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cranelift-codegen-0.104.0/src/ir/progpoint.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cranelift-codegen-0.103.0/src/ir/progpoint.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cranelift-codegen-0.102.1/src/ir/progpoint.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cranelift-codegen-0.102.1/src/ir/progpoint.rs
wasmtime-14.0.4 ./ext/cargo-vendor/cranelift-codegen-0.101.4/src/ir/progpoint.rs
wasmtime-14.0.3 ./ext/cargo-vendor/cranelift-codegen-0.101.4/src/ir/progpoint.rs
wasmtime-14.0.1 ./ext/cargo-vendor/cranelift-codegen-0.101.1/src/ir/progpoint.rs
wasmtime-14.0.0 ./ext/cargo-vendor/cranelift-codegen-0.101.1/src/ir/progpoint.rs
wasmtime-13.0.0 ./ext/cargo-vendor/cranelift-codegen-0.100.0/src/ir/progpoint.rs
wasmtime-12.0.1 ./ext/cargo-vendor/cranelift-codegen-0.99.1/src/ir/progpoint.rs
wasmtime-12.0.0 ./ext/cargo-vendor/cranelift-codegen-0.99.1/src/ir/progpoint.rs
wasmtime-11.0.0 ./ext/cargo-vendor/cranelift-codegen-0.98.1/src/ir/progpoint.rs
wasmtime-10.0.1 ./ext/cargo-vendor/cranelift-codegen-0.97.1/src/ir/progpoint.rs
wasmtime-10.0.0 ./ext/cargo-vendor/cranelift-codegen-0.97.1/src/ir/progpoint.rs
wasmtime-9.0.4 ./ext/cargo-vendor/cranelift-codegen-0.96.4/src/ir/progpoint.rs
wasmtime-9.0.1 ./ext/cargo-vendor/cranelift-codegen-0.96.1/src/ir/progpoint.rs
wasmtime-8.0.0 ./ext/cargo-vendor/cranelift-codegen-0.95.0/src/ir/progpoint.rs