CBMC
Loading...
Searching...
No Matches
show_vcc.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Output of the verification conditions (VCCs)
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "show_vcc.h"
13
14#include <util/format_expr.h>
15#include <util/json_irep.h>
16#include <util/output_file.h>
17#include <util/ui_message.h>
18
20
24static void
26{
27 bool has_threads = equation.has_threads();
28 bool first = true;
29
30 for(symex_target_equationt::SSA_stepst::const_iterator s_it =
31 equation.SSA_steps.begin();
32 s_it != equation.SSA_steps.end();
33 s_it++)
34 {
35 if(!s_it->is_assert())
36 continue;
37
38 if(first)
39 first = false;
40 else
41 out << '\n';
42
43 if(s_it->source.pc->source_location().is_not_nil())
44 out << s_it->source.pc->source_location() << '\n';
45
46 if(!s_it->comment.empty())
47 out << s_it->comment << '\n';
48
49 symex_target_equationt::SSA_stepst::const_iterator p_it =
50 equation.SSA_steps.begin();
51
52 // we show everything in case there are threads
53 symex_target_equationt::SSA_stepst::const_iterator last_it =
54 has_threads ? equation.SSA_steps.end() : s_it;
55
56 for(std::size_t count = 1; p_it != last_it; p_it++)
57 if(p_it->is_assume() || p_it->is_assignment() || p_it->is_constraint())
58 {
59 if(!p_it->ignore)
60 {
61 out << messaget::faint << "{-" << count << "} " << messaget::reset
62 << format(p_it->cond_expr) << '\n';
63
64#ifdef DEBUG
65 out << "GUARD: " << format(p_it->guard) << '\n';
66 out << '\n';
67#endif
68
69 count++;
70 }
71 }
72
73 // Unicode equivalent of "|--------------------------"
74 out << messaget::faint << u8"\u251c";
75 for(unsigned i = 0; i < 26; i++)
76 out << u8"\u2500";
77 out << messaget::reset << '\n';
78
79 // split property into multiple disjunts, if applicable
81
82 if(s_it->cond_expr.id() == ID_or)
83 disjuncts = to_or_expr(s_it->cond_expr).operands();
84 else
85 disjuncts.push_back(s_it->cond_expr);
86
87 std::size_t count = 1;
88 for(const auto &disjunct : disjuncts)
89 {
90 out << messaget::faint << '{' << count << "} " << messaget::reset
91 << format(disjunct) << '\n';
92 count++;
93 }
94
95 out << messaget::eom;
96 }
97}
98
107static void
108show_vcc_json(std::ostream &out, const symex_target_equationt &equation)
109{
111
112 json_arrayt &json_vccs = json_result["vccs"].make_array();
113
114 bool has_threads = equation.has_threads();
115
116 for(symex_target_equationt::SSA_stepst::const_iterator s_it =
117 equation.SSA_steps.begin();
118 s_it != equation.SSA_steps.end();
119 s_it++)
120 {
121 if(!s_it->is_assert())
122 continue;
123
124 // vcc object
125 json_objectt &object = json_vccs.push_back(jsont()).make_object();
126
127 const source_locationt &source_location =
128 s_it->source.pc->source_location();
129 if(source_location.is_not_nil())
130 object["sourceLocation"] = json(source_location);
131
132 const std::string &s = s_it->comment;
133 if(!s.empty())
134 object["comment"] = json_stringt(s);
135
136 // we show everything in case there are threads
137 symex_target_equationt::SSA_stepst::const_iterator last_it =
138 has_threads ? equation.SSA_steps.end() : s_it;
139
140 json_arrayt &json_constraints = object["constraints"].make_array();
141
142 for(symex_target_equationt::SSA_stepst::const_iterator p_it =
143 equation.SSA_steps.begin();
144 p_it != last_it;
145 p_it++)
146 {
147 if(
148 (p_it->is_assume() || p_it->is_assignment() || p_it->is_constraint()) &&
149 !p_it->ignore)
150 {
151 std::ostringstream string_value;
152 string_value << format(p_it->cond_expr);
154 }
155 }
156
157 std::ostringstream string_value;
158 string_value << format(s_it->cond_expr);
159 object["expression"] = json_stringt(string_value.str());
160 }
161
162 out << ",\n" << json_result;
163}
164
166 const optionst &options,
167 ui_message_handlert &ui_message_handler,
168 const symex_target_equationt &equation)
169{
170 messaget msg(ui_message_handler);
171
172 const std::string &filename = options.get_option("outfile");
173
174 output_filet output_file{filename.empty() ? "-" : filename};
175 bool have_file = output_file.is_file();
176
177 std::ostream &out = output_file.stream();
178
179 switch(ui_message_handler.get_ui())
180 {
182 msg.error() << "XML UI not supported" << messaget::eom;
183 return;
184
186 show_vcc_json(out, equation);
187 break;
188
190 if(have_file)
191 {
192 msg.status() << "Verification conditions written to file"
193 << messaget::eom;
196 show_vcc_plain(mout.status(), equation);
197 }
198 else
199 {
200 msg.status() << "VERIFICATION CONDITIONS:\n" << messaget::eom;
201 show_vcc_plain(msg.status(), equation);
202 }
203 break;
204 }
205}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
std::vector< exprt > operandst
Definition expr.h:59
bool is_not_nil() const
Definition irep.h:372
Definition json.h:27
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
static const commandt reset
return to default formatting, as defined by the terminal
Definition message.h:335
static const commandt faint
render text with faint font
Definition message.h:377
static eomt eom
Definition message.h:289
const std::string get_option(const std::string &option) const
Definition options.cpp:67
RAII container for an output stream that is either stdout or a file.
Definition output_file.h:22
Inheriting the interface of symex_targett this class represents the SSA form of the input program as ...
virtual uit get_ui() const
Definition ui_message.h:33
static format_containert< T > format(const T &o)
Definition format.h:37
Output file container that handles stdout ("-") and regular files.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
static void show_vcc_plain(messaget::mstreamt &out, const symex_target_equationt &equation)
Output equations from equation in plain text format to the given output stream out.
Definition show_vcc.cpp:25
static void show_vcc_json(std::ostream &out, const symex_target_equationt &equation)
Output equations from equation in the JSON format to the given output stream out.
Definition show_vcc.cpp:108
void show_vcc(const optionst &options, ui_message_handlert &ui_message_handler, const symex_target_equationt &equation)
Output equations from equation to a file or to the standard output.
Definition show_vcc.cpp:165
Output of the verification conditions (VCCs)
const or_exprt & to_or_expr(const exprt &expr)
Cast an exprt to a or_exprt.
Definition std_expr.h:2230
Generate Equation using Symbolic Execution.