Skip to content

Commit b5c0672

Browse files
committed
SMV: submodule type
This introduces a class to document the existing SMV submodule type.
1 parent 01ccf33 commit b5c0672

File tree

6 files changed

+58
-12
lines changed

6 files changed

+58
-12
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ IREP_ID_ONE(smv_setin)
3737
IREP_ID_ONE(smv_setnotin)
3838
IREP_ID_ONE(smv_signed_cast)
3939
IREP_ID_ONE(smv_sizeof)
40+
IREP_ID_ONE(smv_submodule)
4041
IREP_ID_ONE(smv_swconst)
4142
IREP_ID_ONE(smv_union)
4243
IREP_ID_ONE(smv_unsigned_cast)

src/smvlang/expr2smv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,9 @@ std::string type2smv(const typet &type, const namespacet &ns)
10581058
{
10591059
return "set";
10601060
}
1061-
else if(type.id()=="submodule")
1061+
else if(type.id() == ID_smv_submodule)
10621062
{
1063-
auto code = type.get_string(ID_identifier);
1063+
auto code = id2string(to_smv_submodule_type(type).identifier());
10641064
const exprt &e=(exprt &)type;
10651065
if(e.has_operands())
10661066
{

src/smvlang/parser.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "smv_expr.h"
66
#include "smv_parser.h"
77
#include "smv_typecheck.h"
8+
#include "smv_types.h"
89

910
#include <util/mathematical_types.h>
1011
#include <util/std_expr.h>
@@ -657,14 +658,14 @@ simple_type_specifier:
657658
module_type_specifier:
658659
module_name
659660
{
660-
init($$, "submodule");
661-
stack_expr($$).set(ID_identifier,
661+
init($$, ID_smv_submodule);
662+
to_smv_submodule_type(stack_type($$)).identifier(
662663
smv_module_symbol(stack_expr($1).id_string()));
663664
}
664665
| module_name '(' parameter_list ')'
665666
{
666-
init($$, "submodule");
667-
stack_expr($$).set(ID_identifier,
667+
init($$, ID_smv_submodule);
668+
to_smv_submodule_type(stack_type($$)).identifier(
668669
smv_module_symbol(stack_expr($1).id_string()));
669670
stack_expr($$).operands().swap(stack_expr($3).operands());
670671
}

src/smvlang/smv_language.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
1414
#include "expr2smv.h"
1515
#include "smv_parser.h"
1616
#include "smv_typecheck.h"
17+
#include "smv_types.h"
1718

1819
/*******************************************************************\
1920
@@ -69,8 +70,9 @@ void smv_languaget::dependencies(
6970

7071
for(smv_parse_treet::mc_varst::const_iterator it=smv_module.vars.begin();
7172
it!=smv_module.vars.end(); it++)
72-
if(it->second.type.id()=="submodule")
73-
module_set.insert(it->second.type.get_string("identifier"));
73+
if(it->second.type.id() == ID_smv_submodule)
74+
module_set.insert(
75+
id2string(to_smv_submodule_type(it->second.type).identifier()));
7476
}
7577

7678
/*******************************************************************\
@@ -145,7 +147,7 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &)
145147

146148
for(smv_parse_treet::mc_varst::const_iterator it=module.vars.begin();
147149
it!=module.vars.end(); it++)
148-
if(it->second.type.id()!="submodule")
150+
if(it->second.type.id() != ID_smv_submodule)
149151
{
150152
symbol_tablet symbol_table;
151153
namespacet ns{symbol_table};
@@ -160,7 +162,7 @@ void smv_languaget::show_parse(std::ostream &out, message_handlert &)
160162
for(smv_parse_treet::mc_varst::const_iterator
161163
it=module.vars.begin();
162164
it!=module.vars.end(); it++)
163-
if(it->second.type.id()=="submodule")
165+
if(it->second.type.id() == ID_smv_submodule)
164166
{
165167
symbol_tablet symbol_table;
166168
namespacet ns(symbol_table);

src/smvlang/smv_typecheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void smv_typecheckt::flatten_hierarchy(smv_parse_treet::modulet &smv_module)
196196
{
197197
for(auto &item : smv_module.items)
198198
{
199-
if(item.is_var() && item.expr.type().id() == "submodule")
199+
if(item.is_var() && item.expr.type().id() == ID_smv_submodule)
200200
{
201201
exprt &inst =
202202
static_cast<exprt &>(static_cast<irept &>(item.expr.type()));
@@ -2167,7 +2167,7 @@ void smv_typecheckt::create_var_symbols(
21672167
else
21682168
symbol.pretty_name = strip_smv_prefix(symbol.name);
21692169

2170-
if(symbol.type.id() == "submodule")
2170+
if(symbol.type.id() == ID_smv_submodule)
21712171
symbol.is_input = false;
21722172
else
21732173
symbol.is_input = true;

src/smvlang/smv_types.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,46 @@ inline smv_enumeration_typet &to_smv_enumeration_type(typet &type)
7171
return static_cast<smv_enumeration_typet &>(type);
7272
}
7373

74+
/// The type used for VAR declarations that are in fact module instantiations
75+
class smv_submodule_typet : public typet
76+
{
77+
public:
78+
explicit smv_submodule_typet(irep_idt _identifier) : typet{ID_smv_submodule}
79+
{
80+
identifier(_identifier);
81+
}
82+
83+
irep_idt identifier() const
84+
{
85+
return get(ID_identifier);
86+
}
87+
88+
void identifier(irep_idt _identifier)
89+
{
90+
set(ID_identifier, _identifier);
91+
}
92+
};
93+
94+
/*! \brief Cast a generic typet to a \ref smv_submodule_typet
95+
*
96+
* This is an unchecked conversion. \a type must be known to be \ref
97+
* smv_submodule_typet.
98+
*
99+
* \param type Source type
100+
* \return Object of type \ref smv_submodule_typet
101+
*
102+
* \ingroup gr_std_types
103+
*/
104+
inline const smv_submodule_typet &to_smv_submodule_type(const typet &type)
105+
{
106+
PRECONDITION(type.id() == ID_smv_submodule);
107+
return static_cast<const smv_submodule_typet &>(type);
108+
}
109+
110+
inline smv_submodule_typet &to_smv_submodule_type(typet &type)
111+
{
112+
PRECONDITION(type.id() == ID_smv_submodule);
113+
return static_cast<smv_submodule_typet &>(type);
114+
}
115+
74116
#endif // CPROVER_SMV_TYPES_H

0 commit comments

Comments
 (0)