Skip to content

Commit 084fc14

Browse files
Merge pull request #3129 from peterschrammel/output-options
Functions for outputting options
2 parents ebce18a + 5b8d9a3 commit 084fc14

File tree

6 files changed

+113
-3
lines changed

6 files changed

+113
-3
lines changed
340 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
for(String arg : args) {
4+
}
5+
}
6+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--verbosity 10 --unwind 2 --disable-uncaught-exception-check --throw-assertion-error
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
assertions: "1"
8+
assumptions: "1"
9+
java-threading: "0"
10+
lazy-methods: "1"
11+
propagation: "1"
12+
refine-strings: "1"
13+
sat-preprocessor: "1"
14+
simplify: "1"
15+
simplify-if: "1"
16+
symex-driven-lazy-loading: "0"
17+
throw-assertion-error: "1"
18+
throw-runtime-exceptions: "0"
19+
uncaught-exception-check: "0"
20+
unwind: "2"
21+
--
22+
--
23+
Symex-driven lazy loading would expect symex-driven-lazy-loading: "1".

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <util/exit_codes.h>
2121
#include <util/invariant.h>
2222
#include <util/unicode.h>
23+
#include <util/xml.h>
2324
#include <util/version.h>
2425

2526
#include <langapi/language.h>
@@ -390,6 +391,9 @@ int jbmc_parse_optionst::doit()
390391
return 0; // should contemplate EX_OK from sysexits.h
391392
}
392393

394+
eval_verbosity(
395+
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);
396+
393397
//
394398
// command line options
395399
//
@@ -412,16 +416,35 @@ int jbmc_parse_optionst::doit()
412416
return 6; // should contemplate EX_SOFTWARE from sysexits.h
413417
}
414418

415-
eval_verbosity(
416-
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);
417-
418419
//
419420
// Print a banner
420421
//
421422
status() << "JBMC version " << CBMC_VERSION << " " << sizeof(void *) * 8
422423
<< "-bit " << config.this_architecture() << " "
423424
<< config.this_operating_system() << eom;
424425

426+
// output the options
427+
switch(ui_message_handler.get_ui())
428+
{
429+
case ui_message_handlert::uit::PLAIN:
430+
conditional_output(debug(), [&options](messaget::mstreamt &mstream) {
431+
mstream << "\nOptions: \n";
432+
options.output(mstream);
433+
mstream << messaget::eom;
434+
});
435+
break;
436+
case ui_message_handlert::uit::JSON_UI:
437+
{
438+
json_objectt json_options;
439+
json_options["options"] = options.to_json();
440+
debug() << json_options;
441+
break;
442+
}
443+
case ui_message_handlert::uit::XML_UI:
444+
debug() << options.to_xml();
445+
break;
446+
}
447+
425448
register_language(new_ansi_c_language);
426449
register_language(new_java_bytecode_language);
427450

src/util/options.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "options.h"
1313

14+
#include "json.h"
1415
#include "string2int.h"
16+
#include "xml.h"
1517

1618
void optionst::set_option(const std::string &option,
1719
const std::string &value)
@@ -84,3 +86,52 @@ const optionst::value_listt &optionst::get_list_option(
8486
else
8587
return it->second;
8688
}
89+
90+
/// Returns the options as JSON key value pairs
91+
json_objectt optionst::to_json() const
92+
{
93+
json_objectt json_options;
94+
for(const auto &option_pair : option_map)
95+
{
96+
json_arrayt &values = json_options[option_pair.first].make_array();
97+
for(const auto &value : option_pair.second)
98+
values.push_back(json_stringt(value));
99+
}
100+
return json_options;
101+
}
102+
103+
/// Returns the options in XML format
104+
xmlt optionst::to_xml() const
105+
{
106+
xmlt xml_options("options");
107+
for(const auto &option_pair : option_map)
108+
{
109+
xmlt &xml_option = xml_options.new_element("option");
110+
xml_option.set_attribute("name", option_pair.first);
111+
for(const auto &value : option_pair.second)
112+
{
113+
xmlt &xml_value = xml_option.new_element("value");
114+
xml_value.data = value;
115+
}
116+
}
117+
return xml_options;
118+
}
119+
120+
/// Outputs the options to `out`
121+
void optionst::output(std::ostream &out) const
122+
{
123+
for(const auto &option_pair : option_map)
124+
{
125+
out << option_pair.first << ": ";
126+
bool first = true;
127+
for(const auto &value : option_pair.second)
128+
{
129+
if(first)
130+
first = false;
131+
else
132+
out << ", ";
133+
out << '"' << value << '"';
134+
}
135+
out << "\n";
136+
}
137+
}

src/util/options.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Author: Daniel Kroening, [email protected]
1616
#include <map>
1717
#include <list>
1818

19+
class json_objectt;
20+
class xmlt;
21+
1922
class optionst
2023
{
2124
public:
@@ -55,6 +58,10 @@ class optionst
5558
return *this;
5659
}
5760

61+
json_objectt to_json() const;
62+
xmlt to_xml() const;
63+
void output(std::ostream &out) const;
64+
5865
protected:
5966
option_mapt option_map;
6067
const value_listt empty_list;

0 commit comments

Comments
 (0)