Skip to content

Commit b900edc

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 37f60f2 commit b900edc

17 files changed

+607
-3
lines changed

Diff for: CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ cprover_default_properties(
165165
linking
166166
pointer-analysis
167167
solvers
168+
statement-list
168169
symtab2gb
169170
testing-utils
170171
unit

Diff for: src/CMakeLists.txt

+1
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)

Diff for: src/Makefile

+2-1
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

Diff for: src/cbmc/CMakeLists.txt

+1
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
)

Diff for: src/cbmc/Makefile

+2-1
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

Diff for: src/cbmc/cbmc_languages.cpp

+3-1
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

Diff for: src/cbmc/module_dependencies.txt

+1
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

Diff for: src/statement-list/CMakeLists.txt

+14
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)

Diff for: src/statement-list/Makefile

+54
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+
+35
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+
}

Diff for: src/statement-list/converters/expr2statement_list.h

+30
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

Diff for: src/statement-list/statement_list_language.cpp

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 <util/get_base_name.h>
20+
21+
void statement_list_languaget::set_language_options(const optionst &)
22+
{
23+
return;
24+
}
25+
26+
bool statement_list_languaget::generate_support_functions(symbol_tablet &)
27+
{
28+
return false;
29+
}
30+
31+
bool statement_list_languaget::typecheck(
32+
symbol_tablet &symbol_table,
33+
const std::string &module,
34+
const bool keep_file_local)
35+
{
36+
symbol_tablet new_symbol_table;
37+
38+
if(statement_list_typecheck(
39+
parse_tree, new_symbol_table, module, get_message_handler()))
40+
return true;
41+
42+
remove_internal_symbols(
43+
new_symbol_table, this->get_message_handler(), keep_file_local);
44+
45+
if(linking(symbol_table, new_symbol_table, get_message_handler()))
46+
return true;
47+
48+
return false;
49+
}
50+
51+
bool statement_list_languaget::parse(
52+
std::istream &instream,
53+
const std::string &path)
54+
{
55+
statement_list_parser.clear();
56+
parse_path = path;
57+
statement_list_parser.set_line_no(0);
58+
statement_list_parser.set_file(path);
59+
statement_list_parser.in = &instream;
60+
statement_list_scanner_init();
61+
bool result = statement_list_parser.parse();
62+
63+
// store result
64+
statement_list_parser.swap_tree(parse_tree);
65+
66+
return result;
67+
}
68+
69+
void statement_list_languaget::show_parse(std::ostream &out)
70+
{
71+
parse_tree.output(out);
72+
}
73+
74+
bool statement_list_languaget::can_keep_file_local()
75+
{
76+
return true;
77+
}
78+
79+
bool statement_list_languaget::typecheck(
80+
symbol_tablet &symbol_table,
81+
const std::string &module)
82+
{
83+
return typecheck(symbol_table, module, true);
84+
}
85+
86+
bool statement_list_languaget::from_expr(
87+
const exprt &expr,
88+
std::string &code,
89+
const namespacet &)
90+
{
91+
code = expr2stl(expr);
92+
return false;
93+
}
94+
95+
bool statement_list_languaget::from_type(
96+
const typet &type,
97+
std::string &code,
98+
const namespacet &)
99+
{
100+
code = type2stl(type);
101+
return false;
102+
}
103+
104+
bool statement_list_languaget::type_to_name(
105+
const typet &type,
106+
std::string &name,
107+
const namespacet &ns)
108+
{
109+
return from_type(type, name, ns);
110+
}
111+
112+
bool statement_list_languaget::to_expr(
113+
const std::string &,
114+
const std::string &,
115+
exprt &,
116+
const namespacet &)
117+
{
118+
return true;
119+
}
120+
121+
statement_list_languaget::statement_list_languaget()
122+
{
123+
}
124+
125+
statement_list_languaget::~statement_list_languaget()
126+
{
127+
parse_tree.clear();
128+
}
129+
130+
void statement_list_languaget::modules_provided(std::set<std::string> &modules)
131+
{
132+
modules.insert(get_base_name(parse_path, true));
133+
}
134+
135+
std::set<std::string> statement_list_languaget::extensions() const
136+
{
137+
return {"awl"};
138+
}
139+
140+
std::unique_ptr<languaget> new_statement_list_language()
141+
{
142+
return util_make_unique<statement_list_languaget>();
143+
}
144+
145+
std::unique_ptr<languaget> statement_list_languaget::new_language()
146+
{
147+
return util_make_unique<statement_list_languaget>();
148+
}
149+
150+
std::string statement_list_languaget::id() const
151+
{
152+
return "Statement List";
153+
}
154+
155+
std::string statement_list_languaget::description() const
156+
{
157+
return "Statement List Language by Siemens";
158+
}

0 commit comments

Comments
 (0)