Line data Source code
1 : /* Declaration of class record_layout.
2 : Copyright (C) 2022-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it
8 : under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful, but
13 : WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_ANALYZER_RECORD_LAYOUT_H
22 : #define GCC_ANALYZER_RECORD_LAYOUT_H
23 :
24 : #include "analyzer/store.h"
25 :
26 : namespace ana {
27 :
28 : extern concrete_bit_offset
29 : get_bit_position (const_tree field);
30 :
31 : extern tree
32 : get_field_at_bit_offset (tree record_type,
33 : concrete_bit_offset bit_offset);
34 :
35 : /* Information of the layout of a RECORD_TYPE, capturing it as a vector
36 : of items, where each item is either a field or padding. */
37 :
38 4700 : class record_layout
39 : {
40 : public:
41 : /* An item within a record; either a field, or padding after a field. */
42 119748 : struct item
43 : {
44 : public:
45 23880 : item (const concrete_bit_range &br,
46 : const_tree field,
47 : bool is_padding)
48 23880 : : m_bit_range (br),
49 23880 : m_field (field),
50 23880 : m_is_padding (is_padding)
51 : {
52 : }
53 :
54 4591 : concrete_bit_offset get_start_offset () const
55 : {
56 4591 : return m_bit_range.get_start_offset ();
57 : }
58 21958 : concrete_bit_offset get_next_offset () const
59 : {
60 21958 : return m_bit_range.get_next_offset ();
61 : }
62 :
63 11712 : bool contains_p (concrete_bit_offset offset) const
64 : {
65 11712 : return m_bit_range.contains_p (offset);
66 : }
67 :
68 0 : void dump_to_pp (pretty_printer *pp) const
69 : {
70 0 : if (m_is_padding)
71 0 : pp_printf (pp, "padding after %qD", m_field);
72 : else
73 0 : pp_printf (pp, "%qD", m_field);
74 0 : pp_string (pp, ", ");
75 0 : m_bit_range.dump_to_pp (pp);
76 0 : }
77 :
78 : concrete_bit_range m_bit_range;
79 : const_tree m_field;
80 : bool m_is_padding;
81 : };
82 :
83 : record_layout (const_tree record_type);
84 :
85 : void dump_to_pp (pretty_printer *pp) const;
86 : DEBUG_FUNCTION void dump () const;
87 :
88 : const record_layout::item *get_item_at (concrete_bit_offset offset) const;
89 :
90 80 : auto begin () const { return m_items.begin (); }
91 80 : auto end () const { return m_items.end (); }
92 :
93 : private:
94 : void maybe_pad_to (concrete_bit_offset next_offset);
95 :
96 : auto_vec<item> m_items;
97 : };
98 :
99 : } // namespace ana
100 :
101 : #endif /* GCC_ANALYZER_RECORD_LAYOUT_H */
|