1 /// These are automatically generated C++ bindings for isl.
3 /// isl is a library for computing with integer sets and maps described by
4 /// Presburger formulas. On top of this, isl provides various tools for
5 /// polyhedral compilation, ranging from dependence analysis over scheduling
12 #include <isl/options.h>
19 #include <type_traits>
21 #if __cplusplus >= 201703L
26 /* ISL_USE_EXCEPTIONS should be defined to 1 if exceptions are available.
27 * gcc and clang define __cpp_exceptions; MSVC and xlC define _CPPUNWIND.
28 * Older versions of gcc (e.g., 4.9) only define __EXCEPTIONS.
29 * If exceptions are not available, any error condition will result
32 #ifndef ISL_USE_EXCEPTIONS
33 #if defined(__cpp_exceptions) || defined(_CPPUNWIND) || defined(__EXCEPTIONS)
34 #define ISL_USE_EXCEPTIONS 1
36 #define ISL_USE_EXCEPTIONS 0
45 /* implicit */ ctx(isl_ctx *ctx) : ptr(ctx) {}
54 #if __cplusplus >= 201703L
55 static void free_user(void *user) {
56 std::any *p = static_cast<std::any *>(user);
62 /* Macros hiding try/catch.
63 * If exceptions are not available, then no exceptions will be thrown and
64 * there is nothing to catch.
66 #if ISL_USE_EXCEPTIONS
67 #define ISL_CPP_TRY try
68 #define ISL_CPP_CATCH_ALL catch (...)
70 #define ISL_CPP_TRY if (1)
71 #define ISL_CPP_CATCH_ALL if (0)
74 #if ISL_USE_EXCEPTIONS
76 /* Class capturing isl errors.
78 * The what() return value is stored in a reference counted string
79 * to ensure that the copy constructor and the assignment operator
80 * do not throw any exceptions.
82 class exception : public std::exception {
83 std::shared_ptr<std::string> what_str;
86 inline exception(const char *what_arg, const char *msg,
87 const char *file, int line);
90 exception(const char *what_arg) {
91 what_str = std::make_shared<std::string>(what_arg);
93 static inline void throw_error(enum isl_error error, const char *msg,
94 const char *file, int line);
95 virtual const char *what() const noexcept {
96 return what_str->c_str();
99 /* Default behavior on error conditions that occur inside isl calls
100 * performed from inside the bindings.
101 * In the case exceptions are available, isl should continue
102 * without printing a warning since the warning message
103 * will be included in the exception thrown from inside the bindings.
105 static constexpr auto on_error = ISL_ON_ERROR_CONTINUE;
106 /* Wrapper for throwing an exception with the given message.
108 static void throw_invalid(const char *msg, const char *file, int line) {
109 throw_error(isl_error_invalid, msg, file, line);
111 static inline void throw_last_error(ctx ctx);
114 /* Create an exception of a type described by "what_arg", with
115 * error message "msg" in line "line" of file "file".
117 * Create a string holding the what() return value that
118 * corresponds to what isl would have printed.
119 * If no error message or no error file was set, then use "what_arg" instead.
121 exception::exception(const char *what_arg, const char *msg, const char *file,
125 what_str = std::make_shared<std::string>(what_arg);
127 what_str = std::make_shared<std::string>(std::string(file) +
128 ":" + std::to_string(line) + ": " + msg);
131 class exception_abort : public exception {
133 exception_abort(const char *msg, const char *file, int line) :
134 exception("execution aborted", msg, file, line) {}
137 class exception_alloc : public exception {
139 exception_alloc(const char *msg, const char *file, int line) :
140 exception("memory allocation failure", msg, file, line) {}
143 class exception_unknown : public exception {
145 exception_unknown(const char *msg, const char *file, int line) :
146 exception("unknown failure", msg, file, line) {}
149 class exception_internal : public exception {
151 exception_internal(const char *msg, const char *file, int line) :
152 exception("internal error", msg, file, line) {}
155 class exception_invalid : public exception {
157 exception_invalid(const char *msg, const char *file, int line) :
158 exception("invalid argument", msg, file, line) {}
161 class exception_quota : public exception {
163 exception_quota(const char *msg, const char *file, int line) :
164 exception("quota exceeded", msg, file, line) {}
167 class exception_unsupported : public exception {
169 exception_unsupported(const char *msg, const char *file, int line) :
170 exception("unsupported operation", msg, file, line) {}
173 /* Throw an exception of the class that corresponds to "error", with
174 * error message "msg" in line "line" of file "file".
176 * isl_error_none is treated as an invalid error type.
178 void exception::throw_error(enum isl_error error, const char *msg,
179 const char *file, int line)
184 case isl_error_abort: throw exception_abort(msg, file, line);
185 case isl_error_alloc: throw exception_alloc(msg, file, line);
186 case isl_error_unknown: throw exception_unknown(msg, file, line);
187 case isl_error_internal: throw exception_internal(msg, file, line);
188 case isl_error_invalid: throw exception_invalid(msg, file, line);
189 case isl_error_quota: throw exception_quota(msg, file, line);
190 case isl_error_unsupported:
191 throw exception_unsupported(msg, file, line);
194 throw exception_invalid("invalid error type", file, line);
197 /* Throw an exception corresponding to the last error on "ctx" and
200 * If "ctx" is NULL or if it is not in an error state at the start,
201 * then an invalid argument exception is thrown.
203 void exception::throw_last_error(ctx ctx)
205 enum isl_error error;
206 const char *msg, *file;
209 error = isl_ctx_last_error(ctx.get());
210 msg = isl_ctx_last_error_msg(ctx.get());
211 file = isl_ctx_last_error_file(ctx.get());
212 line = isl_ctx_last_error_line(ctx.get());
213 isl_ctx_reset_error(ctx.get());
215 throw_error(error, msg, file, line);
225 /* Default behavior on error conditions that occur inside isl calls
226 * performed from inside the bindings.
227 * In the case exceptions are not available, isl should abort.
229 static constexpr auto on_error = ISL_ON_ERROR_ABORT;
230 /* Wrapper for throwing an exception with the given message.
231 * In the case exceptions are not available, print an error and abort.
233 static void throw_invalid(const char *msg, const char *file, int line) {
234 fprintf(stderr, "%s:%d: %s\n", file, line, msg);
237 /* Throw an exception corresponding to the last
239 * isl should already abort when an error condition occurs,
240 * so this function should never be called.
242 static void throw_last_error(ctx ctx) {
249 /* Helper class for setting the on_error and resetting the option
250 * to the original value when leaving the scope.
252 class options_scoped_set_on_error {
256 options_scoped_set_on_error(class ctx ctx, int on_error) {
257 this->ctx = ctx.get();
258 saved_on_error = isl_options_get_on_error(this->ctx);
259 isl_options_set_on_error(this->ctx, on_error);
261 ~options_scoped_set_on_error() {
262 isl_options_set_on_error(ctx, saved_on_error);