2 * Copyright 2011 Leiden University. All rights reserved.
3 * Copyright 2013 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
40 #include "scop_yaml.h"
42 static char *extract_string(isl_ctx
*ctx
, yaml_document_t
*document
,
45 if (node
->type
!= YAML_SCALAR_NODE
)
46 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
49 return strdup((char *) node
->data
.scalar
.value
);
52 static int extract_int(isl_ctx
*ctx
, yaml_document_t
*document
,
55 if (node
->type
!= YAML_SCALAR_NODE
)
56 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
59 return atoi((char *) node
->data
.scalar
.value
);
62 static double extract_double(isl_ctx
*ctx
, yaml_document_t
*document
,
65 if (node
->type
!= YAML_SCALAR_NODE
)
66 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
69 return strtod((char *) node
->data
.scalar
.value
, NULL
);
72 static enum pet_expr_type
extract_expr_type(isl_ctx
*ctx
,
73 yaml_document_t
*document
, yaml_node_t
*node
)
75 if (node
->type
!= YAML_SCALAR_NODE
)
76 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
79 return pet_str_type((char *) node
->data
.scalar
.value
);
82 static enum pet_op_type
extract_op(isl_ctx
*ctx
, yaml_document_t
*document
,
85 if (node
->type
!= YAML_SCALAR_NODE
)
86 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
89 return pet_str_op((char *) node
->data
.scalar
.value
);
92 static __isl_give isl_set
*extract_set(isl_ctx
*ctx
, yaml_document_t
*document
,
95 if (node
->type
!= YAML_SCALAR_NODE
)
96 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
99 return isl_set_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
102 static __isl_give isl_id
*extract_id(isl_ctx
*ctx
, yaml_document_t
*document
,
105 if (node
->type
!= YAML_SCALAR_NODE
)
106 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
109 return isl_id_alloc(ctx
, (char *) node
->data
.scalar
.value
, NULL
);
112 static __isl_give isl_map
*extract_map(isl_ctx
*ctx
, yaml_document_t
*document
,
115 if (node
->type
!= YAML_SCALAR_NODE
)
116 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
119 return isl_map_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
122 /* Extract an isl_val from "node".
124 static __isl_give isl_val
*extract_val(isl_ctx
*ctx
, yaml_document_t
*document
,
127 if (node
->type
!= YAML_SCALAR_NODE
)
128 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
131 return isl_val_read_from_str(ctx
, (char *) node
->data
.scalar
.value
);
134 /* Extract an isl_multi_pw_aff from "node".
136 static __isl_give isl_multi_pw_aff
*extract_multi_pw_aff(isl_ctx
*ctx
,
137 yaml_document_t
*document
, yaml_node_t
*node
)
139 if (node
->type
!= YAML_SCALAR_NODE
)
140 isl_die(ctx
, isl_error_invalid
, "expecting scalar node",
143 return isl_multi_pw_aff_read_from_str(ctx
,
144 (char *) node
->data
.scalar
.value
);
147 /* Extract a pet_type from "node".
149 static struct pet_type
*extract_type(isl_ctx
*ctx
,
150 yaml_document_t
*document
, yaml_node_t
*node
)
152 struct pet_type
*type
;
153 yaml_node_pair_t
* pair
;
155 if (node
->type
!= YAML_MAPPING_NODE
)
156 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
159 type
= isl_calloc_type(ctx
, struct pet_type
);
163 for (pair
= node
->data
.mapping
.pairs
.start
;
164 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
165 yaml_node_t
*key
, *value
;
167 key
= yaml_document_get_node(document
, pair
->key
);
168 value
= yaml_document_get_node(document
, pair
->value
);
170 if (key
->type
!= YAML_SCALAR_NODE
)
171 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
172 return pet_type_free(type
));
174 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
175 type
->name
= extract_string(ctx
, document
, value
);
176 if (!strcmp((char *) key
->data
.scalar
.value
, "definition"))
177 type
->definition
= extract_string(ctx
, document
, value
);
183 /* Extract a sequence of types from "node" and store them in scop->types.
185 static struct pet_scop
*extract_types(isl_ctx
*ctx
,
186 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
189 yaml_node_item_t
*item
;
191 if (node
->type
!= YAML_SEQUENCE_NODE
)
192 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
195 scop
->n_type
= node
->data
.sequence
.items
.top
196 - node
->data
.sequence
.items
.start
;
197 scop
->types
= isl_calloc_array(ctx
, struct pet_type
*, scop
->n_type
);
199 return pet_scop_free(scop
);
201 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
202 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
205 n
= yaml_document_get_node(document
, *item
);
206 scop
->types
[i
] = extract_type(ctx
, document
, n
);
208 return pet_scop_free(scop
);
214 static struct pet_array
*extract_array(isl_ctx
*ctx
, yaml_document_t
*document
,
217 struct pet_array
*array
;
218 yaml_node_pair_t
* pair
;
220 if (node
->type
!= YAML_MAPPING_NODE
)
221 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
224 array
= isl_calloc_type(ctx
, struct pet_array
);
228 for (pair
= node
->data
.mapping
.pairs
.start
;
229 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
230 yaml_node_t
*key
, *value
;
232 key
= yaml_document_get_node(document
, pair
->key
);
233 value
= yaml_document_get_node(document
, pair
->value
);
235 if (key
->type
!= YAML_SCALAR_NODE
)
236 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
237 return pet_array_free(array
));
239 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
240 array
->context
= extract_set(ctx
, document
, value
);
241 if (!strcmp((char *) key
->data
.scalar
.value
, "extent"))
242 array
->extent
= extract_set(ctx
, document
, value
);
243 if (!strcmp((char *) key
->data
.scalar
.value
, "value_bounds"))
244 array
->value_bounds
= extract_set(ctx
, document
, value
);
245 if (!strcmp((char *) key
->data
.scalar
.value
, "element_type"))
246 array
->element_type
=
247 extract_string(ctx
, document
, value
);
248 if (!strcmp((char *) key
->data
.scalar
.value
, "element_size"))
249 array
->element_size
= extract_int(ctx
, document
, value
);
250 if (!strcmp((char *) key
->data
.scalar
.value
,
251 "element_is_record"))
252 array
->element_is_record
=
253 extract_int(ctx
, document
, value
);
254 if (!strcmp((char *) key
->data
.scalar
.value
, "live_out"))
255 array
->live_out
= extract_int(ctx
, document
, value
);
256 if (!strcmp((char *) key
->data
.scalar
.value
,
258 array
->uniquely_defined
=
259 extract_int(ctx
, document
, value
);
260 if (!strcmp((char *) key
->data
.scalar
.value
, "declared"))
261 array
->declared
= extract_int(ctx
, document
, value
);
262 if (!strcmp((char *) key
->data
.scalar
.value
, "exposed"))
263 array
->exposed
= extract_int(ctx
, document
, value
);
269 static struct pet_scop
*extract_arrays(isl_ctx
*ctx
, yaml_document_t
*document
,
270 yaml_node_t
*node
, struct pet_scop
*scop
)
273 yaml_node_item_t
*item
;
275 if (node
->type
!= YAML_SEQUENCE_NODE
)
276 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
279 scop
->n_array
= node
->data
.sequence
.items
.top
280 - node
->data
.sequence
.items
.start
;
281 scop
->arrays
= isl_calloc_array(ctx
, struct pet_array
*, scop
->n_array
);
283 return pet_scop_free(scop
);
285 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
286 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
289 n
= yaml_document_get_node(document
, *item
);
290 scop
->arrays
[i
] = extract_array(ctx
, document
, n
);
291 if (!scop
->arrays
[i
])
292 return pet_scop_free(scop
);
298 static struct pet_expr
*extract_expr(isl_ctx
*ctx
, yaml_document_t
*document
,
301 static struct pet_expr
*extract_arguments(isl_ctx
*ctx
,
302 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
305 yaml_node_item_t
*item
;
307 if (node
->type
!= YAML_SEQUENCE_NODE
)
308 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
309 return pet_expr_free(expr
));
311 expr
->n_arg
= node
->data
.sequence
.items
.top
312 - node
->data
.sequence
.items
.start
;
313 expr
->args
= isl_calloc_array(ctx
, struct pet_expr
*, expr
->n_arg
);
315 return pet_expr_free(expr
);
317 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
318 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
321 n
= yaml_document_get_node(document
, *item
);
322 expr
->args
[i
] = extract_expr(ctx
, document
, n
);
324 return pet_expr_free(expr
);
330 /* Extract pet_expr_double specific fields from "node" and
331 * update "expr" accordingly.
333 static struct pet_expr
*extract_expr_double(isl_ctx
*ctx
,
334 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
336 yaml_node_pair_t
*pair
;
338 for (pair
= node
->data
.mapping
.pairs
.start
;
339 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
340 yaml_node_t
*key
, *value
;
342 key
= yaml_document_get_node(document
, pair
->key
);
343 value
= yaml_document_get_node(document
, pair
->value
);
345 if (key
->type
!= YAML_SCALAR_NODE
)
346 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
347 return pet_expr_free(expr
));
349 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
350 expr
->d
.val
= extract_double(ctx
, document
, value
);
351 if (!strcmp((char *) key
->data
.scalar
.value
, "string"))
352 expr
->d
.s
= extract_string(ctx
, document
, value
);
358 /* Extract pet_expr_access specific fields from "node" and
359 * update "expr" accordingly.
361 static struct pet_expr
*extract_expr_access(isl_ctx
*ctx
,
362 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
364 yaml_node_pair_t
*pair
;
366 for (pair
= node
->data
.mapping
.pairs
.start
;
367 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
368 yaml_node_t
*key
, *value
;
370 key
= yaml_document_get_node(document
, pair
->key
);
371 value
= yaml_document_get_node(document
, pair
->value
);
373 if (key
->type
!= YAML_SCALAR_NODE
)
374 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
375 return pet_expr_free(expr
));
377 if (!strcmp((char *) key
->data
.scalar
.value
, "relation"))
378 expr
->acc
.access
= extract_map(ctx
, document
, value
);
379 if (!strcmp((char *) key
->data
.scalar
.value
, "index"))
380 expr
->acc
.index
= extract_multi_pw_aff(ctx
, document
,
382 if (!strcmp((char *) key
->data
.scalar
.value
, "reference"))
383 expr
->acc
.ref_id
= extract_id(ctx
, document
, value
);
384 if (!strcmp((char *) key
->data
.scalar
.value
, "read"))
385 expr
->acc
.read
= extract_int(ctx
, document
, value
);
386 if (!strcmp((char *) key
->data
.scalar
.value
, "write"))
387 expr
->acc
.write
= extract_int(ctx
, document
, value
);
393 /* Extract operation expression specific fields from "node" and
394 * update "expr" accordingly.
396 static struct pet_expr
*extract_expr_op(isl_ctx
*ctx
,
397 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
399 yaml_node_pair_t
*pair
;
401 for (pair
= node
->data
.mapping
.pairs
.start
;
402 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
403 yaml_node_t
*key
, *value
;
405 key
= yaml_document_get_node(document
, pair
->key
);
406 value
= yaml_document_get_node(document
, pair
->value
);
408 if (key
->type
!= YAML_SCALAR_NODE
)
409 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
410 return pet_expr_free(expr
));
412 if (!strcmp((char *) key
->data
.scalar
.value
, "operation"))
413 expr
->op
= extract_op(ctx
, document
, value
);
419 /* Extract pet_expr_call specific fields from "node" and
420 * update "expr" accordingly.
422 static struct pet_expr
*extract_expr_call(isl_ctx
*ctx
,
423 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
425 yaml_node_pair_t
*pair
;
427 for (pair
= node
->data
.mapping
.pairs
.start
;
428 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
429 yaml_node_t
*key
, *value
;
431 key
= yaml_document_get_node(document
, pair
->key
);
432 value
= yaml_document_get_node(document
, pair
->value
);
434 if (key
->type
!= YAML_SCALAR_NODE
)
435 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
436 return pet_expr_free(expr
));
438 if (!strcmp((char *) key
->data
.scalar
.value
, "name"))
439 expr
->name
= extract_string(ctx
, document
, value
);
445 /* Extract pet_expr_cast specific fields from "node" and
446 * update "expr" accordingly.
448 static struct pet_expr
*extract_expr_cast(isl_ctx
*ctx
,
449 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
451 yaml_node_pair_t
*pair
;
453 for (pair
= node
->data
.mapping
.pairs
.start
;
454 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
455 yaml_node_t
*key
, *value
;
457 key
= yaml_document_get_node(document
, pair
->key
);
458 value
= yaml_document_get_node(document
, pair
->value
);
460 if (key
->type
!= YAML_SCALAR_NODE
)
461 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
462 return pet_expr_free(expr
));
464 if (!strcmp((char *) key
->data
.scalar
.value
, "type_name"))
465 expr
->type_name
= extract_string(ctx
, document
, value
);
471 /* Extract pet_expr_int specific fields from "node" and
472 * update "expr" accordingly.
474 static struct pet_expr
*extract_expr_int(isl_ctx
*ctx
,
475 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_expr
*expr
)
477 yaml_node_pair_t
* pair
;
479 for (pair
= node
->data
.mapping
.pairs
.start
;
480 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
481 yaml_node_t
*key
, *value
;
483 key
= yaml_document_get_node(document
, pair
->key
);
484 value
= yaml_document_get_node(document
, pair
->value
);
486 if (key
->type
!= YAML_SCALAR_NODE
)
487 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
488 return pet_expr_free(expr
));
490 if (!strcmp((char *) key
->data
.scalar
.value
, "value"))
491 expr
->i
= extract_val(ctx
, document
, value
);
497 /* Extract a pet_expr from "node".
499 * We first extract the type and arguments of the expression and
500 * then extract additional fields depending on the type.
502 static struct pet_expr
*extract_expr(isl_ctx
*ctx
, yaml_document_t
*document
,
505 struct pet_expr
*expr
;
506 yaml_node_pair_t
*pair
;
508 if (node
->type
!= YAML_MAPPING_NODE
)
509 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
512 expr
= isl_calloc_type(ctx
, struct pet_expr
);
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
, "type"))
528 expr
->type
= extract_expr_type(ctx
, document
, value
);
530 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
531 expr
= extract_arguments(ctx
, document
, value
, expr
);
536 switch (expr
->type
) {
537 case pet_expr_access
:
538 expr
= extract_expr_access(ctx
, document
, node
, expr
);
540 case pet_expr_double
:
541 expr
= extract_expr_double(ctx
, document
, node
, expr
);
544 expr
= extract_expr_call(ctx
, document
, node
, expr
);
547 expr
= extract_expr_cast(ctx
, document
, node
, expr
);
550 expr
= extract_expr_int(ctx
, document
, node
, expr
);
553 expr
= extract_expr_op(ctx
, document
, node
, expr
);
560 static struct pet_stmt
*extract_stmt_arguments(isl_ctx
*ctx
,
561 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_stmt
*stmt
)
564 yaml_node_item_t
*item
;
566 if (node
->type
!= YAML_SEQUENCE_NODE
)
567 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
568 return pet_stmt_free(stmt
));
570 stmt
->n_arg
= node
->data
.sequence
.items
.top
571 - node
->data
.sequence
.items
.start
;
572 stmt
->args
= isl_calloc_array(ctx
, struct pet_expr
*, stmt
->n_arg
);
574 return pet_stmt_free(stmt
);
576 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
577 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
580 n
= yaml_document_get_node(document
, *item
);
581 stmt
->args
[i
] = extract_expr(ctx
, document
, n
);
583 return pet_stmt_free(stmt
);
589 static struct pet_stmt
*extract_stmt(isl_ctx
*ctx
, yaml_document_t
*document
,
592 struct pet_stmt
*stmt
;
593 yaml_node_pair_t
* pair
;
595 if (node
->type
!= YAML_MAPPING_NODE
)
596 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
599 stmt
= isl_calloc_type(ctx
, struct pet_stmt
);
603 for (pair
= node
->data
.mapping
.pairs
.start
;
604 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
605 yaml_node_t
*key
, *value
;
607 key
= yaml_document_get_node(document
, pair
->key
);
608 value
= yaml_document_get_node(document
, pair
->value
);
610 if (key
->type
!= YAML_SCALAR_NODE
)
611 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
612 return pet_stmt_free(stmt
));
614 if (!strcmp((char *) key
->data
.scalar
.value
, "line"))
615 stmt
->line
= extract_int(ctx
, document
, value
);
616 if (!strcmp((char *) key
->data
.scalar
.value
, "domain"))
617 stmt
->domain
= extract_set(ctx
, document
, value
);
618 if (!strcmp((char *) key
->data
.scalar
.value
, "schedule"))
619 stmt
->schedule
= extract_map(ctx
, document
, value
);
620 if (!strcmp((char *) key
->data
.scalar
.value
, "body"))
621 stmt
->body
= extract_expr(ctx
, document
, value
);
623 if (!strcmp((char *) key
->data
.scalar
.value
, "arguments"))
624 stmt
= extract_stmt_arguments(ctx
, document
,
633 static struct pet_scop
*extract_statements(isl_ctx
*ctx
,
634 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
637 yaml_node_item_t
*item
;
639 if (node
->type
!= YAML_SEQUENCE_NODE
)
640 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
643 scop
->n_stmt
= node
->data
.sequence
.items
.top
644 - node
->data
.sequence
.items
.start
;
645 scop
->stmts
= isl_calloc_array(ctx
, struct pet_stmt
*, scop
->n_stmt
);
647 return pet_scop_free(scop
);
649 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
650 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
653 n
= yaml_document_get_node(document
, *item
);
654 scop
->stmts
[i
] = extract_stmt(ctx
, document
, n
);
656 return pet_scop_free(scop
);
662 /* Extract a pet_implication from "node".
664 static struct pet_implication
*extract_implication(isl_ctx
*ctx
,
665 yaml_document_t
*document
, yaml_node_t
*node
)
667 struct pet_implication
*implication
;
668 yaml_node_pair_t
* pair
;
670 if (node
->type
!= YAML_MAPPING_NODE
)
671 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
674 implication
= isl_calloc_type(ctx
, struct pet_implication
);
678 for (pair
= node
->data
.mapping
.pairs
.start
;
679 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
680 yaml_node_t
*key
, *value
;
682 key
= yaml_document_get_node(document
, pair
->key
);
683 value
= yaml_document_get_node(document
, pair
->value
);
685 if (key
->type
!= YAML_SCALAR_NODE
)
686 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
687 return pet_implication_free(implication
));
689 if (!strcmp((char *) key
->data
.scalar
.value
, "satisfied"))
690 implication
->satisfied
=
691 extract_int(ctx
, document
, value
);
692 if (!strcmp((char *) key
->data
.scalar
.value
, "extension"))
693 implication
->extension
=
694 extract_map(ctx
, document
, value
);
700 /* Extract a sequence of implications from "node" and
701 * store them in scop->implications.
703 static struct pet_scop
*extract_implications(isl_ctx
*ctx
,
704 yaml_document_t
*document
, yaml_node_t
*node
, struct pet_scop
*scop
)
707 yaml_node_item_t
*item
;
709 if (node
->type
!= YAML_SEQUENCE_NODE
)
710 isl_die(ctx
, isl_error_invalid
, "expecting sequence",
713 scop
->n_implication
= node
->data
.sequence
.items
.top
714 - node
->data
.sequence
.items
.start
;
715 scop
->implications
= isl_calloc_array(ctx
, struct pet_implication
*,
716 scop
->n_implication
);
717 if (!scop
->implications
)
718 return pet_scop_free(scop
);
720 for (item
= node
->data
.sequence
.items
.start
, i
= 0;
721 item
< node
->data
.sequence
.items
.top
; ++item
, ++i
) {
724 n
= yaml_document_get_node(document
, *item
);
725 scop
->implications
[i
] = extract_implication(ctx
, document
, n
);
726 if (!scop
->implications
[i
])
727 return pet_scop_free(scop
);
733 static struct pet_scop
*extract_scop(isl_ctx
*ctx
, yaml_document_t
*document
,
736 struct pet_scop
*scop
;
737 yaml_node_pair_t
* pair
;
742 if (node
->type
!= YAML_MAPPING_NODE
)
743 isl_die(ctx
, isl_error_invalid
, "expecting mapping",
746 scop
= pet_scop_alloc(ctx
);
750 for (pair
= node
->data
.mapping
.pairs
.start
;
751 pair
< node
->data
.mapping
.pairs
.top
; ++pair
) {
752 yaml_node_t
*key
, *value
;
754 key
= yaml_document_get_node(document
, pair
->key
);
755 value
= yaml_document_get_node(document
, pair
->value
);
757 if (key
->type
!= YAML_SCALAR_NODE
)
758 isl_die(ctx
, isl_error_invalid
, "expecting scalar key",
759 return pet_scop_free(scop
));
760 if (!strcmp((char *) key
->data
.scalar
.value
, "context"))
761 scop
->context
= extract_set(ctx
, document
, value
);
762 if (!strcmp((char *) key
->data
.scalar
.value
, "context_value"))
763 scop
->context_value
= extract_set(ctx
, document
, value
);
764 if (!strcmp((char *) key
->data
.scalar
.value
, "types"))
765 scop
= extract_types(ctx
, document
, value
, scop
);
766 if (!strcmp((char *) key
->data
.scalar
.value
, "arrays"))
767 scop
= extract_arrays(ctx
, document
, value
, scop
);
768 if (!strcmp((char *) key
->data
.scalar
.value
, "statements"))
769 scop
= extract_statements(ctx
, document
, value
, scop
);
770 if (!strcmp((char *) key
->data
.scalar
.value
, "implications"))
771 scop
= extract_implications(ctx
, document
, value
, scop
);
776 if (!scop
->context_value
) {
777 isl_space
*space
= isl_space_params_alloc(ctx
, 0);
778 scop
->context_value
= isl_set_universe(space
);
779 if (!scop
->context_value
)
780 return pet_scop_free(scop
);
786 /* Extract a pet_scop from the YAML description in "in".
788 struct pet_scop
*pet_scop_parse(isl_ctx
*ctx
, FILE *in
)
790 struct pet_scop
*scop
= NULL
;
791 yaml_parser_t parser
;
793 yaml_document_t document
= { 0 };
795 yaml_parser_initialize(&parser
);
797 yaml_parser_set_input_file(&parser
, in
);
799 if (!yaml_parser_load(&parser
, &document
))
802 root
= yaml_document_get_root_node(&document
);
804 scop
= extract_scop(ctx
, &document
, root
);
806 yaml_document_delete(&document
);
808 yaml_parser_delete(&parser
);
812 yaml_parser_delete(&parser
);