add isl_stream_read_map
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 13 Apr 2010 07:30:02 +0000 (09:30 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 13 Apr 2010 07:30:02 +0000 (09:30 +0200)
include/isl_stream.h
isl_input.c

index 2a896a2..2480e2f 100644 (file)
@@ -81,6 +81,7 @@ enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
        const char *name);
 
 struct isl_obj isl_stream_read_obj(struct isl_stream *s);
+__isl_give isl_map *isl_stream_read_map(struct isl_stream *s, int nparam);
 
 #if defined(__cplusplus)
 }
index 8b8480a..9d9788f 100644 (file)
@@ -1367,6 +1367,22 @@ struct isl_obj isl_stream_read_obj(struct isl_stream *s)
        return obj_read(s, -1);
 }
 
+__isl_give isl_map *isl_stream_read_map(struct isl_stream *s, int nparam)
+{
+       struct isl_obj obj;
+       struct isl_map *map;
+
+       obj = obj_read(s, nparam);
+       if (obj.v)
+               isl_assert(s->ctx, obj.type == isl_obj_map ||
+                                  obj.type == isl_obj_set, goto error);
+
+       return obj.v;
+error:
+       obj.type->free(obj.v);
+       return NULL;
+}
+
 static struct isl_basic_map *basic_map_read(struct isl_stream *s, int nparam)
 {
        struct isl_obj obj;
@@ -1448,27 +1464,25 @@ error:
 __isl_give isl_map *isl_map_read_from_file(struct isl_ctx *ctx,
                FILE *input, int nparam)
 {
-       struct isl_obj obj;
        struct isl_map *map;
        struct isl_stream *s = isl_stream_new_file(ctx, input);
        if (!s)
                return NULL;
-       obj = obj_read(s, nparam);
+       map = isl_stream_read_map(s, nparam);
        isl_stream_free(s);
-       return obj.v;
+       return map;
 }
 
 __isl_give isl_map *isl_map_read_from_str(struct isl_ctx *ctx,
                const char *str, int nparam)
 {
-       struct isl_obj obj;
        struct isl_map *map;
        struct isl_stream *s = isl_stream_new_str(ctx, str);
        if (!s)
                return NULL;
-       obj = obj_read(s, nparam);
+       map = isl_stream_read_map(s, nparam);
        isl_stream_free(s);
-       return obj.v;
+       return map;
 }
 
 __isl_give isl_set *isl_set_read_from_file(struct isl_ctx *ctx,