Bug Summary

File:tools/polly/lib/External/isl/isl_schedule_read.c
Warning:line 253, column 2
Value stored to 'key' is never read

Annotated Source Code

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