Coverage Report

Created: 2018-12-13 20:48

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_schedule_read.c
Line
Count
Source (jump to first uncovered line)
1
#include <isl/id.h>
2
#include <isl/val.h>
3
#include <isl/schedule.h>
4
#include <isl/stream.h>
5
#include <isl_schedule_private.h>
6
#include <isl_schedule_tree.h>
7
8
/* An enumeration of the various keys that may appear in a YAML mapping
9
 * of a schedule.
10
 */
11
enum isl_schedule_key {
12
  isl_schedule_key_error = -1,
13
  isl_schedule_key_child,
14
  isl_schedule_key_coincident,
15
  isl_schedule_key_context,
16
  isl_schedule_key_contraction,
17
  isl_schedule_key_domain,
18
  isl_schedule_key_expansion,
19
  isl_schedule_key_extension,
20
  isl_schedule_key_filter,
21
  isl_schedule_key_guard,
22
  isl_schedule_key_leaf,
23
  isl_schedule_key_mark,
24
  isl_schedule_key_options,
25
  isl_schedule_key_permutable,
26
  isl_schedule_key_schedule,
27
  isl_schedule_key_sequence,
28
  isl_schedule_key_set,
29
  isl_schedule_key_end
30
};
31
32
/* Textual representations of the YAML keys for an isl_schedule object.
33
 */
34
static char *key_str[] = {
35
  [isl_schedule_key_child] = "child",
36
  [isl_schedule_key_coincident] = "coincident",
37
  [isl_schedule_key_context] = "context",
38
  [isl_schedule_key_contraction] = "contraction",
39
  [isl_schedule_key_domain] = "domain",
40
  [isl_schedule_key_expansion] = "expansion",
41
  [isl_schedule_key_extension] = "extension",
42
  [isl_schedule_key_filter] = "filter",
43
  [isl_schedule_key_guard] = "guard",
44
  [isl_schedule_key_leaf] = "leaf",
45
  [isl_schedule_key_mark] = "mark",
46
  [isl_schedule_key_options] = "options",
47
  [isl_schedule_key_permutable] = "permutable",
48
  [isl_schedule_key_schedule] = "schedule",
49
  [isl_schedule_key_sequence] = "sequence",
50
  [isl_schedule_key_set] = "set",
51
};
52
53
#undef KEY
54
0
#define KEY enum isl_schedule_key
55
#undef KEY_ERROR
56
0
#define KEY_ERROR isl_schedule_key_error
57
#undef KEY_END
58
0
#define KEY_END isl_schedule_key_end
59
#include "extract_key.c"
60
61
static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
62
  __isl_keep isl_stream *s);
63
64
/* Read a subtree with context root node from "s".
65
 */
66
static __isl_give isl_schedule_tree *read_context(__isl_keep isl_stream *s)
67
0
{
68
0
  isl_set *context = NULL;
69
0
  isl_schedule_tree *tree;
70
0
  isl_ctx *ctx;
71
0
  struct isl_token *tok;
72
0
  enum isl_schedule_key key;
73
0
  char *str;
74
0
  int more;
75
0
76
0
  ctx = isl_stream_get_ctx(s);
77
0
78
0
  key = get_key(s);
79
0
80
0
  if (isl_stream_yaml_next(s) < 0)
81
0
    return NULL;
82
0
83
0
  tok = isl_stream_next_token(s);
84
0
  if (!tok) {
85
0
    isl_stream_error(s, NULL, "unexpected EOF");
86
0
    return NULL;
87
0
  }
88
0
  str = isl_token_get_str(ctx, tok);
89
0
  context = isl_set_read_from_str(ctx, str);
90
0
  free(str);
91
0
  isl_token_free(tok);
92
0
93
0
  more = isl_stream_yaml_next(s);
94
0
  if (more < 0)
95
0
    goto error;
96
0
  if (!more) {
97
0
    tree = isl_schedule_tree_from_context(context);
98
0
  } else {
99
0
    key = get_key(s);
100
0
    if (key != isl_schedule_key_child)
101
0
      isl_die(ctx, isl_error_invalid, "expecting child",
102
0
        goto error);
103
0
    if (isl_stream_yaml_next(s) < 0)
104
0
      goto error;
105
0
    tree = isl_stream_read_schedule_tree(s);
106
0
    tree = isl_schedule_tree_insert_context(tree, context);
107
0
  }
108
0
109
0
  return tree;
110
0
error:
111
0
  isl_set_free(context);
112
0
  return NULL;
113
0
}
114
115
/* Read a subtree with domain root node from "s".
116
 */
117
static __isl_give isl_schedule_tree *read_domain(__isl_keep isl_stream *s)
118
0
{
119
0
  isl_union_set *domain = NULL;
120
0
  isl_schedule_tree *tree;
121
0
  isl_ctx *ctx;
122
0
  struct isl_token *tok;
123
0
  enum isl_schedule_key key;
124
0
  char *str;
125
0
  int more;
126
0
127
0
  ctx = isl_stream_get_ctx(s);
128
0
129
0
  key = get_key(s);
130
0
131
0
  if (isl_stream_yaml_next(s) < 0)
132
0
    return NULL;
133
0
134
0
  tok = isl_stream_next_token(s);
135
0
  if (!tok) {
136
0
    isl_stream_error(s, NULL, "unexpected EOF");
137
0
    return NULL;
138
0
  }
139
0
  str = isl_token_get_str(ctx, tok);
140
0
  domain = isl_union_set_read_from_str(ctx, str);
141
0
  free(str);
142
0
  isl_token_free(tok);
143
0
144
0
  more = isl_stream_yaml_next(s);
145
0
  if (more < 0)
146
0
    goto error;
147
0
  if (!more) {
148
0
    tree = isl_schedule_tree_from_domain(domain);
149
0
  } else {
150
0
    key = get_key(s);
151
0
    if (key != isl_schedule_key_child)
152
0
      isl_die(ctx, isl_error_invalid, "expecting child",
153
0
        goto error);
154
0
    if (isl_stream_yaml_next(s) < 0)
155
0
      goto error;
156
0
    tree = isl_stream_read_schedule_tree(s);
157
0
    tree = isl_schedule_tree_insert_domain(tree, domain);
158
0
  }
159
0
160
0
  return tree;
161
0
error:
162
0
  isl_union_set_free(domain);
163
0
  return NULL;
164
0
}
165
166
/* Read a subtree with expansion root node from "s".
167
 */
168
static __isl_give isl_schedule_tree *read_expansion(isl_stream *s)
169
0
{
170
0
  isl_ctx *ctx;
171
0
  isl_union_pw_multi_aff *contraction = NULL;
172
0
  isl_union_map *expansion = NULL;
173
0
  isl_schedule_tree *tree = NULL;
174
0
  int more;
175
0
176
0
  ctx = isl_stream_get_ctx(s);
177
0
178
0
  do {
179
0
    struct isl_token *tok;
180
0
    enum isl_schedule_key key;
181
0
    char *str;
182
0
183
0
    key = get_key(s);
184
0
    if (isl_stream_yaml_next(s) < 0)
185
0
      goto error;
186
0
187
0
    switch (key) {
188
0
    case isl_schedule_key_contraction:
189
0
      isl_union_pw_multi_aff_free(contraction);
190
0
      tok = isl_stream_next_token(s);
191
0
      str = isl_token_get_str(ctx, tok);
192
0
      contraction = isl_union_pw_multi_aff_read_from_str(ctx,
193
0
                  str);
194
0
      free(str);
195
0
      isl_token_free(tok);
196
0
      if (!contraction)
197
0
        goto error;
198
0
      break;
199
0
    case isl_schedule_key_expansion:
200
0
      isl_union_map_free(expansion);
201
0
      tok = isl_stream_next_token(s);
202
0
      str = isl_token_get_str(ctx, tok);
203
0
      expansion = isl_union_map_read_from_str(ctx, str);
204
0
      free(str);
205
0
      isl_token_free(tok);
206
0
      if (!expansion)
207
0
        goto error;
208
0
      break;
209
0
    case isl_schedule_key_child:
210
0
      isl_schedule_tree_free(tree);
211
0
      tree = isl_stream_read_schedule_tree(s);
212
0
      if (!tree)
213
0
        goto error;
214
0
      break;
215
0
    default:
216
0
      isl_die(ctx, isl_error_invalid, "unexpected key",
217
0
        goto error);
218
0
    }
219
0
  } while ((more = isl_stream_yaml_next(s)) > 0);
220
0
221
0
  if (more < 0)
222
0
    goto error;
223
0
224
0
  if (!contraction)
225
0
    isl_die(ctx, isl_error_invalid, "missing contraction",
226
0
      goto error);
227
0
  if (!expansion)
228
0
    isl_die(ctx, isl_error_invalid, "missing expansion",
229
0
      goto error);
230
0
231
0
  if (!tree)
232
0
    return isl_schedule_tree_from_expansion(contraction, expansion);
233
0
  return isl_schedule_tree_insert_expansion(tree, contraction, expansion);
234
0
error:
235
0
  isl_schedule_tree_free(tree);
236
0
  isl_union_pw_multi_aff_free(contraction);
237
0
  isl_union_map_free(expansion);
238
0
  return NULL;
239
0
}
240
241
/* Read a subtree with extension root node from "s".
242
 */
243
static __isl_give isl_schedule_tree *read_extension(isl_stream *s)
244
0
{
245
0
  isl_union_map *extension = NULL;
246
0
  isl_schedule_tree *tree;
247
0
  isl_ctx *ctx;
248
0
  struct isl_token *tok;
249
0
  enum isl_schedule_key key;
250
0
  char *str;
251
0
  int more;
252
0
253
0
  ctx = isl_stream_get_ctx(s);
254
0
255
0
  key = get_key(s);
256
0
257
0
  if (isl_stream_yaml_next(s) < 0)
258
0
    return NULL;
259
0
260
0
  tok = isl_stream_next_token(s);
261
0
  if (!tok) {
262
0
    isl_stream_error(s, NULL, "unexpected EOF");
263
0
    return NULL;
264
0
  }
265
0
  str = isl_token_get_str(ctx, tok);
266
0
  extension = isl_union_map_read_from_str(ctx, str);
267
0
  free(str);
268
0
  isl_token_free(tok);
269
0
270
0
  more = isl_stream_yaml_next(s);
271
0
  if (more < 0)
272
0
    goto error;
273
0
  if (!more) {
274
0
    tree = isl_schedule_tree_from_extension(extension);
275
0
  } else {
276
0
    key = get_key(s);
277
0
    if (key != isl_schedule_key_child)
278
0
      isl_die(ctx, isl_error_invalid, "expecting child",
279
0
        goto error);
280
0
    if (isl_stream_yaml_next(s) < 0)
281
0
      goto error;
282
0
    tree = isl_stream_read_schedule_tree(s);
283
0
    tree = isl_schedule_tree_insert_extension(tree, extension);
284
0
  }
285
0
286
0
  return tree;
287
0
error:
288
0
  isl_union_map_free(extension);
289
0
  return NULL;
290
0
}
291
292
/* Read a subtree with filter root node from "s".
293
 */
294
static __isl_give isl_schedule_tree *read_filter(__isl_keep isl_stream *s)
295
0
{
296
0
  isl_union_set *filter = NULL;
297
0
  isl_schedule_tree *tree;
298
0
  isl_ctx *ctx;
299
0
  struct isl_token *tok;
300
0
  enum isl_schedule_key key;
301
0
  char *str;
302
0
  int more;
303
0
304
0
  ctx = isl_stream_get_ctx(s);
305
0
306
0
  key = get_key(s);
307
0
308
0
  if (isl_stream_yaml_next(s) < 0)
309
0
    return NULL;
310
0
311
0
  tok = isl_stream_next_token(s);
312
0
  if (!tok) {
313
0
    isl_stream_error(s, NULL, "unexpected EOF");
314
0
    return NULL;
315
0
  }
316
0
  str = isl_token_get_str(ctx, tok);
317
0
  filter = isl_union_set_read_from_str(ctx, str);
318
0
  free(str);
319
0
  isl_token_free(tok);
320
0
321
0
  more = isl_stream_yaml_next(s);
322
0
  if (more < 0)
323
0
    goto error;
324
0
  if (!more) {
325
0
    tree = isl_schedule_tree_from_filter(filter);
326
0
  } else {
327
0
    key = get_key(s);
328
0
    if (key != isl_schedule_key_child)
329
0
      isl_die(ctx, isl_error_invalid, "expecting child",
330
0
        goto error);
331
0
    if (isl_stream_yaml_next(s) < 0)
332
0
      goto error;
333
0
    tree = isl_stream_read_schedule_tree(s);
334
0
    tree = isl_schedule_tree_insert_filter(tree, filter);
335
0
  }
336
0
337
0
  return tree;
338
0
error:
339
0
  isl_union_set_free(filter);
340
0
  return NULL;
341
0
}
342
343
/* Read a subtree with guard root node from "s".
344
 */
345
static __isl_give isl_schedule_tree *read_guard(isl_stream *s)
346
0
{
347
0
  isl_set *guard = NULL;
348
0
  isl_schedule_tree *tree;
349
0
  isl_ctx *ctx;
350
0
  struct isl_token *tok;
351
0
  enum isl_schedule_key key;
352
0
  char *str;
353
0
  int more;
354
0
355
0
  ctx = isl_stream_get_ctx(s);
356
0
357
0
  key = get_key(s);
358
0
359
0
  if (isl_stream_yaml_next(s) < 0)
360
0
    return NULL;
361
0
362
0
  tok = isl_stream_next_token(s);
363
0
  if (!tok) {
364
0
    isl_stream_error(s, NULL, "unexpected EOF");
365
0
    return NULL;
366
0
  }
367
0
  str = isl_token_get_str(ctx, tok);
368
0
  guard = isl_set_read_from_str(ctx, str);
369
0
  free(str);
370
0
  isl_token_free(tok);
371
0
372
0
  more = isl_stream_yaml_next(s);
373
0
  if (more < 0)
374
0
    goto error;
375
0
  if (!more) {
376
0
    tree = isl_schedule_tree_from_guard(guard);
377
0
  } else {
378
0
    key = get_key(s);
379
0
    if (key != isl_schedule_key_child)
380
0
      isl_die(ctx, isl_error_invalid, "expecting child",
381
0
        goto error);
382
0
    if (isl_stream_yaml_next(s) < 0)
383
0
      goto error;
384
0
    tree = isl_stream_read_schedule_tree(s);
385
0
    tree = isl_schedule_tree_insert_guard(tree, guard);
386
0
  }
387
0
388
0
  return tree;
389
0
error:
390
0
  isl_set_free(guard);
391
0
  return NULL;
392
0
}
393
394
/* Read a subtree with mark root node from "s".
395
 */
396
static __isl_give isl_schedule_tree *read_mark(isl_stream *s)
397
0
{
398
0
  isl_id *mark;
399
0
  isl_schedule_tree *tree;
400
0
  isl_ctx *ctx;
401
0
  struct isl_token *tok;
402
0
  enum isl_schedule_key key;
403
0
  char *str;
404
0
  int more;
405
0
406
0
  ctx = isl_stream_get_ctx(s);
407
0
408
0
  key = get_key(s);
409
0
410
0
  if (isl_stream_yaml_next(s) < 0)
411
0
    return NULL;
412
0
413
0
  tok = isl_stream_next_token(s);
414
0
  if (!tok) {
415
0
    isl_stream_error(s, NULL, "unexpected EOF");
416
0
    return NULL;
417
0
  }
418
0
  str = isl_token_get_str(ctx, tok);
419
0
  mark = isl_id_alloc(ctx, str, NULL);
420
0
  free(str);
421
0
  isl_token_free(tok);
422
0
423
0
  more = isl_stream_yaml_next(s);
424
0
  if (more < 0)
425
0
    goto error;
426
0
  if (!more) {
427
0
    isl_die(ctx, isl_error_invalid, "expecting child",
428
0
      goto error);
429
0
  } else {
430
0
    key = get_key(s);
431
0
    if (key != isl_schedule_key_child)
432
0
      isl_die(ctx, isl_error_invalid, "expecting child",
433
0
        goto error);
434
0
    if (isl_stream_yaml_next(s) < 0)
435
0
      goto error;
436
0
    tree = isl_stream_read_schedule_tree(s);
437
0
    tree = isl_schedule_tree_insert_mark(tree, mark);
438
0
  }
439
0
440
0
  return tree;
441
0
error:
442
0
  isl_id_free(mark);
443
0
  return NULL;
444
0
}
445
446
/* Read a sequence of integers from "s" (representing the coincident
447
 * property of a band node).
448
 */
449
static __isl_give isl_val_list *read_coincident(__isl_keep isl_stream *s)
450
0
{
451
0
  isl_ctx *ctx;
452
0
  isl_val_list *list;
453
0
  int more;
454
0
455
0
  ctx = isl_stream_get_ctx(s);
456
0
457
0
  if (isl_stream_yaml_read_start_sequence(s) < 0)
458
0
    return NULL;
459
0
460
0
  list = isl_val_list_alloc(ctx, 0);
461
0
  while  ((more = isl_stream_yaml_next(s)) > 0) {
462
0
    isl_val *val;
463
0
464
0
    val = isl_stream_read_val(s);
465
0
    list = isl_val_list_add(list, val);
466
0
  }
467
0
468
0
  if (more < 0 || isl_stream_yaml_read_end_sequence(s))
469
0
    list = isl_val_list_free(list);
470
0
471
0
  return list;
472
0
}
473
474
/* Set the (initial) coincident properties of "band" according to
475
 * the (initial) elements of "coincident".
476
 */
477
static __isl_give isl_schedule_band *set_coincident(
478
  __isl_take isl_schedule_band *band, __isl_take isl_val_list *coincident)
479
0
{
480
0
  int i;
481
0
  int n, m;
482
0
483
0
  n = isl_schedule_band_n_member(band);
484
0
  m = isl_val_list_n_val(coincident);
485
0
486
0
  for (i = 0; i < n && i < m; ++i) {
487
0
    isl_val *v;
488
0
489
0
    v = isl_val_list_get_val(coincident, i);
490
0
    if (!v)
491
0
      band = isl_schedule_band_free(band);
492
0
    band = isl_schedule_band_member_set_coincident(band, i,
493
0
              !isl_val_is_zero(v));
494
0
    isl_val_free(v);
495
0
  }
496
0
  isl_val_list_free(coincident);
497
0
  return band;
498
0
}
499
500
/* Read a subtree with band root node from "s".
501
 */
502
static __isl_give isl_schedule_tree *read_band(isl_stream *s)
503
0
{
504
0
  isl_multi_union_pw_aff *schedule = NULL;
505
0
  isl_schedule_tree *tree = NULL;
506
0
  isl_val_list *coincident = NULL;
507
0
  isl_union_set *options = NULL;
508
0
  isl_ctx *ctx;
509
0
  isl_schedule_band *band;
510
0
  int permutable = 0;
511
0
  int more;
512
0
513
0
  ctx = isl_stream_get_ctx(s);
514
0
515
0
  do {
516
0
    struct isl_token *tok;
517
0
    enum isl_schedule_key key;
518
0
    char *str;
519
0
    isl_val *v;
520
0
521
0
    key = get_key(s);
522
0
    if (isl_stream_yaml_next(s) < 0)
523
0
      goto error;
524
0
525
0
    switch (key) {
526
0
    case isl_schedule_key_schedule:
527
0
      schedule = isl_multi_union_pw_aff_free(schedule);
528
0
      tok = isl_stream_next_token(s);
529
0
      if (!tok) {
530
0
        isl_stream_error(s, NULL, "unexpected EOF");
531
0
        goto error;
532
0
      }
533
0
      str = isl_token_get_str(ctx, tok);
534
0
      schedule = isl_multi_union_pw_aff_read_from_str(ctx,
535
0
                  str);
536
0
      free(str);
537
0
      isl_token_free(tok);
538
0
      if (!schedule)
539
0
        goto error;
540
0
      break;
541
0
    case isl_schedule_key_coincident:
542
0
      coincident = read_coincident(s);
543
0
      if (!coincident)
544
0
        goto error;
545
0
      break;
546
0
    case isl_schedule_key_permutable:
547
0
      v = isl_stream_read_val(s);
548
0
      permutable = !isl_val_is_zero(v);
549
0
      isl_val_free(v);
550
0
      break;
551
0
    case isl_schedule_key_options:
552
0
      isl_union_set_free(options);
553
0
      tok = isl_stream_next_token(s);
554
0
      str = isl_token_get_str(ctx, tok);
555
0
      options = isl_union_set_read_from_str(ctx, str);
556
0
      free(str);
557
0
      isl_token_free(tok);
558
0
      if (!options)
559
0
        goto error;
560
0
      break;
561
0
    case isl_schedule_key_child:
562
0
      isl_schedule_tree_free(tree);
563
0
      tree = isl_stream_read_schedule_tree(s);
564
0
      if (!tree)
565
0
        goto error;
566
0
      break;
567
0
    default:
568
0
      isl_die(ctx, isl_error_invalid, "unexpected key",
569
0
        goto error);
570
0
    }
571
0
  } while ((more = isl_stream_yaml_next(s)) > 0);
572
0
573
0
  if (more < 0)
574
0
    goto error;
575
0
576
0
  if (!schedule)
577
0
    isl_die(ctx, isl_error_invalid, "missing schedule", goto error);
578
0
579
0
  band = isl_schedule_band_from_multi_union_pw_aff(schedule);
580
0
  band = isl_schedule_band_set_permutable(band, permutable);
581
0
  if (coincident)
582
0
    band = set_coincident(band, coincident);
583
0
  if (options)
584
0
    band = isl_schedule_band_set_ast_build_options(band, options);
585
0
  if (tree)
586
0
    tree = isl_schedule_tree_insert_band(tree, band);
587
0
  else
588
0
    tree = isl_schedule_tree_from_band(band);
589
0
590
0
  return tree;
591
0
error:
592
0
  isl_val_list_free(coincident);
593
0
  isl_union_set_free(options);
594
0
  isl_schedule_tree_free(tree);
595
0
  isl_multi_union_pw_aff_free(schedule);
596
0
  return NULL;
597
0
}
598
599
/* Read a subtree with root node of type "type" from "s".
600
 * The node is represented by a sequence of children.
601
 */
602
static __isl_give isl_schedule_tree *read_children(isl_stream *s,
603
  enum isl_schedule_node_type type)
604
0
{
605
0
  isl_ctx *ctx;
606
0
  isl_schedule_tree_list *list;
607
0
  int more;
608
0
609
0
  ctx = isl_stream_get_ctx(s);
610
0
611
0
  isl_token_free(isl_stream_next_token(s));
612
0
613
0
  if (isl_stream_yaml_next(s) < 0)
614
0
    return NULL;
615
0
616
0
  if (isl_stream_yaml_read_start_sequence(s))
617
0
    return NULL;
618
0
619
0
  list = isl_schedule_tree_list_alloc(ctx, 0);
620
0
  while ((more = isl_stream_yaml_next(s)) > 0) {
621
0
    isl_schedule_tree *tree;
622
0
623
0
    tree = isl_stream_read_schedule_tree(s);
624
0
    list = isl_schedule_tree_list_add(list, tree);
625
0
  }
626
0
627
0
  if (more < 0 || isl_stream_yaml_read_end_sequence(s))
628
0
    list = isl_schedule_tree_list_free(list);
629
0
630
0
  return isl_schedule_tree_from_children(type, list);
631
0
}
632
633
/* Read a subtree with sequence root node from "s".
634
 */
635
static __isl_give isl_schedule_tree *read_sequence(isl_stream *s)
636
0
{
637
0
  return read_children(s, isl_schedule_node_sequence);
638
0
}
639
640
/* Read a subtree with set root node from "s".
641
 */
642
static __isl_give isl_schedule_tree *read_set(isl_stream *s)
643
0
{
644
0
  return read_children(s, isl_schedule_node_set);
645
0
}
646
647
/* Read a schedule (sub)tree from "s".
648
 *
649
 * We first determine the type of the root node based on the first
650
 * mapping key and then hand over to a function tailored to reading
651
 * nodes of this type.
652
 */
653
static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
654
  struct isl_stream *s)
655
0
{
656
0
  enum isl_schedule_key key;
657
0
  struct isl_token *tok;
658
0
  isl_schedule_tree *tree = NULL;
659
0
  int more;
660
0
661
0
  if (isl_stream_yaml_read_start_mapping(s))
662
0
    return NULL;
663
0
  more = isl_stream_yaml_next(s);
664
0
  if (more < 0)
665
0
    return NULL;
666
0
  if (!more) {
667
0
    isl_stream_error(s, NULL, "missing key");
668
0
    return NULL;
669
0
  }
670
0
671
0
  tok = isl_stream_next_token(s);
672
0
  key = extract_key(s, tok);
673
0
  isl_stream_push_token(s, tok);
674
0
  if (key < 0)
675
0
    return NULL;
676
0
  switch (key) {
677
0
  case isl_schedule_key_context:
678
0
    tree = read_context(s);
679
0
    break;
680
0
  case isl_schedule_key_domain:
681
0
    tree = read_domain(s);
682
0
    break;
683
0
  case isl_schedule_key_contraction:
684
0
  case isl_schedule_key_expansion:
685
0
    tree = read_expansion(s);
686
0
    break;
687
0
  case isl_schedule_key_extension:
688
0
    tree = read_extension(s);
689
0
    break;
690
0
  case isl_schedule_key_filter:
691
0
    tree = read_filter(s);
692
0
    break;
693
0
  case isl_schedule_key_guard:
694
0
    tree = read_guard(s);
695
0
    break;
696
0
  case isl_schedule_key_leaf:
697
0
    isl_token_free(isl_stream_next_token(s));
698
0
    tree = isl_schedule_tree_leaf(isl_stream_get_ctx(s));
699
0
    break;
700
0
  case isl_schedule_key_mark:
701
0
    tree = read_mark(s);
702
0
    break;
703
0
  case isl_schedule_key_sequence:
704
0
    tree = read_sequence(s);
705
0
    break;
706
0
  case isl_schedule_key_set:
707
0
    tree = read_set(s);
708
0
    break;
709
0
  case isl_schedule_key_schedule:
710
0
  case isl_schedule_key_coincident:
711
0
  case isl_schedule_key_options:
712
0
  case isl_schedule_key_permutable:
713
0
    tree = read_band(s);
714
0
    break;
715
0
  case isl_schedule_key_child:
716
0
    isl_die(isl_stream_get_ctx(s), isl_error_unsupported,
717
0
      "cannot identify node type", return NULL);
718
0
  case isl_schedule_key_end:
719
0
  case isl_schedule_key_error:
720
0
    return NULL;
721
0
  }
722
0
723
0
  if (isl_stream_yaml_read_end_mapping(s) < 0) {
724
0
    isl_stream_error(s, NULL, "unexpected extra elements");
725
0
    return isl_schedule_tree_free(tree);
726
0
  }
727
0
728
0
  return tree;
729
0
}
730
731
/* Read an isl_schedule from "s".
732
 */
733
__isl_give isl_schedule *isl_stream_read_schedule(isl_stream *s)
734
0
{
735
0
  isl_ctx *ctx;
736
0
  isl_schedule_tree *tree;
737
0
738
0
  if (!s)
739
0
    return NULL;
740
0
741
0
  ctx = isl_stream_get_ctx(s);
742
0
  tree = isl_stream_read_schedule_tree(s);
743
0
  return isl_schedule_from_schedule_tree(ctx, tree);
744
0
}
745
746
/* Read an isl_schedule from "input".
747
 */
748
__isl_give isl_schedule *isl_schedule_read_from_file(isl_ctx *ctx, FILE *input)
749
0
{
750
0
  struct isl_stream *s;
751
0
  isl_schedule *schedule;
752
0
753
0
  s = isl_stream_new_file(ctx, input);
754
0
  if (!s)
755
0
    return NULL;
756
0
  schedule = isl_stream_read_schedule(s);
757
0
  isl_stream_free(s);
758
0
759
0
  return schedule;
760
0
}
761
762
/* Read an isl_schedule from "str".
763
 */
764
__isl_give isl_schedule *isl_schedule_read_from_str(isl_ctx *ctx,
765
  const char *str)
766
0
{
767
0
  struct isl_stream *s;
768
0
  isl_schedule *schedule;
769
0
770
0
  s = isl_stream_new_str(ctx, str);
771
0
  if (!s)
772
0
    return NULL;
773
0
  schedule = isl_stream_read_schedule(s);
774
0
  isl_stream_free(s);
775
0
776
0
  return schedule;
777
0
}