Coverage Report

Created: 2018-02-20 23:11

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