Skip to content

Commit 6ca35c2

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Add documentation to memory snapshot harness
Code level documentation for the class methods.
1 parent 7eaf157 commit 6ca35c2

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,97 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
5151
{
5252
}
5353

54+
/// The main function of this harness, consists of the following:
55+
/// 1. Load memory table from the snapshot.
56+
/// 2. Add initial section to the user-specified initial location.
57+
/// 3. Assign global variables their snapshot values (via the harness
58+
/// function).
59+
/// 4. Insert call of the initial location (with nondet values) into the
60+
/// harness function.
61+
/// 5. Build symbol for the harness functions.
62+
/// 6. Insert harness function into \p goto_model.
63+
/// \param goto_model: goto model to be modified
64+
/// \param harness_function_name: name of the resulting harness function
5465
void generate(goto_modelt &goto_model, const irep_idt &harness_function_name)
5566
override;
5667

5768
protected:
69+
/// Collect the memory-snapshot specific cmdline options (one at a time)
70+
/// \param option: memory-snapshot | initial-location | havoc-variables
71+
/// \param values: list of arguments related to a given option
5872
void handle_option(
5973
const std::string &option,
6074
const std::list<std::string> &values) override;
6175

76+
/// Check that user options make sense:
77+
/// On their own, e.g. location number cannot be specified without a function.
78+
/// In relation to the input program, e.g. function name must be known via
79+
/// the symbol table.
80+
/// \param goto_model: the model containing the symbol table, goto functions,
81+
/// etc.
6282
void validate_options(const goto_modelt &goto_model) override;
6383

84+
/// Parse the snapshot JSON file and initialise the symbol table
85+
/// \param file: the snapshot JSON file
86+
/// \param snapshot: the resulting symbol table built from the snapshot
6487
void
6588
get_memory_snapshot(const std::string &file, symbol_tablet &snapshot) const;
6689

90+
/// Modify the entry-point function to start from the user-specified initial
91+
/// location.
92+
/// Turn this:
93+
///
94+
/// int foo() {
95+
/// ..first_part..
96+
/// i: //location_number=i
97+
/// ..second_part..
98+
/// }
99+
///
100+
/// Into this:
101+
///
102+
/// func_init_done;
103+
/// __CPROVER_initialize() {
104+
/// ...
105+
/// func_init_done = false;
106+
/// }
107+
/// int foo() {
108+
/// if (func_init_done) goto 1;
109+
/// func_init_done = true;
110+
/// goto i;
111+
/// 1: ;
112+
/// ..first_part..
113+
/// i: //location_number=i
114+
/// ..second_part..
115+
/// }
116+
///
117+
/// \param goto_model: Model where the modification takes place
67118
void add_init_section(goto_modelt &goto_model) const;
68119

120+
/// For each global symbol in the \p snapshot symbol table either:
121+
/// 1) add \ref code_assignt assigning a value from the \p snapshot to the
122+
/// symbol
123+
/// or
124+
/// 2) recursively initialise the symbol to a non-deterministic value of the
125+
/// right type
126+
/// \param snapshot: snapshot to load the symbols and their values from
127+
/// \param goto_model: model to initialise the havoc-ing
128+
/// \return the block of code where the assignments are added
69129
code_blockt add_assignments_to_globals(
70130
const symbol_tablet &snapshot,
71131
goto_modelt &goto_model) const;
132+
133+
/// Create as many non-deterministic arguments as there are arguments of the
134+
/// \p called_function_symbol and add a function call with those arguments
135+
/// \param called_function_symbol: the function to be called
136+
/// \param code: the block of code where the function call is added
72137
void add_call_with_nondet_arguments(
73138
const symbolt &called_function_symbol,
74139
code_blockt &code) const;
75140

141+
/// Insert the \p function into the symbol table (and the goto functions map)
142+
/// of the \p goto_model
143+
/// \param goto_model: goto model where the insertion is to take place
144+
/// \param function: symbol of the function to be inserted
76145
void insert_harness_function_into_goto_model(
77146
goto_modelt &goto_model,
78147
const symbolt &function) const;

0 commit comments

Comments
 (0)