scheduling: optionally split parallel rows in non-tilable bands
[platform/upstream/isl.git] / isl_stream.c
index 09ef60d..c544149 100644 (file)
@@ -127,6 +127,7 @@ static struct isl_stream* isl_stream_new(struct isl_ctx *ctx)
        s->col = 0;
        s->eof = 0;
        s->c = -1;
+       s->n_un = 0;
        for (i = 0; i < 5; ++i)
                s->tokens[i] = NULL;
        s->n_token = 0;
@@ -164,6 +165,8 @@ static int stream_getc(struct isl_stream *s)
        int c;
        if (s->eof)
                return -1;
+       if (s->n_un)
+               return s->c = s->un[--s->n_un];
        if (s->file)
                c = fgetc(s->file);
        else {
@@ -184,6 +187,13 @@ static int stream_getc(struct isl_stream *s)
        return c;
 }
 
+static void isl_stream_ungetc(struct isl_stream *s, int c)
+{
+       isl_assert(s->ctx, s->n_un < 5, return);
+       s->un[s->n_un++] = c;
+       s->c = -1;
+}
+
 static int isl_stream_getc(struct isl_stream *s)
 {
        int c;
@@ -191,29 +201,24 @@ static int isl_stream_getc(struct isl_stream *s)
        do {
                c = stream_getc(s);
                if (c != '\\')
-                       break;
+                       return c;
                c = stream_getc(s);
        } while (c == '\n');
 
-       return c;
-}
+       isl_stream_ungetc(s, c);
 
-static void isl_stream_ungetc(struct isl_stream *s, int c)
-{
-       if (s->file)
-               ungetc(c, s->file);
-       else
-               --s->str;
-       s->c = -1;
+       return '\\';
 }
 
 static int isl_stream_push_char(struct isl_stream *s, int c)
 {
        if (s->len >= s->size) {
+               char *buffer;
                s->size = (3*s->size)/2;
-               s->buffer = isl_realloc_array(s->ctx, s->buffer, char, s->size);
-               if (!s->buffer)
+               buffer = isl_realloc_array(s->ctx, s->buffer, char, s->size);
+               if (!buffer)
                        return -1;
+               s->buffer = buffer;
        }
        s->buffer[s->len++] = c;
        return 0;
@@ -245,6 +250,8 @@ static enum isl_token_type check_keywords(struct isl_stream *s)
                return ISL_TOKEN_INFTY;
        if (!strcasecmp(s->buffer, "NaN"))
                return ISL_TOKEN_NAN;
+       if (!strcasecmp(s->buffer, "min"))
+               return ISL_TOKEN_MIN;
        if (!strcasecmp(s->buffer, "max"))
                return ISL_TOKEN_MAX;
        if (!strcasecmp(s->buffer, "rat"))
@@ -253,6 +260,10 @@ static enum isl_token_type check_keywords(struct isl_stream *s)
                return ISL_TOKEN_TRUE;
        if (!strcasecmp(s->buffer, "false"))
                return ISL_TOKEN_FALSE;
+       if (!strcasecmp(s->buffer, "ceild"))
+               return ISL_TOKEN_CEILD;
+       if (!strcasecmp(s->buffer, "floord"))
+               return ISL_TOKEN_FLOORD;
 
        if (!s->keywords)
                return ISL_TOKEN_IDENT;
@@ -317,12 +328,12 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
        if (c == '(' ||
            c == ')' ||
            c == '+' ||
-           c == '/' ||
            c == '*' ||
            c == '%' ||
            c == '^' ||
            c == '=' ||
            c == '@' ||
+           c == '$' ||
            c == ',' ||
            c == '.' ||
            c == ';' ||
@@ -501,6 +512,32 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                        tok->u.s = strdup("||");
                return tok;
        }
+       if (c == '/') {
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               if ((c = isl_stream_getc(s)) != '\\' && c != -1) {
+                       tok->type = (enum isl_token_type) '/';
+                       isl_stream_ungetc(s, c);
+               } else {
+                       tok->u.s = strdup("/\\");
+                       tok->type = ISL_TOKEN_AND;
+               }
+               return tok;
+       }
+       if (c == '\\') {
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               if ((c = isl_stream_getc(s)) != '/' && c != -1) {
+                       tok->type = (enum isl_token_type) '\\';
+                       isl_stream_ungetc(s, c);
+               } else {
+                       tok->u.s = strdup("\\/");
+                       tok->type = ISL_TOKEN_OR;
+               }
+               return tok;
+       }
        if (c == '!') {
                tok = isl_token_new(s->ctx, line, col, old_line != line);
                if (!tok)