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
40 #include "scop_yaml.h"
43 static int emit_string(yaml_emitter_t
*emitter
, const char *str
)
47 if (!yaml_scalar_event_initialize(&event
, NULL
, NULL
,
48 (yaml_char_t
*) str
, strlen(str
),
49 1, 1, YAML_PLAIN_SCALAR_STYLE
))
51 if (!yaml_emitter_emit(emitter
, &event
))
57 /* Print the string "name" and the string "str" to "emitter".
59 static int emit_named_string(yaml_emitter_t
*emitter
, const char *name
,
62 if (emit_string(emitter
, name
) < 0)
64 if (emit_string(emitter
, str
) < 0)
69 /* Print the isl_id "id" to "emitter".
71 static int emit_id(yaml_emitter_t
*emitter
, __isl_keep isl_id
*id
)
73 return emit_string(emitter
, isl_id_get_name(id
));
76 /* Print the string "name" and the isl_id "id" to "emitter".
78 static int emit_named_id(yaml_emitter_t
*emitter
, const char *name
,
79 __isl_keep isl_id
*id
)
81 if (emit_string(emitter
, name
) < 0)
83 if (emit_id(emitter
, id
) < 0)
88 static int emit_int(yaml_emitter_t
*emitter
, int i
)
92 snprintf(buffer
, sizeof(buffer
), "%d", i
);
93 return emit_string(emitter
, buffer
);
96 static int emit_named_int(yaml_emitter_t
*emitter
, const char *name
, int i
)
98 if (emit_string(emitter
, name
) < 0)
100 if (emit_int(emitter
, i
) < 0)
105 /* Print the unsigned integer "u" to "emitter".
107 static int emit_unsigned(yaml_emitter_t
*emitter
, unsigned u
)
111 snprintf(buffer
, sizeof(buffer
), "%u", u
);
112 return emit_string(emitter
, buffer
);
115 /* Print the string "name" and the unsigned integer "u" to "emitter".
117 static int emit_named_unsigned(yaml_emitter_t
*emitter
, const char *name
,
120 if (emit_string(emitter
, name
) < 0)
122 if (emit_int(emitter
, u
) < 0)
127 static int emit_double(yaml_emitter_t
*emitter
, double d
)
131 snprintf(buffer
, sizeof(buffer
), "%g", d
);
132 return emit_string(emitter
, buffer
);
135 static int emit_map(yaml_emitter_t
*emitter
, __isl_keep isl_map
*map
)
137 isl_ctx
*ctx
= isl_map_get_ctx(map
);
142 p
= isl_printer_to_str(ctx
);
143 p
= isl_printer_print_map(p
, map
);
144 str
= isl_printer_get_str(p
);
146 r
= emit_string(emitter
, str
);
151 /* Print the isl_val "val" to "emitter".
153 static int emit_val(yaml_emitter_t
*emitter
, __isl_keep isl_val
*val
)
155 isl_ctx
*ctx
= isl_val_get_ctx(val
);
160 p
= isl_printer_to_str(ctx
);
161 p
= isl_printer_print_val(p
, val
);
162 str
= isl_printer_get_str(p
);
164 r
= emit_string(emitter
, str
);
169 /* Print the string "name" and the isl_val "val" to "emitter".
171 static int emit_named_val(yaml_emitter_t
*emitter
, const char *name
,
172 __isl_keep isl_val
*val
)
174 if (emit_string(emitter
, name
) < 0)
176 if (emit_val(emitter
, val
) < 0)
181 static int emit_set(yaml_emitter_t
*emitter
, __isl_keep isl_set
*set
)
183 isl_ctx
*ctx
= isl_set_get_ctx(set
);
188 p
= isl_printer_to_str(ctx
);
189 p
= isl_printer_print_set(p
, set
);
190 str
= isl_printer_get_str(p
);
192 r
= emit_string(emitter
, str
);
197 static int emit_named_set(yaml_emitter_t
*emitter
, const char *name
,
198 __isl_keep isl_set
*set
)
200 if (emit_string(emitter
, name
) < 0)
202 if (emit_set(emitter
, set
) < 0)
207 /* Print the string "name" and the map "map" to "emitter".
209 static int emit_named_map(yaml_emitter_t
*emitter
, const char *name
,
210 __isl_keep isl_map
*map
)
212 if (emit_string(emitter
, name
) < 0)
214 if (emit_map(emitter
, map
) < 0)
219 /* Print the union set "uset" to "emitter".
221 static int emit_union_set(yaml_emitter_t
*emitter
,
222 __isl_keep isl_union_set
*uset
)
224 isl_ctx
*ctx
= isl_union_set_get_ctx(uset
);
229 p
= isl_printer_to_str(ctx
);
230 p
= isl_printer_print_union_set(p
, uset
);
231 str
= isl_printer_get_str(p
);
233 r
= emit_string(emitter
, str
);
238 /* Print the union map "umap" to "emitter".
240 static int emit_union_map(yaml_emitter_t
*emitter
,
241 __isl_keep isl_union_map
*umap
)
243 isl_ctx
*ctx
= isl_union_map_get_ctx(umap
);
248 p
= isl_printer_to_str(ctx
);
249 p
= isl_printer_print_union_map(p
, umap
);
250 str
= isl_printer_get_str(p
);
252 r
= emit_string(emitter
, str
);
257 /* Print the string "name" and the union set "uset" to "emitter".
259 static int emit_named_union_set(yaml_emitter_t
*emitter
, const char *name
,
260 __isl_keep isl_union_set
*uset
)
262 if (emit_string(emitter
, name
) < 0)
264 if (emit_union_set(emitter
, uset
) < 0)
269 /* Print the string "name" and the union map "umap" to "emitter".
271 static int emit_named_union_map(yaml_emitter_t
*emitter
, const char *name
,
272 __isl_keep isl_union_map
*umap
)
274 if (emit_string(emitter
, name
) < 0)
276 if (emit_union_map(emitter
, umap
) < 0)
281 /* Print the isl_multi_pw_aff "mpa" to "emitter".
283 static int emit_multi_pw_aff(yaml_emitter_t
*emitter
,
284 __isl_keep isl_multi_pw_aff
*mpa
)
286 isl_ctx
*ctx
= isl_multi_pw_aff_get_ctx(mpa
);
291 p
= isl_printer_to_str(ctx
);
292 p
= isl_printer_print_multi_pw_aff(p
, mpa
);
293 str
= isl_printer_get_str(p
);
295 r
= emit_string(emitter
, str
);
300 /* Print the string "name" and the isl_multi_pw_aff "mpa" to "emitter".
302 static int emit_named_multi_pw_aff(yaml_emitter_t
*emitter
, const char *name
,
303 __isl_keep isl_multi_pw_aff
*mpa
)
305 if (emit_string(emitter
, name
) < 0)
307 if (emit_multi_pw_aff(emitter
, mpa
) < 0)
312 /* Print the schedule "schedule" to "emitter".
314 static int emit_schedule(yaml_emitter_t
*emitter
,
315 __isl_keep isl_schedule
*schedule
)
317 isl_ctx
*ctx
= isl_schedule_get_ctx(schedule
);
322 p
= isl_printer_to_str(ctx
);
323 p
= isl_printer_print_schedule(p
, schedule
);
324 str
= isl_printer_get_str(p
);
326 r
= emit_string(emitter
, str
);
331 /* Print the string "name" and the schedule "schedule" to "emitter".
333 static int emit_named_schedule(yaml_emitter_t
*emitter
, const char *name
,
334 __isl_keep isl_schedule
*schedule
)
336 if (emit_string(emitter
, name
) < 0)
338 if (emit_schedule(emitter
, schedule
) < 0)
343 /* Print "type" to "emitter".
345 static int emit_type(yaml_emitter_t
*emitter
, struct pet_type
*type
)
349 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
350 YAML_BLOCK_MAPPING_STYLE
))
352 if (!yaml_emitter_emit(emitter
, &event
))
355 if (emit_string(emitter
, "name") < 0)
357 if (emit_string(emitter
, type
->name
) < 0)
360 if (emit_string(emitter
, "definition") < 0)
362 if (emit_string(emitter
, type
->definition
) < 0)
365 if (!yaml_mapping_end_event_initialize(&event
))
367 if (!yaml_emitter_emit(emitter
, &event
))
373 /* Print the list of "n_type" "types", if any, to "emitter".
375 static int emit_types(yaml_emitter_t
*emitter
, int n_type
,
376 struct pet_type
**types
)
384 if (emit_string(emitter
, "types") < 0)
386 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
387 YAML_BLOCK_SEQUENCE_STYLE
))
389 if (!yaml_emitter_emit(emitter
, &event
))
392 for (i
= 0; i
< n_type
; ++i
)
393 if (emit_type(emitter
, types
[i
]) < 0)
396 if (!yaml_sequence_end_event_initialize(&event
))
398 if (!yaml_emitter_emit(emitter
, &event
))
404 static int emit_array(yaml_emitter_t
*emitter
, struct pet_array
*array
)
408 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
409 YAML_BLOCK_MAPPING_STYLE
))
411 if (!yaml_emitter_emit(emitter
, &event
))
414 if (emit_string(emitter
, "context") < 0)
416 if (emit_set(emitter
, array
->context
) < 0)
419 if (emit_string(emitter
, "extent") < 0)
421 if (emit_set(emitter
, array
->extent
) < 0)
424 if (array
->value_bounds
) {
425 if (emit_string(emitter
, "value_bounds") < 0)
427 if (emit_set(emitter
, array
->value_bounds
) < 0)
431 if (emit_string(emitter
, "element_type") < 0)
433 if (emit_string(emitter
, array
->element_type
) < 0)
435 if (emit_named_int(emitter
, "element_size", array
->element_size
) < 0)
438 if (array
->element_is_record
)
439 if (emit_named_int(emitter
, "element_is_record",
440 array
->element_is_record
) < 0)
443 if (array
->live_out
) {
444 if (emit_string(emitter
, "live_out") < 0)
446 if (emit_string(emitter
, "1") < 0)
450 if (array
->uniquely_defined
) {
451 if (emit_string(emitter
, "uniquely_defined") < 0)
453 if (emit_string(emitter
, "1") < 0)
457 if (array
->declared
&& emit_named_int(emitter
, "declared", 1) < 0)
459 if (array
->exposed
&& emit_named_int(emitter
, "exposed", 1) < 0)
462 if (!yaml_mapping_end_event_initialize(&event
))
464 if (!yaml_emitter_emit(emitter
, &event
))
470 static int emit_arrays(yaml_emitter_t
*emitter
, int n_array
,
471 struct pet_array
**arrays
)
476 if (emit_string(emitter
, "arrays") < 0)
478 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
479 YAML_BLOCK_SEQUENCE_STYLE
))
481 if (!yaml_emitter_emit(emitter
, &event
))
484 for (i
= 0; i
< n_array
; ++i
)
485 if (emit_array(emitter
, arrays
[i
]) < 0)
488 if (!yaml_sequence_end_event_initialize(&event
))
490 if (!yaml_emitter_emit(emitter
, &event
))
496 static int emit_expr_type(yaml_emitter_t
*emitter
, enum pet_expr_type type
)
498 if (emit_string(emitter
, pet_type_str(type
)) < 0)
503 /* Print the fields of the access expression "expr" to "emitter".
505 * Only print the access relations that are present and relevant
506 * for the type of access.
508 * If the depth of the access is equal to the depth that can be derived from
509 * the index expression, then there is no need to print it.
511 static int emit_access_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
515 if (expr
->acc
.kill
&& expr
->acc
.access
[pet_expr_access_fake_killed
] &&
516 emit_named_union_map(emitter
, "killed",
517 expr
->acc
.access
[pet_expr_access_fake_killed
]) < 0)
519 if (expr
->acc
.read
&& expr
->acc
.access
[pet_expr_access_may_read
] &&
520 emit_named_union_map(emitter
, "may_read",
521 expr
->acc
.access
[pet_expr_access_may_read
]) < 0)
523 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_may_write
] &&
524 emit_named_union_map(emitter
, "may_write",
525 expr
->acc
.access
[pet_expr_access_may_write
]) < 0)
527 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_must_write
] &&
528 emit_named_union_map(emitter
, "must_write",
529 expr
->acc
.access
[pet_expr_access_must_write
]) < 0)
531 if (emit_named_multi_pw_aff(emitter
, "index", expr
->acc
.index
) < 0)
533 depth
= isl_multi_pw_aff_dim(expr
->acc
.index
, isl_dim_out
);
534 if (expr
->acc
.depth
!= depth
&&
535 emit_named_int(emitter
, "depth", expr
->acc
.depth
) < 0)
537 if (expr
->acc
.ref_id
&&
538 emit_named_id(emitter
, "reference", expr
->acc
.ref_id
) < 0)
540 if (expr
->acc
.kill
) {
541 if (emit_named_unsigned(emitter
, "kill", 1) < 0)
544 if (emit_string(emitter
, "read") < 0)
546 if (emit_int(emitter
, expr
->acc
.read
) < 0)
548 if (emit_string(emitter
, "write") < 0)
550 if (emit_int(emitter
, expr
->acc
.write
) < 0)
557 static int emit_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
561 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
562 YAML_BLOCK_MAPPING_STYLE
))
564 if (!yaml_emitter_emit(emitter
, &event
))
567 if (emit_string(emitter
, "type") < 0)
569 if (emit_expr_type(emitter
, expr
->type
) < 0)
572 switch (expr
->type
) {
576 if (emit_named_val(emitter
, "value", expr
->i
) < 0)
579 case pet_expr_double
:
580 if (emit_string(emitter
, "value") < 0)
582 if (emit_double(emitter
, expr
->d
.val
) < 0)
584 if (emit_string(emitter
, "string") < 0)
586 if (emit_string(emitter
, expr
->d
.s
) < 0)
589 case pet_expr_access
:
590 if (emit_access_expr(emitter
, expr
) < 0)
594 if (emit_string(emitter
, "operation") < 0)
596 if (emit_string(emitter
, pet_op_str(expr
->op
)) < 0)
600 if (emit_string(emitter
, "name") < 0)
602 if (emit_string(emitter
, expr
->c
.name
) < 0)
606 if (emit_string(emitter
, "type_name") < 0)
608 if (emit_string(emitter
, expr
->type_name
) < 0)
613 if (expr
->n_arg
> 0) {
616 if (emit_string(emitter
, "arguments") < 0)
618 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
619 YAML_BLOCK_SEQUENCE_STYLE
))
621 if (!yaml_emitter_emit(emitter
, &event
))
624 for (i
= 0; i
< expr
->n_arg
; ++i
)
625 if (emit_expr(emitter
, expr
->args
[i
]) < 0)
628 if (!yaml_sequence_end_event_initialize(&event
))
630 if (!yaml_emitter_emit(emitter
, &event
))
634 if (!yaml_mapping_end_event_initialize(&event
))
636 if (!yaml_emitter_emit(emitter
, &event
))
642 /* Print the string "name" and the expression "expr" to "emitter".
644 static int emit_named_expr(yaml_emitter_t
*emitter
, const char *name
,
645 __isl_keep pet_expr
*expr
)
647 if (emit_string(emitter
, name
) < 0)
649 if (emit_expr(emitter
, expr
) < 0)
654 /* Print "type" to "emitter".
656 static int emit_tree_type(yaml_emitter_t
*emitter
, enum pet_tree_type type
)
658 if (emit_string(emitter
, pet_tree_type_str(type
)) < 0)
663 /* Recursively print "tree" to "emitter".
665 static int emit_tree(yaml_emitter_t
*emitter
, __isl_keep pet_tree
*tree
)
670 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
671 YAML_BLOCK_MAPPING_STYLE
))
673 if (!yaml_emitter_emit(emitter
, &event
))
676 if (emit_string(emitter
, "type") < 0)
678 if (emit_tree_type(emitter
, tree
->type
) < 0)
681 switch (tree
->type
) {
685 if (emit_named_int(emitter
, "block", tree
->u
.b
.block
) < 0)
687 if (tree
->u
.b
.n
== 0)
690 if (emit_string(emitter
, "children") < 0)
692 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
693 YAML_BLOCK_SEQUENCE_STYLE
))
695 if (!yaml_emitter_emit(emitter
, &event
))
698 for (i
= 0; i
< tree
->u
.b
.n
; ++i
)
699 if (emit_tree(emitter
, tree
->u
.b
.child
[i
]) < 0)
702 if (!yaml_sequence_end_event_initialize(&event
))
704 if (!yaml_emitter_emit(emitter
, &event
))
708 case pet_tree_continue
:
711 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
714 case pet_tree_decl_init
:
715 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
717 if (emit_named_expr(emitter
,
718 "initialization", tree
->u
.d
.init
) < 0)
722 if (emit_named_expr(emitter
, "expr", tree
->u
.e
.expr
) < 0)
726 if (tree
->u
.l
.independent
)
727 if (emit_named_int(emitter
, "independent", 1) < 0)
729 if (emit_named_int(emitter
, "declared", tree
->u
.l
.declared
) < 0)
731 if (emit_named_expr(emitter
, "variable", tree
->u
.l
.iv
) < 0)
733 if (emit_named_expr(emitter
,
734 "initialization", tree
->u
.l
.init
) < 0)
736 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
738 if (emit_named_expr(emitter
, "increment", tree
->u
.l
.inc
) < 0)
740 if (emit_string(emitter
, "body") < 0)
742 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
746 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
748 if (emit_string(emitter
, "body") < 0)
750 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
753 case pet_tree_infinite_loop
:
754 if (emit_string(emitter
, "body") < 0)
756 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
760 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
762 if (emit_string(emitter
, "then") < 0)
764 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
767 case pet_tree_if_else
:
768 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
770 if (emit_string(emitter
, "then") < 0)
772 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
774 if (emit_string(emitter
, "else") < 0)
776 if (emit_tree(emitter
, tree
->u
.i
.else_body
) < 0)
781 if (!yaml_mapping_end_event_initialize(&event
))
783 if (!yaml_emitter_emit(emitter
, &event
))
789 static int emit_stmt(yaml_emitter_t
*emitter
, struct pet_stmt
*stmt
)
793 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
794 YAML_BLOCK_MAPPING_STYLE
))
796 if (!yaml_emitter_emit(emitter
, &event
))
799 if (emit_string(emitter
, "line") < 0)
801 if (emit_int(emitter
, pet_loc_get_line(stmt
->loc
)) < 0)
804 if (emit_string(emitter
, "domain") < 0)
806 if (emit_set(emitter
, stmt
->domain
) < 0)
809 if (emit_string(emitter
, "body") < 0)
811 if (emit_tree(emitter
, stmt
->body
) < 0)
814 if (stmt
->n_arg
> 0) {
817 if (emit_string(emitter
, "arguments") < 0)
819 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
820 YAML_BLOCK_SEQUENCE_STYLE
))
822 if (!yaml_emitter_emit(emitter
, &event
))
825 for (i
= 0; i
< stmt
->n_arg
; ++i
)
826 if (emit_expr(emitter
, stmt
->args
[i
]) < 0)
829 if (!yaml_sequence_end_event_initialize(&event
))
831 if (!yaml_emitter_emit(emitter
, &event
))
835 if (!yaml_mapping_end_event_initialize(&event
))
837 if (!yaml_emitter_emit(emitter
, &event
))
843 static int emit_statements(yaml_emitter_t
*emitter
, int n_stmt
,
844 struct pet_stmt
**stmts
)
849 if (emit_string(emitter
, "statements") < 0)
851 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
852 YAML_BLOCK_SEQUENCE_STYLE
))
854 if (!yaml_emitter_emit(emitter
, &event
))
857 for (i
= 0; i
< n_stmt
; ++i
)
858 if (emit_stmt(emitter
, stmts
[i
]) < 0)
861 if (!yaml_sequence_end_event_initialize(&event
))
863 if (!yaml_emitter_emit(emitter
, &event
))
869 /* Print "implication" to "emitter".
871 static int emit_implication(yaml_emitter_t
*emitter
,
872 struct pet_implication
*implication
)
876 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
877 YAML_BLOCK_MAPPING_STYLE
))
879 if (!yaml_emitter_emit(emitter
, &event
))
882 if (emit_named_int(emitter
, "satisfied", implication
->satisfied
) < 0)
885 if (emit_named_map(emitter
, "extension", implication
->extension
) < 0)
888 if (!yaml_mapping_end_event_initialize(&event
))
890 if (!yaml_emitter_emit(emitter
, &event
))
896 /* Print the list of "n_implication" "implications", if any, to "emitter".
898 static int emit_implications(yaml_emitter_t
*emitter
, int n_implication
,
899 struct pet_implication
**implications
)
904 if (n_implication
== 0)
907 if (emit_string(emitter
, "implications") < 0)
909 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
910 YAML_BLOCK_SEQUENCE_STYLE
))
912 if (!yaml_emitter_emit(emitter
, &event
))
915 for (i
= 0; i
< n_implication
; ++i
)
916 if (emit_implication(emitter
, implications
[i
]) < 0)
919 if (!yaml_sequence_end_event_initialize(&event
))
921 if (!yaml_emitter_emit(emitter
, &event
))
927 /* Print "independence" to "emitter".
929 static int emit_independence(yaml_emitter_t
*emitter
,
930 struct pet_independence
*independence
)
934 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
935 YAML_BLOCK_MAPPING_STYLE
))
937 if (!yaml_emitter_emit(emitter
, &event
))
940 if (emit_named_union_map(emitter
, "filter", independence
->filter
) < 0)
943 if (emit_named_union_set(emitter
, "local", independence
->local
) < 0)
946 if (!yaml_mapping_end_event_initialize(&event
))
948 if (!yaml_emitter_emit(emitter
, &event
))
954 /* Print the list of "n_independence" "independences", if any, to "emitter".
956 static int emit_independences(yaml_emitter_t
*emitter
, int n_independence
,
957 struct pet_independence
**independences
)
962 if (n_independence
== 0)
965 if (emit_string(emitter
, "independences") < 0)
967 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
968 YAML_BLOCK_SEQUENCE_STYLE
))
970 if (!yaml_emitter_emit(emitter
, &event
))
973 for (i
= 0; i
< n_independence
; ++i
)
974 if (emit_independence(emitter
, independences
[i
]) < 0)
977 if (!yaml_sequence_end_event_initialize(&event
))
979 if (!yaml_emitter_emit(emitter
, &event
))
985 static int emit_scop(yaml_emitter_t
*emitter
, struct pet_scop
*scop
)
989 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
990 YAML_BLOCK_MAPPING_STYLE
))
992 if (!yaml_emitter_emit(emitter
, &event
))
995 if (emit_named_unsigned(emitter
,
996 "start", pet_loc_get_start(scop
->loc
)) < 0)
998 if (emit_named_unsigned(emitter
, "end", pet_loc_get_end(scop
->loc
)) < 0)
1000 if (emit_named_string(emitter
,
1001 "indent", pet_loc_get_indent(scop
->loc
)) < 0)
1003 if (emit_string(emitter
, "context") < 0)
1005 if (emit_set(emitter
, scop
->context
) < 0)
1007 if (!isl_set_plain_is_universe(scop
->context_value
) &&
1008 emit_named_set(emitter
, "context_value", scop
->context_value
) < 0)
1010 if (emit_named_schedule(emitter
, "schedule", scop
->schedule
) < 0)
1013 if (emit_types(emitter
, scop
->n_type
, scop
->types
) < 0)
1015 if (emit_arrays(emitter
, scop
->n_array
, scop
->arrays
) < 0)
1018 if (emit_statements(emitter
, scop
->n_stmt
, scop
->stmts
) < 0)
1021 if (emit_implications(emitter
, scop
->n_implication
,
1022 scop
->implications
) < 0)
1025 if (emit_independences(emitter
, scop
->n_independence
,
1026 scop
->independences
) < 0)
1029 if (!yaml_mapping_end_event_initialize(&event
))
1031 if (!yaml_emitter_emit(emitter
, &event
))
1037 /* Print a YAML serialization of "scop" to "out".
1039 int pet_scop_emit(FILE *out
, struct pet_scop
*scop
)
1041 yaml_emitter_t emitter
;
1044 yaml_emitter_initialize(&emitter
);
1046 yaml_emitter_set_output_file(&emitter
, out
);
1048 yaml_stream_start_event_initialize(&event
, YAML_UTF8_ENCODING
);
1049 if (!yaml_emitter_emit(&emitter
, &event
))
1052 if (!yaml_document_start_event_initialize(&event
, NULL
, NULL
, NULL
, 1))
1054 if (!yaml_emitter_emit(&emitter
, &event
))
1057 if (emit_scop(&emitter
, scop
) < 0)
1060 if (!yaml_document_end_event_initialize(&event
, 1))
1062 if (!yaml_emitter_emit(&emitter
, &event
))
1065 yaml_stream_end_event_initialize(&event
);
1066 if (!yaml_emitter_emit(&emitter
, &event
))
1069 yaml_emitter_delete(&emitter
);
1072 yaml_emitter_delete(&emitter
);