CBMC
is_threaded.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Over-approximate Concurrency for Threaded Goto Programs
4 
5 Author: Daniel Kroening
6 
7 Date: October 2012
8 
9 \*******************************************************************/
10 
13 
14 #include "is_threaded.h"
15 
16 #include "ai.h"
17 
19 {
20 public:
21  bool reachable;
23 
25  reachable(false),
26  is_threaded(false)
27  {
28  // this is bottom
29  }
30 
32  {
33  INVARIANT(src.reachable,
34  "Abstract states are only merged at reachable locations");
35 
36  bool old_reachable=reachable;
37  bool old_is_threaded=is_threaded;
38 
39  reachable=true;
41 
42  return old_reachable!=reachable ||
43  old_is_threaded!=is_threaded;
44  }
45 
46  void transform(
47  const irep_idt &,
48  trace_ptrt trace_from,
49  const irep_idt &,
50  trace_ptrt,
51  ai_baset &,
52  const namespacet &) override
53  {
54  locationt from{trace_from->current_location()};
55 
57  "Transformers are only applied at reachable locations");
58 
59  if(from->is_start_thread())
60  is_threaded=true;
61  }
62 
63  void make_bottom() final override
64  {
65  reachable=false;
66  is_threaded=false;
67  }
68 
69  void make_top() final override
70  {
71  reachable=true;
72  is_threaded=true;
73  }
74 
75  void make_entry() final override
76  {
77  reachable=true;
78  is_threaded=false;
79  }
80 
81  bool is_bottom() const override final
82  {
84  "A location cannot be threaded if it is not reachable.");
85 
86  return !reachable;
87  }
88 
89  bool is_top() const override final
90  {
91  return reachable && is_threaded;
92  }
93 };
94 
95 void is_threadedt::compute(const goto_functionst &goto_functions)
96 {
97  // the analysis doesn't actually use the namespace, fake one
98  symbol_tablet symbol_table;
99  const namespacet ns(symbol_table);
100 
101  ait<is_threaded_domaint> is_threaded_analysis;
102 
103  is_threaded_analysis(goto_functions, ns);
104 
105  for(const auto &gf_entry : goto_functions.function_map)
106  {
107  forall_goto_program_instructions(i_it, gf_entry.second.body)
108  {
109  auto domain_ptr = is_threaded_analysis.abstract_state_before(i_it);
110  if(static_cast<const is_threaded_domaint &>(*domain_ptr).is_threaded)
111  is_threaded_set.insert(i_it);
112  }
113  }
114 }
Abstract Interpretation.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:117
virtual cstate_ptrt abstract_state_before(locationt l) const
Get a copy of the abstract state before the given instruction, without needing to know what kind of d...
Definition: ai.h:221
The interface offered by a domain, allows code to manipulate domains without knowing their exact type...
Definition: ai_domain.h:54
ai_history_baset::trace_ptrt trace_ptrt
Definition: ai_domain.h:73
goto_programt::const_targett locationt
Definition: ai_domain.h:72
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition: ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
A collection of goto functions.
function_mapt function_map
bool is_bottom() const override final
Definition: is_threaded.cpp:81
void transform(const irep_idt &, trace_ptrt trace_from, const irep_idt &, trace_ptrt, ai_baset &, const namespacet &) override
how function calls are treated: a) there is an edge from each call site to the function head b) there...
Definition: is_threaded.cpp:46
bool merge(const is_threaded_domaint &src, trace_ptrt, trace_ptrt)
Definition: is_threaded.cpp:31
void make_bottom() final override
no states
Definition: is_threaded.cpp:63
void make_entry() final override
Make this domain a reasonable entry-point state For most domains top is sufficient.
Definition: is_threaded.cpp:75
void make_top() final override
all states – the analysis doesn't use this directly (see make_entry) and domains may refuse to implem...
Definition: is_threaded.cpp:69
bool is_top() const override final
Definition: is_threaded.cpp:89
void compute(const goto_functionst &goto_functions)
Definition: is_threaded.cpp:95
is_threaded_sett is_threaded_set
Definition: is_threaded.h:50
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The symbol table.
Definition: symbol_table.h:14
#define forall_goto_program_instructions(it, program)
Over-approximate Concurrency for Threaded Goto Programs.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:534