CBMC
goto_instruction_code.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Data structures representing instructions in a GOTO program
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "goto_instruction_code.h"
13 
14 #include <util/arith_tools.h>
15 #include <util/c_types.h>
16 #include <util/cprover_prefix.h>
17 #include <util/namespace.h>
18 #include <util/std_expr.h>
19 #include <util/string_constant.h>
20 #include <util/symbol.h>
21 
23  std::vector<exprt> arguments,
24  std::optional<source_locationt> location)
25  : codet{ID_input, std::move(arguments)}
26 {
27  if(location)
28  add_source_location() = std::move(*location);
30 }
31 
33  const irep_idt &description,
34  exprt expression,
35  std::optional<source_locationt> location)
36  : code_inputt{
38  string_constantt(description),
39  from_integer(0, c_index_type()))),
40  std::move(expression)},
41  std::move(location)}
42 {
43 }
44 
45 void code_inputt::check(const codet &code, const validation_modet vm)
46 {
47  DATA_CHECK(
48  vm, code.operands().size() >= 2, "input must have at least two operands");
49 }
50 
52  std::vector<exprt> arguments,
53  std::optional<source_locationt> location)
54  : codet{ID_output, std::move(arguments)}
55 {
56  if(location)
57  add_source_location() = std::move(*location);
59 }
60 
62  const irep_idt &description,
63  exprt expression,
64  std::optional<source_locationt> location)
65  : code_outputt{
67  string_constantt(description),
68  from_integer(0, c_index_type()))),
69  std::move(expression)},
70  std::move(location)}
71 {
72 }
73 
74 void code_outputt::check(const codet &code, const validation_modet vm)
75 {
76  DATA_CHECK(
77  vm, code.operands().size() >= 2, "output must have at least two operands");
78 }
79 
81 havoc_slice_call(const exprt &p, const exprt &size, const namespacet &ns)
82 {
83  irep_idt identifier = CPROVER_PREFIX "havoc_slice";
84  symbol_exprt havoc_slice_function = ns.lookup(identifier).symbol_expr();
85  code_function_callt::argumentst arguments = {p, size};
86  return code_function_callt{std::move(havoc_slice_function),
87  std::move(arguments)};
88 }
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
bitvector_typet c_index_type()
Definition: c_types.cpp:16
Operator to return the address of an object.
Definition: pointer_expr.h:540
goto_instruction_codet representation of a function call statement.
exprt::operandst argumentst
A goto_instruction_codet representing the declaration that an input of a particular description has a...
static void check(const goto_instruction_codet &code, const validation_modet vm=validation_modet::INVARIANT)
code_inputt(std::vector< exprt > arguments, std::optional< source_locationt > location={})
This constructor is for support of calls to __CPROVER_input in user code.
A goto_instruction_codet representing the declaration that an output of a particular description has ...
code_outputt(std::vector< exprt > arguments, std::optional< source_locationt > location={})
This constructor is for support of calls to __CPROVER_output in user code.
static void check(const goto_instruction_codet &code, const validation_modet vm=validation_modet::INVARIANT)
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:29
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
source_locationt & add_source_location()
Definition: expr.h:236
operandst & operands()
Definition: expr.h:94
Array index operator.
Definition: std_expr.h:1465
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:148
Expression to hold a symbol (variable)
Definition: std_expr.h:131
#define CPROVER_PREFIX
code_function_callt havoc_slice_call(const exprt &p, const exprt &size, const namespacet &ns)
Builds a code_function_callt to __CPROVER_havoc_slice(p, size).
API to expression classes.
Symbol table entry.
#define DATA_CHECK(vm, condition, message)
This macro takes a condition which denotes a well-formedness criterion on goto programs,...
Definition: validate.h:22
validation_modet