Line data Source code
1 : #ifndef CONTROLFLOW_HPP 2 : #define CONTROLFLOW_HPP 3 : 4 : #include <vector> 5 : #include <fstream> 6 : #include "common/tables.hpp" 7 : #include "common/poliz.hpp" 8 : 9 : /* Эта опция нужна для прорисовки ГПУ по шагам */ 10 : //#define CFG_STEPBYSTEP 11 : 12 : struct flowTree { 13 : int ID; // Для визуализации 14 : POLIZ block; // Блок кода 15 : bool splitted; 16 : 17 196 : explicit flowTree(int id): ID(id), splitted(false) {}; 18 : /* 0 -- безусловный переход, 1 -- True, 2 -- False */ 19 : std::vector<std::pair<flowTree*, char>> prev; // Множество предыдущих блоков 20 : std::vector<std::pair<flowTree*, char>> next; // Множество следующих блоков 21 : static std::vector<int> checked; // Для поиска 22 : flowTree* getFT(int id, bool head = true); // Поиск 23 : flowTree* split(int id); // Разбиение ветки по номеру блока 24 : }; 25 : 26 : class ControlFlowGraph { 27 : flowTree ft; 28 : std::vector<flowTree *> tails; 29 : std::ofstream graph; 30 : std::vector<int> drawed; 31 : int blocksNum; 32 : int jumpsNum; 33 : int funcsNum; 34 : public: 35 29 : ControlFlowGraph(): ft(0), blocksNum(0), jumpsNum(0), funcsNum(0) {}; 36 : 37 : void clear(void); 38 : void make(POLIZ * p); 39 : void info(void) const; 40 : flowTree * head(void); 41 : flowTree * tailStop(void); 42 : void findTails(flowTree * ft); 43 : std::vector<flowTree *> tailRet(void); 44 : IdentTable * decompose(IdentTable* IT, POLIZ* poliz); 45 : void newBlock(int blockId, POLIZ * p, flowTree * curBlock, char cond = 0); 46 : void makeBranch(POLIZ * p, flowTree * curBlock, flowTree * fb, bool exists); 47 : void deleteBranch(std::vector<std::pair<flowTree *, char>> vec, std::vector<flowTree*> * del); 48 : void newConn(POLIZ* poliz, flowTree * curBlock, std::vector<int> * ls, std::vector<flowTree *> * eb); 49 : void insertBlock(POLIZ* poliz, flowTree * curBlock, std::vector<int> * ls, std::vector<flowTree *> * eb); 50 : 51 : #ifdef DRAW_GRAPH 52 : void draw(const std::string & filename); 53 : void drawNode(flowTree p); 54 : void drawEdge(flowTree & p); 55 : #endif 56 : ~ControlFlowGraph(); 57 : }; 58 : 59 : #endif