Better implementation of symbols and constants
[linpy.git] / pypol / islhelper.py
1 import ctypes, ctypes.util
2
3 from . import _islhelper
4 from ._islhelper import isl_basic_set_constraints, isl_set_basic_sets
5
6
7 __all__ = [
8 'libisl',
9 'isl_version',
10 'mainctx',
11 'isl_val_to_int',
12 'isl_basic_set_to_str', 'isl_basic_set_constraints',
13 'isl_set_to_str', 'isl_set_basic_sets',
14 ]
15
16
17 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
18 libisl.isl_dim_set = _islhelper.dim_set
19
20 libisl.isl_version.restype = ctypes.c_char_p
21 isl_version = libisl.isl_version().decode().strip()[len('isl-'):]
22
23
24 mainctx = libisl.isl_ctx_alloc()
25
26
27 libisl.isl_printer_get_str.restype = ctypes.c_char_p
28
29 def isl_val_to_int(islval):
30 islpr = libisl.isl_printer_to_str(mainctx)
31 islpr = libisl.isl_printer_print_val(islpr, islval)
32 string = libisl.isl_printer_get_str(islpr).decode()
33 return int(string)
34
35 def isl_basic_set_to_str(islbset):
36 islpr = libisl.isl_printer_to_str(mainctx)
37 islpr = libisl.isl_printer_print_basic_set(islpr, islbset)
38 string = libisl.isl_printer_get_str(islpr).decode()
39 return string
40
41 def isl_set_to_str(islset):
42 islpr = libisl.isl_printer_to_str(mainctx)
43 islpr = libisl.isl_printer_print_set(islpr, islset)
44 string = libisl.isl_printer_get_str(islpr).decode()
45 return string