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 relations (if any)
394 * need 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
, "may_read"))
436 expr
= pet_expr_access_set_access(expr
,
437 pet_expr_access_may_read
,
438 extract_union_map(ctx
, document
, value
));
439 if (!strcmp((char *) key
->data
.scalar
.value
, "may_write"))
440 expr
= pet_expr_access_set_access(expr
,
441 pet_expr_access_may_write
,
442 extract_union_map(ctx
, document
, value
));
443 if (!strcmp((char *) key
->data
.scalar
.value
, "must_write"))
444 expr
= pet_expr_access_set_access(expr
,
445 pet_expr_access_must_write
,
446 extract_union_map(ctx
, document
, value
));
447 if (!strcmp((char *) key
->data
.scalar
.value
, "killed"))
448 expr
= pet_expr_access_set_access(expr
,
449 pet_expr_access_killed
,
450 extract_union_map(ctx
, document
, value
));
451 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
452 expr
= pet_expr_access_set_ref_id(expr
,
453 extract_id(ctx
, document
, value
));
454 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
455 expr
= pet_expr_access_set_read(expr
,
456 extract_int(ctx
, document
, value
));
457 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
458 expr
= pet_expr_access_set_write(expr
,
459 extract_int(ctx
, document
, value
));
460 if (!strcmp((char *) key
->data
.scalar
.value
, "kill"))
461 expr
= pet_expr_access_set_kill(expr
,
462 extract_int(ctx
, document
, value
));
468 /* Extract operation expression specific fields from "node" and
469 * update "expr" accordingly.
471 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
472 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
474 yaml_node_pair_t
*pair
;
476 for (pair
= node
->data
.mapping
.pairs
.start
;
477 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
478 yaml_node_t
*key
, *value
;
480 key
= yaml_document_get_node(document
, pair
->key
);
481 value
= yaml_document_get_node(document
, pair
->value
);
483 if (key
->type
!= YAML_SCALAR_NODE
)
484 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
485 return pet_expr_free(expr
));
487 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
488 expr
= pet_expr_op_set_type(expr
,
489 extract_op(ctx
, document
, value
));
495 /* Extract pet_expr_call specific fields from "node" and
496 * update "expr" accordingly.
498 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
499 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
501 yaml_node_pair_t
*pair
;
503 for (pair
= node
->data
.mapping
.pairs
.start
;
504 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
505 yaml_node_t
*key
, *value
;
507 key
= yaml_document_get_node(document
, pair
->key
);
508 value
= yaml_document_get_node(document
, pair
->value
);
510 if (key
->type
!= YAML_SCALAR_NODE
)
511 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
512 return pet_expr_free(expr
));
514 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
515 expr
= pet_expr_call_set_name(expr
,
516 extract_string(ctx
, document
, value
));
522 /* Extract pet_expr_cast specific fields from "node" and
523 * update "expr" accordingly.
525 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
526 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
528 yaml_node_pair_t
*pair
;
530 for (pair
= node
->data
.mapping
.pairs
.start
;
531 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
532 yaml_node_t
*key
, *value
;
534 key
= yaml_document_get_node(document
, pair
->key
);
535 value
= yaml_document_get_node(document
, pair
->value
);
537 if (key
->type
!= YAML_SCALAR_NODE
)
538 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
539 return pet_expr_free(expr
));
541 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
542 expr
= pet_expr_cast_set_type_name(expr
,
543 extract_string(ctx
, document
, value
));
549 /* Extract pet_expr_int specific fields from "node" and
550 * update "expr" accordingly.
552 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
553 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
555 yaml_node_pair_t
* pair
;
557 for (pair
= node
->data
.mapping
.pairs
.start
;
558 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
559 yaml_node_t
*key
, *value
;
561 key
= yaml_document_get_node(document
, pair
->key
);
562 value
= yaml_document_get_node(document
, pair
->value
);
564 if (key
->type
!= YAML_SCALAR_NODE
)
565 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
566 return pet_expr_free(expr
));
568 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
569 expr
= pet_expr_int_set_val(expr
,
570 extract_val(ctx
, document
, value
));
576 /* Extract a pet_expr from "node".
578 * We first extract the type and arguments of the expression and
579 * then extract additional fields depending on the type.
581 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
582 yaml_document_t
*document
, yaml_node_t
*node
)
584 enum pet_expr_type type
= pet_expr_error
;
586 yaml_node_pair_t
*pair
;
588 if (node
->type
!= YAML_MAPPING_NODE
)
589 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
592 for (pair
= node
->data
.mapping
.pairs
.start
;
593 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
594 yaml_node_t
*key
, *value
;
596 key
= yaml_document_get_node(document
, pair
->key
);
597 value
= yaml_document_get_node(document
, pair
->value
);
599 if (key
->type
!= YAML_SCALAR_NODE
)
600 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
601 return pet_expr_free(expr
));
603 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
604 type
= extract_expr_type(ctx
, document
, value
);
607 if (type
== pet_expr_error
)
608 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
611 expr
= pet_expr_alloc(ctx
, type
);
615 for (pair
= node
->data
.mapping
.pairs
.start
;
616 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
617 yaml_node_t
*key
, *value
;
619 key
= yaml_document_get_node(document
, pair
->key
);
620 value
= yaml_document_get_node(document
, pair
->value
);
622 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
623 expr
= extract_arguments(ctx
, document
, value
, expr
);
630 isl_die(ctx
, isl_error_internal
, "unreachable code",
632 case pet_expr_access
:
633 expr
= extract_expr_access(ctx
, document
, node
, expr
);
635 case pet_expr_double
:
636 expr
= extract_expr_double(ctx
, document
, node
, expr
);
639 expr
= extract_expr_call(ctx
, document
, node
, expr
);
642 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
645 expr
= extract_expr_int(ctx
, document
, node
, expr
);
648 expr
= extract_expr_op(ctx
, document
, node
, expr
);
655 /* Extract a pet_tree_type from "node".
657 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
658 yaml_document_t
*document
, yaml_node_t
*node
)
660 if (node
->type
!= YAML_SCALAR_NODE
)
661 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
664 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
667 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
668 yaml_document_t
*document
, yaml_node_t
*node
);
670 /* Extract a pet_tree of type pet_tree_block from "node".
672 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
673 yaml_document_t
*document
, yaml_node_t
*node
)
677 yaml_node_pair_t
*pair
;
678 yaml_node_item_t
*item
;
679 yaml_node_t
*children
= NULL
;
682 for (pair
= node
->data
.mapping
.pairs
.start
;
683 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
684 yaml_node_t
*key
, *value
;
686 key
= yaml_document_get_node(document
, pair
->key
);
687 value
= yaml_document_get_node(document
, pair
->value
);
689 if (key
->type
!= YAML_SCALAR_NODE
)
690 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
693 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
694 block
= extract_int(ctx
, document
, value
);
695 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
702 n
= children
->data
.sequence
.items
.top
-
703 children
->data
.sequence
.items
.start
;
705 tree
= pet_tree_new_block(ctx
, block
, n
);
709 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
710 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
714 n
= yaml_document_get_node(document
, *item
);
715 child
= extract_tree(ctx
, document
, n
);
716 tree
= pet_tree_block_add_child(tree
, child
);
722 /* Extract a pet_tree of type pet_tree_decl from "node".
724 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
725 yaml_document_t
*document
, yaml_node_t
*node
)
727 yaml_node_pair_t
*pair
;
728 pet_expr
*var
= NULL
;
730 for (pair
= node
->data
.mapping
.pairs
.start
;
731 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
732 yaml_node_t
*key
, *value
;
734 key
= yaml_document_get_node(document
, pair
->key
);
735 value
= yaml_document_get_node(document
, pair
->value
);
737 if (key
->type
!= YAML_SCALAR_NODE
)
738 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
741 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
742 var
= extract_expr(ctx
, document
, value
);
749 isl_die(ctx
, isl_error_invalid
,
750 "no variable field", return NULL
);
752 return pet_tree_new_decl(var
);
755 /* Extract a pet_tree of type pet_tree_decl_init from "node".
757 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
758 yaml_document_t
*document
, yaml_node_t
*node
)
760 yaml_node_pair_t
*pair
;
761 pet_expr
*var
= NULL
;
762 pet_expr
*init
= NULL
;
764 for (pair
= node
->data
.mapping
.pairs
.start
;
765 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
766 yaml_node_t
*key
, *value
;
768 key
= yaml_document_get_node(document
, pair
->key
);
769 value
= yaml_document_get_node(document
, pair
->value
);
771 if (key
->type
!= YAML_SCALAR_NODE
)
772 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
775 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
776 var
= extract_expr(ctx
, document
, value
);
780 if (!strcmp((char *) key
->data
.scalar
.value
,
782 init
= extract_expr(ctx
, document
, value
);
789 isl_die(ctx
, isl_error_invalid
,
790 "no variable field", goto error
);
792 isl_die(ctx
, isl_error_invalid
,
793 "no initialization field", goto error
);
795 return pet_tree_new_decl_init(var
, init
);
802 /* Extract a pet_tree of type pet_tree_expr from "node".
804 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
805 yaml_document_t
*document
, yaml_node_t
*node
)
807 yaml_node_pair_t
*pair
;
808 pet_expr
*expr
= NULL
;
810 for (pair
= node
->data
.mapping
.pairs
.start
;
811 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
812 yaml_node_t
*key
, *value
;
814 key
= yaml_document_get_node(document
, pair
->key
);
815 value
= yaml_document_get_node(document
, pair
->value
);
817 if (key
->type
!= YAML_SCALAR_NODE
)
818 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
821 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
822 expr
= extract_expr(ctx
, document
, value
);
829 isl_die(ctx
, isl_error_invalid
,
830 "no expr field", return NULL
);
832 return pet_tree_new_expr(expr
);
835 /* Extract a pet_tree of type pet_tree_while from "node".
837 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
838 yaml_document_t
*document
, yaml_node_t
*node
)
840 yaml_node_pair_t
*pair
;
841 pet_expr
*cond
= NULL
;
842 pet_tree
*body
= NULL
;
844 for (pair
= node
->data
.mapping
.pairs
.start
;
845 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
846 yaml_node_t
*key
, *value
;
848 key
= yaml_document_get_node(document
, pair
->key
);
849 value
= yaml_document_get_node(document
, pair
->value
);
851 if (key
->type
!= YAML_SCALAR_NODE
)
852 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
855 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
856 cond
= extract_expr(ctx
, document
, value
);
860 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
861 body
= extract_tree(ctx
, document
, value
);
868 isl_die(ctx
, isl_error_invalid
,
869 "no condition field", goto error
);
871 isl_die(ctx
, isl_error_invalid
,
872 "no body field", goto error
);
874 return pet_tree_new_while(cond
, body
);
881 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
883 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
884 yaml_document_t
*document
, yaml_node_t
*node
)
886 yaml_node_pair_t
*pair
;
889 for (pair
= node
->data
.mapping
.pairs
.start
;
890 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
891 yaml_node_t
*key
, *value
;
893 key
= yaml_document_get_node(document
, pair
->key
);
894 value
= yaml_document_get_node(document
, pair
->value
);
896 if (key
->type
!= YAML_SCALAR_NODE
)
897 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
900 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
901 body
= extract_tree(ctx
, document
, value
);
908 isl_die(ctx
, isl_error_invalid
,
909 "no body field", return NULL
);
911 return pet_tree_new_infinite_loop(body
);
914 /* Extract a pet_tree of type pet_tree_if from "node".
916 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
917 yaml_document_t
*document
, yaml_node_t
*node
)
919 yaml_node_pair_t
*pair
;
920 pet_expr
*cond
= NULL
;
921 pet_tree
*then_body
= NULL
;
923 for (pair
= node
->data
.mapping
.pairs
.start
;
924 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
925 yaml_node_t
*key
, *value
;
927 key
= yaml_document_get_node(document
, pair
->key
);
928 value
= yaml_document_get_node(document
, pair
->value
);
930 if (key
->type
!= YAML_SCALAR_NODE
)
931 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
934 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
935 cond
= extract_expr(ctx
, document
, value
);
939 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
940 then_body
= extract_tree(ctx
, document
, value
);
947 isl_die(ctx
, isl_error_invalid
,
948 "no condition field", goto error
);
950 isl_die(ctx
, isl_error_invalid
,
951 "no then body", goto error
);
953 return pet_tree_new_if(cond
, then_body
);
956 pet_tree_free(then_body
);
960 /* Extract a pet_tree of type pet_tree_if_else from "node".
962 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
963 yaml_document_t
*document
, yaml_node_t
*node
)
965 yaml_node_pair_t
*pair
;
966 pet_expr
*cond
= NULL
;
967 pet_tree
*then_body
= NULL
;
968 pet_tree
*else_body
= NULL
;
970 for (pair
= node
->data
.mapping
.pairs
.start
;
971 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
972 yaml_node_t
*key
, *value
;
974 key
= yaml_document_get_node(document
, pair
->key
);
975 value
= yaml_document_get_node(document
, pair
->value
);
977 if (key
->type
!= YAML_SCALAR_NODE
)
978 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
981 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
982 cond
= extract_expr(ctx
, document
, value
);
986 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
987 then_body
= extract_tree(ctx
, document
, value
);
991 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
992 else_body
= extract_tree(ctx
, document
, value
);
999 isl_die(ctx
, isl_error_invalid
,
1000 "no condition field", goto error
);
1002 isl_die(ctx
, isl_error_invalid
,
1003 "no then body", goto error
);
1005 isl_die(ctx
, isl_error_invalid
,
1006 "no else body", goto error
);
1008 return pet_tree_new_if_else(cond
, then_body
, else_body
);
1010 pet_expr_free(cond
);
1011 pet_tree_free(then_body
);
1012 pet_tree_free(else_body
);
1016 /* Extract a pet_tree of type pet_tree_for from "node".
1018 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1019 yaml_document_t
*document
, yaml_node_t
*node
)
1021 yaml_node_pair_t
*pair
;
1023 int independent
= 0;
1024 pet_expr
*iv
= NULL
;
1025 pet_expr
*init
= NULL
;
1026 pet_expr
*cond
= NULL
;
1027 pet_expr
*inc
= NULL
;
1028 pet_tree
*body
= NULL
;
1030 for (pair
= node
->data
.mapping
.pairs
.start
;
1031 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1032 yaml_node_t
*key
, *value
;
1034 key
= yaml_document_get_node(document
, pair
->key
);
1035 value
= yaml_document_get_node(document
, pair
->value
);
1037 if (key
->type
!= YAML_SCALAR_NODE
)
1038 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1041 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1042 declared
= extract_int(ctx
, document
, value
);
1043 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1044 independent
= extract_int(ctx
, document
, value
);
1045 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1046 iv
= extract_expr(ctx
, document
, value
);
1050 if (!strcmp((char *) key
->data
.scalar
.value
,
1051 "initialization")) {
1052 init
= extract_expr(ctx
, document
, value
);
1056 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1057 cond
= extract_expr(ctx
, document
, value
);
1061 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1062 inc
= extract_expr(ctx
, document
, value
);
1066 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1067 body
= extract_tree(ctx
, document
, value
);
1074 isl_die(ctx
, isl_error_invalid
,
1075 "no variable field", goto error
);
1077 isl_die(ctx
, isl_error_invalid
,
1078 "no initialization field", goto error
);
1080 isl_die(ctx
, isl_error_invalid
,
1081 "no condition field", goto error
);
1083 isl_die(ctx
, isl_error_invalid
,
1084 "no increment field", goto error
);
1086 isl_die(ctx
, isl_error_invalid
,
1087 "no body field", goto error
);
1089 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1093 pet_expr_free(init
);
1094 pet_expr_free(cond
);
1096 pet_tree_free(body
);
1100 /* Extract a pet_tree from "node".
1102 * We first extract the type of the pet_tree and then call
1103 * the appropriate function to extract and construct a pet_tree
1106 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1107 yaml_document_t
*document
, yaml_node_t
*node
)
1109 enum pet_tree_type type
= pet_tree_error
;
1111 yaml_node_pair_t
*pair
;
1113 if (node
->type
!= YAML_MAPPING_NODE
)
1114 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1117 for (pair
= node
->data
.mapping
.pairs
.start
;
1118 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1119 yaml_node_t
*key
, *value
;
1121 key
= yaml_document_get_node(document
, pair
->key
);
1122 value
= yaml_document_get_node(document
, pair
->value
);
1124 if (key
->type
!= YAML_SCALAR_NODE
)
1125 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1126 return pet_tree_free(tree
));
1128 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1129 type
= extract_tree_type(ctx
, document
, value
);
1132 if (type
== pet_tree_error
)
1133 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1137 case pet_tree_error
:
1139 case pet_tree_block
:
1140 tree
= extract_tree_block(ctx
, document
, node
);
1142 case pet_tree_break
:
1143 tree
= pet_tree_new_break(ctx
);
1145 case pet_tree_continue
:
1146 tree
= pet_tree_new_continue(ctx
);
1149 tree
= extract_tree_decl(ctx
, document
, node
);
1151 case pet_tree_decl_init
:
1152 tree
= extract_tree_decl_init(ctx
, document
, node
);
1155 tree
= extract_tree_expr(ctx
, document
, node
);
1158 tree
= extract_tree_for(ctx
, document
, node
);
1160 case pet_tree_while
:
1161 tree
= extract_tree_while(ctx
, document
, node
);
1163 case pet_tree_infinite_loop
:
1164 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1167 tree
= extract_tree_if(ctx
, document
, node
);
1169 case pet_tree_if_else
:
1170 tree
= extract_tree_if_else(ctx
, document
, node
);
1177 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1178 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1181 yaml_node_item_t
*item
;
1183 if (node
->type
!= YAML_SEQUENCE_NODE
)
1184 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1185 return pet_stmt_free(stmt
));
1187 stmt
->n_arg
= node
->data
.sequence
.items
.top
1188 - node
->data
.sequence
.items
.start
;
1189 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1191 return pet_stmt_free(stmt
);
1193 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1194 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1197 n
= yaml_document_get_node(document
, *item
);
1198 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1200 return pet_stmt_free(stmt
);
1206 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1209 struct pet_stmt
*stmt
;
1210 yaml_node_pair_t
* pair
;
1212 unsigned start
= 0, end
= 0;
1213 char *indent
= NULL
;
1215 if (node
->type
!= YAML_MAPPING_NODE
)
1216 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1219 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1223 stmt
->loc
= &pet_loc_dummy
;
1225 for (pair
= node
->data
.mapping
.pairs
.start
;
1226 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1227 yaml_node_t
*key
, *value
;
1229 key
= yaml_document_get_node(document
, pair
->key
);
1230 value
= yaml_document_get_node(document
, pair
->value
);
1232 if (key
->type
!= YAML_SCALAR_NODE
)
1233 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1234 return pet_stmt_free(stmt
));
1236 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1237 indent
= extract_string(ctx
, document
, value
);
1238 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1239 line
= extract_int(ctx
, document
, value
);
1240 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1241 start
= extract_int(ctx
, document
, value
);
1242 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1243 end
= extract_int(ctx
, document
, value
);
1244 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1245 stmt
->domain
= extract_set(ctx
, document
, value
);
1246 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1247 stmt
->schedule
= extract_map(ctx
, document
, value
);
1248 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1249 stmt
->body
= extract_tree(ctx
, document
, value
);
1251 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1252 stmt
= extract_stmt_arguments(ctx
, document
,
1259 indent
= strdup("");
1260 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1262 return pet_stmt_free(stmt
);
1267 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1268 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1271 yaml_node_item_t
*item
;
1273 if (node
->type
!= YAML_SEQUENCE_NODE
)
1274 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1277 scop
->n_stmt
= node
->data
.sequence
.items
.top
1278 - node
->data
.sequence
.items
.start
;
1279 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1281 return pet_scop_free(scop
);
1283 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1284 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1287 n
= yaml_document_get_node(document
, *item
);
1288 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1289 if (!scop
->stmts
[i
])
1290 return pet_scop_free(scop
);
1296 /* Extract a pet_implication from "node".
1298 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1299 yaml_document_t
*document
, yaml_node_t
*node
)
1301 struct pet_implication
*implication
;
1302 yaml_node_pair_t
* pair
;
1304 if (node
->type
!= YAML_MAPPING_NODE
)
1305 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1308 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1312 for (pair
= node
->data
.mapping
.pairs
.start
;
1313 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1314 yaml_node_t
*key
, *value
;
1316 key
= yaml_document_get_node(document
, pair
->key
);
1317 value
= yaml_document_get_node(document
, pair
->value
);
1319 if (key
->type
!= YAML_SCALAR_NODE
)
1320 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1321 return pet_implication_free(implication
));
1323 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1324 implication
->satisfied
=
1325 extract_int(ctx
, document
, value
);
1326 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1327 implication
->extension
=
1328 extract_map(ctx
, document
, value
);
1334 /* Extract a sequence of implications from "node" and
1335 * store them in scop->implications.
1337 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1338 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1341 yaml_node_item_t
*item
;
1343 if (node
->type
!= YAML_SEQUENCE_NODE
)
1344 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1347 scop
->n_implication
= node
->data
.sequence
.items
.top
1348 - node
->data
.sequence
.items
.start
;
1349 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1350 scop
->n_implication
);
1351 if (!scop
->implications
)
1352 return pet_scop_free(scop
);
1354 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1355 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1358 n
= yaml_document_get_node(document
, *item
);
1359 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1360 if (!scop
->implications
[i
])
1361 return pet_scop_free(scop
);
1367 /* Extract a pet_independence from "node".
1369 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1370 yaml_document_t
*document
, yaml_node_t
*node
)
1372 struct pet_independence
*independence
;
1373 yaml_node_pair_t
* pair
;
1375 if (node
->type
!= YAML_MAPPING_NODE
)
1376 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1379 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1383 for (pair
= node
->data
.mapping
.pairs
.start
;
1384 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1385 yaml_node_t
*key
, *value
;
1387 key
= yaml_document_get_node(document
, pair
->key
);
1388 value
= yaml_document_get_node(document
, pair
->value
);
1390 if (key
->type
!= YAML_SCALAR_NODE
)
1391 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1392 return pet_independence_free(independence
));
1394 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1395 independence
->filter
=
1396 extract_union_map(ctx
, document
, value
);
1397 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1398 independence
->local
=
1399 extract_union_set(ctx
, document
, value
);
1402 if (!independence
->filter
)
1403 isl_die(ctx
, isl_error_invalid
, "no filter field",
1404 return pet_independence_free(independence
));
1405 if (!independence
->local
)
1406 isl_die(ctx
, isl_error_invalid
, "no local field",
1407 return pet_independence_free(independence
));
1409 return independence
;
1412 /* Extract a sequence of independences from "node" and
1413 * store them in scop->independences.
1415 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1416 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1419 yaml_node_item_t
*item
;
1421 if (node
->type
!= YAML_SEQUENCE_NODE
)
1422 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1425 scop
->n_independence
= node
->data
.sequence
.items
.top
1426 - node
->data
.sequence
.items
.start
;
1427 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1428 scop
->n_independence
);
1429 if (!scop
->independences
)
1430 return pet_scop_free(scop
);
1432 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1433 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1436 n
= yaml_document_get_node(document
, *item
);
1437 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1438 if (!scop
->independences
[i
])
1439 return pet_scop_free(scop
);
1445 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1448 struct pet_scop
*scop
;
1449 yaml_node_pair_t
* pair
;
1454 if (node
->type
!= YAML_MAPPING_NODE
)
1455 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1458 scop
= pet_scop_alloc(ctx
);
1462 for (pair
= node
->data
.mapping
.pairs
.start
;
1463 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1464 yaml_node_t
*key
, *value
;
1466 key
= yaml_document_get_node(document
, pair
->key
);
1467 value
= yaml_document_get_node(document
, pair
->value
);
1469 if (key
->type
!= YAML_SCALAR_NODE
)
1470 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1471 return pet_scop_free(scop
));
1472 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1473 scop
->context
= extract_set(ctx
, document
, value
);
1474 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1475 scop
->context_value
= extract_set(ctx
, document
, value
);
1476 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1477 scop
= extract_types(ctx
, document
, value
, scop
);
1478 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1479 scop
= extract_arrays(ctx
, document
, value
, scop
);
1480 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1481 scop
= extract_statements(ctx
, document
, value
, scop
);
1482 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1483 scop
= extract_implications(ctx
, document
, value
, scop
);
1484 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1485 scop
= extract_independences(ctx
,
1486 document
, value
, scop
);
1491 if (!scop
->context_value
) {
1492 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1493 scop
->context_value
= isl_set_universe(space
);
1494 if (!scop
->context_value
)
1495 return pet_scop_free(scop
);
1501 /* Extract a pet_scop from the YAML description in "in".
1503 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1505 struct pet_scop
*scop
= NULL
;
1506 yaml_parser_t parser
;
1508 yaml_document_t document
= { 0 };
1510 yaml_parser_initialize(&parser
);
1512 yaml_parser_set_input_file(&parser
, in
);
1514 if (!yaml_parser_load(&parser
, &document
))
1517 root
= yaml_document_get_root_node(&document
);
1519 scop
= extract_scop(ctx
, &document
, root
);
1521 yaml_document_delete(&document
);
1523 yaml_parser_delete(&parser
);
1527 yaml_parser_delete(&parser
);
1528 pet_scop_free(scop
);