Skip to content

Commit b1e8a7c

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 aa975d0 commit b1e8a7c

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
@@ -49,28 +49,97 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
4949
{
5050
}
5151

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

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

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

82+
/// Parse the snapshot JSON file and initialise the symbol table
83+
/// \param file: the snapshot JSON file
84+
/// \param snapshot: the resulting symbol table built from the snapshot
6285
void
6386
get_memory_snapshot(const std::string &file, symbol_tablet &snapshot) const;
6487

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

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

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

0 commit comments

Comments
 (0)