mlir/attributes/
named.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2024-2025, Giordano Salvador
// SPDX-License-Identifier: BSD-3-Clause

#![allow(dead_code)]

use mlir_sys::MlirAttribute;
use mlir_sys::MlirNamedAttribute;
use mlir_sys::mlirNamedAttributeGet;

use std::cmp;

use crate::attributes;
use crate::do_unsafe;
use crate::ir;

use attributes::IAttribute;
use ir::Attribute;
use ir::Identifier;

#[derive(Clone)]
pub struct Named(MlirNamedAttribute);

impl Named {
    pub fn new(id: &Identifier, attr: &Attribute) -> Self {
        Named::from(do_unsafe!(mlirNamedAttributeGet(*id.get(), *attr.get())))
    }

    pub fn get(&self) -> &MlirNamedAttribute {
        &self.0
    }

    pub fn get_identifier(&self) -> Identifier {
        Identifier::from(self.get().name)
    }

    pub fn get_mut(&mut self) -> &mut MlirNamedAttribute {
        &mut self.0
    }
}
impl From<MlirNamedAttribute> for Named {
    fn from(attr: MlirNamedAttribute) -> Self {
        Self(attr)
    }
}

impl IAttribute for Named {
    fn get(&self) -> &MlirAttribute {
        &self.0.attribute
    }

    fn get_mut(&mut self) -> &mut MlirAttribute {
        &mut self.0.attribute
    }
}

impl cmp::PartialEq for Named {
    fn eq(&self, rhs: &Self) -> bool {
        self.as_attribute() == rhs.as_attribute() && self.get_identifier() == rhs.get_identifier()
    }
}