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 an isl_schedule from "node".
177 static __isl_give isl_schedule
*extract_schedule(isl_ctx
*ctx
,
178 yaml_document_t
*document
, yaml_node_t
*node
)
180 if (node
->type
!= YAML_SCALAR_NODE
)
181 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
184 return isl_schedule_read_from_str(ctx
,
185 (char *) node
->data
.scalar
.value
);
188 /* Extract a pet_type from "node".
190 static struct pet_type
*extract_type(isl_ctx
*ctx
,
191 yaml_document_t
*document
, yaml_node_t
*node
)
193 struct pet_type
*type
;
194 yaml_node_pair_t
* pair
;
196 if (node
->type
!= YAML_MAPPING_NODE
)
197 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
200 type
= isl_calloc_type(ctx
, struct pet_type
);
204 for (pair
= node
->data
.mapping
.pairs
.start
;
205 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
206 yaml_node_t
*key
, *value
;
208 key
= yaml_document_get_node(document
, pair
->key
);
209 value
= yaml_document_get_node(document
, pair
->value
);
211 if (key
->type
!= YAML_SCALAR_NODE
)
212 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
213 return pet_type_free(type
));
215 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
216 type
->name
= extract_string(ctx
, document
, value
);
217 if (!strcmp((char *) key
->data
.scalar
.value
, "definition"))
218 type
->definition
= extract_string(ctx
, document
, value
);
224 /* Extract a sequence of types from "node" and store them in scop->types.
226 static struct pet_scop
*extract_types(isl_ctx
*ctx
,
227 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
230 yaml_node_item_t
*item
;
232 if (node
->type
!= YAML_SEQUENCE_NODE
)
233 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
236 scop
->n_type
= node
->data
.sequence
.items
.top
237 - node
->data
.sequence
.items
.start
;
238 scop
->types
= isl_calloc_array(ctx
, struct pet_type
*, scop
->n_type
);
240 return pet_scop_free(scop
);
242 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
243 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
246 n
= yaml_document_get_node(document
, *item
);
247 scop
->types
[i
] = extract_type(ctx
, document
, n
);
249 return pet_scop_free(scop
);
255 static struct pet_array
*extract_array(isl_ctx
*ctx
, yaml_document_t
*document
,
258 struct pet_array
*array
;
259 yaml_node_pair_t
* pair
;
261 if (node
->type
!= YAML_MAPPING_NODE
)
262 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
265 array
= isl_calloc_type(ctx
, struct pet_array
);
269 for (pair
= node
->data
.mapping
.pairs
.start
;
270 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
271 yaml_node_t
*key
, *value
;
273 key
= yaml_document_get_node(document
, pair
->key
);
274 value
= yaml_document_get_node(document
, pair
->value
);
276 if (key
->type
!= YAML_SCALAR_NODE
)
277 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
278 return pet_array_free(array
));
280 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
281 array
->context
= extract_set(ctx
, document
, value
);
282 if (!strcmp((char *) key
->data
.scalar
.value
, "extent"))
283 array
->extent
= extract_set(ctx
, document
, value
);
284 if (!strcmp((char *) key
->data
.scalar
.value
, "value_bounds"))
285 array
->value_bounds
= extract_set(ctx
, document
, value
);
286 if (!strcmp((char *) key
->data
.scalar
.value
, "element_type"))
287 array
->element_type
=
288 extract_string(ctx
, document
, value
);
289 if (!strcmp((char *) key
->data
.scalar
.value
, "element_size"))
290 array
->element_size
= extract_int(ctx
, document
, value
);
291 if (!strcmp((char *) key
->data
.scalar
.value
,
292 "element_is_record"))
293 array
->element_is_record
=
294 extract_int(ctx
, document
, value
);
295 if (!strcmp((char *) key
->data
.scalar
.value
, "live_out"))
296 array
->live_out
= extract_int(ctx
, document
, value
);
297 if (!strcmp((char *) key
->data
.scalar
.value
,
299 array
->uniquely_defined
=
300 extract_int(ctx
, document
, value
);
301 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
302 array
->declared
= extract_int(ctx
, document
, value
);
303 if (!strcmp((char *) key
->data
.scalar
.value
, "exposed"))
304 array
->exposed
= extract_int(ctx
, document
, value
);
310 static struct pet_scop
*extract_arrays(isl_ctx
*ctx
, yaml_document_t
*document
,
311 yaml_node_t
*node
, struct pet_scop
*scop
)
314 yaml_node_item_t
*item
;
316 if (node
->type
!= YAML_SEQUENCE_NODE
)
317 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
320 scop
->n_array
= node
->data
.sequence
.items
.top
321 - node
->data
.sequence
.items
.start
;
322 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*, scop
->n_array
);
324 return pet_scop_free(scop
);
326 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
327 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
330 n
= yaml_document_get_node(document
, *item
);
331 scop
->arrays
[i
] = extract_array(ctx
, document
, n
);
332 if (!scop
->arrays
[i
])
333 return pet_scop_free(scop
);
339 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
340 yaml_document_t
*document
, yaml_node_t
*node
);
342 static __isl_give pet_expr
*extract_arguments(isl_ctx
*ctx
,
343 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
346 yaml_node_item_t
*item
;
348 if (node
->type
!= YAML_SEQUENCE_NODE
)
349 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
350 return pet_expr_free(expr
));
352 n
= node
->data
.sequence
.items
.top
- node
->data
.sequence
.items
.start
;
353 expr
= pet_expr_set_n_arg(expr
, n
);
355 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
356 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
360 n
= yaml_document_get_node(document
, *item
);
361 arg
= extract_expr(ctx
, document
, n
);
362 expr
= pet_expr_set_arg(expr
, i
, arg
);
368 /* Extract pet_expr_double specific fields from "node" and
369 * update "expr" accordingly.
371 static __isl_give pet_expr
*extract_expr_double(isl_ctx
*ctx
,
372 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
374 yaml_node_pair_t
*pair
;
378 for (pair
= node
->data
.mapping
.pairs
.start
;
379 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
380 yaml_node_t
*key
, *value
;
382 key
= yaml_document_get_node(document
, pair
->key
);
383 value
= yaml_document_get_node(document
, pair
->value
);
385 if (key
->type
!= YAML_SCALAR_NODE
)
386 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
387 return pet_expr_free(expr
));
389 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
390 d
= extract_double(ctx
, document
, value
);
391 if (!strcmp((char *) key
->data
.scalar
.value
, "string"))
392 s
= extract_string(ctx
, document
, value
);
395 expr
= pet_expr_double_set(expr
, d
, s
);
401 /* Extract pet_expr_access specific fields from "node" and
402 * update "expr" accordingly.
404 * The depth of the access is initialized by pet_expr_access_set_index.
405 * Any explicitly specified depth therefore needs to be set after
406 * setting the index expression. Similiarly, the access relations (if any)
407 * need to be set after setting the depth.
409 static __isl_give pet_expr
*extract_expr_access(isl_ctx
*ctx
,
410 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
412 yaml_node_pair_t
*pair
;
414 isl_multi_pw_aff
*index
= NULL
;
416 for (pair
= node
->data
.mapping
.pairs
.start
;
417 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
418 yaml_node_t
*key
, *value
;
420 key
= yaml_document_get_node(document
, pair
->key
);
421 value
= yaml_document_get_node(document
, pair
->value
);
423 if (key
->type
!= YAML_SCALAR_NODE
)
424 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
425 return pet_expr_free(expr
));
427 if (!strcmp((char *) key
->data
.scalar
.value
, "index"))
428 index
= extract_multi_pw_aff(ctx
, document
, value
);
429 if (!strcmp((char *) key
->data
.scalar
.value
, "depth"))
430 depth
= extract_int(ctx
, document
, value
);
433 expr
= pet_expr_access_set_index(expr
, index
);
435 expr
= pet_expr_access_set_depth(expr
, depth
);
437 for (pair
= node
->data
.mapping
.pairs
.start
;
438 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
439 yaml_node_t
*key
, *value
;
441 key
= yaml_document_get_node(document
, pair
->key
);
442 value
= yaml_document_get_node(document
, pair
->value
);
444 if (key
->type
!= YAML_SCALAR_NODE
)
445 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
446 return pet_expr_free(expr
));
448 if (!strcmp((char *) key
->data
.scalar
.value
, "may_read"))
449 expr
= pet_expr_access_set_access(expr
,
450 pet_expr_access_may_read
,
451 extract_union_map(ctx
, document
, value
));
452 if (!strcmp((char *) key
->data
.scalar
.value
, "may_write"))
453 expr
= pet_expr_access_set_access(expr
,
454 pet_expr_access_may_write
,
455 extract_union_map(ctx
, document
, value
));
456 if (!strcmp((char *) key
->data
.scalar
.value
, "must_write"))
457 expr
= pet_expr_access_set_access(expr
,
458 pet_expr_access_must_write
,
459 extract_union_map(ctx
, document
, value
));
460 if (!strcmp((char *) key
->data
.scalar
.value
, "killed"))
461 expr
= pet_expr_access_set_access(expr
,
462 pet_expr_access_killed
,
463 extract_union_map(ctx
, document
, value
));
464 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
465 expr
= pet_expr_access_set_ref_id(expr
,
466 extract_id(ctx
, document
, value
));
467 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
468 expr
= pet_expr_access_set_read(expr
,
469 extract_int(ctx
, document
, value
));
470 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
471 expr
= pet_expr_access_set_write(expr
,
472 extract_int(ctx
, document
, value
));
473 if (!strcmp((char *) key
->data
.scalar
.value
, "kill"))
474 expr
= pet_expr_access_set_kill(expr
,
475 extract_int(ctx
, document
, value
));
481 /* Extract operation expression specific fields from "node" and
482 * update "expr" accordingly.
484 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
485 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
487 yaml_node_pair_t
*pair
;
489 for (pair
= node
->data
.mapping
.pairs
.start
;
490 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
491 yaml_node_t
*key
, *value
;
493 key
= yaml_document_get_node(document
, pair
->key
);
494 value
= yaml_document_get_node(document
, pair
->value
);
496 if (key
->type
!= YAML_SCALAR_NODE
)
497 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
498 return pet_expr_free(expr
));
500 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
501 expr
= pet_expr_op_set_type(expr
,
502 extract_op(ctx
, document
, value
));
508 /* Extract pet_expr_call specific fields from "node" and
509 * update "expr" accordingly.
511 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
512 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
514 yaml_node_pair_t
*pair
;
516 for (pair
= node
->data
.mapping
.pairs
.start
;
517 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
518 yaml_node_t
*key
, *value
;
520 key
= yaml_document_get_node(document
, pair
->key
);
521 value
= yaml_document_get_node(document
, pair
->value
);
523 if (key
->type
!= YAML_SCALAR_NODE
)
524 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
525 return pet_expr_free(expr
));
527 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
528 expr
= pet_expr_call_set_name(expr
,
529 extract_string(ctx
, document
, value
));
535 /* Extract pet_expr_cast specific fields from "node" and
536 * update "expr" accordingly.
538 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
539 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
541 yaml_node_pair_t
*pair
;
543 for (pair
= node
->data
.mapping
.pairs
.start
;
544 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
545 yaml_node_t
*key
, *value
;
547 key
= yaml_document_get_node(document
, pair
->key
);
548 value
= yaml_document_get_node(document
, pair
->value
);
550 if (key
->type
!= YAML_SCALAR_NODE
)
551 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
552 return pet_expr_free(expr
));
554 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
555 expr
= pet_expr_cast_set_type_name(expr
,
556 extract_string(ctx
, document
, value
));
562 /* Extract pet_expr_int specific fields from "node" and
563 * update "expr" accordingly.
565 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
566 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
568 yaml_node_pair_t
* pair
;
570 for (pair
= node
->data
.mapping
.pairs
.start
;
571 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
572 yaml_node_t
*key
, *value
;
574 key
= yaml_document_get_node(document
, pair
->key
);
575 value
= yaml_document_get_node(document
, pair
->value
);
577 if (key
->type
!= YAML_SCALAR_NODE
)
578 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
579 return pet_expr_free(expr
));
581 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
582 expr
= pet_expr_int_set_val(expr
,
583 extract_val(ctx
, document
, value
));
589 /* Extract a pet_expr from "node".
591 * We first extract the type and arguments of the expression and
592 * then extract additional fields depending on the type.
594 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
595 yaml_document_t
*document
, yaml_node_t
*node
)
597 enum pet_expr_type type
= pet_expr_error
;
599 yaml_node_pair_t
*pair
;
601 if (node
->type
!= YAML_MAPPING_NODE
)
602 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
605 for (pair
= node
->data
.mapping
.pairs
.start
;
606 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
607 yaml_node_t
*key
, *value
;
609 key
= yaml_document_get_node(document
, pair
->key
);
610 value
= yaml_document_get_node(document
, pair
->value
);
612 if (key
->type
!= YAML_SCALAR_NODE
)
613 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
614 return pet_expr_free(expr
));
616 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
617 type
= extract_expr_type(ctx
, document
, value
);
620 if (type
== pet_expr_error
)
621 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
624 expr
= pet_expr_alloc(ctx
, type
);
628 for (pair
= node
->data
.mapping
.pairs
.start
;
629 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
630 yaml_node_t
*key
, *value
;
632 key
= yaml_document_get_node(document
, pair
->key
);
633 value
= yaml_document_get_node(document
, pair
->value
);
635 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
636 expr
= extract_arguments(ctx
, document
, value
, expr
);
643 isl_die(ctx
, isl_error_internal
, "unreachable code",
645 case pet_expr_access
:
646 expr
= extract_expr_access(ctx
, document
, node
, expr
);
648 case pet_expr_double
:
649 expr
= extract_expr_double(ctx
, document
, node
, expr
);
652 expr
= extract_expr_call(ctx
, document
, node
, expr
);
655 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
658 expr
= extract_expr_int(ctx
, document
, node
, expr
);
661 expr
= extract_expr_op(ctx
, document
, node
, expr
);
668 /* Extract a pet_tree_type from "node".
670 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
671 yaml_document_t
*document
, yaml_node_t
*node
)
673 if (node
->type
!= YAML_SCALAR_NODE
)
674 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
677 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
680 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
681 yaml_document_t
*document
, yaml_node_t
*node
);
683 /* Extract a pet_tree of type pet_tree_block from "node".
685 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
686 yaml_document_t
*document
, yaml_node_t
*node
)
690 yaml_node_pair_t
*pair
;
691 yaml_node_item_t
*item
;
692 yaml_node_t
*children
= NULL
;
695 for (pair
= node
->data
.mapping
.pairs
.start
;
696 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
697 yaml_node_t
*key
, *value
;
699 key
= yaml_document_get_node(document
, pair
->key
);
700 value
= yaml_document_get_node(document
, pair
->value
);
702 if (key
->type
!= YAML_SCALAR_NODE
)
703 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
706 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
707 block
= extract_int(ctx
, document
, value
);
708 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
715 n
= children
->data
.sequence
.items
.top
-
716 children
->data
.sequence
.items
.start
;
718 tree
= pet_tree_new_block(ctx
, block
, n
);
722 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
723 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
727 n
= yaml_document_get_node(document
, *item
);
728 child
= extract_tree(ctx
, document
, n
);
729 tree
= pet_tree_block_add_child(tree
, child
);
735 /* Extract a pet_tree of type pet_tree_decl from "node".
737 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
738 yaml_document_t
*document
, yaml_node_t
*node
)
740 yaml_node_pair_t
*pair
;
741 pet_expr
*var
= NULL
;
743 for (pair
= node
->data
.mapping
.pairs
.start
;
744 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
745 yaml_node_t
*key
, *value
;
747 key
= yaml_document_get_node(document
, pair
->key
);
748 value
= yaml_document_get_node(document
, pair
->value
);
750 if (key
->type
!= YAML_SCALAR_NODE
)
751 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
754 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
755 var
= extract_expr(ctx
, document
, value
);
762 isl_die(ctx
, isl_error_invalid
,
763 "no variable field", return NULL
);
765 return pet_tree_new_decl(var
);
768 /* Extract a pet_tree of type pet_tree_decl_init from "node".
770 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
771 yaml_document_t
*document
, yaml_node_t
*node
)
773 yaml_node_pair_t
*pair
;
774 pet_expr
*var
= NULL
;
775 pet_expr
*init
= NULL
;
777 for (pair
= node
->data
.mapping
.pairs
.start
;
778 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
779 yaml_node_t
*key
, *value
;
781 key
= yaml_document_get_node(document
, pair
->key
);
782 value
= yaml_document_get_node(document
, pair
->value
);
784 if (key
->type
!= YAML_SCALAR_NODE
)
785 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
788 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
789 var
= extract_expr(ctx
, document
, value
);
793 if (!strcmp((char *) key
->data
.scalar
.value
,
795 init
= extract_expr(ctx
, document
, value
);
802 isl_die(ctx
, isl_error_invalid
,
803 "no variable field", goto error
);
805 isl_die(ctx
, isl_error_invalid
,
806 "no initialization field", goto error
);
808 return pet_tree_new_decl_init(var
, init
);
815 /* Extract a pet_tree of type pet_tree_expr from "node".
817 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
818 yaml_document_t
*document
, yaml_node_t
*node
)
820 yaml_node_pair_t
*pair
;
821 pet_expr
*expr
= NULL
;
823 for (pair
= node
->data
.mapping
.pairs
.start
;
824 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
825 yaml_node_t
*key
, *value
;
827 key
= yaml_document_get_node(document
, pair
->key
);
828 value
= yaml_document_get_node(document
, pair
->value
);
830 if (key
->type
!= YAML_SCALAR_NODE
)
831 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
834 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
835 expr
= extract_expr(ctx
, document
, value
);
842 isl_die(ctx
, isl_error_invalid
,
843 "no expr field", return NULL
);
845 return pet_tree_new_expr(expr
);
848 /* Extract a pet_tree of type pet_tree_while from "node".
850 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
851 yaml_document_t
*document
, yaml_node_t
*node
)
853 yaml_node_pair_t
*pair
;
854 pet_expr
*cond
= NULL
;
855 pet_tree
*body
= NULL
;
857 for (pair
= node
->data
.mapping
.pairs
.start
;
858 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
859 yaml_node_t
*key
, *value
;
861 key
= yaml_document_get_node(document
, pair
->key
);
862 value
= yaml_document_get_node(document
, pair
->value
);
864 if (key
->type
!= YAML_SCALAR_NODE
)
865 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
868 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
869 cond
= extract_expr(ctx
, document
, value
);
873 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
874 body
= extract_tree(ctx
, document
, value
);
881 isl_die(ctx
, isl_error_invalid
,
882 "no condition field", goto error
);
884 isl_die(ctx
, isl_error_invalid
,
885 "no body field", goto error
);
887 return pet_tree_new_while(cond
, body
);
894 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
896 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
897 yaml_document_t
*document
, yaml_node_t
*node
)
899 yaml_node_pair_t
*pair
;
902 for (pair
= node
->data
.mapping
.pairs
.start
;
903 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
904 yaml_node_t
*key
, *value
;
906 key
= yaml_document_get_node(document
, pair
->key
);
907 value
= yaml_document_get_node(document
, pair
->value
);
909 if (key
->type
!= YAML_SCALAR_NODE
)
910 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
913 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
914 body
= extract_tree(ctx
, document
, value
);
921 isl_die(ctx
, isl_error_invalid
,
922 "no body field", return NULL
);
924 return pet_tree_new_infinite_loop(body
);
927 /* Extract a pet_tree of type pet_tree_if from "node".
929 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
930 yaml_document_t
*document
, yaml_node_t
*node
)
932 yaml_node_pair_t
*pair
;
933 pet_expr
*cond
= NULL
;
934 pet_tree
*then_body
= NULL
;
936 for (pair
= node
->data
.mapping
.pairs
.start
;
937 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
938 yaml_node_t
*key
, *value
;
940 key
= yaml_document_get_node(document
, pair
->key
);
941 value
= yaml_document_get_node(document
, pair
->value
);
943 if (key
->type
!= YAML_SCALAR_NODE
)
944 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
947 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
948 cond
= extract_expr(ctx
, document
, value
);
952 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
953 then_body
= extract_tree(ctx
, document
, value
);
960 isl_die(ctx
, isl_error_invalid
,
961 "no condition field", goto error
);
963 isl_die(ctx
, isl_error_invalid
,
964 "no then body", goto error
);
966 return pet_tree_new_if(cond
, then_body
);
969 pet_tree_free(then_body
);
973 /* Extract a pet_tree of type pet_tree_if_else from "node".
975 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
976 yaml_document_t
*document
, yaml_node_t
*node
)
978 yaml_node_pair_t
*pair
;
979 pet_expr
*cond
= NULL
;
980 pet_tree
*then_body
= NULL
;
981 pet_tree
*else_body
= NULL
;
983 for (pair
= node
->data
.mapping
.pairs
.start
;
984 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
985 yaml_node_t
*key
, *value
;
987 key
= yaml_document_get_node(document
, pair
->key
);
988 value
= yaml_document_get_node(document
, pair
->value
);
990 if (key
->type
!= YAML_SCALAR_NODE
)
991 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
994 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
995 cond
= extract_expr(ctx
, document
, value
);
999 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
1000 then_body
= extract_tree(ctx
, document
, value
);
1004 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
1005 else_body
= extract_tree(ctx
, document
, value
);
1012 isl_die(ctx
, isl_error_invalid
,
1013 "no condition field", goto error
);
1015 isl_die(ctx
, isl_error_invalid
,
1016 "no then body", goto error
);
1018 isl_die(ctx
, isl_error_invalid
,
1019 "no else body", goto error
);
1021 return pet_tree_new_if_else(cond
, then_body
, else_body
);
1023 pet_expr_free(cond
);
1024 pet_tree_free(then_body
);
1025 pet_tree_free(else_body
);
1029 /* Extract a pet_tree of type pet_tree_for from "node".
1031 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1032 yaml_document_t
*document
, yaml_node_t
*node
)
1034 yaml_node_pair_t
*pair
;
1036 int independent
= 0;
1037 pet_expr
*iv
= NULL
;
1038 pet_expr
*init
= NULL
;
1039 pet_expr
*cond
= NULL
;
1040 pet_expr
*inc
= NULL
;
1041 pet_tree
*body
= NULL
;
1043 for (pair
= node
->data
.mapping
.pairs
.start
;
1044 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1045 yaml_node_t
*key
, *value
;
1047 key
= yaml_document_get_node(document
, pair
->key
);
1048 value
= yaml_document_get_node(document
, pair
->value
);
1050 if (key
->type
!= YAML_SCALAR_NODE
)
1051 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1054 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1055 declared
= extract_int(ctx
, document
, value
);
1056 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1057 independent
= extract_int(ctx
, document
, value
);
1058 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1059 iv
= extract_expr(ctx
, document
, value
);
1063 if (!strcmp((char *) key
->data
.scalar
.value
,
1064 "initialization")) {
1065 init
= extract_expr(ctx
, document
, value
);
1069 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1070 cond
= extract_expr(ctx
, document
, value
);
1074 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1075 inc
= extract_expr(ctx
, document
, value
);
1079 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1080 body
= extract_tree(ctx
, document
, value
);
1087 isl_die(ctx
, isl_error_invalid
,
1088 "no variable field", goto error
);
1090 isl_die(ctx
, isl_error_invalid
,
1091 "no initialization field", goto error
);
1093 isl_die(ctx
, isl_error_invalid
,
1094 "no condition field", goto error
);
1096 isl_die(ctx
, isl_error_invalid
,
1097 "no increment field", goto error
);
1099 isl_die(ctx
, isl_error_invalid
,
1100 "no body field", goto error
);
1102 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1106 pet_expr_free(init
);
1107 pet_expr_free(cond
);
1109 pet_tree_free(body
);
1113 /* Extract a pet_tree from "node".
1115 * We first extract the type of the pet_tree and then call
1116 * the appropriate function to extract and construct a pet_tree
1119 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1120 yaml_document_t
*document
, yaml_node_t
*node
)
1122 enum pet_tree_type type
= pet_tree_error
;
1124 yaml_node_pair_t
*pair
;
1126 if (node
->type
!= YAML_MAPPING_NODE
)
1127 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1130 for (pair
= node
->data
.mapping
.pairs
.start
;
1131 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1132 yaml_node_t
*key
, *value
;
1134 key
= yaml_document_get_node(document
, pair
->key
);
1135 value
= yaml_document_get_node(document
, pair
->value
);
1137 if (key
->type
!= YAML_SCALAR_NODE
)
1138 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1139 return pet_tree_free(tree
));
1141 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1142 type
= extract_tree_type(ctx
, document
, value
);
1145 if (type
== pet_tree_error
)
1146 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1150 case pet_tree_error
:
1152 case pet_tree_block
:
1153 tree
= extract_tree_block(ctx
, document
, node
);
1155 case pet_tree_break
:
1156 tree
= pet_tree_new_break(ctx
);
1158 case pet_tree_continue
:
1159 tree
= pet_tree_new_continue(ctx
);
1162 tree
= extract_tree_decl(ctx
, document
, node
);
1164 case pet_tree_decl_init
:
1165 tree
= extract_tree_decl_init(ctx
, document
, node
);
1168 tree
= extract_tree_expr(ctx
, document
, node
);
1171 tree
= extract_tree_for(ctx
, document
, node
);
1173 case pet_tree_while
:
1174 tree
= extract_tree_while(ctx
, document
, node
);
1176 case pet_tree_infinite_loop
:
1177 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1180 tree
= extract_tree_if(ctx
, document
, node
);
1182 case pet_tree_if_else
:
1183 tree
= extract_tree_if_else(ctx
, document
, node
);
1190 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1191 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1194 yaml_node_item_t
*item
;
1196 if (node
->type
!= YAML_SEQUENCE_NODE
)
1197 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1198 return pet_stmt_free(stmt
));
1200 stmt
->n_arg
= node
->data
.sequence
.items
.top
1201 - node
->data
.sequence
.items
.start
;
1202 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1204 return pet_stmt_free(stmt
);
1206 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1207 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1210 n
= yaml_document_get_node(document
, *item
);
1211 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1213 return pet_stmt_free(stmt
);
1219 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1222 struct pet_stmt
*stmt
;
1223 yaml_node_pair_t
* pair
;
1225 unsigned start
= 0, end
= 0;
1226 char *indent
= NULL
;
1228 if (node
->type
!= YAML_MAPPING_NODE
)
1229 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1232 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1236 stmt
->loc
= &pet_loc_dummy
;
1238 for (pair
= node
->data
.mapping
.pairs
.start
;
1239 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1240 yaml_node_t
*key
, *value
;
1242 key
= yaml_document_get_node(document
, pair
->key
);
1243 value
= yaml_document_get_node(document
, pair
->value
);
1245 if (key
->type
!= YAML_SCALAR_NODE
)
1246 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1247 return pet_stmt_free(stmt
));
1249 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1250 indent
= extract_string(ctx
, document
, value
);
1251 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1252 line
= extract_int(ctx
, document
, value
);
1253 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1254 start
= extract_int(ctx
, document
, value
);
1255 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1256 end
= extract_int(ctx
, document
, value
);
1257 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1258 stmt
->domain
= extract_set(ctx
, document
, value
);
1259 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1260 stmt
->body
= extract_tree(ctx
, document
, value
);
1262 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1263 stmt
= extract_stmt_arguments(ctx
, document
,
1270 indent
= strdup("");
1271 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1273 return pet_stmt_free(stmt
);
1278 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1279 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1282 yaml_node_item_t
*item
;
1284 if (node
->type
!= YAML_SEQUENCE_NODE
)
1285 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1288 scop
->n_stmt
= node
->data
.sequence
.items
.top
1289 - node
->data
.sequence
.items
.start
;
1290 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1292 return pet_scop_free(scop
);
1294 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1295 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1298 n
= yaml_document_get_node(document
, *item
);
1299 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1300 if (!scop
->stmts
[i
])
1301 return pet_scop_free(scop
);
1307 /* Extract a pet_implication from "node".
1309 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1310 yaml_document_t
*document
, yaml_node_t
*node
)
1312 struct pet_implication
*implication
;
1313 yaml_node_pair_t
* pair
;
1315 if (node
->type
!= YAML_MAPPING_NODE
)
1316 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1319 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1323 for (pair
= node
->data
.mapping
.pairs
.start
;
1324 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1325 yaml_node_t
*key
, *value
;
1327 key
= yaml_document_get_node(document
, pair
->key
);
1328 value
= yaml_document_get_node(document
, pair
->value
);
1330 if (key
->type
!= YAML_SCALAR_NODE
)
1331 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1332 return pet_implication_free(implication
));
1334 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1335 implication
->satisfied
=
1336 extract_int(ctx
, document
, value
);
1337 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1338 implication
->extension
=
1339 extract_map(ctx
, document
, value
);
1345 /* Extract a sequence of implications from "node" and
1346 * store them in scop->implications.
1348 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1349 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1352 yaml_node_item_t
*item
;
1354 if (node
->type
!= YAML_SEQUENCE_NODE
)
1355 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1358 scop
->n_implication
= node
->data
.sequence
.items
.top
1359 - node
->data
.sequence
.items
.start
;
1360 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1361 scop
->n_implication
);
1362 if (!scop
->implications
)
1363 return pet_scop_free(scop
);
1365 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1366 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1369 n
= yaml_document_get_node(document
, *item
);
1370 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1371 if (!scop
->implications
[i
])
1372 return pet_scop_free(scop
);
1378 /* Extract a pet_independence from "node".
1380 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1381 yaml_document_t
*document
, yaml_node_t
*node
)
1383 struct pet_independence
*independence
;
1384 yaml_node_pair_t
* pair
;
1386 if (node
->type
!= YAML_MAPPING_NODE
)
1387 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1390 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1394 for (pair
= node
->data
.mapping
.pairs
.start
;
1395 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1396 yaml_node_t
*key
, *value
;
1398 key
= yaml_document_get_node(document
, pair
->key
);
1399 value
= yaml_document_get_node(document
, pair
->value
);
1401 if (key
->type
!= YAML_SCALAR_NODE
)
1402 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1403 return pet_independence_free(independence
));
1405 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1406 independence
->filter
=
1407 extract_union_map(ctx
, document
, value
);
1408 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1409 independence
->local
=
1410 extract_union_set(ctx
, document
, value
);
1413 if (!independence
->filter
)
1414 isl_die(ctx
, isl_error_invalid
, "no filter field",
1415 return pet_independence_free(independence
));
1416 if (!independence
->local
)
1417 isl_die(ctx
, isl_error_invalid
, "no local field",
1418 return pet_independence_free(independence
));
1420 return independence
;
1423 /* Extract a sequence of independences from "node" and
1424 * store them in scop->independences.
1426 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1427 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1430 yaml_node_item_t
*item
;
1432 if (node
->type
!= YAML_SEQUENCE_NODE
)
1433 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1436 scop
->n_independence
= node
->data
.sequence
.items
.top
1437 - node
->data
.sequence
.items
.start
;
1438 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1439 scop
->n_independence
);
1440 if (!scop
->independences
)
1441 return pet_scop_free(scop
);
1443 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1444 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1447 n
= yaml_document_get_node(document
, *item
);
1448 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1449 if (!scop
->independences
[i
])
1450 return pet_scop_free(scop
);
1456 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1459 struct pet_scop
*scop
;
1460 yaml_node_pair_t
* pair
;
1465 if (node
->type
!= YAML_MAPPING_NODE
)
1466 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1469 scop
= pet_scop_alloc(ctx
);
1473 for (pair
= node
->data
.mapping
.pairs
.start
;
1474 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1475 yaml_node_t
*key
, *value
;
1477 key
= yaml_document_get_node(document
, pair
->key
);
1478 value
= yaml_document_get_node(document
, pair
->value
);
1480 if (key
->type
!= YAML_SCALAR_NODE
)
1481 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1482 return pet_scop_free(scop
));
1483 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1484 scop
->context
= extract_set(ctx
, document
, value
);
1485 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1486 scop
->context_value
= extract_set(ctx
, document
, value
);
1487 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1488 scop
->schedule
= extract_schedule(ctx
, document
, value
);
1489 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1490 scop
= extract_types(ctx
, document
, value
, scop
);
1491 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1492 scop
= extract_arrays(ctx
, document
, value
, scop
);
1493 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1494 scop
= extract_statements(ctx
, document
, value
, scop
);
1495 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1496 scop
= extract_implications(ctx
, document
, value
, scop
);
1497 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1498 scop
= extract_independences(ctx
,
1499 document
, value
, scop
);
1504 if (!scop
->context_value
) {
1505 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1506 scop
->context_value
= isl_set_universe(space
);
1507 if (!scop
->context_value
)
1508 return pet_scop_free(scop
);
1514 /* Extract a pet_scop from the YAML description in "in".
1516 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1518 struct pet_scop
*scop
= NULL
;
1519 yaml_parser_t parser
;
1521 yaml_document_t document
= { 0 };
1523 yaml_parser_initialize(&parser
);
1525 yaml_parser_set_input_file(&parser
, in
);
1527 if (!yaml_parser_load(&parser
, &document
))
1530 root
= yaml_document_get_root_node(&document
);
1532 scop
= extract_scop(ctx
, &document
, root
);
1534 yaml_document_delete(&document
);
1536 yaml_parser_delete(&parser
);
1540 yaml_parser_delete(&parser
);
1541 pet_scop_free(scop
);