Skip to content

Commit 80349c4

Browse files
committed
SMV: submodule type
This introduces a class to document the existing SMV submodule type.
1 parent 2be0696 commit 80349c4

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

src/hw_cbmc_irep_ids.h

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

src/smvlang/expr2smv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,9 @@ std::string type2smv(const typet &type, const namespacet &ns)
10201020
{
10211021
return "set";
10221022
}
1023-
else if(type.id()=="submodule")
1023+
else if(type.id() == ID_smv_submodule)
10241024
{
1025-
auto code = type.get_string(ID_identifier);
1025+
auto code = id2string(to_smv_submodule_type(type).identifier());
10261026
const exprt &e=(exprt &)type;
10271027
if(e.has_operands())
10281028
{

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, [email protected]
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()));
@@ -2103,7 +2103,7 @@ void smv_typecheckt::create_var_symbols(
21032103
else
21042104
symbol.pretty_name = strip_smv_prefix(symbol.name);
21052105

2106-
if(symbol.type.id() == "submodule")
2106+
if(symbol.type.id() == ID_smv_submodule)
21072107
symbol.is_input = false;
21082108
else
21092109
symbol.is_input = true;

src/smvlang/smv_types.h

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

74+
class smv_submodule_typet : public typet
75+
{
76+
public:
77+
explicit smv_submodule_typet(irep_idt _identifier) : typet{ID_smv_submodule}
78+
{
79+
identifier(_identifier);
80+
}
81+
82+
irep_idt identifier() const
83+
{
84+
return get(ID_identifier);
85+
}
86+
87+
void identifier(irep_idt _identifier)
88+
{
89+
set(ID_identifier, _identifier);
90+
}
91+
};
92+
93+
inline const smv_submodule_typet &to_smv_submodule_type(const typet &type)
94+
{
95+
PRECONDITION(type.id() == ID_smv_submodule);
96+
return static_cast<const smv_submodule_typet &>(type);
97+
}
98+
99+
inline smv_submodule_typet &to_smv_submodule_type(typet &type)
100+
{
101+
PRECONDITION(type.id() == ID_smv_submodule);
102+
return static_cast<smv_submodule_typet &>(type);
103+
}
104+
74105
#endif // CPROVER_SMV_TYPES_H

0 commit comments

Comments
 (0)