1 /* Text art visualizations within -fanalyzer.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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)
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.
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/>. */
21 #ifndef GCC_ANALYZER_ACCESS_DIAGRAM_H
22 #define GCC_ANALYZER_ACCESS_DIAGRAM_H
24 #include "text-art/canvas.h"
25 #include "text-art/theme.h"
26 #include "text-art/widget.h"
27 #include "analyzer/analyzer.h"
28 #include "analyzer/store.h"
35 bit_size_expr (const svalue
&num_bits
) : m_num_bits (num_bits
) {}
37 std::unique_ptr
<text_art::styled_string
>
38 maybe_get_formatted_str (text_art::style_manager
&sm
,
39 const region_model
&model
,
40 const char *concrete_single_bit_fmt
,
41 const char *concrete_plural_bits_fmt
,
42 const char *concrete_single_byte_fmt
,
43 const char *concrete_plural_bytes_fmt
,
44 const char *symbolic_bits_fmt
,
45 const char *symbolic_bytes_fmt
) const;
46 bool maybe_print_for_user (pretty_printer
*pp
,
47 const region_model
&model
) const;
49 const svalue
*maybe_get_as_bytes (region_model_manager
&mgr
) const;
52 const svalue
&m_num_bits
;
55 /* A range of bits within a base region, where each endpoint
56 could be concrete or symbolic (not necessarily the same). */
61 : m_start (), m_next ()
64 access_range (region_offset start
, region_offset next
,
65 region_model_manager
&mgr
)
66 : m_start (strip_types (start
, mgr
)), m_next (strip_types (next
, mgr
))
68 access_range (const region
*base_region
, const bit_range
&bits
);
69 access_range (const region
*base_region
, const byte_range
&bytes
);
70 access_range (const region
®
, region_model_manager
*);
72 bool concrete_p () const
74 return m_start
.concrete_p () && m_next
.concrete_p ();
77 bool empty_p () const;
79 bit_size_expr
get_size (region_model_manager
*mgr
) const;
81 bool get_size_in_bits (bit_size_t
*out
) const
85 *out
= m_next
.get_bit_offset () - m_start
.get_bit_offset ();
91 bool as_concrete_bit_range (bit_range
*out
) const
95 bit_size_t size
= m_next
.get_bit_offset () - m_start
.get_bit_offset ();
96 *out
= bit_range (m_start
.get_bit_offset (), size
);
99 bool as_concrete_byte_range (byte_range
*out
) const
101 bit_range
bits (0, 0);
102 if (!as_concrete_bit_range (&bits
))
104 return bits
.as_byte_range (out
);
107 bool contains_p (const access_range
&other
) const;
109 void dump_to_pp (pretty_printer
*pp
, bool) const;
110 void dump (bool) const;
111 void log (const char *title
, logger
&) const;
113 region_offset m_start
;
114 region_offset m_next
;
117 struct access_operation
119 access_operation (const region_model
&model
,
120 enum access_direction dir
,
122 const svalue
*sval_hint
)
126 m_sval_hint (sval_hint
),
127 m_base_region (reg
.get_base_region ())
130 region_model_manager
*get_manager () const
132 return m_model
.get_manager ();
135 /* Get the valid bits to access within the base region. */
136 access_range
get_valid_bits () const;
138 /* Get the actual bits accessed within the base region. */
139 access_range
get_actual_bits () const;
141 bool maybe_get_invalid_before_bits (access_range
*out
) const;
142 bool maybe_get_invalid_after_bits (access_range
*out
) const;
144 const region_model
&m_model
;
145 enum access_direction m_dir
;
147 const svalue
*m_sval_hint
;
148 const region
*m_base_region
;
151 class access_diagram
: public text_art::wrapper_widget
154 access_diagram (const access_operation
&op
,
155 diagnostic_event_id_t region_creation_event_id
,
156 text_art::style_manager
&sm
,
157 const text_art::theme
&theme
,
159 const char *get_desc () const override
161 return "access_diagram";
167 #endif /* GCC_ANALYZER_ACCESS_DIAGRAM_H */