cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
local_cfg.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: CFG for One Function
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#include "
local_cfg.h
"
13
14
void
local_cfgt::build
(
const
goto_programt
&goto_program)
15
{
16
nodes
.resize(goto_program.
instructions
.size());
17
18
{
19
node_nrt
loc_nr=0;
20
21
for
(
goto_programt::const_targett
it=goto_program.
instructions
.begin();
22
it!=goto_program.
instructions
.end();
23
it++, loc_nr++)
24
{
25
loc_map
[it]=loc_nr;
26
nodes
[loc_nr].t=it;
27
}
28
}
29
30
for
(
node_nrt
loc_nr=0; loc_nr<
nodes
.size(); loc_nr++)
31
{
32
nodet
&node=
nodes
[loc_nr];
33
const
goto_programt::instructiont
&instruction=*node.
t
;
34
35
switch
(instruction.
type
())
36
{
37
case
GOTO
:
38
if
(instruction.
condition
() !=
true
)
39
node.
successors
.push_back(loc_nr+1);
40
41
for
(
const
auto
&target : instruction.
targets
)
42
{
43
node_nrt
l=
loc_map
.find(target)->second;
44
node.
successors
.push_back(l);
45
}
46
break
;
47
48
case
START_THREAD
:
49
node.
successors
.push_back(loc_nr+1);
50
51
for
(
const
auto
&target : instruction.
targets
)
52
{
53
node_nrt
l=
loc_map
.find(target)->second;
54
node.
successors
.push_back(l);
55
}
56
break
;
57
58
case
THROW
:
59
case
END_FUNCTION
:
60
case
END_THREAD
:
61
break
;
// no successor
62
63
case
CATCH
:
64
case
SET_RETURN_VALUE
:
65
case
ATOMIC_BEGIN
:
66
case
ATOMIC_END
:
67
case
LOCATION
:
68
case
SKIP
:
69
case
OTHER
:
70
case
ASSERT
:
71
case
ASSUME
:
72
case
FUNCTION_CALL
:
73
case
DECL
:
74
case
DEAD
:
75
case
ASSIGN
:
76
node.
successors
.push_back(loc_nr + 1);
77
break
;
78
79
case
INCOMPLETE_GOTO
:
80
case
NO_INSTRUCTION_TYPE
:
81
DATA_INVARIANT
(
false
,
"Only complete instructions can be analyzed"
);
82
break
;
83
}
84
}
85
}
goto_programt::instructiont
This class represents an instruction in the GOTO intermediate representation.
Definition
goto_program.h:180
goto_programt::instructiont::targets
targetst targets
The list of successor instructions.
Definition
goto_program.h:413
goto_programt::instructiont::condition
const exprt & condition() const
Get the condition of gotos, assume, assert.
Definition
goto_program.h:365
goto_programt::instructiont::type
goto_program_instruction_typet type() const
What kind of instruction?
Definition
goto_program.h:343
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition
goto_program.h:72
goto_programt::instructions
instructionst instructions
The list of instructions in the goto program.
Definition
goto_program.h:621
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition
goto_program.h:614
local_cfgt::nodet
Definition
local_cfg.h:26
local_cfgt::nodet::t
goto_programt::const_targett t
Definition
local_cfg.h:28
local_cfgt::nodet::successors
successorst successors
Definition
local_cfg.h:29
local_cfgt::nodes
nodest nodes
Definition
local_cfg.h:38
local_cfgt::node_nrt
std::size_t node_nrt
Definition
local_cfg.h:22
local_cfgt::loc_map
loc_mapt loc_map
Definition
local_cfg.h:35
local_cfgt::build
void build(const goto_programt &goto_program)
Definition
local_cfg.cpp:14
FUNCTION_CALL
@ FUNCTION_CALL
Definition
goto_program.h:48
ATOMIC_END
@ ATOMIC_END
Definition
goto_program.h:43
DEAD
@ DEAD
Definition
goto_program.h:47
LOCATION
@ LOCATION
Definition
goto_program.h:40
END_FUNCTION
@ END_FUNCTION
Definition
goto_program.h:41
ASSIGN
@ ASSIGN
Definition
goto_program.h:45
ASSERT
@ ASSERT
Definition
goto_program.h:35
SET_RETURN_VALUE
@ SET_RETURN_VALUE
Definition
goto_program.h:44
ATOMIC_BEGIN
@ ATOMIC_BEGIN
Definition
goto_program.h:42
CATCH
@ CATCH
Definition
goto_program.h:50
END_THREAD
@ END_THREAD
Definition
goto_program.h:39
SKIP
@ SKIP
Definition
goto_program.h:37
NO_INSTRUCTION_TYPE
@ NO_INSTRUCTION_TYPE
Definition
goto_program.h:32
START_THREAD
@ START_THREAD
Definition
goto_program.h:38
THROW
@ THROW
Definition
goto_program.h:49
DECL
@ DECL
Definition
goto_program.h:46
OTHER
@ OTHER
Definition
goto_program.h:36
GOTO
@ GOTO
Definition
goto_program.h:33
INCOMPLETE_GOTO
@ INCOMPLETE_GOTO
Definition
goto_program.h:51
ASSUME
@ ASSUME
Definition
goto_program.h:34
local_cfg.h
CFG for One Function.
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition
invariant.h:534
analyses
local_cfg.cpp
Generated by
1.17.0