Skip to main content

melior/ir/value/
value_like.rs

1use super::Type;
2use mlir_sys::{
3    mlirValueDump, mlirValueGetType, mlirValueIsABlockArgument, mlirValueIsAOpResult, MlirValue,
4};
5
6/// Trait for value-like types.
7pub trait ValueLike<'c> {
8    /// Converts a value into a raw value.
9    fn to_raw(&self) -> MlirValue;
10
11    /// Returns a type.
12    fn r#type(&self) -> Type<'c> {
13        unsafe { Type::from_raw(mlirValueGetType(self.to_raw())) }
14    }
15
16    /// Returns `true` if a value is a block argument.
17    fn is_block_argument(&self) -> bool {
18        unsafe { mlirValueIsABlockArgument(self.to_raw()) }
19    }
20
21    /// Returns `true` if a value is an operation result.
22    fn is_operation_result(&self) -> bool {
23        unsafe { mlirValueIsAOpResult(self.to_raw()) }
24    }
25
26    /// Dumps a value.
27    fn dump(&self) {
28        unsafe { mlirValueDump(self.to_raw()) }
29    }
30}