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
42 #include <isl/union_set.h>
43 #include <isl/union_map.h>
44 #include <isl/schedule.h>
45 #include <isl/printer.h>
50 #include "scop_yaml.h"
53 static int emit_string(yaml_emitter_t
*emitter
, const char *str
)
57 if (!yaml_scalar_event_initialize(&event
, NULL
, NULL
,
58 (yaml_char_t
*) str
, strlen(str
),
59 1, 1, YAML_PLAIN_SCALAR_STYLE
))
61 if (!yaml_emitter_emit(emitter
, &event
))
67 /* Print the string "name" and the string "str" to "emitter".
69 static int emit_named_string(yaml_emitter_t
*emitter
, const char *name
,
72 if (emit_string(emitter
, name
) < 0)
74 if (emit_string(emitter
, str
) < 0)
79 /* Print the isl_id "id" to "emitter".
81 static int emit_id(yaml_emitter_t
*emitter
, __isl_keep isl_id
*id
)
83 return emit_string(emitter
, isl_id_get_name(id
));
86 /* Print the string "name" and the isl_id "id" to "emitter".
88 static int emit_named_id(yaml_emitter_t
*emitter
, const char *name
,
89 __isl_keep isl_id
*id
)
91 if (emit_string(emitter
, name
) < 0)
93 if (emit_id(emitter
, id
) < 0)
98 static int emit_int(yaml_emitter_t
*emitter
, int i
)
102 snprintf(buffer
, sizeof(buffer
), "%d", i
);
103 return emit_string(emitter
, buffer
);
106 static int emit_named_int(yaml_emitter_t
*emitter
, const char *name
, int i
)
108 if (emit_string(emitter
, name
) < 0)
110 if (emit_int(emitter
, i
) < 0)
115 /* Print the unsigned integer "u" to "emitter".
117 static int emit_unsigned(yaml_emitter_t
*emitter
, unsigned u
)
121 snprintf(buffer
, sizeof(buffer
), "%u", u
);
122 return emit_string(emitter
, buffer
);
125 /* Print the string "name" and the unsigned integer "u" to "emitter".
127 static int emit_named_unsigned(yaml_emitter_t
*emitter
, const char *name
,
130 if (emit_string(emitter
, name
) < 0)
132 if (emit_unsigned(emitter
, u
) < 0)
137 static int emit_double(yaml_emitter_t
*emitter
, double d
)
141 snprintf(buffer
, sizeof(buffer
), "%g", d
);
142 return emit_string(emitter
, buffer
);
145 static int emit_map(yaml_emitter_t
*emitter
, __isl_keep isl_map
*map
)
147 isl_ctx
*ctx
= isl_map_get_ctx(map
);
152 p
= isl_printer_to_str(ctx
);
153 p
= isl_printer_print_map(p
, map
);
154 str
= isl_printer_get_str(p
);
156 r
= emit_string(emitter
, str
);
161 /* Print the isl_val "val" to "emitter".
163 static int emit_val(yaml_emitter_t
*emitter
, __isl_keep isl_val
*val
)
165 isl_ctx
*ctx
= isl_val_get_ctx(val
);
170 p
= isl_printer_to_str(ctx
);
171 p
= isl_printer_print_val(p
, val
);
172 str
= isl_printer_get_str(p
);
174 r
= emit_string(emitter
, str
);
179 /* Print the string "name" and the isl_val "val" to "emitter".
181 static int emit_named_val(yaml_emitter_t
*emitter
, const char *name
,
182 __isl_keep isl_val
*val
)
184 if (emit_string(emitter
, name
) < 0)
186 if (emit_val(emitter
, val
) < 0)
191 static int emit_set(yaml_emitter_t
*emitter
, __isl_keep isl_set
*set
)
193 isl_ctx
*ctx
= isl_set_get_ctx(set
);
198 p
= isl_printer_to_str(ctx
);
199 p
= isl_printer_print_set(p
, set
);
200 str
= isl_printer_get_str(p
);
202 r
= emit_string(emitter
, str
);
207 static int emit_named_set(yaml_emitter_t
*emitter
, const char *name
,
208 __isl_keep isl_set
*set
)
210 if (emit_string(emitter
, name
) < 0)
212 if (emit_set(emitter
, set
) < 0)
217 /* Print the string "name" and the map "map" to "emitter".
219 static int emit_named_map(yaml_emitter_t
*emitter
, const char *name
,
220 __isl_keep isl_map
*map
)
222 if (emit_string(emitter
, name
) < 0)
224 if (emit_map(emitter
, map
) < 0)
229 /* Print the union set "uset" to "emitter".
231 static int emit_union_set(yaml_emitter_t
*emitter
,
232 __isl_keep isl_union_set
*uset
)
234 isl_ctx
*ctx
= isl_union_set_get_ctx(uset
);
239 p
= isl_printer_to_str(ctx
);
240 p
= isl_printer_print_union_set(p
, uset
);
241 str
= isl_printer_get_str(p
);
243 r
= emit_string(emitter
, str
);
248 /* Print the union map "umap" to "emitter".
250 static int emit_union_map(yaml_emitter_t
*emitter
,
251 __isl_keep isl_union_map
*umap
)
253 isl_ctx
*ctx
= isl_union_map_get_ctx(umap
);
258 p
= isl_printer_to_str(ctx
);
259 p
= isl_printer_print_union_map(p
, umap
);
260 str
= isl_printer_get_str(p
);
262 r
= emit_string(emitter
, str
);
267 /* Print the string "name" and the union set "uset" to "emitter".
269 static int emit_named_union_set(yaml_emitter_t
*emitter
, const char *name
,
270 __isl_keep isl_union_set
*uset
)
272 if (emit_string(emitter
, name
) < 0)
274 if (emit_union_set(emitter
, uset
) < 0)
279 /* Print the string "name" and the union map "umap" to "emitter".
281 static int emit_named_union_map(yaml_emitter_t
*emitter
, const char *name
,
282 __isl_keep isl_union_map
*umap
)
284 if (emit_string(emitter
, name
) < 0)
286 if (emit_union_map(emitter
, umap
) < 0)
291 /* Print the isl_multi_pw_aff "mpa" to "emitter".
293 static int emit_multi_pw_aff(yaml_emitter_t
*emitter
,
294 __isl_keep isl_multi_pw_aff
*mpa
)
296 isl_ctx
*ctx
= isl_multi_pw_aff_get_ctx(mpa
);
301 p
= isl_printer_to_str(ctx
);
302 p
= isl_printer_print_multi_pw_aff(p
, mpa
);
303 str
= isl_printer_get_str(p
);
305 r
= emit_string(emitter
, str
);
310 /* Print the string "name" and the isl_multi_pw_aff "mpa" to "emitter".
312 static int emit_named_multi_pw_aff(yaml_emitter_t
*emitter
, const char *name
,
313 __isl_keep isl_multi_pw_aff
*mpa
)
315 if (emit_string(emitter
, name
) < 0)
317 if (emit_multi_pw_aff(emitter
, mpa
) < 0)
322 /* Print the schedule "schedule" to "emitter".
324 static int emit_schedule(yaml_emitter_t
*emitter
,
325 __isl_keep isl_schedule
*schedule
)
327 isl_ctx
*ctx
= isl_schedule_get_ctx(schedule
);
332 p
= isl_printer_to_str(ctx
);
333 p
= isl_printer_print_schedule(p
, schedule
);
334 str
= isl_printer_get_str(p
);
336 r
= emit_string(emitter
, str
);
341 /* Print the string "name" and the schedule "schedule" to "emitter".
343 static int emit_named_schedule(yaml_emitter_t
*emitter
, const char *name
,
344 __isl_keep isl_schedule
*schedule
)
346 if (emit_string(emitter
, name
) < 0)
348 if (emit_schedule(emitter
, schedule
) < 0)
353 /* Print "type" to "emitter".
355 static int emit_type(yaml_emitter_t
*emitter
, struct pet_type
*type
)
359 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
360 YAML_BLOCK_MAPPING_STYLE
))
362 if (!yaml_emitter_emit(emitter
, &event
))
365 if (emit_string(emitter
, "name") < 0)
367 if (emit_string(emitter
, type
->name
) < 0)
370 if (emit_string(emitter
, "definition") < 0)
372 if (emit_string(emitter
, type
->definition
) < 0)
375 if (!yaml_mapping_end_event_initialize(&event
))
377 if (!yaml_emitter_emit(emitter
, &event
))
383 /* Print the list of "n_type" "types", if any, to "emitter".
385 static int emit_types(yaml_emitter_t
*emitter
, int n_type
,
386 struct pet_type
**types
)
394 if (emit_string(emitter
, "types") < 0)
396 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
397 YAML_BLOCK_SEQUENCE_STYLE
))
399 if (!yaml_emitter_emit(emitter
, &event
))
402 for (i
= 0; i
< n_type
; ++i
)
403 if (emit_type(emitter
, types
[i
]) < 0)
406 if (!yaml_sequence_end_event_initialize(&event
))
408 if (!yaml_emitter_emit(emitter
, &event
))
414 static int emit_array(yaml_emitter_t
*emitter
, struct pet_array
*array
)
418 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
419 YAML_BLOCK_MAPPING_STYLE
))
421 if (!yaml_emitter_emit(emitter
, &event
))
424 if (emit_string(emitter
, "context") < 0)
426 if (emit_set(emitter
, array
->context
) < 0)
429 if (emit_string(emitter
, "extent") < 0)
431 if (emit_set(emitter
, array
->extent
) < 0)
434 if (array
->value_bounds
) {
435 if (emit_string(emitter
, "value_bounds") < 0)
437 if (emit_set(emitter
, array
->value_bounds
) < 0)
441 if (emit_string(emitter
, "element_type") < 0)
443 if (emit_string(emitter
, array
->element_type
) < 0)
445 if (emit_named_int(emitter
, "element_size", array
->element_size
) < 0)
448 if (array
->element_is_record
)
449 if (emit_named_int(emitter
, "element_is_record",
450 array
->element_is_record
) < 0)
453 if (array
->live_out
) {
454 if (emit_string(emitter
, "live_out") < 0)
456 if (emit_string(emitter
, "1") < 0)
460 if (array
->uniquely_defined
) {
461 if (emit_string(emitter
, "uniquely_defined") < 0)
463 if (emit_string(emitter
, "1") < 0)
467 if (array
->declared
&& emit_named_int(emitter
, "declared", 1) < 0)
469 if (array
->exposed
&& emit_named_int(emitter
, "exposed", 1) < 0)
472 if (!yaml_mapping_end_event_initialize(&event
))
474 if (!yaml_emitter_emit(emitter
, &event
))
480 static int emit_arrays(yaml_emitter_t
*emitter
, int n_array
,
481 struct pet_array
**arrays
)
486 if (emit_string(emitter
, "arrays") < 0)
488 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
489 YAML_BLOCK_SEQUENCE_STYLE
))
491 if (!yaml_emitter_emit(emitter
, &event
))
494 for (i
= 0; i
< n_array
; ++i
)
495 if (emit_array(emitter
, arrays
[i
]) < 0)
498 if (!yaml_sequence_end_event_initialize(&event
))
500 if (!yaml_emitter_emit(emitter
, &event
))
506 static int emit_expr_type(yaml_emitter_t
*emitter
, enum pet_expr_type type
)
508 if (emit_string(emitter
, pet_type_str(type
)) < 0)
513 /* Print the fields of the access expression "expr" to "emitter".
515 * Only print the access relations that are present and relevant
516 * for the type of access.
518 * If the depth of the access is equal to the depth that can be derived from
519 * the index expression, then there is no need to print it.
521 static int emit_access_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
525 if (expr
->acc
.kill
&& expr
->acc
.access
[pet_expr_access_fake_killed
] &&
526 emit_named_union_map(emitter
, "killed",
527 expr
->acc
.access
[pet_expr_access_fake_killed
]) < 0)
529 if (expr
->acc
.read
&& expr
->acc
.access
[pet_expr_access_may_read
] &&
530 emit_named_union_map(emitter
, "may_read",
531 expr
->acc
.access
[pet_expr_access_may_read
]) < 0)
533 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_may_write
] &&
534 emit_named_union_map(emitter
, "may_write",
535 expr
->acc
.access
[pet_expr_access_may_write
]) < 0)
537 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_must_write
] &&
538 emit_named_union_map(emitter
, "must_write",
539 expr
->acc
.access
[pet_expr_access_must_write
]) < 0)
541 if (emit_named_multi_pw_aff(emitter
, "index", expr
->acc
.index
) < 0)
543 depth
= isl_multi_pw_aff_dim(expr
->acc
.index
, isl_dim_out
);
544 if (expr
->acc
.depth
!= depth
&&
545 emit_named_int(emitter
, "depth", expr
->acc
.depth
) < 0)
547 if (expr
->acc
.ref_id
&&
548 emit_named_id(emitter
, "reference", expr
->acc
.ref_id
) < 0)
550 if (expr
->acc
.kill
) {
551 if (emit_named_unsigned(emitter
, "kill", 1) < 0)
554 if (emit_string(emitter
, "read") < 0)
556 if (emit_int(emitter
, expr
->acc
.read
) < 0)
558 if (emit_string(emitter
, "write") < 0)
560 if (emit_int(emitter
, expr
->acc
.write
) < 0)
567 static int emit_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
571 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
572 YAML_BLOCK_MAPPING_STYLE
))
574 if (!yaml_emitter_emit(emitter
, &event
))
577 if (emit_string(emitter
, "type") < 0)
579 if (emit_expr_type(emitter
, expr
->type
) < 0)
582 switch (expr
->type
) {
586 if (emit_named_val(emitter
, "value", expr
->i
) < 0)
589 case pet_expr_double
:
590 if (emit_string(emitter
, "value") < 0)
592 if (emit_double(emitter
, expr
->d
.val
) < 0)
594 if (emit_string(emitter
, "string") < 0)
596 if (emit_string(emitter
, expr
->d
.s
) < 0)
599 case pet_expr_access
:
600 if (emit_access_expr(emitter
, expr
) < 0)
604 if (emit_string(emitter
, "operation") < 0)
606 if (emit_string(emitter
, pet_op_str(expr
->op
)) < 0)
610 if (emit_string(emitter
, "name") < 0)
612 if (emit_string(emitter
, expr
->c
.name
) < 0)
616 if (emit_string(emitter
, "type_name") < 0)
618 if (emit_string(emitter
, expr
->type_name
) < 0)
623 if (expr
->n_arg
> 0) {
626 if (emit_string(emitter
, "arguments") < 0)
628 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
629 YAML_BLOCK_SEQUENCE_STYLE
))
631 if (!yaml_emitter_emit(emitter
, &event
))
634 for (i
= 0; i
< expr
->n_arg
; ++i
)
635 if (emit_expr(emitter
, expr
->args
[i
]) < 0)
638 if (!yaml_sequence_end_event_initialize(&event
))
640 if (!yaml_emitter_emit(emitter
, &event
))
644 if (!yaml_mapping_end_event_initialize(&event
))
646 if (!yaml_emitter_emit(emitter
, &event
))
652 /* Print the string "name" and the expression "expr" to "emitter".
654 static int emit_named_expr(yaml_emitter_t
*emitter
, const char *name
,
655 __isl_keep pet_expr
*expr
)
657 if (emit_string(emitter
, name
) < 0)
659 if (emit_expr(emitter
, expr
) < 0)
664 /* Print "type" to "emitter".
666 static int emit_tree_type(yaml_emitter_t
*emitter
, enum pet_tree_type type
)
668 if (emit_string(emitter
, pet_tree_type_str(type
)) < 0)
673 /* Recursively print "tree" to "emitter".
675 static int emit_tree(yaml_emitter_t
*emitter
, __isl_keep pet_tree
*tree
)
680 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
681 YAML_BLOCK_MAPPING_STYLE
))
683 if (!yaml_emitter_emit(emitter
, &event
))
686 if (emit_string(emitter
, "type") < 0)
688 if (emit_tree_type(emitter
, tree
->type
) < 0)
691 switch (tree
->type
) {
695 if (emit_named_int(emitter
, "block", tree
->u
.b
.block
) < 0)
697 if (tree
->u
.b
.n
== 0)
700 if (emit_string(emitter
, "children") < 0)
702 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
703 YAML_BLOCK_SEQUENCE_STYLE
))
705 if (!yaml_emitter_emit(emitter
, &event
))
708 for (i
= 0; i
< tree
->u
.b
.n
; ++i
)
709 if (emit_tree(emitter
, tree
->u
.b
.child
[i
]) < 0)
712 if (!yaml_sequence_end_event_initialize(&event
))
714 if (!yaml_emitter_emit(emitter
, &event
))
718 case pet_tree_continue
:
721 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
724 case pet_tree_decl_init
:
725 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
727 if (emit_named_expr(emitter
,
728 "initialization", tree
->u
.d
.init
) < 0)
732 if (emit_named_expr(emitter
, "expr", tree
->u
.e
.expr
) < 0)
736 if (tree
->u
.l
.independent
)
737 if (emit_named_int(emitter
, "independent", 1) < 0)
739 if (emit_named_int(emitter
, "declared", tree
->u
.l
.declared
) < 0)
741 if (emit_named_expr(emitter
, "variable", tree
->u
.l
.iv
) < 0)
743 if (emit_named_expr(emitter
,
744 "initialization", tree
->u
.l
.init
) < 0)
746 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
748 if (emit_named_expr(emitter
, "increment", tree
->u
.l
.inc
) < 0)
750 if (emit_string(emitter
, "body") < 0)
752 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
756 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
758 if (emit_string(emitter
, "body") < 0)
760 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
763 case pet_tree_infinite_loop
:
764 if (emit_string(emitter
, "body") < 0)
766 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
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)
777 case pet_tree_if_else
:
778 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
780 if (emit_string(emitter
, "then") < 0)
782 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
784 if (emit_string(emitter
, "else") < 0)
786 if (emit_tree(emitter
, tree
->u
.i
.else_body
) < 0)
791 if (!yaml_mapping_end_event_initialize(&event
))
793 if (!yaml_emitter_emit(emitter
, &event
))
799 static int emit_stmt(yaml_emitter_t
*emitter
, struct pet_stmt
*stmt
)
803 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
804 YAML_BLOCK_MAPPING_STYLE
))
806 if (!yaml_emitter_emit(emitter
, &event
))
809 if (emit_string(emitter
, "line") < 0)
811 if (emit_int(emitter
, pet_loc_get_line(stmt
->loc
)) < 0)
814 if (emit_string(emitter
, "domain") < 0)
816 if (emit_set(emitter
, stmt
->domain
) < 0)
819 if (emit_string(emitter
, "body") < 0)
821 if (emit_tree(emitter
, stmt
->body
) < 0)
824 if (stmt
->n_arg
> 0) {
827 if (emit_string(emitter
, "arguments") < 0)
829 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
830 YAML_BLOCK_SEQUENCE_STYLE
))
832 if (!yaml_emitter_emit(emitter
, &event
))
835 for (i
= 0; i
< stmt
->n_arg
; ++i
)
836 if (emit_expr(emitter
, stmt
->args
[i
]) < 0)
839 if (!yaml_sequence_end_event_initialize(&event
))
841 if (!yaml_emitter_emit(emitter
, &event
))
845 if (!yaml_mapping_end_event_initialize(&event
))
847 if (!yaml_emitter_emit(emitter
, &event
))
853 static int emit_statements(yaml_emitter_t
*emitter
, int n_stmt
,
854 struct pet_stmt
**stmts
)
859 if (emit_string(emitter
, "statements") < 0)
861 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
862 YAML_BLOCK_SEQUENCE_STYLE
))
864 if (!yaml_emitter_emit(emitter
, &event
))
867 for (i
= 0; i
< n_stmt
; ++i
)
868 if (emit_stmt(emitter
, stmts
[i
]) < 0)
871 if (!yaml_sequence_end_event_initialize(&event
))
873 if (!yaml_emitter_emit(emitter
, &event
))
879 /* Print "implication" to "emitter".
881 static int emit_implication(yaml_emitter_t
*emitter
,
882 struct pet_implication
*implication
)
886 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
887 YAML_BLOCK_MAPPING_STYLE
))
889 if (!yaml_emitter_emit(emitter
, &event
))
892 if (emit_named_int(emitter
, "satisfied", implication
->satisfied
) < 0)
895 if (emit_named_map(emitter
, "extension", implication
->extension
) < 0)
898 if (!yaml_mapping_end_event_initialize(&event
))
900 if (!yaml_emitter_emit(emitter
, &event
))
906 /* Print the list of "n_implication" "implications", if any, to "emitter".
908 static int emit_implications(yaml_emitter_t
*emitter
, int n_implication
,
909 struct pet_implication
**implications
)
914 if (n_implication
== 0)
917 if (emit_string(emitter
, "implications") < 0)
919 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
920 YAML_BLOCK_SEQUENCE_STYLE
))
922 if (!yaml_emitter_emit(emitter
, &event
))
925 for (i
= 0; i
< n_implication
; ++i
)
926 if (emit_implication(emitter
, implications
[i
]) < 0)
929 if (!yaml_sequence_end_event_initialize(&event
))
931 if (!yaml_emitter_emit(emitter
, &event
))
937 /* Print "independence" to "emitter".
939 static int emit_independence(yaml_emitter_t
*emitter
,
940 struct pet_independence
*independence
)
944 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
945 YAML_BLOCK_MAPPING_STYLE
))
947 if (!yaml_emitter_emit(emitter
, &event
))
950 if (emit_named_union_map(emitter
, "filter", independence
->filter
) < 0)
953 if (emit_named_union_set(emitter
, "local", independence
->local
) < 0)
956 if (!yaml_mapping_end_event_initialize(&event
))
958 if (!yaml_emitter_emit(emitter
, &event
))
964 /* Print the list of "n_independence" "independences", if any, to "emitter".
966 static int emit_independences(yaml_emitter_t
*emitter
, int n_independence
,
967 struct pet_independence
**independences
)
972 if (n_independence
== 0)
975 if (emit_string(emitter
, "independences") < 0)
977 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
978 YAML_BLOCK_SEQUENCE_STYLE
))
980 if (!yaml_emitter_emit(emitter
, &event
))
983 for (i
= 0; i
< n_independence
; ++i
)
984 if (emit_independence(emitter
, independences
[i
]) < 0)
987 if (!yaml_sequence_end_event_initialize(&event
))
989 if (!yaml_emitter_emit(emitter
, &event
))
995 static int emit_scop(yaml_emitter_t
*emitter
, struct pet_scop
*scop
)
999 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
1000 YAML_BLOCK_MAPPING_STYLE
))
1002 if (!yaml_emitter_emit(emitter
, &event
))
1005 if (emit_named_unsigned(emitter
,
1006 "start", pet_loc_get_start(scop
->loc
)) < 0)
1008 if (emit_named_unsigned(emitter
, "end", pet_loc_get_end(scop
->loc
)) < 0)
1010 if (emit_named_string(emitter
,
1011 "indent", pet_loc_get_indent(scop
->loc
)) < 0)
1013 if (emit_string(emitter
, "context") < 0)
1015 if (emit_set(emitter
, scop
->context
) < 0)
1017 if (!isl_set_plain_is_universe(scop
->context_value
) &&
1018 emit_named_set(emitter
, "context_value", scop
->context_value
) < 0)
1020 if (emit_named_schedule(emitter
, "schedule", scop
->schedule
) < 0)
1023 if (emit_types(emitter
, scop
->n_type
, scop
->types
) < 0)
1025 if (emit_arrays(emitter
, scop
->n_array
, scop
->arrays
) < 0)
1028 if (emit_statements(emitter
, scop
->n_stmt
, scop
->stmts
) < 0)
1031 if (emit_implications(emitter
, scop
->n_implication
,
1032 scop
->implications
) < 0)
1035 if (emit_independences(emitter
, scop
->n_independence
,
1036 scop
->independences
) < 0)
1039 if (!yaml_mapping_end_event_initialize(&event
))
1041 if (!yaml_emitter_emit(emitter
, &event
))
1047 /* Print a YAML serialization of "scop" to "out".
1049 int pet_scop_emit(FILE *out
, struct pet_scop
*scop
)
1051 yaml_emitter_t emitter
;
1054 yaml_emitter_initialize(&emitter
);
1056 yaml_emitter_set_output_file(&emitter
, out
);
1058 yaml_stream_start_event_initialize(&event
, YAML_UTF8_ENCODING
);
1059 if (!yaml_emitter_emit(&emitter
, &event
))
1062 if (!yaml_document_start_event_initialize(&event
, NULL
, NULL
, NULL
, 1))
1064 if (!yaml_emitter_emit(&emitter
, &event
))
1067 if (emit_scop(&emitter
, scop
) < 0)
1070 if (!yaml_document_end_event_initialize(&event
, 1))
1072 if (!yaml_emitter_emit(&emitter
, &event
))
1075 yaml_stream_end_event_initialize(&event
);
1076 if (!yaml_emitter_emit(&emitter
, &event
))
1079 yaml_emitter_delete(&emitter
);
1082 yaml_emitter_delete(&emitter
);