int continue_on_error;
};
-struct isl_arg bound_options_arg[] = {
-ISL_ARG_CHILD(struct bound_options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARGS_START(struct bound_options, bound_options_args)
+ISL_ARG_CHILD(struct bound_options, isl, "isl", &isl_options_args,
+ "isl options")
ISL_ARG_BOOL(struct bound_options, verify, 'T', "verify", 0, NULL)
ISL_ARG_BOOL(struct bound_options, print_all, 'A', "print-all", 0, NULL)
ISL_ARG_BOOL(struct bound_options, continue_on_error, '\0', "continue-on-error", 0, NULL)
-ISL_ARG_END
-};
+ISL_ARGS_END
-ISL_ARG_DEF(bound_options, struct bound_options, bound_options_arg)
+ISL_ARG_DEF(bound_options, struct bound_options, bound_options_args)
static __isl_give isl_set *set_bounds(__isl_take isl_set *set)
{
assert(options);
argc = bound_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(bound_options_arg, options);
+ ctx = isl_ctx_alloc_with_options(&bound_options_args, options);
s = isl_stream_new_file(ctx, stdin);
obj = isl_stream_read_obj(s);
unsigned format;
};
-struct isl_arg cat_options_arg[] = {
-ISL_ARG_CHILD(struct cat_options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARGS_START(struct cat_options, cat_options_args)
+ISL_ARG_CHILD(struct cat_options, isl, "isl", &isl_options_args, "isl options")
ISL_ARG_CHOICE(struct cat_options, format, 0, "format", \
cat_format, ISL_FORMAT_ISL, "output format")
-ISL_ARG_END
-};
+ISL_ARGS_END
-ISL_ARG_DEF(cat_options, struct cat_options, cat_options_arg)
+ISL_ARG_DEF(cat_options, struct cat_options, cat_options_args)
int main(int argc, char **argv)
{
assert(options);
argc = cat_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(cat_options_arg, options);
+ ctx = isl_ctx_alloc_with_options(&cat_options_args, options);
s = isl_stream_new_file(ctx, stdin);
obj = isl_stream_read_obj(s);
assert(options);
argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(isl_options_arg, options);
+ ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
map = isl_map_read_from_file(ctx, stdin);
map = isl_map_transitive_closure(map, &exact);
isl_arg_version
};
+struct isl_args;
+
struct isl_arg {
enum isl_arg_type type;
char short_name;
const char *default_value;
} str;
struct {
- struct isl_arg *child;
- size_t size;
+ struct isl_args *child;
} child;
struct {
void (*print_version)(void);
} u;
};
+struct isl_args {
+ size_t options_size;
+ struct isl_arg *args;
+};
+
+#define ISL_ARGS_START(s,name) \
+ struct isl_arg name ## LIST[]; \
+ struct isl_args name = { sizeof(s), name ## LIST }; \
+ struct isl_arg name ## LIST[] = {
+#define ISL_ARGS_END \
+ { isl_arg_end } };
+
#define ISL_ARG_ALIAS(l) { \
.type = isl_arg_alias, \
.long_name = l, \
},
#define ISL_ARG_STR(st,f,s,l,a,d,h) \
ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
-#define _ISL_ARG_CHILD(o,sz,l,c,h,fl) { \
+#define _ISL_ARG_CHILD(o,l,c,h,fl) { \
.type = isl_arg_child, \
.long_name = l, \
.offset = o, \
.help_msg = h, \
.flags = fl, \
- .u = { .child = { .child = c, .size = sz } } \
+ .u = { .child = { .child = c } } \
},
#define ISL_ARG_CHILD(st,f,l,c,h) \
- _ISL_ARG_CHILD(offsetof(st, f),sizeof(*((st *)NULL)->f),l,c,h,0)
+ _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0)
#define ISL_ARG_GROUP_F(c,h,fl) \
- _ISL_ARG_CHILD(-1,0,NULL,c,h,fl)
+ _ISL_ARG_CHILD(-1,NULL,c,h,fl)
#define ISL_ARG_GROUP(c,h) \
ISL_ARG_GROUP_F(c,h,0)
#define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
.type = isl_arg_version, \
.u = { .version = { .print_version = print } } \
},
-#define ISL_ARG_END { isl_arg_end }
#define ISL_ARG_ALL (1 << 0)
-void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
-void isl_arg_free(struct isl_arg *arg, void *opt);
-int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
+void isl_args_set_defaults(struct isl_args *args, void *opt);
+void isl_args_free(struct isl_args *args, void *opt);
+int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
unsigned flags);
-#define ISL_ARG_DECL(prefix,st,arg) \
-extern struct isl_arg arg[]; \
+#define ISL_ARG_DECL(prefix,st,args) \
+extern struct isl_args args; \
st *prefix ## _new_with_defaults(void); \
void prefix ## _free(st *opt); \
int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
-#define ISL_ARG_DEF(prefix,st,arg) \
+#define ISL_ARG_DEF(prefix,st,args) \
st *prefix ## _new_with_defaults() \
{ \
st *opt = (st *)calloc(1, sizeof(st)); \
if (opt) \
- isl_arg_set_defaults(arg, opt); \
+ isl_args_set_defaults(&(args), opt); \
return opt; \
} \
\
void prefix ## _free(st *opt) \
{ \
- isl_arg_free(arg, opt); \
+ isl_args_free(&(args), opt); \
} \
\
int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
{ \
- return isl_arg_parse(arg, argc, argv, opt, flags); \
+ return isl_args_parse(&(args), argc, argv, opt, flags); \
}
#if defined(__cplusplus)
struct isl_options *isl_ctx_options(isl_ctx *ctx);
-isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt);
+isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args,
+ __isl_take void *opt);
isl_ctx *isl_ctx_alloc(void);
-void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg);
+void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args);
int isl_ctx_parse_options(isl_ctx *ctx, int argc, char **argv, unsigned flags);
void isl_ctx_ref(struct isl_ctx *ctx);
void isl_ctx_deref(struct isl_ctx *ctx);
void isl_ctx_resume(isl_ctx *ctx);
int isl_ctx_aborted(isl_ctx *ctx);
-#define ISL_ARG_CTX_DECL(prefix,st,arg) \
+#define ISL_ARG_CTX_DECL(prefix,st,args) \
st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
-#define ISL_ARG_CTX_DEF(prefix,st,arg) \
+#define ISL_ARG_CTX_DEF(prefix,st,args) \
st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
{ \
- return (st *)isl_ctx_peek_options(ctx, arg); \
+ return (st *)isl_ctx_peek_options(ctx, &(args)); \
}
enum isl_error isl_ctx_last_error(isl_ctx *ctx);
int schedule_split_parallel;
};
-ISL_ARG_DECL(isl_options, struct isl_options, isl_options_arg)
-
-extern struct isl_arg isl_options_arg[];
+ISL_ARG_DECL(isl_options, struct isl_options, isl_options_args)
#if defined(__cplusplus)
}
static struct isl_arg help_arg[] = {
ISL_ARG_PHANTOM_BOOL('h', "help", NULL, "print this help, then exit")
-ISL_ARG_END
};
static void set_default_choice(struct isl_arg *arg, void *opt)
if (arg->offset == (size_t) -1)
child = opt;
else {
- child = calloc(1, arg->u.child.size);
+ child = calloc(1, arg->u.child.child->options_size);
*(void **)(((char *)opt) + arg->offset) = child;
}
if (child)
- isl_arg_set_defaults(arg->u.child.child, child);
+ isl_args_set_defaults(arg->u.child.child, child);
}
static void set_default_user(struct isl_arg *arg, void *opt)
*(const char **)(((char *)opt) + arg->offset) = str;
}
-void isl_arg_set_defaults(struct isl_arg *arg, void *opt)
+void isl_args_set_defaults(struct isl_args *args, void *opt)
{
int i;
- for (i = 0; arg[i].type != isl_arg_end; ++i) {
- switch (arg[i].type) {
+ for (i = 0; args->args[i].type != isl_arg_end; ++i) {
+ switch (args->args[i].type) {
case isl_arg_choice:
- set_default_choice(&arg[i], opt);
+ set_default_choice(&args->args[i], opt);
break;
case isl_arg_flags:
- set_default_flags(&arg[i], opt);
+ set_default_flags(&args->args[i], opt);
break;
case isl_arg_bool:
- set_default_bool(&arg[i], opt);
+ set_default_bool(&args->args[i], opt);
break;
case isl_arg_child:
- set_default_child(&arg[i], opt);
+ set_default_child(&args->args[i], opt);
break;
case isl_arg_user:
- set_default_user(&arg[i], opt);
+ set_default_user(&args->args[i], opt);
break;
case isl_arg_int:
- set_default_int(&arg[i], opt);
+ set_default_int(&args->args[i], opt);
break;
case isl_arg_long:
- set_default_long(&arg[i], opt);
+ set_default_long(&args->args[i], opt);
break;
case isl_arg_ulong:
- set_default_ulong(&arg[i], opt);
+ set_default_ulong(&args->args[i], opt);
break;
case isl_arg_arg:
case isl_arg_str:
- set_default_str(&arg[i], opt);
+ set_default_str(&args->args[i], opt);
break;
case isl_arg_alias:
case isl_arg_footer:
switch (arg[i].type) {
case isl_arg_child:
if (arg[i].offset == (size_t) -1)
- free_args(arg[i].u.child.child, opt);
+ free_args(arg[i].u.child.child->args, opt);
else
- isl_arg_free(arg[i].u.child.child,
+ isl_args_free(arg[i].u.child.child,
*(void **)(((char *)opt) + arg[i].offset));
break;
case isl_arg_arg:
}
}
-void isl_arg_free(struct isl_arg *arg, void *opt)
+void isl_args_free(struct isl_args *args, void *opt)
{
if (!opt)
return;
- free_args(arg, opt);
+ free_args(args->args, opt);
free(opt);
}
child = opt;
else
child = *(void **)(((char *) opt) + arg[i].offset);
- print_help(arg[i].u.child.child, arg[i].long_name, child);
+ print_help(arg[i].u.child.child->args, arg[i].long_name, child);
any = 1;
}
}
case isl_arg_version:
return 1;
case isl_arg_child:
- if (any_version(decl[i].u.child.child))
+ if (any_version(decl[i].u.child.child->args))
return 1;
break;
default:
child = *(void **)(((char *)opt) + decl->offset);
prefix = decl->long_name;
}
- return parse_option(decl->u.child.child, arg, prefix, child);
+ return parse_option(decl->u.child.child->args, arg, prefix, child);
}
static int parse_option(struct isl_arg *decl, char **arg,
decl[i].u.version.print_version();
break;
case isl_arg_child:
- print_version(decl[i].u.child.child);
+ print_version(decl[i].u.child.child->args);
break;
default:
break;
return -1;
}
-int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
+int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
unsigned flags)
{
int a = -1;
int i;
int n;
- n = n_arg(arg);
+ n = n_arg(args->args);
for (i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--help") == 0)
- print_help_and_exit(arg, argv[0], opt);
+ print_help_and_exit(args->args, argv[0], opt);
}
for (i = 1; i < argc; ++i) {
if ((strcmp(argv[i], "--version") == 0 ||
- strcmp(argv[i], "-V") == 0) && any_version(arg))
- print_version_and_exit(arg);
+ strcmp(argv[i], "-V") == 0) && any_version(args->args))
+ print_version_and_exit(args->args);
}
while (argc > 1 + skip) {
int parsed;
if (argv[1 + skip][0] != '-') {
- a = next_arg(arg, a);
+ a = next_arg(args->args, a);
if (a >= 0) {
char **p;
- p = (char **)(((char *)opt)+arg[a].offset);
+ p = (char **)(((char *)opt)+args->args[a].offset);
free(*p);
*p = strdup(argv[1 + skip]);
argc = drop_argument(argc, argv, 1 + skip, 1);
++skip;
continue;
}
- parsed = parse_option(arg, &argv[1 + skip], NULL, opt);
+ parsed = parse_option(args->args, &argv[1 + skip], NULL, opt);
if (parsed)
argc = drop_argument(argc, argv, 1 + skip, parsed);
else if (ISL_FL_ISSET(flags, ISL_ARG_ALL)) {
#include <isl_ctx_private.h>
#include <isl/vec.h>
-static struct isl_options *find_nested_options(struct isl_arg *arg,
- void *opt, struct isl_arg *wanted)
+static struct isl_options *find_nested_options(struct isl_args *args,
+ void *opt, struct isl_args *wanted)
{
int i;
struct isl_options *options;
- if (arg == wanted)
+ if (args == wanted)
return opt;
- for (i = 0; arg[i].type != isl_arg_end; ++i) {
- if (arg[i].type != isl_arg_child)
+ for (i = 0; args->args[i].type != isl_arg_end; ++i) {
+ if (args->args[i].type != isl_arg_child)
continue;
- options = find_nested_options(arg[i].u.child.child,
- *(void **)(((char *)opt) + arg->offset), wanted);
+ options = find_nested_options(args->args[i].u.child.child,
+ *(void **)(((char *)opt) + args->args[i].offset),
+ wanted);
if (options)
return options;
}
return NULL;
}
-static struct isl_options *find_nested_isl_options(struct isl_arg *arg,
+static struct isl_options *find_nested_isl_options(struct isl_args *args,
void *opt)
{
- return find_nested_options(arg, opt, isl_options_arg);
+ return find_nested_options(args, opt, &isl_options_args);
}
-void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg)
+void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_args *args)
{
if (!ctx)
return NULL;
- return find_nested_options(ctx->user_arg, ctx->user_opt, arg);
+ return find_nested_options(ctx->user_args, ctx->user_opt, args);
}
-isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, void *user_opt)
+isl_ctx *isl_ctx_alloc_with_options(struct isl_args *args, void *user_opt)
{
struct isl_ctx *ctx = NULL;
struct isl_options *opt = NULL;
if (!user_opt)
return NULL;
- opt = find_nested_isl_options(arg, user_opt);
+ opt = find_nested_isl_options(args, user_opt);
if (!opt) {
opt = isl_options_new_with_defaults();
if (!opt)
if (!ctx->stats)
goto error;
- ctx->user_arg = arg;
+ ctx->user_args = args;
ctx->user_opt = user_opt;
ctx->opt_allocated = opt_allocated;
ctx->opt = opt;
return ctx;
error:
- isl_arg_free(arg, user_opt);
+ isl_args_free(args, user_opt);
if (opt_allocated)
isl_options_free(opt);
free(ctx);
opt = isl_options_new_with_defaults();
- return isl_ctx_alloc_with_options(isl_options_arg, opt);
+ return isl_ctx_alloc_with_options(&isl_options_args, opt);
}
void isl_ctx_ref(struct isl_ctx *ctx)
isl_int_clear(ctx->two);
isl_int_clear(ctx->negone);
isl_int_clear(ctx->normalize_gcd);
- isl_arg_free(ctx->user_arg, ctx->user_opt);
+ isl_args_free(ctx->user_args, ctx->user_opt);
if (ctx->opt_allocated)
free(ctx->opt);
free(ctx->stats);
{
if (!ctx)
return -1;
- return isl_arg_parse(ctx->user_arg, argc, argv, ctx->user_opt, flags);
+ return isl_args_parse(ctx->user_args, argc, argv, ctx->user_opt, flags);
}
int opt_allocated;
struct isl_options *opt;
void *user_opt;
- struct isl_arg *user_arg;
+ struct isl_args *user_args;
isl_int zero;
isl_int one;
printf("%s", isl_version());
}
-struct isl_arg isl_options_arg[] = {
+ISL_ARGS_START(struct isl_options, isl_options_args)
ISL_ARG_CHOICE(struct isl_options, lp_solver, 0, "lp-solver", \
isl_lp_solver_choice, ISL_LP_TAB, "lp solver to use")
ISL_ARG_CHOICE(struct isl_options, ilp_solver, 0, "ilp-solver", \
"schedule-split-parallel", 1,
"split non-tilable bands with parallel schedules")
ISL_ARG_VERSION(print_version)
-ISL_ARG_END
-};
+ISL_ARGS_END
-ISL_ARG_DEF(isl_options, struct isl_options, isl_options_arg)
+ISL_ARG_DEF(isl_options, struct isl_options, isl_options_args)
{0}
};
-struct isl_arg options_arg[] = {
-ISL_ARG_CHILD(struct options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARGS_START(struct options, options_args)
+ISL_ARG_CHILD(struct options, isl, "isl", &isl_options_args, "isl options")
ISL_ARG_BOOL(struct options, verify, 'T', "verify", 0, NULL)
ISL_ARG_CHOICE(struct options, format, 0, "format",
pip_format, FORMAT_SET, "output format")
-ISL_ARG_END
-};
+ISL_ARGS_END
-ISL_ARG_DEF(options, struct options, options_arg)
+ISL_ARG_DEF(options, struct options, options_args)
static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset)
{
assert(options);
argc = options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options_arg, options);
+ ctx = isl_ctx_alloc_with_options(&options_args, options);
context = isl_basic_set_read_from_file(ctx, stdin);
assert(context);