2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2013-2014 Ecole Normale Superieure. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
41 #include "scop_yaml.h"
44 static char *extract_string(isl_ctx
*ctx
, yaml_document_t
*document
,
47 if (node
->type
!= YAML_SCALAR_NODE
)
48 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
51 return strdup((char *) node
->data
.scalar
.value
);
54 static int extract_int(isl_ctx
*ctx
, yaml_document_t
*document
,
57 if (node
->type
!= YAML_SCALAR_NODE
)
58 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
61 return atoi((char *) node
->data
.scalar
.value
);
64 static double extract_double(isl_ctx
*ctx
, yaml_document_t
*document
,
67 if (node
->type
!= YAML_SCALAR_NODE
)
68 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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",
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
,
87 if (node
->type
!= YAML_SCALAR_NODE
)
88 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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
,
97 if (node
->type
!= YAML_SCALAR_NODE
)
98 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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
,
107 if (node
->type
!= YAML_SCALAR_NODE
)
108 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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
,
117 if (node
->type
!= YAML_SCALAR_NODE
)
118 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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",
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",
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
,
155 if (node
->type
!= YAML_SCALAR_NODE
)
156 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
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",
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",
187 type
= isl_calloc_type(ctx
, struct pet_type
);
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
);
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
)
217 yaml_node_item_t
*item
;
219 if (node
->type
!= YAML_SEQUENCE_NODE
)
220 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
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
);
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
) {
233 n
= yaml_document_get_node(document
, *item
);
234 scop
->types
[i
] = extract_type(ctx
, document
, n
);
236 return pet_scop_free(scop
);
242 static struct pet_array
*extract_array(isl_ctx
*ctx
, yaml_document_t
*document
,
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",
252 array
= isl_calloc_type(ctx
, struct pet_array
);
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
,
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
);
297 static struct pet_scop
*extract_arrays(isl_ctx
*ctx
, yaml_document_t
*document
,
298 yaml_node_t
*node
, struct pet_scop
*scop
)
301 yaml_node_item_t
*item
;
303 if (node
->type
!= YAML_SEQUENCE_NODE
)
304 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
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
);
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
) {
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
);
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
)
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
) {
347 n
= yaml_document_get_node(document
, *item
);
348 arg
= extract_expr(ctx
, document
, n
);
349 expr
= pet_expr_set_arg(expr
, i
, arg
);
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
;
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
);
388 /* Extract pet_expr_access specific fields from "node" and
389 * update "expr" accordingly.
391 * The depth of the access is initialized by pet_expr_access_set_index.
392 * Any explicitly specified depth therefore needs to be set after
393 * setting the index expression. Similiarly, the access relation (if any)
394 * needs to be set after setting the depth.
396 static __isl_give pet_expr
*extract_expr_access(isl_ctx
*ctx
,
397 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
399 yaml_node_pair_t
*pair
;
401 isl_multi_pw_aff
*index
= NULL
;
403 for (pair
= node
->data
.mapping
.pairs
.start
;
404 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
405 yaml_node_t
*key
, *value
;
407 key
= yaml_document_get_node(document
, pair
->key
);
408 value
= yaml_document_get_node(document
, pair
->value
);
410 if (key
->type
!= YAML_SCALAR_NODE
)
411 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
412 return pet_expr_free(expr
));
414 if (!strcmp((char *) key
->data
.scalar
.value
, "index"))
415 index
= extract_multi_pw_aff(ctx
, document
, value
);
416 if (!strcmp((char *) key
->data
.scalar
.value
, "depth"))
417 depth
= extract_int(ctx
, document
, value
);
420 expr
= pet_expr_access_set_index(expr
, index
);
422 expr
= pet_expr_access_set_depth(expr
, depth
);
424 for (pair
= node
->data
.mapping
.pairs
.start
;
425 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
426 yaml_node_t
*key
, *value
;
428 key
= yaml_document_get_node(document
, pair
->key
);
429 value
= yaml_document_get_node(document
, pair
->value
);
431 if (key
->type
!= YAML_SCALAR_NODE
)
432 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
433 return pet_expr_free(expr
));
435 if (!strcmp((char *) key
->data
.scalar
.value
, "relation"))
436 expr
= pet_expr_access_set_access(expr
,
437 extract_map(ctx
, document
, value
));
438 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
439 expr
= pet_expr_access_set_ref_id(expr
,
440 extract_id(ctx
, document
, value
));
441 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
442 expr
= pet_expr_access_set_read(expr
,
443 extract_int(ctx
, document
, value
));
444 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
445 expr
= pet_expr_access_set_write(expr
,
446 extract_int(ctx
, document
, value
));
452 /* Extract operation expression specific fields from "node" and
453 * update "expr" accordingly.
455 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
456 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
458 yaml_node_pair_t
*pair
;
460 for (pair
= node
->data
.mapping
.pairs
.start
;
461 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
462 yaml_node_t
*key
, *value
;
464 key
= yaml_document_get_node(document
, pair
->key
);
465 value
= yaml_document_get_node(document
, pair
->value
);
467 if (key
->type
!= YAML_SCALAR_NODE
)
468 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
469 return pet_expr_free(expr
));
471 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
472 expr
= pet_expr_op_set_type(expr
,
473 extract_op(ctx
, document
, value
));
479 /* Extract pet_expr_call specific fields from "node" and
480 * update "expr" accordingly.
482 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
483 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
485 yaml_node_pair_t
*pair
;
487 for (pair
= node
->data
.mapping
.pairs
.start
;
488 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
489 yaml_node_t
*key
, *value
;
491 key
= yaml_document_get_node(document
, pair
->key
);
492 value
= yaml_document_get_node(document
, pair
->value
);
494 if (key
->type
!= YAML_SCALAR_NODE
)
495 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
496 return pet_expr_free(expr
));
498 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
499 expr
= pet_expr_call_set_name(expr
,
500 extract_string(ctx
, document
, value
));
506 /* Extract pet_expr_cast specific fields from "node" and
507 * update "expr" accordingly.
509 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
510 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
512 yaml_node_pair_t
*pair
;
514 for (pair
= node
->data
.mapping
.pairs
.start
;
515 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
516 yaml_node_t
*key
, *value
;
518 key
= yaml_document_get_node(document
, pair
->key
);
519 value
= yaml_document_get_node(document
, pair
->value
);
521 if (key
->type
!= YAML_SCALAR_NODE
)
522 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
523 return pet_expr_free(expr
));
525 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
526 expr
= pet_expr_cast_set_type_name(expr
,
527 extract_string(ctx
, document
, value
));
533 /* Extract pet_expr_int specific fields from "node" and
534 * update "expr" accordingly.
536 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
537 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
539 yaml_node_pair_t
* pair
;
541 for (pair
= node
->data
.mapping
.pairs
.start
;
542 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
543 yaml_node_t
*key
, *value
;
545 key
= yaml_document_get_node(document
, pair
->key
);
546 value
= yaml_document_get_node(document
, pair
->value
);
548 if (key
->type
!= YAML_SCALAR_NODE
)
549 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
550 return pet_expr_free(expr
));
552 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
553 expr
= pet_expr_int_set_val(expr
,
554 extract_val(ctx
, document
, value
));
560 /* Extract a pet_expr from "node".
562 * We first extract the type and arguments of the expression and
563 * then extract additional fields depending on the type.
565 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
566 yaml_document_t
*document
, yaml_node_t
*node
)
568 enum pet_expr_type type
= pet_expr_error
;
570 yaml_node_pair_t
*pair
;
572 if (node
->type
!= YAML_MAPPING_NODE
)
573 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
576 for (pair
= node
->data
.mapping
.pairs
.start
;
577 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
578 yaml_node_t
*key
, *value
;
580 key
= yaml_document_get_node(document
, pair
->key
);
581 value
= yaml_document_get_node(document
, pair
->value
);
583 if (key
->type
!= YAML_SCALAR_NODE
)
584 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
585 return pet_expr_free(expr
));
587 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
588 type
= extract_expr_type(ctx
, document
, value
);
591 if (type
== pet_expr_error
)
592 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
595 expr
= pet_expr_alloc(ctx
, type
);
599 for (pair
= node
->data
.mapping
.pairs
.start
;
600 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
601 yaml_node_t
*key
, *value
;
603 key
= yaml_document_get_node(document
, pair
->key
);
604 value
= yaml_document_get_node(document
, pair
->value
);
606 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
607 expr
= extract_arguments(ctx
, document
, value
, expr
);
614 isl_die(ctx
, isl_error_internal
, "unreachable code",
616 case pet_expr_access
:
617 expr
= extract_expr_access(ctx
, document
, node
, expr
);
619 case pet_expr_double
:
620 expr
= extract_expr_double(ctx
, document
, node
, expr
);
623 expr
= extract_expr_call(ctx
, document
, node
, expr
);
626 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
629 expr
= extract_expr_int(ctx
, document
, node
, expr
);
632 expr
= extract_expr_op(ctx
, document
, node
, expr
);
639 /* Extract a pet_tree_type from "node".
641 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
642 yaml_document_t
*document
, yaml_node_t
*node
)
644 if (node
->type
!= YAML_SCALAR_NODE
)
645 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
648 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
651 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
652 yaml_document_t
*document
, yaml_node_t
*node
);
654 /* Extract a pet_tree of type pet_tree_block from "node".
656 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
657 yaml_document_t
*document
, yaml_node_t
*node
)
661 yaml_node_pair_t
*pair
;
662 yaml_node_item_t
*item
;
663 yaml_node_t
*children
= NULL
;
666 for (pair
= node
->data
.mapping
.pairs
.start
;
667 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
668 yaml_node_t
*key
, *value
;
670 key
= yaml_document_get_node(document
, pair
->key
);
671 value
= yaml_document_get_node(document
, pair
->value
);
673 if (key
->type
!= YAML_SCALAR_NODE
)
674 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
677 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
678 block
= extract_int(ctx
, document
, value
);
679 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
686 n
= children
->data
.sequence
.items
.top
-
687 children
->data
.sequence
.items
.start
;
689 tree
= pet_tree_new_block(ctx
, block
, n
);
693 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
694 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
698 n
= yaml_document_get_node(document
, *item
);
699 child
= extract_tree(ctx
, document
, n
);
700 tree
= pet_tree_block_add_child(tree
, child
);
706 /* Extract a pet_tree of type pet_tree_decl from "node".
708 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
709 yaml_document_t
*document
, yaml_node_t
*node
)
711 yaml_node_pair_t
*pair
;
712 pet_expr
*var
= NULL
;
714 for (pair
= node
->data
.mapping
.pairs
.start
;
715 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
716 yaml_node_t
*key
, *value
;
718 key
= yaml_document_get_node(document
, pair
->key
);
719 value
= yaml_document_get_node(document
, pair
->value
);
721 if (key
->type
!= YAML_SCALAR_NODE
)
722 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
725 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
726 var
= extract_expr(ctx
, document
, value
);
733 isl_die(ctx
, isl_error_invalid
,
734 "no variable field", return NULL
);
736 return pet_tree_new_decl(var
);
739 /* Extract a pet_tree of type pet_tree_decl_init from "node".
741 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
742 yaml_document_t
*document
, yaml_node_t
*node
)
744 yaml_node_pair_t
*pair
;
745 pet_expr
*var
= NULL
;
746 pet_expr
*init
= NULL
;
748 for (pair
= node
->data
.mapping
.pairs
.start
;
749 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
750 yaml_node_t
*key
, *value
;
752 key
= yaml_document_get_node(document
, pair
->key
);
753 value
= yaml_document_get_node(document
, pair
->value
);
755 if (key
->type
!= YAML_SCALAR_NODE
)
756 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
759 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
760 var
= extract_expr(ctx
, document
, value
);
764 if (!strcmp((char *) key
->data
.scalar
.value
,
766 init
= extract_expr(ctx
, document
, value
);
773 isl_die(ctx
, isl_error_invalid
,
774 "no variable field", goto error
);
776 isl_die(ctx
, isl_error_invalid
,
777 "no initialization field", goto error
);
779 return pet_tree_new_decl_init(var
, init
);
786 /* Extract a pet_tree of type pet_tree_expr from "node".
788 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
789 yaml_document_t
*document
, yaml_node_t
*node
)
791 yaml_node_pair_t
*pair
;
792 pet_expr
*expr
= NULL
;
794 for (pair
= node
->data
.mapping
.pairs
.start
;
795 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
796 yaml_node_t
*key
, *value
;
798 key
= yaml_document_get_node(document
, pair
->key
);
799 value
= yaml_document_get_node(document
, pair
->value
);
801 if (key
->type
!= YAML_SCALAR_NODE
)
802 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
805 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
806 expr
= extract_expr(ctx
, document
, value
);
813 isl_die(ctx
, isl_error_invalid
,
814 "no expr field", return NULL
);
816 return pet_tree_new_expr(expr
);
819 /* Extract a pet_tree of type pet_tree_while from "node".
821 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
822 yaml_document_t
*document
, yaml_node_t
*node
)
824 yaml_node_pair_t
*pair
;
825 pet_expr
*cond
= NULL
;
826 pet_tree
*body
= NULL
;
828 for (pair
= node
->data
.mapping
.pairs
.start
;
829 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
830 yaml_node_t
*key
, *value
;
832 key
= yaml_document_get_node(document
, pair
->key
);
833 value
= yaml_document_get_node(document
, pair
->value
);
835 if (key
->type
!= YAML_SCALAR_NODE
)
836 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
839 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
840 cond
= extract_expr(ctx
, document
, value
);
844 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
845 body
= extract_tree(ctx
, document
, value
);
852 isl_die(ctx
, isl_error_invalid
,
853 "no condition field", goto error
);
855 isl_die(ctx
, isl_error_invalid
,
856 "no body field", goto error
);
858 return pet_tree_new_while(cond
, body
);
865 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
867 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
868 yaml_document_t
*document
, yaml_node_t
*node
)
870 yaml_node_pair_t
*pair
;
873 for (pair
= node
->data
.mapping
.pairs
.start
;
874 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
875 yaml_node_t
*key
, *value
;
877 key
= yaml_document_get_node(document
, pair
->key
);
878 value
= yaml_document_get_node(document
, pair
->value
);
880 if (key
->type
!= YAML_SCALAR_NODE
)
881 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
884 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
885 body
= extract_tree(ctx
, document
, value
);
892 isl_die(ctx
, isl_error_invalid
,
893 "no body field", return NULL
);
895 return pet_tree_new_infinite_loop(body
);
898 /* Extract a pet_tree of type pet_tree_if from "node".
900 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
901 yaml_document_t
*document
, yaml_node_t
*node
)
903 yaml_node_pair_t
*pair
;
904 pet_expr
*cond
= NULL
;
905 pet_tree
*then_body
= NULL
;
907 for (pair
= node
->data
.mapping
.pairs
.start
;
908 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
909 yaml_node_t
*key
, *value
;
911 key
= yaml_document_get_node(document
, pair
->key
);
912 value
= yaml_document_get_node(document
, pair
->value
);
914 if (key
->type
!= YAML_SCALAR_NODE
)
915 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
918 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
919 cond
= extract_expr(ctx
, document
, value
);
923 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
924 then_body
= extract_tree(ctx
, document
, value
);
931 isl_die(ctx
, isl_error_invalid
,
932 "no condition field", goto error
);
934 isl_die(ctx
, isl_error_invalid
,
935 "no then body", goto error
);
937 return pet_tree_new_if(cond
, then_body
);
940 pet_tree_free(then_body
);
944 /* Extract a pet_tree of type pet_tree_if_else from "node".
946 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
947 yaml_document_t
*document
, yaml_node_t
*node
)
949 yaml_node_pair_t
*pair
;
950 pet_expr
*cond
= NULL
;
951 pet_tree
*then_body
= NULL
;
952 pet_tree
*else_body
= NULL
;
954 for (pair
= node
->data
.mapping
.pairs
.start
;
955 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
956 yaml_node_t
*key
, *value
;
958 key
= yaml_document_get_node(document
, pair
->key
);
959 value
= yaml_document_get_node(document
, pair
->value
);
961 if (key
->type
!= YAML_SCALAR_NODE
)
962 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
965 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
966 cond
= extract_expr(ctx
, document
, value
);
970 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
971 then_body
= extract_tree(ctx
, document
, value
);
975 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
976 else_body
= extract_tree(ctx
, document
, value
);
983 isl_die(ctx
, isl_error_invalid
,
984 "no condition field", goto error
);
986 isl_die(ctx
, isl_error_invalid
,
987 "no then body", goto error
);
989 isl_die(ctx
, isl_error_invalid
,
990 "no else body", goto error
);
992 return pet_tree_new_if_else(cond
, then_body
, else_body
);
995 pet_tree_free(then_body
);
996 pet_tree_free(else_body
);
1000 /* Extract a pet_tree of type pet_tree_for from "node".
1002 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1003 yaml_document_t
*document
, yaml_node_t
*node
)
1005 yaml_node_pair_t
*pair
;
1007 int independent
= 0;
1008 pet_expr
*iv
= NULL
;
1009 pet_expr
*init
= NULL
;
1010 pet_expr
*cond
= NULL
;
1011 pet_expr
*inc
= NULL
;
1012 pet_tree
*body
= NULL
;
1014 for (pair
= node
->data
.mapping
.pairs
.start
;
1015 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1016 yaml_node_t
*key
, *value
;
1018 key
= yaml_document_get_node(document
, pair
->key
);
1019 value
= yaml_document_get_node(document
, pair
->value
);
1021 if (key
->type
!= YAML_SCALAR_NODE
)
1022 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1025 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1026 declared
= extract_int(ctx
, document
, value
);
1027 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1028 independent
= extract_int(ctx
, document
, value
);
1029 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1030 iv
= extract_expr(ctx
, document
, value
);
1034 if (!strcmp((char *) key
->data
.scalar
.value
,
1035 "initialization")) {
1036 init
= extract_expr(ctx
, document
, value
);
1040 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1041 cond
= extract_expr(ctx
, document
, value
);
1045 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1046 inc
= extract_expr(ctx
, document
, value
);
1050 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1051 body
= extract_tree(ctx
, document
, value
);
1058 isl_die(ctx
, isl_error_invalid
,
1059 "no variable field", goto error
);
1061 isl_die(ctx
, isl_error_invalid
,
1062 "no initialization field", goto error
);
1064 isl_die(ctx
, isl_error_invalid
,
1065 "no condition field", goto error
);
1067 isl_die(ctx
, isl_error_invalid
,
1068 "no increment field", goto error
);
1070 isl_die(ctx
, isl_error_invalid
,
1071 "no body field", goto error
);
1073 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1077 pet_expr_free(init
);
1078 pet_expr_free(cond
);
1080 pet_tree_free(body
);
1084 /* Extract a pet_tree from "node".
1086 * We first extract the type of the pet_tree and then call
1087 * the appropriate function to extract and construct a pet_tree
1090 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1091 yaml_document_t
*document
, yaml_node_t
*node
)
1093 enum pet_tree_type type
= pet_tree_error
;
1095 yaml_node_pair_t
*pair
;
1097 if (node
->type
!= YAML_MAPPING_NODE
)
1098 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1101 for (pair
= node
->data
.mapping
.pairs
.start
;
1102 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1103 yaml_node_t
*key
, *value
;
1105 key
= yaml_document_get_node(document
, pair
->key
);
1106 value
= yaml_document_get_node(document
, pair
->value
);
1108 if (key
->type
!= YAML_SCALAR_NODE
)
1109 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1110 return pet_tree_free(tree
));
1112 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1113 type
= extract_tree_type(ctx
, document
, value
);
1116 if (type
== pet_tree_error
)
1117 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1121 case pet_tree_error
:
1123 case pet_tree_block
:
1124 tree
= extract_tree_block(ctx
, document
, node
);
1126 case pet_tree_break
:
1127 tree
= pet_tree_new_break(ctx
);
1129 case pet_tree_continue
:
1130 tree
= pet_tree_new_continue(ctx
);
1133 tree
= extract_tree_decl(ctx
, document
, node
);
1135 case pet_tree_decl_init
:
1136 tree
= extract_tree_decl_init(ctx
, document
, node
);
1139 tree
= extract_tree_expr(ctx
, document
, node
);
1142 tree
= extract_tree_for(ctx
, document
, node
);
1144 case pet_tree_while
:
1145 tree
= extract_tree_while(ctx
, document
, node
);
1147 case pet_tree_infinite_loop
:
1148 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1151 tree
= extract_tree_if(ctx
, document
, node
);
1153 case pet_tree_if_else
:
1154 tree
= extract_tree_if_else(ctx
, document
, node
);
1161 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1162 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1165 yaml_node_item_t
*item
;
1167 if (node
->type
!= YAML_SEQUENCE_NODE
)
1168 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1169 return pet_stmt_free(stmt
));
1171 stmt
->n_arg
= node
->data
.sequence
.items
.top
1172 - node
->data
.sequence
.items
.start
;
1173 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1175 return pet_stmt_free(stmt
);
1177 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1178 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1181 n
= yaml_document_get_node(document
, *item
);
1182 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1184 return pet_stmt_free(stmt
);
1190 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1193 struct pet_stmt
*stmt
;
1194 yaml_node_pair_t
* pair
;
1196 unsigned start
= 0, end
= 0;
1197 char *indent
= NULL
;
1199 if (node
->type
!= YAML_MAPPING_NODE
)
1200 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1203 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1207 stmt
->loc
= &pet_loc_dummy
;
1209 for (pair
= node
->data
.mapping
.pairs
.start
;
1210 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1211 yaml_node_t
*key
, *value
;
1213 key
= yaml_document_get_node(document
, pair
->key
);
1214 value
= yaml_document_get_node(document
, pair
->value
);
1216 if (key
->type
!= YAML_SCALAR_NODE
)
1217 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1218 return pet_stmt_free(stmt
));
1220 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1221 indent
= extract_string(ctx
, document
, value
);
1222 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1223 line
= extract_int(ctx
, document
, value
);
1224 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1225 start
= extract_int(ctx
, document
, value
);
1226 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1227 end
= extract_int(ctx
, document
, value
);
1228 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1229 stmt
->domain
= extract_set(ctx
, document
, value
);
1230 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1231 stmt
->schedule
= extract_map(ctx
, document
, value
);
1232 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1233 stmt
->body
= extract_tree(ctx
, document
, value
);
1235 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1236 stmt
= extract_stmt_arguments(ctx
, document
,
1243 indent
= strdup("");
1244 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1246 return pet_stmt_free(stmt
);
1251 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1252 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1255 yaml_node_item_t
*item
;
1257 if (node
->type
!= YAML_SEQUENCE_NODE
)
1258 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1261 scop
->n_stmt
= node
->data
.sequence
.items
.top
1262 - node
->data
.sequence
.items
.start
;
1263 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1265 return pet_scop_free(scop
);
1267 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1268 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1271 n
= yaml_document_get_node(document
, *item
);
1272 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1273 if (!scop
->stmts
[i
])
1274 return pet_scop_free(scop
);
1280 /* Extract a pet_implication from "node".
1282 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1283 yaml_document_t
*document
, yaml_node_t
*node
)
1285 struct pet_implication
*implication
;
1286 yaml_node_pair_t
* pair
;
1288 if (node
->type
!= YAML_MAPPING_NODE
)
1289 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1292 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1296 for (pair
= node
->data
.mapping
.pairs
.start
;
1297 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1298 yaml_node_t
*key
, *value
;
1300 key
= yaml_document_get_node(document
, pair
->key
);
1301 value
= yaml_document_get_node(document
, pair
->value
);
1303 if (key
->type
!= YAML_SCALAR_NODE
)
1304 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1305 return pet_implication_free(implication
));
1307 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1308 implication
->satisfied
=
1309 extract_int(ctx
, document
, value
);
1310 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1311 implication
->extension
=
1312 extract_map(ctx
, document
, value
);
1318 /* Extract a sequence of implications from "node" and
1319 * store them in scop->implications.
1321 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1322 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1325 yaml_node_item_t
*item
;
1327 if (node
->type
!= YAML_SEQUENCE_NODE
)
1328 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1331 scop
->n_implication
= node
->data
.sequence
.items
.top
1332 - node
->data
.sequence
.items
.start
;
1333 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1334 scop
->n_implication
);
1335 if (!scop
->implications
)
1336 return pet_scop_free(scop
);
1338 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1339 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1342 n
= yaml_document_get_node(document
, *item
);
1343 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1344 if (!scop
->implications
[i
])
1345 return pet_scop_free(scop
);
1351 /* Extract a pet_independence from "node".
1353 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1354 yaml_document_t
*document
, yaml_node_t
*node
)
1356 struct pet_independence
*independence
;
1357 yaml_node_pair_t
* pair
;
1359 if (node
->type
!= YAML_MAPPING_NODE
)
1360 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1363 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1367 for (pair
= node
->data
.mapping
.pairs
.start
;
1368 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1369 yaml_node_t
*key
, *value
;
1371 key
= yaml_document_get_node(document
, pair
->key
);
1372 value
= yaml_document_get_node(document
, pair
->value
);
1374 if (key
->type
!= YAML_SCALAR_NODE
)
1375 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1376 return pet_independence_free(independence
));
1378 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1379 independence
->filter
=
1380 extract_union_map(ctx
, document
, value
);
1381 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1382 independence
->local
=
1383 extract_union_set(ctx
, document
, value
);
1386 if (!independence
->filter
)
1387 isl_die(ctx
, isl_error_invalid
, "no filter field",
1388 return pet_independence_free(independence
));
1389 if (!independence
->local
)
1390 isl_die(ctx
, isl_error_invalid
, "no local field",
1391 return pet_independence_free(independence
));
1393 return independence
;
1396 /* Extract a sequence of independences from "node" and
1397 * store them in scop->independences.
1399 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1400 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1403 yaml_node_item_t
*item
;
1405 if (node
->type
!= YAML_SEQUENCE_NODE
)
1406 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1409 scop
->n_independence
= node
->data
.sequence
.items
.top
1410 - node
->data
.sequence
.items
.start
;
1411 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1412 scop
->n_independence
);
1413 if (!scop
->independences
)
1414 return pet_scop_free(scop
);
1416 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1417 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1420 n
= yaml_document_get_node(document
, *item
);
1421 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1422 if (!scop
->independences
[i
])
1423 return pet_scop_free(scop
);
1429 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1432 struct pet_scop
*scop
;
1433 yaml_node_pair_t
* pair
;
1438 if (node
->type
!= YAML_MAPPING_NODE
)
1439 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1442 scop
= pet_scop_alloc(ctx
);
1446 for (pair
= node
->data
.mapping
.pairs
.start
;
1447 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1448 yaml_node_t
*key
, *value
;
1450 key
= yaml_document_get_node(document
, pair
->key
);
1451 value
= yaml_document_get_node(document
, pair
->value
);
1453 if (key
->type
!= YAML_SCALAR_NODE
)
1454 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1455 return pet_scop_free(scop
));
1456 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1457 scop
->context
= extract_set(ctx
, document
, value
);
1458 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1459 scop
->context_value
= extract_set(ctx
, document
, value
);
1460 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1461 scop
= extract_types(ctx
, document
, value
, scop
);
1462 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1463 scop
= extract_arrays(ctx
, document
, value
, scop
);
1464 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1465 scop
= extract_statements(ctx
, document
, value
, scop
);
1466 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1467 scop
= extract_implications(ctx
, document
, value
, scop
);
1468 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1469 scop
= extract_independences(ctx
,
1470 document
, value
, scop
);
1475 if (!scop
->context_value
) {
1476 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1477 scop
->context_value
= isl_set_universe(space
);
1478 if (!scop
->context_value
)
1479 return pet_scop_free(scop
);
1485 /* Extract a pet_scop from the YAML description in "in".
1487 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1489 struct pet_scop
*scop
= NULL
;
1490 yaml_parser_t parser
;
1492 yaml_document_t document
= { 0 };
1494 yaml_parser_initialize(&parser
);
1496 yaml_parser_set_input_file(&parser
, in
);
1498 if (!yaml_parser_load(&parser
, &document
))
1501 root
= yaml_document_get_root_node(&document
);
1503 scop
= extract_scop(ctx
, &document
, root
);
1505 yaml_document_delete(&document
);
1507 yaml_parser_delete(&parser
);
1511 yaml_parser_delete(&parser
);
1512 pet_scop_free(scop
);