Line data Source code
1 : /* A (base_region, symbolic bit offset) pair for representing
2 : where a region starts in memory.
3 : Copyright (C) 2026 Free Software Foundation, Inc.
4 : Contributed by David Malcolm <dmalcolm@redhat.com>.
5 :
6 : This file is part of GCC.
7 :
8 : GCC is free software; you can redistribute it and/or modify it
9 : under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3, or (at your option)
11 : any later version.
12 :
13 : GCC is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with GCC; see the file COPYING3. If not see
20 : <http://www.gnu.org/licenses/>. */
21 :
22 : #ifndef GCC_ANALYZER_SYMBOLIC_MEMORY_OFFSETS_H
23 : #define GCC_ANALYZER_SYMBOLIC_MEMORY_OFFSETS_H
24 :
25 : #include "analyzer/symbolic-ranges.h"
26 :
27 : namespace ana {
28 : namespace symbolic {
29 :
30 : /* A (base_region, symbolic bit offset) pair for representing
31 : where a region starts in memory.
32 : Note that these have a granularity of *bits*. */
33 :
34 : class memory_offset
35 : {
36 : public:
37 : using symbolic_bit_offset = symbolic::scalar<integer_with_unit<units::bit>>;
38 :
39 151566 : memory_offset (const region &base_reg,
40 : const symbolic_bit_offset &bit_offset)
41 3336 : : m_base_reg (base_reg),
42 3336 : m_bit_offset (bit_offset)
43 : {
44 : }
45 :
46 : void dump () const;
47 :
48 : bool
49 : operator== (const memory_offset &other) const
50 : {
51 : return (&m_base_reg == &other.m_base_reg
52 : && &m_bit_offset == &other.m_bit_offset);
53 : }
54 :
55 : bool
56 : operator!= (const memory_offset &other) const
57 : {
58 : return !(*this == other);
59 : }
60 :
61 : int
62 : cmp (const memory_offset &other) const;
63 :
64 : bool
65 : zero_offset_p () const
66 : {
67 : return m_bit_offset.is_zero_p ();
68 : }
69 :
70 : bool non_null_p () const;
71 :
72 : std::unique_ptr<text_art::tree_widget>
73 : make_dump_widget (node_dump_state &nds) const;
74 :
75 : void
76 : accept_node_visitor (symbolic::node_visitor &v) const;
77 :
78 : std::unique_ptr<json::object>
79 : to_json () const;
80 :
81 : const region &
82 423939 : get_base_region () const { return m_base_reg; }
83 :
84 : const symbolic_bit_offset &
85 424644 : get_bit_offset () const { return m_bit_offset; }
86 :
87 : private:
88 : const region &m_base_reg;
89 : const symbolic_bit_offset &m_bit_offset;
90 : };
91 :
92 : } // namespace ana::symbolic
93 :
94 : } // namespace ana
95 :
96 : #endif /* GCC_ANALYZER_SYMBOLIC_MEMORY_OFFSETS_H */
|