Skip to content

Functions for outputting options #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added jbmc/regression/jbmc/output-options/Main.class
Binary file not shown.
6 changes: 6 additions & 0 deletions jbmc/regression/jbmc/output-options/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
for(String arg : args) {
}
}
}
23 changes: 23 additions & 0 deletions jbmc/regression/jbmc/output-options/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CORE symex-driven-lazy-loading-expected-failure
Main.class
--verbosity 10 --unwind 2 --disable-uncaught-exception-check --throw-assertion-error
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
assertions: "1"
assumptions: "1"
java-threading: "0"
lazy-methods: "1"
propagation: "1"
refine-strings: "1"
sat-preprocessor: "1"
simplify: "1"
simplify-if: "1"
symex-driven-lazy-loading: "0"
throw-assertion-error: "1"
throw-runtime-exceptions: "0"
uncaught-exception-check: "0"
unwind: "2"
--
--
Symex-driven lazy loading would expect symex-driven-lazy-loading: "1".
29 changes: 26 additions & 3 deletions jbmc/src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
#include <util/exit_codes.h>
#include <util/invariant.h>
#include <util/unicode.h>
#include <util/xml.h>
#include <util/version.h>

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

eval_verbosity(
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);

//
// command line options
//
Expand All @@ -412,16 +416,35 @@ int jbmc_parse_optionst::doit()
return 6; // should contemplate EX_SOFTWARE from sysexits.h
}

eval_verbosity(
cmdline.get_value("verbosity"), messaget::M_STATISTICS, ui_message_handler);

//
// Print a banner
//
status() << "JBMC version " << CBMC_VERSION << " " << sizeof(void *) * 8
<< "-bit " << config.this_architecture() << " "
<< config.this_operating_system() << eom;

// output the options
switch(ui_message_handler.get_ui())
{
case ui_message_handlert::uit::PLAIN:
conditional_output(debug(), [&options](messaget::mstreamt &mstream) {
mstream << "\nOptions: \n";
options.output(mstream);
mstream << messaget::eom;
});
break;
case ui_message_handlert::uit::JSON_UI:
{
json_objectt json_options;
json_options["options"] = options.to_json();
debug() << json_options;
break;
}
case ui_message_handlert::uit::XML_UI:
debug() << options.to_xml();
break;
}

register_language(new_ansi_c_language);
register_language(new_java_bytecode_language);

Expand Down
51 changes: 51 additions & 0 deletions src/util/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Author: Daniel Kroening, [email protected]

#include "options.h"

#include "json.h"
#include "string2int.h"
#include "xml.h"

void optionst::set_option(const std::string &option,
const std::string &value)
Expand Down Expand Up @@ -84,3 +86,52 @@ const optionst::value_listt &optionst::get_list_option(
else
return it->second;
}

/// Returns the options as JSON key value pairs
json_objectt optionst::to_json() const
{
json_objectt json_options;
for(const auto &option_pair : option_map)
{
json_arrayt &values = json_options[option_pair.first].make_array();
for(const auto &value : option_pair.second)
values.push_back(json_stringt(value));
}
return json_options;
}

/// Returns the options in XML format
xmlt optionst::to_xml() const
{
xmlt xml_options("options");
for(const auto &option_pair : option_map)
{
xmlt &xml_option = xml_options.new_element("option");
xml_option.set_attribute("name", option_pair.first);
for(const auto &value : option_pair.second)
{
xmlt &xml_value = xml_option.new_element("value");
xml_value.data = value;
}
}
return xml_options;
}

/// Outputs the options to `out`
void optionst::output(std::ostream &out) const
{
for(const auto &option_pair : option_map)
{
out << option_pair.first << ": ";
bool first = true;
for(const auto &value : option_pair.second)
{
if(first)
first = false;
else
out << ", ";
out << '"' << value << '"';
}
out << "\n";
}
}
7 changes: 7 additions & 0 deletions src/util/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Author: Daniel Kroening, [email protected]
#include <map>
#include <list>

class json_objectt;
class xmlt;

class optionst
{
public:
Expand Down Expand Up @@ -55,6 +58,10 @@ class optionst
return *this;
}

json_objectt to_json() const;
xmlt to_xml() const;
void output(std::ostream &out) const;

protected:
option_mapt option_map;
const value_listt empty_list;
Expand Down