Skip to content

Commit 1c09ffd

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Add documentation to memory snapshot harness
This may need modification after #4150 is merged.
1 parent 38f7ae0 commit 1c09ffd

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Author: Daniel Poetzl
3232
"--initial-location <func[:<n>]>\n" \
3333
" use given function and location number as " \
3434
"entry\n point\n" \
35+
"--havoc-variables vars initialise variables from vars to\n" \
36+
" non-deterministic values" \
3537
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
3638
// clang-format on
3739

@@ -47,30 +49,93 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
4749
{
4850
}
4951

52+
/// 1. load memory table from the snapshot
53+
/// 2. add initial section to the initial location
54+
/// 3. assign global variables their snapshot values (via the harness
55+
/// function)
56+
/// 4. insert call of the initial location (with nondet values) into the
57+
/// harness function
58+
/// 5. build symbol for the harness functions
59+
/// 6. insert harness function into \p goto_model
60+
/// \param goto_model: goto model to be modified
61+
/// \param harness_function_name: name of the resulting harness function
5062
void generate(goto_modelt &goto_model, const irep_idt &harness_function_name)
5163
override;
5264

5365
protected:
66+
/// Collect the memory-snapshot specific cmdline options (one at a time)
67+
/// \param option: memory-snapshot | initial-location | havoc-variables
68+
/// \param values: list of arguments related to a given option
5469
void handle_option(
5570
const std::string &option,
5671
const std::list<std::string> &values) override;
5772

73+
/// Check that user options make sense:
74+
/// On their own, e.g. location number cannot be specified without a function.
75+
/// In relation to the input program, e.g. function name must be known via
76+
/// the symbol table.
5877
void validate_options() override;
5978

79+
/// Parse the snapshot JSON file and initialise the symbol table
80+
/// \param file: the snapshot JSON file
81+
/// \param snapshot: the resulting symbol table build from the snapshot
6082
void
6183
get_memory_snapshot(const std::string &file, symbol_tablet &snapshot) const;
6284

85+
/// Turn this:
86+
/// --------------------------------------------------------------------------
87+
/// int foo() {
88+
/// ..first_part..
89+
/// i: //location_number=i
90+
/// ..second_part..
91+
/// }
92+
/// --------------------------------------------------------------------------
93+
94+
/// Into this:
95+
/// --------------------------------------------------------------------------
96+
/// func_init_done;
97+
/// __CPROVER_initialize() {
98+
/// ...
99+
/// func_init_done = false;
100+
/// }
101+
/// int foo() {
102+
/// if (func_init_done) goto 1;
103+
/// func_init_done = true;
104+
/// goto i;
105+
/// 1: ;
106+
/// ..first_part..
107+
/// i: //location_number=i
108+
/// ..second_part..
109+
/// }
110+
/// --------------------------------------------------------------------------
111+
/// \param goto_model: Model where the modification takes place
63112
void add_init_section(goto_modelt &goto_model) const;
64113

114+
/// For each global symbol in the \p snapshot symbol table either:
115+
/// 1) add \ref code_assignt assigning a value from the \snapshot to the
116+
/// symbol
117+
/// 2) recursively initialise the symbol to a non-deterministic value of the
118+
/// right type
119+
/// \param snapshot: snapshot to load the symbols and their values from
120+
/// \param goto_model: model to initialise the havoc-ing
121+
/// \param code: block of code where the assignments are added
65122
void add_assignments_to_globals(
66123
const symbol_tablet &snapshot,
67124
goto_modelt &goto_model,
68125
code_blockt &code) const;
69126

127+
/// Create as many non-deterministic arguments as there are arguments of the
128+
/// \p called_function_symbol and add a function call with those arguments
129+
/// \param called_function_symbol: the function to be called
130+
/// \param code: the block of code where the function call is added
70131
void add_call_with_nondet_arguments(
71132
const symbolt &called_function_symbol,
72133
code_blockt &code) const;
73134

135+
/// Insert the \p function into the symbol table (and the goto functions map)
136+
/// of the \p goto_model
137+
/// \param goto_model: goto model where the insertion is to take place
138+
/// \param function: symbol of the function to be inserted
74139
void insert_function(goto_modelt &goto_model, const symbolt &function) const;
75140

76141
std::string memory_snapshot;

0 commit comments

Comments
 (0)