-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfg.h
63 lines (52 loc) · 1.31 KB
/
cfg.h
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
#ifndef CFG_H
#define CFG_H
#include "disasm.h"
#include <array>
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <initializer_list>
class basic_block : public std::list<vins> {
public:
std::vector<basic_block*> predecessors;
std::vector<basic_block*> successors;
std::set<basic_block*> callers;
basic_block* next;
basic_block() {
next = nullptr;
visited = false;
forward_visited = false;
backward_visited = false;
}
basic_block(std::initializer_list<vins> ins)
:std::list<vins>(ins)
{
next = nullptr;
visited = false;
forward_visited = false;
backward_visited = false;
}
bool is_exit() const { return successors.empty(); }
bool is_entry() const { return front().is_pseudo() && front().operands == "func_entry"; }
bool visited; // for analysis
bool forward_visited;
bool backward_visited;
friend std::ostream& operator<<(std::ostream& os, const basic_block& bb);
};
class control_flow_graph : public std::list<basic_block> {
public:
void reset() {
for (auto& bb : *this) {
bb.visited = false;
bb.forward_visited = false;
bb.backward_visited = false;
}
}
const std::set<std::string>& entries() const;
private:
std::set<std::string> _entries;
};
control_flow_graph get_cfg(lifter& lift);
std::list<vins> cfg_dump(control_flow_graph& cfg);
#endif //CFG_H