From e2d8fba498ca41eeeb6332cb8da0c8764cf118d1 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 17 Mar 2011 10:07:22 +0100 Subject: [PATCH] iscc: allow interruption of computation from the keyboard Signed-off-by: Sven Verdoolaege --- configure.in | 1 + iscc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- isl | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index fbf8122..6938459 100644 --- a/configure.in +++ b/configure.in @@ -26,6 +26,7 @@ PKG_PROG_PKG_CONFIG AC_CHECK_HEADERS(getopt.h) AC_CHECK_HEADERS(sys/times.h) +AC_CHECK_FUNCS(sigaction) AC_MSG_CHECKING(whether to build shared libbarvinok) AC_ARG_ENABLE(shared_barvinok, diff --git a/iscc.c b/iscc.c index a114123..ecabb01 100644 --- a/iscc.c +++ b/iscc.c @@ -14,6 +14,49 @@ #include "config.h" +#ifdef HAVE_SIGACTION +#include + +static isl_ctx *main_ctx; + +static void handler(int signum) +{ + if (isl_ctx_aborted(main_ctx)) + exit(EXIT_FAILURE); + isl_ctx_abort(main_ctx); +} + +static struct sigaction sa_old; + +static void install_signal_handler(isl_ctx *ctx) +{ + struct sigaction sa; + + main_ctx = ctx; + + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_handler = &handler; + sa.sa_flags = SA_RESTART; + sigaction(SIGINT, &sa, &sa_old); +} + +static void remove_signal_handler(isl_ctx *ctx) +{ + sigaction(SIGINT, &sa_old, NULL); +} + +#else + +static void install_signal_handler(isl_ctx *ctx) +{ +} + +static void remove_signal_handler(isl_ctx *ctx) +{ +} + +#endif + #ifdef HAVE_CLOOG #include #endif @@ -2004,8 +2047,13 @@ static __isl_give isl_printer *read_line(struct isl_stream *s, only_print = 1; obj = read_expr(s, table); - if (obj.type == isl_obj_none || obj.v == NULL) + if (obj.type == isl_obj_none || obj.v == NULL) { + if (isl_ctx_last_error(s->ctx) == isl_error_abort) { + fprintf(stderr, "Interrupted\n"); + isl_ctx_reset_error(s->ctx); + } goto error; + } if (isl_stream_eat(s, ';')) goto error; @@ -2135,10 +2183,15 @@ int main(int argc, char **argv) register_named_ops(s); + install_signal_handler(ctx); + while (p && !s->eof) { + isl_ctx_resume(main_ctx); p = read_line(s, table, p, tty); } + remove_signal_handler(ctx); + isl_printer_free(p); isl_hash_table_foreach(ctx, table, free_cb, NULL); isl_hash_table_free(ctx, table); diff --git a/isl b/isl index 5958931..5d62e96 160000 --- a/isl +++ b/isl @@ -1 +1 @@ -Subproject commit 5958931f4fffe80ccbf82a99bb2995bca137396d +Subproject commit 5d62e96a2f406d00644db6e1711ad0fe042b9e06 -- 2.11.4.GIT