-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_blocks.hpp
78 lines (61 loc) · 1.83 KB
/
basic_blocks.hpp
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
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <regex>
#include <set>
#include <algorithm>
#include <fstream>
#include "line.hpp"
class BasicBlock{
public:
BasicBlock()
: bb_id{bb_count++},
m_use{{""}}, m_def{{""}},
m_in{{""}}, m_out{{""}}
{}
BasicBlock(std::string s)
: bb_id{-1},
m_use{{""}}, m_def{{""}},
m_in{{""}}, m_out{{""}}
{}
void addLine(std::string& line);
std::vector<Line*> getLines() const;
void addChild(BasicBlock* c);
std::vector<BasicBlock*>& getChildren();
void print();
int getID();
friend std::set<std::string> line_in(const BasicBlock& bb, Line* line);
friend std::set<std::string> line_out(const BasicBlock& bb, Line* line);
std::set<std::string> use();
std::set<std::string> def();
std::set<std::string> in_bb();
std::set<std::string> out_bb();
std::set<std::string> in_bb() const;
std::set<std::string> out_bb() const;
void print_def() const;
void print_use() const;
void print_in() const;
void print_out() const;
// CFG construction and manipulation
static std::set<std::string> cfg;
std::string toGraphNode();
static void toGraph(BasicBlock* root);
static void saveGraph(std::string outputFilePath);
static void displayGraph(std::string filePath);
void setVisited();
bool isVisited();
void clean_sets();
private:
static int bb_count;
int bb_id;
std::set<std::string> m_use;
std::set<std::string> m_def;
std::set<std::string> m_in;
std::set<std::string> m_out;
std::vector<Line*> _lines;
std::vector<BasicBlock*> _children;
bool visited; // HACK: for graphing
};
std::set<std::string> line_in(const BasicBlock& bb, std::string& line);
std::set<std::string> line_out(const BasicBlock& bb, std::string& line);