7 #include <isl/stream.h>
8 #include <isl/vertices.h>
10 #include <isl_obj_list.h>
11 #include <isl_obj_str.h>
12 #include <barvinok/isl.h>
13 #include <barvinok/options.h>
20 static isl_ctx
*main_ctx
;
22 static void handler(int signum
)
24 if (isl_ctx_aborted(main_ctx
))
26 isl_ctx_abort(main_ctx
);
29 static struct sigaction sa_old
;
31 static void install_signal_handler(isl_ctx
*ctx
)
37 memset(&sa
, 0, sizeof(struct sigaction
));
38 sa
.sa_handler
= &handler
;
39 sa
.sa_flags
= SA_RESTART
;
40 sigaction(SIGINT
, &sa
, &sa_old
);
43 static void remove_signal_handler(isl_ctx
*ctx
)
45 sigaction(SIGINT
, &sa_old
, NULL
);
50 static void install_signal_handler(isl_ctx
*ctx
)
54 static void remove_signal_handler(isl_ctx
*ctx
)
61 #include <cloog/isl/cloog.h>
64 static int isl_bool_false
= 0;
65 static int isl_bool_true
= 1;
66 static int isl_bool_error
= -1;
68 enum iscc_op
{ ISCC_READ
, ISCC_WRITE
, ISCC_SOURCE
, ISCC_VERTICES
,
69 ISCC_LAST
, ISCC_ANY
, ISCC_BEFORE
, ISCC_UNDER
,
70 ISCC_TYPEOF
, ISCC_PRINT
,
72 static const char *op_name
[ISCC_N_OP
] = {
74 [ISCC_WRITE
] = "write",
75 [ISCC_PRINT
] = "print",
76 [ISCC_SOURCE
] = "source",
77 [ISCC_VERTICES
] = "vertices",
80 [ISCC_BEFORE
] = "before",
81 [ISCC_UNDER
] = "under",
82 [ISCC_TYPEOF
] = "typeof"
84 static enum isl_token_type iscc_op
[ISCC_N_OP
];
86 struct isl_arg_choice iscc_format
[] = {
87 {"isl", ISL_FORMAT_ISL
},
88 {"omega", ISL_FORMAT_OMEGA
},
89 {"polylib", ISL_FORMAT_POLYLIB
},
90 {"ext-polylib", ISL_FORMAT_EXT_POLYLIB
},
91 {"latex", ISL_FORMAT_LATEX
},
97 struct barvinok_options
*barvinok
;
102 struct isl_arg iscc_options_arg
[] = {
103 ISL_ARG_CHILD(struct iscc_options
, barvinok
, "barvinok", barvinok_options_arg
,
105 ISL_ARG_CHOICE(struct iscc_options
, format
, 0, "format", \
106 iscc_format
, ISL_FORMAT_ISL
, "output format")
107 ISL_ARG_BOOL(struct iscc_options
, io
, 0, "io", 1,
108 "allow read and write operations")
112 ISL_ARG_DEF(iscc_options
, struct iscc_options
, iscc_options_arg
)
113 ISL_ARG_CTX_DEF(iscc_options
, struct iscc_options
, iscc_options_arg
)
115 static void *isl_obj_bool_copy(void *v
)
120 static void isl_obj_bool_free(void *v
)
124 static __isl_give isl_printer
*isl_obj_bool_print(__isl_take isl_printer
*p
,
127 if (v
== &isl_bool_true
)
128 return isl_printer_print_str(p
, "True");
129 else if (v
== &isl_bool_false
)
130 return isl_printer_print_str(p
, "False");
132 return isl_printer_print_str(p
, "Error");
135 static void *isl_obj_bool_add(void *v1
, void *v2
)
140 struct isl_obj_vtable isl_obj_bool_vtable
= {
146 #define isl_obj_bool (&isl_obj_bool_vtable)
148 int *isl_bool_from_int(int res
)
150 return res
< 0 ? &isl_bool_error
: res
? &isl_bool_true
: &isl_bool_false
;
153 int *union_map_is_equal(__isl_take isl_union_map
*map1
,
154 __isl_take isl_union_map
*map2
)
156 int res
= isl_union_map_is_equal(map1
, map2
);
157 isl_union_map_free(map1
);
158 isl_union_map_free(map2
);
159 return isl_bool_from_int(res
);
161 int *union_set_is_equal(__isl_take isl_union_set
*set1
,
162 __isl_take isl_union_set
*set2
)
164 return union_map_is_equal((isl_union_map
*)set1
, (isl_union_map
*)set2
);
167 int *union_map_is_subset(__isl_take isl_union_map
*map1
,
168 __isl_take isl_union_map
*map2
)
170 int res
= isl_union_map_is_subset(map1
, map2
);
171 isl_union_map_free(map1
);
172 isl_union_map_free(map2
);
173 return isl_bool_from_int(res
);
175 int *union_set_is_subset(__isl_take isl_union_set
*set1
,
176 __isl_take isl_union_set
*set2
)
178 return union_map_is_subset((isl_union_map
*)set1
, (isl_union_map
*)set2
);
181 int *union_map_is_strict_subset(__isl_take isl_union_map
*map1
,
182 __isl_take isl_union_map
*map2
)
184 int res
= isl_union_map_is_strict_subset(map1
, map2
);
185 isl_union_map_free(map1
);
186 isl_union_map_free(map2
);
187 return isl_bool_from_int(res
);
189 int *union_set_is_strict_subset(__isl_take isl_union_set
*set1
,
190 __isl_take isl_union_set
*set2
)
192 return union_map_is_strict_subset((isl_union_map
*)set1
,
193 (isl_union_map
*)set2
);
196 int *union_map_is_superset(__isl_take isl_union_map
*map1
,
197 __isl_take isl_union_map
*map2
)
199 return union_map_is_subset(map2
, map1
);
201 int *union_set_is_superset(__isl_take isl_union_set
*set1
,
202 __isl_take isl_union_set
*set2
)
204 return union_set_is_subset(set2
, set1
);
207 int *union_map_is_strict_superset(__isl_take isl_union_map
*map1
,
208 __isl_take isl_union_map
*map2
)
210 return union_map_is_strict_subset(map2
, map1
);
212 int *union_set_is_strict_superset(__isl_take isl_union_set
*set1
,
213 __isl_take isl_union_set
*set2
)
215 return union_set_is_strict_subset(set2
, set1
);
218 extern struct isl_obj_vtable isl_obj_list_vtable
;
219 #define isl_obj_list (&isl_obj_list_vtable)
221 typedef void *(*isc_bin_op_fn
)(void *lhs
, void *rhs
);
223 enum isl_token_type op
;
229 struct isc_named_bin_op
{
231 struct isc_bin_op op
;
235 isl_union_pw_qpolynomial
*upwqp
;
236 isl_union_pw_qpolynomial
*res
;
239 static int eval_at(__isl_take isl_point
*pnt
, void *user
)
241 struct iscc_at
*at
= (struct iscc_at
*) user
;
245 set
= isl_set_from_point(isl_point_copy(pnt
));
246 qp
= isl_union_pw_qpolynomial_eval(
247 isl_union_pw_qpolynomial_copy(at
->upwqp
), pnt
);
249 at
->res
= isl_union_pw_qpolynomial_add(at
->res
,
250 isl_union_pw_qpolynomial_from_pw_qpolynomial(
251 isl_pw_qpolynomial_alloc(set
, qp
)));
256 __isl_give isl_union_pw_qpolynomial
*isl_union_pw_qpolynomial_at(
257 __isl_take isl_union_pw_qpolynomial
*upwqp
,
258 __isl_take isl_union_set
*uset
)
263 at
.res
= isl_union_pw_qpolynomial_zero(isl_union_set_get_dim(uset
));
265 isl_union_set_foreach_point(uset
, eval_at
, &at
);
267 isl_union_pw_qpolynomial_free(upwqp
);
268 isl_union_set_free(uset
);
273 struct iscc_fold_at
{
274 isl_union_pw_qpolynomial_fold
*upwf
;
275 isl_union_pw_qpolynomial
*res
;
278 static int eval_fold_at(__isl_take isl_point
*pnt
, void *user
)
280 struct iscc_fold_at
*at
= (struct iscc_fold_at
*) user
;
284 set
= isl_set_from_point(isl_point_copy(pnt
));
285 qp
= isl_union_pw_qpolynomial_fold_eval(
286 isl_union_pw_qpolynomial_fold_copy(at
->upwf
), pnt
);
288 at
->res
= isl_union_pw_qpolynomial_add(at
->res
,
289 isl_union_pw_qpolynomial_from_pw_qpolynomial(
290 isl_pw_qpolynomial_alloc(set
, qp
)));
295 __isl_give isl_union_pw_qpolynomial
*isl_union_pw_qpolynomial_fold_at(
296 __isl_take isl_union_pw_qpolynomial_fold
*upwf
,
297 __isl_take isl_union_set
*uset
)
299 struct iscc_fold_at at
;
302 at
.res
= isl_union_pw_qpolynomial_zero(isl_union_set_get_dim(uset
));
304 isl_union_set_foreach_point(uset
, eval_fold_at
, &at
);
306 isl_union_pw_qpolynomial_fold_free(upwf
);
307 isl_union_set_free(uset
);
312 static __isl_give isl_union_pw_qpolynomial_fold
*union_pw_qpolynomial_add_union_pw_qpolynomial_fold(
313 __isl_take isl_union_pw_qpolynomial
*upwqp
,
314 __isl_take isl_union_pw_qpolynomial_fold
*upwf
)
316 return isl_union_pw_qpolynomial_fold_add_union_pw_qpolynomial(upwf
,
320 static __isl_give
struct isl_list
*union_map_apply_union_pw_qpolynomial_fold(
321 __isl_take isl_union_map
*umap
,
322 __isl_take isl_union_pw_qpolynomial_fold
*upwf
)
325 struct isl_list
*list
;
328 ctx
= isl_union_map_get_ctx(umap
);
329 list
= isl_list_alloc(ctx
, 2);
333 list
->obj
[0].type
= isl_obj_union_pw_qpolynomial_fold
;
334 list
->obj
[0].v
= isl_union_map_apply_union_pw_qpolynomial_fold(umap
,
336 list
->obj
[1].type
= isl_obj_bool
;
337 list
->obj
[1].v
= tight
? &isl_bool_true
: &isl_bool_false
;
338 if (tight
< 0 || !list
->obj
[0].v
)
343 isl_union_map_free(umap
);
344 isl_union_pw_qpolynomial_fold_free(upwf
);
350 static __isl_give isl_union_pw_qpolynomial
*union_pw_qpolynomial_int_mul(
351 __isl_take isl_union_pw_qpolynomial
*upwqp
, __isl_take isl_int_obj
*i
)
359 isl_int_obj_get_int(i
, &v
);
360 upwqp
= isl_union_pw_qpolynomial_mul_isl_int(upwqp
, v
);
367 isl_union_pw_qpolynomial_free(upwqp
);
371 static __isl_give isl_union_pw_qpolynomial
*int_union_pw_qpolynomial_mul(
372 __isl_take isl_int_obj
*i
, __isl_take isl_union_pw_qpolynomial
*upwqp
)
374 return union_pw_qpolynomial_int_mul(upwqp
, i
);
377 static __isl_give isl_union_pw_qpolynomial_fold
*union_pw_qpolynomial_fold_int_mul(
378 __isl_take isl_union_pw_qpolynomial_fold
*upwf
,
379 __isl_take isl_int_obj
*i
)
387 isl_int_obj_get_int(i
, &v
);
388 upwf
= isl_union_pw_qpolynomial_fold_mul_isl_int(upwf
, v
);
395 isl_union_pw_qpolynomial_fold_free(upwf
);
399 static __isl_give isl_union_pw_qpolynomial_fold
*int_union_pw_qpolynomial_fold_mul(
400 __isl_take isl_int_obj
*i
,
401 __isl_take isl_union_pw_qpolynomial_fold
*upwf
)
403 return union_pw_qpolynomial_fold_int_mul(upwf
, i
);
406 struct isc_bin_op bin_ops
[] = {
407 { '+', isl_obj_int
, isl_obj_int
, isl_obj_int
,
408 (isc_bin_op_fn
) &isl_int_obj_add
},
409 { '-', isl_obj_int
, isl_obj_int
, isl_obj_int
,
410 (isc_bin_op_fn
) &isl_int_obj_sub
},
411 { '*', isl_obj_int
, isl_obj_int
, isl_obj_int
,
412 (isc_bin_op_fn
) &isl_int_obj_mul
},
413 { '+', isl_obj_union_set
, isl_obj_union_set
,
415 (isc_bin_op_fn
) &isl_union_set_union
},
416 { '+', isl_obj_union_map
, isl_obj_union_map
,
418 (isc_bin_op_fn
) &isl_union_map_union
},
419 { '-', isl_obj_union_set
, isl_obj_union_set
,
421 (isc_bin_op_fn
) &isl_union_set_subtract
},
422 { '-', isl_obj_union_map
, isl_obj_union_map
,
424 (isc_bin_op_fn
) &isl_union_map_subtract
},
425 { '*', isl_obj_union_set
, isl_obj_union_set
,
427 (isc_bin_op_fn
) &isl_union_set_intersect
},
428 { '*', isl_obj_union_map
, isl_obj_union_map
,
430 (isc_bin_op_fn
) &isl_union_map_intersect
},
431 { '*', isl_obj_union_map
, isl_obj_union_set
,
433 (isc_bin_op_fn
) &isl_union_map_intersect_domain
},
434 { '.', isl_obj_union_map
, isl_obj_union_map
,
436 (isc_bin_op_fn
) &isl_union_map_apply_range
},
437 { '.', isl_obj_union_map
, isl_obj_union_pw_qpolynomial
,
438 isl_obj_union_pw_qpolynomial
,
439 (isc_bin_op_fn
) &isl_union_map_apply_union_pw_qpolynomial
},
440 { '.', isl_obj_union_map
, isl_obj_union_pw_qpolynomial_fold
,
442 (isc_bin_op_fn
) &union_map_apply_union_pw_qpolynomial_fold
},
443 { ISL_TOKEN_TO
, isl_obj_union_set
, isl_obj_union_set
,
445 (isc_bin_op_fn
) &isl_union_map_from_domain_and_range
},
446 { '=', isl_obj_union_set
, isl_obj_union_set
, isl_obj_bool
,
447 (isc_bin_op_fn
) &union_set_is_equal
},
448 { '=', isl_obj_union_map
, isl_obj_union_map
, isl_obj_bool
,
449 (isc_bin_op_fn
) &union_map_is_equal
},
450 { ISL_TOKEN_LE
, isl_obj_union_set
, isl_obj_union_set
,
451 isl_obj_bool
, (isc_bin_op_fn
) &union_set_is_subset
},
452 { ISL_TOKEN_LE
, isl_obj_union_map
, isl_obj_union_map
,
453 isl_obj_bool
, (isc_bin_op_fn
) &union_map_is_subset
},
454 { ISL_TOKEN_LT
, isl_obj_union_set
, isl_obj_union_set
,
455 isl_obj_bool
, (isc_bin_op_fn
) &union_set_is_strict_subset
},
456 { ISL_TOKEN_LT
, isl_obj_union_map
, isl_obj_union_map
,
457 isl_obj_bool
, (isc_bin_op_fn
) &union_map_is_strict_subset
},
458 { ISL_TOKEN_GE
, isl_obj_union_set
, isl_obj_union_set
,
459 isl_obj_bool
, (isc_bin_op_fn
) &union_set_is_superset
},
460 { ISL_TOKEN_GE
, isl_obj_union_map
, isl_obj_union_map
,
461 isl_obj_bool
, (isc_bin_op_fn
) &union_map_is_superset
},
462 { ISL_TOKEN_GT
, isl_obj_union_set
, isl_obj_union_set
,
463 isl_obj_bool
, (isc_bin_op_fn
) &union_set_is_strict_superset
},
464 { ISL_TOKEN_GT
, isl_obj_union_map
, isl_obj_union_map
,
465 isl_obj_bool
, (isc_bin_op_fn
) &union_map_is_strict_superset
},
466 { ISL_TOKEN_LEX_LE
, isl_obj_union_set
, isl_obj_union_set
,
468 (isc_bin_op_fn
) &isl_union_set_lex_le_union_set
},
469 { ISL_TOKEN_LEX_LT
, isl_obj_union_set
, isl_obj_union_set
,
471 (isc_bin_op_fn
) &isl_union_set_lex_lt_union_set
},
472 { ISL_TOKEN_LEX_GE
, isl_obj_union_set
, isl_obj_union_set
,
474 (isc_bin_op_fn
) &isl_union_set_lex_ge_union_set
},
475 { ISL_TOKEN_LEX_GT
, isl_obj_union_set
, isl_obj_union_set
,
477 (isc_bin_op_fn
) &isl_union_set_lex_gt_union_set
},
478 { ISL_TOKEN_LEX_LE
, isl_obj_union_map
, isl_obj_union_map
,
480 (isc_bin_op_fn
) &isl_union_map_lex_le_union_map
},
481 { ISL_TOKEN_LEX_LT
, isl_obj_union_map
, isl_obj_union_map
,
483 (isc_bin_op_fn
) &isl_union_map_lex_lt_union_map
},
484 { ISL_TOKEN_LEX_GE
, isl_obj_union_map
, isl_obj_union_map
,
486 (isc_bin_op_fn
) &isl_union_map_lex_ge_union_map
},
487 { ISL_TOKEN_LEX_GT
, isl_obj_union_map
, isl_obj_union_map
,
489 (isc_bin_op_fn
) &isl_union_map_lex_gt_union_map
},
490 { '.', isl_obj_union_pw_qpolynomial_fold
,
491 isl_obj_union_pw_qpolynomial_fold
,
492 isl_obj_union_pw_qpolynomial_fold
,
493 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_fold_fold
},
494 { '+', isl_obj_union_pw_qpolynomial
, isl_obj_union_pw_qpolynomial
,
495 isl_obj_union_pw_qpolynomial
,
496 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_add
},
497 { '+', isl_obj_union_pw_qpolynomial
,
498 isl_obj_union_pw_qpolynomial_fold
,
499 isl_obj_union_pw_qpolynomial_fold
,
500 (isc_bin_op_fn
) &union_pw_qpolynomial_add_union_pw_qpolynomial_fold
},
501 { '+', isl_obj_union_pw_qpolynomial_fold
,
502 isl_obj_union_pw_qpolynomial
,
503 isl_obj_union_pw_qpolynomial_fold
,
504 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_fold_add_union_pw_qpolynomial
},
505 { '-', isl_obj_union_pw_qpolynomial
, isl_obj_union_pw_qpolynomial
,
506 isl_obj_union_pw_qpolynomial
,
507 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_sub
},
508 { '*', isl_obj_int
, isl_obj_union_pw_qpolynomial
,
509 isl_obj_union_pw_qpolynomial
,
510 (isc_bin_op_fn
) &int_union_pw_qpolynomial_mul
},
511 { '*', isl_obj_union_pw_qpolynomial
, isl_obj_int
,
512 isl_obj_union_pw_qpolynomial
,
513 (isc_bin_op_fn
) &union_pw_qpolynomial_int_mul
},
514 { '*', isl_obj_int
, isl_obj_union_pw_qpolynomial_fold
,
515 isl_obj_union_pw_qpolynomial_fold
,
516 (isc_bin_op_fn
) &int_union_pw_qpolynomial_fold_mul
},
517 { '*', isl_obj_union_pw_qpolynomial_fold
, isl_obj_int
,
518 isl_obj_union_pw_qpolynomial_fold
,
519 (isc_bin_op_fn
) &union_pw_qpolynomial_fold_int_mul
},
520 { '*', isl_obj_union_pw_qpolynomial
, isl_obj_union_pw_qpolynomial
,
521 isl_obj_union_pw_qpolynomial
,
522 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_mul
},
523 { '*', isl_obj_union_pw_qpolynomial
, isl_obj_union_set
,
524 isl_obj_union_pw_qpolynomial
,
525 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_intersect_domain
},
526 { '*', isl_obj_union_pw_qpolynomial_fold
, isl_obj_union_set
,
527 isl_obj_union_pw_qpolynomial_fold
,
528 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_fold_intersect_domain
},
529 { '@', isl_obj_union_pw_qpolynomial
, isl_obj_union_set
,
530 isl_obj_union_pw_qpolynomial
,
531 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_at
},
532 { '@', isl_obj_union_pw_qpolynomial_fold
, isl_obj_union_set
,
533 isl_obj_union_pw_qpolynomial
,
534 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_fold_at
},
535 { '%', isl_obj_union_set
, isl_obj_union_set
,
537 (isc_bin_op_fn
) &isl_union_set_gist
},
538 { '%', isl_obj_union_map
, isl_obj_union_map
,
540 (isc_bin_op_fn
) &isl_union_map_gist
},
541 { '%', isl_obj_union_pw_qpolynomial
, isl_obj_union_set
,
542 isl_obj_union_pw_qpolynomial
,
543 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_gist
},
544 { '%', isl_obj_union_pw_qpolynomial_fold
, isl_obj_union_set
,
545 isl_obj_union_pw_qpolynomial_fold
,
546 (isc_bin_op_fn
) &isl_union_pw_qpolynomial_fold_gist
},
547 { '+', isl_obj_str
, isl_obj_str
, isl_obj_str
,
548 (isc_bin_op_fn
) &isl_str_concat
},
552 static __isl_give isl_union_map
*map_after_map(__isl_take isl_union_map
*umap1
,
553 __isl_take isl_union_map
*umap2
)
555 return isl_union_map_apply_range(umap2
, umap1
);
558 static __isl_give isl_union_pw_qpolynomial
*qpolynomial_after_map(
559 __isl_take isl_union_pw_qpolynomial
*upwqp
,
560 __isl_take isl_union_map
*umap
)
562 return isl_union_map_apply_union_pw_qpolynomial(umap
, upwqp
);
565 static __isl_give
struct isl_list
*qpolynomial_fold_after_map(
566 __isl_take isl_union_pw_qpolynomial_fold
*upwf
,
567 __isl_take isl_union_map
*umap
)
569 return union_map_apply_union_pw_qpolynomial_fold(umap
, upwf
);
572 struct isc_named_bin_op named_bin_ops
[] = {
573 { "after", { -1, isl_obj_union_map
, isl_obj_union_map
,
575 (isc_bin_op_fn
) &map_after_map
} },
576 { "after", { -1, isl_obj_union_pw_qpolynomial
,
577 isl_obj_union_map
, isl_obj_union_pw_qpolynomial
,
578 (isc_bin_op_fn
) &qpolynomial_after_map
} },
579 { "after", { -1, isl_obj_union_pw_qpolynomial_fold
,
580 isl_obj_union_map
, isl_obj_list
,
581 (isc_bin_op_fn
) &qpolynomial_fold_after_map
} },
582 { "before", { -1, isl_obj_union_map
, isl_obj_union_map
,
584 (isc_bin_op_fn
) &isl_union_map_apply_range
} },
585 { "before", { -1, isl_obj_union_map
,
586 isl_obj_union_pw_qpolynomial
, isl_obj_union_pw_qpolynomial
,
587 (isc_bin_op_fn
) &isl_union_map_apply_union_pw_qpolynomial
} },
588 { "before", { -1, isl_obj_union_map
,
589 isl_obj_union_pw_qpolynomial_fold
, isl_obj_list
,
590 (isc_bin_op_fn
) &union_map_apply_union_pw_qpolynomial_fold
} },
591 { "cross", { -1, isl_obj_union_set
, isl_obj_union_set
,
593 (isc_bin_op_fn
) &isl_union_set_product
} },
594 { "cross", { -1, isl_obj_union_map
, isl_obj_union_map
,
596 (isc_bin_op_fn
) &isl_union_map_product
} },
600 __isl_give isl_set
*union_set_sample(__isl_take isl_union_set
*uset
)
602 return isl_set_from_basic_set(isl_union_set_sample(uset
));
605 __isl_give isl_map
*union_map_sample(__isl_take isl_union_map
*umap
)
607 return isl_map_from_basic_map(isl_union_map_sample(umap
));
610 static __isl_give
struct isl_list
*union_map_power(
611 __isl_take isl_union_map
*umap
)
614 struct isl_list
*list
;
617 ctx
= isl_union_map_get_ctx(umap
);
618 list
= isl_list_alloc(ctx
, 2);
622 list
->obj
[0].type
= isl_obj_union_map
;
623 list
->obj
[0].v
= isl_union_map_power(umap
, &exact
);
624 list
->obj
[1].type
= isl_obj_bool
;
625 list
->obj
[1].v
= exact
? &isl_bool_true
: &isl_bool_false
;
626 if (exact
< 0 || !list
->obj
[0].v
)
631 isl_union_map_free(umap
);
637 static __isl_give
struct isl_list
*union_pw_qpolynomial_upper_bound(
638 __isl_take isl_union_pw_qpolynomial
*upwqp
)
641 struct isl_list
*list
;
644 ctx
= isl_union_pw_qpolynomial_get_ctx(upwqp
);
645 list
= isl_list_alloc(ctx
, 2);
649 list
->obj
[0].type
= isl_obj_union_pw_qpolynomial_fold
;
650 list
->obj
[0].v
= isl_union_pw_qpolynomial_bound(upwqp
,
651 isl_fold_max
, &tight
);
652 list
->obj
[1].type
= isl_obj_bool
;
653 list
->obj
[1].v
= tight
? &isl_bool_true
: &isl_bool_false
;
654 if (tight
< 0 || !list
->obj
[0].v
)
659 isl_union_pw_qpolynomial_free(upwqp
);
666 void *map_codegen(void *arg
)
669 isl_union_map
*umap
= (isl_union_map
*)arg
;
670 isl_ctx
*ctx
= isl_union_map_get_ctx(umap
);
672 CloogOptions
*options
;
673 CloogDomain
*context
;
674 CloogUnionDomain
*ud
;
676 struct clast_stmt
*stmt
;
678 state
= cloog_isl_state_malloc(ctx
);
679 options
= cloog_options_malloc(state
);
680 options
->language
= LANGUAGE_C
;
681 options
->strides
= 1;
683 ud
= cloog_union_domain_from_isl_union_map(isl_union_map_copy(umap
));
685 dim
= isl_union_map_get_dim(umap
);
686 context
= cloog_domain_from_isl_set(isl_set_universe(dim
));
688 input
= cloog_input_alloc(context
, ud
);
690 stmt
= cloog_clast_create_from_input(input
, options
);
691 clast_pprint(stdout
, stmt
, 0, options
);
692 cloog_clast_free(stmt
);
695 cloog_options_free(options
);
696 cloog_state_free(state
);
697 isl_union_map_free(umap
);
701 void *set_codegen(void *arg
)
704 isl_union_set
*uset
= (isl_union_set
*)arg
;
705 isl_ctx
*ctx
= isl_union_set_get_ctx(uset
);
707 CloogOptions
*options
;
708 CloogDomain
*context
;
709 CloogUnionDomain
*ud
;
711 struct clast_stmt
*stmt
;
713 if (isl_union_set_n_set(uset
) > 1)
714 isl_die(ctx
, isl_error_invalid
,
715 "code generation for more than one domain "
716 "requires a schedule", goto error
);
718 state
= cloog_isl_state_malloc(ctx
);
719 options
= cloog_options_malloc(state
);
720 options
->language
= LANGUAGE_C
;
721 options
->strides
= 1;
723 ud
= cloog_union_domain_from_isl_union_set(isl_union_set_copy(uset
));
725 dim
= isl_union_set_get_dim(uset
);
726 context
= cloog_domain_from_isl_set(isl_set_universe(dim
));
728 input
= cloog_input_alloc(context
, ud
);
730 stmt
= cloog_clast_create_from_input(input
, options
);
731 clast_pprint(stdout
, stmt
, 0, options
);
732 cloog_clast_free(stmt
);
734 cloog_options_free(options
);
735 cloog_state_free(state
);
737 isl_union_set_free(uset
);
742 static int add_point(__isl_take isl_point
*pnt
, void *user
)
744 isl_union_set
**scan
= (isl_union_set
**) user
;
746 *scan
= isl_union_set_add_set(*scan
, isl_set_from_point(pnt
));
751 static __isl_give isl_union_set
*union_set_scan(__isl_take isl_union_set
*uset
)
755 scan
= isl_union_set_empty(isl_union_set_get_dim(uset
));
757 if (isl_union_set_foreach_point(uset
, add_point
, &scan
) < 0) {
758 isl_union_set_free(scan
);
762 isl_union_set_free(uset
);
766 static __isl_give isl_union_map
*union_map_scan(__isl_take isl_union_map
*umap
)
768 return isl_union_set_unwrap(union_set_scan(isl_union_map_wrap(umap
)));
771 static __isl_give isl_union_pw_qpolynomial
*union_pw_qpolynomial_poly(
772 __isl_take isl_union_pw_qpolynomial
*upwqp
)
774 return isl_union_pw_qpolynomial_to_polynomial(upwqp
, 0);
777 static __isl_give isl_union_pw_qpolynomial
*union_pw_qpolynomial_lpoly(
778 __isl_take isl_union_pw_qpolynomial
*upwqp
)
780 return isl_union_pw_qpolynomial_to_polynomial(upwqp
, -1);
783 static __isl_give isl_union_pw_qpolynomial
*union_pw_qpolynomial_upoly(
784 __isl_take isl_union_pw_qpolynomial
*upwqp
)
786 return isl_union_pw_qpolynomial_to_polynomial(upwqp
, 1);
789 typedef void *(*isc_un_op_fn
)(void *arg
);
791 enum isl_token_type op
;
796 struct isc_named_un_op
{
800 struct isc_named_un_op named_un_ops
[] = {
801 {"aff", { -1, isl_obj_union_map
, isl_obj_union_map
,
802 (isc_un_op_fn
) &isl_union_map_affine_hull
} },
803 {"aff", { -1, isl_obj_union_set
, isl_obj_union_set
,
804 (isc_un_op_fn
) &isl_union_set_affine_hull
} },
805 {"card", { -1, isl_obj_union_set
,
806 isl_obj_union_pw_qpolynomial
,
807 (isc_un_op_fn
) &isl_union_set_card
} },
808 {"card", { -1, isl_obj_union_map
,
809 isl_obj_union_pw_qpolynomial
,
810 (isc_un_op_fn
) &isl_union_map_card
} },
811 {"coalesce", { -1, isl_obj_union_set
, isl_obj_union_set
,
812 (isc_un_op_fn
) &isl_union_set_coalesce
} },
813 {"coalesce", { -1, isl_obj_union_map
, isl_obj_union_map
,
814 (isc_un_op_fn
) &isl_union_map_coalesce
} },
815 {"coalesce", { -1, isl_obj_union_pw_qpolynomial
,
816 isl_obj_union_pw_qpolynomial
,
817 (isc_un_op_fn
) &isl_union_pw_qpolynomial_coalesce
} },
818 {"coalesce", { -1, isl_obj_union_pw_qpolynomial_fold
,
819 isl_obj_union_pw_qpolynomial_fold
,
820 (isc_un_op_fn
) &isl_union_pw_qpolynomial_fold_coalesce
} },
822 {"codegen", { -1, isl_obj_union_set
, isl_obj_none
,
824 {"codegen", { -1, isl_obj_union_map
, isl_obj_none
,
827 {"deltas", { -1, isl_obj_union_map
, isl_obj_union_set
,
828 (isc_un_op_fn
) &isl_union_map_deltas
} },
829 {"deltas_map", { -1, isl_obj_union_map
, isl_obj_union_map
,
830 (isc_un_op_fn
) &isl_union_map_deltas_map
} },
831 {"dom", { -1, isl_obj_union_map
, isl_obj_union_set
,
832 (isc_un_op_fn
) &isl_union_map_domain
} },
833 {"dom", { -1, isl_obj_union_pw_qpolynomial
, isl_obj_union_set
,
834 (isc_un_op_fn
) &isl_union_pw_qpolynomial_domain
} },
835 {"dom", { -1, isl_obj_union_pw_qpolynomial_fold
,
837 (isc_un_op_fn
) &isl_union_pw_qpolynomial_fold_domain
} },
838 {"domain", { -1, isl_obj_union_map
, isl_obj_union_set
,
839 (isc_un_op_fn
) &isl_union_map_domain
} },
840 {"domain", { -1, isl_obj_union_pw_qpolynomial
,
842 (isc_un_op_fn
) &isl_union_pw_qpolynomial_domain
} },
843 {"domain", { -1, isl_obj_union_pw_qpolynomial_fold
,
845 (isc_un_op_fn
) &isl_union_pw_qpolynomial_fold_domain
} },
846 {"domain_map", { -1, isl_obj_union_map
, isl_obj_union_map
,
847 (isc_un_op_fn
) &isl_union_map_domain_map
} },
848 {"ran", { -1, isl_obj_union_map
, isl_obj_union_set
,
849 (isc_un_op_fn
) &isl_union_map_range
} },
850 {"range", { -1, isl_obj_union_map
, isl_obj_union_set
,
851 (isc_un_op_fn
) &isl_union_map_range
} },
852 {"range_map", { -1, isl_obj_union_map
, isl_obj_union_map
,
853 (isc_un_op_fn
) &isl_union_map_range_map
} },
854 {"identity", { -1, isl_obj_union_set
, isl_obj_union_map
,
855 (isc_un_op_fn
) &isl_union_set_identity
} },
856 {"lexmin", { -1, isl_obj_union_map
, isl_obj_union_map
,
857 (isc_un_op_fn
) &isl_union_map_lexmin
} },
858 {"lexmax", { -1, isl_obj_union_map
, isl_obj_union_map
,
859 (isc_un_op_fn
) &isl_union_map_lexmax
} },
860 {"lexmin", { -1, isl_obj_union_set
, isl_obj_union_set
,
861 (isc_un_op_fn
) &isl_union_set_lexmin
} },
862 {"lexmax", { -1, isl_obj_union_set
, isl_obj_union_set
,
863 (isc_un_op_fn
) &isl_union_set_lexmax
} },
864 {"poly", { -1, isl_obj_union_map
, isl_obj_union_map
,
865 (isc_un_op_fn
) &isl_union_map_polyhedral_hull
} },
866 {"poly", { -1, isl_obj_union_set
, isl_obj_union_set
,
867 (isc_un_op_fn
) &isl_union_set_polyhedral_hull
} },
868 {"poly", { -1, isl_obj_union_pw_qpolynomial
,
869 isl_obj_union_pw_qpolynomial
,
870 (isc_un_op_fn
) &union_pw_qpolynomial_poly
} },
871 {"lpoly", { -1, isl_obj_union_pw_qpolynomial
,
872 isl_obj_union_pw_qpolynomial
,
873 (isc_un_op_fn
) &union_pw_qpolynomial_lpoly
} },
874 {"upoly", { -1, isl_obj_union_pw_qpolynomial
,
875 isl_obj_union_pw_qpolynomial
,
876 (isc_un_op_fn
) &union_pw_qpolynomial_upoly
} },
877 {"pow", { -1, isl_obj_union_map
, isl_obj_list
,
878 (isc_un_op_fn
) &union_map_power
} },
879 {"sample", { -1, isl_obj_union_set
, isl_obj_set
,
880 (isc_un_op_fn
) &union_set_sample
} },
881 {"sample", { -1, isl_obj_union_map
, isl_obj_map
,
882 (isc_un_op_fn
) &union_map_sample
} },
883 {"scan", { -1, isl_obj_union_set
, isl_obj_union_set
,
884 (isc_un_op_fn
) &union_set_scan
} },
885 {"scan", { -1, isl_obj_union_map
, isl_obj_union_map
,
886 (isc_un_op_fn
) &union_map_scan
} },
887 {"sum", { -1, isl_obj_union_pw_qpolynomial
,
888 isl_obj_union_pw_qpolynomial
,
889 (isc_un_op_fn
) &isl_union_pw_qpolynomial_sum
} },
890 {"ub", { -1, isl_obj_union_pw_qpolynomial
, isl_obj_list
,
891 (isc_un_op_fn
) &union_pw_qpolynomial_upper_bound
} },
892 {"unwrap", { -1, isl_obj_union_set
, isl_obj_union_map
,
893 (isc_un_op_fn
) &isl_union_set_unwrap
} },
894 {"wrap", { -1, isl_obj_union_map
, isl_obj_union_set
,
895 (isc_un_op_fn
) &isl_union_map_wrap
} },
896 {"zip", { -1, isl_obj_union_map
, isl_obj_union_map
,
897 (isc_un_op_fn
) &isl_union_map_zip
} },
901 struct isl_named_obj
{
906 static void free_obj(struct isl_obj obj
)
908 obj
.type
->free(obj
.v
);
911 static int same_name(const void *entry
, const void *val
)
913 const struct isl_named_obj
*named
= (const struct isl_named_obj
*)entry
;
915 return !strcmp(named
->name
, val
);
918 static int do_assign(struct isl_ctx
*ctx
, struct isl_hash_table
*table
,
919 char *name
, struct isl_obj obj
)
921 struct isl_hash_table_entry
*entry
;
923 struct isl_named_obj
*named
;
925 name_hash
= isl_hash_string(isl_hash_init(), name
);
926 entry
= isl_hash_table_find(ctx
, table
, name_hash
, same_name
, name
, 1);
931 free_obj(named
->obj
);
934 named
= isl_alloc_type(ctx
, struct isl_named_obj
);
949 static struct isl_obj
stored_obj(struct isl_ctx
*ctx
,
950 struct isl_hash_table
*table
, char *name
)
952 struct isl_obj obj
= { isl_obj_none
, NULL
};
953 struct isl_hash_table_entry
*entry
;
956 name_hash
= isl_hash_string(isl_hash_init(), name
);
957 entry
= isl_hash_table_find(ctx
, table
, name_hash
, same_name
, name
, 0);
959 struct isl_named_obj
*named
;
962 } else if (isdigit(name
[0]))
963 fprintf(stderr
, "unknown identifier '$%s'\n", name
);
965 fprintf(stderr
, "unknown identifier '%s'\n", name
);
968 obj
.v
= obj
.type
->copy(obj
.v
);
972 static int is_subtype(struct isl_obj obj
, isl_obj_type super
)
974 if (obj
.type
== super
)
976 if (obj
.type
== isl_obj_map
&& super
== isl_obj_union_map
)
978 if (obj
.type
== isl_obj_set
&& super
== isl_obj_union_set
)
980 if (obj
.type
== isl_obj_pw_qpolynomial
&&
981 super
== isl_obj_union_pw_qpolynomial
)
983 if (obj
.type
== isl_obj_pw_qpolynomial_fold
&&
984 super
== isl_obj_union_pw_qpolynomial_fold
)
986 if (obj
.type
== isl_obj_union_set
&& isl_union_set_is_empty(obj
.v
))
988 if (obj
.type
== isl_obj_list
) {
989 struct isl_list
*list
= obj
.v
;
990 if (list
->n
== 2 && list
->obj
[1].type
== isl_obj_bool
)
991 return is_subtype(list
->obj
[0], super
);
993 if (super
== isl_obj_str
)
998 static struct isl_obj
obj_at(struct isl_obj obj
, int i
)
1000 struct isl_list
*list
= obj
.v
;
1003 obj
.v
= obj
.type
->copy(obj
.v
);
1005 isl_list_free(list
);
1010 static struct isl_obj
convert(isl_ctx
*ctx
, struct isl_obj obj
,
1013 if (obj
.type
== type
)
1015 if (obj
.type
== isl_obj_map
&& type
== isl_obj_union_map
) {
1016 obj
.type
= isl_obj_union_map
;
1017 obj
.v
= isl_union_map_from_map(obj
.v
);
1020 if (obj
.type
== isl_obj_set
&& type
== isl_obj_union_set
) {
1021 obj
.type
= isl_obj_union_set
;
1022 obj
.v
= isl_union_set_from_set(obj
.v
);
1025 if (obj
.type
== isl_obj_pw_qpolynomial
&&
1026 type
== isl_obj_union_pw_qpolynomial
) {
1027 obj
.type
= isl_obj_union_pw_qpolynomial
;
1028 obj
.v
= isl_union_pw_qpolynomial_from_pw_qpolynomial(obj
.v
);
1031 if (obj
.type
== isl_obj_pw_qpolynomial_fold
&&
1032 type
== isl_obj_union_pw_qpolynomial_fold
) {
1033 obj
.type
= isl_obj_union_pw_qpolynomial_fold
;
1034 obj
.v
= isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(obj
.v
);
1037 if (obj
.type
== isl_obj_union_set
&& isl_union_set_is_empty(obj
.v
)) {
1038 if (type
== isl_obj_union_map
) {
1039 obj
.type
= isl_obj_union_map
;
1042 if (type
== isl_obj_union_pw_qpolynomial
) {
1043 isl_dim
*dim
= isl_union_set_get_dim(obj
.v
);
1044 isl_union_set_free(obj
.v
);
1045 obj
.v
= isl_union_pw_qpolynomial_zero(dim
);
1046 obj
.type
= isl_obj_union_pw_qpolynomial
;
1049 if (type
== isl_obj_union_pw_qpolynomial_fold
) {
1050 isl_dim
*dim
= isl_union_set_get_dim(obj
.v
);
1051 isl_union_set_free(obj
.v
);
1052 obj
.v
= isl_union_pw_qpolynomial_fold_zero(dim
,
1054 obj
.type
= isl_obj_union_pw_qpolynomial_fold
;
1058 if (obj
.type
== isl_obj_list
) {
1059 struct isl_list
*list
= obj
.v
;
1060 if (list
->n
== 2 && list
->obj
[1].type
== isl_obj_bool
)
1061 return convert(ctx
, obj_at(obj
, 0), type
);
1063 if (type
== isl_obj_str
) {
1068 p
= isl_printer_to_str(ctx
);
1071 p
= obj
.type
->print(p
, obj
.v
);
1072 s
= isl_printer_get_str(p
);
1073 isl_printer_free(p
);
1075 str
= isl_str_from_string(ctx
, s
);
1080 obj
.type
= isl_obj_str
;
1086 obj
.type
= isl_obj_none
;
1091 static struct isc_bin_op
*read_bin_op_if_available(struct isl_stream
*s
,
1095 struct isl_token
*tok
;
1097 tok
= isl_stream_next_token(s
);
1101 for (i
= 0; ; ++i
) {
1104 if (bin_ops
[i
].op
!= tok
->type
)
1106 if (!is_subtype(lhs
, bin_ops
[i
].lhs
))
1109 isl_token_free(tok
);
1113 for (i
= 0; ; ++i
) {
1114 if (!named_bin_ops
[i
].name
)
1116 if (named_bin_ops
[i
].op
.op
!= tok
->type
)
1118 if (!is_subtype(lhs
, named_bin_ops
[i
].op
.lhs
))
1121 isl_token_free(tok
);
1122 return &named_bin_ops
[i
].op
;
1125 isl_stream_push_token(s
, tok
);
1130 static struct isc_un_op
*read_prefix_un_op_if_available(struct isl_stream
*s
)
1133 struct isl_token
*tok
;
1135 tok
= isl_stream_next_token(s
);
1139 for (i
= 0; ; ++i
) {
1140 if (!named_un_ops
[i
].name
)
1142 if (named_un_ops
[i
].op
.op
!= tok
->type
)
1145 isl_token_free(tok
);
1146 return &named_un_ops
[i
].op
;
1149 isl_stream_push_token(s
, tok
);
1154 static struct isc_un_op
*find_matching_un_op(struct isc_un_op
*like
,
1159 for (i
= 0; ; ++i
) {
1160 if (!named_un_ops
[i
].name
)
1162 if (named_un_ops
[i
].op
.op
!= like
->op
)
1164 if (!is_subtype(arg
, named_un_ops
[i
].op
.arg
))
1167 return &named_un_ops
[i
].op
;
1173 static int is_assign(struct isl_stream
*s
)
1175 struct isl_token
*tok
;
1176 struct isl_token
*tok2
;
1179 tok
= isl_stream_next_token(s
);
1182 if (tok
->type
!= ISL_TOKEN_IDENT
) {
1183 isl_stream_push_token(s
, tok
);
1187 tok2
= isl_stream_next_token(s
);
1189 isl_stream_push_token(s
, tok
);
1192 assign
= tok2
->type
== ISL_TOKEN_DEF
;
1193 isl_stream_push_token(s
, tok2
);
1194 isl_stream_push_token(s
, tok
);
1199 static struct isl_obj
read_obj(struct isl_stream
*s
,
1200 struct isl_hash_table
*table
);
1201 static struct isl_obj
read_expr(struct isl_stream
*s
,
1202 struct isl_hash_table
*table
);
1204 static struct isl_obj
read_un_op_expr(struct isl_stream
*s
,
1205 struct isl_hash_table
*table
, struct isc_un_op
*op
)
1207 struct isl_obj obj
= { isl_obj_none
, NULL
};
1209 obj
= read_obj(s
, table
);
1213 op
= find_matching_un_op(op
, obj
);
1216 isl_die(s
->ctx
, isl_error_invalid
,
1217 "no such unary operator defined on given operand",
1220 obj
= convert(s
->ctx
, obj
, op
->arg
);
1221 obj
.v
= op
->fn(obj
.v
);
1227 obj
.type
= isl_obj_none
;
1232 static struct isl_obj
transitive_closure(struct isl_ctx
*ctx
, struct isl_obj obj
)
1234 struct isl_list
*list
;
1237 if (obj
.type
!= isl_obj_union_map
)
1238 obj
= convert(ctx
, obj
, isl_obj_union_map
);
1239 isl_assert(ctx
, obj
.type
== isl_obj_union_map
, goto error
);
1240 list
= isl_list_alloc(ctx
, 2);
1244 list
->obj
[0].type
= isl_obj_union_map
;
1245 list
->obj
[0].v
= isl_union_map_transitive_closure(obj
.v
, &exact
);
1246 list
->obj
[1].type
= isl_obj_bool
;
1247 list
->obj
[1].v
= exact
? &isl_bool_true
: &isl_bool_false
;
1249 obj
.type
= isl_obj_list
;
1250 if (exact
< 0 || !list
->obj
[0].v
)
1256 obj
.type
= isl_obj_none
;
1261 static struct isl_obj
obj_at_index(struct isl_stream
*s
, struct isl_obj obj
)
1263 struct isl_list
*list
= obj
.v
;
1264 struct isl_token
*tok
;
1267 tok
= isl_stream_next_token(s
);
1268 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
) {
1269 isl_stream_error(s
, tok
, "expecting index");
1271 isl_stream_push_token(s
, tok
);
1274 i
= isl_int_get_si(tok
->u
.v
);
1275 isl_token_free(tok
);
1276 isl_assert(s
->ctx
, i
< list
->n
, goto error
);
1277 if (isl_stream_eat(s
, ']'))
1280 return obj_at(obj
, i
);
1283 obj
.type
= isl_obj_none
;
1288 static struct isl_obj
apply(struct isl_stream
*s
, __isl_take isl_union_map
*umap
,
1289 struct isl_hash_table
*table
)
1293 obj
= read_expr(s
, table
);
1294 isl_assert(s
->ctx
, is_subtype(obj
, isl_obj_union_set
) ||
1295 is_subtype(obj
, isl_obj_union_map
), goto error
);
1297 if (obj
.type
== isl_obj_list
) {
1298 struct isl_list
*list
= obj
.v
;
1299 if (list
->n
== 2 && list
->obj
[1].type
== isl_obj_bool
)
1300 obj
= obj_at(obj
, 0);
1302 if (obj
.type
== isl_obj_set
)
1303 obj
= convert(s
->ctx
, obj
, isl_obj_union_set
);
1304 else if (obj
.type
== isl_obj_map
)
1305 obj
= convert(s
->ctx
, obj
, isl_obj_union_map
);
1306 if (obj
.type
== isl_obj_union_set
) {
1307 obj
.v
= isl_union_set_apply(obj
.v
, umap
);
1309 obj
.v
= isl_union_map_apply_range(obj
.v
, umap
);
1313 if (isl_stream_eat(s
, ')'))
1318 isl_union_map_free(umap
);
1321 obj
.type
= isl_obj_none
;
1326 static struct isl_obj
apply_fun(struct isl_stream
*s
,
1327 struct isl_obj obj
, struct isl_hash_table
*table
)
1331 arg
= read_expr(s
, table
);
1332 if (!is_subtype(arg
, isl_obj_union_map
) &&
1333 !is_subtype(arg
, isl_obj_union_set
))
1334 isl_die(s
->ctx
, isl_error_invalid
,
1335 "expecting set of map argument", goto error
);
1337 if (arg
.type
== isl_obj_list
) {
1338 struct isl_list
*list
= arg
.v
;
1339 if (list
->n
== 2 && list
->obj
[1].type
== isl_obj_bool
)
1340 arg
= obj_at(arg
, 0);
1342 if (arg
.type
== isl_obj_set
)
1343 arg
= convert(s
->ctx
, arg
, isl_obj_union_set
);
1344 else if (arg
.type
== isl_obj_map
)
1345 arg
= convert(s
->ctx
, arg
, isl_obj_union_map
);
1346 if (arg
.type
== isl_obj_union_set
) {
1347 arg
.v
= isl_union_map_from_range(arg
.v
);
1348 arg
.type
= isl_obj_union_map
;
1350 if (obj
.type
== isl_obj_union_pw_qpolynomial
) {
1351 obj
.v
= isl_union_map_apply_union_pw_qpolynomial(arg
.v
, obj
.v
);
1353 obj
.type
= isl_obj_list
;
1354 obj
.v
= union_map_apply_union_pw_qpolynomial_fold(arg
.v
, obj
.v
);
1359 if (isl_stream_eat(s
, ')'))
1367 obj
.type
= isl_obj_none
;
1372 struct add_vertex_data
{
1373 struct isl_list
*list
;
1377 static int add_vertex(__isl_take isl_vertex
*vertex
, void *user
)
1379 struct add_vertex_data
*data
= (struct add_vertex_data
*)user
;
1380 isl_basic_set
*expr
;
1382 expr
= isl_vertex_get_expr(vertex
);
1384 data
->list
->obj
[data
->i
].type
= isl_obj_set
;
1385 data
->list
->obj
[data
->i
].v
= isl_set_from_basic_set(expr
);
1388 isl_vertex_free(vertex
);
1393 static int set_vertices(__isl_take isl_set
*set
, void *user
)
1396 isl_basic_set
*hull
;
1397 isl_vertices
*vertices
= NULL
;
1398 struct isl_list
*list
= NULL
;
1400 struct add_vertex_data
*data
= (struct add_vertex_data
*)user
;
1402 set
= isl_set_remove_divs(set
);
1403 hull
= isl_set_convex_hull(set
);
1404 vertices
= isl_basic_set_compute_vertices(hull
);
1405 isl_basic_set_free(hull
);
1409 ctx
= isl_vertices_get_ctx(vertices
);
1410 data
->list
= isl_list_alloc(ctx
, isl_vertices_get_n_vertices(vertices
));
1415 r
= isl_vertices_foreach_vertex(vertices
, &add_vertex
, user
);
1417 data
->list
= isl_list_concat(list
, data
->list
);
1419 isl_vertices_free(vertices
);
1424 isl_vertices_free(vertices
);
1428 static struct isl_obj
vertices(struct isl_stream
*s
,
1429 struct isl_hash_table
*table
)
1433 struct isl_list
*list
= NULL
;
1434 isl_union_set
*uset
;
1435 struct add_vertex_data data
= { NULL
};
1437 obj
= read_expr(s
, table
);
1438 obj
= convert(s
->ctx
, obj
, isl_obj_union_set
);
1439 isl_assert(s
->ctx
, obj
.type
== isl_obj_union_set
, goto error
);
1443 ctx
= isl_union_set_get_ctx(uset
);
1444 list
= isl_list_alloc(ctx
, 0);
1450 if (isl_union_set_foreach_set(uset
, &set_vertices
, &data
) < 0)
1453 isl_union_set_free(uset
);
1455 obj
.type
= isl_obj_list
;
1460 isl_union_set_free(uset
);
1461 isl_list_free(data
.list
);
1463 obj
.type
= isl_obj_none
;
1468 static struct isl_obj
type_of(struct isl_stream
*s
,
1469 struct isl_hash_table
*table
)
1473 const char *type
= "unknown";
1475 obj
= read_expr(s
, table
);
1477 if (obj
.type
== isl_obj_map
||
1478 obj
.type
== isl_obj_union_map
)
1480 if (obj
.type
== isl_obj_set
||
1481 obj
.type
== isl_obj_union_set
)
1483 if (obj
.type
== isl_obj_pw_qpolynomial
||
1484 obj
.type
== isl_obj_union_pw_qpolynomial
)
1485 type
= "piecewise quasipolynomial";
1486 if (obj
.type
== isl_obj_pw_qpolynomial_fold
||
1487 obj
.type
== isl_obj_union_pw_qpolynomial_fold
)
1488 type
= "piecewise quasipolynomial fold";
1489 if (obj
.type
== isl_obj_list
)
1491 if (obj
.type
== isl_obj_bool
)
1493 if (obj
.type
== isl_obj_str
)
1495 if (obj
.type
== isl_obj_int
)
1499 obj
.type
= isl_obj_str
;
1500 obj
.v
= isl_str_from_string(s
->ctx
, strdup(type
));
1505 static __isl_give isl_union_map
*read_map(struct isl_stream
*s
,
1506 struct isl_hash_table
*table
)
1510 obj
= read_obj(s
, table
);
1511 obj
= convert(s
->ctx
, obj
, isl_obj_union_map
);
1512 isl_assert(s
->ctx
, obj
.type
== isl_obj_union_map
, goto error
);
1519 static struct isl_obj
last_any(struct isl_stream
*s
,
1520 struct isl_hash_table
*table
, __isl_take isl_union_map
*must_source
,
1521 __isl_take isl_union_map
*may_source
)
1523 struct isl_obj obj
= { isl_obj_none
, NULL
};
1524 isl_union_map
*sink
= NULL
;
1525 isl_union_map
*schedule
= NULL
;
1526 isl_union_map
*may_dep
;
1527 isl_union_map
*must_dep
;
1529 if (isl_stream_eat(s
, iscc_op
[ISCC_BEFORE
]))
1532 sink
= read_map(s
, table
);
1536 if (isl_stream_eat(s
, iscc_op
[ISCC_UNDER
]))
1539 schedule
= read_map(s
, table
);
1543 if (isl_union_map_compute_flow(sink
, must_source
, may_source
,
1544 schedule
, &must_dep
, &may_dep
,
1548 obj
.type
= isl_obj_union_map
;
1549 obj
.v
= isl_union_map_union(must_dep
, may_dep
);
1553 isl_union_map_free(may_source
);
1554 isl_union_map_free(must_source
);
1555 isl_union_map_free(sink
);
1556 isl_union_map_free(schedule
);
1558 obj
.type
= isl_obj_none
;
1563 static struct isl_obj
any(struct isl_stream
*s
, struct isl_hash_table
*table
)
1565 struct isl_obj obj
= { isl_obj_none
, NULL
};
1566 isl_union_map
*must_source
= NULL
;
1567 isl_union_map
*may_source
= NULL
;
1568 isl_union_map
*sink
= NULL
;
1569 isl_union_map
*schedule
= NULL
;
1570 isl_union_map
*may_dep
;
1572 may_source
= read_map(s
, table
);
1576 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_LAST
])) {
1577 must_source
= read_map(s
, table
);
1580 return last_any(s
, table
, must_source
, may_source
);
1583 if (isl_stream_eat(s
, iscc_op
[ISCC_BEFORE
]))
1586 sink
= read_map(s
, table
);
1590 if (isl_stream_eat(s
, iscc_op
[ISCC_UNDER
]))
1593 schedule
= read_map(s
, table
);
1597 must_source
= isl_union_map_empty(isl_union_map_get_dim(sink
));
1598 if (isl_union_map_compute_flow(sink
, must_source
, may_source
,
1599 schedule
, NULL
, &may_dep
,
1603 obj
.type
= isl_obj_union_map
;
1608 isl_union_map_free(may_source
);
1609 isl_union_map_free(must_source
);
1610 isl_union_map_free(sink
);
1611 isl_union_map_free(schedule
);
1613 obj
.type
= isl_obj_none
;
1618 static struct isl_obj
last(struct isl_stream
*s
, struct isl_hash_table
*table
)
1620 struct isl_obj obj
= { isl_obj_none
, NULL
};
1621 struct isl_list
*list
= NULL
;
1622 isl_union_map
*must_source
= NULL
;
1623 isl_union_map
*may_source
= NULL
;
1624 isl_union_map
*sink
= NULL
;
1625 isl_union_map
*schedule
= NULL
;
1626 isl_union_map
*must_dep
;
1627 isl_union_map
*must_no_source
;
1629 must_source
= read_map(s
, table
);
1633 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_ANY
])) {
1634 may_source
= read_map(s
, table
);
1637 return last_any(s
, table
, must_source
, may_source
);
1640 list
= isl_list_alloc(s
->ctx
, 2);
1644 if (isl_stream_eat(s
, iscc_op
[ISCC_BEFORE
]))
1647 sink
= read_map(s
, table
);
1651 if (isl_stream_eat(s
, iscc_op
[ISCC_UNDER
]))
1654 schedule
= read_map(s
, table
);
1658 may_source
= isl_union_map_empty(isl_union_map_get_dim(sink
));
1659 if (isl_union_map_compute_flow(sink
, must_source
, may_source
,
1660 schedule
, &must_dep
, NULL
,
1661 &must_no_source
, NULL
) < 0)
1664 list
->obj
[0].type
= isl_obj_union_map
;
1665 list
->obj
[0].v
= must_dep
;
1666 list
->obj
[1].type
= isl_obj_union_map
;
1667 list
->obj
[1].v
= must_no_source
;
1670 obj
.type
= isl_obj_list
;
1674 isl_list_free(list
);
1675 isl_union_map_free(may_source
);
1676 isl_union_map_free(must_source
);
1677 isl_union_map_free(sink
);
1678 isl_union_map_free(schedule
);
1680 obj
.type
= isl_obj_none
;
1685 static struct isl_obj
power(struct isl_stream
*s
, struct isl_obj obj
)
1687 struct isl_token
*tok
;
1689 if (isl_stream_eat_if_available(s
, '+'))
1690 return transitive_closure(s
->ctx
, obj
);
1692 tok
= isl_stream_next_token(s
);
1693 if (!tok
|| tok
->type
!= ISL_TOKEN_VALUE
|| isl_int_cmp_si(tok
->u
.v
, -1)) {
1694 isl_stream_error(s
, tok
, "expecting -1");
1696 isl_stream_push_token(s
, tok
);
1699 isl_token_free(tok
);
1700 isl_assert(s
->ctx
, is_subtype(obj
, isl_obj_union_map
), goto error
);
1701 if (obj
.type
!= isl_obj_union_map
)
1702 obj
= convert(s
->ctx
, obj
, isl_obj_union_map
);
1704 obj
.v
= isl_union_map_reverse(obj
.v
);
1711 obj
.type
= isl_obj_none
;
1716 static struct isl_obj
read_from_file(struct isl_stream
*s
)
1719 struct isl_token
*tok
;
1720 struct isl_stream
*s_file
;
1721 struct iscc_options
*options
;
1724 tok
= isl_stream_next_token(s
);
1725 if (!tok
|| tok
->type
!= ISL_TOKEN_STRING
) {
1726 isl_stream_error(s
, tok
, "expecting filename");
1727 isl_token_free(tok
);
1731 options
= isl_ctx_peek_iscc_options(s
->ctx
);
1732 if (!options
|| !options
->io
) {
1733 isl_token_free(tok
);
1734 isl_die(s
->ctx
, isl_error_invalid
,
1735 "read operation not allowed", goto error
);
1738 file
= fopen(tok
->u
.s
, "r");
1739 isl_token_free(tok
);
1740 isl_assert(s
->ctx
, file
, goto error
);
1742 s_file
= isl_stream_new_file(s
->ctx
, file
);
1748 obj
= isl_stream_read_obj(s_file
);
1750 isl_stream_free(s_file
);
1755 obj
.type
= isl_obj_none
;
1760 static struct isl_obj
write_to_file(struct isl_stream
*s
,
1761 struct isl_hash_table
*table
)
1764 struct isl_token
*tok
;
1765 struct isl_stream
*s_file
;
1766 struct iscc_options
*options
;
1770 tok
= isl_stream_next_token(s
);
1771 if (!tok
|| tok
->type
!= ISL_TOKEN_STRING
) {
1772 isl_stream_error(s
, tok
, "expecting filename");
1773 isl_token_free(tok
);
1777 obj
= read_expr(s
, table
);
1779 options
= isl_ctx_peek_iscc_options(s
->ctx
);
1780 if (!options
|| !options
->io
) {
1781 isl_token_free(tok
);
1782 isl_die(s
->ctx
, isl_error_invalid
,
1783 "write operation not allowed", goto error
);
1786 file
= fopen(tok
->u
.s
, "w");
1787 isl_token_free(tok
);
1789 isl_die(s
->ctx
, isl_error_unknown
,
1790 "could not open file for writing", goto error
);
1792 p
= isl_printer_to_file(s
->ctx
, file
);
1793 p
= isl_printer_set_output_format(p
, options
->format
);
1794 p
= obj
.type
->print(p
, obj
.v
);
1795 p
= isl_printer_end_line(p
);
1796 isl_printer_free(p
);
1801 obj
.type
= isl_obj_none
;
1806 static struct isl_obj
read_string_if_available(struct isl_stream
*s
)
1808 struct isl_token
*tok
;
1809 struct isl_obj obj
= { isl_obj_none
, NULL
};
1811 tok
= isl_stream_next_token(s
);
1814 if (tok
->type
== ISL_TOKEN_STRING
) {
1816 str
= isl_str_alloc(s
->ctx
);
1819 str
->s
= strdup(tok
->u
.s
);
1820 isl_token_free(tok
);
1822 obj
.type
= isl_obj_str
;
1824 isl_stream_push_token(s
, tok
);
1827 isl_token_free(tok
);
1831 static struct isl_obj
read_bool_if_available(struct isl_stream
*s
)
1833 struct isl_token
*tok
;
1834 struct isl_obj obj
= { isl_obj_none
, NULL
};
1836 tok
= isl_stream_next_token(s
);
1839 if (tok
->type
== ISL_TOKEN_FALSE
|| tok
->type
== ISL_TOKEN_TRUE
) {
1840 int is_true
= tok
->type
== ISL_TOKEN_TRUE
;
1841 isl_token_free(tok
);
1842 obj
.v
= is_true
? &isl_bool_true
: &isl_bool_false
;
1843 obj
.type
= isl_obj_bool
;
1845 isl_stream_push_token(s
, tok
);
1848 isl_token_free(tok
);
1852 static __isl_give
char *read_ident(struct isl_stream
*s
)
1855 struct isl_token
*tok
, *tok2
;
1857 name
= isl_stream_read_ident_if_available(s
);
1861 tok
= isl_stream_next_token(s
);
1864 if (tok
->type
!= '$') {
1865 isl_stream_push_token(s
, tok
);
1868 tok2
= isl_stream_next_token(s
);
1869 if (!tok2
|| tok2
->type
!= ISL_TOKEN_VALUE
) {
1871 isl_stream_push_token(s
, tok2
);
1872 isl_stream_push_token(s
, tok
);
1876 name
= isl_int_get_str(tok2
->u
.v
);
1877 isl_token_free(tok
);
1878 isl_token_free(tok2
);
1883 static struct isl_obj
read_list(struct isl_stream
*s
,
1884 struct isl_hash_table
*table
, struct isl_obj obj
)
1886 struct isl_list
*list
;
1888 list
= isl_list_alloc(s
->ctx
, 2);
1892 list
->obj
[1] = read_obj(s
, table
);
1894 obj
.type
= isl_obj_list
;
1896 if (!list
->obj
[1].v
)
1899 while (isl_stream_eat_if_available(s
, ',')) {
1900 obj
.v
= list
= isl_list_add_obj(list
, read_obj(s
, table
));
1908 obj
.type
= isl_obj_none
;
1913 static struct isl_obj
read_obj(struct isl_stream
*s
,
1914 struct isl_hash_table
*table
)
1916 struct isl_obj obj
= { isl_obj_none
, NULL
};
1918 struct isc_un_op
*op
= NULL
;
1920 obj
= read_string_if_available(s
);
1923 obj
= read_bool_if_available(s
);
1926 if (isl_stream_eat_if_available(s
, '(')) {
1927 obj
= read_expr(s
, table
);
1928 if (obj
.v
&& isl_stream_eat_if_available(s
, ','))
1929 obj
= read_list(s
, table
, obj
);
1930 if (!obj
.v
|| isl_stream_eat(s
, ')'))
1933 op
= read_prefix_un_op_if_available(s
);
1935 return read_un_op_expr(s
, table
, op
);
1937 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_READ
]))
1938 return read_from_file(s
);
1939 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_WRITE
]))
1940 return write_to_file(s
, table
);
1941 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_VERTICES
]))
1942 return vertices(s
, table
);
1943 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_ANY
]))
1944 return any(s
, table
);
1945 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_LAST
]))
1946 return last(s
, table
);
1947 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_TYPEOF
]))
1948 return type_of(s
, table
);
1950 name
= read_ident(s
);
1952 obj
= stored_obj(s
->ctx
, table
, name
);
1954 obj
= isl_stream_read_obj(s
);
1959 if (isl_stream_eat_if_available(s
, '^'))
1960 obj
= power(s
, obj
);
1961 else if (obj
.type
== isl_obj_list
&& isl_stream_eat_if_available(s
, '['))
1962 obj
= obj_at_index(s
, obj
);
1963 else if (is_subtype(obj
, isl_obj_union_map
) &&
1964 isl_stream_eat_if_available(s
, '(')) {
1965 obj
= convert(s
->ctx
, obj
, isl_obj_union_map
);
1966 obj
= apply(s
, obj
.v
, table
);
1967 } else if (is_subtype(obj
, isl_obj_union_pw_qpolynomial
) &&
1968 isl_stream_eat_if_available(s
, '(')) {
1969 obj
= convert(s
->ctx
, obj
, isl_obj_union_pw_qpolynomial
);
1970 obj
= apply_fun(s
, obj
, table
);
1971 } else if (is_subtype(obj
, isl_obj_union_pw_qpolynomial_fold
) &&
1972 isl_stream_eat_if_available(s
, '(')) {
1973 obj
= convert(s
->ctx
, obj
, isl_obj_union_pw_qpolynomial_fold
);
1974 obj
= apply_fun(s
, obj
, table
);
1980 obj
.type
= isl_obj_none
;
1985 static struct isc_bin_op
*find_matching_bin_op(struct isc_bin_op
*like
,
1986 struct isl_obj lhs
, struct isl_obj rhs
)
1990 for (i
= 0; ; ++i
) {
1993 if (bin_ops
[i
].op
!= like
->op
)
1995 if (!is_subtype(lhs
, bin_ops
[i
].lhs
))
1997 if (!is_subtype(rhs
, bin_ops
[i
].rhs
))
2003 for (i
= 0; ; ++i
) {
2004 if (!named_bin_ops
[i
].name
)
2006 if (named_bin_ops
[i
].op
.op
!= like
->op
)
2008 if (!is_subtype(lhs
, named_bin_ops
[i
].op
.lhs
))
2010 if (!is_subtype(rhs
, named_bin_ops
[i
].op
.rhs
))
2013 return &named_bin_ops
[i
].op
;
2019 static int next_is_neg_int(struct isl_stream
*s
)
2021 struct isl_token
*tok
;
2024 tok
= isl_stream_next_token(s
);
2025 ret
= tok
&& tok
->type
== ISL_TOKEN_VALUE
&& isl_int_is_neg(tok
->u
.v
);
2026 isl_stream_push_token(s
, tok
);
2031 static struct isl_obj
read_expr(struct isl_stream
*s
,
2032 struct isl_hash_table
*table
)
2034 struct isl_obj obj
= { isl_obj_none
, NULL
};
2035 struct isl_obj right_obj
= { isl_obj_none
, NULL
};
2037 obj
= read_obj(s
, table
);
2039 struct isc_bin_op
*op
= NULL
;
2041 op
= read_bin_op_if_available(s
, obj
);
2045 right_obj
= read_obj(s
, table
);
2047 op
= find_matching_bin_op(op
, obj
, right_obj
);
2050 isl_die(s
->ctx
, isl_error_invalid
,
2051 "no such binary operator defined on given operands",
2054 obj
= convert(s
->ctx
, obj
, op
->lhs
);
2055 right_obj
= convert(s
->ctx
, right_obj
, op
->rhs
);
2056 obj
.v
= op
->fn(obj
.v
, right_obj
.v
);
2060 if (obj
.type
== isl_obj_int
&& next_is_neg_int(s
)) {
2061 right_obj
= read_obj(s
, table
);
2062 obj
.v
= isl_int_obj_add(obj
.v
, right_obj
.v
);
2067 free_obj(right_obj
);
2069 obj
.type
= isl_obj_none
;
2074 static __isl_give isl_printer
*source_file(struct isl_stream
*s
,
2075 struct isl_hash_table
*table
, __isl_take isl_printer
*p
);
2077 static __isl_give isl_printer
*read_line(struct isl_stream
*s
,
2078 struct isl_hash_table
*table
, __isl_take isl_printer
*p
, int tty
)
2080 struct isl_obj obj
= { isl_obj_none
, NULL
};
2084 struct isc_bin_op
*op
= NULL
;
2089 if (isl_stream_is_empty(s
))
2092 if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_SOURCE
]))
2093 return source_file(s
, table
, p
);
2095 assign
= is_assign(s
);
2097 lhs
= isl_stream_read_ident_if_available(s
);
2098 if (isl_stream_eat(s
, ISL_TOKEN_DEF
))
2100 } else if (isl_stream_eat_if_available(s
, iscc_op
[ISCC_PRINT
]))
2105 obj
= read_expr(s
, table
);
2106 if (obj
.type
== isl_obj_none
|| obj
.v
== NULL
) {
2107 if (isl_ctx_last_error(s
->ctx
) == isl_error_abort
) {
2108 fprintf(stderr
, "Interrupted\n");
2109 isl_ctx_reset_error(s
->ctx
);
2113 if (isl_stream_eat(s
, ';'))
2117 p
= obj
.type
->print(p
, obj
.v
);
2118 p
= isl_printer_end_line(p
);
2123 static int count
= 0;
2124 snprintf(buf
, sizeof(buf
), "$%d", count
++);
2125 lhs
= strdup(buf
+ 1);
2127 p
= isl_printer_print_str(p
, buf
);
2128 p
= isl_printer_print_str(p
, " := ");
2129 p
= obj
.type
->print(p
, obj
.v
);
2130 p
= isl_printer_end_line(p
);
2132 if (do_assign(s
->ctx
, table
, lhs
, obj
))
2137 isl_stream_flush_tokens(s
);
2138 isl_stream_skip_line(s
);
2144 int free_cb(void **entry
, void *user
)
2146 struct isl_named_obj
*named
= *entry
;
2148 free_obj(named
->obj
);
2155 static void register_named_ops(struct isl_stream
*s
)
2159 for (i
= 0; i
< ISCC_N_OP
; ++i
) {
2160 iscc_op
[i
] = isl_stream_register_keyword(s
, op_name
[i
]);
2161 assert(iscc_op
[i
] != ISL_TOKEN_ERROR
);
2164 for (i
= 0; ; ++i
) {
2165 if (!named_un_ops
[i
].name
)
2167 named_un_ops
[i
].op
.op
= isl_stream_register_keyword(s
,
2168 named_un_ops
[i
].name
);
2169 assert(named_un_ops
[i
].op
.op
!= ISL_TOKEN_ERROR
);
2172 for (i
= 0; ; ++i
) {
2173 if (!named_bin_ops
[i
].name
)
2175 named_bin_ops
[i
].op
.op
= isl_stream_register_keyword(s
,
2176 named_bin_ops
[i
].name
);
2177 assert(named_bin_ops
[i
].op
.op
!= ISL_TOKEN_ERROR
);
2181 static __isl_give isl_printer
*source_file(struct isl_stream
*s
,
2182 struct isl_hash_table
*table
, __isl_take isl_printer
*p
)
2184 struct isl_token
*tok
;
2185 struct isl_stream
*s_file
;
2188 tok
= isl_stream_next_token(s
);
2189 if (!tok
|| tok
->type
!= ISL_TOKEN_STRING
) {
2190 isl_stream_error(s
, tok
, "expecting filename");
2191 isl_token_free(tok
);
2195 file
= fopen(tok
->u
.s
, "r");
2196 isl_token_free(tok
);
2197 isl_assert(s
->ctx
, file
, return p
);
2199 s_file
= isl_stream_new_file(s
->ctx
, file
);
2205 register_named_ops(s_file
);
2207 while (!s_file
->eof
)
2208 p
= read_line(s_file
, table
, p
, 0);
2210 isl_stream_free(s_file
);
2213 isl_stream_eat(s
, ';');
2218 int main(int argc
, char **argv
)
2220 struct isl_ctx
*ctx
;
2221 struct isl_stream
*s
;
2222 struct isl_hash_table
*table
;
2223 struct iscc_options
*options
;
2225 int tty
= isatty(0);
2227 options
= iscc_options_new_with_defaults();
2229 argc
= iscc_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
2231 ctx
= isl_ctx_alloc_with_options(iscc_options_arg
, options
);
2232 s
= isl_stream_new_file(ctx
, stdin
);
2234 table
= isl_hash_table_alloc(ctx
, 10);
2236 p
= isl_printer_to_file(ctx
, stdout
);
2237 p
= isl_printer_set_output_format(p
, options
->format
);
2240 register_named_ops(s
);
2242 install_signal_handler(ctx
);
2244 while (p
&& !s
->eof
) {
2245 isl_ctx_resume(main_ctx
);
2246 p
= read_line(s
, table
, p
, tty
);
2249 remove_signal_handler(ctx
);
2251 isl_printer_free(p
);
2252 isl_hash_table_foreach(ctx
, table
, free_cb
, NULL
);
2253 isl_hash_table_free(ctx
, table
);