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
));
447 if (!strcmp((char *) key
->data
.scalar
.value
, "kill"))
448 expr
= pet_expr_access_set_kill(expr
,
449 extract_int(ctx
, document
, value
));
455 /* Extract operation expression specific fields from "node" and
456 * update "expr" accordingly.
458 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
459 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
461 yaml_node_pair_t
*pair
;
463 for (pair
= node
->data
.mapping
.pairs
.start
;
464 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
465 yaml_node_t
*key
, *value
;
467 key
= yaml_document_get_node(document
, pair
->key
);
468 value
= yaml_document_get_node(document
, pair
->value
);
470 if (key
->type
!= YAML_SCALAR_NODE
)
471 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
472 return pet_expr_free(expr
));
474 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
475 expr
= pet_expr_op_set_type(expr
,
476 extract_op(ctx
, document
, value
));
482 /* Extract pet_expr_call specific fields from "node" and
483 * update "expr" accordingly.
485 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
486 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
488 yaml_node_pair_t
*pair
;
490 for (pair
= node
->data
.mapping
.pairs
.start
;
491 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
492 yaml_node_t
*key
, *value
;
494 key
= yaml_document_get_node(document
, pair
->key
);
495 value
= yaml_document_get_node(document
, pair
->value
);
497 if (key
->type
!= YAML_SCALAR_NODE
)
498 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
499 return pet_expr_free(expr
));
501 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
502 expr
= pet_expr_call_set_name(expr
,
503 extract_string(ctx
, document
, value
));
509 /* Extract pet_expr_cast specific fields from "node" and
510 * update "expr" accordingly.
512 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
513 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
515 yaml_node_pair_t
*pair
;
517 for (pair
= node
->data
.mapping
.pairs
.start
;
518 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
519 yaml_node_t
*key
, *value
;
521 key
= yaml_document_get_node(document
, pair
->key
);
522 value
= yaml_document_get_node(document
, pair
->value
);
524 if (key
->type
!= YAML_SCALAR_NODE
)
525 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
526 return pet_expr_free(expr
));
528 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
529 expr
= pet_expr_cast_set_type_name(expr
,
530 extract_string(ctx
, document
, value
));
536 /* Extract pet_expr_int specific fields from "node" and
537 * update "expr" accordingly.
539 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
540 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
542 yaml_node_pair_t
* pair
;
544 for (pair
= node
->data
.mapping
.pairs
.start
;
545 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
546 yaml_node_t
*key
, *value
;
548 key
= yaml_document_get_node(document
, pair
->key
);
549 value
= yaml_document_get_node(document
, pair
->value
);
551 if (key
->type
!= YAML_SCALAR_NODE
)
552 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
553 return pet_expr_free(expr
));
555 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
556 expr
= pet_expr_int_set_val(expr
,
557 extract_val(ctx
, document
, value
));
563 /* Extract a pet_expr from "node".
565 * We first extract the type and arguments of the expression and
566 * then extract additional fields depending on the type.
568 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
569 yaml_document_t
*document
, yaml_node_t
*node
)
571 enum pet_expr_type type
= pet_expr_error
;
573 yaml_node_pair_t
*pair
;
575 if (node
->type
!= YAML_MAPPING_NODE
)
576 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
579 for (pair
= node
->data
.mapping
.pairs
.start
;
580 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
581 yaml_node_t
*key
, *value
;
583 key
= yaml_document_get_node(document
, pair
->key
);
584 value
= yaml_document_get_node(document
, pair
->value
);
586 if (key
->type
!= YAML_SCALAR_NODE
)
587 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
588 return pet_expr_free(expr
));
590 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
591 type
= extract_expr_type(ctx
, document
, value
);
594 if (type
== pet_expr_error
)
595 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
598 expr
= pet_expr_alloc(ctx
, type
);
602 for (pair
= node
->data
.mapping
.pairs
.start
;
603 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
604 yaml_node_t
*key
, *value
;
606 key
= yaml_document_get_node(document
, pair
->key
);
607 value
= yaml_document_get_node(document
, pair
->value
);
609 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
610 expr
= extract_arguments(ctx
, document
, value
, expr
);
617 isl_die(ctx
, isl_error_internal
, "unreachable code",
619 case pet_expr_access
:
620 expr
= extract_expr_access(ctx
, document
, node
, expr
);
622 case pet_expr_double
:
623 expr
= extract_expr_double(ctx
, document
, node
, expr
);
626 expr
= extract_expr_call(ctx
, document
, node
, expr
);
629 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
632 expr
= extract_expr_int(ctx
, document
, node
, expr
);
635 expr
= extract_expr_op(ctx
, document
, node
, expr
);
642 /* Extract a pet_tree_type from "node".
644 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
645 yaml_document_t
*document
, yaml_node_t
*node
)
647 if (node
->type
!= YAML_SCALAR_NODE
)
648 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
651 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
654 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
655 yaml_document_t
*document
, yaml_node_t
*node
);
657 /* Extract a pet_tree of type pet_tree_block from "node".
659 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
660 yaml_document_t
*document
, yaml_node_t
*node
)
664 yaml_node_pair_t
*pair
;
665 yaml_node_item_t
*item
;
666 yaml_node_t
*children
= NULL
;
669 for (pair
= node
->data
.mapping
.pairs
.start
;
670 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
671 yaml_node_t
*key
, *value
;
673 key
= yaml_document_get_node(document
, pair
->key
);
674 value
= yaml_document_get_node(document
, pair
->value
);
676 if (key
->type
!= YAML_SCALAR_NODE
)
677 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
680 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
681 block
= extract_int(ctx
, document
, value
);
682 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
689 n
= children
->data
.sequence
.items
.top
-
690 children
->data
.sequence
.items
.start
;
692 tree
= pet_tree_new_block(ctx
, block
, n
);
696 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
697 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
701 n
= yaml_document_get_node(document
, *item
);
702 child
= extract_tree(ctx
, document
, n
);
703 tree
= pet_tree_block_add_child(tree
, child
);
709 /* Extract a pet_tree of type pet_tree_decl from "node".
711 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
712 yaml_document_t
*document
, yaml_node_t
*node
)
714 yaml_node_pair_t
*pair
;
715 pet_expr
*var
= NULL
;
717 for (pair
= node
->data
.mapping
.pairs
.start
;
718 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
719 yaml_node_t
*key
, *value
;
721 key
= yaml_document_get_node(document
, pair
->key
);
722 value
= yaml_document_get_node(document
, pair
->value
);
724 if (key
->type
!= YAML_SCALAR_NODE
)
725 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
728 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
729 var
= extract_expr(ctx
, document
, value
);
736 isl_die(ctx
, isl_error_invalid
,
737 "no variable field", return NULL
);
739 return pet_tree_new_decl(var
);
742 /* Extract a pet_tree of type pet_tree_decl_init from "node".
744 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
745 yaml_document_t
*document
, yaml_node_t
*node
)
747 yaml_node_pair_t
*pair
;
748 pet_expr
*var
= NULL
;
749 pet_expr
*init
= NULL
;
751 for (pair
= node
->data
.mapping
.pairs
.start
;
752 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
753 yaml_node_t
*key
, *value
;
755 key
= yaml_document_get_node(document
, pair
->key
);
756 value
= yaml_document_get_node(document
, pair
->value
);
758 if (key
->type
!= YAML_SCALAR_NODE
)
759 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
762 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
763 var
= extract_expr(ctx
, document
, value
);
767 if (!strcmp((char *) key
->data
.scalar
.value
,
769 init
= extract_expr(ctx
, document
, value
);
776 isl_die(ctx
, isl_error_invalid
,
777 "no variable field", goto error
);
779 isl_die(ctx
, isl_error_invalid
,
780 "no initialization field", goto error
);
782 return pet_tree_new_decl_init(var
, init
);
789 /* Extract a pet_tree of type pet_tree_expr from "node".
791 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
792 yaml_document_t
*document
, yaml_node_t
*node
)
794 yaml_node_pair_t
*pair
;
795 pet_expr
*expr
= NULL
;
797 for (pair
= node
->data
.mapping
.pairs
.start
;
798 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
799 yaml_node_t
*key
, *value
;
801 key
= yaml_document_get_node(document
, pair
->key
);
802 value
= yaml_document_get_node(document
, pair
->value
);
804 if (key
->type
!= YAML_SCALAR_NODE
)
805 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
808 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
809 expr
= extract_expr(ctx
, document
, value
);
816 isl_die(ctx
, isl_error_invalid
,
817 "no expr field", return NULL
);
819 return pet_tree_new_expr(expr
);
822 /* Extract a pet_tree of type pet_tree_while from "node".
824 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
825 yaml_document_t
*document
, yaml_node_t
*node
)
827 yaml_node_pair_t
*pair
;
828 pet_expr
*cond
= NULL
;
829 pet_tree
*body
= NULL
;
831 for (pair
= node
->data
.mapping
.pairs
.start
;
832 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
833 yaml_node_t
*key
, *value
;
835 key
= yaml_document_get_node(document
, pair
->key
);
836 value
= yaml_document_get_node(document
, pair
->value
);
838 if (key
->type
!= YAML_SCALAR_NODE
)
839 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
842 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
843 cond
= extract_expr(ctx
, document
, value
);
847 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
848 body
= extract_tree(ctx
, document
, value
);
855 isl_die(ctx
, isl_error_invalid
,
856 "no condition field", goto error
);
858 isl_die(ctx
, isl_error_invalid
,
859 "no body field", goto error
);
861 return pet_tree_new_while(cond
, body
);
868 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
870 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
871 yaml_document_t
*document
, yaml_node_t
*node
)
873 yaml_node_pair_t
*pair
;
876 for (pair
= node
->data
.mapping
.pairs
.start
;
877 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
878 yaml_node_t
*key
, *value
;
880 key
= yaml_document_get_node(document
, pair
->key
);
881 value
= yaml_document_get_node(document
, pair
->value
);
883 if (key
->type
!= YAML_SCALAR_NODE
)
884 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
887 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
888 body
= extract_tree(ctx
, document
, value
);
895 isl_die(ctx
, isl_error_invalid
,
896 "no body field", return NULL
);
898 return pet_tree_new_infinite_loop(body
);
901 /* Extract a pet_tree of type pet_tree_if from "node".
903 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
904 yaml_document_t
*document
, yaml_node_t
*node
)
906 yaml_node_pair_t
*pair
;
907 pet_expr
*cond
= NULL
;
908 pet_tree
*then_body
= NULL
;
910 for (pair
= node
->data
.mapping
.pairs
.start
;
911 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
912 yaml_node_t
*key
, *value
;
914 key
= yaml_document_get_node(document
, pair
->key
);
915 value
= yaml_document_get_node(document
, pair
->value
);
917 if (key
->type
!= YAML_SCALAR_NODE
)
918 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
921 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
922 cond
= extract_expr(ctx
, document
, value
);
926 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
927 then_body
= extract_tree(ctx
, document
, value
);
934 isl_die(ctx
, isl_error_invalid
,
935 "no condition field", goto error
);
937 isl_die(ctx
, isl_error_invalid
,
938 "no then body", goto error
);
940 return pet_tree_new_if(cond
, then_body
);
943 pet_tree_free(then_body
);
947 /* Extract a pet_tree of type pet_tree_if_else from "node".
949 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
950 yaml_document_t
*document
, yaml_node_t
*node
)
952 yaml_node_pair_t
*pair
;
953 pet_expr
*cond
= NULL
;
954 pet_tree
*then_body
= NULL
;
955 pet_tree
*else_body
= NULL
;
957 for (pair
= node
->data
.mapping
.pairs
.start
;
958 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
959 yaml_node_t
*key
, *value
;
961 key
= yaml_document_get_node(document
, pair
->key
);
962 value
= yaml_document_get_node(document
, pair
->value
);
964 if (key
->type
!= YAML_SCALAR_NODE
)
965 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
968 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
969 cond
= extract_expr(ctx
, document
, value
);
973 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
974 then_body
= extract_tree(ctx
, document
, value
);
978 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
979 else_body
= extract_tree(ctx
, document
, value
);
986 isl_die(ctx
, isl_error_invalid
,
987 "no condition field", goto error
);
989 isl_die(ctx
, isl_error_invalid
,
990 "no then body", goto error
);
992 isl_die(ctx
, isl_error_invalid
,
993 "no else body", goto error
);
995 return pet_tree_new_if_else(cond
, then_body
, else_body
);
998 pet_tree_free(then_body
);
999 pet_tree_free(else_body
);
1003 /* Extract a pet_tree of type pet_tree_for from "node".
1005 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1006 yaml_document_t
*document
, yaml_node_t
*node
)
1008 yaml_node_pair_t
*pair
;
1010 int independent
= 0;
1011 pet_expr
*iv
= NULL
;
1012 pet_expr
*init
= NULL
;
1013 pet_expr
*cond
= NULL
;
1014 pet_expr
*inc
= NULL
;
1015 pet_tree
*body
= NULL
;
1017 for (pair
= node
->data
.mapping
.pairs
.start
;
1018 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1019 yaml_node_t
*key
, *value
;
1021 key
= yaml_document_get_node(document
, pair
->key
);
1022 value
= yaml_document_get_node(document
, pair
->value
);
1024 if (key
->type
!= YAML_SCALAR_NODE
)
1025 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1028 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1029 declared
= extract_int(ctx
, document
, value
);
1030 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1031 independent
= extract_int(ctx
, document
, value
);
1032 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1033 iv
= extract_expr(ctx
, document
, value
);
1037 if (!strcmp((char *) key
->data
.scalar
.value
,
1038 "initialization")) {
1039 init
= extract_expr(ctx
, document
, value
);
1043 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1044 cond
= extract_expr(ctx
, document
, value
);
1048 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1049 inc
= extract_expr(ctx
, document
, value
);
1053 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1054 body
= extract_tree(ctx
, document
, value
);
1061 isl_die(ctx
, isl_error_invalid
,
1062 "no variable field", goto error
);
1064 isl_die(ctx
, isl_error_invalid
,
1065 "no initialization field", goto error
);
1067 isl_die(ctx
, isl_error_invalid
,
1068 "no condition field", goto error
);
1070 isl_die(ctx
, isl_error_invalid
,
1071 "no increment field", goto error
);
1073 isl_die(ctx
, isl_error_invalid
,
1074 "no body field", goto error
);
1076 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1080 pet_expr_free(init
);
1081 pet_expr_free(cond
);
1083 pet_tree_free(body
);
1087 /* Extract a pet_tree from "node".
1089 * We first extract the type of the pet_tree and then call
1090 * the appropriate function to extract and construct a pet_tree
1093 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1094 yaml_document_t
*document
, yaml_node_t
*node
)
1096 enum pet_tree_type type
= pet_tree_error
;
1098 yaml_node_pair_t
*pair
;
1100 if (node
->type
!= YAML_MAPPING_NODE
)
1101 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1104 for (pair
= node
->data
.mapping
.pairs
.start
;
1105 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1106 yaml_node_t
*key
, *value
;
1108 key
= yaml_document_get_node(document
, pair
->key
);
1109 value
= yaml_document_get_node(document
, pair
->value
);
1111 if (key
->type
!= YAML_SCALAR_NODE
)
1112 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1113 return pet_tree_free(tree
));
1115 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1116 type
= extract_tree_type(ctx
, document
, value
);
1119 if (type
== pet_tree_error
)
1120 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1124 case pet_tree_error
:
1126 case pet_tree_block
:
1127 tree
= extract_tree_block(ctx
, document
, node
);
1129 case pet_tree_break
:
1130 tree
= pet_tree_new_break(ctx
);
1132 case pet_tree_continue
:
1133 tree
= pet_tree_new_continue(ctx
);
1136 tree
= extract_tree_decl(ctx
, document
, node
);
1138 case pet_tree_decl_init
:
1139 tree
= extract_tree_decl_init(ctx
, document
, node
);
1142 tree
= extract_tree_expr(ctx
, document
, node
);
1145 tree
= extract_tree_for(ctx
, document
, node
);
1147 case pet_tree_while
:
1148 tree
= extract_tree_while(ctx
, document
, node
);
1150 case pet_tree_infinite_loop
:
1151 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1154 tree
= extract_tree_if(ctx
, document
, node
);
1156 case pet_tree_if_else
:
1157 tree
= extract_tree_if_else(ctx
, document
, node
);
1164 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1165 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1168 yaml_node_item_t
*item
;
1170 if (node
->type
!= YAML_SEQUENCE_NODE
)
1171 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1172 return pet_stmt_free(stmt
));
1174 stmt
->n_arg
= node
->data
.sequence
.items
.top
1175 - node
->data
.sequence
.items
.start
;
1176 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1178 return pet_stmt_free(stmt
);
1180 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1181 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1184 n
= yaml_document_get_node(document
, *item
);
1185 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1187 return pet_stmt_free(stmt
);
1193 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1196 struct pet_stmt
*stmt
;
1197 yaml_node_pair_t
* pair
;
1199 unsigned start
= 0, end
= 0;
1200 char *indent
= NULL
;
1202 if (node
->type
!= YAML_MAPPING_NODE
)
1203 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1206 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1210 stmt
->loc
= &pet_loc_dummy
;
1212 for (pair
= node
->data
.mapping
.pairs
.start
;
1213 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1214 yaml_node_t
*key
, *value
;
1216 key
= yaml_document_get_node(document
, pair
->key
);
1217 value
= yaml_document_get_node(document
, pair
->value
);
1219 if (key
->type
!= YAML_SCALAR_NODE
)
1220 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1221 return pet_stmt_free(stmt
));
1223 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1224 indent
= extract_string(ctx
, document
, value
);
1225 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1226 line
= extract_int(ctx
, document
, value
);
1227 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1228 start
= extract_int(ctx
, document
, value
);
1229 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1230 end
= extract_int(ctx
, document
, value
);
1231 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1232 stmt
->domain
= extract_set(ctx
, document
, value
);
1233 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1234 stmt
->schedule
= extract_map(ctx
, document
, value
);
1235 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1236 stmt
->body
= extract_tree(ctx
, document
, value
);
1238 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1239 stmt
= extract_stmt_arguments(ctx
, document
,
1246 indent
= strdup("");
1247 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1249 return pet_stmt_free(stmt
);
1254 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1255 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1258 yaml_node_item_t
*item
;
1260 if (node
->type
!= YAML_SEQUENCE_NODE
)
1261 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1264 scop
->n_stmt
= node
->data
.sequence
.items
.top
1265 - node
->data
.sequence
.items
.start
;
1266 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1268 return pet_scop_free(scop
);
1270 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1271 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1274 n
= yaml_document_get_node(document
, *item
);
1275 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1276 if (!scop
->stmts
[i
])
1277 return pet_scop_free(scop
);
1283 /* Extract a pet_implication from "node".
1285 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1286 yaml_document_t
*document
, yaml_node_t
*node
)
1288 struct pet_implication
*implication
;
1289 yaml_node_pair_t
* pair
;
1291 if (node
->type
!= YAML_MAPPING_NODE
)
1292 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1295 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1299 for (pair
= node
->data
.mapping
.pairs
.start
;
1300 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1301 yaml_node_t
*key
, *value
;
1303 key
= yaml_document_get_node(document
, pair
->key
);
1304 value
= yaml_document_get_node(document
, pair
->value
);
1306 if (key
->type
!= YAML_SCALAR_NODE
)
1307 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1308 return pet_implication_free(implication
));
1310 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1311 implication
->satisfied
=
1312 extract_int(ctx
, document
, value
);
1313 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1314 implication
->extension
=
1315 extract_map(ctx
, document
, value
);
1321 /* Extract a sequence of implications from "node" and
1322 * store them in scop->implications.
1324 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1325 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1328 yaml_node_item_t
*item
;
1330 if (node
->type
!= YAML_SEQUENCE_NODE
)
1331 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1334 scop
->n_implication
= node
->data
.sequence
.items
.top
1335 - node
->data
.sequence
.items
.start
;
1336 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1337 scop
->n_implication
);
1338 if (!scop
->implications
)
1339 return pet_scop_free(scop
);
1341 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1342 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1345 n
= yaml_document_get_node(document
, *item
);
1346 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1347 if (!scop
->implications
[i
])
1348 return pet_scop_free(scop
);
1354 /* Extract a pet_independence from "node".
1356 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1357 yaml_document_t
*document
, yaml_node_t
*node
)
1359 struct pet_independence
*independence
;
1360 yaml_node_pair_t
* pair
;
1362 if (node
->type
!= YAML_MAPPING_NODE
)
1363 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1366 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1370 for (pair
= node
->data
.mapping
.pairs
.start
;
1371 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1372 yaml_node_t
*key
, *value
;
1374 key
= yaml_document_get_node(document
, pair
->key
);
1375 value
= yaml_document_get_node(document
, pair
->value
);
1377 if (key
->type
!= YAML_SCALAR_NODE
)
1378 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1379 return pet_independence_free(independence
));
1381 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1382 independence
->filter
=
1383 extract_union_map(ctx
, document
, value
);
1384 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1385 independence
->local
=
1386 extract_union_set(ctx
, document
, value
);
1389 if (!independence
->filter
)
1390 isl_die(ctx
, isl_error_invalid
, "no filter field",
1391 return pet_independence_free(independence
));
1392 if (!independence
->local
)
1393 isl_die(ctx
, isl_error_invalid
, "no local field",
1394 return pet_independence_free(independence
));
1396 return independence
;
1399 /* Extract a sequence of independences from "node" and
1400 * store them in scop->independences.
1402 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1403 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1406 yaml_node_item_t
*item
;
1408 if (node
->type
!= YAML_SEQUENCE_NODE
)
1409 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1412 scop
->n_independence
= node
->data
.sequence
.items
.top
1413 - node
->data
.sequence
.items
.start
;
1414 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1415 scop
->n_independence
);
1416 if (!scop
->independences
)
1417 return pet_scop_free(scop
);
1419 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1420 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1423 n
= yaml_document_get_node(document
, *item
);
1424 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1425 if (!scop
->independences
[i
])
1426 return pet_scop_free(scop
);
1432 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1435 struct pet_scop
*scop
;
1436 yaml_node_pair_t
* pair
;
1441 if (node
->type
!= YAML_MAPPING_NODE
)
1442 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1445 scop
= pet_scop_alloc(ctx
);
1449 for (pair
= node
->data
.mapping
.pairs
.start
;
1450 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1451 yaml_node_t
*key
, *value
;
1453 key
= yaml_document_get_node(document
, pair
->key
);
1454 value
= yaml_document_get_node(document
, pair
->value
);
1456 if (key
->type
!= YAML_SCALAR_NODE
)
1457 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1458 return pet_scop_free(scop
));
1459 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1460 scop
->context
= extract_set(ctx
, document
, value
);
1461 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1462 scop
->context_value
= extract_set(ctx
, document
, value
);
1463 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1464 scop
= extract_types(ctx
, document
, value
, scop
);
1465 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1466 scop
= extract_arrays(ctx
, document
, value
, scop
);
1467 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1468 scop
= extract_statements(ctx
, document
, value
, scop
);
1469 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1470 scop
= extract_implications(ctx
, document
, value
, scop
);
1471 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1472 scop
= extract_independences(ctx
,
1473 document
, value
, scop
);
1478 if (!scop
->context_value
) {
1479 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1480 scop
->context_value
= isl_set_universe(space
);
1481 if (!scop
->context_value
)
1482 return pet_scop_free(scop
);
1488 /* Extract a pet_scop from the YAML description in "in".
1490 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1492 struct pet_scop
*scop
= NULL
;
1493 yaml_parser_t parser
;
1495 yaml_document_t document
= { 0 };
1497 yaml_parser_initialize(&parser
);
1499 yaml_parser_set_input_file(&parser
, in
);
1501 if (!yaml_parser_load(&parser
, &document
))
1504 root
= yaml_document_get_root_node(&document
);
1506 scop
= extract_scop(ctx
, &document
, root
);
1508 yaml_document_delete(&document
);
1510 yaml_parser_delete(&parser
);
1514 yaml_parser_delete(&parser
);
1515 pet_scop_free(scop
);