GCC Middle and Back End API Reference
access-diagram.h
Go to the documentation of this file.
1/* Text art visualizations within -fanalyzer.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_ANALYZER_ACCESS_DIAGRAM_H
22#define GCC_ANALYZER_ACCESS_DIAGRAM_H
23
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"
29
30namespace ana {
31
33{
34public:
36
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;
47 const region_model &model) const;
48
50
51private:
53};
54
55/* A range of bits within a base region, where each endpoint
56 could be concrete or symbolic (not necessarily the same). */
57
59{
61 : m_start (), m_next ()
62 {
63 }
69 access_range (const region *base_region, const byte_range &bytes);
71
72 bool concrete_p () const
73 {
74 return m_start.concrete_p () && m_next.concrete_p ();
75 }
76
77 bool empty_p () const;
78
80
81 bool get_size_in_bits (bit_size_t *out) const
82 {
83 if (concrete_p ())
84 {
86 return true;
87 }
88 return false;
89 }
90
92 {
93 if (!concrete_p ())
94 return false;
96 *out = bit_range (m_start.get_bit_offset (), size);
97 return true;
98 }
100 {
101 bit_range bits (0, 0);
102 if (!as_concrete_bit_range (&bits))
103 return false;
104 return bits.as_byte_range (out);
105 }
106
107 bool contains_p (const access_range &other) const;
108
109 void dump_to_pp (pretty_printer *pp, bool) const;
110 void dump (bool) const;
111 void log (const char *title, logger &) const;
112
115};
116
118{
120 enum access_direction dir,
121 const region &reg,
122 const svalue *sval_hint)
123 : m_model (model),
124 m_dir (dir),
125 m_reg (reg),
127 m_base_region (reg.get_base_region ())
128 {}
129
131 {
132 return m_model.get_manager ();
133 }
134
135 /* Get the valid bits to access within the base region. */
137
138 /* Get the actual bits accessed within the base region. */
140
143
146 const region &m_reg;
149};
150
151class access_diagram : public text_art::wrapper_widget
152{
153public:
156 text_art::style_manager &sm,
157 const text_art::theme &theme,
158 logger *logger);
159 const char *get_desc () const override
160 {
161 return "access_diagram";
162 }
163};
164
165} // namespace ana
166
167#endif /* GCC_ANALYZER_ACCESS_DIAGRAM_H */
Definition access-diagram.h:152
const char * get_desc() const override
Definition access-diagram.h:159
access_diagram(const access_operation &op, diagnostic_event_id_t region_creation_event_id, text_art::style_manager &sm, const text_art::theme &theme, logger *logger)
Definition access-diagram.h:33
const svalue * maybe_get_as_bytes(region_model_manager &mgr) const
bool maybe_print_for_user(pretty_printer *pp, const region_model &model) const
std::unique_ptr< text_art::styled_string > maybe_get_formatted_str(text_art::style_manager &sm, const region_model &model, const char *concrete_single_bit_fmt, const char *concrete_plural_bits_fmt, const char *concrete_single_byte_fmt, const char *concrete_plural_bytes_fmt, const char *symbolic_bits_fmt, const char *symbolic_bytes_fmt) const
const svalue & m_num_bits
Definition access-diagram.h:52
bit_size_expr(const svalue &num_bits)
Definition access-diagram.h:35
Definition analyzer-logging.h:34
Definition region-model-manager.h:32
Definition region-model.h:258
region_model_manager * get_manager() const
Definition region-model.h:457
Definition analyzer.h:192
bit_offset_t get_bit_offset() const
Definition analyzer.h:217
bool concrete_p() const
Definition analyzer.h:214
Definition region.h:125
Definition svalue.h:90
Definition diagnostic-event-id.h:37
Definition pretty-print.h:244
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
Definition access-diagram.h:30
access_direction
Definition analyzer.h:354
const svalue * strip_types(const svalue *sval, region_model_manager &mgr)
offset_int bit_size_t
Definition analyzer.h:180
Definition access-diagram.h:118
access_range get_valid_bits() const
const region_model & m_model
Definition access-diagram.h:144
region_model_manager * get_manager() const
Definition access-diagram.h:130
bool maybe_get_invalid_before_bits(access_range *out) const
access_range get_actual_bits() const
enum access_direction m_dir
Definition access-diagram.h:145
access_operation(const region_model &model, enum access_direction dir, const region &reg, const svalue *sval_hint)
Definition access-diagram.h:119
bool maybe_get_invalid_after_bits(access_range *out) const
const region * m_base_region
Definition access-diagram.h:148
const region & m_reg
Definition access-diagram.h:146
const svalue * m_sval_hint
Definition access-diagram.h:147
Definition access-diagram.h:59
void dump(bool) const
access_range(const region *base_region, const bit_range &bits)
access_range(const region *base_region, const byte_range &bytes)
void dump_to_pp(pretty_printer *pp, bool) const
bool as_concrete_byte_range(byte_range *out) const
Definition access-diagram.h:99
bool get_size_in_bits(bit_size_t *out) const
Definition access-diagram.h:81
void log(const char *title, logger &) const
bit_size_expr get_size(region_model_manager *mgr) const
bool contains_p(const access_range &other) const
bool as_concrete_bit_range(bit_range *out) const
Definition access-diagram.h:91
region_offset m_next
Definition access-diagram.h:114
access_range(const region &reg, region_model_manager *)
access_range()
Definition access-diagram.h:60
bool empty_p() const
region_offset m_start
Definition access-diagram.h:113
bool concrete_p() const
Definition access-diagram.h:72
access_range(region_offset start, region_offset next, region_model_manager &mgr)
Definition access-diagram.h:64
Definition store.h:231
bool as_byte_range(byte_range *out) const
Definition store.h:307