Skip to content

Commit 694b8cf

Browse files
author
Daniel Kroening
committed
Peter forgot to git-add show_goto_functions.cpp
1 parent f564e9c commit 694b8cf

File tree

9 files changed

+190
-80
lines changed

9 files changed

+190
-80
lines changed

src/cbmc/bmc.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
1515
#include <util/source_location.h>
1616
#include <util/time_stopping.h>
1717
#include <util/message_stream.h>
18+
#include <util/json.h>
1819

1920
#include <langapi/mode.h>
2021
#include <langapi/languages.h>
@@ -87,8 +88,14 @@ void bmct::error_trace()
8788
}
8889
break;
8990

90-
default:
91-
assert(false);
91+
case ui_message_handlert::JSON_UI:
92+
{
93+
json_objectt counterexample;
94+
jsont &json_trace=counterexample["counterexample"];
95+
convert(ns, goto_trace, json_trace);
96+
std::cout << ",\n" << counterexample << "\n";
97+
}
98+
break;
9299
}
93100

94101
const std::string graphml=options.get_option("graphml-cex");
@@ -105,22 +112,6 @@ void bmct::error_trace()
105112
write_graphml(cex_graph, out);
106113
}
107114
}
108-
109-
if(options.get_option("json-cex")!="")
110-
{
111-
jsont json_trace;
112-
convert(ns, goto_trace, json_trace);
113-
114-
if(options.get_option("json-cex")=="-")
115-
{
116-
std::cout << json_trace;
117-
}
118-
else
119-
{
120-
std::ofstream out(options.get_option("json-cex").c_str());
121-
out << json_trace << '\n';
122-
}
123-
}
124115
}
125116

126117
/*******************************************************************\
@@ -223,9 +214,14 @@ void bmct::report_success()
223214
std::cout << "\n";
224215
}
225216
break;
226-
227-
default:
228-
assert(false);
217+
218+
case ui_message_handlert::JSON_UI:
219+
{
220+
json_objectt json_result;
221+
json_result["cProverStatus"]=json_stringt("success");
222+
std::cout << ",\n" << json_result;
223+
}
224+
break;
229225
}
230226
}
231227

@@ -258,9 +254,14 @@ void bmct::report_failure()
258254
std::cout << "\n";
259255
}
260256
break;
261-
262-
default:
263-
assert(false);
257+
258+
case ui_message_handlert::JSON_UI:
259+
{
260+
json_objectt json_result;
261+
json_result["cProverStatus"]=json_stringt("failure");
262+
std::cout << ",\n" << json_result;
263+
}
264+
break;
264265
}
265266
}
266267

src/cbmc/cbmc_parse_options.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
442442

443443
if(cmdline.isset("graphml-cex"))
444444
options.set_option("graphml-cex", cmdline.get_value("graphml-cex"));
445-
446-
if(cmdline.isset("json-cex"))
447-
options.set_option("json-cex", cmdline.get_value("json-cex"));
448445
}
449446

450447
/*******************************************************************\
@@ -652,15 +649,17 @@ int cbmc_parse_optionst::get_goto_program(
652649

653650
if(!infile)
654651
{
655-
error() << "failed to open input file `" << filename << "'" << eom;
652+
error() << "failed to open input file `"
653+
<< filename << "'" << eom;
656654
return 6;
657655
}
658656

659657
languaget *language=get_language_from_filename(filename);
660658

661659
if(language==NULL)
662660
{
663-
error() << "failed to figure out type of file `" << filename << "'" << eom;
661+
error() << "failed to figure out type of file `"
662+
<< filename << "'" << eom;
664663
return 6;
665664
}
666665

@@ -715,7 +714,8 @@ int cbmc_parse_optionst::get_goto_program(
715714
{
716715
status() << "Reading GOTO program from file " << eom;
717716

718-
if(read_object_and_link(*it, symbol_table, goto_functions, get_message_handler()))
717+
if(read_object_and_link(*it, symbol_table, goto_functions,
718+
get_message_handler()))
719719
return 6;
720720
}
721721

@@ -964,6 +964,7 @@ bool cbmc_parse_optionst::process_goto_program(
964964
// show it?
965965
if(cmdline.isset("show-goto-functions"))
966966
{
967+
namespacet ns(symbol_table);
967968
goto_functions.output(ns, std::cout);
968969
return true;
969970
}
@@ -1164,5 +1165,6 @@ void cbmc_parse_optionst::help()
11641165
" --version show version and exit\n"
11651166
" --xml-ui use XML-formatted output\n"
11661167
" --xml-interface bi-directional XML interface\n"
1168+
" --json-ui use JSON-formatted output\n"
11671169
"\n";
11681170
}

src/cbmc/cbmc_parse_options.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class optionst;
3131
"(bounds-check)(pointer-check)(div-by-zero-check)(memory-leak-check)" \
3232
"(signed-overflow-check)(unsigned-overflow-check)(float-overflow-check)(nan-check)" \
3333
"(no-assertions)(no-assumptions)" \
34-
"(xml-ui)(xml-interface)" \
34+
"(xml-ui)(xml-interface)(json-ui)" \
3535
"(smt1)(smt2)(fpa)(cvc3)(cvc4)(boolector)(yices)(z3)(opensmt)(mathsat)" \
3636
"(no-sat-preprocessor)" \
3737
"(no-pretty-names)(beautify)" \
@@ -52,8 +52,8 @@ class optionst;
5252
"(arrays-uf-always)(arrays-uf-never)" \
5353
"(string-abstraction)(no-arch)(arch):" \
5454
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
55-
"(graphml-cex):(json-cex):" \
56-
"(floatbv)(all-properties)" // legacy, and will eventually disappear
55+
"(graphml-cex):" \
56+
"(floatbv)(all-claims)(all-properties)(decide)" // legacy, and will eventually disappear
5757

5858
class cbmc_parse_optionst:
5959
public parse_options_baset,

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,5 +1347,6 @@ void goto_instrument_parse_optionst::help()
13471347
" --use-system-headers with --dump-c/--dump-cpp: generate C source with includes\n"
13481348
" --version show version and exit\n"
13491349
" --xml-ui use XML-formatted output\n"
1350+
" --json-ui use JSON-formatted output\n"
13501351
"\n";
13511352
}

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Author: Daniel Kroening, [email protected]
5454
"(cav11)" \
5555
"(show-natural-loops)(accelerate)(havoc-loops)" \
5656
"(error-label):(string-abstraction)" \
57-
"(verbosity):(version)(xml-ui)(show-loops)" \
57+
"(verbosity):(version)(xml-ui)(json-ui)(show-loops)" \
5858
"(accelerate)(constant-propagator)" \
5959
"(k-induction):(step-case)(base-case)" \
6060
"(show-call-sequences)(check-call-sequence)" \

src/goto-programs/read_goto_binary.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ bool read_object_and_link(
397397
goto_functionst &functions,
398398
message_handlert &message_handler)
399399
{
400-
message_handler.print(8, "Reading: " + file_name);
400+
messaget(message_handler).statistics() << "Reading: "
401+
<< file_name << messaget::eom;
401402

402403
// we read into a temporary model
403404
goto_modelt temp_model;

src/goto-programs/show_properties.cpp

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include <iostream>
1010

1111
#include <util/xml.h>
12+
#include <util/json.h>
1213
#include <util/i2string.h>
1314
#include <util/xml_expr.h>
1415

@@ -89,6 +90,10 @@ void show_properties(
8990
std::cout << xml_property << std::endl;
9091
}
9192
break;
93+
94+
case ui_message_handlert::JSON_UI:
95+
assert(false);
96+
break;
9297

9398
case ui_message_handlert::PLAIN:
9499
std::cout << "Property " << property_id << ":" << std::endl;
@@ -106,9 +111,10 @@ void show_properties(
106111
}
107112
}
108113

114+
109115
/*******************************************************************\
110116
111-
Function: show_properties
117+
Function: cbmc_parseoptionst::show_properties_json
112118
113119
Inputs:
114120
@@ -118,17 +124,99 @@ Function: show_properties
118124
119125
\*******************************************************************/
120126

121-
void show_properties(
127+
void show_properties_json(
128+
json_arrayt &json_properties,
129+
const namespacet &ns,
130+
const irep_idt &identifier,
131+
const goto_programt &goto_program)
132+
{
133+
for(goto_programt::instructionst::const_iterator
134+
it=goto_program.instructions.begin();
135+
it!=goto_program.instructions.end();
136+
it++)
137+
{
138+
if(!it->is_assert())
139+
continue;
140+
141+
const source_locationt &source_location=it->source_location;
142+
143+
const irep_idt &comment=source_location.get_comment();
144+
//const irep_idt &function=location.get_function();
145+
const irep_idt &property_class=source_location.get_property_class();
146+
const irep_idt description=
147+
(comment==""?"assertion":comment);
148+
149+
irep_idt property_id=source_location.get_property_id();
150+
151+
json_objectt &json_property=
152+
json_properties.push_back(jsont()).make_object();
153+
json_property["name"]=json_stringt(id2string(property_id));
154+
json_property["class"]=json_stringt(id2string(property_class));
155+
#if 0 //TODO
156+
json_property["location"]=json(it->source_location);
157+
#endif
158+
json_property["description"]=json_stringt(id2string(description));
159+
json_property["expression"]=
160+
json_stringt(from_expr(ns, identifier, it->guard));
161+
}
162+
}
163+
164+
/*******************************************************************\
165+
166+
Function: show_properties_json
167+
168+
Inputs:
169+
170+
Outputs:
171+
172+
Purpose:
173+
174+
\*******************************************************************/
175+
176+
void show_properties_json(
122177
const namespacet &ns,
123-
ui_message_handlert::uit ui,
124178
const goto_functionst &goto_functions)
125179
{
180+
json_arrayt json_properties;
126181
for(goto_functionst::function_mapt::const_iterator
127182
it=goto_functions.function_map.begin();
128183
it!=goto_functions.function_map.end();
129184
it++)
185+
{
130186
if(!it->second.is_inlined())
131-
show_properties(ns, it->first, ui, it->second.body);
187+
show_properties_json(json_properties, ns, it->first, it->second.body);
188+
}
189+
json_objectt json_result;
190+
json_result["properties"] = json_properties;
191+
std::cout << ",\n" << json_result;
192+
}
193+
194+
/*******************************************************************\
195+
196+
Function: show_properties
197+
198+
Inputs:
199+
200+
Outputs:
201+
202+
Purpose:
203+
204+
\*******************************************************************/
205+
206+
void show_properties(
207+
const namespacet &ns,
208+
ui_message_handlert::uit ui,
209+
const goto_functionst &goto_functions)
210+
{
211+
if(ui == ui_message_handlert::JSON_UI)
212+
show_properties_json(ns, goto_functions);
213+
else
214+
for(goto_functionst::function_mapt::const_iterator
215+
it=goto_functions.function_map.begin();
216+
it!=goto_functions.function_map.end();
217+
it++)
218+
if(!it->second.is_inlined())
219+
show_properties(ns, it->first, ui, it->second.body);
132220
}
133221

134222
/*******************************************************************\
@@ -148,6 +236,9 @@ void show_properties(
148236
ui_message_handlert::uit ui)
149237
{
150238
const namespacet ns(goto_model.symbol_table);
151-
show_properties(ns, ui, goto_model.goto_functions);
239+
if(ui == ui_message_handlert::JSON_UI)
240+
show_properties_json(ns, goto_model.goto_functions);
241+
else
242+
show_properties(ns, ui, goto_model.goto_functions);
152243
}
153244

src/langapi/language_ui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ static ui_message_handlert::uit get_ui_cmdline(const cmdlinet &cmdline)
3636
if(cmdline.isset("xml-ui"))
3737
return ui_message_handlert::XML_UI;
3838

39+
if(cmdline.isset("json-ui"))
40+
return ui_message_handlert::JSON_UI;
41+
3942
return ui_message_handlert::PLAIN;
4043
}
4144

0 commit comments

Comments
 (0)