melior/ir/attribute/
attribute_like.rs1use crate::{
2 ir::{r#type::TypeId, Type},
3 ContextRef,
4};
5use melior_macro::attribute_check_functions;
6use mlir_sys::{
7 mlirAttributeDump, mlirAttributeGetContext, mlirAttributeGetType, mlirAttributeGetTypeID,
8 MlirAttribute,
9};
10
11pub trait AttributeLike<'c> {
13 fn to_raw(&self) -> MlirAttribute;
15
16 fn context(&self) -> ContextRef<'c> {
18 unsafe { ContextRef::from_raw(mlirAttributeGetContext(self.to_raw())) }
19 }
20
21 fn r#type(&self) -> Type {
23 unsafe { Type::from_raw(mlirAttributeGetType(self.to_raw())) }
24 }
25
26 fn type_id(&self) -> TypeId<'c> {
28 unsafe { TypeId::from_raw(mlirAttributeGetTypeID(self.to_raw())) }
29 }
30
31 fn dump(&self) {
33 unsafe { mlirAttributeDump(self.to_raw()) }
34 }
35
36 attribute_check_functions!(
37 mlirAttributeIsAAffineMap,
38 mlirAttributeIsAArray,
39 mlirAttributeIsABool,
40 mlirAttributeIsADenseBoolArray,
41 mlirAttributeIsADenseElements,
42 mlirAttributeIsADenseF32Array,
43 mlirAttributeIsADenseF64Array,
44 mlirAttributeIsADenseFPElements,
45 mlirAttributeIsADenseI16Array,
46 mlirAttributeIsADenseI32Array,
47 mlirAttributeIsADenseI64Array,
48 mlirAttributeIsADenseI8Array,
49 mlirAttributeIsADenseIntElements,
50 mlirAttributeIsADictionary,
51 mlirAttributeIsAElements,
52 mlirAttributeIsAFlatSymbolRef,
53 mlirAttributeIsAFloat,
54 mlirAttributeIsAInteger,
55 mlirAttributeIsAIntegerSet,
56 mlirAttributeIsAOpaque,
57 mlirAttributeIsASparseElements,
58 mlirAttributeIsASparseTensorEncodingAttr,
59 mlirAttributeIsAStridedLayout,
60 mlirAttributeIsAString,
61 mlirAttributeIsASymbolRef,
62 mlirAttributeIsAType,
63 mlirAttributeIsAUnit,
64 );
65}