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
37 #include <isl/union_set.h>
42 #include "scop_yaml.h"
45 static int emit_string(yaml_emitter_t
*emitter
, const char *str
)
49 if (!yaml_scalar_event_initialize(&event
, NULL
, NULL
,
50 (yaml_char_t
*) str
, strlen(str
),
51 1, 1, YAML_PLAIN_SCALAR_STYLE
))
53 if (!yaml_emitter_emit(emitter
, &event
))
59 /* Print the string "name" and the string "str" to "emitter".
61 static int emit_named_string(yaml_emitter_t
*emitter
, const char *name
,
64 if (emit_string(emitter
, name
) < 0)
66 if (emit_string(emitter
, str
) < 0)
71 /* Print the isl_id "id" to "emitter".
73 static int emit_id(yaml_emitter_t
*emitter
, __isl_keep isl_id
*id
)
75 return emit_string(emitter
, isl_id_get_name(id
));
78 /* Print the string "name" and the isl_id "id" to "emitter".
80 static int emit_named_id(yaml_emitter_t
*emitter
, const char *name
,
81 __isl_keep isl_id
*id
)
83 if (emit_string(emitter
, name
) < 0)
85 if (emit_id(emitter
, id
) < 0)
90 static int emit_int(yaml_emitter_t
*emitter
, int i
)
94 snprintf(buffer
, sizeof(buffer
), "%d", i
);
95 return emit_string(emitter
, buffer
);
98 static int emit_named_int(yaml_emitter_t
*emitter
, const char *name
, int i
)
100 if (emit_string(emitter
, name
) < 0)
102 if (emit_int(emitter
, i
) < 0)
107 /* Print the unsigned integer "u" to "emitter".
109 static int emit_unsigned(yaml_emitter_t
*emitter
, unsigned u
)
113 snprintf(buffer
, sizeof(buffer
), "%u", u
);
114 return emit_string(emitter
, buffer
);
117 /* Print the string "name" and the unsigned integer "u" to "emitter".
119 static int emit_named_unsigned(yaml_emitter_t
*emitter
, const char *name
,
122 if (emit_string(emitter
, name
) < 0)
124 if (emit_int(emitter
, u
) < 0)
129 static int emit_double(yaml_emitter_t
*emitter
, double d
)
133 snprintf(buffer
, sizeof(buffer
), "%g", d
);
134 return emit_string(emitter
, buffer
);
137 static int emit_map(yaml_emitter_t
*emitter
, __isl_keep isl_map
*map
)
139 isl_ctx
*ctx
= isl_map_get_ctx(map
);
144 p
= isl_printer_to_str(ctx
);
145 p
= isl_printer_print_map(p
, map
);
146 str
= isl_printer_get_str(p
);
148 r
= emit_string(emitter
, str
);
153 /* Print the isl_val "val" to "emitter".
155 static int emit_val(yaml_emitter_t
*emitter
, __isl_keep isl_val
*val
)
157 isl_ctx
*ctx
= isl_val_get_ctx(val
);
162 p
= isl_printer_to_str(ctx
);
163 p
= isl_printer_print_val(p
, val
);
164 str
= isl_printer_get_str(p
);
166 r
= emit_string(emitter
, str
);
171 /* Print the string "name" and the isl_val "val" to "emitter".
173 static int emit_named_val(yaml_emitter_t
*emitter
, const char *name
,
174 __isl_keep isl_val
*val
)
176 if (emit_string(emitter
, name
) < 0)
178 if (emit_val(emitter
, val
) < 0)
183 static int emit_set(yaml_emitter_t
*emitter
, __isl_keep isl_set
*set
)
185 isl_ctx
*ctx
= isl_set_get_ctx(set
);
190 p
= isl_printer_to_str(ctx
);
191 p
= isl_printer_print_set(p
, set
);
192 str
= isl_printer_get_str(p
);
194 r
= emit_string(emitter
, str
);
199 static int emit_named_set(yaml_emitter_t
*emitter
, const char *name
,
200 __isl_keep isl_set
*set
)
202 if (emit_string(emitter
, name
) < 0)
204 if (emit_set(emitter
, set
) < 0)
209 /* Print the string "name" and the map "map" to "emitter".
211 static int emit_named_map(yaml_emitter_t
*emitter
, const char *name
,
212 __isl_keep isl_map
*map
)
214 if (emit_string(emitter
, name
) < 0)
216 if (emit_map(emitter
, map
) < 0)
221 /* Print the union set "uset" to "emitter".
223 static int emit_union_set(yaml_emitter_t
*emitter
,
224 __isl_keep isl_union_set
*uset
)
226 isl_ctx
*ctx
= isl_union_set_get_ctx(uset
);
231 p
= isl_printer_to_str(ctx
);
232 p
= isl_printer_print_union_set(p
, uset
);
233 str
= isl_printer_get_str(p
);
235 r
= emit_string(emitter
, str
);
240 /* Print the union map "umap" to "emitter".
242 static int emit_union_map(yaml_emitter_t
*emitter
,
243 __isl_keep isl_union_map
*umap
)
245 isl_ctx
*ctx
= isl_union_map_get_ctx(umap
);
250 p
= isl_printer_to_str(ctx
);
251 p
= isl_printer_print_union_map(p
, umap
);
252 str
= isl_printer_get_str(p
);
254 r
= emit_string(emitter
, str
);
259 /* Print the string "name" and the union set "uset" to "emitter".
261 static int emit_named_union_set(yaml_emitter_t
*emitter
, const char *name
,
262 __isl_keep isl_union_set
*uset
)
264 if (emit_string(emitter
, name
) < 0)
266 if (emit_union_set(emitter
, uset
) < 0)
271 /* Print the string "name" and the union map "umap" to "emitter".
273 static int emit_named_union_map(yaml_emitter_t
*emitter
, const char *name
,
274 __isl_keep isl_union_map
*umap
)
276 if (emit_string(emitter
, name
) < 0)
278 if (emit_union_map(emitter
, umap
) < 0)
283 /* Print the isl_multi_pw_aff "mpa" to "emitter".
285 static int emit_multi_pw_aff(yaml_emitter_t
*emitter
,
286 __isl_keep isl_multi_pw_aff
*mpa
)
288 isl_ctx
*ctx
= isl_multi_pw_aff_get_ctx(mpa
);
293 p
= isl_printer_to_str(ctx
);
294 p
= isl_printer_print_multi_pw_aff(p
, mpa
);
295 str
= isl_printer_get_str(p
);
297 r
= emit_string(emitter
, str
);
302 /* Print the string "name" and the isl_multi_pw_aff "mpa" to "emitter".
304 static int emit_named_multi_pw_aff(yaml_emitter_t
*emitter
, const char *name
,
305 __isl_keep isl_multi_pw_aff
*mpa
)
307 if (emit_string(emitter
, name
) < 0)
309 if (emit_multi_pw_aff(emitter
, mpa
) < 0)
314 /* Print the schedule "schedule" to "emitter".
316 static int emit_schedule(yaml_emitter_t
*emitter
,
317 __isl_keep isl_schedule
*schedule
)
319 isl_ctx
*ctx
= isl_schedule_get_ctx(schedule
);
324 p
= isl_printer_to_str(ctx
);
325 p
= isl_printer_print_schedule(p
, schedule
);
326 str
= isl_printer_get_str(p
);
328 r
= emit_string(emitter
, str
);
333 /* Print the string "name" and the schedule "schedule" to "emitter".
335 static int emit_named_schedule(yaml_emitter_t
*emitter
, const char *name
,
336 __isl_keep isl_schedule
*schedule
)
338 if (emit_string(emitter
, name
) < 0)
340 if (emit_schedule(emitter
, schedule
) < 0)
345 /* Print "type" to "emitter".
347 static int emit_type(yaml_emitter_t
*emitter
, struct pet_type
*type
)
351 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
352 YAML_BLOCK_MAPPING_STYLE
))
354 if (!yaml_emitter_emit(emitter
, &event
))
357 if (emit_string(emitter
, "name") < 0)
359 if (emit_string(emitter
, type
->name
) < 0)
362 if (emit_string(emitter
, "definition") < 0)
364 if (emit_string(emitter
, type
->definition
) < 0)
367 if (!yaml_mapping_end_event_initialize(&event
))
369 if (!yaml_emitter_emit(emitter
, &event
))
375 /* Print the list of "n_type" "types", if any, to "emitter".
377 static int emit_types(yaml_emitter_t
*emitter
, int n_type
,
378 struct pet_type
**types
)
386 if (emit_string(emitter
, "types") < 0)
388 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
389 YAML_BLOCK_SEQUENCE_STYLE
))
391 if (!yaml_emitter_emit(emitter
, &event
))
394 for (i
= 0; i
< n_type
; ++i
)
395 if (emit_type(emitter
, types
[i
]) < 0)
398 if (!yaml_sequence_end_event_initialize(&event
))
400 if (!yaml_emitter_emit(emitter
, &event
))
406 static int emit_array(yaml_emitter_t
*emitter
, struct pet_array
*array
)
410 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
411 YAML_BLOCK_MAPPING_STYLE
))
413 if (!yaml_emitter_emit(emitter
, &event
))
416 if (emit_string(emitter
, "context") < 0)
418 if (emit_set(emitter
, array
->context
) < 0)
421 if (emit_string(emitter
, "extent") < 0)
423 if (emit_set(emitter
, array
->extent
) < 0)
426 if (array
->value_bounds
) {
427 if (emit_string(emitter
, "value_bounds") < 0)
429 if (emit_set(emitter
, array
->value_bounds
) < 0)
433 if (emit_string(emitter
, "element_type") < 0)
435 if (emit_string(emitter
, array
->element_type
) < 0)
437 if (emit_named_int(emitter
, "element_size", array
->element_size
) < 0)
440 if (array
->element_is_record
)
441 if (emit_named_int(emitter
, "element_is_record",
442 array
->element_is_record
) < 0)
445 if (array
->live_out
) {
446 if (emit_string(emitter
, "live_out") < 0)
448 if (emit_string(emitter
, "1") < 0)
452 if (array
->uniquely_defined
) {
453 if (emit_string(emitter
, "uniquely_defined") < 0)
455 if (emit_string(emitter
, "1") < 0)
459 if (array
->declared
&& emit_named_int(emitter
, "declared", 1) < 0)
461 if (array
->exposed
&& emit_named_int(emitter
, "exposed", 1) < 0)
464 if (!yaml_mapping_end_event_initialize(&event
))
466 if (!yaml_emitter_emit(emitter
, &event
))
472 static int emit_arrays(yaml_emitter_t
*emitter
, int n_array
,
473 struct pet_array
**arrays
)
478 if (emit_string(emitter
, "arrays") < 0)
480 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
481 YAML_BLOCK_SEQUENCE_STYLE
))
483 if (!yaml_emitter_emit(emitter
, &event
))
486 for (i
= 0; i
< n_array
; ++i
)
487 if (emit_array(emitter
, arrays
[i
]) < 0)
490 if (!yaml_sequence_end_event_initialize(&event
))
492 if (!yaml_emitter_emit(emitter
, &event
))
498 static int emit_expr_type(yaml_emitter_t
*emitter
, enum pet_expr_type type
)
500 if (emit_string(emitter
, pet_type_str(type
)) < 0)
505 /* Print the fields of the access expression "expr" to "emitter".
507 * Only print the access relations that are present and relevant
508 * for the type of access.
510 * If the depth of the access is equal to the depth that can be derived from
511 * the index expression, then there is no need to print it.
513 static int emit_access_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
517 if (expr
->acc
.kill
&& expr
->acc
.access
[pet_expr_access_fake_killed
] &&
518 emit_named_union_map(emitter
, "killed",
519 expr
->acc
.access
[pet_expr_access_fake_killed
]) < 0)
521 if (expr
->acc
.read
&& expr
->acc
.access
[pet_expr_access_may_read
] &&
522 emit_named_union_map(emitter
, "may_read",
523 expr
->acc
.access
[pet_expr_access_may_read
]) < 0)
525 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_may_write
] &&
526 emit_named_union_map(emitter
, "may_write",
527 expr
->acc
.access
[pet_expr_access_may_write
]) < 0)
529 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_must_write
] &&
530 emit_named_union_map(emitter
, "must_write",
531 expr
->acc
.access
[pet_expr_access_must_write
]) < 0)
533 if (emit_named_multi_pw_aff(emitter
, "index", expr
->acc
.index
) < 0)
535 depth
= isl_multi_pw_aff_dim(expr
->acc
.index
, isl_dim_out
);
536 if (expr
->acc
.depth
!= depth
&&
537 emit_named_int(emitter
, "depth", expr
->acc
.depth
) < 0)
539 if (expr
->acc
.ref_id
&&
540 emit_named_id(emitter
, "reference", expr
->acc
.ref_id
) < 0)
542 if (expr
->acc
.kill
) {
543 if (emit_named_unsigned(emitter
, "kill", 1) < 0)
546 if (emit_string(emitter
, "read") < 0)
548 if (emit_int(emitter
, expr
->acc
.read
) < 0)
550 if (emit_string(emitter
, "write") < 0)
552 if (emit_int(emitter
, expr
->acc
.write
) < 0)
559 static int emit_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
563 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
564 YAML_BLOCK_MAPPING_STYLE
))
566 if (!yaml_emitter_emit(emitter
, &event
))
569 if (emit_string(emitter
, "type") < 0)
571 if (emit_expr_type(emitter
, expr
->type
) < 0)
574 switch (expr
->type
) {
578 if (emit_named_val(emitter
, "value", expr
->i
) < 0)
581 case pet_expr_double
:
582 if (emit_string(emitter
, "value") < 0)
584 if (emit_double(emitter
, expr
->d
.val
) < 0)
586 if (emit_string(emitter
, "string") < 0)
588 if (emit_string(emitter
, expr
->d
.s
) < 0)
591 case pet_expr_access
:
592 if (emit_access_expr(emitter
, expr
) < 0)
596 if (emit_string(emitter
, "operation") < 0)
598 if (emit_string(emitter
, pet_op_str(expr
->op
)) < 0)
602 if (emit_string(emitter
, "name") < 0)
604 if (emit_string(emitter
, expr
->c
.name
) < 0)
608 if (emit_string(emitter
, "type_name") < 0)
610 if (emit_string(emitter
, expr
->type_name
) < 0)
615 if (expr
->n_arg
> 0) {
618 if (emit_string(emitter
, "arguments") < 0)
620 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
621 YAML_BLOCK_SEQUENCE_STYLE
))
623 if (!yaml_emitter_emit(emitter
, &event
))
626 for (i
= 0; i
< expr
->n_arg
; ++i
)
627 if (emit_expr(emitter
, expr
->args
[i
]) < 0)
630 if (!yaml_sequence_end_event_initialize(&event
))
632 if (!yaml_emitter_emit(emitter
, &event
))
636 if (!yaml_mapping_end_event_initialize(&event
))
638 if (!yaml_emitter_emit(emitter
, &event
))
644 /* Print the string "name" and the expression "expr" to "emitter".
646 static int emit_named_expr(yaml_emitter_t
*emitter
, const char *name
,
647 __isl_keep pet_expr
*expr
)
649 if (emit_string(emitter
, name
) < 0)
651 if (emit_expr(emitter
, expr
) < 0)
656 /* Print "type" to "emitter".
658 static int emit_tree_type(yaml_emitter_t
*emitter
, enum pet_tree_type type
)
660 if (emit_string(emitter
, pet_tree_type_str(type
)) < 0)
665 /* Recursively print "tree" to "emitter".
667 static int emit_tree(yaml_emitter_t
*emitter
, __isl_keep pet_tree
*tree
)
672 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
673 YAML_BLOCK_MAPPING_STYLE
))
675 if (!yaml_emitter_emit(emitter
, &event
))
678 if (emit_string(emitter
, "type") < 0)
680 if (emit_tree_type(emitter
, tree
->type
) < 0)
683 switch (tree
->type
) {
687 if (emit_named_int(emitter
, "block", tree
->u
.b
.block
) < 0)
689 if (tree
->u
.b
.n
== 0)
692 if (emit_string(emitter
, "children") < 0)
694 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
695 YAML_BLOCK_SEQUENCE_STYLE
))
697 if (!yaml_emitter_emit(emitter
, &event
))
700 for (i
= 0; i
< tree
->u
.b
.n
; ++i
)
701 if (emit_tree(emitter
, tree
->u
.b
.child
[i
]) < 0)
704 if (!yaml_sequence_end_event_initialize(&event
))
706 if (!yaml_emitter_emit(emitter
, &event
))
710 case pet_tree_continue
:
713 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
716 case pet_tree_decl_init
:
717 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
719 if (emit_named_expr(emitter
,
720 "initialization", tree
->u
.d
.init
) < 0)
724 if (emit_named_expr(emitter
, "expr", tree
->u
.e
.expr
) < 0)
728 if (tree
->u
.l
.independent
)
729 if (emit_named_int(emitter
, "independent", 1) < 0)
731 if (emit_named_int(emitter
, "declared", tree
->u
.l
.declared
) < 0)
733 if (emit_named_expr(emitter
, "variable", tree
->u
.l
.iv
) < 0)
735 if (emit_named_expr(emitter
,
736 "initialization", tree
->u
.l
.init
) < 0)
738 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
740 if (emit_named_expr(emitter
, "increment", tree
->u
.l
.inc
) < 0)
742 if (emit_string(emitter
, "body") < 0)
744 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
748 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
750 if (emit_string(emitter
, "body") < 0)
752 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
755 case pet_tree_infinite_loop
:
756 if (emit_string(emitter
, "body") < 0)
758 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
762 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
764 if (emit_string(emitter
, "then") < 0)
766 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
769 case pet_tree_if_else
:
770 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
772 if (emit_string(emitter
, "then") < 0)
774 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
776 if (emit_string(emitter
, "else") < 0)
778 if (emit_tree(emitter
, tree
->u
.i
.else_body
) < 0)
783 if (!yaml_mapping_end_event_initialize(&event
))
785 if (!yaml_emitter_emit(emitter
, &event
))
791 static int emit_stmt(yaml_emitter_t
*emitter
, struct pet_stmt
*stmt
)
795 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
796 YAML_BLOCK_MAPPING_STYLE
))
798 if (!yaml_emitter_emit(emitter
, &event
))
801 if (emit_string(emitter
, "line") < 0)
803 if (emit_int(emitter
, pet_loc_get_line(stmt
->loc
)) < 0)
806 if (emit_string(emitter
, "domain") < 0)
808 if (emit_set(emitter
, stmt
->domain
) < 0)
811 if (emit_string(emitter
, "body") < 0)
813 if (emit_tree(emitter
, stmt
->body
) < 0)
816 if (stmt
->n_arg
> 0) {
819 if (emit_string(emitter
, "arguments") < 0)
821 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
822 YAML_BLOCK_SEQUENCE_STYLE
))
824 if (!yaml_emitter_emit(emitter
, &event
))
827 for (i
= 0; i
< stmt
->n_arg
; ++i
)
828 if (emit_expr(emitter
, stmt
->args
[i
]) < 0)
831 if (!yaml_sequence_end_event_initialize(&event
))
833 if (!yaml_emitter_emit(emitter
, &event
))
837 if (!yaml_mapping_end_event_initialize(&event
))
839 if (!yaml_emitter_emit(emitter
, &event
))
845 static int emit_statements(yaml_emitter_t
*emitter
, int n_stmt
,
846 struct pet_stmt
**stmts
)
851 if (emit_string(emitter
, "statements") < 0)
853 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
854 YAML_BLOCK_SEQUENCE_STYLE
))
856 if (!yaml_emitter_emit(emitter
, &event
))
859 for (i
= 0; i
< n_stmt
; ++i
)
860 if (emit_stmt(emitter
, stmts
[i
]) < 0)
863 if (!yaml_sequence_end_event_initialize(&event
))
865 if (!yaml_emitter_emit(emitter
, &event
))
871 /* Print "implication" to "emitter".
873 static int emit_implication(yaml_emitter_t
*emitter
,
874 struct pet_implication
*implication
)
878 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
879 YAML_BLOCK_MAPPING_STYLE
))
881 if (!yaml_emitter_emit(emitter
, &event
))
884 if (emit_named_int(emitter
, "satisfied", implication
->satisfied
) < 0)
887 if (emit_named_map(emitter
, "extension", implication
->extension
) < 0)
890 if (!yaml_mapping_end_event_initialize(&event
))
892 if (!yaml_emitter_emit(emitter
, &event
))
898 /* Print the list of "n_implication" "implications", if any, to "emitter".
900 static int emit_implications(yaml_emitter_t
*emitter
, int n_implication
,
901 struct pet_implication
**implications
)
906 if (n_implication
== 0)
909 if (emit_string(emitter
, "implications") < 0)
911 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
912 YAML_BLOCK_SEQUENCE_STYLE
))
914 if (!yaml_emitter_emit(emitter
, &event
))
917 for (i
= 0; i
< n_implication
; ++i
)
918 if (emit_implication(emitter
, implications
[i
]) < 0)
921 if (!yaml_sequence_end_event_initialize(&event
))
923 if (!yaml_emitter_emit(emitter
, &event
))
929 /* Print "independence" to "emitter".
931 static int emit_independence(yaml_emitter_t
*emitter
,
932 struct pet_independence
*independence
)
936 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
937 YAML_BLOCK_MAPPING_STYLE
))
939 if (!yaml_emitter_emit(emitter
, &event
))
942 if (emit_named_union_map(emitter
, "filter", independence
->filter
) < 0)
945 if (emit_named_union_set(emitter
, "local", independence
->local
) < 0)
948 if (!yaml_mapping_end_event_initialize(&event
))
950 if (!yaml_emitter_emit(emitter
, &event
))
956 /* Print the list of "n_independence" "independences", if any, to "emitter".
958 static int emit_independences(yaml_emitter_t
*emitter
, int n_independence
,
959 struct pet_independence
**independences
)
964 if (n_independence
== 0)
967 if (emit_string(emitter
, "independences") < 0)
969 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
970 YAML_BLOCK_SEQUENCE_STYLE
))
972 if (!yaml_emitter_emit(emitter
, &event
))
975 for (i
= 0; i
< n_independence
; ++i
)
976 if (emit_independence(emitter
, independences
[i
]) < 0)
979 if (!yaml_sequence_end_event_initialize(&event
))
981 if (!yaml_emitter_emit(emitter
, &event
))
987 static int emit_scop(yaml_emitter_t
*emitter
, struct pet_scop
*scop
)
991 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
992 YAML_BLOCK_MAPPING_STYLE
))
994 if (!yaml_emitter_emit(emitter
, &event
))
997 if (emit_named_unsigned(emitter
,
998 "start", pet_loc_get_start(scop
->loc
)) < 0)
1000 if (emit_named_unsigned(emitter
, "end", pet_loc_get_end(scop
->loc
)) < 0)
1002 if (emit_named_string(emitter
,
1003 "indent", pet_loc_get_indent(scop
->loc
)) < 0)
1005 if (emit_string(emitter
, "context") < 0)
1007 if (emit_set(emitter
, scop
->context
) < 0)
1009 if (!isl_set_plain_is_universe(scop
->context_value
) &&
1010 emit_named_set(emitter
, "context_value", scop
->context_value
) < 0)
1012 if (emit_named_schedule(emitter
, "schedule", scop
->schedule
) < 0)
1015 if (emit_types(emitter
, scop
->n_type
, scop
->types
) < 0)
1017 if (emit_arrays(emitter
, scop
->n_array
, scop
->arrays
) < 0)
1020 if (emit_statements(emitter
, scop
->n_stmt
, scop
->stmts
) < 0)
1023 if (emit_implications(emitter
, scop
->n_implication
,
1024 scop
->implications
) < 0)
1027 if (emit_independences(emitter
, scop
->n_independence
,
1028 scop
->independences
) < 0)
1031 if (!yaml_mapping_end_event_initialize(&event
))
1033 if (!yaml_emitter_emit(emitter
, &event
))
1039 /* Print a YAML serialization of "scop" to "out".
1041 int pet_scop_emit(FILE *out
, struct pet_scop
*scop
)
1043 yaml_emitter_t emitter
;
1046 yaml_emitter_initialize(&emitter
);
1048 yaml_emitter_set_output_file(&emitter
, out
);
1050 yaml_stream_start_event_initialize(&event
, YAML_UTF8_ENCODING
);
1051 if (!yaml_emitter_emit(&emitter
, &event
))
1054 if (!yaml_document_start_event_initialize(&event
, NULL
, NULL
, NULL
, 1))
1056 if (!yaml_emitter_emit(&emitter
, &event
))
1059 if (emit_scop(&emitter
, scop
) < 0)
1062 if (!yaml_document_end_event_initialize(&event
, 1))
1064 if (!yaml_emitter_emit(&emitter
, &event
))
1067 yaml_stream_end_event_initialize(&event
);
1068 if (!yaml_emitter_emit(&emitter
, &event
))
1071 yaml_emitter_delete(&emitter
);
1074 yaml_emitter_delete(&emitter
);