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
38 #include <isl/union_set.h>
43 #include "scop_yaml.h"
46 static char *extract_string(isl_ctx
*ctx
, yaml_document_t
*document
,
49 if (node
->type
!= YAML_SCALAR_NODE
)
50 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
53 return strdup((char *) node
->data
.scalar
.value
);
56 static int extract_int(isl_ctx
*ctx
, yaml_document_t
*document
,
59 if (node
->type
!= YAML_SCALAR_NODE
)
60 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
63 return atoi((char *) node
->data
.scalar
.value
);
66 static double extract_double(isl_ctx
*ctx
, yaml_document_t
*document
,
69 if (node
->type
!= YAML_SCALAR_NODE
)
70 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
73 return strtod((char *) node
->data
.scalar
.value
, NULL
);
76 static enum pet_expr_type
extract_expr_type(isl_ctx
*ctx
,
77 yaml_document_t
*document
, yaml_node_t
*node
)
79 if (node
->type
!= YAML_SCALAR_NODE
)
80 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
83 return pet_str_type((char *) node
->data
.scalar
.value
);
86 static enum pet_op_type
extract_op(isl_ctx
*ctx
, yaml_document_t
*document
,
89 if (node
->type
!= YAML_SCALAR_NODE
)
90 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
93 return pet_str_op((char *) node
->data
.scalar
.value
);
96 static __isl_give isl_set
*extract_set(isl_ctx
*ctx
, yaml_document_t
*document
,
99 if (node
->type
!= YAML_SCALAR_NODE
)
100 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
103 return isl_set_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
106 static __isl_give isl_id
*extract_id(isl_ctx
*ctx
, yaml_document_t
*document
,
109 if (node
->type
!= YAML_SCALAR_NODE
)
110 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
113 return isl_id_alloc(ctx
, (char *) node
->data
.scalar
.value
, NULL
);
116 static __isl_give isl_map
*extract_map(isl_ctx
*ctx
, yaml_document_t
*document
,
119 if (node
->type
!= YAML_SCALAR_NODE
)
120 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
123 return isl_map_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
126 /* Extract an isl_union_set from "node".
128 static __isl_give isl_union_set
*extract_union_set(isl_ctx
*ctx
,
129 yaml_document_t
*document
, yaml_node_t
*node
)
131 if (node
->type
!= YAML_SCALAR_NODE
)
132 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
135 return isl_union_set_read_from_str(ctx
,
136 (char *) node
->data
.scalar
.value
);
139 /* Extract an isl_union_map from "node".
141 static __isl_give isl_union_map
*extract_union_map(isl_ctx
*ctx
,
142 yaml_document_t
*document
, yaml_node_t
*node
)
144 if (node
->type
!= YAML_SCALAR_NODE
)
145 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
148 return isl_union_map_read_from_str(ctx
,
149 (char *) node
->data
.scalar
.value
);
152 /* Extract an isl_val from "node".
154 static __isl_give isl_val
*extract_val(isl_ctx
*ctx
, yaml_document_t
*document
,
157 if (node
->type
!= YAML_SCALAR_NODE
)
158 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
161 return isl_val_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
164 /* Extract an isl_multi_pw_aff from "node".
166 static __isl_give isl_multi_pw_aff
*extract_multi_pw_aff(isl_ctx
*ctx
,
167 yaml_document_t
*document
, yaml_node_t
*node
)
169 if (node
->type
!= YAML_SCALAR_NODE
)
170 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
173 return isl_multi_pw_aff_read_from_str(ctx
,
174 (char *) node
->data
.scalar
.value
);
177 /* Extract an isl_schedule from "node".
179 static __isl_give isl_schedule
*extract_schedule(isl_ctx
*ctx
,
180 yaml_document_t
*document
, yaml_node_t
*node
)
182 if (node
->type
!= YAML_SCALAR_NODE
)
183 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
186 return isl_schedule_read_from_str(ctx
,
187 (char *) node
->data
.scalar
.value
);
190 /* Extract a pet_type from "node".
192 static struct pet_type
*extract_type(isl_ctx
*ctx
,
193 yaml_document_t
*document
, yaml_node_t
*node
)
195 struct pet_type
*type
;
196 yaml_node_pair_t
* pair
;
198 if (node
->type
!= YAML_MAPPING_NODE
)
199 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
202 type
= isl_calloc_type(ctx
, struct pet_type
);
206 for (pair
= node
->data
.mapping
.pairs
.start
;
207 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
208 yaml_node_t
*key
, *value
;
210 key
= yaml_document_get_node(document
, pair
->key
);
211 value
= yaml_document_get_node(document
, pair
->value
);
213 if (key
->type
!= YAML_SCALAR_NODE
)
214 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
215 return pet_type_free(type
));
217 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
218 type
->name
= extract_string(ctx
, document
, value
);
219 if (!strcmp((char *) key
->data
.scalar
.value
, "definition"))
220 type
->definition
= extract_string(ctx
, document
, value
);
226 /* Extract a sequence of types from "node" and store them in scop->types.
228 static struct pet_scop
*extract_types(isl_ctx
*ctx
,
229 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
232 yaml_node_item_t
*item
;
234 if (node
->type
!= YAML_SEQUENCE_NODE
)
235 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
238 scop
->n_type
= node
->data
.sequence
.items
.top
239 - node
->data
.sequence
.items
.start
;
240 scop
->types
= isl_calloc_array(ctx
, struct pet_type
*, scop
->n_type
);
242 return pet_scop_free(scop
);
244 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
245 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
248 n
= yaml_document_get_node(document
, *item
);
249 scop
->types
[i
] = extract_type(ctx
, document
, n
);
251 return pet_scop_free(scop
);
257 static struct pet_array
*extract_array(isl_ctx
*ctx
, yaml_document_t
*document
,
260 struct pet_array
*array
;
261 yaml_node_pair_t
* pair
;
263 if (node
->type
!= YAML_MAPPING_NODE
)
264 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
267 array
= isl_calloc_type(ctx
, struct pet_array
);
271 for (pair
= node
->data
.mapping
.pairs
.start
;
272 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
273 yaml_node_t
*key
, *value
;
275 key
= yaml_document_get_node(document
, pair
->key
);
276 value
= yaml_document_get_node(document
, pair
->value
);
278 if (key
->type
!= YAML_SCALAR_NODE
)
279 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
280 return pet_array_free(array
));
282 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
283 array
->context
= extract_set(ctx
, document
, value
);
284 if (!strcmp((char *) key
->data
.scalar
.value
, "extent"))
285 array
->extent
= extract_set(ctx
, document
, value
);
286 if (!strcmp((char *) key
->data
.scalar
.value
, "value_bounds"))
287 array
->value_bounds
= extract_set(ctx
, document
, value
);
288 if (!strcmp((char *) key
->data
.scalar
.value
, "element_type"))
289 array
->element_type
=
290 extract_string(ctx
, document
, value
);
291 if (!strcmp((char *) key
->data
.scalar
.value
, "element_size"))
292 array
->element_size
= extract_int(ctx
, document
, value
);
293 if (!strcmp((char *) key
->data
.scalar
.value
,
294 "element_is_record"))
295 array
->element_is_record
=
296 extract_int(ctx
, document
, value
);
297 if (!strcmp((char *) key
->data
.scalar
.value
, "live_out"))
298 array
->live_out
= extract_int(ctx
, document
, value
);
299 if (!strcmp((char *) key
->data
.scalar
.value
,
301 array
->uniquely_defined
=
302 extract_int(ctx
, document
, value
);
303 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
304 array
->declared
= extract_int(ctx
, document
, value
);
305 if (!strcmp((char *) key
->data
.scalar
.value
, "exposed"))
306 array
->exposed
= extract_int(ctx
, document
, value
);
312 static struct pet_scop
*extract_arrays(isl_ctx
*ctx
, yaml_document_t
*document
,
313 yaml_node_t
*node
, struct pet_scop
*scop
)
316 yaml_node_item_t
*item
;
318 if (node
->type
!= YAML_SEQUENCE_NODE
)
319 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
322 scop
->n_array
= node
->data
.sequence
.items
.top
323 - node
->data
.sequence
.items
.start
;
324 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*, scop
->n_array
);
326 return pet_scop_free(scop
);
328 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
329 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
332 n
= yaml_document_get_node(document
, *item
);
333 scop
->arrays
[i
] = extract_array(ctx
, document
, n
);
334 if (!scop
->arrays
[i
])
335 return pet_scop_free(scop
);
341 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
342 yaml_document_t
*document
, yaml_node_t
*node
);
344 static __isl_give pet_expr
*extract_arguments(isl_ctx
*ctx
,
345 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
348 yaml_node_item_t
*item
;
350 if (node
->type
!= YAML_SEQUENCE_NODE
)
351 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
352 return pet_expr_free(expr
));
354 n
= node
->data
.sequence
.items
.top
- node
->data
.sequence
.items
.start
;
355 expr
= pet_expr_set_n_arg(expr
, n
);
357 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
358 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
362 n
= yaml_document_get_node(document
, *item
);
363 arg
= extract_expr(ctx
, document
, n
);
364 expr
= pet_expr_set_arg(expr
, i
, arg
);
370 /* Extract pet_expr_double specific fields from "node" and
371 * update "expr" accordingly.
373 static __isl_give pet_expr
*extract_expr_double(isl_ctx
*ctx
,
374 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
376 yaml_node_pair_t
*pair
;
380 for (pair
= node
->data
.mapping
.pairs
.start
;
381 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
382 yaml_node_t
*key
, *value
;
384 key
= yaml_document_get_node(document
, pair
->key
);
385 value
= yaml_document_get_node(document
, pair
->value
);
387 if (key
->type
!= YAML_SCALAR_NODE
)
388 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
389 return pet_expr_free(expr
));
391 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
392 d
= extract_double(ctx
, document
, value
);
393 if (!strcmp((char *) key
->data
.scalar
.value
, "string"))
394 s
= extract_string(ctx
, document
, value
);
397 expr
= pet_expr_double_set(expr
, d
, s
);
403 /* Extract pet_expr_access specific fields from "node" and
404 * update "expr" accordingly.
406 * The depth of the access is initialized by pet_expr_access_set_index.
407 * Any explicitly specified depth therefore needs to be set after
408 * setting the index expression. Similiarly, the access relations (if any)
409 * need to be set after setting the depth.
411 static __isl_give pet_expr
*extract_expr_access(isl_ctx
*ctx
,
412 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
414 yaml_node_pair_t
*pair
;
416 isl_multi_pw_aff
*index
= NULL
;
418 for (pair
= node
->data
.mapping
.pairs
.start
;
419 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
420 yaml_node_t
*key
, *value
;
422 key
= yaml_document_get_node(document
, pair
->key
);
423 value
= yaml_document_get_node(document
, pair
->value
);
425 if (key
->type
!= YAML_SCALAR_NODE
)
426 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
427 return pet_expr_free(expr
));
429 if (!strcmp((char *) key
->data
.scalar
.value
, "index"))
430 index
= extract_multi_pw_aff(ctx
, document
, value
);
431 if (!strcmp((char *) key
->data
.scalar
.value
, "depth"))
432 depth
= extract_int(ctx
, document
, value
);
435 expr
= pet_expr_access_set_index(expr
, index
);
437 expr
= pet_expr_access_set_depth(expr
, depth
);
439 for (pair
= node
->data
.mapping
.pairs
.start
;
440 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
441 yaml_node_t
*key
, *value
;
443 key
= yaml_document_get_node(document
, pair
->key
);
444 value
= yaml_document_get_node(document
, pair
->value
);
446 if (key
->type
!= YAML_SCALAR_NODE
)
447 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
448 return pet_expr_free(expr
));
450 if (!strcmp((char *) key
->data
.scalar
.value
, "may_read"))
451 expr
= pet_expr_access_set_access(expr
,
452 pet_expr_access_may_read
,
453 extract_union_map(ctx
, document
, value
));
454 if (!strcmp((char *) key
->data
.scalar
.value
, "may_write"))
455 expr
= pet_expr_access_set_access(expr
,
456 pet_expr_access_may_write
,
457 extract_union_map(ctx
, document
, value
));
458 if (!strcmp((char *) key
->data
.scalar
.value
, "must_write"))
459 expr
= pet_expr_access_set_access(expr
,
460 pet_expr_access_must_write
,
461 extract_union_map(ctx
, document
, value
));
462 if (!strcmp((char *) key
->data
.scalar
.value
, "killed"))
463 expr
= pet_expr_access_set_access(expr
,
464 pet_expr_access_killed
,
465 extract_union_map(ctx
, document
, value
));
466 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
467 expr
= pet_expr_access_set_ref_id(expr
,
468 extract_id(ctx
, document
, value
));
469 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
470 expr
= pet_expr_access_set_read(expr
,
471 extract_int(ctx
, document
, value
));
472 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
473 expr
= pet_expr_access_set_write(expr
,
474 extract_int(ctx
, document
, value
));
475 if (!strcmp((char *) key
->data
.scalar
.value
, "kill"))
476 expr
= pet_expr_access_set_kill(expr
,
477 extract_int(ctx
, document
, value
));
483 /* Extract operation expression specific fields from "node" and
484 * update "expr" accordingly.
486 static __isl_give pet_expr
*extract_expr_op(isl_ctx
*ctx
,
487 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
489 yaml_node_pair_t
*pair
;
491 for (pair
= node
->data
.mapping
.pairs
.start
;
492 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
493 yaml_node_t
*key
, *value
;
495 key
= yaml_document_get_node(document
, pair
->key
);
496 value
= yaml_document_get_node(document
, pair
->value
);
498 if (key
->type
!= YAML_SCALAR_NODE
)
499 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
500 return pet_expr_free(expr
));
502 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
503 expr
= pet_expr_op_set_type(expr
,
504 extract_op(ctx
, document
, value
));
510 /* Extract pet_expr_call specific fields from "node" and
511 * update "expr" accordingly.
513 static __isl_give pet_expr
*extract_expr_call(isl_ctx
*ctx
,
514 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
516 yaml_node_pair_t
*pair
;
518 for (pair
= node
->data
.mapping
.pairs
.start
;
519 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
520 yaml_node_t
*key
, *value
;
522 key
= yaml_document_get_node(document
, pair
->key
);
523 value
= yaml_document_get_node(document
, pair
->value
);
525 if (key
->type
!= YAML_SCALAR_NODE
)
526 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
527 return pet_expr_free(expr
));
529 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
530 expr
= pet_expr_call_set_name(expr
,
531 extract_string(ctx
, document
, value
));
537 /* Extract pet_expr_cast specific fields from "node" and
538 * update "expr" accordingly.
540 static __isl_give pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
541 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
543 yaml_node_pair_t
*pair
;
545 for (pair
= node
->data
.mapping
.pairs
.start
;
546 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
547 yaml_node_t
*key
, *value
;
549 key
= yaml_document_get_node(document
, pair
->key
);
550 value
= yaml_document_get_node(document
, pair
->value
);
552 if (key
->type
!= YAML_SCALAR_NODE
)
553 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
554 return pet_expr_free(expr
));
556 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
557 expr
= pet_expr_cast_set_type_name(expr
,
558 extract_string(ctx
, document
, value
));
564 /* Extract pet_expr_int specific fields from "node" and
565 * update "expr" accordingly.
567 static __isl_give pet_expr
*extract_expr_int(isl_ctx
*ctx
,
568 yaml_document_t
*document
, yaml_node_t
*node
, __isl_take pet_expr
*expr
)
570 yaml_node_pair_t
* pair
;
572 for (pair
= node
->data
.mapping
.pairs
.start
;
573 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
574 yaml_node_t
*key
, *value
;
576 key
= yaml_document_get_node(document
, pair
->key
);
577 value
= yaml_document_get_node(document
, pair
->value
);
579 if (key
->type
!= YAML_SCALAR_NODE
)
580 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
581 return pet_expr_free(expr
));
583 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
584 expr
= pet_expr_int_set_val(expr
,
585 extract_val(ctx
, document
, value
));
591 /* Extract a pet_expr from "node".
593 * We first extract the type and arguments of the expression and
594 * then extract additional fields depending on the type.
596 static __isl_give pet_expr
*extract_expr(isl_ctx
*ctx
,
597 yaml_document_t
*document
, yaml_node_t
*node
)
599 enum pet_expr_type type
= pet_expr_error
;
601 yaml_node_pair_t
*pair
;
603 if (node
->type
!= YAML_MAPPING_NODE
)
604 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
607 for (pair
= node
->data
.mapping
.pairs
.start
;
608 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
609 yaml_node_t
*key
, *value
;
611 key
= yaml_document_get_node(document
, pair
->key
);
612 value
= yaml_document_get_node(document
, pair
->value
);
614 if (key
->type
!= YAML_SCALAR_NODE
)
615 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
616 return pet_expr_free(expr
));
618 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
619 type
= extract_expr_type(ctx
, document
, value
);
622 if (type
== pet_expr_error
)
623 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
626 expr
= pet_expr_alloc(ctx
, type
);
630 for (pair
= node
->data
.mapping
.pairs
.start
;
631 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
632 yaml_node_t
*key
, *value
;
634 key
= yaml_document_get_node(document
, pair
->key
);
635 value
= yaml_document_get_node(document
, pair
->value
);
637 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
638 expr
= extract_arguments(ctx
, document
, value
, expr
);
645 isl_die(ctx
, isl_error_internal
, "unreachable code",
647 case pet_expr_access
:
648 expr
= extract_expr_access(ctx
, document
, node
, expr
);
650 case pet_expr_double
:
651 expr
= extract_expr_double(ctx
, document
, node
, expr
);
654 expr
= extract_expr_call(ctx
, document
, node
, expr
);
657 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
660 expr
= extract_expr_int(ctx
, document
, node
, expr
);
663 expr
= extract_expr_op(ctx
, document
, node
, expr
);
670 /* Extract a pet_tree_type from "node".
672 static enum pet_tree_type
extract_tree_type(isl_ctx
*ctx
,
673 yaml_document_t
*document
, yaml_node_t
*node
)
675 if (node
->type
!= YAML_SCALAR_NODE
)
676 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
679 return pet_tree_str_type((char *) node
->data
.scalar
.value
);
682 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
683 yaml_document_t
*document
, yaml_node_t
*node
);
685 /* Extract a pet_tree of type pet_tree_block from "node".
687 static __isl_give pet_tree
*extract_tree_block(isl_ctx
*ctx
,
688 yaml_document_t
*document
, yaml_node_t
*node
)
692 yaml_node_pair_t
*pair
;
693 yaml_node_item_t
*item
;
694 yaml_node_t
*children
= NULL
;
697 for (pair
= node
->data
.mapping
.pairs
.start
;
698 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
699 yaml_node_t
*key
, *value
;
701 key
= yaml_document_get_node(document
, pair
->key
);
702 value
= yaml_document_get_node(document
, pair
->value
);
704 if (key
->type
!= YAML_SCALAR_NODE
)
705 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
708 if (!strcmp((char *) key
->data
.scalar
.value
, "block"))
709 block
= extract_int(ctx
, document
, value
);
710 if (!strcmp((char *) key
->data
.scalar
.value
, "children"))
717 n
= children
->data
.sequence
.items
.top
-
718 children
->data
.sequence
.items
.start
;
720 tree
= pet_tree_new_block(ctx
, block
, n
);
724 for (item
= children
->data
.sequence
.items
.start
, i
= 0;
725 item
< children
->data
.sequence
.items
.top
; ++item
, ++i
) {
729 n
= yaml_document_get_node(document
, *item
);
730 child
= extract_tree(ctx
, document
, n
);
731 tree
= pet_tree_block_add_child(tree
, child
);
737 /* Extract a pet_tree of type pet_tree_decl from "node".
739 static __isl_give pet_tree
*extract_tree_decl(isl_ctx
*ctx
,
740 yaml_document_t
*document
, yaml_node_t
*node
)
742 yaml_node_pair_t
*pair
;
743 pet_expr
*var
= NULL
;
745 for (pair
= node
->data
.mapping
.pairs
.start
;
746 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
747 yaml_node_t
*key
, *value
;
749 key
= yaml_document_get_node(document
, pair
->key
);
750 value
= yaml_document_get_node(document
, pair
->value
);
752 if (key
->type
!= YAML_SCALAR_NODE
)
753 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
756 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
757 var
= extract_expr(ctx
, document
, value
);
764 isl_die(ctx
, isl_error_invalid
,
765 "no variable field", return NULL
);
767 return pet_tree_new_decl(var
);
770 /* Extract a pet_tree of type pet_tree_decl_init from "node".
772 static __isl_give pet_tree
*extract_tree_decl_init(isl_ctx
*ctx
,
773 yaml_document_t
*document
, yaml_node_t
*node
)
775 yaml_node_pair_t
*pair
;
776 pet_expr
*var
= NULL
;
777 pet_expr
*init
= NULL
;
779 for (pair
= node
->data
.mapping
.pairs
.start
;
780 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
781 yaml_node_t
*key
, *value
;
783 key
= yaml_document_get_node(document
, pair
->key
);
784 value
= yaml_document_get_node(document
, pair
->value
);
786 if (key
->type
!= YAML_SCALAR_NODE
)
787 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
790 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
791 var
= extract_expr(ctx
, document
, value
);
795 if (!strcmp((char *) key
->data
.scalar
.value
,
797 init
= extract_expr(ctx
, document
, value
);
804 isl_die(ctx
, isl_error_invalid
,
805 "no variable field", goto error
);
807 isl_die(ctx
, isl_error_invalid
,
808 "no initialization field", goto error
);
810 return pet_tree_new_decl_init(var
, init
);
817 /* Extract a pet_tree of type pet_tree_expr from "node".
819 static __isl_give pet_tree
*extract_tree_expr(isl_ctx
*ctx
,
820 yaml_document_t
*document
, yaml_node_t
*node
)
822 yaml_node_pair_t
*pair
;
823 pet_expr
*expr
= NULL
;
825 for (pair
= node
->data
.mapping
.pairs
.start
;
826 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
827 yaml_node_t
*key
, *value
;
829 key
= yaml_document_get_node(document
, pair
->key
);
830 value
= yaml_document_get_node(document
, pair
->value
);
832 if (key
->type
!= YAML_SCALAR_NODE
)
833 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
836 if (!strcmp((char *) key
->data
.scalar
.value
, "expr")) {
837 expr
= extract_expr(ctx
, document
, value
);
844 isl_die(ctx
, isl_error_invalid
,
845 "no expr field", return NULL
);
847 return pet_tree_new_expr(expr
);
850 /* Extract a pet_tree of type pet_tree_while from "node".
852 static __isl_give pet_tree
*extract_tree_while(isl_ctx
*ctx
,
853 yaml_document_t
*document
, yaml_node_t
*node
)
855 yaml_node_pair_t
*pair
;
856 pet_expr
*cond
= NULL
;
857 pet_tree
*body
= NULL
;
859 for (pair
= node
->data
.mapping
.pairs
.start
;
860 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
861 yaml_node_t
*key
, *value
;
863 key
= yaml_document_get_node(document
, pair
->key
);
864 value
= yaml_document_get_node(document
, pair
->value
);
866 if (key
->type
!= YAML_SCALAR_NODE
)
867 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
870 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
871 cond
= extract_expr(ctx
, document
, value
);
875 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
876 body
= extract_tree(ctx
, document
, value
);
883 isl_die(ctx
, isl_error_invalid
,
884 "no condition field", goto error
);
886 isl_die(ctx
, isl_error_invalid
,
887 "no body field", goto error
);
889 return pet_tree_new_while(cond
, body
);
896 /* Extract a pet_tree of type pet_tree_infinite_loop from "node".
898 static __isl_give pet_tree
*extract_tree_infinite_loop(isl_ctx
*ctx
,
899 yaml_document_t
*document
, yaml_node_t
*node
)
901 yaml_node_pair_t
*pair
;
904 for (pair
= node
->data
.mapping
.pairs
.start
;
905 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
906 yaml_node_t
*key
, *value
;
908 key
= yaml_document_get_node(document
, pair
->key
);
909 value
= yaml_document_get_node(document
, pair
->value
);
911 if (key
->type
!= YAML_SCALAR_NODE
)
912 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
915 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
916 body
= extract_tree(ctx
, document
, value
);
923 isl_die(ctx
, isl_error_invalid
,
924 "no body field", return NULL
);
926 return pet_tree_new_infinite_loop(body
);
929 /* Extract a pet_tree of type pet_tree_if from "node".
931 static __isl_give pet_tree
*extract_tree_if(isl_ctx
*ctx
,
932 yaml_document_t
*document
, yaml_node_t
*node
)
934 yaml_node_pair_t
*pair
;
935 pet_expr
*cond
= NULL
;
936 pet_tree
*then_body
= NULL
;
938 for (pair
= node
->data
.mapping
.pairs
.start
;
939 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
940 yaml_node_t
*key
, *value
;
942 key
= yaml_document_get_node(document
, pair
->key
);
943 value
= yaml_document_get_node(document
, pair
->value
);
945 if (key
->type
!= YAML_SCALAR_NODE
)
946 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
949 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
950 cond
= extract_expr(ctx
, document
, value
);
954 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
955 then_body
= extract_tree(ctx
, document
, value
);
962 isl_die(ctx
, isl_error_invalid
,
963 "no condition field", goto error
);
965 isl_die(ctx
, isl_error_invalid
,
966 "no then body", goto error
);
968 return pet_tree_new_if(cond
, then_body
);
971 pet_tree_free(then_body
);
975 /* Extract a pet_tree of type pet_tree_if_else from "node".
977 static __isl_give pet_tree
*extract_tree_if_else(isl_ctx
*ctx
,
978 yaml_document_t
*document
, yaml_node_t
*node
)
980 yaml_node_pair_t
*pair
;
981 pet_expr
*cond
= NULL
;
982 pet_tree
*then_body
= NULL
;
983 pet_tree
*else_body
= NULL
;
985 for (pair
= node
->data
.mapping
.pairs
.start
;
986 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
987 yaml_node_t
*key
, *value
;
989 key
= yaml_document_get_node(document
, pair
->key
);
990 value
= yaml_document_get_node(document
, pair
->value
);
992 if (key
->type
!= YAML_SCALAR_NODE
)
993 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
996 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
997 cond
= extract_expr(ctx
, document
, value
);
1001 if (!strcmp((char *) key
->data
.scalar
.value
, "then")) {
1002 then_body
= extract_tree(ctx
, document
, value
);
1006 if (!strcmp((char *) key
->data
.scalar
.value
, "else")) {
1007 else_body
= extract_tree(ctx
, document
, value
);
1014 isl_die(ctx
, isl_error_invalid
,
1015 "no condition field", goto error
);
1017 isl_die(ctx
, isl_error_invalid
,
1018 "no then body", goto error
);
1020 isl_die(ctx
, isl_error_invalid
,
1021 "no else body", goto error
);
1023 return pet_tree_new_if_else(cond
, then_body
, else_body
);
1025 pet_expr_free(cond
);
1026 pet_tree_free(then_body
);
1027 pet_tree_free(else_body
);
1031 /* Extract a pet_tree of type pet_tree_for from "node".
1033 static __isl_give pet_tree
*extract_tree_for(isl_ctx
*ctx
,
1034 yaml_document_t
*document
, yaml_node_t
*node
)
1036 yaml_node_pair_t
*pair
;
1038 int independent
= 0;
1039 pet_expr
*iv
= NULL
;
1040 pet_expr
*init
= NULL
;
1041 pet_expr
*cond
= NULL
;
1042 pet_expr
*inc
= NULL
;
1043 pet_tree
*body
= NULL
;
1045 for (pair
= node
->data
.mapping
.pairs
.start
;
1046 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1047 yaml_node_t
*key
, *value
;
1049 key
= yaml_document_get_node(document
, pair
->key
);
1050 value
= yaml_document_get_node(document
, pair
->value
);
1052 if (key
->type
!= YAML_SCALAR_NODE
)
1053 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1056 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
1057 declared
= extract_int(ctx
, document
, value
);
1058 if (!strcmp((char *) key
->data
.scalar
.value
, "independent"))
1059 independent
= extract_int(ctx
, document
, value
);
1060 if (!strcmp((char *) key
->data
.scalar
.value
, "variable")) {
1061 iv
= extract_expr(ctx
, document
, value
);
1065 if (!strcmp((char *) key
->data
.scalar
.value
,
1066 "initialization")) {
1067 init
= extract_expr(ctx
, document
, value
);
1071 if (!strcmp((char *) key
->data
.scalar
.value
, "condition")) {
1072 cond
= extract_expr(ctx
, document
, value
);
1076 if (!strcmp((char *) key
->data
.scalar
.value
, "increment")) {
1077 inc
= extract_expr(ctx
, document
, value
);
1081 if (!strcmp((char *) key
->data
.scalar
.value
, "body")) {
1082 body
= extract_tree(ctx
, document
, value
);
1089 isl_die(ctx
, isl_error_invalid
,
1090 "no variable field", goto error
);
1092 isl_die(ctx
, isl_error_invalid
,
1093 "no initialization field", goto error
);
1095 isl_die(ctx
, isl_error_invalid
,
1096 "no condition field", goto error
);
1098 isl_die(ctx
, isl_error_invalid
,
1099 "no increment field", goto error
);
1101 isl_die(ctx
, isl_error_invalid
,
1102 "no body field", goto error
);
1104 return pet_tree_new_for(independent
, declared
, iv
, init
, cond
, inc
,
1108 pet_expr_free(init
);
1109 pet_expr_free(cond
);
1111 pet_tree_free(body
);
1115 /* Extract a pet_tree from "node".
1117 * We first extract the type of the pet_tree and then call
1118 * the appropriate function to extract and construct a pet_tree
1121 static __isl_give pet_tree
*extract_tree(isl_ctx
*ctx
,
1122 yaml_document_t
*document
, yaml_node_t
*node
)
1124 enum pet_tree_type type
= pet_tree_error
;
1126 yaml_node_pair_t
*pair
;
1128 if (node
->type
!= YAML_MAPPING_NODE
)
1129 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1132 for (pair
= node
->data
.mapping
.pairs
.start
;
1133 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1134 yaml_node_t
*key
, *value
;
1136 key
= yaml_document_get_node(document
, pair
->key
);
1137 value
= yaml_document_get_node(document
, pair
->value
);
1139 if (key
->type
!= YAML_SCALAR_NODE
)
1140 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1141 return pet_tree_free(tree
));
1143 if (!strcmp((char *) key
->data
.scalar
.value
, "type"))
1144 type
= extract_tree_type(ctx
, document
, value
);
1147 if (type
== pet_tree_error
)
1148 isl_die(ctx
, isl_error_invalid
, "cannot determine type",
1152 case pet_tree_error
:
1154 case pet_tree_block
:
1155 tree
= extract_tree_block(ctx
, document
, node
);
1157 case pet_tree_break
:
1158 tree
= pet_tree_new_break(ctx
);
1160 case pet_tree_continue
:
1161 tree
= pet_tree_new_continue(ctx
);
1164 tree
= extract_tree_decl(ctx
, document
, node
);
1166 case pet_tree_decl_init
:
1167 tree
= extract_tree_decl_init(ctx
, document
, node
);
1170 tree
= extract_tree_expr(ctx
, document
, node
);
1173 tree
= extract_tree_for(ctx
, document
, node
);
1175 case pet_tree_while
:
1176 tree
= extract_tree_while(ctx
, document
, node
);
1178 case pet_tree_infinite_loop
:
1179 tree
= extract_tree_infinite_loop(ctx
, document
, node
);
1182 tree
= extract_tree_if(ctx
, document
, node
);
1184 case pet_tree_if_else
:
1185 tree
= extract_tree_if_else(ctx
, document
, node
);
1192 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
1193 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
1196 yaml_node_item_t
*item
;
1198 if (node
->type
!= YAML_SEQUENCE_NODE
)
1199 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1200 return pet_stmt_free(stmt
));
1202 stmt
->n_arg
= node
->data
.sequence
.items
.top
1203 - node
->data
.sequence
.items
.start
;
1204 stmt
->args
= isl_calloc_array(ctx
, pet_expr
*, stmt
->n_arg
);
1206 return pet_stmt_free(stmt
);
1208 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1209 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1212 n
= yaml_document_get_node(document
, *item
);
1213 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
1215 return pet_stmt_free(stmt
);
1221 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
1224 struct pet_stmt
*stmt
;
1225 yaml_node_pair_t
* pair
;
1227 unsigned start
= 0, end
= 0;
1228 char *indent
= NULL
;
1230 if (node
->type
!= YAML_MAPPING_NODE
)
1231 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1234 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
1238 stmt
->loc
= &pet_loc_dummy
;
1240 for (pair
= node
->data
.mapping
.pairs
.start
;
1241 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1242 yaml_node_t
*key
, *value
;
1244 key
= yaml_document_get_node(document
, pair
->key
);
1245 value
= yaml_document_get_node(document
, pair
->value
);
1247 if (key
->type
!= YAML_SCALAR_NODE
)
1248 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1249 return pet_stmt_free(stmt
));
1251 if (!strcmp((char *) key
->data
.scalar
.value
, "indent"))
1252 indent
= extract_string(ctx
, document
, value
);
1253 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
1254 line
= extract_int(ctx
, document
, value
);
1255 if (!strcmp((char *) key
->data
.scalar
.value
, "start"))
1256 start
= extract_int(ctx
, document
, value
);
1257 if (!strcmp((char *) key
->data
.scalar
.value
, "end"))
1258 end
= extract_int(ctx
, document
, value
);
1259 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
1260 stmt
->domain
= extract_set(ctx
, document
, value
);
1261 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
1262 stmt
->body
= extract_tree(ctx
, document
, value
);
1264 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
1265 stmt
= extract_stmt_arguments(ctx
, document
,
1272 indent
= strdup("");
1273 stmt
->loc
= pet_loc_alloc(ctx
, start
, end
, line
, indent
);
1275 return pet_stmt_free(stmt
);
1280 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
1281 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1284 yaml_node_item_t
*item
;
1286 if (node
->type
!= YAML_SEQUENCE_NODE
)
1287 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1290 scop
->n_stmt
= node
->data
.sequence
.items
.top
1291 - node
->data
.sequence
.items
.start
;
1292 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
1294 return pet_scop_free(scop
);
1296 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1297 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1300 n
= yaml_document_get_node(document
, *item
);
1301 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
1302 if (!scop
->stmts
[i
])
1303 return pet_scop_free(scop
);
1309 /* Extract a pet_implication from "node".
1311 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
1312 yaml_document_t
*document
, yaml_node_t
*node
)
1314 struct pet_implication
*implication
;
1315 yaml_node_pair_t
* pair
;
1317 if (node
->type
!= YAML_MAPPING_NODE
)
1318 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1321 implication
= isl_calloc_type(ctx
, struct pet_implication
);
1325 for (pair
= node
->data
.mapping
.pairs
.start
;
1326 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1327 yaml_node_t
*key
, *value
;
1329 key
= yaml_document_get_node(document
, pair
->key
);
1330 value
= yaml_document_get_node(document
, pair
->value
);
1332 if (key
->type
!= YAML_SCALAR_NODE
)
1333 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1334 return pet_implication_free(implication
));
1336 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
1337 implication
->satisfied
=
1338 extract_int(ctx
, document
, value
);
1339 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
1340 implication
->extension
=
1341 extract_map(ctx
, document
, value
);
1347 /* Extract a sequence of implications from "node" and
1348 * store them in scop->implications.
1350 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
1351 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1354 yaml_node_item_t
*item
;
1356 if (node
->type
!= YAML_SEQUENCE_NODE
)
1357 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1360 scop
->n_implication
= node
->data
.sequence
.items
.top
1361 - node
->data
.sequence
.items
.start
;
1362 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
1363 scop
->n_implication
);
1364 if (!scop
->implications
)
1365 return pet_scop_free(scop
);
1367 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1368 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1371 n
= yaml_document_get_node(document
, *item
);
1372 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
1373 if (!scop
->implications
[i
])
1374 return pet_scop_free(scop
);
1380 /* Extract a pet_independence from "node".
1382 static struct pet_independence
*extract_independence(isl_ctx
*ctx
,
1383 yaml_document_t
*document
, yaml_node_t
*node
)
1385 struct pet_independence
*independence
;
1386 yaml_node_pair_t
* pair
;
1388 if (node
->type
!= YAML_MAPPING_NODE
)
1389 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1392 independence
= isl_calloc_type(ctx
, struct pet_independence
);
1396 for (pair
= node
->data
.mapping
.pairs
.start
;
1397 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1398 yaml_node_t
*key
, *value
;
1400 key
= yaml_document_get_node(document
, pair
->key
);
1401 value
= yaml_document_get_node(document
, pair
->value
);
1403 if (key
->type
!= YAML_SCALAR_NODE
)
1404 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1405 return pet_independence_free(independence
));
1407 if (!strcmp((char *) key
->data
.scalar
.value
, "filter"))
1408 independence
->filter
=
1409 extract_union_map(ctx
, document
, value
);
1410 if (!strcmp((char *) key
->data
.scalar
.value
, "local"))
1411 independence
->local
=
1412 extract_union_set(ctx
, document
, value
);
1415 if (!independence
->filter
)
1416 isl_die(ctx
, isl_error_invalid
, "no filter field",
1417 return pet_independence_free(independence
));
1418 if (!independence
->local
)
1419 isl_die(ctx
, isl_error_invalid
, "no local field",
1420 return pet_independence_free(independence
));
1422 return independence
;
1425 /* Extract a sequence of independences from "node" and
1426 * store them in scop->independences.
1428 static struct pet_scop
*extract_independences(isl_ctx
*ctx
,
1429 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
1432 yaml_node_item_t
*item
;
1434 if (node
->type
!= YAML_SEQUENCE_NODE
)
1435 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
1438 scop
->n_independence
= node
->data
.sequence
.items
.top
1439 - node
->data
.sequence
.items
.start
;
1440 scop
->independences
= isl_calloc_array(ctx
, struct pet_independence
*,
1441 scop
->n_independence
);
1442 if (!scop
->independences
)
1443 return pet_scop_free(scop
);
1445 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
1446 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
1449 n
= yaml_document_get_node(document
, *item
);
1450 scop
->independences
[i
] = extract_independence(ctx
, document
, n
);
1451 if (!scop
->independences
[i
])
1452 return pet_scop_free(scop
);
1458 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
1461 struct pet_scop
*scop
;
1462 yaml_node_pair_t
* pair
;
1467 if (node
->type
!= YAML_MAPPING_NODE
)
1468 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
1471 scop
= pet_scop_alloc(ctx
);
1475 for (pair
= node
->data
.mapping
.pairs
.start
;
1476 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
1477 yaml_node_t
*key
, *value
;
1479 key
= yaml_document_get_node(document
, pair
->key
);
1480 value
= yaml_document_get_node(document
, pair
->value
);
1482 if (key
->type
!= YAML_SCALAR_NODE
)
1483 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
1484 return pet_scop_free(scop
));
1485 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
1486 scop
->context
= extract_set(ctx
, document
, value
);
1487 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
1488 scop
->context_value
= extract_set(ctx
, document
, value
);
1489 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
1490 scop
->schedule
= extract_schedule(ctx
, document
, value
);
1491 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
1492 scop
= extract_types(ctx
, document
, value
, scop
);
1493 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
1494 scop
= extract_arrays(ctx
, document
, value
, scop
);
1495 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
1496 scop
= extract_statements(ctx
, document
, value
, scop
);
1497 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
1498 scop
= extract_implications(ctx
, document
, value
, scop
);
1499 if (!strcmp((char *) key
->data
.scalar
.value
, "independences"))
1500 scop
= extract_independences(ctx
,
1501 document
, value
, scop
);
1506 if (!scop
->context_value
) {
1507 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
1508 scop
->context_value
= isl_set_universe(space
);
1509 if (!scop
->context_value
)
1510 return pet_scop_free(scop
);
1516 /* Extract a pet_scop from the YAML description in "in".
1518 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
1520 struct pet_scop
*scop
= NULL
;
1521 yaml_parser_t parser
;
1523 yaml_document_t document
= { 0 };
1525 yaml_parser_initialize(&parser
);
1527 yaml_parser_set_input_file(&parser
, in
);
1529 if (!yaml_parser_load(&parser
, &document
))
1532 root
= yaml_document_get_root_node(&document
);
1534 scop
= extract_scop(ctx
, &document
, root
);
1536 yaml_document_delete(&document
);
1538 yaml_parser_delete(&parser
);
1542 yaml_parser_delete(&parser
);
1543 pet_scop_free(scop
);