elina_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4// TODO: check if this is okay
5#![allow(improper_ctypes)]
6
7// include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
8mod bindings;
9pub use bindings::*;
10
11// extern "C" {
12//     pub fn foreach_linterm_of_linexpr0(
13//         linexpr: *mut elina_linexpr0_t,
14//         f: fn (i: size_t, dim: elina_dim_t, coeff: *mut elina_coeff_t) -> i32,
15//     ) -> i32;
16// }
17
18
19#[repr(u32)]
20#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
21pub enum TexprUnop {
22    Neg = elina_texpr_op_t_ELINA_TEXPR_NEG,
23}
24
25#[repr(u32)]
26#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
27pub enum TexprBinop {
28    Add = elina_texpr_op_t_ELINA_TEXPR_ADD,
29    Sub = elina_texpr_op_t_ELINA_TEXPR_SUB,
30    Mul = elina_texpr_op_t_ELINA_TEXPR_MUL,
31    Div = elina_texpr_op_t_ELINA_TEXPR_DIV,
32    Mod = elina_texpr_op_t_ELINA_TEXPR_MOD,
33}
34
35#[repr(u32)]
36#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
37pub enum ConsTyp {
38    SUPEQ = elina_constyp_t_ELINA_CONS_SUPEQ,
39    SUP = elina_constyp_t_ELINA_CONS_SUP,
40    EQ = elina_constyp_t_ELINA_CONS_EQ,
41    DISEQ = elina_constyp_t_ELINA_CONS_DISEQ,
42    //MODEQ, needs support in Tcons in the form of a proper scalar
43}
44
45impl From<elina_constyp_t> for ConsTyp {
46    fn from(c: elina_constyp_t) -> Self {
47        match c {
48            c if c == elina_constyp_t_ELINA_CONS_SUPEQ => ConsTyp::SUPEQ,
49            c if c == elina_constyp_t_ELINA_CONS_SUP => ConsTyp::SUP,
50            c if c == elina_constyp_t_ELINA_CONS_EQ => ConsTyp::EQ,
51            c if c == elina_constyp_t_ELINA_CONS_DISEQ => ConsTyp::DISEQ,
52            c => panic!("constyp not supported: {}", c),
53        }
54    }
55}
56
57pub fn bool_from_c_bool(b: bool_) -> bool {
58    b == true_
59}
60
61pub fn c_bool_from_bool(b: bool) -> bool_ {
62    if b {
63        true_
64    } else {
65        false_
66    }
67}
68
69#[cfg(test)]
70mod tests {
71    use std::ffi::CString;
72    use crate::{elina_abstract0_approximate, elina_abstract0_fprint, elina_abstract0_meet, elina_abstract0_top, elina_constyp_t_ELINA_CONS_SUPEQ, elina_manager_alloc, elina_tcons0_t, elina_texpr0_cst_scalar_int, elina_texpr0_dim, elina_texpr0_print, false_, opt_pk_manager_alloc, stderr, stdout};
73
74
75
76    #[test]
77    fn manager_alloc() {
78        unsafe {
79            let intdim = 5;
80            let realdim = 0;
81
82
83            let man = opt_pk_manager_alloc(false_);
84
85            let x0 = elina_texpr0_dim(0);
86            let cst_5 = elina_texpr0_cst_scalar_int(5);
87            let top = elina_abstract0_top(man, intdim, realdim);
88
89            // let meet = elina_abstract0_meet(man, false_, top, cons);
90            let names = ["x0", "x1", "x2", "x3", "x4"].map(|s| {
91                let mut cstring = CString::new(s);
92                cstring.unwrap().into_raw()
93            }).as_mut_ptr();
94            let ret = elina_abstract0_fprint(stderr, man, top, names);
95
96
97            // elina_texpr0_print()
98
99        }
100    }
101
102    #[test]
103    fn it_works() {
104        assert_eq!(2 + 2, 4);
105    }
106}