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)
471 if (array
->outer
&& emit_named_int(emitter
, "outer", 1) < 0)
474 if (!yaml_mapping_end_event_initialize(&event
))
476 if (!yaml_emitter_emit(emitter
, &event
))
482 static int emit_arrays(yaml_emitter_t
*emitter
, int n_array
,
483 struct pet_array
**arrays
)
488 if (emit_string(emitter
, "arrays") < 0)
490 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
491 YAML_BLOCK_SEQUENCE_STYLE
))
493 if (!yaml_emitter_emit(emitter
, &event
))
496 for (i
= 0; i
< n_array
; ++i
)
497 if (emit_array(emitter
, arrays
[i
]) < 0)
500 if (!yaml_sequence_end_event_initialize(&event
))
502 if (!yaml_emitter_emit(emitter
, &event
))
508 static int emit_expr_type(yaml_emitter_t
*emitter
, enum pet_expr_type type
)
510 if (emit_string(emitter
, pet_type_str(type
)) < 0)
515 /* Print the fields of the access expression "expr" to "emitter".
517 * Only print the access relations that are present and relevant
518 * for the type of access.
520 * If the depth of the access is equal to the depth that can be derived from
521 * the index expression, then there is no need to print it.
523 static int emit_access_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
527 if (expr
->acc
.kill
&& expr
->acc
.access
[pet_expr_access_fake_killed
] &&
528 emit_named_union_map(emitter
, "killed",
529 expr
->acc
.access
[pet_expr_access_fake_killed
]) < 0)
531 if (expr
->acc
.read
&& expr
->acc
.access
[pet_expr_access_may_read
] &&
532 emit_named_union_map(emitter
, "may_read",
533 expr
->acc
.access
[pet_expr_access_may_read
]) < 0)
535 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_may_write
] &&
536 emit_named_union_map(emitter
, "may_write",
537 expr
->acc
.access
[pet_expr_access_may_write
]) < 0)
539 if (expr
->acc
.write
&& expr
->acc
.access
[pet_expr_access_must_write
] &&
540 emit_named_union_map(emitter
, "must_write",
541 expr
->acc
.access
[pet_expr_access_must_write
]) < 0)
543 if (emit_named_multi_pw_aff(emitter
, "index", expr
->acc
.index
) < 0)
545 depth
= isl_multi_pw_aff_dim(expr
->acc
.index
, isl_dim_out
);
546 if (expr
->acc
.depth
!= depth
&&
547 emit_named_int(emitter
, "depth", expr
->acc
.depth
) < 0)
549 if (expr
->acc
.ref_id
&&
550 emit_named_id(emitter
, "reference", expr
->acc
.ref_id
) < 0)
552 if (expr
->acc
.kill
) {
553 if (emit_named_unsigned(emitter
, "kill", 1) < 0)
556 if (emit_string(emitter
, "read") < 0)
558 if (emit_int(emitter
, expr
->acc
.read
) < 0)
560 if (emit_string(emitter
, "write") < 0)
562 if (emit_int(emitter
, expr
->acc
.write
) < 0)
569 static int emit_expr(yaml_emitter_t
*emitter
, __isl_keep pet_expr
*expr
)
573 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
574 YAML_BLOCK_MAPPING_STYLE
))
576 if (!yaml_emitter_emit(emitter
, &event
))
579 if (emit_string(emitter
, "type") < 0)
581 if (emit_expr_type(emitter
, expr
->type
) < 0)
584 switch (expr
->type
) {
588 if (emit_named_val(emitter
, "value", expr
->i
) < 0)
591 case pet_expr_double
:
592 if (emit_string(emitter
, "value") < 0)
594 if (emit_double(emitter
, expr
->d
.val
) < 0)
596 if (emit_string(emitter
, "string") < 0)
598 if (emit_string(emitter
, expr
->d
.s
) < 0)
601 case pet_expr_access
:
602 if (emit_access_expr(emitter
, expr
) < 0)
606 if (emit_string(emitter
, "operation") < 0)
608 if (emit_string(emitter
, pet_op_str(expr
->op
)) < 0)
612 if (emit_string(emitter
, "name") < 0)
614 if (emit_string(emitter
, expr
->c
.name
) < 0)
618 if (emit_string(emitter
, "type_name") < 0)
620 if (emit_string(emitter
, expr
->type_name
) < 0)
625 if (expr
->n_arg
> 0) {
628 if (emit_string(emitter
, "arguments") < 0)
630 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
631 YAML_BLOCK_SEQUENCE_STYLE
))
633 if (!yaml_emitter_emit(emitter
, &event
))
636 for (i
= 0; i
< expr
->n_arg
; ++i
)
637 if (emit_expr(emitter
, expr
->args
[i
]) < 0)
640 if (!yaml_sequence_end_event_initialize(&event
))
642 if (!yaml_emitter_emit(emitter
, &event
))
646 if (!yaml_mapping_end_event_initialize(&event
))
648 if (!yaml_emitter_emit(emitter
, &event
))
654 /* Print the string "name" and the expression "expr" to "emitter".
656 static int emit_named_expr(yaml_emitter_t
*emitter
, const char *name
,
657 __isl_keep pet_expr
*expr
)
659 if (emit_string(emitter
, name
) < 0)
661 if (emit_expr(emitter
, expr
) < 0)
666 /* Print "type" to "emitter".
668 static int emit_tree_type(yaml_emitter_t
*emitter
, enum pet_tree_type type
)
670 if (emit_string(emitter
, pet_tree_type_str(type
)) < 0)
675 /* Recursively print "tree" to "emitter".
677 static int emit_tree(yaml_emitter_t
*emitter
, __isl_keep pet_tree
*tree
)
682 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
683 YAML_BLOCK_MAPPING_STYLE
))
685 if (!yaml_emitter_emit(emitter
, &event
))
688 if (emit_string(emitter
, "type") < 0)
690 if (emit_tree_type(emitter
, tree
->type
) < 0)
693 switch (tree
->type
) {
697 if (emit_named_int(emitter
, "block", tree
->u
.b
.block
) < 0)
699 if (tree
->u
.b
.n
== 0)
702 if (emit_string(emitter
, "children") < 0)
704 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
705 YAML_BLOCK_SEQUENCE_STYLE
))
707 if (!yaml_emitter_emit(emitter
, &event
))
710 for (i
= 0; i
< tree
->u
.b
.n
; ++i
)
711 if (emit_tree(emitter
, tree
->u
.b
.child
[i
]) < 0)
714 if (!yaml_sequence_end_event_initialize(&event
))
716 if (!yaml_emitter_emit(emitter
, &event
))
720 case pet_tree_continue
:
723 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
726 case pet_tree_decl_init
:
727 if (emit_named_expr(emitter
, "variable", tree
->u
.d
.var
) < 0)
729 if (emit_named_expr(emitter
,
730 "initialization", tree
->u
.d
.init
) < 0)
734 case pet_tree_return
:
735 if (emit_named_expr(emitter
, "expr", tree
->u
.e
.expr
) < 0)
739 if (tree
->u
.l
.independent
)
740 if (emit_named_int(emitter
, "independent", 1) < 0)
742 if (emit_named_int(emitter
, "declared", tree
->u
.l
.declared
) < 0)
744 if (emit_named_expr(emitter
, "variable", tree
->u
.l
.iv
) < 0)
746 if (emit_named_expr(emitter
,
747 "initialization", tree
->u
.l
.init
) < 0)
749 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
751 if (emit_named_expr(emitter
, "increment", tree
->u
.l
.inc
) < 0)
753 if (emit_string(emitter
, "body") < 0)
755 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
759 if (emit_named_expr(emitter
, "condition", tree
->u
.l
.cond
) < 0)
761 if (emit_string(emitter
, "body") < 0)
763 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
766 case pet_tree_infinite_loop
:
767 if (emit_string(emitter
, "body") < 0)
769 if (emit_tree(emitter
, tree
->u
.l
.body
) < 0)
773 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
775 if (emit_string(emitter
, "then") < 0)
777 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
780 case pet_tree_if_else
:
781 if (emit_named_expr(emitter
, "condition", tree
->u
.i
.cond
) < 0)
783 if (emit_string(emitter
, "then") < 0)
785 if (emit_tree(emitter
, tree
->u
.i
.then_body
) < 0)
787 if (emit_string(emitter
, "else") < 0)
789 if (emit_tree(emitter
, tree
->u
.i
.else_body
) < 0)
794 if (!yaml_mapping_end_event_initialize(&event
))
796 if (!yaml_emitter_emit(emitter
, &event
))
802 static int emit_stmt(yaml_emitter_t
*emitter
, struct pet_stmt
*stmt
)
806 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
807 YAML_BLOCK_MAPPING_STYLE
))
809 if (!yaml_emitter_emit(emitter
, &event
))
812 if (emit_string(emitter
, "line") < 0)
814 if (emit_int(emitter
, pet_loc_get_line(stmt
->loc
)) < 0)
817 if (emit_string(emitter
, "domain") < 0)
819 if (emit_set(emitter
, stmt
->domain
) < 0)
822 if (emit_string(emitter
, "body") < 0)
824 if (emit_tree(emitter
, stmt
->body
) < 0)
827 if (stmt
->n_arg
> 0) {
830 if (emit_string(emitter
, "arguments") < 0)
832 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
833 YAML_BLOCK_SEQUENCE_STYLE
))
835 if (!yaml_emitter_emit(emitter
, &event
))
838 for (i
= 0; i
< stmt
->n_arg
; ++i
)
839 if (emit_expr(emitter
, stmt
->args
[i
]) < 0)
842 if (!yaml_sequence_end_event_initialize(&event
))
844 if (!yaml_emitter_emit(emitter
, &event
))
848 if (!yaml_mapping_end_event_initialize(&event
))
850 if (!yaml_emitter_emit(emitter
, &event
))
856 static int emit_statements(yaml_emitter_t
*emitter
, int n_stmt
,
857 struct pet_stmt
**stmts
)
862 if (emit_string(emitter
, "statements") < 0)
864 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
865 YAML_BLOCK_SEQUENCE_STYLE
))
867 if (!yaml_emitter_emit(emitter
, &event
))
870 for (i
= 0; i
< n_stmt
; ++i
)
871 if (emit_stmt(emitter
, stmts
[i
]) < 0)
874 if (!yaml_sequence_end_event_initialize(&event
))
876 if (!yaml_emitter_emit(emitter
, &event
))
882 /* Print "implication" to "emitter".
884 static int emit_implication(yaml_emitter_t
*emitter
,
885 struct pet_implication
*implication
)
889 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
890 YAML_BLOCK_MAPPING_STYLE
))
892 if (!yaml_emitter_emit(emitter
, &event
))
895 if (emit_named_int(emitter
, "satisfied", implication
->satisfied
) < 0)
898 if (emit_named_map(emitter
, "extension", implication
->extension
) < 0)
901 if (!yaml_mapping_end_event_initialize(&event
))
903 if (!yaml_emitter_emit(emitter
, &event
))
909 /* Print the list of "n_implication" "implications", if any, to "emitter".
911 static int emit_implications(yaml_emitter_t
*emitter
, int n_implication
,
912 struct pet_implication
**implications
)
917 if (n_implication
== 0)
920 if (emit_string(emitter
, "implications") < 0)
922 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
923 YAML_BLOCK_SEQUENCE_STYLE
))
925 if (!yaml_emitter_emit(emitter
, &event
))
928 for (i
= 0; i
< n_implication
; ++i
)
929 if (emit_implication(emitter
, implications
[i
]) < 0)
932 if (!yaml_sequence_end_event_initialize(&event
))
934 if (!yaml_emitter_emit(emitter
, &event
))
940 /* Print "independence" to "emitter".
942 static int emit_independence(yaml_emitter_t
*emitter
,
943 struct pet_independence
*independence
)
947 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
948 YAML_BLOCK_MAPPING_STYLE
))
950 if (!yaml_emitter_emit(emitter
, &event
))
953 if (emit_named_union_map(emitter
, "filter", independence
->filter
) < 0)
956 if (emit_named_union_set(emitter
, "local", independence
->local
) < 0)
959 if (!yaml_mapping_end_event_initialize(&event
))
961 if (!yaml_emitter_emit(emitter
, &event
))
967 /* Print the list of "n_independence" "independences", if any, to "emitter".
969 static int emit_independences(yaml_emitter_t
*emitter
, int n_independence
,
970 struct pet_independence
**independences
)
975 if (n_independence
== 0)
978 if (emit_string(emitter
, "independences") < 0)
980 if (!yaml_sequence_start_event_initialize(&event
, NULL
, NULL
, 1,
981 YAML_BLOCK_SEQUENCE_STYLE
))
983 if (!yaml_emitter_emit(emitter
, &event
))
986 for (i
= 0; i
< n_independence
; ++i
)
987 if (emit_independence(emitter
, independences
[i
]) < 0)
990 if (!yaml_sequence_end_event_initialize(&event
))
992 if (!yaml_emitter_emit(emitter
, &event
))
998 static int emit_scop(yaml_emitter_t
*emitter
, struct pet_scop
*scop
)
1002 if (!yaml_mapping_start_event_initialize(&event
, NULL
, NULL
, 1,
1003 YAML_BLOCK_MAPPING_STYLE
))
1005 if (!yaml_emitter_emit(emitter
, &event
))
1008 if (emit_named_unsigned(emitter
,
1009 "start", pet_loc_get_start(scop
->loc
)) < 0)
1011 if (emit_named_unsigned(emitter
, "end", pet_loc_get_end(scop
->loc
)) < 0)
1013 if (emit_named_string(emitter
,
1014 "indent", pet_loc_get_indent(scop
->loc
)) < 0)
1016 if (emit_string(emitter
, "context") < 0)
1018 if (emit_set(emitter
, scop
->context
) < 0)
1020 if (!isl_set_plain_is_universe(scop
->context_value
) &&
1021 emit_named_set(emitter
, "context_value", scop
->context_value
) < 0)
1023 if (emit_named_schedule(emitter
, "schedule", scop
->schedule
) < 0)
1026 if (emit_types(emitter
, scop
->n_type
, scop
->types
) < 0)
1028 if (emit_arrays(emitter
, scop
->n_array
, scop
->arrays
) < 0)
1031 if (emit_statements(emitter
, scop
->n_stmt
, scop
->stmts
) < 0)
1034 if (emit_implications(emitter
, scop
->n_implication
,
1035 scop
->implications
) < 0)
1038 if (emit_independences(emitter
, scop
->n_independence
,
1039 scop
->independences
) < 0)
1042 if (!yaml_mapping_end_event_initialize(&event
))
1044 if (!yaml_emitter_emit(emitter
, &event
))
1050 /* Print a YAML serialization of "scop" to "out".
1052 int pet_scop_emit(FILE *out
, struct pet_scop
*scop
)
1054 yaml_emitter_t emitter
;
1057 yaml_emitter_initialize(&emitter
);
1059 yaml_emitter_set_output_file(&emitter
, out
);
1061 yaml_stream_start_event_initialize(&event
, YAML_UTF8_ENCODING
);
1062 if (!yaml_emitter_emit(&emitter
, &event
))
1065 if (!yaml_document_start_event_initialize(&event
, NULL
, NULL
, NULL
, 1))
1067 if (!yaml_emitter_emit(&emitter
, &event
))
1070 if (emit_scop(&emitter
, scop
) < 0)
1073 if (!yaml_document_end_event_initialize(&event
, 1))
1075 if (!yaml_emitter_emit(&emitter
, &event
))
1078 yaml_stream_end_event_initialize(&event
);
1079 if (!yaml_emitter_emit(&emitter
, &event
))
1082 yaml_emitter_delete(&emitter
);
1085 yaml_emitter_delete(&emitter
);