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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pub mod arith;
pub mod cf;
mod handle;
pub mod llvm;
mod registry;
pub use self::{handle::Handle, registry::Registry};
use crate::mlir_sys::{
mlirDialectEqual, mlirDialectGetContext, mlirDialectGetNamespace, MlirDialect,
};
use crate::{
context::{Context, ContextRef},
string_ref::StringRef,
};
use std::marker::PhantomData;
#[derive(Clone, Copy, Debug)]
pub struct Dialect<'c> {
raw: MlirDialect,
_context: PhantomData<&'c Context>,
}
impl<'c> Dialect<'c> {
pub fn context(&self) -> ContextRef<'c> {
unsafe { ContextRef::from_raw(mlirDialectGetContext(self.raw)) }
}
pub fn namespace(&self) -> StringRef {
unsafe { StringRef::from_raw(mlirDialectGetNamespace(self.raw)) }
}
pub(crate) unsafe fn from_raw(dialect: MlirDialect) -> Self {
Self {
raw: dialect,
_context: Default::default(),
}
}
}
impl<'c> PartialEq for Dialect<'c> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirDialectEqual(self.raw, other.raw) }
}
}
impl<'c> Eq for Dialect<'c> {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn equal() {
let context = Context::new();
assert_eq!(
Handle::func().load_dialect(&context),
Handle::func().load_dialect(&context)
);
}
#[test]
fn not_equal() {
let context = Context::new();
assert_ne!(
Handle::func().load_dialect(&context),
Handle::llvm().load_dialect(&context)
);
}
}