CBMC
structured_trace_util.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Author: Diffblue
4 
5 \*******************************************************************/
6 
10 
11 #include "structured_trace_util.h"
12 #include "goto_trace.h"
13 
14 #include <algorithm>
15 
18 {
19  const bool is_loophead = std::any_of(
20  instruction.incoming_edges.begin(),
21  instruction.incoming_edges.end(),
22  [](goto_programt::targett t) { return t->is_backwards_goto(); });
23 
24  return is_loophead ? default_step_kindt::LOOP_HEAD
26 }
27 std::string default_step_name(const default_step_kindt &step_type)
28 {
29  switch(step_type)
30  {
32  return "location-only";
34  return "loop-head";
35  }
37 }
38 
40  const goto_trace_stept &step,
41  const source_locationt &previous_source_location)
42 {
43  const source_locationt &source_location = step.pc->source_location();
44  if(source_location.is_nil() || source_location.get_file().empty())
45  return {};
46 
47  const auto default_step_kind = ::default_step_kind(*step.pc);
48 
49  // If this is just a source location then we output only the first
50  // location of a sequence of same locations.
51  // However, we don't want to suppress loop head locations because
52  // they might come from different loop iterations. If we suppressed
53  // them it would be impossible to know which loop iteration
54  // we are in.
55  if(
56  source_location == previous_source_location &&
58  {
59  return {};
60  }
61 
63  step.hidden,
64  step.thread_nr,
65  step.step_nr,
66  source_location};
67 }
default_step
optionalt< default_trace_stept > default_step(const goto_trace_stept &step, const source_locationt &previous_source_location)
Definition: structured_trace_util.cpp:39
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:503
default_step_kindt::LOCATION_ONLY
@ LOCATION_ONLY
default_step_name
std::string default_step_name(const default_step_kindt &step_type)
Turns a default_step_kindt into a string that can be used in the trace.
Definition: structured_trace_util.cpp:27
default_step_kindt::LOOP_HEAD
@ LOOP_HEAD
goto_trace_stept
Step of the trace of a GOTO program.
Definition: goto_trace.h:49
goto_trace.h
default_step_kindt
default_step_kindt
There are two kinds of step for location markers - location-only and loop-head (for locations associa...
Definition: structured_trace_util.h:20
goto_trace_stept::step_nr
std::size_t step_nr
Number of the step in the trace.
Definition: goto_trace.h:53
goto_trace_stept::pc
goto_programt::const_targett pc
Definition: goto_trace.h:112
irept::is_nil
bool is_nil() const
Definition: irep.h:376
dstringt::empty
bool empty() const
Definition: dstring.h:88
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
goto_trace_stept::thread_nr
unsigned thread_nr
Definition: goto_trace.h:115
default_step_kind
default_step_kindt default_step_kind(const goto_programt::instructiont &instruction)
Identify for a given instruction whether it is a loophead or just a location.
Definition: structured_trace_util.cpp:17
source_locationt
Definition: source_location.h:18
default_trace_stept
Definition: structured_trace_util.h:40
goto_programt::instructiont::incoming_edges
std::set< targett > incoming_edges
Definition: goto_program.h:422
goto_trace_stept::hidden
bool hidden
Definition: goto_trace.h:100
source_locationt::get_file
const irep_idt & get_file() const
Definition: source_location.h:35
structured_trace_util.h
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition: goto_program.h:180
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:586