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
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(test)]
mod mlir_tests {
    use super::*;
    use std::ffi::CString;

    #[test]
    fn test_context() {
        unsafe {
            let ctx = mlirContextCreate();
            assert!(mlirContextEqual(ctx, ctx));
            mlirContextDestroy(ctx);
        }
    }

    #[test]
    fn create_string() {
        unsafe {
            let string = CString::new("Hello, world!").unwrap();

            mlirStringRefCreateFromCString(string.as_ptr());
        }
    }

    #[test]
    fn test_location() {
        unsafe {
            let registry = mlirDialectRegistryCreate();
            let context = mlirContextCreate();

            mlirContextAppendDialectRegistry(context, registry);
            mlirRegisterAllDialects(registry);

            let location = mlirLocationUnknownGet(context);
            let string = CString::new("newmod").unwrap();
            let reference = mlirStringRefCreateFromCString(string.as_ptr());

            mlirOperationStateGet(reference, location);

            mlirContextDestroy(context);
            mlirDialectRegistryDestroy(registry);
        }
    }
}