Skip to content

Commit 832d761

Browse files
committed
Integrate STL parser into CBMC executable
Includes a basic Statement List language interface (although without any typechecking yet) as well as modifications to some Makefiles and cbmc_languages.cpp. Use the --show-parse-tree option when parsing a .awl file to see the project's output.
1 parent 9759ca5 commit 832d761

17 files changed

+608
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ cprover_default_properties(
162162
linking
163163
pointer-analysis
164164
solvers
165+
statement-list
165166
symtab2gb
166167
testing-utils
167168
unit

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ add_subdirectory(langapi)
9696
add_subdirectory(linking)
9797
add_subdirectory(pointer-analysis)
9898
add_subdirectory(solvers)
99+
add_subdirectory(statement-list)
99100
add_subdirectory(util)
100101

101102
add_subdirectory(cbmc)

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DIRS = analyses \
2020
memory-analyzer \
2121
pointer-analysis \
2222
solvers \
23+
statement-list \
2324
symtab2gb \
2425
util \
2526
xmllang \
@@ -60,7 +61,7 @@ cpp.dir: ansi-c.dir linking.dir
6061

6162
languages: util.dir langapi.dir \
6263
cpp.dir ansi-c.dir xmllang.dir assembler.dir \
63-
jsil.dir json.dir json-symtab-language.dir
64+
jsil.dir json.dir json-symtab-language.dir statement-list.dir
6465

6566
solvers.dir: util.dir
6667

src/cbmc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_link_libraries(cbmc-lib
2323
linking
2424
pointer-analysis
2525
solvers
26+
statement-list
2627
util
2728
xml
2829
)

src/cbmc/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
88
../cpp/cpp$(LIBEXT) \
99
../json/json$(LIBEXT) \
1010
../json-symtab-language/json-symtab-language$(LIBEXT) \
11+
../statement-list/statement-list$(LIBEXT) \
1112
../linking/linking$(LIBEXT) \
1213
../big-int/big-int$(LIBEXT) \
1314
../goto-checker/goto-checker$(LIBEXT) \
@@ -41,7 +42,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
4142
../xmllang/xmllang$(LIBEXT) \
4243
../assembler/assembler$(LIBEXT) \
4344
../solvers/solvers$(LIBEXT) \
44-
../util/util$(LIBEXT)
45+
../util/util$(LIBEXT) \
4546

4647
INCLUDES= -I ..
4748

src/cbmc/cbmc_languages.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ Author: Daniel Kroening, [email protected]
1616
#include <ansi-c/ansi_c_language.h>
1717
#include <cpp/cpp_language.h>
1818
#include <json-symtab-language/json_symtab_language.h>
19+
#include <statement-list/statement_list_language.h>
1920

2021
#ifdef HAVE_JSIL
21-
#include <jsil/jsil_language.h>
22+
# include <jsil/jsil_language.h>
2223
#endif
2324

2425
void cbmc_parse_optionst::register_languages()
2526
{
2627
register_language(new_ansi_c_language);
28+
register_language(new_statement_list_language);
2729
register_language(new_cpp_language);
2830
register_language(new_json_symtab_language);
2931

src/cbmc/module_dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ langapi # should go away
1313
linking
1414
pointer-analysis
1515
solvers
16+
statement-list
1617
xmllang
1718
util

src/statement-list/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generic_bison(statement_list)
2+
generic_flex(statement_list)
3+
4+
file(GLOB_RECURSE sources "*.cpp" "*.h")
5+
6+
add_library(statement-list
7+
${sources}
8+
${BISON_parser_OUTPUTS}
9+
${FLEX_scanner_OUTPUTS}
10+
)
11+
12+
generic_includes(statement-list)
13+
14+
target_link_libraries(statement-list util)

src/statement-list/Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
SRC = converters/convert_bool_literal.cpp \
2+
converters/convert_int_literal.cpp \
3+
converters/convert_real_literal.cpp \
4+
converters/convert_string_value.cpp \
5+
converters/expr2statement_list.cpp \
6+
statement_list_language.cpp \
7+
statement_list_lex.yy.cpp \
8+
statement_list_parse_tree.cpp \
9+
statement_list_parser.cpp \
10+
statement_list_typecheck.cpp \
11+
statement_list_y.tab.cpp \
12+
# Empty last line
13+
14+
INCLUDES= -I ..
15+
16+
include ../config.inc
17+
include ../common
18+
19+
CLEANFILES = stl$(LIBEXT) \
20+
statement_list_y.tab.h statement_list_y.tab.cpp \
21+
statement_list_lex.yy.cpp statement_list_y.tab.cpp.output \
22+
statement_list_y.output
23+
24+
all: statement-list$(LIBEXT)
25+
26+
###############################################################################
27+
28+
statement_list_y.tab.cpp: parser.y
29+
$(YACC) $(YFLAGS) $$flags -pyystatement_list -d parser.y -o $@
30+
31+
statement_list_y.tab.h: statement_list_y.tab.cpp
32+
if [ -e statement_list_y.tab.hpp ] ; then mv statement_list_y.tab.hpp \
33+
statement_list_y.tab.h ; else mv statement_list_y.tab.cpp.h \
34+
statement_list_y.tab.h ; fi
35+
36+
statement_list_lex.yy.cpp: scanner.l
37+
$(LEX) -Pyystatement_list -o$@ scanner.l
38+
39+
# extra dependencies
40+
statement_list_y.tab$(OBJEXT): statement_list_y.tab.cpp \
41+
statement_list_y.tab.h
42+
statement_list_lex.yy$(OBJEXT): statement_list_y.tab.cpp \
43+
statement_list_lex.yy.cpp statement_list_y.tab.h
44+
45+
###############################################################################
46+
47+
generated_files: statement_list_y.tab.cpp statement_list_lex.yy.cpp \
48+
statement_list_y.tab.h
49+
50+
###############################################################################
51+
52+
statement-list$(LIBEXT): $(OBJ)
53+
$(LINKLIB)
54+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************\
2+
3+
Module: Conversion from Expression or Type to Statement List
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "expr2statement_list.h"
10+
11+
#include <util/symbol.h>
12+
13+
std::string expr2stl(const exprt &expr)
14+
{
15+
// TODO: Implement expr2stl.
16+
// Expand this section so that it is able to properly convert from
17+
// CBMC expressions to STL code.
18+
return expr.pretty();
19+
}
20+
21+
std::string type2stl(const typet &type)
22+
{
23+
// TODO: Implement type2stl.
24+
// Expand this section so that it is able to properly convert from
25+
// CBMC types to STL code.
26+
return type.pretty();
27+
}
28+
29+
std::string type2stl(const typet &type, const std::string &identifier)
30+
{
31+
// TODO: Implement type2stl.
32+
// Expand this section so that it is able to properly convert from
33+
// CBMC types to STL code.
34+
return type.pretty();
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************\
2+
3+
Module: Conversion from Expression or Type to Statement List Language
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_STATEMENT_LIST_CONVERTERS_EXPR2STATEMENT_LIST_H
10+
#define CPROVER_STATEMENT_LIST_CONVERTERS_EXPR2STATEMENT_LIST_H
11+
12+
#include <string>
13+
14+
/// Converts a given expression to human-readable STL code.
15+
/// \param expr: Expression to be converted.
16+
/// \result String with the STL representation of the given parameters.
17+
std::string expr2stl(const class exprt &expr);
18+
19+
/// Converts a given type to human-readable STL code.
20+
/// \param type: Type to be converted.
21+
/// \result String with the STL representation of the given type.
22+
std::string type2stl(const class typet &type);
23+
24+
/// Converts a given type and identifier to human-readable STL code.
25+
/// \param type: Type to be converted.
26+
/// \param identifier: Identifier to be converted.
27+
/// \result String with the STL representation of the given parameters.
28+
std::string type2stl(const class typet &type, const std::string &identifier);
29+
30+
#endif // CPROVER_STATEMENT_LIST_CONVERTERS_EXPR2STATEMENT_LIST_H
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*******************************************************************\
2+
3+
Module: Statement List Language Interface
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Statement List Language Interface
11+
12+
#include "statement_list_language.h"
13+
#include "converters/expr2statement_list.h"
14+
#include "statement_list_parser.h"
15+
#include "statement_list_typecheck.h"
16+
17+
#include <linking/linking.h>
18+
#include <linking/remove_internal_symbols.h>
19+
#include <memory>
20+
#include <util/get_base_name.h>
21+
22+
void statement_list_languaget::set_language_options(const optionst &)
23+
{
24+
return;
25+
}
26+
27+
bool statement_list_languaget::generate_support_functions(symbol_tablet &)
28+
{
29+
return false;
30+
}
31+
32+
bool statement_list_languaget::typecheck(
33+
symbol_tablet &symbol_table,
34+
const std::string &module,
35+
const bool keep_file_local)
36+
{
37+
symbol_tablet new_symbol_table;
38+
39+
if(statement_list_typecheck(
40+
parse_tree, new_symbol_table, module, get_message_handler()))
41+
return true;
42+
43+
remove_internal_symbols(
44+
new_symbol_table, this->get_message_handler(), keep_file_local);
45+
46+
if(linking(symbol_table, new_symbol_table, get_message_handler()))
47+
return true;
48+
49+
return false;
50+
}
51+
52+
bool statement_list_languaget::parse(
53+
std::istream &instream,
54+
const std::string &path)
55+
{
56+
statement_list_parser.clear();
57+
parse_path = path;
58+
statement_list_parser.set_line_no(0);
59+
statement_list_parser.set_file(path);
60+
statement_list_parser.in = &instream;
61+
statement_list_scanner_init();
62+
bool result = statement_list_parser.parse();
63+
64+
// store result
65+
statement_list_parser.swap_tree(parse_tree);
66+
67+
return result;
68+
}
69+
70+
void statement_list_languaget::show_parse(std::ostream &out)
71+
{
72+
parse_tree.output(out);
73+
}
74+
75+
bool statement_list_languaget::can_keep_file_local()
76+
{
77+
return true;
78+
}
79+
80+
bool statement_list_languaget::typecheck(
81+
symbol_tablet &symbol_table,
82+
const std::string &module)
83+
{
84+
return typecheck(symbol_table, module, true);
85+
}
86+
87+
bool statement_list_languaget::from_expr(
88+
const exprt &expr,
89+
std::string &code,
90+
const namespacet &)
91+
{
92+
code = expr2stl(expr);
93+
return false;
94+
}
95+
96+
bool statement_list_languaget::from_type(
97+
const typet &type,
98+
std::string &code,
99+
const namespacet &)
100+
{
101+
code = type2stl(type);
102+
return false;
103+
}
104+
105+
bool statement_list_languaget::type_to_name(
106+
const typet &type,
107+
std::string &name,
108+
const namespacet &ns)
109+
{
110+
return from_type(type, name, ns);
111+
}
112+
113+
bool statement_list_languaget::to_expr(
114+
const std::string &,
115+
const std::string &,
116+
exprt &,
117+
const namespacet &)
118+
{
119+
return true;
120+
}
121+
122+
statement_list_languaget::statement_list_languaget()
123+
{
124+
}
125+
126+
statement_list_languaget::~statement_list_languaget()
127+
{
128+
parse_tree.clear();
129+
}
130+
131+
void statement_list_languaget::modules_provided(std::set<std::string> &modules)
132+
{
133+
modules.insert(get_base_name(parse_path, true));
134+
}
135+
136+
std::set<std::string> statement_list_languaget::extensions() const
137+
{
138+
return {"awl"};
139+
}
140+
141+
std::unique_ptr<languaget> new_statement_list_language()
142+
{
143+
return util_make_unique<statement_list_languaget>();
144+
}
145+
146+
std::unique_ptr<languaget> statement_list_languaget::new_language()
147+
{
148+
return util_make_unique<statement_list_languaget>();
149+
}
150+
151+
std::string statement_list_languaget::id() const
152+
{
153+
return "Statement List";
154+
}
155+
156+
std::string statement_list_languaget::description() const
157+
{
158+
return "Statement List Language by Siemens";
159+
}

0 commit comments

Comments
 (0)