Skip to content

Commit 1edf4d9

Browse files
authored
Merge pull request #4924 from MatWise/feature/stl-boolean-additions
Statement List: Language additions for boolean instructions
2 parents c71d73c + e01c4b5 commit 1edf4d9

File tree

11 files changed

+447
-172
lines changed

11 files changed

+447
-172
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FUNCTION_BLOCK "Bool5"
2+
VERSION : 0.1
3+
VAR_INPUT
4+
in1 : Bool;
5+
END_VAR
6+
7+
VAR_OUTPUT
8+
out1 : Bool;
9+
END_VAR
10+
11+
12+
BEGIN
13+
NETWORK
14+
TITLE =
15+
CLR;
16+
X #in1;
17+
XN #in1;
18+
= #out1;
19+
CALL "__CPROVER_assert"
20+
( condition := #out1
21+
);
22+
23+
END_FUNCTION_BLOCK
24+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.awl
3+
--function \"Bool5\"
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 0 of 1 failed \(1 iterations\)$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
^warning: ignoring

regression/statement-list/Function_Call/main.awl renamed to regression/statement-list/Function_Call1/main.awl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FUNCTION_BLOCK "Function_Call"
1+
FUNCTION_BLOCK "Function_Call1"
22
VERSION : 0.1
33
VAR_INPUT
44
In1 : Bool;

regression/statement-list/Function_Call/test.desc renamed to regression/statement-list/Function_Call1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.awl
33
--show-parse-tree
44
^EXIT=0$
55
^SIGNAL=0$
6-
^Name: "Function_Call"$
6+
^Name: "Function_Call1"$
77
^Version: 0[.]1$
88
^statement_list_call "__Function"$
99
^ param := In1$
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FUNCTION "Called_Function" : Void
2+
VERSION : 0.1
3+
VAR_INPUT
4+
Input : Bool;
5+
END_VAR
6+
7+
BEGIN
8+
NETWORK
9+
TITLE =
10+
11+
END_FUNCTION
12+
13+
14+
FUNCTION_BLOCK "Function_Call2"
15+
VERSION : 0.1
16+
VAR_INPUT
17+
In1 : Bool;
18+
END_VAR
19+
20+
BEGIN
21+
NETWORK
22+
TITLE =
23+
CALL "__CPROVER_assert"
24+
( condition := TRUE
25+
);
26+
27+
CALL "__CPROVER_assume"
28+
( condition := #In1
29+
);
30+
31+
CALL "__CPROVER_assert"
32+
( condition := #In1
33+
);
34+
35+
CALL "Called_Function"
36+
( Input := #In1
37+
);
38+
39+
END_FUNCTION_BLOCK
40+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.awl
3+
--function \"Function_Call2\"
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/statement-list/parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ Oom_Param_Assignment:
10801080
;
10811081

10821082
Param_Assignment:
1083-
Variable_Name TOK_ASSIGNMENT Variable_Access
1083+
Variable_Name TOK_ASSIGNMENT IL_Operand
10841084
{
10851085
newstack($$);
10861086
parser_stack($$) = equal_exprt{std::move(parser_stack($1)),

src/statement-list/statement_list_parse_tree_io.cpp

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,40 @@ Author: Matthias Weiss, [email protected]
1515
#include <util/arith_tools.h>
1616
#include <util/ieee_float.h>
1717

18+
/// String to indicate that there is no value.
1819
#define NO_VALUE "(none)"
1920

2021
/// Prints a constant to the given output stream.
21-
/// \param [out] out: Stream that should receive the result.
22+
/// \param [out] os: Stream that should receive the result.
2223
/// \param constant: Constant that shall be printed.
23-
static void output_constant(std::ostream &out, const constant_exprt &constant)
24+
static void output_constant(std::ostream &os, const constant_exprt &constant)
2425
{
2526
mp_integer ivalue;
2627
if(!to_integer(constant, ivalue))
27-
out << ivalue;
28+
os << ivalue;
2829
else if(can_cast_type<floatbv_typet>(constant.type()))
2930
{
3031
ieee_floatt real{get_real_type()};
3132
real.from_expr(constant);
32-
out << real.to_float();
33+
os << real.to_float();
3334
}
3435
else
35-
out << constant.get_value();
36+
os << constant.get_value();
37+
}
38+
39+
/// Prints the assignment of a module parameter to the given output stream.
40+
/// \param [out] os: Stream that should receive the result.
41+
/// \param assignment: Assignment that shall be printed.
42+
static void
43+
output_parameter_assignment(std::ostream &os, const equal_exprt &assignment)
44+
{
45+
os << assignment.lhs().get(ID_identifier) << " := ";
46+
const constant_exprt *const constant =
47+
expr_try_dynamic_cast<constant_exprt>(assignment.rhs());
48+
if(constant)
49+
output_constant(os, *constant);
50+
else
51+
os << assignment.rhs().get(ID_identifier);
3652
}
3753

3854
void output_parse_tree(
@@ -65,176 +81,178 @@ void output_parse_tree(
6581
}
6682

6783
void output_function_block(
68-
std::ostream &out,
84+
std::ostream &os,
6985
const statement_list_parse_treet::function_blockt &function_block)
7086
{
71-
output_tia_module_properties(function_block, out);
72-
output_common_var_declarations(out, function_block);
73-
output_static_var_declarations(out, function_block);
74-
output_network_list(out, function_block.networks);
87+
output_tia_module_properties(function_block, os);
88+
output_common_var_declarations(os, function_block);
89+
output_static_var_declarations(os, function_block);
90+
output_network_list(os, function_block.networks);
7591
}
7692

7793
void output_function(
78-
std::ostream &out,
94+
std::ostream &os,
7995
const statement_list_parse_treet::functiont &function)
8096
{
81-
output_tia_module_properties(function, out);
82-
output_return_value(function, out);
83-
output_common_var_declarations(out, function);
84-
output_network_list(out, function.networks);
97+
output_tia_module_properties(function, os);
98+
output_return_value(function, os);
99+
output_common_var_declarations(os, function);
100+
output_network_list(os, function.networks);
85101
}
86102

87103
void output_tia_module_properties(
88104
const statement_list_parse_treet::tia_modulet &module,
89-
std::ostream &out)
105+
std::ostream &os)
90106
{
91-
out << "Name: " << module.name << '\n';
92-
out << "Version: " << module.version << "\n\n";
107+
os << "Name: " << module.name << '\n';
108+
os << "Version: " << module.version << "\n\n";
93109
}
94110

95111
void output_return_value(
96112
const statement_list_parse_treet::functiont &function,
97-
std::ostream &out)
113+
std::ostream &os)
98114
{
99-
out << "Return type: ";
115+
os << "Return type: ";
100116
if(function.return_type.is_nil())
101-
out << "Void";
117+
os << "Void";
102118
else
103-
out << function.return_type.id();
104-
out << "\n\n";
119+
os << function.return_type.id();
120+
os << "\n\n";
105121
}
106122

107123
void output_common_var_declarations(
108-
std::ostream &out,
124+
std::ostream &os,
109125
const statement_list_parse_treet::tia_modulet &module)
110126
{
111127
if(!module.var_input.empty())
112128
{
113-
out << "--------- Input Variables ----------\n\n";
114-
output_var_declaration_list(out, module.var_input);
129+
os << "--------- Input Variables ----------\n\n";
130+
output_var_declaration_list(os, module.var_input);
115131
}
116132

117133
if(!module.var_inout.empty())
118134
{
119-
out << "--------- In/Out Variables ---------\n\n";
120-
output_var_declaration_list(out, module.var_inout);
135+
os << "--------- In/Out Variables ---------\n\n";
136+
output_var_declaration_list(os, module.var_inout);
121137
}
122138

123139
if(!module.var_output.empty())
124140
{
125-
out << "--------- Output Variables ---------\n\n";
126-
output_var_declaration_list(out, module.var_output);
141+
os << "--------- Output Variables ---------\n\n";
142+
output_var_declaration_list(os, module.var_output);
127143
}
128144

129145
if(!module.var_constant.empty())
130146
{
131-
out << "-------- Constant Variables --------\n\n";
132-
output_var_declaration_list(out, module.var_constant);
147+
os << "-------- Constant Variables --------\n\n";
148+
output_var_declaration_list(os, module.var_constant);
133149
}
134150

135151
if(!module.var_temp.empty())
136152
{
137-
out << "---------- Temp Variables ----------\n\n";
138-
output_var_declaration_list(out, module.var_temp);
153+
os << "---------- Temp Variables ----------\n\n";
154+
output_var_declaration_list(os, module.var_temp);
139155
}
140156
}
141157

142158
void output_static_var_declarations(
143-
std::ostream &out,
159+
std::ostream &os,
144160
const statement_list_parse_treet::function_blockt &block)
145161
{
146162
if(!block.var_static.empty())
147163
{
148-
out << "--------- Static Variables ---------\n\n";
149-
output_var_declaration_list(out, block.var_static);
164+
os << "--------- Static Variables ---------\n\n";
165+
output_var_declaration_list(os, block.var_static);
150166
}
151167
}
152168

153169
void output_var_declaration_list(
154-
std::ostream &out,
170+
std::ostream &os,
155171
const statement_list_parse_treet::var_declarationst &declarations)
156172
{
157173
for(const auto &declaration : declarations)
158174
{
159-
output_var_declaration(out, declaration);
160-
out << "\n\n";
175+
output_var_declaration(os, declaration);
176+
os << "\n\n";
161177
}
162178
}
163179

164180
void output_var_declaration(
165-
std::ostream &out,
181+
std::ostream &os,
166182
const statement_list_parse_treet::var_declarationt &declaration)
167183
{
168-
out << declaration.variable.pretty() << '\n';
169-
out << " * default_value: ";
184+
os << declaration.variable.pretty() << '\n';
185+
os << " * default_value: ";
170186
if(declaration.default_value)
171187
{
172188
const constant_exprt &constant =
173189
to_constant_expr(declaration.default_value.value());
174-
output_constant(out, constant);
190+
output_constant(os, constant);
175191
}
176192
else
177-
out << NO_VALUE;
193+
os << NO_VALUE;
178194
}
179195

180196
void output_network_list(
181-
std::ostream &out,
197+
std::ostream &os,
182198
const statement_list_parse_treet::networkst &networks)
183199
{
184-
out << "-------------- Networks --------------\n\n";
200+
os << "-------------- Networks --------------\n\n";
185201
for(const auto &network : networks)
186202
{
187-
output_network(out, network);
188-
out << '\n';
203+
output_network(os, network);
204+
os << '\n';
189205
}
190206
}
191207

192208
void output_network(
193-
std::ostream &out,
209+
std::ostream &os,
194210
const statement_list_parse_treet::networkt &network)
195211
{
196-
out << "Title: " << network.title.value_or(NO_VALUE) << '\n';
197-
out << "Instructions: ";
212+
os << "Title: " << network.title.value_or(NO_VALUE) << '\n';
213+
os << "Instructions: ";
198214
if(network.instructions.empty())
199-
out << NO_VALUE;
200-
out << '\n';
215+
os << NO_VALUE;
216+
os << '\n';
201217
for(const auto &instruction : network.instructions)
202218
{
203-
output_instruction(out, instruction);
204-
out << '\n';
219+
output_instruction(os, instruction);
220+
os << '\n';
205221
}
206222
}
207223

208224
void output_instruction(
209-
std::ostream &out,
225+
std::ostream &os,
210226
const statement_list_parse_treet::instructiont &instruction)
211227
{
212228
for(const codet &token : instruction.tokens)
213229
{
214-
out << token.get_statement();
230+
os << token.get_statement();
215231
for(const auto &expr : token.operands())
216232
{
217-
if(expr.id() == ID_symbol)
233+
const symbol_exprt *const symbol =
234+
expr_try_dynamic_cast<symbol_exprt>(expr);
235+
if(symbol)
218236
{
219-
out << '\t' << expr.get(ID_identifier);
237+
os << '\t' << symbol->get_identifier();
220238
continue;
221239
}
222240
const constant_exprt *const constant =
223241
expr_try_dynamic_cast<constant_exprt>(expr);
224242
if(constant)
225243
{
226-
out << '\t';
227-
output_constant(out, *constant);
244+
os << '\t';
245+
output_constant(os, *constant);
228246
continue;
229247
}
230-
const equal_exprt *const eq = expr_try_dynamic_cast<equal_exprt>(expr);
231-
if(eq)
248+
const equal_exprt *const equal = expr_try_dynamic_cast<equal_exprt>(expr);
249+
if(equal)
232250
{
233-
out << "\n\t" << eq->lhs().get(ID_identifier)
234-
<< " := " << eq->rhs().get(ID_identifier);
251+
os << "\n\t";
252+
output_parameter_assignment(os, *equal);
253+
continue;
235254
}
236-
else
237-
out << '\t' << expr.id();
255+
os << '\t' << expr.id();
238256
}
239257
}
240258
}

0 commit comments

Comments
 (0)