OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SKSL_CFGGENERATOR | |
9 #define SKSL_CFGGENERATOR | |
10 | |
11 #include "ir/SkSLExpression.h" | |
12 #include "ir/SkSLFunctionDefinition.h" | |
13 | |
14 #include <set> | |
15 #include <stack> | |
16 | |
17 namespace SkSL { | |
18 | |
19 typedef size_t BlockId; | |
dogben
2016/10/13 03:55:43
nit: document this is index in CFG::fBlocks.
| |
20 | |
21 struct BasicBlock { | |
22 struct Node { | |
23 enum Kind { | |
24 kStatement_Kind, | |
25 kExpression_Kind | |
26 }; | |
27 | |
28 Kind fKind; | |
29 const IRNode* fNode; | |
30 }; | |
31 | |
32 std::vector<Node> fNodes; | |
33 std::set<BlockId> fEntrances; | |
34 std::set<BlockId> fExits; | |
35 // variable definitions upon entering this basic block (null expression = un defined) | |
36 std::unordered_map<const Variable*, const Expression*> fBefore; | |
37 }; | |
38 | |
39 struct CFG { | |
40 BlockId fStart; | |
41 BlockId fExit; | |
42 std::vector<BasicBlock> fBlocks; | |
43 | |
44 void dump(); | |
45 | |
46 private: | |
47 BlockId fCurrent; | |
48 | |
49 // Adds a new block, adds an exit from the current block to the new block, t hen marks the new | |
50 // block as the current block | |
51 BlockId newBlock(); | |
52 | |
53 // Adds a new block, but does not mark it current or add an exit from the cu rrent block | |
54 BlockId newIsolatedBlock(); | |
55 | |
56 // Adds an exit from the from block to the to block | |
57 void addExit(BlockId from, BlockId to); | |
58 | |
59 friend class CFGGenerator; | |
60 }; | |
61 | |
62 /** | |
63 * Converts functions into control flow graphs. | |
64 */ | |
65 class CFGGenerator { | |
66 public: | |
67 CFGGenerator() {} | |
68 | |
69 CFG getCFG(const FunctionDefinition& f); | |
dogben
2016/10/13 03:55:43
nit: mention getCFG does not set BasicBlock::fBefo
| |
70 | |
71 private: | |
72 void addStatement(CFG& cfg, const Statement* s); | |
73 | |
74 void addExpression(CFG& cfg, const Expression* e); | |
75 | |
76 void addLValue(CFG& cfg, const Expression* e); | |
77 | |
78 std::stack<BlockId> fLoopContinues; | |
79 std::stack<BlockId> fLoopExits; | |
80 }; | |
81 | |
82 } | |
83 | |
84 #endif | |
OLD | NEW |