|
Packit |
fb9d21 |
/*
|
|
Packit |
fb9d21 |
* Copyright 2008-2009 Katholieke Universiteit Leuven
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* Use of this software is governed by the MIT license
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* Written by Sven Verdoolaege, K.U.Leuven, Departement
|
|
Packit |
fb9d21 |
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
|
|
Packit |
fb9d21 |
*/
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#ifndef ISL_CTX_H
|
|
Packit |
fb9d21 |
#define ISL_CTX_H
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#include <stdio.h>
|
|
Packit |
fb9d21 |
#include <stdlib.h>
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#include <isl/arg.h>
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#ifndef __isl_give
|
|
Packit |
fb9d21 |
#define __isl_give
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_take
|
|
Packit |
fb9d21 |
#define __isl_take
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_keep
|
|
Packit |
fb9d21 |
#define __isl_keep
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_null
|
|
Packit |
fb9d21 |
#define __isl_null
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_export
|
|
Packit |
fb9d21 |
#define __isl_export
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_overload
|
|
Packit |
fb9d21 |
#define __isl_overload
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_constructor
|
|
Packit |
fb9d21 |
#define __isl_constructor
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
#ifndef __isl_subclass
|
|
Packit |
fb9d21 |
#define __isl_subclass(super)
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#if defined(__cplusplus)
|
|
Packit |
fb9d21 |
extern "C" {
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
/* Nearly all isa functions require a struct isl_ctx allocated using
|
|
Packit |
fb9d21 |
* isl_ctx_alloc. This ctx contains (or will contain) options that
|
|
Packit |
fb9d21 |
* control the behavior of the library and some caches.
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* An object allocated within a given ctx should never be used inside
|
|
Packit |
fb9d21 |
* another ctx. Functions for moving objects from one ctx to another
|
|
Packit |
fb9d21 |
* will be added as the need arises.
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* A given context should only be used inside a single thread.
|
|
Packit |
fb9d21 |
* A global context for synchronization between different threads
|
|
Packit |
fb9d21 |
* as well as functions for moving a context to a different thread
|
|
Packit |
fb9d21 |
* will be added as the need arises.
|
|
Packit |
fb9d21 |
*
|
|
Packit |
fb9d21 |
* If anything goes wrong (out of memory, failed assertion), then
|
|
Packit |
fb9d21 |
* the library will currently simply abort. This will be made
|
|
Packit |
fb9d21 |
* configurable in the future.
|
|
Packit |
fb9d21 |
* Users of the library should expect functions that return
|
|
Packit |
fb9d21 |
* a pointer to a structure, to return NULL, indicating failure.
|
|
Packit |
fb9d21 |
* Any function accepting a pointer to a structure will treat
|
|
Packit |
fb9d21 |
* a NULL argument as a failure, resulting in the function freeing
|
|
Packit |
fb9d21 |
* the remaining structures (if any) and returning NULL itself
|
|
Packit |
fb9d21 |
* (in case of pointer return type).
|
|
Packit |
fb9d21 |
* The only exception is the isl_ctx argument, which should never be NULL.
|
|
Packit |
fb9d21 |
*/
|
|
Packit |
fb9d21 |
struct isl_stats {
|
|
Packit |
fb9d21 |
long gbr_solved_lps;
|
|
Packit |
fb9d21 |
};
|
|
Packit |
fb9d21 |
enum isl_error {
|
|
Packit |
fb9d21 |
isl_error_none = 0,
|
|
Packit |
fb9d21 |
isl_error_abort,
|
|
Packit |
fb9d21 |
isl_error_alloc,
|
|
Packit |
fb9d21 |
isl_error_unknown,
|
|
Packit |
fb9d21 |
isl_error_internal,
|
|
Packit |
fb9d21 |
isl_error_invalid,
|
|
Packit |
fb9d21 |
isl_error_quota,
|
|
Packit |
fb9d21 |
isl_error_unsupported
|
|
Packit |
fb9d21 |
};
|
|
Packit |
fb9d21 |
typedef enum {
|
|
Packit |
fb9d21 |
isl_stat_error = -1,
|
|
Packit |
fb9d21 |
isl_stat_ok = 0
|
|
Packit |
fb9d21 |
} isl_stat;
|
|
Packit |
fb9d21 |
typedef enum {
|
|
Packit |
fb9d21 |
isl_bool_error = -1,
|
|
Packit |
fb9d21 |
isl_bool_false = 0,
|
|
Packit |
fb9d21 |
isl_bool_true = 1
|
|
Packit |
fb9d21 |
} isl_bool;
|
|
Packit |
fb9d21 |
struct isl_ctx;
|
|
Packit |
fb9d21 |
typedef struct isl_ctx isl_ctx;
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
/* Some helper macros */
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
|
|
Packit |
fb9d21 |
#define ISL_DEPRECATED __attribute__((__deprecated__))
|
|
Packit |
fb9d21 |
#else
|
|
Packit |
fb9d21 |
#define ISL_DEPRECATED
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
|
|
Packit |
fb9d21 |
#define ISL_FL_SET(l, f) ((l) |= (f))
|
|
Packit |
fb9d21 |
#define ISL_FL_CLR(l, f) ((l) &= ~(f))
|
|
Packit |
fb9d21 |
#define ISL_FL_ISSET(l, f) (!!((l) & (f)))
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
|
|
Packit |
fb9d21 |
#define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
|
|
Packit |
fb9d21 |
#define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
|
|
Packit |
fb9d21 |
#define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
void *isl_malloc_or_die(isl_ctx *ctx, size_t size);
|
|
Packit |
fb9d21 |
void *isl_calloc_or_die(isl_ctx *ctx, size_t nmemb, size_t size);
|
|
Packit |
fb9d21 |
void *isl_realloc_or_die(isl_ctx *ctx, void *ptr, size_t size);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_alloc(ctx,type,size) ((type *)isl_malloc_or_die(ctx, size))
|
|
Packit |
fb9d21 |
#define isl_calloc(ctx,type,size) ((type *)isl_calloc_or_die(ctx,\
|
|
Packit |
fb9d21 |
1, size))
|
|
Packit |
fb9d21 |
#define isl_realloc(ctx,ptr,type,size) ((type *)isl_realloc_or_die(ctx,\
|
|
Packit |
fb9d21 |
ptr, size))
|
|
Packit |
fb9d21 |
#define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
|
|
Packit |
fb9d21 |
#define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
|
|
Packit |
fb9d21 |
#define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
|
|
Packit |
fb9d21 |
#define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
|
|
Packit |
fb9d21 |
#define isl_calloc_array(ctx,type,n) ((type *)isl_calloc_or_die(ctx,\
|
|
Packit |
fb9d21 |
n, sizeof(type)))
|
|
Packit |
fb9d21 |
#define isl_realloc_array(ctx,ptr,type,n) \
|
|
Packit |
fb9d21 |
isl_realloc(ctx,ptr,type,(n)*sizeof(type))
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_die(ctx,errno,msg,code) \
|
|
Packit |
fb9d21 |
do { \
|
|
Packit |
fb9d21 |
isl_handle_error(ctx, errno, msg, __FILE__, __LINE__); \
|
|
Packit |
fb9d21 |
code; \
|
|
Packit |
fb9d21 |
} while (0)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
void isl_handle_error(isl_ctx *ctx, enum isl_error error, const char *msg,
|
|
Packit |
fb9d21 |
const char *file, int line);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_assert4(ctx,test,code,errno) \
|
|
Packit |
fb9d21 |
do { \
|
|
Packit |
fb9d21 |
if (test) \
|
|
Packit |
fb9d21 |
break; \
|
|
Packit |
fb9d21 |
isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
|
|
Packit |
fb9d21 |
} while (0)
|
|
Packit |
fb9d21 |
#define isl_assert(ctx,test,code) \
|
|
Packit |
fb9d21 |
isl_assert4(ctx,test,code,isl_error_unknown)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define isl_min(a,b) ((a < b) ? (a) : (b))
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
/* struct isl_ctx functions */
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
struct isl_options *isl_ctx_options(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args,
|
|
Packit |
fb9d21 |
__isl_take void *opt);
|
|
Packit |
fb9d21 |
isl_ctx *isl_ctx_alloc(void);
|
|
Packit |
fb9d21 |
void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
|
|
Packit |
fb9d21 |
int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
|
|
Packit |
fb9d21 |
void isl_ctx_ref(struct isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_deref(struct isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_free(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
void isl_ctx_abort(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_resume(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
int isl_ctx_aborted(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
void isl_ctx_set_max_operations(isl_ctx *ctx, unsigned long max_operations);
|
|
Packit |
fb9d21 |
unsigned long isl_ctx_get_max_operations(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_reset_operations(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_ARG_CTX_DECL(prefix,st,args) \
|
|
Packit |
fb9d21 |
st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_ARG_CTX_DEF(prefix,st,args) \
|
|
Packit |
fb9d21 |
st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
|
|
Packit |
fb9d21 |
{ \
|
|
Packit |
fb9d21 |
return (st *)isl_ctx_peek_options(ctx, &(args)); \
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_GET_INT_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
int prefix ## _get_ ## field(isl_ctx *ctx) \
|
|
Packit |
fb9d21 |
{ \
|
|
Packit |
fb9d21 |
st *options; \
|
|
Packit |
fb9d21 |
options = isl_ctx_peek_ ## prefix(ctx); \
|
|
Packit |
fb9d21 |
if (!options) \
|
|
Packit |
fb9d21 |
isl_die(ctx, isl_error_invalid, \
|
|
Packit |
fb9d21 |
"isl_ctx does not reference " #prefix, \
|
|
Packit |
fb9d21 |
return -1); \
|
|
Packit |
fb9d21 |
return options->field; \
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_SET_INT_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
isl_stat prefix ## _set_ ## field(isl_ctx *ctx, int val) \
|
|
Packit |
fb9d21 |
{ \
|
|
Packit |
fb9d21 |
st *options; \
|
|
Packit |
fb9d21 |
options = isl_ctx_peek_ ## prefix(ctx); \
|
|
Packit |
fb9d21 |
if (!options) \
|
|
Packit |
fb9d21 |
isl_die(ctx, isl_error_invalid, \
|
|
Packit |
fb9d21 |
"isl_ctx does not reference " #prefix, \
|
|
Packit |
fb9d21 |
return isl_stat_error); \
|
|
Packit |
fb9d21 |
options->field = val; \
|
|
Packit |
fb9d21 |
return isl_stat_ok; \
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_GET_STR_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
const char *prefix ## _get_ ## field(isl_ctx *ctx) \
|
|
Packit |
fb9d21 |
{ \
|
|
Packit |
fb9d21 |
st *options; \
|
|
Packit |
fb9d21 |
options = isl_ctx_peek_ ## prefix(ctx); \
|
|
Packit |
fb9d21 |
if (!options) \
|
|
Packit |
fb9d21 |
isl_die(ctx, isl_error_invalid, \
|
|
Packit |
fb9d21 |
"isl_ctx does not reference " #prefix, \
|
|
Packit |
fb9d21 |
return NULL); \
|
|
Packit |
fb9d21 |
return options->field; \
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_SET_STR_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
isl_stat prefix ## _set_ ## field(isl_ctx *ctx, const char *val) \
|
|
Packit |
fb9d21 |
{ \
|
|
Packit |
fb9d21 |
st *options; \
|
|
Packit |
fb9d21 |
options = isl_ctx_peek_ ## prefix(ctx); \
|
|
Packit |
fb9d21 |
if (!options) \
|
|
Packit |
fb9d21 |
isl_die(ctx, isl_error_invalid, \
|
|
Packit |
fb9d21 |
"isl_ctx does not reference " #prefix, \
|
|
Packit |
fb9d21 |
return isl_stat_error); \
|
|
Packit |
fb9d21 |
if (!val) \
|
|
Packit |
fb9d21 |
return isl_stat_error; \
|
|
Packit |
fb9d21 |
free(options->field); \
|
|
Packit |
fb9d21 |
options->field = strdup(val); \
|
|
Packit |
fb9d21 |
if (!options->field) \
|
|
Packit |
fb9d21 |
return isl_stat_error; \
|
|
Packit |
fb9d21 |
return isl_stat_ok; \
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_GET_BOOL_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
ISL_CTX_GET_INT_DEF(prefix,st,args,field)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_SET_BOOL_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
ISL_CTX_SET_INT_DEF(prefix,st,args,field)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_GET_CHOICE_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
ISL_CTX_GET_INT_DEF(prefix,st,args,field)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#define ISL_CTX_SET_CHOICE_DEF(prefix,st,args,field) \
|
|
Packit |
fb9d21 |
ISL_CTX_SET_INT_DEF(prefix,st,args,field)
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
enum isl_error isl_ctx_last_error(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_reset_error(isl_ctx *ctx);
|
|
Packit |
fb9d21 |
void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#if defined(__cplusplus)
|
|
Packit |
fb9d21 |
}
|
|
Packit |
fb9d21 |
#endif
|
|
Packit |
fb9d21 |
|
|
Packit |
fb9d21 |
#endif
|