Skip to content

Commit 084f651

Browse files
committed
Integrate ST parser into CBMC executable
Includes a basic ST 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 9f4fb50 commit 084f651

12 files changed

+501
-2
lines changed

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+
structured-text \
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 structured-text.dir
6465

6566
solvers.dir: util.dir
6667

src/cbmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
4141
../xmllang/xmllang$(LIBEXT) \
4242
../assembler/assembler$(LIBEXT) \
4343
../solvers/solvers$(LIBEXT) \
44+
../structured-text/structured-text$(LIBEXT) \
4445
../util/util$(LIBEXT) \
4546
../json/json$(LIBEXT)
4647

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 <structured-text/structured_text_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_structured_text_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+
structured-text
1617
xmllang
1718
util

src/structured-text/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
SRC = converters/convert_int_value.cpp \
2+
converters/convert_real_value.cpp \
3+
converters/convert_string_value.cpp \
4+
converters/expr2structured_text.cpp \
5+
structured_text_language.cpp \
6+
structured_text_lex.yy.cpp \
7+
structured_text_parse_tree.cpp \
8+
structured_text_parser.cpp \
9+
structured_text_typecheck.cpp \
10+
structured_text_y.tab.cpp \
11+
# Empty last line
12+
13+
INCLUDES= -I ..
14+
15+
include ../config.inc
16+
include ../common
17+
18+
CLEANFILES = stl$(LIBEXT) \
19+
structured_text_y.tab.h structured_text_y.tab.cpp \
20+
structured_text_lex.yy.cpp structured_text_y.tab.cpp.output \
21+
structured_text_y.output
22+
23+
all: structured-text$(LIBEXT)
24+
25+
###############################################################################
26+
27+
structured_text_y.tab.cpp: parser.y
28+
$(YACC) $(YFLAGS) $$flags -pyystructured_text -d parser.y -o $@
29+
30+
structured_text_y.tab.h: structured_text_y.tab.cpp
31+
if [ -e structured_text_y.tab.hpp ] ; then mv structured_text_y.tab.hpp \
32+
structured_text_y.tab.h ; else mv structured_text_y.tab.cpp.h \
33+
structured_text_y.tab.h ; fi
34+
35+
structured_text_lex.yy.cpp: scanner.l
36+
$(LEX) -Pyystructured_text -o$@ scanner.l
37+
38+
# extra dependencies
39+
structured_text_y.tab$(OBJEXT): structured_text_y.tab.cpp \
40+
structured_text_y.tab.h
41+
structured_text_lex.yy$(OBJEXT): structured_text_y.tab.cpp \
42+
structured_text_lex.yy.cpp structured_text_y.tab.h
43+
44+
###############################################################################
45+
46+
generated_files: structured_text_y.tab.cpp structured_text_lex.yy.cpp \
47+
structured_text_y.tab.h
48+
49+
###############################################################################
50+
51+
structured-text$(LIBEXT): $(OBJ)
52+
$(LINKLIB)
53+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************\
2+
3+
Module: Conversion from Expression or Type to Structured Text
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "expr2structured_text.h"
10+
#include <util/symbol.h>
11+
12+
std::string expr2stl(const exprt &expr)
13+
{
14+
// TODO: Implement.
15+
return "";
16+
}
17+
18+
std::string type2stl(const typet &type)
19+
{
20+
// TODO: Implement.
21+
return "";
22+
}
23+
24+
std::string type2stl(const typet &type, const std::string &identifier)
25+
{
26+
// TODO: Implement.
27+
return "";
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*******************************************************************\
2+
3+
Module: Conversion from Expression or Type to Structured Text
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_STRUCTURED_TEXT_CONVERTERS_EXPR2STRUCTURED_TEXT_H
10+
#define CPROVER_STRUCTURED_TEXT_CONVERTERS_EXPR2STRUCTURED_TEXT_H
11+
12+
#include <string>
13+
14+
class exprt;
15+
class namespacet;
16+
class typet;
17+
18+
std::string expr2stl(const exprt &expr);
19+
20+
std::string type2stl(const typet &type);
21+
22+
std::string type2stl(const typet &type, const std::string &identifier);
23+
24+
#endif // CPROVER_STRUCTURED_TEXT_CONVERTERS_EXPR2STRUCTURED_TEXT_H
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Interface
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Interface
11+
12+
#include "structured_text_language.h"
13+
#include "converters/expr2structured_text.h"
14+
#include "structured_text_parser.h"
15+
#include "structured_text_typecheck.h"
16+
17+
#include <linking/linking.h>
18+
#include <linking/remove_internal_symbols.h>
19+
#include <util/get_base_name.h>
20+
21+
bool structured_text_languaget::generate_support_functions(
22+
symbol_tablet &symbol_table)
23+
{
24+
return false;
25+
}
26+
27+
bool structured_text_languaget::typecheck(
28+
symbol_tablet &symbol_table,
29+
const std::string &module,
30+
const bool keep_file_local)
31+
{
32+
symbol_tablet new_symbol_table;
33+
34+
if(structured_text_typecheck(
35+
parse_tree, new_symbol_table, module, get_message_handler()))
36+
{
37+
return true;
38+
}
39+
40+
remove_internal_symbols(
41+
new_symbol_table, this->get_message_handler(), keep_file_local);
42+
43+
if(linking(symbol_table, new_symbol_table, get_message_handler()))
44+
return true;
45+
46+
return false;
47+
}
48+
49+
bool structured_text_languaget::parse(
50+
std::istream &instream,
51+
const std::string &path)
52+
{
53+
structured_text_parser.clear();
54+
parse_path = path;
55+
structured_text_parser.set_line_no(0);
56+
structured_text_parser.set_file(path);
57+
structured_text_parser.in = &instream;
58+
structured_text_scanner_init();
59+
bool result = structured_text_parser.parse();
60+
61+
// store result
62+
structured_text_parser.swap_tree(parse_tree);
63+
64+
return result;
65+
}
66+
67+
void structured_text_languaget::show_parse(std::ostream &out)
68+
{
69+
parse_tree.output(out);
70+
}
71+
72+
bool structured_text_languaget::from_expr(
73+
const exprt &expr,
74+
std::string &code,
75+
const namespacet &ns)
76+
{
77+
code = expr2stl(expr);
78+
return false;
79+
}
80+
81+
bool structured_text_languaget::from_type(
82+
const typet &type,
83+
std::string &code,
84+
const namespacet &ns)
85+
{
86+
code = type2stl(type);
87+
return false;
88+
}
89+
90+
bool structured_text_languaget::type_to_name(
91+
const typet &type,
92+
std::string &name,
93+
const namespacet &ns)
94+
{
95+
return from_type(type, name, ns);
96+
}
97+
98+
bool structured_text_languaget::to_expr(
99+
const std::string &code,
100+
const std::string &module,
101+
exprt &expr,
102+
const namespacet &ns)
103+
{
104+
// unused parameters
105+
(void)code;
106+
(void)module;
107+
(void)expr;
108+
(void)ns;
109+
110+
return true;
111+
}
112+
113+
structured_text_languaget::~structured_text_languaget()
114+
{
115+
parse_tree.clear();
116+
}
117+
118+
void structured_text_languaget::modules_provided(std::set<std::string> &modules)
119+
{
120+
modules.insert(get_base_name(parse_path, true));
121+
}
122+
123+
std::set<std::string> structured_text_languaget::extensions() const
124+
{
125+
return {"awl"};
126+
}
127+
128+
std::unique_ptr<languaget> new_structured_text_language()
129+
{
130+
return util_make_unique<structured_text_languaget>();
131+
}

0 commit comments

Comments
 (0)