tree2scop.c: extract_kill: update kill expression rather than creating new one
[pet.git] / parse.c
blob11d9fc6cb9f91b300db5436470f4d67996452943
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2013-2014 Ecole Normale Superieure. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation
30 * are those of the authors and should not be interpreted as
31 * representing official policies, either expressed or implied, of
32 * Leiden University.
33 */
35 #include <stdlib.h>
36 #include <yaml.h>
38 #include "expr.h"
39 #include "loc.h"
40 #include "scop.h"
41 #include "scop_yaml.h"
42 #include "tree.h"
44 static char *extract_string(isl_ctx *ctx, yaml_document_t *document,
45 yaml_node_t *node)
47 if (node->type != YAML_SCALAR_NODE)
48 isl_die(ctx, isl_error_invalid, "expecting scalar node",
49 return NULL);
51 return strdup((char *) node->data.scalar.value);
54 static int extract_int(isl_ctx *ctx, yaml_document_t *document,
55 yaml_node_t *node)
57 if (node->type != YAML_SCALAR_NODE)
58 isl_die(ctx, isl_error_invalid, "expecting scalar node",
59 return -1);
61 return atoi((char *) node->data.scalar.value);
64 static double extract_double(isl_ctx *ctx, yaml_document_t *document,
65 yaml_node_t *node)
67 if (node->type != YAML_SCALAR_NODE)
68 isl_die(ctx, isl_error_invalid, "expecting scalar node",
69 return -1);
71 return strtod((char *) node->data.scalar.value, NULL);
74 static enum pet_expr_type extract_expr_type(isl_ctx *ctx,
75 yaml_document_t *document, yaml_node_t *node)
77 if (node->type != YAML_SCALAR_NODE)
78 isl_die(ctx, isl_error_invalid, "expecting scalar node",
79 return -1);
81 return pet_str_type((char *) node->data.scalar.value);
84 static enum pet_op_type extract_op(isl_ctx *ctx, yaml_document_t *document,
85 yaml_node_t *node)
87 if (node->type != YAML_SCALAR_NODE)
88 isl_die(ctx, isl_error_invalid, "expecting scalar node",
89 return -1);
91 return pet_str_op((char *) node->data.scalar.value);
94 static __isl_give isl_set *extract_set(isl_ctx *ctx, yaml_document_t *document,
95 yaml_node_t *node)
97 if (node->type != YAML_SCALAR_NODE)
98 isl_die(ctx, isl_error_invalid, "expecting scalar node",
99 return NULL);
101 return isl_set_read_from_str(ctx, (char *) node->data.scalar.value);
104 static __isl_give isl_id *extract_id(isl_ctx *ctx, yaml_document_t *document,
105 yaml_node_t *node)
107 if (node->type != YAML_SCALAR_NODE)
108 isl_die(ctx, isl_error_invalid, "expecting scalar node",
109 return NULL);
111 return isl_id_alloc(ctx, (char *) node->data.scalar.value, NULL);
114 static __isl_give isl_map *extract_map(isl_ctx *ctx, yaml_document_t *document,
115 yaml_node_t *node)
117 if (node->type != YAML_SCALAR_NODE)
118 isl_die(ctx, isl_error_invalid, "expecting scalar node",
119 return NULL);
121 return isl_map_read_from_str(ctx, (char *) node->data.scalar.value);
124 /* Extract an isl_union_set from "node".
126 static __isl_give isl_union_set *extract_union_set(isl_ctx *ctx,
127 yaml_document_t *document, yaml_node_t *node)
129 if (node->type != YAML_SCALAR_NODE)
130 isl_die(ctx, isl_error_invalid, "expecting scalar node",
131 return NULL);
133 return isl_union_set_read_from_str(ctx,
134 (char *) node->data.scalar.value);
137 /* Extract an isl_union_map from "node".
139 static __isl_give isl_union_map *extract_union_map(isl_ctx *ctx,
140 yaml_document_t *document, yaml_node_t *node)
142 if (node->type != YAML_SCALAR_NODE)
143 isl_die(ctx, isl_error_invalid, "expecting scalar node",
144 return NULL);
146 return isl_union_map_read_from_str(ctx,
147 (char *) node->data.scalar.value);
150 /* Extract an isl_val from "node".
152 static __isl_give isl_val *extract_val(isl_ctx *ctx, yaml_document_t *document,
153 yaml_node_t *node)
155 if (node->type != YAML_SCALAR_NODE)
156 isl_die(ctx, isl_error_invalid, "expecting scalar node",
157 return NULL);
159 return isl_val_read_from_str(ctx, (char *) node->data.scalar.value);
162 /* Extract an isl_multi_pw_aff from "node".
164 static __isl_give isl_multi_pw_aff *extract_multi_pw_aff(isl_ctx *ctx,
165 yaml_document_t *document, yaml_node_t *node)
167 if (node->type != YAML_SCALAR_NODE)
168 isl_die(ctx, isl_error_invalid, "expecting scalar node",
169 return NULL);
171 return isl_multi_pw_aff_read_from_str(ctx,
172 (char *) node->data.scalar.value);
175 /* Extract a pet_type from "node".
177 static struct pet_type *extract_type(isl_ctx *ctx,
178 yaml_document_t *document, yaml_node_t *node)
180 struct pet_type *type;
181 yaml_node_pair_t * pair;
183 if (node->type != YAML_MAPPING_NODE)
184 isl_die(ctx, isl_error_invalid, "expecting mapping",
185 return NULL);
187 type = isl_calloc_type(ctx, struct pet_type);
188 if (!type)
189 return NULL;
191 for (pair = node->data.mapping.pairs.start;
192 pair < node->data.mapping.pairs.top; ++pair) {
193 yaml_node_t *key, *value;
195 key = yaml_document_get_node(document, pair->key);
196 value = yaml_document_get_node(document, pair->value);
198 if (key->type != YAML_SCALAR_NODE)
199 isl_die(ctx, isl_error_invalid, "expecting scalar key",
200 return pet_type_free(type));
202 if (!strcmp((char *) key->data.scalar.value, "name"))
203 type->name = extract_string(ctx, document, value);
204 if (!strcmp((char *) key->data.scalar.value, "definition"))
205 type->definition = extract_string(ctx, document, value);
208 return type;
211 /* Extract a sequence of types from "node" and store them in scop->types.
213 static struct pet_scop *extract_types(isl_ctx *ctx,
214 yaml_document_t *document, yaml_node_t *node, struct pet_scop *scop)
216 int i;
217 yaml_node_item_t *item;
219 if (node->type != YAML_SEQUENCE_NODE)
220 isl_die(ctx, isl_error_invalid, "expecting sequence",
221 return NULL);
223 scop->n_type = node->data.sequence.items.top
224 - node->data.sequence.items.start;
225 scop->types = isl_calloc_array(ctx, struct pet_type *, scop->n_type);
226 if (!scop->types)
227 return pet_scop_free(scop);
229 for (item = node->data.sequence.items.start, i = 0;
230 item < node->data.sequence.items.top; ++item, ++i) {
231 yaml_node_t *n;
233 n = yaml_document_get_node(document, *item);
234 scop->types[i] = extract_type(ctx, document, n);
235 if (!scop->types[i])
236 return pet_scop_free(scop);
239 return scop;
242 static struct pet_array *extract_array(isl_ctx *ctx, yaml_document_t *document,
243 yaml_node_t *node)
245 struct pet_array *array;
246 yaml_node_pair_t * pair;
248 if (node->type != YAML_MAPPING_NODE)
249 isl_die(ctx, isl_error_invalid, "expecting mapping",
250 return NULL);
252 array = isl_calloc_type(ctx, struct pet_array);
253 if (!array)
254 return NULL;
256 for (pair = node->data.mapping.pairs.start;
257 pair < node->data.mapping.pairs.top; ++pair) {
258 yaml_node_t *key, *value;
260 key = yaml_document_get_node(document, pair->key);
261 value = yaml_document_get_node(document, pair->value);
263 if (key->type != YAML_SCALAR_NODE)
264 isl_die(ctx, isl_error_invalid, "expecting scalar key",
265 return pet_array_free(array));
267 if (!strcmp((char *) key->data.scalar.value, "context"))
268 array->context = extract_set(ctx, document, value);
269 if (!strcmp((char *) key->data.scalar.value, "extent"))
270 array->extent = extract_set(ctx, document, value);
271 if (!strcmp((char *) key->data.scalar.value, "value_bounds"))
272 array->value_bounds = extract_set(ctx, document, value);
273 if (!strcmp((char *) key->data.scalar.value, "element_type"))
274 array->element_type =
275 extract_string(ctx, document, value);
276 if (!strcmp((char *) key->data.scalar.value, "element_size"))
277 array->element_size = extract_int(ctx, document, value);
278 if (!strcmp((char *) key->data.scalar.value,
279 "element_is_record"))
280 array->element_is_record =
281 extract_int(ctx, document, value);
282 if (!strcmp((char *) key->data.scalar.value, "live_out"))
283 array->live_out = extract_int(ctx, document, value);
284 if (!strcmp((char *) key->data.scalar.value,
285 "uniquely_defined"))
286 array->uniquely_defined =
287 extract_int(ctx, document, value);
288 if (!strcmp((char *) key->data.scalar.value, "declared"))
289 array->declared = extract_int(ctx, document, value);
290 if (!strcmp((char *) key->data.scalar.value, "exposed"))
291 array->exposed = extract_int(ctx, document, value);
294 return array;
297 static struct pet_scop *extract_arrays(isl_ctx *ctx, yaml_document_t *document,
298 yaml_node_t *node, struct pet_scop *scop)
300 int i;
301 yaml_node_item_t *item;
303 if (node->type != YAML_SEQUENCE_NODE)
304 isl_die(ctx, isl_error_invalid, "expecting sequence",
305 return NULL);
307 scop->n_array = node->data.sequence.items.top
308 - node->data.sequence.items.start;
309 scop->arrays = isl_calloc_array(ctx, struct pet_array *, scop->n_array);
310 if (!scop->arrays)
311 return pet_scop_free(scop);
313 for (item = node->data.sequence.items.start, i = 0;
314 item < node->data.sequence.items.top; ++item, ++i) {
315 yaml_node_t *n;
317 n = yaml_document_get_node(document, *item);
318 scop->arrays[i] = extract_array(ctx, document, n);
319 if (!scop->arrays[i])
320 return pet_scop_free(scop);
323 return scop;
326 static __isl_give pet_expr *extract_expr(isl_ctx *ctx,
327 yaml_document_t *document, yaml_node_t *node);
329 static __isl_give pet_expr *extract_arguments(isl_ctx *ctx,
330 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
332 int i, n;
333 yaml_node_item_t *item;
335 if (node->type != YAML_SEQUENCE_NODE)
336 isl_die(ctx, isl_error_invalid, "expecting sequence",
337 return pet_expr_free(expr));
339 n = node->data.sequence.items.top - node->data.sequence.items.start;
340 expr = pet_expr_set_n_arg(expr, n);
342 for (item = node->data.sequence.items.start, i = 0;
343 item < node->data.sequence.items.top; ++item, ++i) {
344 yaml_node_t *n;
345 pet_expr *arg;
347 n = yaml_document_get_node(document, *item);
348 arg = extract_expr(ctx, document, n);
349 expr = pet_expr_set_arg(expr, i, arg);
352 return expr;
355 /* Extract pet_expr_double specific fields from "node" and
356 * update "expr" accordingly.
358 static __isl_give pet_expr *extract_expr_double(isl_ctx *ctx,
359 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
361 yaml_node_pair_t *pair;
362 double d = 0;
363 char *s = NULL;
365 for (pair = node->data.mapping.pairs.start;
366 pair < node->data.mapping.pairs.top; ++pair) {
367 yaml_node_t *key, *value;
369 key = yaml_document_get_node(document, pair->key);
370 value = yaml_document_get_node(document, pair->value);
372 if (key->type != YAML_SCALAR_NODE)
373 isl_die(ctx, isl_error_invalid, "expecting scalar key",
374 return pet_expr_free(expr));
376 if (!strcmp((char *) key->data.scalar.value, "value"))
377 d = extract_double(ctx, document, value);
378 if (!strcmp((char *) key->data.scalar.value, "string"))
379 s = extract_string(ctx, document, value);
382 expr = pet_expr_double_set(expr, d, s);
383 free(s);
385 return expr;
388 /* Extract pet_expr_access specific fields from "node" and
389 * update "expr" accordingly.
391 static __isl_give pet_expr *extract_expr_access(isl_ctx *ctx,
392 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
394 yaml_node_pair_t *pair;
396 for (pair = node->data.mapping.pairs.start;
397 pair < node->data.mapping.pairs.top; ++pair) {
398 yaml_node_t *key, *value;
400 key = yaml_document_get_node(document, pair->key);
401 value = yaml_document_get_node(document, pair->value);
403 if (key->type != YAML_SCALAR_NODE)
404 isl_die(ctx, isl_error_invalid, "expecting scalar key",
405 return pet_expr_free(expr));
407 if (!strcmp((char *) key->data.scalar.value, "relation"))
408 expr = pet_expr_access_set_access(expr,
409 extract_map(ctx, document, value));
410 if (!strcmp((char *) key->data.scalar.value, "index"))
411 expr = pet_expr_access_set_index(expr,
412 extract_multi_pw_aff(ctx, document, value));
413 if (!strcmp((char *) key->data.scalar.value, "reference"))
414 expr = pet_expr_access_set_ref_id(expr,
415 extract_id(ctx, document, value));
416 if (!strcmp((char *) key->data.scalar.value, "read"))
417 expr = pet_expr_access_set_read(expr,
418 extract_int(ctx, document, value));
419 if (!strcmp((char *) key->data.scalar.value, "write"))
420 expr = pet_expr_access_set_write(expr,
421 extract_int(ctx, document, value));
424 return expr;
427 /* Extract operation expression specific fields from "node" and
428 * update "expr" accordingly.
430 static __isl_give pet_expr *extract_expr_op(isl_ctx *ctx,
431 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
433 yaml_node_pair_t *pair;
435 for (pair = node->data.mapping.pairs.start;
436 pair < node->data.mapping.pairs.top; ++pair) {
437 yaml_node_t *key, *value;
439 key = yaml_document_get_node(document, pair->key);
440 value = yaml_document_get_node(document, pair->value);
442 if (key->type != YAML_SCALAR_NODE)
443 isl_die(ctx, isl_error_invalid, "expecting scalar key",
444 return pet_expr_free(expr));
446 if (!strcmp((char *) key->data.scalar.value, "operation"))
447 expr = pet_expr_op_set_type(expr,
448 extract_op(ctx, document, value));
451 return expr;
454 /* Extract pet_expr_call specific fields from "node" and
455 * update "expr" accordingly.
457 static __isl_give pet_expr *extract_expr_call(isl_ctx *ctx,
458 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
460 yaml_node_pair_t *pair;
462 for (pair = node->data.mapping.pairs.start;
463 pair < node->data.mapping.pairs.top; ++pair) {
464 yaml_node_t *key, *value;
466 key = yaml_document_get_node(document, pair->key);
467 value = yaml_document_get_node(document, pair->value);
469 if (key->type != YAML_SCALAR_NODE)
470 isl_die(ctx, isl_error_invalid, "expecting scalar key",
471 return pet_expr_free(expr));
473 if (!strcmp((char *) key->data.scalar.value, "name"))
474 expr = pet_expr_call_set_name(expr,
475 extract_string(ctx, document, value));
478 return expr;
481 /* Extract pet_expr_cast specific fields from "node" and
482 * update "expr" accordingly.
484 static __isl_give pet_expr *extract_expr_cast(isl_ctx *ctx,
485 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
487 yaml_node_pair_t *pair;
489 for (pair = node->data.mapping.pairs.start;
490 pair < node->data.mapping.pairs.top; ++pair) {
491 yaml_node_t *key, *value;
493 key = yaml_document_get_node(document, pair->key);
494 value = yaml_document_get_node(document, pair->value);
496 if (key->type != YAML_SCALAR_NODE)
497 isl_die(ctx, isl_error_invalid, "expecting scalar key",
498 return pet_expr_free(expr));
500 if (!strcmp((char *) key->data.scalar.value, "type_name"))
501 expr = pet_expr_cast_set_type_name(expr,
502 extract_string(ctx, document, value));
505 return expr;
508 /* Extract pet_expr_int specific fields from "node" and
509 * update "expr" accordingly.
511 static __isl_give pet_expr *extract_expr_int(isl_ctx *ctx,
512 yaml_document_t *document, yaml_node_t *node, __isl_take pet_expr *expr)
514 yaml_node_pair_t * pair;
516 for (pair = node->data.mapping.pairs.start;
517 pair < node->data.mapping.pairs.top; ++pair) {
518 yaml_node_t *key, *value;
520 key = yaml_document_get_node(document, pair->key);
521 value = yaml_document_get_node(document, pair->value);
523 if (key->type != YAML_SCALAR_NODE)
524 isl_die(ctx, isl_error_invalid, "expecting scalar key",
525 return pet_expr_free(expr));
527 if (!strcmp((char *) key->data.scalar.value, "value"))
528 expr = pet_expr_int_set_val(expr,
529 extract_val(ctx, document, value));
532 return expr;
535 /* Extract a pet_expr from "node".
537 * We first extract the type and arguments of the expression and
538 * then extract additional fields depending on the type.
540 static __isl_give pet_expr *extract_expr(isl_ctx *ctx,
541 yaml_document_t *document, yaml_node_t *node)
543 enum pet_expr_type type = pet_expr_error;
544 pet_expr *expr;
545 yaml_node_pair_t *pair;
547 if (node->type != YAML_MAPPING_NODE)
548 isl_die(ctx, isl_error_invalid, "expecting mapping",
549 return NULL);
551 for (pair = node->data.mapping.pairs.start;
552 pair < node->data.mapping.pairs.top; ++pair) {
553 yaml_node_t *key, *value;
555 key = yaml_document_get_node(document, pair->key);
556 value = yaml_document_get_node(document, pair->value);
558 if (key->type != YAML_SCALAR_NODE)
559 isl_die(ctx, isl_error_invalid, "expecting scalar key",
560 return pet_expr_free(expr));
562 if (!strcmp((char *) key->data.scalar.value, "type"))
563 type = extract_expr_type(ctx, document, value);
566 if (type == pet_expr_error)
567 isl_die(ctx, isl_error_invalid, "cannot determine type",
568 return NULL);
570 expr = pet_expr_alloc(ctx, type);
571 if (!expr)
572 return NULL;
574 for (pair = node->data.mapping.pairs.start;
575 pair < node->data.mapping.pairs.top; ++pair) {
576 yaml_node_t *key, *value;
578 key = yaml_document_get_node(document, pair->key);
579 value = yaml_document_get_node(document, pair->value);
581 if (!strcmp((char *) key->data.scalar.value, "arguments"))
582 expr = extract_arguments(ctx, document, value, expr);
583 if (!expr)
584 return NULL;
587 switch (type) {
588 case pet_expr_error:
589 isl_die(ctx, isl_error_internal, "unreachable code",
590 return NULL);
591 case pet_expr_access:
592 expr = extract_expr_access(ctx, document, node, expr);
593 break;
594 case pet_expr_double:
595 expr = extract_expr_double(ctx, document, node, expr);
596 break;
597 case pet_expr_call:
598 expr = extract_expr_call(ctx, document, node, expr);
599 break;
600 case pet_expr_cast:
601 expr = extract_expr_cast(ctx, document, node, expr);
602 break;
603 case pet_expr_int:
604 expr = extract_expr_int(ctx, document, node, expr);
605 break;
606 case pet_expr_op:
607 expr = extract_expr_op(ctx, document, node, expr);
608 break;
611 return expr;
614 /* Extract a pet_tree_type from "node".
616 static enum pet_tree_type extract_tree_type(isl_ctx *ctx,
617 yaml_document_t *document, yaml_node_t *node)
619 if (node->type != YAML_SCALAR_NODE)
620 isl_die(ctx, isl_error_invalid, "expecting scalar node",
621 return -1);
623 return pet_tree_str_type((char *) node->data.scalar.value);
626 static __isl_give pet_tree *extract_tree(isl_ctx *ctx,
627 yaml_document_t *document, yaml_node_t *node);
629 /* Extract a pet_tree of type pet_tree_block from "node".
631 static __isl_give pet_tree *extract_tree_block(isl_ctx *ctx,
632 yaml_document_t *document, yaml_node_t *node)
634 int block = 0;
635 int i, n;
636 yaml_node_pair_t *pair;
637 yaml_node_item_t *item;
638 yaml_node_t *children = NULL;
639 pet_tree *tree;
641 for (pair = node->data.mapping.pairs.start;
642 pair < node->data.mapping.pairs.top; ++pair) {
643 yaml_node_t *key, *value;
645 key = yaml_document_get_node(document, pair->key);
646 value = yaml_document_get_node(document, pair->value);
648 if (key->type != YAML_SCALAR_NODE)
649 isl_die(ctx, isl_error_invalid, "expecting scalar key",
650 return NULL);
652 if (!strcmp((char *) key->data.scalar.value, "block"))
653 block = extract_int(ctx, document, value);
654 if (!strcmp((char *) key->data.scalar.value, "children"))
655 children = value;
658 if (!children)
659 n = 0;
660 else
661 n = children->data.sequence.items.top -
662 children->data.sequence.items.start;
664 tree = pet_tree_new_block(ctx, block, n);
665 if (!children)
666 return tree;
668 for (item = children->data.sequence.items.start, i = 0;
669 item < children->data.sequence.items.top; ++item, ++i) {
670 yaml_node_t *n;
671 pet_tree *child;
673 n = yaml_document_get_node(document, *item);
674 child = extract_tree(ctx, document, n);
675 tree = pet_tree_block_add_child(tree, child);
678 return tree;
681 /* Extract a pet_tree of type pet_tree_decl from "node".
683 static __isl_give pet_tree *extract_tree_decl(isl_ctx *ctx,
684 yaml_document_t *document, yaml_node_t *node)
686 yaml_node_pair_t *pair;
687 pet_expr *var = NULL;
689 for (pair = node->data.mapping.pairs.start;
690 pair < node->data.mapping.pairs.top; ++pair) {
691 yaml_node_t *key, *value;
693 key = yaml_document_get_node(document, pair->key);
694 value = yaml_document_get_node(document, pair->value);
696 if (key->type != YAML_SCALAR_NODE)
697 isl_die(ctx, isl_error_invalid, "expecting scalar key",
698 return NULL);
700 if (!strcmp((char *) key->data.scalar.value, "variable")) {
701 var = extract_expr(ctx, document, value);
702 if (!var)
703 return NULL;
707 if (!var)
708 isl_die(ctx, isl_error_invalid,
709 "no variable field", return NULL);
711 return pet_tree_new_decl(var);
714 /* Extract a pet_tree of type pet_tree_decl_init from "node".
716 static __isl_give pet_tree *extract_tree_decl_init(isl_ctx *ctx,
717 yaml_document_t *document, yaml_node_t *node)
719 yaml_node_pair_t *pair;
720 pet_expr *var = NULL;
721 pet_expr *init = NULL;
723 for (pair = node->data.mapping.pairs.start;
724 pair < node->data.mapping.pairs.top; ++pair) {
725 yaml_node_t *key, *value;
727 key = yaml_document_get_node(document, pair->key);
728 value = yaml_document_get_node(document, pair->value);
730 if (key->type != YAML_SCALAR_NODE)
731 isl_die(ctx, isl_error_invalid, "expecting scalar key",
732 return NULL);
734 if (!strcmp((char *) key->data.scalar.value, "variable")) {
735 var = extract_expr(ctx, document, value);
736 if (!var)
737 goto error;
739 if (!strcmp((char *) key->data.scalar.value,
740 "initialization")) {
741 init = extract_expr(ctx, document, value);
742 if (!init)
743 goto error;
747 if (!var)
748 isl_die(ctx, isl_error_invalid,
749 "no variable field", goto error);
750 if (!init)
751 isl_die(ctx, isl_error_invalid,
752 "no initialization field", goto error);
754 return pet_tree_new_decl_init(var, init);
755 error:
756 pet_expr_free(var);
757 pet_expr_free(init);
758 return NULL;
761 /* Extract a pet_tree of type pet_tree_expr from "node".
763 static __isl_give pet_tree *extract_tree_expr(isl_ctx *ctx,
764 yaml_document_t *document, yaml_node_t *node)
766 yaml_node_pair_t *pair;
767 pet_expr *expr = NULL;
769 for (pair = node->data.mapping.pairs.start;
770 pair < node->data.mapping.pairs.top; ++pair) {
771 yaml_node_t *key, *value;
773 key = yaml_document_get_node(document, pair->key);
774 value = yaml_document_get_node(document, pair->value);
776 if (key->type != YAML_SCALAR_NODE)
777 isl_die(ctx, isl_error_invalid, "expecting scalar key",
778 return NULL);
780 if (!strcmp((char *) key->data.scalar.value, "expr")) {
781 expr = extract_expr(ctx, document, value);
782 if (!expr)
783 return NULL;
787 if (!expr)
788 isl_die(ctx, isl_error_invalid,
789 "no expr field", return NULL);
791 return pet_tree_new_expr(expr);
794 /* Extract a pet_tree of type pet_tree_while from "node".
796 static __isl_give pet_tree *extract_tree_while(isl_ctx *ctx,
797 yaml_document_t *document, yaml_node_t *node)
799 yaml_node_pair_t *pair;
800 pet_expr *cond = NULL;
801 pet_tree *body = NULL;
803 for (pair = node->data.mapping.pairs.start;
804 pair < node->data.mapping.pairs.top; ++pair) {
805 yaml_node_t *key, *value;
807 key = yaml_document_get_node(document, pair->key);
808 value = yaml_document_get_node(document, pair->value);
810 if (key->type != YAML_SCALAR_NODE)
811 isl_die(ctx, isl_error_invalid, "expecting scalar key",
812 return NULL);
814 if (!strcmp((char *) key->data.scalar.value, "condition")) {
815 cond = extract_expr(ctx, document, value);
816 if (!cond)
817 goto error;
819 if (!strcmp((char *) key->data.scalar.value, "body")) {
820 body = extract_tree(ctx, document, value);
821 if (!body)
822 goto error;
826 if (!cond)
827 isl_die(ctx, isl_error_invalid,
828 "no condition field", goto error);
829 if (!body)
830 isl_die(ctx, isl_error_invalid,
831 "no body field", goto error);
833 return pet_tree_new_while(cond, body);
834 error:
835 pet_expr_free(cond);
836 pet_tree_free(body);
837 return NULL;
840 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
842 static __isl_give pet_tree *extract_tree_infinite_loop(isl_ctx *ctx,
843 yaml_document_t *document, yaml_node_t *node)
845 yaml_node_pair_t *pair;
846 pet_tree *body;
848 for (pair = node->data.mapping.pairs.start;
849 pair < node->data.mapping.pairs.top; ++pair) {
850 yaml_node_t *key, *value;
852 key = yaml_document_get_node(document, pair->key);
853 value = yaml_document_get_node(document, pair->value);
855 if (key->type != YAML_SCALAR_NODE)
856 isl_die(ctx, isl_error_invalid, "expecting scalar key",
857 return NULL);
859 if (!strcmp((char *) key->data.scalar.value, "body")) {
860 body = extract_tree(ctx, document, value);
861 if (!body)
862 return NULL;
866 if (!body)
867 isl_die(ctx, isl_error_invalid,
868 "no body field", return NULL);
870 return pet_tree_new_infinite_loop(body);
873 /* Extract a pet_tree of type pet_tree_if from "node".
875 static __isl_give pet_tree *extract_tree_if(isl_ctx *ctx,
876 yaml_document_t *document, yaml_node_t *node)
878 yaml_node_pair_t *pair;
879 pet_expr *cond = NULL;
880 pet_tree *then_body = NULL;
882 for (pair = node->data.mapping.pairs.start;
883 pair < node->data.mapping.pairs.top; ++pair) {
884 yaml_node_t *key, *value;
886 key = yaml_document_get_node(document, pair->key);
887 value = yaml_document_get_node(document, pair->value);
889 if (key->type != YAML_SCALAR_NODE)
890 isl_die(ctx, isl_error_invalid, "expecting scalar key",
891 return NULL);
893 if (!strcmp((char *) key->data.scalar.value, "condition")) {
894 cond = extract_expr(ctx, document, value);
895 if (!cond)
896 goto error;
898 if (!strcmp((char *) key->data.scalar.value, "then")) {
899 then_body = extract_tree(ctx, document, value);
900 if (!then_body)
901 goto error;
905 if (!cond)
906 isl_die(ctx, isl_error_invalid,
907 "no condition field", goto error);
908 if (!then_body)
909 isl_die(ctx, isl_error_invalid,
910 "no then body", goto error);
912 return pet_tree_new_if(cond, then_body);
913 error:
914 pet_expr_free(cond);
915 pet_tree_free(then_body);
916 return NULL;
919 /* Extract a pet_tree of type pet_tree_if_else from "node".
921 static __isl_give pet_tree *extract_tree_if_else(isl_ctx *ctx,
922 yaml_document_t *document, yaml_node_t *node)
924 yaml_node_pair_t *pair;
925 pet_expr *cond = NULL;
926 pet_tree *then_body = NULL;
927 pet_tree *else_body = NULL;
929 for (pair = node->data.mapping.pairs.start;
930 pair < node->data.mapping.pairs.top; ++pair) {
931 yaml_node_t *key, *value;
933 key = yaml_document_get_node(document, pair->key);
934 value = yaml_document_get_node(document, pair->value);
936 if (key->type != YAML_SCALAR_NODE)
937 isl_die(ctx, isl_error_invalid, "expecting scalar key",
938 return NULL);
940 if (!strcmp((char *) key->data.scalar.value, "condition")) {
941 cond = extract_expr(ctx, document, value);
942 if (!cond)
943 goto error;
945 if (!strcmp((char *) key->data.scalar.value, "then")) {
946 then_body = extract_tree(ctx, document, value);
947 if (!then_body)
948 goto error;
950 if (!strcmp((char *) key->data.scalar.value, "else")) {
951 else_body = extract_tree(ctx, document, value);
952 if (!else_body)
953 goto error;
957 if (!cond)
958 isl_die(ctx, isl_error_invalid,
959 "no condition field", goto error);
960 if (!then_body)
961 isl_die(ctx, isl_error_invalid,
962 "no then body", goto error);
963 if (!else_body)
964 isl_die(ctx, isl_error_invalid,
965 "no else body", goto error);
967 return pet_tree_new_if_else(cond, then_body, else_body);
968 error:
969 pet_expr_free(cond);
970 pet_tree_free(then_body);
971 pet_tree_free(else_body);
972 return NULL;
975 /* Extract a pet_tree of type pet_tree_for from "node".
977 static __isl_give pet_tree *extract_tree_for(isl_ctx *ctx,
978 yaml_document_t *document, yaml_node_t *node)
980 yaml_node_pair_t *pair;
981 int declared = 0;
982 int independent = 0;
983 pet_expr *iv = NULL;
984 pet_expr *init = NULL;
985 pet_expr *cond = NULL;
986 pet_expr *inc = NULL;
987 pet_tree *body = NULL;
989 for (pair = node->data.mapping.pairs.start;
990 pair < node->data.mapping.pairs.top; ++pair) {
991 yaml_node_t *key, *value;
993 key = yaml_document_get_node(document, pair->key);
994 value = yaml_document_get_node(document, pair->value);
996 if (key->type != YAML_SCALAR_NODE)
997 isl_die(ctx, isl_error_invalid, "expecting scalar key",
998 return NULL);
1000 if (!strcmp((char *) key->data.scalar.value, "declared"))
1001 declared = extract_int(ctx, document, value);
1002 if (!strcmp((char *) key->data.scalar.value, "independent"))
1003 independent = extract_int(ctx, document, value);
1004 if (!strcmp((char *) key->data.scalar.value, "variable")) {
1005 iv = extract_expr(ctx, document, value);
1006 if (!iv)
1007 goto error;
1009 if (!strcmp((char *) key->data.scalar.value,
1010 "initialization")) {
1011 init = extract_expr(ctx, document, value);
1012 if (!init)
1013 goto error;
1015 if (!strcmp((char *) key->data.scalar.value, "condition")) {
1016 cond = extract_expr(ctx, document, value);
1017 if (!cond)
1018 goto error;
1020 if (!strcmp((char *) key->data.scalar.value, "increment")) {
1021 inc = extract_expr(ctx, document, value);
1022 if (!inc)
1023 goto error;
1025 if (!strcmp((char *) key->data.scalar.value, "body")) {
1026 body = extract_tree(ctx, document, value);
1027 if (!body)
1028 goto error;
1032 if (!iv)
1033 isl_die(ctx, isl_error_invalid,
1034 "no variable field", goto error);
1035 if (!init)
1036 isl_die(ctx, isl_error_invalid,
1037 "no initialization field", goto error);
1038 if (!cond)
1039 isl_die(ctx, isl_error_invalid,
1040 "no condition field", goto error);
1041 if (!inc)
1042 isl_die(ctx, isl_error_invalid,
1043 "no increment field", goto error);
1044 if (!body)
1045 isl_die(ctx, isl_error_invalid,
1046 "no body field", goto error);
1048 return pet_tree_new_for(independent, declared, iv, init, cond, inc,
1049 body);
1050 error:
1051 pet_expr_free(iv);
1052 pet_expr_free(init);
1053 pet_expr_free(cond);
1054 pet_expr_free(inc);
1055 pet_tree_free(body);
1056 return NULL;
1059 /* Extract a pet_tree from "node".
1061 * We first extract the type of the pet_tree and then call
1062 * the appropriate function to extract and construct a pet_tree
1063 * of that type.
1065 static __isl_give pet_tree *extract_tree(isl_ctx *ctx,
1066 yaml_document_t *document, yaml_node_t *node)
1068 enum pet_tree_type type = pet_tree_error;
1069 pet_tree *tree;
1070 yaml_node_pair_t *pair;
1072 if (node->type != YAML_MAPPING_NODE)
1073 isl_die(ctx, isl_error_invalid, "expecting mapping",
1074 return NULL);
1076 for (pair = node->data.mapping.pairs.start;
1077 pair < node->data.mapping.pairs.top; ++pair) {
1078 yaml_node_t *key, *value;
1080 key = yaml_document_get_node(document, pair->key);
1081 value = yaml_document_get_node(document, pair->value);
1083 if (key->type != YAML_SCALAR_NODE)
1084 isl_die(ctx, isl_error_invalid, "expecting scalar key",
1085 return pet_tree_free(tree));
1087 if (!strcmp((char *) key->data.scalar.value, "type"))
1088 type = extract_tree_type(ctx, document, value);
1091 if (type == pet_tree_error)
1092 isl_die(ctx, isl_error_invalid, "cannot determine type",
1093 return NULL);
1095 switch (type) {
1096 case pet_tree_error:
1097 return NULL;
1098 case pet_tree_block:
1099 tree = extract_tree_block(ctx, document, node);
1100 break;
1101 case pet_tree_break:
1102 tree = pet_tree_new_break(ctx);
1103 break;
1104 case pet_tree_continue:
1105 tree = pet_tree_new_continue(ctx);
1106 break;
1107 case pet_tree_decl:
1108 tree = extract_tree_decl(ctx, document, node);
1109 break;
1110 case pet_tree_decl_init:
1111 tree = extract_tree_decl_init(ctx, document, node);
1112 break;
1113 case pet_tree_expr:
1114 tree = extract_tree_expr(ctx, document, node);
1115 break;
1116 case pet_tree_for:
1117 tree = extract_tree_for(ctx, document, node);
1118 break;
1119 case pet_tree_while:
1120 tree = extract_tree_while(ctx, document, node);
1121 break;
1122 case pet_tree_infinite_loop:
1123 tree = extract_tree_infinite_loop(ctx, document, node);
1124 break;
1125 case pet_tree_if:
1126 tree = extract_tree_if(ctx, document, node);
1127 break;
1128 case pet_tree_if_else:
1129 tree = extract_tree_if_else(ctx, document, node);
1130 break;
1133 return tree;
1136 static struct pet_stmt *extract_stmt_arguments(isl_ctx *ctx,
1137 yaml_document_t *document, yaml_node_t *node, struct pet_stmt *stmt)
1139 int i;
1140 yaml_node_item_t *item;
1142 if (node->type != YAML_SEQUENCE_NODE)
1143 isl_die(ctx, isl_error_invalid, "expecting sequence",
1144 return pet_stmt_free(stmt));
1146 stmt->n_arg = node->data.sequence.items.top
1147 - node->data.sequence.items.start;
1148 stmt->args = isl_calloc_array(ctx, pet_expr *, stmt->n_arg);
1149 if (!stmt->args)
1150 return pet_stmt_free(stmt);
1152 for (item = node->data.sequence.items.start, i = 0;
1153 item < node->data.sequence.items.top; ++item, ++i) {
1154 yaml_node_t *n;
1156 n = yaml_document_get_node(document, *item);
1157 stmt->args[i] = extract_expr(ctx, document, n);
1158 if (!stmt->args[i])
1159 return pet_stmt_free(stmt);
1162 return stmt;
1165 static struct pet_stmt *extract_stmt(isl_ctx *ctx, yaml_document_t *document,
1166 yaml_node_t *node)
1168 struct pet_stmt *stmt;
1169 yaml_node_pair_t * pair;
1170 int line = -1;
1171 unsigned start = 0, end = 0;
1172 char *indent = NULL;
1174 if (node->type != YAML_MAPPING_NODE)
1175 isl_die(ctx, isl_error_invalid, "expecting mapping",
1176 return NULL);
1178 stmt = isl_calloc_type(ctx, struct pet_stmt);
1179 if (!stmt)
1180 return NULL;
1182 stmt->loc = &pet_loc_dummy;
1184 for (pair = node->data.mapping.pairs.start;
1185 pair < node->data.mapping.pairs.top; ++pair) {
1186 yaml_node_t *key, *value;
1188 key = yaml_document_get_node(document, pair->key);
1189 value = yaml_document_get_node(document, pair->value);
1191 if (key->type != YAML_SCALAR_NODE)
1192 isl_die(ctx, isl_error_invalid, "expecting scalar key",
1193 return pet_stmt_free(stmt));
1195 if (!strcmp((char *) key->data.scalar.value, "indent"))
1196 indent = extract_string(ctx, document, value);
1197 if (!strcmp((char *) key->data.scalar.value, "line"))
1198 line = extract_int(ctx, document, value);
1199 if (!strcmp((char *) key->data.scalar.value, "start"))
1200 start = extract_int(ctx, document, value);
1201 if (!strcmp((char *) key->data.scalar.value, "end"))
1202 end = extract_int(ctx, document, value);
1203 if (!strcmp((char *) key->data.scalar.value, "domain"))
1204 stmt->domain = extract_set(ctx, document, value);
1205 if (!strcmp((char *) key->data.scalar.value, "schedule"))
1206 stmt->schedule = extract_map(ctx, document, value);
1207 if (!strcmp((char *) key->data.scalar.value, "body"))
1208 stmt->body = extract_tree(ctx, document, value);
1210 if (!strcmp((char *) key->data.scalar.value, "arguments"))
1211 stmt = extract_stmt_arguments(ctx, document,
1212 value, stmt);
1213 if (!stmt)
1214 return NULL;
1217 if (!indent)
1218 indent = strdup("");
1219 stmt->loc = pet_loc_alloc(ctx, start, end, line, indent);
1220 if (!stmt->loc)
1221 return pet_stmt_free(stmt);
1223 return stmt;
1226 static struct pet_scop *extract_statements(isl_ctx *ctx,
1227 yaml_document_t *document, yaml_node_t *node, struct pet_scop *scop)
1229 int i;
1230 yaml_node_item_t *item;
1232 if (node->type != YAML_SEQUENCE_NODE)
1233 isl_die(ctx, isl_error_invalid, "expecting sequence",
1234 return NULL);
1236 scop->n_stmt = node->data.sequence.items.top
1237 - node->data.sequence.items.start;
1238 scop->stmts = isl_calloc_array(ctx, struct pet_stmt *, scop->n_stmt);
1239 if (!scop->stmts)
1240 return pet_scop_free(scop);
1242 for (item = node->data.sequence.items.start, i = 0;
1243 item < node->data.sequence.items.top; ++item, ++i) {
1244 yaml_node_t *n;
1246 n = yaml_document_get_node(document, *item);
1247 scop->stmts[i] = extract_stmt(ctx, document, n);
1248 if (!scop->stmts[i])
1249 return pet_scop_free(scop);
1252 return scop;
1255 /* Extract a pet_implication from "node".
1257 static struct pet_implication *extract_implication(isl_ctx *ctx,
1258 yaml_document_t *document, yaml_node_t *node)
1260 struct pet_implication *implication;
1261 yaml_node_pair_t * pair;
1263 if (node->type != YAML_MAPPING_NODE)
1264 isl_die(ctx, isl_error_invalid, "expecting mapping",
1265 return NULL);
1267 implication = isl_calloc_type(ctx, struct pet_implication);
1268 if (!implication)
1269 return NULL;
1271 for (pair = node->data.mapping.pairs.start;
1272 pair < node->data.mapping.pairs.top; ++pair) {
1273 yaml_node_t *key, *value;
1275 key = yaml_document_get_node(document, pair->key);
1276 value = yaml_document_get_node(document, pair->value);
1278 if (key->type != YAML_SCALAR_NODE)
1279 isl_die(ctx, isl_error_invalid, "expecting scalar key",
1280 return pet_implication_free(implication));
1282 if (!strcmp((char *) key->data.scalar.value, "satisfied"))
1283 implication->satisfied =
1284 extract_int(ctx, document, value);
1285 if (!strcmp((char *) key->data.scalar.value, "extension"))
1286 implication->extension =
1287 extract_map(ctx, document, value);
1290 return implication;
1293 /* Extract a sequence of implications from "node" and
1294 * store them in scop->implications.
1296 static struct pet_scop *extract_implications(isl_ctx *ctx,
1297 yaml_document_t *document, yaml_node_t *node, struct pet_scop *scop)
1299 int i;
1300 yaml_node_item_t *item;
1302 if (node->type != YAML_SEQUENCE_NODE)
1303 isl_die(ctx, isl_error_invalid, "expecting sequence",
1304 return NULL);
1306 scop->n_implication = node->data.sequence.items.top
1307 - node->data.sequence.items.start;
1308 scop->implications = isl_calloc_array(ctx, struct pet_implication *,
1309 scop->n_implication);
1310 if (!scop->implications)
1311 return pet_scop_free(scop);
1313 for (item = node->data.sequence.items.start, i = 0;
1314 item < node->data.sequence.items.top; ++item, ++i) {
1315 yaml_node_t *n;
1317 n = yaml_document_get_node(document, *item);
1318 scop->implications[i] = extract_implication(ctx, document, n);
1319 if (!scop->implications[i])
1320 return pet_scop_free(scop);
1323 return scop;
1326 /* Extract a pet_independence from "node".
1328 static struct pet_independence *extract_independence(isl_ctx *ctx,
1329 yaml_document_t *document, yaml_node_t *node)
1331 struct pet_independence *independence;
1332 yaml_node_pair_t * pair;
1334 if (node->type != YAML_MAPPING_NODE)
1335 isl_die(ctx, isl_error_invalid, "expecting mapping",
1336 return NULL);
1338 independence = isl_calloc_type(ctx, struct pet_independence);
1339 if (!independence)
1340 return NULL;
1342 for (pair = node->data.mapping.pairs.start;
1343 pair < node->data.mapping.pairs.top; ++pair) {
1344 yaml_node_t *key, *value;
1346 key = yaml_document_get_node(document, pair->key);
1347 value = yaml_document_get_node(document, pair->value);
1349 if (key->type != YAML_SCALAR_NODE)
1350 isl_die(ctx, isl_error_invalid, "expecting scalar key",
1351 return pet_independence_free(independence));
1353 if (!strcmp((char *) key->data.scalar.value, "filter"))
1354 independence->filter =
1355 extract_union_map(ctx, document, value);
1356 if (!strcmp((char *) key->data.scalar.value, "local"))
1357 independence->local =
1358 extract_union_set(ctx, document, value);
1361 if (!independence->filter)
1362 isl_die(ctx, isl_error_invalid, "no filter field",
1363 return pet_independence_free(independence));
1364 if (!independence->local)
1365 isl_die(ctx, isl_error_invalid, "no local field",
1366 return pet_independence_free(independence));
1368 return independence;
1371 /* Extract a sequence of independences from "node" and
1372 * store them in scop->independences.
1374 static struct pet_scop *extract_independences(isl_ctx *ctx,
1375 yaml_document_t *document, yaml_node_t *node, struct pet_scop *scop)
1377 int i;
1378 yaml_node_item_t *item;
1380 if (node->type != YAML_SEQUENCE_NODE)
1381 isl_die(ctx, isl_error_invalid, "expecting sequence",
1382 return NULL);
1384 scop->n_independence = node->data.sequence.items.top
1385 - node->data.sequence.items.start;
1386 scop->independences = isl_calloc_array(ctx, struct pet_independence *,
1387 scop->n_independence);
1388 if (!scop->independences)
1389 return pet_scop_free(scop);
1391 for (item = node->data.sequence.items.start, i = 0;
1392 item < node->data.sequence.items.top; ++item, ++i) {
1393 yaml_node_t *n;
1395 n = yaml_document_get_node(document, *item);
1396 scop->independences[i] = extract_independence(ctx, document, n);
1397 if (!scop->independences[i])
1398 return pet_scop_free(scop);
1401 return scop;
1404 static struct pet_scop *extract_scop(isl_ctx *ctx, yaml_document_t *document,
1405 yaml_node_t *node)
1407 struct pet_scop *scop;
1408 yaml_node_pair_t * pair;
1410 if (!node)
1411 return NULL;
1413 if (node->type != YAML_MAPPING_NODE)
1414 isl_die(ctx, isl_error_invalid, "expecting mapping",
1415 return NULL);
1417 scop = pet_scop_alloc(ctx);
1418 if (!scop)
1419 return NULL;
1421 for (pair = node->data.mapping.pairs.start;
1422 pair < node->data.mapping.pairs.top; ++pair) {
1423 yaml_node_t *key, *value;
1425 key = yaml_document_get_node(document, pair->key);
1426 value = yaml_document_get_node(document, pair->value);
1428 if (key->type != YAML_SCALAR_NODE)
1429 isl_die(ctx, isl_error_invalid, "expecting scalar key",
1430 return pet_scop_free(scop));
1431 if (!strcmp((char *) key->data.scalar.value, "context"))
1432 scop->context = extract_set(ctx, document, value);
1433 if (!strcmp((char *) key->data.scalar.value, "context_value"))
1434 scop->context_value = extract_set(ctx, document, value);
1435 if (!strcmp((char *) key->data.scalar.value, "types"))
1436 scop = extract_types(ctx, document, value, scop);
1437 if (!strcmp((char *) key->data.scalar.value, "arrays"))
1438 scop = extract_arrays(ctx, document, value, scop);
1439 if (!strcmp((char *) key->data.scalar.value, "statements"))
1440 scop = extract_statements(ctx, document, value, scop);
1441 if (!strcmp((char *) key->data.scalar.value, "implications"))
1442 scop = extract_implications(ctx, document, value, scop);
1443 if (!strcmp((char *) key->data.scalar.value, "independences"))
1444 scop = extract_independences(ctx,
1445 document, value, scop);
1446 if (!scop)
1447 return NULL;
1450 if (!scop->context_value) {
1451 isl_space *space = isl_space_params_alloc(ctx, 0);
1452 scop->context_value = isl_set_universe(space);
1453 if (!scop->context_value)
1454 return pet_scop_free(scop);
1457 return scop;
1460 /* Extract a pet_scop from the YAML description in "in".
1462 struct pet_scop *pet_scop_parse(isl_ctx *ctx, FILE *in)
1464 struct pet_scop *scop = NULL;
1465 yaml_parser_t parser;
1466 yaml_node_t *root;
1467 yaml_document_t document = { 0 };
1469 yaml_parser_initialize(&parser);
1471 yaml_parser_set_input_file(&parser, in);
1473 if (!yaml_parser_load(&parser, &document))
1474 goto error;
1476 root = yaml_document_get_root_node(&document);
1478 scop = extract_scop(ctx, &document, root);
1480 yaml_document_delete(&document);
1482 yaml_parser_delete(&parser);
1484 return scop;
1485 error:
1486 yaml_parser_delete(&parser);
1487 pet_scop_free(scop);
1488 return NULL;