Skip to content

Commit 7051df5

Browse files
Merge pull request #4855 from thomasspriggs/tas/iot
Add `code_inputt` and `code_outputt` for `ID_input` and `ID_output`
2 parents acb3aba + 0617618 commit 7051df5

File tree

15 files changed

+186
-90
lines changed

15 files changed

+186
-90
lines changed

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
311311

312312
// we iterate through all the parameters of the function under test, allocate
313313
// an object for that parameter (recursively allocating other objects
314-
// necessary to initialize it), and declare such object as an ID_input
314+
// necessary to initialize it), and mark such object using `code_inputt`.
315315
for(std::size_t param_number=0;
316316
param_number<parameters.size();
317317
param_number++)
@@ -420,17 +420,8 @@ std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
420420
}
421421

422422
// record as an input
423-
codet input(ID_input);
424-
input.operands().resize(2);
425-
input.op0()=
426-
address_of_exprt(
427-
index_exprt(
428-
string_constantt(base_name),
429-
from_integer(0, index_type())));
430-
input.op1()=main_arguments[param_number];
431-
input.add_source_location()=function.location;
432-
433-
init_code.add(std::move(input));
423+
init_code.add(
424+
code_inputt{base_name, main_arguments[param_number], function.location});
434425
}
435426

436427
return make_pair(init_code, main_arguments);
@@ -467,13 +458,8 @@ static optionalt<codet> record_return_value(
467458
const symbolt &return_symbol =
468459
symbol_table.lookup_ref(JAVA_ENTRY_POINT_RETURN_SYMBOL);
469460

470-
codet output(ID_output);
471-
output.operands().resize(2);
472-
output.op0() = address_of_exprt(index_exprt(
473-
string_constantt(return_symbol.base_name), from_integer(0, index_type())));
474-
output.op1() = return_symbol.symbol_expr();
475-
output.add_source_location() = function.location;
476-
return output;
461+
return code_outputt{
462+
return_symbol.base_name, return_symbol.symbol_expr(), function.location};
477463
}
478464

479465
static code_blockt record_pointer_parameters(
@@ -495,14 +481,8 @@ static code_blockt record_pointer_parameters(
495481
if(!can_cast_type<pointer_typet>(p_symbol.type))
496482
continue;
497483

498-
codet output(ID_output);
499-
output.operands().resize(2);
500-
output.op0() = address_of_exprt(index_exprt(
501-
string_constantt(p_symbol.base_name), from_integer(0, index_type())));
502-
output.op1() = arguments[param_number];
503-
output.add_source_location() = function.location;
504-
505-
init_code.add(std::move(output));
484+
init_code.add(code_outputt{
485+
p_symbol.base_name, arguments[param_number], function.location});
506486
}
507487
return init_code;
508488
}
@@ -511,20 +491,13 @@ static codet record_exception(
511491
const symbolt &function,
512492
const symbol_table_baset &symbol_table)
513493
{
514-
// record exceptional return variable as output
515-
codet output(ID_output);
516-
output.operands().resize(2);
517-
518494
// retrieve the exception variable
519495
const symbolt &exc_symbol =
520496
symbol_table.lookup_ref(JAVA_ENTRY_POINT_EXCEPTION_SYMBOL);
521497

522-
output.op0()=address_of_exprt(
523-
index_exprt(string_constantt(exc_symbol.base_name),
524-
from_integer(0, index_type())));
525-
output.op1()=exc_symbol.symbol_expr();
526-
output.add_source_location()=function.location;
527-
return output;
498+
// record exceptional return variable as output
499+
return code_outputt{
500+
exc_symbol.base_name, exc_symbol.symbol_expr(), function.location};
528501
}
529502

530503
main_function_resultt get_main_symbol(

jbmc/src/java_bytecode/java_entry_point.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ using build_argumentst =
3333
///
3434
/// 1. Allocates and initializes the parameters of the method under test.
3535
/// 2. Call it and save its return variable in the variable 'return'.
36-
/// 3. Declare variable 'return' as an output variable (codet with id
37-
/// ID_output), together with other objects possibly altered by the execution
36+
/// 3. Declare variable 'return' as an output variable using a `code_outputt`,
37+
/// together with other objects possibly altered by the execution of
3838
/// the method under test (in `java_record_outputs`)
3939
///
4040
/// When \p assume_init_pointers_not_null is false, the generated parameter

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,11 @@ void record_function_outputs(
5959

6060
if(has_return_value)
6161
{
62-
// record return value
63-
codet output(ID_output);
64-
output.operands().resize(2);
65-
6662
const symbolt &return_symbol = symbol_table.lookup_ref("return'");
6763

68-
output.op0()=
69-
address_of_exprt(
70-
index_exprt(
71-
string_constantt(return_symbol.base_name),
72-
from_integer(0, index_type())));
73-
74-
output.op1()=return_symbol.symbol_expr();
75-
output.add_source_location()=function.location;
76-
77-
init_code.add(std::move(output));
64+
// record return value
65+
init_code.add(code_outputt{
66+
return_symbol.base_name, return_symbol.symbol_expr(), function.location});
7867
}
7968

8069
#if 0
@@ -333,15 +322,8 @@ bool generate_ansi_c_start_function(
333322
init_code.add(code_assumet(std::move(le)));
334323
}
335324

336-
{
337-
// record argc as an input
338-
codet input(ID_input);
339-
input.operands().resize(2);
340-
input.op0()=address_of_exprt(
341-
index_exprt(string_constantt("argc"), from_integer(0, index_type())));
342-
input.op1()=argc_symbol.symbol_expr();
343-
init_code.add(std::move(input));
344-
}
325+
// record argc as an input
326+
init_code.add(code_inputt{"argc", argc_symbol.symbol_expr()});
345327

346328
if(parameters.size()==3)
347329
{

src/ansi-c/expr2c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,10 +2867,10 @@ std::string expr2ct::convert_code(
28672867
if(statement==ID_fence)
28682868
return convert_code_fence(src, indent);
28692869

2870-
if(statement==ID_input)
2870+
if(can_cast_expr<code_inputt>(src))
28712871
return convert_code_input(src, indent);
28722872

2873-
if(statement==ID_output)
2873+
if(can_cast_expr<code_outputt>(src))
28742874
return convert_code_output(src, indent);
28752875

28762876
if(statement==ID_assume)

src/cpp/library/cprover.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ void __CPROVER_assume(__CPROVER_bool assumption) __attribute__((__noreturn__));
2222
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
2323
void __CPROVER_precondition(__CPROVER_bool assertion, const char *description);
2424

25-
void __CPROVER_input(const char *id, ...);
26-
void __CPROVER_output(const char *id, ...);
25+
// NOLINTNEXTLINE(build/deprecated)
26+
void __CPROVER_input(const char *description, ...);
27+
// NOLINTNEXTLINE(build/deprecated)
28+
void __CPROVER_output(const char *description, ...);
2729

2830
// concurrency-related
2931
void __CPROVER_atomic_begin();

src/goto-programs/builtin_functions.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,29 @@ void goto_convertt::do_input(
316316
const exprt::operandst &arguments,
317317
goto_programt &dest)
318318
{
319-
codet input_code(ID_input);
320-
input_code.operands()=arguments;
321-
input_code.add_source_location()=function.source_location();
322-
323319
if(arguments.size()<2)
324320
{
325321
error().source_location=function.find_source_location();
326322
error() << "input takes at least two arguments" << eom;
327323
throw 0;
328324
}
329325

330-
copy(input_code, OTHER, dest);
326+
copy(code_inputt{arguments, function.source_location()}, OTHER, dest);
331327
}
332328

333329
void goto_convertt::do_output(
334330
const exprt &function,
335331
const exprt::operandst &arguments,
336332
goto_programt &dest)
337333
{
338-
codet output_code(ID_output);
339-
output_code.operands()=arguments;
340-
output_code.add_source_location()=function.source_location();
341-
342334
if(arguments.size()<2)
343335
{
344336
error().source_location=function.find_source_location();
345337
error() << "output takes at least two arguments" << eom;
346338
throw 0;
347339
}
348340

349-
copy(output_code, OTHER, dest);
341+
copy(code_outputt{arguments, function.source_location()}, OTHER, dest);
350342
}
351343

352344
void goto_convertt::do_atomic_begin(

src/goto-programs/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void interpretert::execute_other()
408408
assign(address, rhs);
409409
}
410410
}
411-
else if(statement==ID_output)
411+
else if(can_cast_expr<code_outputt>(pc->get_other()))
412412
{
413413
return;
414414
}

src/goto-symex/symex_other.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ void goto_symext::symex_other(
9797
const codet clean_code = to_code(clean_expr(code, state, false));
9898
symex_printf(state, clean_code);
9999
}
100-
else if(statement==ID_input)
100+
else if(can_cast_expr<code_inputt>(code))
101101
{
102102
const codet clean_code = to_code(clean_expr(code, state, false));
103103
symex_input(state, clean_code);
104104
}
105-
else if(statement==ID_output)
105+
else if(can_cast_expr<code_outputt>(code))
106106
{
107107
const codet clean_code = to_code(clean_expr(code, state, false));
108108
symex_output(state, clean_code);

src/pointer-analysis/value_set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ void value_sett::apply_code_rec(
16341634
else if(statement==ID_fence)
16351635
{
16361636
}
1637-
else if(statement==ID_input || statement==ID_output)
1637+
else if(can_cast_expr<code_inputt>(code) || can_cast_expr<code_outputt>(code))
16381638
{
16391639
// doesn't do anything
16401640
}

src/pointer-analysis/value_set_fi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ void value_set_fit::apply_code(const codet &code, const namespacet &ns)
14001400
statement==ID_array_set)
14011401
{
14021402
}
1403-
else if(statement==ID_input || statement==ID_output)
1403+
else if(can_cast_expr<code_inputt>(code) || can_cast_expr<code_outputt>(code))
14041404
{
14051405
// doesn't do anything
14061406
}

src/pointer-analysis/value_set_fivr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ void value_set_fivrt::apply_code(const codet &code, const namespacet &ns)
15281528
assign(lhs, code_return.return_value(), ns);
15291529
}
15301530
}
1531-
else if(statement==ID_input || statement==ID_output)
1531+
else if(can_cast_expr<code_inputt>(code) || can_cast_expr<code_outputt>(code))
15321532
{
15331533
// doesn't do anything
15341534
}

src/pointer-analysis/value_set_fivrns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ void value_set_fivrnst::apply_code(const codet &code, const namespacet &ns)
11921192
assign(lhs, code_return.return_value(), ns);
11931193
}
11941194
}
1195-
else if(statement==ID_input || statement==ID_output)
1195+
else if(can_cast_expr<code_inputt>(code) || can_cast_expr<code_outputt>(code))
11961196
{
11971197
// doesn't do anything
11981198
}

src/util/allocate_objects.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,8 @@ void allocate_objectst::mark_created_symbols_as_input(code_blockt &init_code)
247247
// INPUT("<identifier>", <identifier>);
248248
for(symbolt const *symbol_ptr : symbols_created)
249249
{
250-
codet input_code(ID_input);
251-
input_code.operands().resize(2);
252-
input_code.op0() = address_of_exprt(index_exprt(
253-
string_constantt(symbol_ptr->base_name), from_integer(0, index_type())));
254-
input_code.op1() = symbol_ptr->symbol_expr();
255-
input_code.add_source_location() = source_location;
256-
init_code.add(std::move(input_code));
250+
init_code.add(code_inputt{
251+
symbol_ptr->base_name, symbol_ptr->symbol_expr(), source_location});
257252
}
258253
}
259254

src/util/std_code.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "std_code.h"
1313

14+
#include "arith_tools.h"
15+
#include "c_types.h"
1416
#include "std_expr.h"
17+
#include "string_constant.h"
1518

1619
/// If this `codet` is a \ref code_blockt (i.e.\ it represents a block of
1720
/// statements), return the unmodified input. Otherwise (i.e.\ the `codet`
@@ -167,3 +170,59 @@ void code_function_bodyt::set_parameter_identifiers(
167170
sub.back().set(ID_identifier, id);
168171
}
169172
}
173+
174+
code_inputt::code_inputt(
175+
std::vector<exprt> arguments,
176+
optionalt<source_locationt> location)
177+
: codet{ID_input, std::move(arguments)}
178+
{
179+
if(location)
180+
add_source_location() = std::move(*location);
181+
check(*this, validation_modet::INVARIANT);
182+
}
183+
184+
code_inputt::code_inputt(
185+
const irep_idt &description,
186+
exprt expression,
187+
optionalt<source_locationt> location)
188+
: code_inputt{{address_of_exprt(index_exprt(
189+
string_constantt(description),
190+
from_integer(0, index_type()))),
191+
std::move(expression)},
192+
std::move(location)}
193+
{
194+
}
195+
196+
void code_inputt::check(const codet &code, const validation_modet vm)
197+
{
198+
DATA_CHECK(
199+
vm, code.operands().size() >= 2, "input must have at least two operands");
200+
}
201+
202+
code_outputt::code_outputt(
203+
std::vector<exprt> arguments,
204+
optionalt<source_locationt> location)
205+
: codet{ID_output, std::move(arguments)}
206+
{
207+
if(location)
208+
add_source_location() = std::move(*location);
209+
check(*this, validation_modet::INVARIANT);
210+
}
211+
212+
code_outputt::code_outputt(
213+
const irep_idt &description,
214+
exprt expression,
215+
optionalt<source_locationt> location)
216+
: code_outputt{{address_of_exprt(index_exprt(
217+
string_constantt(description),
218+
from_integer(0, index_type()))),
219+
std::move(expression)},
220+
std::move(location)}
221+
{
222+
}
223+
224+
void code_outputt::check(const codet &code, const validation_modet vm)
225+
{
226+
DATA_CHECK(
227+
vm, code.operands().size() >= 2, "output must have at least two operands");
228+
}

0 commit comments

Comments
 (0)