INSTALL: add reference to pet/README
[ppn.git] / adg_print.cc
blob062352226943bf72f58842e23b41091e6265f628
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
3 */
5 #include <isa/adg.h>
7 static int init(yaml_emitter_t *emitter, FILE *out)
9 yaml_event_t event;
11 yaml_emitter_initialize(emitter);
13 yaml_emitter_set_output_file(emitter, out);
15 yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
16 if (!yaml_emitter_emit(emitter, &event))
17 return -1;
19 if (!yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 1))
20 return -1;
21 if (!yaml_emitter_emit(emitter, &event))
22 return -1;
23 return 0;
26 static int fini(yaml_emitter_t *emitter)
28 yaml_event_t event;
30 if (!yaml_document_end_event_initialize(&event, 1))
31 goto error;
32 if (!yaml_emitter_emit(emitter, &event))
33 goto error;
35 yaml_stream_end_event_initialize(&event);
36 if (!yaml_emitter_emit(emitter, &event))
37 goto error;
39 yaml_emitter_delete(emitter);
40 return 0;
41 error:
42 yaml_emitter_delete(emitter);
43 return -1;
46 static int emit_string(yaml_emitter_t *emitter, const char *str)
48 yaml_event_t event;
50 if (!yaml_scalar_event_initialize(&event, NULL, NULL,
51 (yaml_char_t *) str, strlen(str),
52 1, 1, YAML_PLAIN_SCALAR_STYLE))
53 return -1;
54 if (!yaml_emitter_emit(emitter, &event))
55 return -1;
57 return 0;
60 static int emit_int(yaml_emitter_t *emitter, int i)
62 char buffer[40];
64 snprintf(buffer, sizeof(buffer), "%d", i);
65 return emit_string(emitter, buffer);
68 static int emit_named_int(yaml_emitter_t *emitter, const char *name, int i)
70 if (emit_string(emitter, name) < 0)
71 return -1;
72 if (emit_int(emitter, i) < 0)
73 return -1;
74 return 0;
77 static int emit_val(yaml_emitter_t *emitter, __isl_keep isl_val *v)
79 isl_ctx *ctx = isl_val_get_ctx(v);
80 isl_printer *p;
81 char *str;
82 int r;
84 p = isl_printer_to_str(ctx);
85 p = isl_printer_print_val(p, v);
86 str = isl_printer_get_str(p);
87 isl_printer_free(p);
88 r = emit_string(emitter, str);
89 free(str);
90 return r;
93 static int emit_named_val(yaml_emitter_t *emitter, const char *name,
94 __isl_keep isl_val *v)
96 if (emit_string(emitter, name) < 0)
97 return -1;
98 if (emit_val(emitter, v) < 0)
99 return -1;
100 return 0;
103 static int emit_named_id(yaml_emitter_t *emitter, const char *name,
104 __isl_keep isl_id *id)
106 if (emit_string(emitter, name) < 0)
107 return -1;
108 if (emit_string(emitter, isl_id_get_name(id)) < 0)
109 return -1;
110 return 0;
113 static int emit_set(yaml_emitter_t *emitter, __isl_keep isl_set *set)
115 isl_ctx *ctx = isl_set_get_ctx(set);
116 isl_printer *p;
117 char *str;
118 int r;
120 p = isl_printer_to_str(ctx);
121 p = isl_printer_print_set(p, set);
122 str = isl_printer_get_str(p);
123 isl_printer_free(p);
124 r = emit_string(emitter, str);
125 free(str);
126 return r;
129 static int emit_map(yaml_emitter_t *emitter, __isl_keep isl_map *map)
131 isl_ctx *ctx = isl_map_get_ctx(map);
132 isl_printer *p;
133 char *str;
134 int r;
136 p = isl_printer_to_str(ctx);
137 p = isl_printer_print_map(p, map);
138 str = isl_printer_get_str(p);
139 isl_printer_free(p);
140 r = emit_string(emitter, str);
141 free(str);
142 return r;
145 static int emit_named_set(yaml_emitter_t *emitter, const char *name,
146 __isl_keep isl_set *set)
148 if (emit_string(emitter, name) < 0)
149 return -1;
150 if (emit_set(emitter, set) < 0)
151 return -1;
152 return 0;
155 static int emit_named_map(yaml_emitter_t *emitter, const char *name,
156 __isl_keep isl_map *map)
158 if (emit_string(emitter, name) < 0)
159 return -1;
160 if (emit_map(emitter, map) < 0)
161 return -1;
162 return 0;
165 static int emit_aff(yaml_emitter_t *emitter, __isl_keep isl_aff *aff)
167 isl_ctx *ctx = isl_aff_get_ctx(aff);
168 isl_printer *p;
169 char *str;
170 int r;
172 p = isl_printer_to_str(ctx);
173 p = isl_printer_print_aff(p, aff);
174 str = isl_printer_get_str(p);
175 isl_printer_free(p);
176 r = emit_string(emitter, str);
177 free(str);
178 return r;
181 static int emit_named_aff(yaml_emitter_t *emitter, const char *name,
182 __isl_keep isl_aff *aff)
184 if (emit_string(emitter, name) < 0)
185 return -1;
186 if (emit_aff(emitter, aff) < 0)
187 return -1;
188 return 0;
191 static int emit_pw_aff(yaml_emitter_t *emitter, __isl_keep isl_pw_aff *pa)
193 isl_ctx *ctx = isl_pw_aff_get_ctx(pa);
194 isl_printer *p;
195 char *str;
196 int r;
198 p = isl_printer_to_str(ctx);
199 p = isl_printer_print_pw_aff(p, pa);
200 str = isl_printer_get_str(p);
201 isl_printer_free(p);
202 r = emit_string(emitter, str);
203 free(str);
204 return r;
207 static int emit_named_pw_aff(yaml_emitter_t *emitter, const char *name,
208 __isl_keep isl_pw_aff *pwaff)
210 if (emit_string(emitter, name) < 0)
211 return -1;
212 if (emit_pw_aff(emitter, pwaff) < 0)
213 return -1;
214 return 0;
217 static int emit_multi_aff(yaml_emitter_t *emitter,
218 __isl_keep isl_multi_aff *maff)
220 isl_ctx *ctx = isl_multi_aff_get_ctx(maff);
221 isl_printer *p;
222 char *str;
223 int r;
225 p = isl_printer_to_str(ctx);
226 p = isl_printer_print_multi_aff(p, maff);
227 str = isl_printer_get_str(p);
228 isl_printer_free(p);
229 r = emit_string(emitter, str);
230 free(str);
231 return r;
234 static int emit_named_multi_aff(yaml_emitter_t *emitter, const char *name,
235 __isl_keep isl_multi_aff *maff)
237 if (emit_string(emitter, name) < 0)
238 return -1;
239 if (emit_multi_aff(emitter, maff) < 0)
240 return -1;
241 return 0;
244 static int emit_pw_multi_aff(yaml_emitter_t *emitter,
245 __isl_keep isl_pw_multi_aff *maff)
247 isl_ctx *ctx = isl_pw_multi_aff_get_ctx(maff);
248 isl_printer *p;
249 char *str;
250 int r;
252 p = isl_printer_to_str(ctx);
253 p = isl_printer_print_pw_multi_aff(p, maff);
254 str = isl_printer_get_str(p);
255 isl_printer_free(p);
256 r = emit_string(emitter, str);
257 free(str);
258 return r;
261 static int emit_named_pw_multi_aff(yaml_emitter_t *emitter, const char *name,
262 __isl_keep isl_pw_multi_aff *maff)
264 if (emit_string(emitter, name) < 0)
265 return -1;
266 if (emit_pw_multi_aff(emitter, maff) < 0)
267 return -1;
268 return 0;
271 int adg_var::print(yaml_emitter_t *emitter)
273 yaml_event_t event;
275 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
276 YAML_FLOW_MAPPING_STYLE))
277 return -1;
278 if (!yaml_emitter_emit(emitter, &event))
279 return -1;
281 if (access && emit_named_pw_multi_aff(emitter, "access", access))
282 return -1;
283 if (type && emit_named_id(emitter, "type", type))
284 return -1;
286 if (!yaml_mapping_end_event_initialize(&event))
287 return -1;
288 if (!yaml_emitter_emit(emitter, &event))
289 return -1;
291 return 0;
294 static int emit_var_list(yaml_emitter_t *emitter,
295 const char *name, std::vector<adg_var *> &list)
297 yaml_event_t event;
299 if (list.size() == 0)
300 return 0;
302 if (emit_string(emitter, name) < 0)
303 return -1;
305 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
306 YAML_BLOCK_SEQUENCE_STYLE))
307 return -1;
308 if (!yaml_emitter_emit(emitter, &event))
309 return -1;
311 for (int i = 0; i < list.size(); ++i)
312 if (list[i]->print(emitter) < 0)
313 return -1;
315 if (!yaml_sequence_end_event_initialize(&event))
316 return -1;
317 if (!yaml_emitter_emit(emitter, &event))
318 return -1;
320 return 0;
323 static int emit_arg_list(yaml_emitter_t *emitter,
324 const char *name, std::vector<adg_arg *> &list)
326 yaml_event_t event;
328 if (list.size() == 0)
329 return 0;
331 if (emit_string(emitter, name) < 0)
332 return -1;
334 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
335 YAML_BLOCK_SEQUENCE_STYLE))
336 return -1;
337 if (!yaml_emitter_emit(emitter, &event))
338 return -1;
340 for (int i = 0; i < list.size(); ++i)
341 if (list[i]->print(emitter) < 0)
342 return -1;
344 if (!yaml_sequence_end_event_initialize(&event))
345 return -1;
346 if (!yaml_emitter_emit(emitter, &event))
347 return -1;
349 return 0;
352 static int emit_named_var(yaml_emitter_t *emitter, const char *name,
353 adg_var *var)
355 if (emit_string(emitter, name) < 0)
356 return -1;
357 if (var->print(emitter) < 0)
358 return -1;
359 return 0;
362 static int emit_arg_type(yaml_emitter_t *emitter, enum adg_arg_type type)
364 const char *s_type;
366 switch (type) {
367 case adg_arg_value:
368 s_type = "value";
369 break;
370 case adg_arg_reference:
371 s_type = "reference";
372 break;
373 case adg_arg_return:
374 s_type = "return";
375 break;
376 case adg_arg_unknown:
377 s_type = "unknown";
378 break;
379 default:
380 return -1;
383 if (emit_string(emitter, "type") < 0)
384 return -1;
385 if (emit_string(emitter, s_type) < 0)
386 return -1;
388 return 0;
391 int adg_arg::print(yaml_emitter_t *emitter)
393 yaml_event_t event;
395 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
396 YAML_FLOW_MAPPING_STYLE))
397 return -1;
398 if (!yaml_emitter_emit(emitter, &event))
399 return -1;
401 if (var && emit_named_var(emitter, "var", var))
402 return -1;
403 if (emit_arg_type(emitter, type))
404 return -1;
406 if (!yaml_mapping_end_event_initialize(&event))
407 return -1;
408 if (!yaml_emitter_emit(emitter, &event))
409 return -1;
411 return 0;
414 int adg_expr::print(yaml_emitter_t *emitter)
416 yaml_event_t event;
418 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
419 YAML_FLOW_MAPPING_STYLE))
420 return -1;
421 if (!yaml_emitter_emit(emitter, &event))
422 return -1;
424 if (name && emit_named_id(emitter, "name", name))
425 return -1;
426 if (expr && emit_named_pw_aff(emitter, "expr", expr))
427 return -1;
429 if (!yaml_mapping_end_event_initialize(&event))
430 return -1;
431 if (!yaml_emitter_emit(emitter, &event))
432 return -1;
434 return 0;
437 static int emit_expr_list(yaml_emitter_t *emitter,
438 const char *name, std::vector<adg_expr *> &list)
440 yaml_event_t event;
442 if (list.size() == 0)
443 return 0;
445 if (emit_string(emitter, name) < 0)
446 return -1;
448 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
449 YAML_BLOCK_SEQUENCE_STYLE))
450 return -1;
451 if (!yaml_emitter_emit(emitter, &event))
452 return -1;
454 for (int i = 0; i < list.size(); ++i)
455 if (list[i]->print(emitter) < 0)
456 return -1;
458 if (!yaml_sequence_end_event_initialize(&event))
459 return -1;
460 if (!yaml_emitter_emit(emitter, &event))
461 return -1;
463 return 0;
466 int adg_domain::print(yaml_emitter_t *emitter)
468 yaml_event_t event;
470 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
471 YAML_ANY_MAPPING_STYLE))
472 return -1;
473 if (!yaml_emitter_emit(emitter, &event))
474 return -1;
476 if (bounds && emit_named_set(emitter, "bounds", bounds))
477 return -1;
478 if (emit_expr_list(emitter, "controls", controls))
479 return -1;
480 if (emit_var_list(emitter, "filters", filters))
481 return -1;
483 if (!yaml_mapping_end_event_initialize(&event))
484 return -1;
485 if (!yaml_emitter_emit(emitter, &event))
486 return -1;
488 return 0;
491 static int emit_named_domain(yaml_emitter_t *emitter, const char *name,
492 adg_domain *domain)
494 if (emit_string(emitter, name) < 0)
495 return -1;
496 if (domain->print(emitter) < 0)
497 return -1;
498 return 0;
501 static int emit_id_list(yaml_emitter_t *emitter,
502 const char *name, std::vector<isl_id *> &list)
504 yaml_event_t event;
506 if (list.size() == 0)
507 return 0;
509 if (emit_string(emitter, name) < 0)
510 return -1;
512 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
513 YAML_FLOW_SEQUENCE_STYLE))
514 return -1;
515 if (!yaml_emitter_emit(emitter, &event))
516 return -1;
518 for (int i = 0; i < list.size(); ++i)
519 if (emit_string(emitter, isl_id_get_name(list[i])) < 0)
520 return -1;
522 if (!yaml_sequence_end_event_initialize(&event))
523 return -1;
524 if (!yaml_emitter_emit(emitter, &event))
525 return -1;
527 return 0;
530 int adg_port::print(yaml_emitter_t *emitter)
532 yaml_event_t event;
534 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
535 YAML_BLOCK_MAPPING_STYLE))
536 return -1;
537 if (!yaml_emitter_emit(emitter, &event))
538 return -1;
540 if (name && emit_named_id(emitter, "name", name))
541 return -1;
542 if (node_name && emit_named_id(emitter, "node", node_name))
543 return -1;
544 if (edge_name && emit_named_id(emitter, "edge", edge_name))
545 return -1;
546 if (emit_var_list(emitter, "vars", vars))
547 return -1;
548 if (domain && emit_named_domain(emitter, "domain", domain))
549 return -1;
551 if (!yaml_mapping_end_event_initialize(&event))
552 return -1;
553 if (!yaml_emitter_emit(emitter, &event))
554 return -1;
556 return 0;
559 int adg_gate::print(yaml_emitter_t *emitter)
561 yaml_event_t event;
563 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
564 YAML_BLOCK_MAPPING_STYLE))
565 return -1;
566 if (!yaml_emitter_emit(emitter, &event))
567 return -1;
569 if (name && emit_named_id(emitter, "name", name))
570 return -1;
571 if (node_name && emit_named_id(emitter, "node", node_name))
572 return -1;
573 if (in && emit_named_var(emitter, "in", in))
574 return -1;
575 if (out && emit_named_var(emitter, "out", out))
576 return -1;
577 if (domain && emit_named_domain(emitter, "domain", domain))
578 return -1;
580 if (!yaml_mapping_end_event_initialize(&event))
581 return -1;
582 if (!yaml_emitter_emit(emitter, &event))
583 return -1;
585 return 0;
588 int adg_function::print(yaml_emitter_t *emitter)
590 yaml_event_t event;
592 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
593 YAML_BLOCK_MAPPING_STYLE))
594 return -1;
595 if (!yaml_emitter_emit(emitter, &event))
596 return -1;
598 if (name && emit_named_id(emitter, "name", name))
599 return -1;
601 if (emit_arg_list(emitter, "in", in))
602 return -1;
603 if (emit_arg_list(emitter, "out", out))
604 return -1;
605 if (emit_expr_list(emitter, "ctrl", ctrl))
606 return -1;
608 if (domain && emit_named_domain(emitter, "domain", domain))
609 return -1;
611 if (!yaml_mapping_end_event_initialize(&event))
612 return -1;
613 if (!yaml_emitter_emit(emitter, &event))
614 return -1;
616 return 0;
619 static int emit_port_list(yaml_emitter_t *emitter,
620 const char *name, std::vector<adg_port *> &list)
622 yaml_event_t event;
624 if (list.size() == 0)
625 return 0;
627 if (emit_string(emitter, name) < 0)
628 return -1;
630 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
631 YAML_BLOCK_SEQUENCE_STYLE))
632 return -1;
633 if (!yaml_emitter_emit(emitter, &event))
634 return -1;
636 for (int i = 0; i < list.size(); ++i)
637 if (list[i]->print(emitter) < 0)
638 return -1;
640 if (!yaml_sequence_end_event_initialize(&event))
641 return -1;
642 if (!yaml_emitter_emit(emitter, &event))
643 return -1;
645 return 0;
648 int adg_node::print(yaml_emitter_t *emitter)
650 yaml_event_t event;
652 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
653 YAML_BLOCK_MAPPING_STYLE))
654 return -1;
655 if (!yaml_emitter_emit(emitter, &event))
656 return -1;
658 if (name && emit_named_id(emitter, "name", name))
659 return -1;
661 if (function) {
662 if (emit_string(emitter, "function") < 0)
663 return -1;
664 function->print(emitter);
667 if (domain && emit_named_domain(emitter, "domain", domain))
668 return -1;
669 if (schedule && emit_named_map(emitter, "schedule", schedule))
670 return -1;
672 if (emit_port_list(emitter, "input_ports", input_ports))
673 return -1;
674 if (emit_port_list(emitter, "output_ports", output_ports))
675 return -1;
676 if (emit_expr_list(emitter, "expressions", expressions))
677 return -1;
679 if (gates.size() > 0) {
680 if (emit_string(emitter, "gates") < 0)
681 return -1;
682 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
683 YAML_BLOCK_SEQUENCE_STYLE))
684 return -1;
685 if (!yaml_emitter_emit(emitter, &event))
686 return -1;
687 for (int i = 0; i < gates.size(); ++i)
688 if (gates[i]->print(emitter))
689 return -1;
690 if (!yaml_sequence_end_event_initialize(&event))
691 return -1;
692 if (!yaml_emitter_emit(emitter, &event))
693 return -1;
696 if (!yaml_mapping_end_event_initialize(&event))
697 return -1;
698 if (!yaml_emitter_emit(emitter, &event))
699 return -1;
701 return 0;
704 static int emit_type(yaml_emitter_t *emitter, enum adg_edge_type type)
706 const char *s_type;
708 switch (type) {
709 case adg_edge_fifo:
710 s_type = "fifo";
711 break;
712 case adg_edge_sticky_fifo:
713 s_type = "sticky fifo";
714 break;
715 case adg_edge_shift_register:
716 s_type = "shift register";
717 break;
718 case adg_edge_broadcast:
719 s_type = "broadcast";
720 break;
721 case adg_edge_generic:
722 s_type = "generic";
723 break;
724 default:
725 return -1;
728 if (emit_string(emitter, "type") < 0)
729 return -1;
730 if (emit_string(emitter, s_type) < 0)
731 return -1;
733 return 0;
736 int adg_edge::print(yaml_emitter_t *emitter)
738 yaml_event_t event;
740 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
741 YAML_BLOCK_MAPPING_STYLE))
742 return -1;
743 if (!yaml_emitter_emit(emitter, &event))
744 return -1;
746 if (name && emit_named_id(emitter, "name", name))
747 return -1;
748 if (emit_type(emitter, type))
749 return -1;
750 if (map && emit_named_multi_aff(emitter, "map", map))
751 return -1;
752 if (from_node_name &&
753 emit_named_id(emitter, "from_node", from_node_name))
754 return -1;
755 if (from_port_name &&
756 emit_named_id(emitter, "from_port", from_port_name))
757 return -1;
758 if (to_node_name && emit_named_id(emitter, "to_node", to_node_name))
759 return -1;
760 if (to_port_name && emit_named_id(emitter, "to_port", to_port_name))
761 return -1;
762 if (value_size)
763 emit_named_val(emitter, "value_size", value_size);
765 if (!yaml_mapping_end_event_initialize(&event))
766 return -1;
767 if (!yaml_emitter_emit(emitter, &event))
768 return -1;
770 return 0;
773 int adg_param::print(yaml_emitter_t *emitter)
775 yaml_event_t event;
777 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
778 YAML_FLOW_MAPPING_STYLE))
779 return -1;
780 if (!yaml_emitter_emit(emitter, &event))
781 return -1;
783 if (name && emit_named_id(emitter, "name", name))
784 return -1;
785 if (lb && emit_named_aff(emitter, "lb", lb))
786 return -1;
787 if (ub && emit_named_aff(emitter, "ub", ub))
788 return -1;
789 if (val && emit_named_aff(emitter, "val", val))
790 return -1;
792 if (!yaml_mapping_end_event_initialize(&event))
793 return -1;
794 if (!yaml_emitter_emit(emitter, &event))
795 return -1;
797 return 0;
800 static int emit_param_list(yaml_emitter_t *emitter,
801 const char *name, std::vector<adg_param *> &list)
803 yaml_event_t event;
805 if (list.size() == 0)
806 return 0;
808 if (emit_string(emitter, name) < 0)
809 return -1;
811 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
812 YAML_ANY_SEQUENCE_STYLE))
813 return -1;
814 if (!yaml_emitter_emit(emitter, &event))
815 return -1;
817 for (int i = 0; i < list.size(); ++i)
818 if (list[i]->print(emitter) < 0)
819 return -1;
821 if (!yaml_sequence_end_event_initialize(&event))
822 return -1;
823 if (!yaml_emitter_emit(emitter, &event))
824 return -1;
826 return 0;
829 int adg::print(yaml_emitter_t *emitter)
831 yaml_event_t event;
833 if (!yaml_mapping_start_event_initialize(&event, NULL, NULL, 1,
834 YAML_BLOCK_MAPPING_STYLE))
835 return -1;
836 if (!yaml_emitter_emit(emitter, &event))
837 return -1;
839 if (name && emit_named_id(emitter, "name", name))
840 return -1;
841 if (context && emit_named_set(emitter, "context", context))
842 return -1;
843 if (iterator_map && emit_named_map(emitter, "iterator_map", iterator_map))
844 return -1;
845 if (emit_id_list(emitter, "iterators", iterators))
846 return -1;
847 if (emit_id_list(emitter, "all_iterators", all_iterators))
848 return -1;
849 if (emit_param_list(emitter, "params", params))
850 return -1;
852 if (nodes.size() > 0) {
853 if (emit_string(emitter, "nodes") < 0)
854 return -1;
855 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
856 YAML_BLOCK_SEQUENCE_STYLE))
857 return -1;
858 if (!yaml_emitter_emit(emitter, &event))
859 return -1;
860 for (int i = 0; i < nodes.size(); ++i)
861 if (nodes[i]->print(emitter))
862 return -1;
863 if (!yaml_sequence_end_event_initialize(&event))
864 return -1;
865 if (!yaml_emitter_emit(emitter, &event))
866 return -1;
869 if (edges.size() > 0) {
870 if (emit_string(emitter, "edges") < 0)
871 return -1;
872 if (!yaml_sequence_start_event_initialize(&event, NULL, NULL, 1,
873 YAML_BLOCK_SEQUENCE_STYLE))
874 return -1;
875 if (!yaml_emitter_emit(emitter, &event))
876 return -1;
877 for (int i = 0; i < edges.size(); ++i)
878 if (edges[i]->print(emitter))
879 return -1;
880 if (!yaml_sequence_end_event_initialize(&event))
881 return -1;
882 if (!yaml_emitter_emit(emitter, &event))
883 return -1;
886 if (!yaml_mapping_end_event_initialize(&event))
887 return -1;
888 if (!yaml_emitter_emit(emitter, &event))
889 return -1;
891 return 0;
894 /* Print a YAML serialization of this to "out".
896 void adg_var::print(FILE *out)
898 yaml_emitter_t emitter;
900 if (init(&emitter, out) < 0) {
901 yaml_emitter_delete(&emitter);
902 return;
904 print(&emitter);
905 fini(&emitter);
909 /* Print a YAML serialization of this to "out".
911 void adg::print(FILE *out)
913 yaml_emitter_t emitter;
915 if (init(&emitter, out) < 0) {
916 yaml_emitter_delete(&emitter);
917 return;
919 print(&emitter);
920 fini(&emitter);