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
44 #include <isl/union_set.h>
45 #include <isl/union_map.h>
50 #include "scop_yaml.h"
53 static char *extract_string(isl_ctx
*ctx
, yaml_document_t
*document
,
56 if (node
->type
!= YAML_SCALAR_NODE
)
57 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
60 return strdup((char *) node
->data
.scalar
.value
);
63 static int extract_int(isl_ctx
*ctx
, yaml_document_t
*document
,
66 if (node
->type
!= YAML_SCALAR_NODE
)
67 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
70 return atoi((char *) node
->data
.scalar
.value
);
73 static double extract_double(isl_ctx
*ctx
, yaml_document_t
*document
,
76 if (node
->type
!= YAML_SCALAR_NODE
)
77 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
80 return strtod((char *) node
->data
.scalar
.value
, NULL
);
83 static enum pet_expr_type
extract_expr_type(isl_ctx
*ctx
,
84 yaml_document_t
*document
, yaml_node_t
*node
)
86 if (node
->type
!= YAML_SCALAR_NODE
)
87 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
90 return pet_str_type((char *) node
->data
.scalar
.value
);
93 static enum pet_op_type
extract_op(isl_ctx
*ctx
, yaml_document_t
*document
,
96 if (node
->type
!= YAML_SCALAR_NODE
)
97 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
100 return pet_str_op((char *) node
->data
.scalar
.value
);
103 static __isl_give isl_set
*extract_set(isl_ctx
*ctx
, yaml_document_t
*document
,
106 if (node
->type
!= YAML_SCALAR_NODE
)
107 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
110 return isl_set_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
113 static __isl_give isl_id
*extract_id(isl_ctx
*ctx
, yaml_document_t
*document
,
116 if (node
->type
!= YAML_SCALAR_NODE
)
117 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
120 return isl_id_alloc(ctx
, (char *) node
->data
.scalar
.value
, NULL
);
123 static __isl_give isl_map
*extract_map(isl_ctx
*ctx
, yaml_document_t
*document
,
126 if (node
->type
!= YAML_SCALAR_NODE
)
127 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
130 return isl_map_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
133 /* Extract an isl_union_set from "node".
135 static __isl_give isl_union_set
*extract_union_set(isl_ctx
*ctx
,
136 yaml_document_t
*document
, yaml_node_t
*node
)
138 if (node
->type
!= YAML_SCALAR_NODE
)
139 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
142 return isl_union_set_read_from_str(ctx
,
143 (char *) node
->data
.scalar
.value
);
146 /* Extract an isl_union_map from "node".
148 static __isl_give isl_union_map
*extract_union_map(isl_ctx
*ctx
,
149 yaml_document_t
*document
, yaml_node_t
*node
)
151 if (node
->type
!= YAML_SCALAR_NODE
)
152 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
155 return isl_union_map_read_from_str(ctx
,
156 (char *) node
->data
.scalar
.value
);
159 /* Extract an isl_val from "node".
161 static __isl_give isl_val
*extract_val(isl_ctx
*ctx
, yaml_document_t
*document
,
164 if (node
->type
!= YAML_SCALAR_NODE
)
165 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
168 return isl_val_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
171 /* Extract an isl_multi_pw_aff from "node".
173 static __isl_give isl_multi_pw_aff
*extract_multi_pw_aff(isl_ctx
*ctx
,
174 yaml_document_t
*document
, yaml_node_t
*node
)
176 if (node
->type
!= YAML_SCALAR_NODE
)
177 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
180 return isl_multi_pw_aff_read_from_str(ctx
,
181 (char *) node
->data
.scalar
.value
);
184 /* Extract an isl_schedule from "node".
186 static __isl_give isl_schedule
*extract_schedule(isl_ctx
*ctx
,
187 yaml_document_t
*document
, yaml_node_t
*node
)
189 if (node
->type
!= YAML_SCALAR_NODE
)
190 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
193 return isl_schedule_read_from_str(ctx
,
194 (char *) node
->data
.scalar
.value
);
197 /* Extract a pet_type from "node".
199 static struct pet_type
*extract_type(isl_ctx
*ctx
,
200 yaml_document_t
*document
, yaml_node_t
*node
)
202 struct pet_type
*type
;
203 yaml_node_pair_t
* pair
;
205 if (node
->type
!= YAML_MAPPING_NODE
)
206 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
209 type
= isl_calloc_type(ctx
, struct pet_type
);
213 for (pair
= node
->data
.mapping
.pairs
.start
;
214 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
215 yaml_node_t
*key
, *value
;
217 key
= yaml_document_get_node(document
, pair
->key
);
218 value
= yaml_document_get_node(document
, pair
->value
);
220 if (key
->type
!= YAML_SCALAR_NODE
)
221 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
222 return pet_type_free(type
));
224 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
225 type
->name
= extract_string(ctx
, document
, value
);
226 if (!strcmp((char *) key
->data
.scalar
.value
, "definition"))
227 type
->definition
= extract_string(ctx
, document
, value
);
233 /* Extract a sequence of types from "node" and store them in scop->types.
235 static struct pet_scop
*extract_types(isl_ctx
*ctx
,
236 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
239 yaml_node_item_t
*item
;
241 if (node
->type
!= YAML_SEQUENCE_NODE
)
242 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
245 scop
->n_type
= node
->data
.sequence
.items
.top
246 - node
->data
.sequence
.items
.start
;
247 scop
->types
= isl_calloc_array(ctx
, struct pet_type
*, scop
->n_type
);
249 return pet_scop_free(scop
);
251 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
252 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
255 n
= yaml_document_get_node(document
, *item
);
256 scop
->types
[i
] = extract_type(ctx
, document
, n
);
258 return pet_scop_free(scop
);
264 static struct pet_array
*extract_array(isl_ctx
*ctx
, yaml_document_t
*document
,
267 struct pet_array
*array
;
268 yaml_node_pair_t
* pair
;
270 if (node
->type
!= YAML_MAPPING_NODE
)
271 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
274 array
= isl_calloc_type(ctx
, struct pet_array
);
278 for (pair
= node
->data
.mapping
.pairs
.start
;
279 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
280 yaml_node_t
*key
, *value
;
282 key
= yaml_document_get_node(document
, pair
->key
);
283 value
= yaml_document_get_node(document
, pair
->value
);
285 if (key
->type
!= YAML_SCALAR_NODE
)
286 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
287 return pet_array_free(array
));
289 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
290 array
->context
= extract_set(ctx
, document
, value
);
291 if (!strcmp((char *) key
->data
.scalar
.value
, "extent"))
292 array
->extent
= extract_set(ctx
, document
, value
);
293 if (!strcmp((char *) key
->data
.scalar
.value
, "value_bounds"))
294 array
->value_bounds
= extract_set(ctx
, document
, value
);
295 if (!strcmp((char *) key
->data
.scalar
.value
, "element_type"))
296 array
->element_type
=
297 extract_string(ctx
, document
, value
);
298 if (!strcmp((char *) key
->data
.scalar
.value
, "element_size"))
299 array
->element_size
= extract_int(ctx
, document
, value
);
300 if (!strcmp((char *) key
->data
.scalar
.value
,
301 "element_is_record"))
302 array
->element_is_record
=
303 extract_int(ctx
, document
, value
);
304 if (!strcmp((char *) key
->data
.scalar
.value
, "live_out"))
305 array
->live_out
= extract_int(ctx
, document
, value
);
306 if (!strcmp((char *) key
->data
.scalar
.value
,
308 array
->uniquely_defined
=
309 extract_int(ctx
, document
, value
);
310 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
311 array
->declared
= extract_int(ctx
, document
, value
);
312 if (!strcmp((char *) key
->data
.scalar
.value
, "exposed"))
313 array
->exposed
= extract_int(ctx
, document
, value
);
319 static struct pet_scop
*extract_arrays(isl_ctx
*ctx
, yaml_document_t
*document
,
320 yaml_node_t
*node
, struct pet_scop
*scop
)
323 yaml_node_item_t
*item
;
325 if (node
->type
!= YAML_SEQUENCE_NODE
)
326 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
329 scop
->n_array
= node
->data
.sequence
.items
.top
330 - node
->data
.sequence
.items
.start
;
331 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*, scop
->n_array
);
333 return pet_scop_free(scop
);
335 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
336 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
339 n
= yaml_document_get_node(document
, *item
);
340 scop
->arrays
[i
] = extract_array(ctx
, document
, n
);
341 if (!scop
->arrays
[i
])
342 return pet_scop_free(scop
);
348 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
349 yaml_document_t
*document
, yaml_node_t
*node
);
351 static __isl_give pet_expr
*extract_arguments(isl_ctx
*ctx
,
352 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
355 yaml_node_item_t
*item
;
357 if (node
->type
!= YAML_SEQUENCE_NODE
)
358 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
359 return pet_expr_free(expr
));
361 n
= node
->data
.sequence
.items
.top
- node
->data
.sequence
.items
.start
;
362 expr
= pet_expr_set_n_arg(expr
, n
);
364 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
365 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
369 n
= yaml_document_get_node(document
, *item
);
370 arg
= extract_expr(ctx
, document
, n
);
371 expr
= pet_expr_set_arg(expr
, i
, arg
);
377 /* Extract pet_expr_double specific fields from "node" and
378 * update "expr" accordingly.
380 static __isl_give pet_expr
*extract_expr_double(isl_ctx
*ctx
,
381 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
383 yaml_node_pair_t
*pair
;
387 for (pair
= node
->data
.mapping
.pairs
.start
;
388 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
389 yaml_node_t
*key
, *value
;
391 key
= yaml_document_get_node(document
, pair
->key
);
392 value
= yaml_document_get_node(document
, pair
->value
);
394 if (key
->type
!= YAML_SCALAR_NODE
)
395 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
396 return pet_expr_free(expr
));
398 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
399 d
= extract_double(ctx
, document
, value
);
400 if (!strcmp((char *) key
->data
.scalar
.value
, "string"))
401 s
= extract_string(ctx
, document
, value
);
404 expr
= pet_expr_double_set(expr
, d
, s
);
410 /* Extract pet_expr_access specific fields from "node" and
411 * update "expr" accordingly.
413 * The depth of the access is initialized by pet_expr_access_set_index.
414 * Any explicitly specified depth therefore needs to be set after
415 * setting the index expression. Similiarly, the access relations (if any)
416 * need to be set after setting the depth.
418 static __isl_give pet_expr
*extract_expr_access(isl_ctx
*ctx
,
419 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
421 yaml_node_pair_t
*pair
;
423 isl_multi_pw_aff
*index
= NULL
;
425 for (pair
= node
->data
.mapping
.pairs
.start
;
426 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
427 yaml_node_t
*key
, *value
;
429 key
= yaml_document_get_node(document
, pair
->key
);
430 value
= yaml_document_get_node(document
, pair
->value
);
432 if (key
->type
!= YAML_SCALAR_NODE
)
433 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
434 return pet_expr_free(expr
));
436 if (!strcmp((char *) key
->data
.scalar
.value
, "index"))
437 index
= extract_multi_pw_aff(ctx
, document
, value
);
438 if (!strcmp((char *) key
->data
.scalar
.value
, "depth"))
439 depth
= extract_int(ctx
, document
, value
);
442 expr
= pet_expr_access_set_index(expr
, index
);
444 expr
= pet_expr_access_set_depth(expr
, depth
);
446 for (pair
= node
->data
.mapping
.pairs
.start
;
447 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
448 yaml_node_t
*key
, *value
;
450 key
= yaml_document_get_node(document
, pair
->key
);
451 value
= yaml_document_get_node(document
, pair
->value
);
453 if (key
->type
!= YAML_SCALAR_NODE
)
454 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
455 return pet_expr_free(expr
));
457 if (!strcmp((char *) key
->data
.scalar
.value
, "may_read"))
458 expr
= pet_expr_access_set_access(expr
,
459 pet_expr_access_may_read
,
460 extract_union_map(ctx
, document
, value
));
461 if (!strcmp((char *) key
->data
.scalar
.value
, "may_write"))
462 expr
= pet_expr_access_set_access(expr
,
463 pet_expr_access_may_write
,
464 extract_union_map(ctx
, document
, value
));
465 if (!strcmp((char *) key
->data
.scalar
.value
, "must_write"))
466 expr
= pet_expr_access_set_access(expr
,
467 pet_expr_access_must_write
,
468 extract_union_map(ctx
, document
, value
));
469 if (!strcmp((char *) key
->data
.scalar
.value
, "killed"))
470 expr
= pet_expr_access_set_access(expr
,
471 pet_expr_access_killed
,
472 extract_union_map(ctx
, document
, value
));
473 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
474 expr
= pet_expr_access_set_ref_id(expr
,
475 extract_id(ctx
, document
, value
));
476 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
477 expr
= pet_expr_access_set_read(expr
,
478 extract_int(ctx
, document
, value
));
479 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
480 expr
= pet_expr_access_set_write(expr
,
481 extract_int(ctx
, document
, value
));
482 if (!strcmp((char *) key
->data
.scalar
.value
, "kill"))
483 expr
= pet_expr_access_set_kill(expr
,
484 extract_int(ctx
, document
, value
));
490 /* Extract operation expression specific fields from "node" and
491 * update "expr" accordingly.
493 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
494 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
496 yaml_node_pair_t
*pair
;
498 for (pair
= node
->data
.mapping
.pairs
.start
;
499 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
500 yaml_node_t
*key
, *value
;
502 key
= yaml_document_get_node(document
, pair
->key
);
503 value
= yaml_document_get_node(document
, pair
->value
);
505 if (key
->type
!= YAML_SCALAR_NODE
)
506 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
507 return pet_expr_free(expr
));
509 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
510 expr
= pet_expr_op_set_type(expr
,
511 extract_op(ctx
, document
, value
));
517 /* Extract pet_expr_call specific fields from "node" and
518 * update "expr" accordingly.
520 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
521 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
523 yaml_node_pair_t
*pair
;
525 for (pair
= node
->data
.mapping
.pairs
.start
;
526 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
527 yaml_node_t
*key
, *value
;
529 key
= yaml_document_get_node(document
, pair
->key
);
530 value
= yaml_document_get_node(document
, pair
->value
);
532 if (key
->type
!= YAML_SCALAR_NODE
)
533 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
534 return pet_expr_free(expr
));
536 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
537 expr
= pet_expr_call_set_name(expr
,
538 extract_string(ctx
, document
, value
));
544 /* Extract pet_expr_cast specific fields from "node" and
545 * update "expr" accordingly.
547 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
548 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
550 yaml_node_pair_t
*pair
;
552 for (pair
= node
->data
.mapping
.pairs
.start
;
553 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
554 yaml_node_t
*key
, *value
;
556 key
= yaml_document_get_node(document
, pair
->key
);
557 value
= yaml_document_get_node(document
, pair
->value
);
559 if (key
->type
!= YAML_SCALAR_NODE
)
560 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
561 return pet_expr_free(expr
));
563 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
564 expr
= pet_expr_cast_set_type_name(expr
,
565 extract_string(ctx
, document
, value
));
571 /* Extract pet_expr_int specific fields from "node" and
572 * update "expr" accordingly.
574 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
575 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
577 yaml_node_pair_t
* pair
;
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
, "value"))
591 expr
= pet_expr_int_set_val(expr
,
592 extract_val(ctx
, document
, value
));
598 /* Extract a pet_expr from "node".
600 * We first extract the type and arguments of the expression and
601 * then extract additional fields depending on the type.
603 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
604 yaml_document_t
*document
, yaml_node_t
*node
)
606 enum pet_expr_type type
= pet_expr_error
;
608 yaml_node_pair_t
*pair
;
610 if (node
->type
!= YAML_MAPPING_NODE
)
611 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
614 for (pair
= node
->data
.mapping
.pairs
.start
;
615 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
616 yaml_node_t
*key
, *value
;
618 key
= yaml_document_get_node(document
, pair
->key
);
619 value
= yaml_document_get_node(document
, pair
->value
);
621 if (key
->type
!= YAML_SCALAR_NODE
)
622 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
623 return pet_expr_free(expr
));
625 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
626 type
= extract_expr_type(ctx
, document
, value
);
629 if (type
== pet_expr_error
)
630 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
633 expr
= pet_expr_alloc(ctx
, type
);
637 for (pair
= node
->data
.mapping
.pairs
.start
;
638 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
639 yaml_node_t
*key
, *value
;
641 key
= yaml_document_get_node(document
, pair
->key
);
642 value
= yaml_document_get_node(document
, pair
->value
);
644 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
645 expr
= extract_arguments(ctx
, document
, value
, expr
);
652 isl_die(ctx
, isl_error_internal
, "unreachable code",
654 case pet_expr_access
:
655 expr
= extract_expr_access(ctx
, document
, node
, expr
);
657 case pet_expr_double
:
658 expr
= extract_expr_double(ctx
, document
, node
, expr
);
661 expr
= extract_expr_call(ctx
, document
, node
, expr
);
664 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
667 expr
= extract_expr_int(ctx
, document
, node
, expr
);
670 expr
= extract_expr_op(ctx
, document
, node
, expr
);
677 /* Extract a pet_tree_type from "node".
679 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
680 yaml_document_t
*document
, yaml_node_t
*node
)
682 if (node
->type
!= YAML_SCALAR_NODE
)
683 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
686 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
689 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
690 yaml_document_t
*document
, yaml_node_t
*node
);
692 /* Extract a pet_tree of type pet_tree_block from "node".
694 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
695 yaml_document_t
*document
, yaml_node_t
*node
)
699 yaml_node_pair_t
*pair
;
700 yaml_node_item_t
*item
;
701 yaml_node_t
*children
= NULL
;
704 for (pair
= node
->data
.mapping
.pairs
.start
;
705 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
706 yaml_node_t
*key
, *value
;
708 key
= yaml_document_get_node(document
, pair
->key
);
709 value
= yaml_document_get_node(document
, pair
->value
);
711 if (key
->type
!= YAML_SCALAR_NODE
)
712 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
715 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
716 block
= extract_int(ctx
, document
, value
);
717 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
724 n
= children
->data
.sequence
.items
.top
-
725 children
->data
.sequence
.items
.start
;
727 tree
= pet_tree_new_block(ctx
, block
, n
);
731 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
732 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
736 n
= yaml_document_get_node(document
, *item
);
737 child
= extract_tree(ctx
, document
, n
);
738 tree
= pet_tree_block_add_child(tree
, child
);
744 /* Extract a pet_tree of type pet_tree_decl from "node".
746 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
747 yaml_document_t
*document
, yaml_node_t
*node
)
749 yaml_node_pair_t
*pair
;
750 pet_expr
*var
= NULL
;
752 for (pair
= node
->data
.mapping
.pairs
.start
;
753 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
754 yaml_node_t
*key
, *value
;
756 key
= yaml_document_get_node(document
, pair
->key
);
757 value
= yaml_document_get_node(document
, pair
->value
);
759 if (key
->type
!= YAML_SCALAR_NODE
)
760 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
763 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
764 var
= extract_expr(ctx
, document
, value
);
771 isl_die(ctx
, isl_error_invalid
,
772 "no variable field", return NULL
);
774 return pet_tree_new_decl(var
);
777 /* Extract a pet_tree of type pet_tree_decl_init from "node".
779 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
780 yaml_document_t
*document
, yaml_node_t
*node
)
782 yaml_node_pair_t
*pair
;
783 pet_expr
*var
= NULL
;
784 pet_expr
*init
= NULL
;
786 for (pair
= node
->data
.mapping
.pairs
.start
;
787 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
788 yaml_node_t
*key
, *value
;
790 key
= yaml_document_get_node(document
, pair
->key
);
791 value
= yaml_document_get_node(document
, pair
->value
);
793 if (key
->type
!= YAML_SCALAR_NODE
)
794 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
797 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
798 var
= extract_expr(ctx
, document
, value
);
802 if (!strcmp((char *) key
->data
.scalar
.value
,
804 init
= extract_expr(ctx
, document
, value
);
811 isl_die(ctx
, isl_error_invalid
,
812 "no variable field", goto error
);
814 isl_die(ctx
, isl_error_invalid
,
815 "no initialization field", goto error
);
817 return pet_tree_new_decl_init(var
, init
);
824 /* Extract a pet_tree of type pet_tree_expr from "node".
826 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
827 yaml_document_t
*document
, yaml_node_t
*node
)
829 yaml_node_pair_t
*pair
;
830 pet_expr
*expr
= NULL
;
832 for (pair
= node
->data
.mapping
.pairs
.start
;
833 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
834 yaml_node_t
*key
, *value
;
836 key
= yaml_document_get_node(document
, pair
->key
);
837 value
= yaml_document_get_node(document
, pair
->value
);
839 if (key
->type
!= YAML_SCALAR_NODE
)
840 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
843 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
844 expr
= extract_expr(ctx
, document
, value
);
851 isl_die(ctx
, isl_error_invalid
,
852 "no expr field", return NULL
);
854 return pet_tree_new_expr(expr
);
857 /* Extract a pet_tree of type pet_tree_while from "node".
859 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
860 yaml_document_t
*document
, yaml_node_t
*node
)
862 yaml_node_pair_t
*pair
;
863 pet_expr
*cond
= NULL
;
864 pet_tree
*body
= NULL
;
866 for (pair
= node
->data
.mapping
.pairs
.start
;
867 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
868 yaml_node_t
*key
, *value
;
870 key
= yaml_document_get_node(document
, pair
->key
);
871 value
= yaml_document_get_node(document
, pair
->value
);
873 if (key
->type
!= YAML_SCALAR_NODE
)
874 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
877 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
878 cond
= extract_expr(ctx
, document
, value
);
882 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
883 body
= extract_tree(ctx
, document
, value
);
890 isl_die(ctx
, isl_error_invalid
,
891 "no condition field", goto error
);
893 isl_die(ctx
, isl_error_invalid
,
894 "no body field", goto error
);
896 return pet_tree_new_while(cond
, body
);
903 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
905 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
906 yaml_document_t
*document
, yaml_node_t
*node
)
908 yaml_node_pair_t
*pair
;
911 for (pair
= node
->data
.mapping
.pairs
.start
;
912 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
913 yaml_node_t
*key
, *value
;
915 key
= yaml_document_get_node(document
, pair
->key
);
916 value
= yaml_document_get_node(document
, pair
->value
);
918 if (key
->type
!= YAML_SCALAR_NODE
)
919 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
922 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
923 body
= extract_tree(ctx
, document
, value
);
930 isl_die(ctx
, isl_error_invalid
,
931 "no body field", return NULL
);
933 return pet_tree_new_infinite_loop(body
);
936 /* Extract a pet_tree of type pet_tree_if from "node".
938 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
939 yaml_document_t
*document
, yaml_node_t
*node
)
941 yaml_node_pair_t
*pair
;
942 pet_expr
*cond
= NULL
;
943 pet_tree
*then_body
= NULL
;
945 for (pair
= node
->data
.mapping
.pairs
.start
;
946 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
947 yaml_node_t
*key
, *value
;
949 key
= yaml_document_get_node(document
, pair
->key
);
950 value
= yaml_document_get_node(document
, pair
->value
);
952 if (key
->type
!= YAML_SCALAR_NODE
)
953 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
956 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
957 cond
= extract_expr(ctx
, document
, value
);
961 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
962 then_body
= extract_tree(ctx
, document
, value
);
969 isl_die(ctx
, isl_error_invalid
,
970 "no condition field", goto error
);
972 isl_die(ctx
, isl_error_invalid
,
973 "no then body", goto error
);
975 return pet_tree_new_if(cond
, then_body
);
978 pet_tree_free(then_body
);
982 /* Extract a pet_tree of type pet_tree_if_else from "node".
984 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
985 yaml_document_t
*document
, yaml_node_t
*node
)
987 yaml_node_pair_t
*pair
;
988 pet_expr
*cond
= NULL
;
989 pet_tree
*then_body
= NULL
;
990 pet_tree
*else_body
= NULL
;
992 for (pair
= node
->data
.mapping
.pairs
.start
;
993 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
994 yaml_node_t
*key
, *value
;
996 key
= yaml_document_get_node(document
, pair
->key
);
997 value
= yaml_document_get_node(document
, pair
->value
);
999 if (key
->type
!= YAML_SCALAR_NODE
)
1000 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1003 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1004 cond
= extract_expr(ctx
, document
, value
);
1008 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
1009 then_body
= extract_tree(ctx
, document
, value
);
1013 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
1014 else_body
= extract_tree(ctx
, document
, value
);
1021 isl_die(ctx
, isl_error_invalid
,
1022 "no condition field", goto error
);
1024 isl_die(ctx
, isl_error_invalid
,
1025 "no then body", goto error
);
1027 isl_die(ctx
, isl_error_invalid
,
1028 "no else body", goto error
);
1030 return pet_tree_new_if_else(cond
, then_body
, else_body
);
1032 pet_expr_free(cond
);
1033 pet_tree_free(then_body
);
1034 pet_tree_free(else_body
);
1038 /* Extract a pet_tree of type pet_tree_for from "node".
1040 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1041 yaml_document_t
*document
, yaml_node_t
*node
)
1043 yaml_node_pair_t
*pair
;
1045 int independent
= 0;
1046 pet_expr
*iv
= NULL
;
1047 pet_expr
*init
= NULL
;
1048 pet_expr
*cond
= NULL
;
1049 pet_expr
*inc
= NULL
;
1050 pet_tree
*body
= NULL
;
1052 for (pair
= node
->data
.mapping
.pairs
.start
;
1053 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1054 yaml_node_t
*key
, *value
;
1056 key
= yaml_document_get_node(document
, pair
->key
);
1057 value
= yaml_document_get_node(document
, pair
->value
);
1059 if (key
->type
!= YAML_SCALAR_NODE
)
1060 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1063 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1064 declared
= extract_int(ctx
, document
, value
);
1065 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1066 independent
= extract_int(ctx
, document
, value
);
1067 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1068 iv
= extract_expr(ctx
, document
, value
);
1072 if (!strcmp((char *) key
->data
.scalar
.value
,
1073 "initialization")) {
1074 init
= extract_expr(ctx
, document
, value
);
1078 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1079 cond
= extract_expr(ctx
, document
, value
);
1083 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1084 inc
= extract_expr(ctx
, document
, value
);
1088 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1089 body
= extract_tree(ctx
, document
, value
);
1096 isl_die(ctx
, isl_error_invalid
,
1097 "no variable field", goto error
);
1099 isl_die(ctx
, isl_error_invalid
,
1100 "no initialization field", goto error
);
1102 isl_die(ctx
, isl_error_invalid
,
1103 "no condition field", goto error
);
1105 isl_die(ctx
, isl_error_invalid
,
1106 "no increment field", goto error
);
1108 isl_die(ctx
, isl_error_invalid
,
1109 "no body field", goto error
);
1111 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1115 pet_expr_free(init
);
1116 pet_expr_free(cond
);
1118 pet_tree_free(body
);
1122 /* Extract a pet_tree from "node".
1124 * We first extract the type of the pet_tree and then call
1125 * the appropriate function to extract and construct a pet_tree
1128 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1129 yaml_document_t
*document
, yaml_node_t
*node
)
1131 enum pet_tree_type type
= pet_tree_error
;
1133 yaml_node_pair_t
*pair
;
1135 if (node
->type
!= YAML_MAPPING_NODE
)
1136 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1139 for (pair
= node
->data
.mapping
.pairs
.start
;
1140 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1141 yaml_node_t
*key
, *value
;
1143 key
= yaml_document_get_node(document
, pair
->key
);
1144 value
= yaml_document_get_node(document
, pair
->value
);
1146 if (key
->type
!= YAML_SCALAR_NODE
)
1147 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1148 return pet_tree_free(tree
));
1150 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1151 type
= extract_tree_type(ctx
, document
, value
);
1154 if (type
== pet_tree_error
)
1155 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1159 case pet_tree_error
:
1161 case pet_tree_block
:
1162 tree
= extract_tree_block(ctx
, document
, node
);
1164 case pet_tree_break
:
1165 tree
= pet_tree_new_break(ctx
);
1167 case pet_tree_continue
:
1168 tree
= pet_tree_new_continue(ctx
);
1171 tree
= extract_tree_decl(ctx
, document
, node
);
1173 case pet_tree_decl_init
:
1174 tree
= extract_tree_decl_init(ctx
, document
, node
);
1177 tree
= extract_tree_expr(ctx
, document
, node
);
1180 tree
= extract_tree_for(ctx
, document
, node
);
1182 case pet_tree_while
:
1183 tree
= extract_tree_while(ctx
, document
, node
);
1185 case pet_tree_infinite_loop
:
1186 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1189 tree
= extract_tree_if(ctx
, document
, node
);
1191 case pet_tree_if_else
:
1192 tree
= extract_tree_if_else(ctx
, document
, node
);
1199 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1200 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1203 yaml_node_item_t
*item
;
1205 if (node
->type
!= YAML_SEQUENCE_NODE
)
1206 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1207 return pet_stmt_free(stmt
));
1209 stmt
->n_arg
= node
->data
.sequence
.items
.top
1210 - node
->data
.sequence
.items
.start
;
1211 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1213 return pet_stmt_free(stmt
);
1215 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1216 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1219 n
= yaml_document_get_node(document
, *item
);
1220 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1222 return pet_stmt_free(stmt
);
1228 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1231 struct pet_stmt
*stmt
;
1232 yaml_node_pair_t
* pair
;
1234 unsigned start
= 0, end
= 0;
1235 char *indent
= NULL
;
1237 if (node
->type
!= YAML_MAPPING_NODE
)
1238 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1241 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1245 stmt
->loc
= &pet_loc_dummy
;
1247 for (pair
= node
->data
.mapping
.pairs
.start
;
1248 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1249 yaml_node_t
*key
, *value
;
1251 key
= yaml_document_get_node(document
, pair
->key
);
1252 value
= yaml_document_get_node(document
, pair
->value
);
1254 if (key
->type
!= YAML_SCALAR_NODE
)
1255 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1256 return pet_stmt_free(stmt
));
1258 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1259 indent
= extract_string(ctx
, document
, value
);
1260 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1261 line
= extract_int(ctx
, document
, value
);
1262 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1263 start
= extract_int(ctx
, document
, value
);
1264 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1265 end
= extract_int(ctx
, document
, value
);
1266 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1267 stmt
->domain
= extract_set(ctx
, document
, value
);
1268 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1269 stmt
->body
= extract_tree(ctx
, document
, value
);
1271 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1272 stmt
= extract_stmt_arguments(ctx
, document
,
1279 indent
= strdup("");
1280 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1282 return pet_stmt_free(stmt
);
1287 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1288 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1291 yaml_node_item_t
*item
;
1293 if (node
->type
!= YAML_SEQUENCE_NODE
)
1294 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1297 scop
->n_stmt
= node
->data
.sequence
.items
.top
1298 - node
->data
.sequence
.items
.start
;
1299 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1301 return pet_scop_free(scop
);
1303 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1304 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1307 n
= yaml_document_get_node(document
, *item
);
1308 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1309 if (!scop
->stmts
[i
])
1310 return pet_scop_free(scop
);
1316 /* Extract a pet_implication from "node".
1318 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1319 yaml_document_t
*document
, yaml_node_t
*node
)
1321 struct pet_implication
*implication
;
1322 yaml_node_pair_t
* pair
;
1324 if (node
->type
!= YAML_MAPPING_NODE
)
1325 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1328 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1332 for (pair
= node
->data
.mapping
.pairs
.start
;
1333 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1334 yaml_node_t
*key
, *value
;
1336 key
= yaml_document_get_node(document
, pair
->key
);
1337 value
= yaml_document_get_node(document
, pair
->value
);
1339 if (key
->type
!= YAML_SCALAR_NODE
)
1340 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1341 return pet_implication_free(implication
));
1343 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1344 implication
->satisfied
=
1345 extract_int(ctx
, document
, value
);
1346 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1347 implication
->extension
=
1348 extract_map(ctx
, document
, value
);
1354 /* Extract a sequence of implications from "node" and
1355 * store them in scop->implications.
1357 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1358 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1361 yaml_node_item_t
*item
;
1363 if (node
->type
!= YAML_SEQUENCE_NODE
)
1364 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1367 scop
->n_implication
= node
->data
.sequence
.items
.top
1368 - node
->data
.sequence
.items
.start
;
1369 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1370 scop
->n_implication
);
1371 if (!scop
->implications
)
1372 return pet_scop_free(scop
);
1374 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1375 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1378 n
= yaml_document_get_node(document
, *item
);
1379 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1380 if (!scop
->implications
[i
])
1381 return pet_scop_free(scop
);
1387 /* Extract a pet_independence from "node".
1389 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1390 yaml_document_t
*document
, yaml_node_t
*node
)
1392 struct pet_independence
*independence
;
1393 yaml_node_pair_t
* pair
;
1395 if (node
->type
!= YAML_MAPPING_NODE
)
1396 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1399 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1403 for (pair
= node
->data
.mapping
.pairs
.start
;
1404 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1405 yaml_node_t
*key
, *value
;
1407 key
= yaml_document_get_node(document
, pair
->key
);
1408 value
= yaml_document_get_node(document
, pair
->value
);
1410 if (key
->type
!= YAML_SCALAR_NODE
)
1411 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1412 return pet_independence_free(independence
));
1414 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1415 independence
->filter
=
1416 extract_union_map(ctx
, document
, value
);
1417 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1418 independence
->local
=
1419 extract_union_set(ctx
, document
, value
);
1422 if (!independence
->filter
)
1423 isl_die(ctx
, isl_error_invalid
, "no filter field",
1424 return pet_independence_free(independence
));
1425 if (!independence
->local
)
1426 isl_die(ctx
, isl_error_invalid
, "no local field",
1427 return pet_independence_free(independence
));
1429 return independence
;
1432 /* Extract a sequence of independences from "node" and
1433 * store them in scop->independences.
1435 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1436 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1439 yaml_node_item_t
*item
;
1441 if (node
->type
!= YAML_SEQUENCE_NODE
)
1442 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1445 scop
->n_independence
= node
->data
.sequence
.items
.top
1446 - node
->data
.sequence
.items
.start
;
1447 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1448 scop
->n_independence
);
1449 if (!scop
->independences
)
1450 return pet_scop_free(scop
);
1452 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1453 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1456 n
= yaml_document_get_node(document
, *item
);
1457 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1458 if (!scop
->independences
[i
])
1459 return pet_scop_free(scop
);
1465 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1468 struct pet_scop
*scop
;
1469 yaml_node_pair_t
* pair
;
1474 if (node
->type
!= YAML_MAPPING_NODE
)
1475 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1478 scop
= pet_scop_alloc(ctx
);
1482 for (pair
= node
->data
.mapping
.pairs
.start
;
1483 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1484 yaml_node_t
*key
, *value
;
1486 key
= yaml_document_get_node(document
, pair
->key
);
1487 value
= yaml_document_get_node(document
, pair
->value
);
1489 if (key
->type
!= YAML_SCALAR_NODE
)
1490 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1491 return pet_scop_free(scop
));
1492 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1493 scop
->context
= extract_set(ctx
, document
, value
);
1494 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1495 scop
->context_value
= extract_set(ctx
, document
, value
);
1496 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1497 scop
->schedule
= extract_schedule(ctx
, document
, value
);
1498 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1499 scop
= extract_types(ctx
, document
, value
, scop
);
1500 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1501 scop
= extract_arrays(ctx
, document
, value
, scop
);
1502 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1503 scop
= extract_statements(ctx
, document
, value
, scop
);
1504 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1505 scop
= extract_implications(ctx
, document
, value
, scop
);
1506 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1507 scop
= extract_independences(ctx
,
1508 document
, value
, scop
);
1513 if (!scop
->context_value
) {
1514 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1515 scop
->context_value
= isl_set_universe(space
);
1516 if (!scop
->context_value
)
1517 return pet_scop_free(scop
);
1523 /* Extract a pet_scop from the YAML description in "in".
1525 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1527 struct pet_scop
*scop
= NULL
;
1528 yaml_parser_t parser
;
1530 yaml_document_t document
= { 0 };
1532 yaml_parser_initialize(&parser
);
1534 yaml_parser_set_input_file(&parser
, in
);
1536 if (!yaml_parser_load(&parser
, &document
))
1539 root
= yaml_document_get_root_node(&document
);
1541 scop
= extract_scop(ctx
, &document
, root
);
1543 yaml_document_delete(&document
);
1545 yaml_parser_delete(&parser
);
1549 yaml_parser_delete(&parser
);
1550 pet_scop_free(scop
);