Skip to content

Commit 5e6e221

Browse files
committed
ebmc language implementation for SMV
This adds an implementation of the ebmc_languaget interface for SMV.
1 parent c35c9f3 commit 5e6e221

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

src/smvlang/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
SRC = smv_expr.cpp \
1+
SRC = smv_ebmc_language.cpp \
2+
smv_expr.cpp \
23
smv_language.cpp \
34
smv_parser.cpp \
45
smv_typecheck.cpp \

src/smvlang/smv_ebmc_language.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*******************************************************************\
2+
3+
Module: SMV Language Interface
4+
5+
Author: Daniel Kroening, dkr@amazon.com
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// SMV Language Interface
11+
12+
#include "smv_ebmc_language.h"
13+
14+
#include <util/cmdline.h>
15+
#include <util/get_module.h>
16+
#include <util/unicode.h>
17+
18+
#include <ebmc/ebmc_error.h>
19+
#include <ebmc/transition_system.h>
20+
21+
#include "smv_parser.h"
22+
#include "smv_typecheck.h"
23+
24+
#include <fstream>
25+
#include <iostream>
26+
27+
std::string smv_file_name(const cmdlinet &cmdline)
28+
{
29+
if(cmdline.args.size() == 0)
30+
throw ebmc_errort{} << "no file name given";
31+
32+
if(cmdline.args.size() >= 2)
33+
throw ebmc_errort{} << "SMV only uses a single file";
34+
35+
return cmdline.args.front();
36+
}
37+
38+
smv_parse_treet smv_ebmc_languaget::parse()
39+
{
40+
smv_parsert smv_parser{message_handler};
41+
42+
auto file_name = smv_file_name(cmdline);
43+
44+
std::ifstream infile{widen_if_needed(file_name)};
45+
46+
if(!infile)
47+
throw ebmc_errort{} << "failed to open " << file_name;
48+
49+
smv_parser.set_file(file_name);
50+
smv_parser.in = &infile;
51+
52+
if(smv_parser.parse())
53+
throw ebmc_errort{} << "parsing has failed";
54+
55+
return std::move(smv_parser.parse_tree);
56+
}
57+
58+
std::optional<transition_systemt> smv_ebmc_languaget::transition_system()
59+
{
60+
if(cmdline.isset("preprocess"))
61+
{
62+
throw ebmc_errort{} << "SMV does not use preprocessing";
63+
}
64+
65+
auto parse_tree = parse();
66+
67+
if(cmdline.isset("show-parse"))
68+
{
69+
parse_tree.show(std::cout);
70+
return {};
71+
}
72+
73+
if(
74+
cmdline.isset("show-modules") || cmdline.isset("modules-xml") ||
75+
cmdline.isset("json-modules"))
76+
{
77+
//show_modules(cmdline, message_handler);
78+
return {};
79+
}
80+
81+
if(cmdline.isset("show-module-hierarchy"))
82+
{
83+
//show_module_hierarchy(cmdline, message_handler);
84+
return {};
85+
}
86+
87+
transition_systemt result;
88+
89+
if(smv_typecheck(parse_tree, result.symbol_table, "main", message_handler))
90+
throw ebmc_errort{} << "typechecking has failed";
91+
92+
if(cmdline.isset("show-symbol-table"))
93+
{
94+
std::cout << result.symbol_table;
95+
return {};
96+
}
97+
98+
result.main_symbol =
99+
&get_module(result.symbol_table, "main", message_handler);
100+
101+
result.trans_expr =
102+
to_trans_expr(result.main_symbol->value);
103+
104+
return result;
105+
}

src/smvlang/smv_ebmc_language.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: SMV Language Interface
4+
5+
Author: Daniel Kroening, dkr@amazon.com
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// SMV Language Interface
11+
12+
#ifndef EBMC_SMV_LANGUAGE_H
13+
#define EBMC_SMV_LANGUAGE_H
14+
15+
#include <ebmc/ebmc_language.h>
16+
17+
class smv_parse_treet;
18+
19+
class smv_ebmc_languaget : public ebmc_languaget
20+
{
21+
public:
22+
smv_ebmc_languaget(cmdlinet &_cmdline, message_handlert &_message_handler)
23+
: ebmc_languaget(_cmdline, _message_handler)
24+
{
25+
}
26+
27+
// produce the transition system, and return it
28+
std::optional<transition_systemt> transition_system() override;
29+
30+
protected:
31+
smv_parse_treet parse();
32+
};
33+
34+
#endif // EBMC_SMV_LANGUAGE_H

0 commit comments

Comments
 (0)