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 : /* Information of the layout of a RECORD_TYPE, capturing it as a vector
29 : of items, where each item is either a field or padding. */
30 :
31 57 : class record_layout
32 : {
33 : public:
34 : /* An item within a record; either a field, or padding after a field. */
35 : struct item
36 : {
37 : public:
38 204 : item (const bit_range &br,
39 : const_tree field,
40 : bool is_padding)
41 204 : : m_bit_range (br),
42 204 : m_field (field),
43 204 : m_is_padding (is_padding)
44 : {
45 : }
46 :
47 110 : bit_offset_t get_start_bit_offset () const
48 : {
49 110 : return m_bit_range.get_start_bit_offset ();
50 : }
51 320 : bit_offset_t get_next_bit_offset () const
52 : {
53 320 : return m_bit_range.get_next_bit_offset ();
54 : }
55 :
56 841 : bool contains_p (bit_offset_t offset) const
57 : {
58 841 : return m_bit_range.contains_p (offset);
59 : }
60 :
61 0 : void dump_to_pp (pretty_printer *pp) const
62 : {
63 0 : if (m_is_padding)
64 0 : pp_printf (pp, "padding after %qD", m_field);
65 : else
66 0 : pp_printf (pp, "%qD", m_field);
67 0 : pp_string (pp, ", ");
68 0 : m_bit_range.dump_to_pp (pp);
69 0 : }
70 :
71 : bit_range m_bit_range;
72 : const_tree m_field;
73 : bool m_is_padding;
74 : };
75 :
76 : record_layout (const_tree record_type);
77 :
78 : void dump_to_pp (pretty_printer *pp) const;
79 : DEBUG_FUNCTION void dump () const;
80 :
81 : const record_layout::item *get_item_at (bit_offset_t offset) const;
82 :
83 80 : auto begin () const { return m_items.begin (); }
84 80 : auto end () const { return m_items.end (); }
85 :
86 : private:
87 : void maybe_pad_to (bit_offset_t next_offset);
88 :
89 : auto_vec<item> m_items;
90 : };
91 :
92 : } // namespace ana
93 :
94 : #endif /* GCC_ANALYZER_RECORD_LAYOUT_H */
|