-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathlocal_cfg.cpp
89 lines (73 loc) · 1.93 KB
/
local_cfg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*******************************************************************\
Module: CFG for One Function
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// CFG for One Function
#include "local_cfg.h"
void local_cfgt::build(const goto_programt &goto_program)
{
nodes.resize(goto_program.instructions.size());
{
node_nrt loc_nr=0;
for(goto_programt::const_targett it=goto_program.instructions.begin();
it!=goto_program.instructions.end();
it++, loc_nr++)
{
loc_map[it]=loc_nr;
nodes[loc_nr].t=it;
}
}
for(node_nrt loc_nr=0; loc_nr<nodes.size(); loc_nr++)
{
nodet &node=nodes[loc_nr];
const goto_programt::instructiont &instruction=*node.t;
switch(instruction.type())
{
case GOTO:
if(
!instruction.condition().is_constant() ||
!to_constant_expr(instruction.condition()).is_true())
{
node.successors.push_back(loc_nr+1);
}
for(const auto &target : instruction.targets)
{
node_nrt l=loc_map.find(target)->second;
node.successors.push_back(l);
}
break;
case START_THREAD:
node.successors.push_back(loc_nr+1);
for(const auto &target : instruction.targets)
{
node_nrt l=loc_map.find(target)->second;
node.successors.push_back(l);
}
break;
case THROW:
case END_FUNCTION:
case END_THREAD:
break; // no successor
case CATCH:
case SET_RETURN_VALUE:
case ATOMIC_BEGIN:
case ATOMIC_END:
case LOCATION:
case SKIP:
case OTHER:
case ASSERT:
case ASSUME:
case FUNCTION_CALL:
case DECL:
case DEAD:
case ASSIGN:
node.successors.push_back(loc_nr + 1);
break;
case INCOMPLETE_GOTO:
case NO_INSTRUCTION_TYPE:
DATA_INVARIANT(false, "Only complete instructions can be analyzed");
break;
}
}
}