Coverage Report

Created: 2017-10-03 07:32

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