15
15
16
16
#include < ansi-c/ansi_c_language.h>
17
17
18
+ #include < util/json.h>
19
+ #include < util/json_expr.h>
20
+
18
21
#include " bmc.h"
19
22
20
23
/* ******************************************************************\
21
24
22
- Function: bmct::show_vcc
25
+ Function: bmct::show_vcc_plain
23
26
24
27
Inputs:
25
28
@@ -29,21 +32,8 @@ Function: bmct::show_vcc
29
32
30
33
\*******************************************************************/
31
34
32
- void bmct::show_vcc (std::ostream &out)
35
+ void bmct::show_vcc_plain (std::ostream &out)
33
36
{
34
- switch (ui)
35
- {
36
- case ui_message_handlert::XML_UI:
37
- error () << " not supported" << eom;
38
- return ;
39
-
40
- case ui_message_handlert::PLAIN:
41
- break ;
42
-
43
- default :
44
- assert (false );
45
- }
46
-
47
37
out << " \n " << " VERIFICATION CONDITIONS:" << " \n " << " \n " ;
48
38
49
39
languagest languages (ns, new_ansi_c_language ());
@@ -99,6 +89,75 @@ void bmct::show_vcc(std::ostream &out)
99
89
100
90
/* ******************************************************************\
101
91
92
+ Function: bmct::show_vcc_json
93
+
94
+ Inputs:
95
+
96
+ Outputs:
97
+
98
+ Purpose:
99
+
100
+ \*******************************************************************/
101
+
102
+ void bmct::show_vcc_json (std::ostream &out)
103
+ {
104
+ json_objectt json_result;
105
+
106
+ json_arrayt &json_vccs=json_result[" vccs" ].make_array ();
107
+
108
+ languagest languages (ns, new_ansi_c_language ());
109
+
110
+ bool has_threads=equation.has_threads ();
111
+
112
+ for (symex_target_equationt::SSA_stepst::iterator
113
+ s_it=equation.SSA_steps .begin ();
114
+ s_it!=equation.SSA_steps .end ();
115
+ s_it++)
116
+ {
117
+ if (!s_it->is_assert ()) continue ;
118
+
119
+ // vcc object
120
+ json_objectt &object=json_vccs.push_back (jsont ()).make_object ();
121
+
122
+ const source_locationt &source_location=s_it->source .pc ->source_location ;
123
+ if (source_location.is_not_nil ())
124
+ object[" sourceLocation" ]=json (source_location);
125
+
126
+ const std::string &s=s_it->comment ;
127
+ if (!s.empty ())
128
+ object[" comment" ]=json_stringt (s);
129
+
130
+ // we show everything in case there are threads
131
+ symex_target_equationt::SSA_stepst::const_iterator
132
+ last_it=has_threads?equation.SSA_steps .end ():s_it;
133
+
134
+ json_arrayt &json_constraints=object[" constraints" ].make_array ();
135
+
136
+ for (symex_target_equationt::SSA_stepst::const_iterator p_it
137
+ =equation.SSA_steps .begin ();
138
+ p_it!=last_it; p_it++)
139
+ {
140
+ if ((p_it->is_assume () ||
141
+ p_it->is_assignment () ||
142
+ p_it->is_constraint ()) &&
143
+ !p_it->ignore )
144
+ {
145
+ std::string string_value;
146
+ languages.from_expr (p_it->cond_expr , string_value);
147
+ json_constraints.push_back (json_stringt (string_value));
148
+ }
149
+ }
150
+
151
+ std::string string_value;
152
+ languages.from_expr (s_it->cond_expr , string_value);
153
+ object[" expression" ]=json_stringt (string_value);
154
+ }
155
+
156
+ out << " ,\n " << json_result;
157
+ }
158
+
159
+ /* ******************************************************************\
160
+
102
161
Function: bmct::show_vcc
103
162
104
163
Inputs:
@@ -112,16 +171,34 @@ Function: bmct::show_vcc
112
171
void bmct::show_vcc ()
113
172
{
114
173
const std::string &filename=options.get_option (" outfile" );
115
-
116
- if (filename.empty () || filename==" -" )
117
- show_vcc (std::cout);
118
- else
174
+ bool have_file=!filename.empty () && filename!=" -" ;
175
+
176
+ std::ofstream of;
177
+
178
+ if (have_file)
119
179
{
120
- std::ofstream out (filename.c_str ());
121
- if (!out)
122
- std::cerr << " failed to open " << filename << std::endl;
123
- else
124
- show_vcc (out);
180
+ of.open (filename);
181
+ if (!of)
182
+ throw " failed to open file " +filename;
183
+ }
184
+
185
+ std::ostream &out=have_file?of:std::cout;
186
+
187
+ switch (ui)
188
+ {
189
+ case ui_message_handlert::XML_UI:
190
+ error () << " XML UI not supported" << eom;
191
+ return ;
192
+
193
+ case ui_message_handlert::JSON_UI:
194
+ show_vcc_json (out);
195
+ break ;
196
+
197
+ case ui_message_handlert::PLAIN:
198
+ show_vcc_plain (out);
199
+ break ;
125
200
}
126
- }
127
201
202
+ if (have_file)
203
+ of.close ();
204
+ }
0 commit comments