Skip to content

Commit e95dd2b

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

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_expr.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,35 @@ inline smv_identifier_exprt &to_smv_identifier_expr(exprt &expr)
362362
return static_cast<smv_identifier_exprt &>(expr);
363363
}
364364

365+
class smv_submodule_typet : public typet
366+
{
367+
public:
368+
explicit smv_submodule_typet(irep_idt _identifier) : typet{ID_smv_submodule}
369+
{
370+
identifier(_identifier);
371+
}
372+
373+
irep_idt identifier() const
374+
{
375+
return get(ID_identifier);
376+
}
377+
378+
void identifier(irep_idt _identifier)
379+
{
380+
set(ID_identifier, _identifier);
381+
}
382+
};
383+
384+
inline const smv_submodule_typet &to_smv_submodule_type(const typet &type)
385+
{
386+
PRECONDITION(type.id() == ID_smv_submodule);
387+
return static_cast<const smv_submodule_typet &>(type);
388+
}
389+
390+
inline smv_submodule_typet &to_smv_submodule_type(typet &type)
391+
{
392+
PRECONDITION(type.id() == ID_smv_submodule);
393+
return static_cast<smv_submodule_typet &>(type);
394+
}
395+
365396
#endif // CPROVER_SMV_EXPR_H

src/smvlang/smv_language.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include <util/symbol_table.h>
1313

1414
#include "expr2smv.h"
15+
#include "smv_expr.h"
1516
#include "smv_parser.h"
1617
#include "smv_typecheck.h"
1718

@@ -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;

0 commit comments

Comments
 (0)