Skip to content
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

SMV: set pretty names for top-level identifiers #452

Merged
merged 1 commit into from
Apr 23, 2024
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
2 changes: 1 addition & 1 deletion regression/ebmc/BDD/BDD1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ BDD1.smv
--bdd
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] AG \(!main::var::some_var = off\): PROVED$
^\[main::spec1\] AG \(!some_var = off\): PROVED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/range_type/range_type1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ range_type1.smv
--bound 10
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] AG main::var::x != 4: PROVED up to bound 10$
^\[main::spec1\] AG x != 4: PROVED up to bound 10$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/range_type/range_type2.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ range_type2.smv
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] AG TRUE: PROVED up to bound 10$
^\[main::spec2\] AG main::var::NET_tmp9: PROVED up to bound 10$
^\[main::spec2\] AG NET_tmp9: PROVED up to bound 10$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/range_type/range_type4.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ range_type4.smv
--bound 10
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] AG \(!main::var::x = 6\): PROVED up to bound 10$
^\[main::spec1\] AG \(!x = 6\): PROVED up to bound 10$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/range_type/range_type5.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ range_type5.smv
--bound 3
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] AG \(!main::var::x = 6\): PROVED up to bound 3$
^\[main::spec1\] AG \(!x = 6\): PROVED up to bound 3$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/small-test1/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ main.smv
--bound 10 --trace
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] AG main::var::x = 1: REFUTED$
^\[main::spec1\] AG x = 1: REFUTED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/small-test2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ main.smv
--bound 2
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] AG main::var::z: REFUTED$
^\[main::spec1\] AG z: REFUTED$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/ebmc/smv/bdd_unsupported_property.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bdd_unsupported_property.smv
--bdd
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] !G main::var::x = FALSE: FAILURE: property not supported by BDD engine$
^\[main::spec2\] G main::var::x = FALSE: REFUTED$
^\[main::spec1\] !G x = FALSE: FAILURE: property not supported by BDD engine$
^\[main::spec2\] G x = FALSE: REFUTED$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/ebmc/smv/bmc_unsupported_property1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bmc_unsupported_property1.smv

^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] EG main::var::x = FALSE: FAILURE: property not supported by BMC engine$
^\[main::spec2\] G main::var::x = FALSE: REFUTED$
^\[main::spec1\] EG x = FALSE: FAILURE: property not supported by BMC engine$
^\[main::spec2\] G x = FALSE: REFUTED$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/ebmc/smv/bmc_unsupported_property2.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bmc_unsupported_property2.smv

^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] EG main::var::x = FALSE: FAILURE: property not supported by BMC engine$
^\[main::spec2\] G main::var::x = TRUE: PROVED up to bound 1$
^\[main::spec1\] EG x = FALSE: FAILURE: property not supported by BMC engine$
^\[main::spec2\] G x = TRUE: PROVED up to bound 1$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/ebmc/smv/bmc_unsupported_property3.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bmc_unsupported_property3.smv
--aig
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] !G main::var::x = FALSE: FAILURE: property not supported by netlist BMC engine$
^\[main::spec2\] G main::var::x = FALSE: REFUTED$
^\[main::spec1\] !G x = FALSE: FAILURE: property not supported by netlist BMC engine$
^\[main::spec2\] G x = FALSE: REFUTED$
--
^warning: ignoring
4 changes: 2 additions & 2 deletions regression/ebmc/smv/initial1.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CORE
initial1.smv
--bound 0
^\[main::spec1\] main::var::tmp1 = TRUE: PROVED up to bound 0$
^\[main::spec2\] main::var::tmp2 = TRUE: REFUTED$
^\[main::spec1\] tmp1 = TRUE: PROVED up to bound 0$
^\[main::spec2\] tmp2 = TRUE: REFUTED$
^EXIT=10$
^SIGNAL=0$
--
Expand Down
2 changes: 1 addition & 1 deletion regression/ebmc/smv/smv_ltlspec1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ smv_ltlspec1.smv
--bdd
^EXIT=0$
^SIGNAL=0$
^\[main::spec1\] G main::var::x != 0: PROVED$
^\[main::spec1\] G x != 0: PROVED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/ebmc/smv/smv_ltlspec2.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ smv_ltlspec2.smv
--bdd
^EXIT=0$
^SIGNAL=0$
^\[smv::main::spec1\] G F main::var::x = 3: PROVED$
^\[smv::main::spec1\] G F x = 3: PROVED$
--
^warning: ignoring
--
Expand Down
8 changes: 4 additions & 4 deletions regression/ebmc/smv/smv_ltlspec3.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ smv_ltlspec3.smv
--bound 10 --numbered-trace
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] X X main::var::x = TRUE: REFUTED$
^\[main::spec1\] X X x = TRUE: REFUTED$
^Counterexample with 3 states:$
^main::var::x@0 = FALSE$
^main::var::x@1 = FALSE$
^main::var::x@2 = FALSE$
^x@0 = FALSE$
^x@1 = FALSE$
^x@2 = FALSE$
--
^warning: ignoring
11 changes: 6 additions & 5 deletions regression/ebmc/smv/smv_ltlspec4.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ smv_ltlspec4.smv
--bound 10 --numbered-trace
^EXIT=10$
^SIGNAL=0$
^\[main::spec1\] F main::var::x = 0: REFUTED$
^main::var::x@0 = 1$
^main::var::x@1 = 2$
^main::var::x@2 = 2$
^\[main::spec2\] F main::var::x = 2: PROVED up to bound 10$
^\[main::spec1\] F x = 0: REFUTED$
^Counterexample with 3 states:$
^x@0 = 1$
^x@1 = 2$
^x@2 = 2$
^\[main::spec2\] F x = 2: PROVED up to bound 10$
--
^warning: ignoring
--
6 changes: 3 additions & 3 deletions regression/ebmc/traces/numbered1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ waveform1.smv
^SIGNAL=0$
^\[main::spec1\] .* REFUTED$
^Counterexample with 21 states:$
^main::var::y@0 = 0$
^main::var::y@10 = 100$
^main::var::y@20 = 200$
^y@0 = 0$
^y@10 = 100$
^y@20 = 200$
--
^warning: ignoring
8 changes: 4 additions & 4 deletions regression/ebmc/traces/waveform1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ waveform1.smv
^SIGNAL=0$
^\[main::spec1\] .* REFUTED$
^Counterexample:$
^ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20$
^main::var::x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20$
^main::var::y 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200$
^main::var::z 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0$
^ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20$
^x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20$
^y 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200$
^z 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0$
--
^warning: ignoring
41 changes: 25 additions & 16 deletions src/smvlang/expr2smv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ Author: Daniel Kroening, [email protected]

\*******************************************************************/

#include <cstring>
#include "expr2smv.h"

#include <util/lispexpr.h>
#include <util/lispirep.h>
#include <util/namespace.h>
#include <util/std_expr.h>

#include "expr2smv.h"
#include <util/symbol.h>

class expr2smvt
{
public:
explicit expr2smvt(const namespacet &__ns) : ns(__ns)
{
}

bool convert_nondet_choice(const exprt &src, std::string &dest, unsigned precedence);

bool convert_binary(const exprt &src, std::string &dest, const std::string &symbol, unsigned precedence);
Expand All @@ -34,7 +38,8 @@ class expr2smvt

bool convert(const exprt &src, std::string &dest);

bool convert_symbol(const exprt &src, std::string &dest, unsigned &precedence);
bool
convert_symbol(const symbol_exprt &, std::string &dest, unsigned &precedence);

bool convert_next_symbol(const exprt &src, std::string &dest, unsigned &precedence);

Expand All @@ -45,6 +50,9 @@ class expr2smvt
bool convert_norep(const exprt &src, std::string &dest, unsigned &precedence);

bool convert(const typet &src, std::string &dest);

protected:
const namespacet &ns;
};

/*
Expand Down Expand Up @@ -312,15 +320,15 @@ Function: expr2smvt::convert_symbol
\*******************************************************************/

bool expr2smvt::convert_symbol(
const exprt &src,
const symbol_exprt &src,
std::string &dest,
unsigned &precedence)
{
precedence=SMV_MAX_PRECEDENCE;
dest=src.get_string(ID_identifier);

if(strncmp(dest.c_str(), "smv::", 5)==0)
dest.erase(0, 5);

auto &symbol = ns.lookup(src);

dest = id2string(symbol.display_name());

return false;
}
Expand All @@ -343,7 +351,8 @@ bool expr2smvt::convert_next_symbol(
unsigned &precedence)
{
std::string tmp;
convert_symbol(src, tmp, precedence);
convert_symbol(
symbol_exprt{src.get(ID_identifier), src.type()}, tmp, precedence);

dest="next("+tmp+")";

Expand Down Expand Up @@ -468,7 +477,7 @@ bool expr2smvt::convert(
to_unary_expr(src), dest, src.id_string() + " ", precedence = 7);

else if(src.id()==ID_symbol)
return convert_symbol(src, dest, precedence);
return convert_symbol(to_symbol_expr(src), dest, precedence);

else if(src.id()==ID_next_symbol)
return convert_next_symbol(src, dest, precedence);
Expand Down Expand Up @@ -527,9 +536,9 @@ Function: expr2smv

\*******************************************************************/

bool expr2smv(const exprt &expr, std::string &code)
bool expr2smv(const exprt &expr, std::string &code, const namespacet &ns)
{
expr2smvt expr2smv;
expr2smvt expr2smv(ns);
return expr2smv.convert(expr, code);
}

Expand All @@ -545,14 +554,14 @@ Function: type2smv

\*******************************************************************/

bool type2smv(const typet &type, std::string &code)
bool type2smv(const typet &type, std::string &code, const namespacet &ns)
{
if(type.id()==ID_bool)
code="boolean";
else if(type.id()==ID_array)
{
std::string tmp;
if(type2smv(to_array_type(type).element_type(), tmp))
if(type2smv(to_array_type(type).element_type(), tmp, ns))
return true;
code="array ";
code+="..";
Expand Down Expand Up @@ -587,7 +596,7 @@ bool type2smv(const typet &type, std::string &code)
{
if(first) first=false; else code+=", ";
std::string tmp;
expr2smv(*it, tmp);
expr2smv(*it, tmp, ns);
code+=tmp;
}
code+=')';
Expand Down
5 changes: 2 additions & 3 deletions src/smvlang/expr2smv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ Author: Daniel Kroening, [email protected]

#include <util/expr.h>

bool expr2smv(const exprt &expr, std::string &code);
bool type2smv(const typet &type, std::string &code);

bool expr2smv(const exprt &, std::string &code, const namespacet &);
bool type2smv(const typet &, std::string &code, const namespacet &);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but rather asking about potential future work: Is bool really the appropriate return type? Shouldn't places that return true really be using UNIMPLEMENTED instead? Then the return type could instead be std::string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to send anything that that code doesn't know how to format to format_expr.

20 changes: 13 additions & 7 deletions src/smvlang/smv_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ Author: Daniel Kroening, [email protected]
\*******************************************************************/

#include "smv_language.h"
#include "smv_typecheck.h"
#include "smv_parser.h"
#include "expr2smv.h"

#include <util/namespace.h>
#include <util/symbol_table.h>

#include "expr2smv.h"
#include "smv_parser.h"
#include "smv_typecheck.h"

/*******************************************************************\

Function: smv_languaget::parse
Expand Down Expand Up @@ -153,7 +155,9 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &)
if(it->second.type.id()!="submodule")
{
std::string msg;
type2smv(it->second.type, msg);
symbol_tablet symbol_table;
namespacet ns(symbol_table);
type2smv(it->second.type, msg, ns);
out << " " << it->first << ": "
<< msg << ";" << std::endl;
}
Expand All @@ -168,7 +172,9 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &)
if(it->second.type.id()=="submodule")
{
std::string msg;
type2smv(it->second.type, msg);
symbol_tablet symbol_table;
namespacet ns(symbol_table);
Comment on lines +175 to +176
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really not have a symbol table or namespace available when invoking show_parse?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is pre typechecking.

type2smv(it->second.type, msg, ns);
out << " " << it->first << ": "
<< msg << ";" << std::endl;
}
Expand Down Expand Up @@ -201,7 +207,7 @@ Function: smv_languaget::from_expr
bool smv_languaget::from_expr(const exprt &expr, std::string &code,
const namespacet &ns)
{
return expr2smv(expr, code);
return expr2smv(expr, code, ns);
}

/*******************************************************************\
Expand All @@ -221,7 +227,7 @@ bool smv_languaget::from_type(
std::string &code,
const namespacet &ns)
{
return type2smv(type, code);
return type2smv(type, code, ns);
}

/*******************************************************************\
Expand Down
Loading