add isl_basic_set_read_from_str
authorSven Verdoolaege <sven@cs.kuleuven.be>
Thu, 25 Dec 2008 12:48:51 +0000 (13:48 +0100)
committerSven Verdoolaege <sven@cs.kuleuven.be>
Thu, 25 Dec 2008 12:48:51 +0000 (13:48 +0100)
include/isl_set.h
isl_input.c
isl_input_omega.c
isl_input_omega.h
isl_test.c
test_inputs/set.omega [new file with mode: 0644]

index 6324453..d1d4a25 100644 (file)
@@ -103,6 +103,8 @@ struct isl_basic_set *isl_basic_set_product(struct isl_basic_set_list *list);
 #define ISL_FORMAT_OMEGA               2
 struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx,
                FILE *input, unsigned nparam, unsigned input_format);
+struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
+               const char *str, unsigned nparam, unsigned input_format);
 struct isl_set *isl_set_read_from_file(struct isl_ctx *ctx,
                FILE *input, unsigned nparam, unsigned input_format);
 #define ISL_FORMAT_POLYLIB_CONSTRAINTS 3
index 81d54d0..2ee8b1e 100644 (file)
@@ -128,6 +128,16 @@ struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx,
                isl_assert(ctx, 0, return NULL);
 }
 
+struct isl_basic_set *isl_basic_set_read_from_str(struct isl_ctx *ctx,
+               const char *str, unsigned nparam, unsigned input_format)
+{
+       if (input_format == ISL_FORMAT_OMEGA) {
+               isl_assert(ctx, nparam == 0, return NULL);
+               return isl_basic_set_read_from_str_omega(ctx, str);
+       } else
+               isl_assert(ctx, 0, return NULL);
+}
+
 struct isl_basic_map *isl_basic_map_read_from_file(struct isl_ctx *ctx,
                FILE *input, unsigned nparam, unsigned input_format)
 {
index 7dea12f..6b59647 100644 (file)
@@ -112,6 +112,13 @@ static struct stream* stream_new_file(struct isl_ctx *ctx, FILE *file)
        return s;
 }
 
+static struct stream* stream_new_str(struct isl_ctx *ctx, const char *str)
+{
+    struct stream *s = stream_new(ctx);
+    s->str = str;
+    return s;
+}
+
 static int stream_getc(struct stream *s)
 {
        int c;
@@ -736,3 +743,29 @@ error:
        isl_basic_map_free(bmap);
        return NULL;
 }
+
+struct isl_basic_map *isl_basic_map_read_from_str_omega(
+               struct isl_ctx *ctx, const char *str)
+{
+       struct isl_basic_map *bmap;
+       struct stream *s = stream_new_str(ctx, str);
+       if (!s)
+               return NULL;
+       bmap = basic_map_read(s);
+       stream_free(s);
+       return bmap;
+}
+
+struct isl_basic_set *isl_basic_set_read_from_str_omega(
+               struct isl_ctx *ctx, const char *str)
+{
+       struct isl_basic_map *bmap;
+       bmap = isl_basic_map_read_from_str_omega(ctx, str);
+       if (!bmap)
+               return NULL;
+       isl_assert(ctx, isl_basic_map_n_in(bmap) == 0, goto error);
+       return (struct isl_basic_set *)bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
+}
index b064b7c..83c9f0e 100644 (file)
@@ -6,7 +6,11 @@
 
 struct isl_basic_set *isl_basic_set_read_from_file_omega(
                struct isl_ctx *ctx, FILE *input);
+struct isl_basic_set *isl_basic_set_read_from_str_omega(
+               struct isl_ctx *ctx, const char *str);
 struct isl_basic_map *isl_basic_map_read_from_file_omega(
                struct isl_ctx *ctx, FILE *input);
+struct isl_basic_map *isl_basic_map_read_from_str_omega(
+               struct isl_ctx *ctx, const char *str);
 
 #endif
index 1eae403..ca4b328 100644 (file)
@@ -7,6 +7,31 @@
 
 static char *srcdir;
 
+void test_read(struct isl_ctx *ctx)
+{
+       char filename[PATH_MAX];
+       FILE *input;
+       int n;
+       struct isl_basic_set *bset1, *bset2;
+       const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
+
+       n = snprintf(filename, sizeof(filename),
+                       "%s/test_inputs/set.omega", srcdir);
+       assert(n < sizeof(filename));
+       input = fopen(filename, "r");
+       assert(input);
+
+       bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA);
+       bset2 = isl_basic_set_read_from_str(ctx, str, 0, ISL_FORMAT_OMEGA);
+
+       assert(isl_basic_set_is_equal(bset1, bset2) == 1);
+
+       isl_basic_set_free(bset1);
+       isl_basic_set_free(bset2);
+
+       fclose(input);
+}
+
 /* Construct the basic set { [i] : 5 <= i <= N } */
 void test_construction(struct isl_ctx *ctx)
 {
@@ -193,6 +218,7 @@ int main()
        srcdir = getenv("srcdir");
 
        ctx = isl_ctx_alloc();
+       test_read(ctx);
        test_construction(ctx);
        test_application(ctx);
        test_affine_hull(ctx);
diff --git a/test_inputs/set.omega b/test_inputs/set.omega
new file mode 100644 (file)
index 0000000..ac8485f
--- /dev/null
@@ -0,0 +1 @@
+{[y]: Exists ( alpha : 2alpha = y)}