1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2020 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7
8 /// @file
9 ///
10 /// This file contains the declarations of the entry points to
11 /// de-serialize an instance of @ref abigail::translation_unit to an
12 /// ABI Instrumentation file in libabigail native XML format.
13
14 #ifndef __ABG_WRITER_H__
15 #define __ABG_WRITER_H__
16
17 #include "abg-fwd.h"
18
19 namespace abigail
20 {
21 namespace xml_writer
22 {
23
24 using namespace abigail::ir;
25
26 /// The style of type id the XML writer will output.
27 enum type_id_style_kind
28 {
29 SEQUENCE_TYPE_ID_STYLE,
30 HASH_TYPE_ID_STYLE
31 };
32
33 class write_context;
34
35 /// A convenience typedef for a shared pointer to write_context.
36 typedef shared_ptr<write_context> write_context_sptr;
37
38 write_context_sptr
39 create_write_context(const environment *env,
40 ostream& output_stream);
41
42 void
43 set_show_locs(write_context& ctxt, bool flag);
44
45 void
46 set_annotate(write_context& ctxt, bool flag);
47
48 void
49 set_write_architecture(write_context& ctxt, bool flag);
50
51 void
52 set_write_corpus_path(write_context& ctxt, bool flag);
53
54 void
55 set_write_comp_dir(write_context& ctxt, bool flag);
56
57 void
58 set_write_elf_needed(write_context& ctxt, bool flag);
59
60 void
61 set_write_default_sizes(write_context& ctxt, bool flag);
62
63 void
64 set_short_locs(write_context& ctxt, bool flag);
65
66 void
67 set_write_parameter_names(write_context& ctxt, bool flag);
68
69 void
70 set_type_id_style(write_context& ctxt, type_id_style_kind style);
71
72 /// A convenience generic function to set common options (usually used
73 /// by Libabigail tools) from a generic options carrying-object, into
74 /// a given @ref write_context.
75 ///
76 /// @param ctxt the @ref the write_context to consider.
77 ///
78 /// @param opts the option-carrying object to set the options from.
79 /// It must contain data members named: annotate, and show_locs, at
80 /// very least.
81 template <typename OPTS>
82 void
set_common_options(write_context & ctxt,const OPTS & opts)83 set_common_options(write_context& ctxt, const OPTS& opts)
84 {
85 set_annotate(ctxt, opts.annotate);
86 set_show_locs(ctxt, opts.show_locs);
87 set_write_architecture(ctxt, opts.write_architecture);
88 set_write_corpus_path(ctxt, opts.write_corpus_path);
89 set_write_comp_dir(ctxt, opts.write_comp_dir);
90 set_write_elf_needed(ctxt, opts.write_elf_needed);
91 set_write_parameter_names(ctxt, opts.write_parameter_names);
92 set_short_locs(ctxt, opts.short_locs);
93 set_write_default_sizes(ctxt, opts.default_sizes);
94 set_type_id_style(ctxt, opts.type_id_style);
95 }
96
97 void
98 set_ostream(write_context& ctxt, ostream& os);
99
100 bool
101 write_translation_unit(write_context& ctxt,
102 const translation_unit& tu,
103 const unsigned indent,
104 bool last = true);
105
106 bool
107 write_corpus_to_archive(const corpus& corp,
108 const string& path,
109 const bool annotate = false);
110
111 bool
112 write_corpus_to_archive(const corpus& corp,
113 const bool annotate = false);
114
115 bool
116 write_corpus_to_archive(const corpus_sptr corp,
117 const bool annotate = false);
118
119 bool
120 write_corpus(write_context& ctxt,
121 const corpus_sptr& corpus,
122 unsigned indent,
123 bool member_of_group = false);
124
125 bool
126 write_corpus_group(write_context& ctx,
127 const corpus_group_sptr& group,
128 unsigned indent);
129
130 }// end namespace xml_writer
131
132 #ifdef WITH_DEBUG_SELF_COMPARISON
133 void
134 write_canonical_type_ids(xml_writer::write_context&, ostream&);
135
136 bool
137 write_canonical_type_ids(xml_writer::write_context&,
138 const string &);
139 #endif
140
141 }// end namespace abigail
142
143 #endif // __ABG_WRITER_H__
144