isl_rs/bindings/
access_info.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Context, Error, Flow, LibISLError};
5use libc::uintptr_t;
6
7/// Wraps `isl_access_info`.
8pub struct AccessInfo {
9    pub ptr: uintptr_t,
10    pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15    fn isl_access_info_compute_flow(acc: uintptr_t) -> uintptr_t;
16
17    fn isl_access_info_free(acc: uintptr_t) -> uintptr_t;
18
19    fn isl_access_info_get_ctx(acc: uintptr_t) -> uintptr_t;
20
21}
22
23impl AccessInfo {
24    /// Wraps `isl_access_info_compute_flow`.
25    pub fn compute_flow(self) -> Result<Flow, LibISLError> {
26        let acc = self;
27        let isl_rs_ctx = acc.get_ctx();
28        let mut acc = acc;
29        acc.do_not_free_on_drop();
30        let acc = acc.ptr;
31        let isl_rs_result = unsafe { isl_access_info_compute_flow(acc) };
32        let isl_rs_result = Flow { ptr: isl_rs_result,
33                                   should_free_on_drop: true };
34        let err = isl_rs_ctx.last_error();
35        if err != Error::None_ {
36            let err_msg = isl_rs_ctx.last_error_msg();
37            isl_rs_ctx.reset_error();
38            return Err(LibISLError::new(err, err_msg));
39        }
40        Ok(isl_rs_result)
41    }
42
43    /// Wraps `isl_access_info_free`.
44    pub fn free(self) -> Result<AccessInfo, LibISLError> {
45        let acc = self;
46        let isl_rs_ctx = acc.get_ctx();
47        let mut acc = acc;
48        acc.do_not_free_on_drop();
49        let acc = acc.ptr;
50        let isl_rs_result = unsafe { isl_access_info_free(acc) };
51        let isl_rs_result = AccessInfo { ptr: isl_rs_result,
52                                         should_free_on_drop: true };
53        let err = isl_rs_ctx.last_error();
54        if err != Error::None_ {
55            let err_msg = isl_rs_ctx.last_error_msg();
56            isl_rs_ctx.reset_error();
57            return Err(LibISLError::new(err, err_msg));
58        }
59        Ok(isl_rs_result)
60    }
61
62    /// Wraps `isl_access_info_get_ctx`.
63    pub fn get_ctx(&self) -> Context {
64        let acc = self;
65        let acc = acc.ptr;
66        let isl_rs_result = unsafe { isl_access_info_get_ctx(acc) };
67        let isl_rs_result = Context { ptr: isl_rs_result,
68                                      should_free_on_drop: false };
69        isl_rs_result
70    }
71
72    /// Does not call isl_access_info_free() on being dropped. (For internal use
73    /// only.)
74    pub fn do_not_free_on_drop(&mut self) {
75        self.should_free_on_drop = false;
76    }
77}
78
79impl Drop for AccessInfo {
80    fn drop(&mut self) {
81        if self.should_free_on_drop {
82            unsafe {
83                isl_access_info_free(self.ptr);
84            }
85        }
86    }
87}